Simplify GUI Proxy implementation & customisation.

This finishes 7c04ea0211 and 1b67a079fb.
GUI Proxy objects are now easier to specialize, code duplication is
reduced, code is made safer.
In details:
- the proxy private is always the IGUIObject* pointer
- the private data is accessed through a safer wrapper
- CreateJSObject returns an opaque type to allow easier extension &
prevent errors.
- The implementation of CreateJSObject is moved near the GUI Proxy
template instantiation, and both are wrapped in a convenient macro (this
makes it so that if you use the macro, you can't forget to overload the
method, and vice-versa).
- The common IGUIObject JS interface no longer needs to be repeated.
- All specialisations are again put in the same file, for improved
compile-time & clarity, given there are so few lines now.
- While at it, implement toSource which makes it possible to `uneval`
components (does the same as toString though).


Differential Revision: https://code.wildfiregames.com/D3826
This was SVN commit r25225.
This commit is contained in:
wraitii
2021-04-09 18:01:47 +00:00
parent 3759fc8a98
commit fc60d80af1
16 changed files with 221 additions and 290 deletions
+10 -1
View File
@@ -285,7 +285,16 @@ public:
template <auto callable, GetterFor<decltype(callable)> thisGetter = nullptr, u16 flags = JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT>
static JSFunctionSpec Wrap(const char* name)
{
return JS_FN(name, (&ToJSNative<callable>), args_info<decltype(callable)>::nb_args, flags);
return JS_FN(name, (&ToJSNative<callable, thisGetter>), args_info<decltype(callable)>::nb_args, flags);
}
/**
* Return a JSFunction from a C++ function.
*/
template <auto callable, GetterFor<decltype(callable)> thisGetter = nullptr, u16 flags = JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT>
static JSFunction* Create(const ScriptRequest& rq, const char* name)
{
return JS_NewFunction(rq.cx, &ToJSNative<callable, thisGetter>, args_info<decltype(callable)>::nb_args, flags, name);
}
/**