Lib/javascript/v8: use context-aware initialization.
Context-aware initialization allows to instantiate add-ons multiple times, most importantly in multiple Workers' contexts. Workers made first appearance in v10.5. Context-aware initialization was option earlier than that, even before supported minimum v6.x, yet condition is chosen more conservatively as NODE_MODULE_VERSION >= 64, a.k.a. v10.0.
This commit is contained in:
parent
0215eaa344
commit
b0c01ea851
4 changed files with 35 additions and 26 deletions
|
|
@ -61,11 +61,11 @@ SWIGRUNTIME void SWIGV8_AddMemberVariable(SWIGV8_FUNCTION_TEMPLATE class_templ,
|
|||
* Registers a class method with given name for a given object.
|
||||
*/
|
||||
SWIGRUNTIME void SWIGV8_AddStaticFunction(SWIGV8_OBJECT obj, const char* symbol,
|
||||
const SwigV8FunctionCallback& _func) {
|
||||
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903) || (SWIG_V8_VERSION < 0x0704)
|
||||
const SwigV8FunctionCallback& _func, v8::Local<v8::Context> context) {
|
||||
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903)
|
||||
obj->Set(SWIGV8_SYMBOL_NEW(symbol), SWIGV8_FUNCTEMPLATE_NEW(_func)->GetFunction());
|
||||
#else
|
||||
SWIGV8_MAYBE_CHECK(obj->Set(SWIGV8_CURRENT_CONTEXT(), SWIGV8_SYMBOL_NEW(symbol), SWIGV8_FUNCTEMPLATE_NEW(_func)->GetFunction(SWIGV8_CURRENT_CONTEXT()).ToLocalChecked()));
|
||||
SWIGV8_MAYBE_CHECK(obj->Set(context, SWIGV8_SYMBOL_NEW(symbol), SWIGV8_FUNCTEMPLATE_NEW(_func)->GetFunction(context).ToLocalChecked()));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
@ -73,11 +73,12 @@ SWIGRUNTIME void SWIGV8_AddStaticFunction(SWIGV8_OBJECT obj, const char* symbol,
|
|||
* Registers a class method with given name for a given object.
|
||||
*/
|
||||
SWIGRUNTIME void SWIGV8_AddStaticVariable(SWIGV8_OBJECT obj, const char* symbol,
|
||||
SwigV8AccessorGetterCallback getter, SwigV8AccessorSetterCallback setter) {
|
||||
SwigV8AccessorGetterCallback getter, SwigV8AccessorSetterCallback setter,
|
||||
v8::Local<v8::Context> context) {
|
||||
#if (V8_MAJOR_VERSION-0) < 5
|
||||
obj->SetAccessor(SWIGV8_SYMBOL_NEW(symbol), getter, setter);
|
||||
#else
|
||||
SWIGV8_MAYBE_CHECK(obj->SetAccessor(SWIGV8_CURRENT_CONTEXT(), SWIGV8_SYMBOL_NEW(symbol), getter, setter));
|
||||
SWIGV8_MAYBE_CHECK(obj->SetAccessor(context, SWIGV8_SYMBOL_NEW(symbol), getter, setter));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue