|
| template<> |
| bool | FromJSVal< bool > (const Request &rq, JS::HandleValue v, bool &out) |
| |
| template<> |
| bool | FromJSVal< float > (const Request &rq, JS::HandleValue v, float &out) |
| |
| template<> |
| bool | FromJSVal< double > (const Request &rq, JS::HandleValue v, double &out) |
| |
| template<> |
| bool | FromJSVal< std::int32_t > (const Request &rq, JS::HandleValue v, std::int32_t &out) |
| |
| template<> |
| bool | FromJSVal< std::uint32_t > (const Request &rq, JS::HandleValue v, std::uint32_t &out) |
| |
| template<> |
| bool | FromJSVal< std::uint16_t > (const Request &rq, JS::HandleValue v, std::uint16_t &out) |
| |
| template<> |
| bool | FromJSVal< std::uint8_t > (const Request &rq, JS::HandleValue v, std::uint8_t &out) |
| |
| template<> |
| bool | FromJSVal< std::wstring > (const Request &rq, JS::HandleValue v, std::wstring &out) |
| |
| template<> |
| bool | FromJSVal< Path > (const Request &rq, JS::HandleValue v, Path &out) |
| |
| template<> |
| bool | FromJSVal< std::string > (const Request &rq, JS::HandleValue v, std::string &out) |
| |
| template<> |
| bool | FromJSVal< CStr8 > (const Request &rq, JS::HandleValue v, CStr8 &out) |
| |
| template<> |
| bool | FromJSVal< CStrW > (const Request &rq, JS::HandleValue v, CStrW &out) |
| |
| template<> |
| bool | FromJSVal< Entity > (const Request &rq, JS::HandleValue v, Entity &out) |
| |
| template<> |
| void | ToJSVal< bool > (const Request &, JS::MutableHandleValue ret, const bool &val) |
| |
| template<> |
| void | ToJSVal< float > (const Request &, JS::MutableHandleValue ret, const float &val) |
| |
| template<> |
| void | ToJSVal< double > (const Request &, JS::MutableHandleValue ret, const double &val) |
| |
| template<> |
| void | ToJSVal< std::int32_t > (const Request &, JS::MutableHandleValue ret, const std::int32_t &val) |
| |
| template<> |
| void | ToJSVal< std::uint16_t > (const Request &, JS::MutableHandleValue ret, const std::uint16_t &val) |
| |
| template<> |
| void | ToJSVal< std::uint8_t > (const Request &, JS::MutableHandleValue ret, const std::uint8_t &val) |
| |
| template<> |
| void | ToJSVal< std::uint32_t > (const Request &, JS::MutableHandleValue ret, const std::uint32_t &val) |
| |
| template<> |
| void | ToJSVal< std::wstring > (const Request &rq, JS::MutableHandleValue ret, const std::wstring &val) |
| |
| template<> |
| void | ToJSVal< Path > (const Request &rq, JS::MutableHandleValue ret, const Path &val) |
| |
| template<> |
| void | ToJSVal< std::string > (const Request &rq, JS::MutableHandleValue ret, const std::string &val) |
| |
| template<> |
| void | ToJSVal< const wchar_t * > (const Request &rq, JS::MutableHandleValue ret, const wchar_t *const &val) |
| |
| template<> |
| void | ToJSVal< const char * > (const Request &rq, JS::MutableHandleValue ret, const char *const &val) |
| |
| template<> |
| void | ToJSVal< CStrW > (const Request &rq, JS::MutableHandleValue ret, const CStrW &val) |
| |
| template<> |
| void | ToJSVal< CStr8 > (const Request &rq, JS::MutableHandleValue ret, const CStr8 &val) |
| |
| template<typename T > |
| bool | FromJSVal (const Request &rq, const JS::HandleValue val, T &ret) |
| | Convert a JS::Value to a C++ type. More...
|
| |
| template<typename T > |
| bool | FromJSVal (const Request &rq, JS::HandleValue v, std::optional< T > &out) |
| |
| template<typename T > |
| void | ToJSVal (const Request &rq, JS::MutableHandleValue ret, T const &val) |
| | Convert a C++ type to a JS::Value. More...
|
| |
| template<std::size_t N> |
| void | ToJSVal (const Request &rq, JS::MutableHandleValue ret, const char(&val)[N]) |
| |
| template<std::size_t N> |
| void | ToJSVal (const Request &rq, JS::MutableHandleValue ret, const wchar_t(&val)[N]) |
| |
| template<> |
| void | ToJSVal< JS::PersistentRootedValue > (const Request &, JS::MutableHandleValue handle, const JS::PersistentRootedValue &a) |
| |
| template<> |
| void | ToJSVal< JS::Heap< JS::Value > > (const Request &, JS::MutableHandleValue handle, const JS::Heap< JS::Value > &a) |
| |
| template<> |
| void | ToJSVal< JS::RootedValue > (const Request &, JS::MutableHandleValue handle, const JS::RootedValue &a) |
| |
| template<> |
| void | ToJSVal< JS::HandleValue > (const Request &, JS::MutableHandleValue handle, const JS::HandleValue &a) |
| |
| template<typename T > |
| bool | FromJSProperty (const Request &rq, const JS::HandleValue val, const char *name, T &ret, bool strict=false) |
| | Convert a named property of an object to a C++ type. More...
|
| |
| template<typename T > |
| void | ToJSVal_vector (const Request &rq, JS::MutableHandleValue ret, const std::vector< T > &val) |
| |
| template<typename T > |
| bool | FromJSVal_vector (const Request &rq, JS::HandleValue v, std::vector< T > &out) |
| |
| std::string | ToString (const Script::Request &rq, JS::MutableHandleValue obj, bool pretty=false) |
| | Convert an object to a UTF-8 encoded string, either with JSON (if pretty == true and there is no JSON error) or with toSource(). More...
|
| |
| bool | ParseJSON (const Script::Request &rq, const std::string &string_utf8, JS::MutableHandleValue out) |
| | Parse a UTF-8-encoded JSON string. More...
|
| |
| void | ReadJSONFile (const Script::Request &rq, const VfsPath &path, JS::MutableHandleValue out) |
| | Read a JSON file. More...
|
| |
| std::string | StringifyJSON (const Script::Request &rq, JS::MutableHandleValue obj, bool indent=true) |
| | Stringify to a JSON string, UTF-8 encoded. More...
|
| |
| template<typename PropType > |
| bool | GetProperty (const Script::Request &rq, JS::HandleValue obj, PropType name, JS::MutableHandleValue out) |
| | Get the named property on the given object. More...
|
| |
| template<typename T , typename PropType > |
| bool | GetProperty (const Script::Request &rq, JS::HandleValue obj, PropType name, T &out) |
| |
| bool | GetProperty (const Script::Request &rq, JS::HandleValue obj, const char *name, JS::MutableHandleObject out) |
| |
| template<typename T > |
| bool | GetPropertyInt (const Script::Request &rq, JS::HandleValue obj, int name, T &out) |
| |
| bool | GetPropertyInt (const Script::Request &rq, JS::HandleValue obj, int name, JS::MutableHandleValue out) |
| |
| bool | HasProperty (const Script::Request &rq, JS::HandleValue obj, const char *name) |
| | Check the named property has been defined on the given object. More...
|
| |
| template<typename PropType > |
| bool | SetProperty (const Script::Request &rq, JS::HandleValue obj, PropType name, JS::HandleValue value, bool constant=false, bool enumerable=true) |
| | Set the named property on the given object. More...
|
| |
| template<typename T , typename PropType > |
| bool | SetProperty (const Script::Request &rq, JS::HandleValue obj, PropType name, const T &value, bool constant=false, bool enumerable=true) |
| |
| template<typename T > |
| bool | SetPropertyInt (const Script::Request &rq, JS::HandleValue obj, int name, const T &value, bool constant=false, bool enumerable=true) |
| |
| template<typename T > |
| bool | GetObjectClassName (const Script::Request &rq, JS::HandleObject obj, T &name) |
| |
| template<typename T > |
| bool | GetObjectClassName (const Script::Request &rq, JS::HandleValue val, T &name) |
| | Get the name of the object's class. More...
|
| |
| bool | DeepFreezeObject (const Script::Request &rq, JS::HandleValue objVal) |
| |
| bool | EnumeratePropertyNames (const Script::Request &rq, JS::HandleValue objVal, bool enumerableOnly, std::vector< std::string > &out) |
| | Returns all properties of the object, both own properties and inherited. More...
|
| |
| JS::Value | CreateObject (const Script::Request &rq) |
| | Create a plain object (i.e. More...
|
| |
| bool | CreateObject (const Script::Request &rq, JS::MutableHandleValue objectValue) |
| |
| template<typename T , typename... Args> |
| bool | CreateObject (const Script::Request &rq, JS::MutableHandleValue objectValue, const char *propertyName, const T &propertyValue, Args const &... args) |
| | Sets the given value to a new plain JS::Object, converts the arguments to JS::Values and sets them as properties. More...
|
| |
| void | UnhandledRejectedPromise (JSContext *cx, bool, JS::HandleObject promise, JS::PromiseRejectionHandlingState state, void *) |
| |
| StructuredClone | WriteStructuredClone (const Script::Request &rq, JS::HandleValue v) |
| |
| void | ReadStructuredClone (const Script::Request &rq, const StructuredClone &ptr, JS::MutableHandleValue ret) |
| |
| JS::Value | CloneValueFromOtherCompartment (const Script::Interface &to, const Script::Interface &from, JS::HandleValue val) |
| | Construct a new value by cloning a value (possibly from a different Compartment). More...
|
| |
| JS::Value | DeepCopy (const Script::Request &rq, JS::HandleValue val) |
| | Clone a JS value, ensuring that changes to the result won't affect the original value. More...
|
| |
Abstraction around a SpiderMonkey JSContext.
Spidermonkey maintains some 'local' state via the JSContext* object.
Wraps SM APIs for manipulating JS objects.
Abstraction around a SpiderMonkey JS::Realm.
This class introduces templates to conveniently wrap C++ functions in JSNative functions.
A class using the RAII (Resource Acquisition Is Initialization) idiom to manage initialization and shutdown of the SpiderMonkey script engine.
A single Script::Context, with the associated context, should only be used on a single thread.
(One means to share data between threads and contexts is to create a Script::StructuredClone.)
It also keeps a count of active script contexts in order to validate the following constraints:
- JS_Init must be called before any ScriptContexts are initialized
- JS_Shutdown must be called after all ScriptContexts have been destroyed
This is rather template heavy, so compilation times beware. The C++ code can have arbitrary arguments and arbitrary return types, so long as they can be converted to/from JS using ToJSVal (FromJSVal respectively), and they are default-constructible (TODO: that can probably changed). (This could be a namespace, but I like being able to specify public/private).
Thread-safety:
- May be used in non-main threads.
- Each Script::Interface must be created, used, and destroyed, all in a single thread (it must never be shared between threads).
This object is an argument to most JSAPI functions. Furthermore, this state is Realm (~ global) dependent. For many reasons, including GC safety, The JSContext* Realm must be set up correctly when accessing it. 'Entering' and 'Leaving' realms must be done in a LIFO manner. SM recommends using JSAutoRealm, which provides an RAII option.
Request combines both of the above in a single convenient package, providing safe access to the JSContext*, the global object, and ensuring that the proper realm has been entered. Most scriptinterface/ functions will take a Request, to ensure proper rooting. You may sometimes have to create one from a Interface.
Be particularly careful when manipulating several script interfaces.