@@ -158,8 +158,9 @@ Local<Value> V8Engine::eval(const Local<String>& script, const Local<Value>& sou
158
158
throw Exception (" can't eval script" );
159
159
}
160
160
v8::ScriptOrigin origin (
161
- #if SCRIPTX_V8_VERSION_GE(9 , 0)
161
+ #if SCRIPTX_V8_VERSION_BETWEEN(9, 0, 12 , 0)
162
162
// V8 9.0 add isolate param for external API
163
+ // V8 12.1 deprecated the isolate version, and introduced the one without isolation
163
164
isolate_,
164
165
#endif
165
166
sourceFile.isNull () || !sourceFile.isString () ? v8::Local<v8::String>()
@@ -180,17 +181,18 @@ Local<Value> V8Engine::eval(const Local<String>& script) { return eval(script, {
180
181
void V8Engine::registerNativeClassStatic (v8::Local<v8::FunctionTemplate> funcT,
181
182
const internal::StaticDefine* staticDefine) {
182
183
for (auto & prop : staticDefine->properties ) {
184
+ using PropDefPtr = internal::StaticDefine::PropertyDefine*;
185
+
183
186
StackFrameScope stack;
184
187
auto name = String::newString (prop.name );
185
188
186
- v8::AccessorGetterCallback getter = nullptr ;
187
- v8::AccessorSetterCallback setter = nullptr ;
189
+ v8::AccessorNameGetterCallback getter = nullptr ;
190
+ v8::AccessorNameSetterCallback setter = nullptr ;
188
191
189
192
if (prop.getter ) {
190
- getter = [](v8::Local<v8::String > /* property*/ ,
193
+ getter = [](v8::Local<v8::Name > /* property*/ ,
191
194
const v8::PropertyCallbackInfo<v8::Value>& info) {
192
- auto ptr = static_cast <internal::StaticDefine::PropertyDefine*>(
193
- info.Data ().As <v8::External>()->Value ());
195
+ auto ptr = static_cast <PropDefPtr>(info.Data ().As <v8::External>()->Value ());
194
196
Tracer trace (EngineScope::currentEngine (), ptr->traceName );
195
197
Local<Value> ret = ptr->getter ();
196
198
try {
@@ -202,10 +204,9 @@ void V8Engine::registerNativeClassStatic(v8::Local<v8::FunctionTemplate> funcT,
202
204
}
203
205
204
206
if (prop.setter ) {
205
- setter = [](v8::Local<v8::String > /* property*/ , v8::Local<v8::Value> value,
207
+ setter = [](v8::Local<v8::Name > /* property*/ , v8::Local<v8::Value> value,
206
208
const v8::PropertyCallbackInfo<void >& info) {
207
- auto ptr = static_cast <internal::StaticDefine::PropertyDefine*>(
208
- info.Data ().As <v8::External>()->Value ());
209
+ auto ptr = static_cast <PropDefPtr>(info.Data ().As <v8::External>()->Value ());
209
210
Tracer trace (EngineScope::currentEngine (), ptr->traceName );
210
211
try {
211
212
ptr->setter (make<Local<Value>>(value));
@@ -216,25 +217,26 @@ void V8Engine::registerNativeClassStatic(v8::Local<v8::FunctionTemplate> funcT,
216
217
} else {
217
218
// v8 requires setter to be present, otherwise, a real js set code with create a new
218
219
// property...
219
- setter = [](v8::Local<v8::String > property, v8::Local<v8::Value> value,
220
+ setter = [](v8::Local<v8::Name > property, v8::Local<v8::Value> value,
220
221
const v8::PropertyCallbackInfo<void >& info) {};
221
222
}
222
223
223
- funcT-> SetNativeDataProperty (
224
- toV8 (isolate_, name), getter, setter,
225
- v8::External::New (isolate_, const_cast <internal::StaticDefine::PropertyDefine* >(&prop)),
226
- v8::PropertyAttribute::DontDelete);
224
+ // SetNativeDataProperty with Local<String> and AccessControl is deprecated
225
+ funcT-> SetNativeDataProperty (v8::Local<v8::Name>:: Cast ( toV8 (isolate_, name) ), getter, setter,
226
+ v8::External::New (isolate_, const_cast <PropDefPtr >(&prop)),
227
+ v8::PropertyAttribute::DontDelete);
227
228
}
228
229
229
230
for (auto & func : staticDefine->functions ) {
231
+ using FuncDefPtr = internal::StaticDefine::FunctionDefine*;
232
+
230
233
StackFrameScope stack;
231
234
auto name = String::newString (func.name );
232
235
233
236
auto fn = v8::FunctionTemplate::New (
234
237
isolate_,
235
238
[](const v8::FunctionCallbackInfo<v8::Value>& info) {
236
- auto funcDef = reinterpret_cast <internal::StaticDefine::FunctionDefine*>(
237
- info.Data ().As <v8::External>()->Value ());
239
+ auto funcDef = reinterpret_cast <FuncDefPtr>(info.Data ().As <v8::External>()->Value ());
238
240
auto engine = v8_backend::currentEngine ();
239
241
Tracer trace (engine, funcDef->traceName );
240
242
@@ -245,8 +247,8 @@ void V8Engine::registerNativeClassStatic(v8::Local<v8::FunctionTemplate> funcT,
245
247
v8_backend::rethrowException (e);
246
248
}
247
249
},
248
- v8::External::New (isolate_, const_cast <internal::StaticDefine::FunctionDefine* >(&func)), {},
249
- 0 , v8::ConstructorBehavior::kThrow );
250
+ v8::External::New (isolate_, const_cast <FuncDefPtr >(&func)), {}, 0 ,
251
+ v8::ConstructorBehavior::kThrow );
250
252
if (!fn.IsEmpty ()) {
251
253
funcT->Set (toV8 (isolate_, name), fn, v8::PropertyAttribute::DontDelete);
252
254
} else {
@@ -453,67 +455,67 @@ void V8Engine::registerNativeClassInstance(v8::Local<v8::FunctionTemplate> funcT
453
455
// instance
454
456
auto instanceT = funcT->PrototypeTemplate ();
455
457
auto signature = v8::Signature::New (isolate_, funcT);
458
+
456
459
for (auto & prop : classDefine->instanceDefine .properties ) {
460
+ // Template::SetAccessor is removed in 12.8
461
+ // using Template::SetAccessorProperty is recommended
462
+
463
+ using PropDefPtr = typename internal::InstanceDefine::PropertyDefine*;
457
464
StackFrameScope stack;
458
465
auto name = String::newString (prop.name );
459
-
460
- v8::AccessorGetterCallback getter = nullptr ;
461
- v8::AccessorSetterCallback setter = nullptr ;
466
+ auto data = v8::External::New (isolate_, const_cast <PropDefPtr>(&prop));
467
+ v8::Local<v8::FunctionTemplate> getter;
468
+ v8::Local<v8::FunctionTemplate> setter;
462
469
463
470
if (prop.getter ) {
464
- getter = [](v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& info) {
465
- auto ptr = static_cast <decltype (&prop)>(info.Data ().As <v8::External>()->Value ());
466
- auto thiz = static_cast <void *>(info.This ()->GetAlignedPointerFromInternalField (
467
- kInstanceObjectAlignedPointer_PolymorphicPointer ));
468
- auto scriptClass =
469
- static_cast <ScriptClass*>(info.This ()->GetAlignedPointerFromInternalField (
470
- kInstanceObjectAlignedPointer_ScriptClass ));
471
- auto & getter = ptr->getter ;
472
-
473
- Tracer trace (scriptClass->getScriptEngine (), ptr->traceName );
474
-
475
- Local<Value> ret = (getter)(thiz);
476
- try {
477
- info.GetReturnValue ().Set (toV8 (info.GetIsolate (), ret));
478
- } catch (const Exception& e) {
479
- v8_backend::rethrowException (e);
480
- }
481
- };
471
+ getter = v8::FunctionTemplate::New (
472
+ isolate_,
473
+ [](const v8::FunctionCallbackInfo<v8::Value>& info) {
474
+ auto ptr = static_cast <PropDefPtr>(info.Data ().As <v8::External>()->Value ());
475
+ auto thiz = static_cast <void *>(info.This ()->GetAlignedPointerFromInternalField (
476
+ kInstanceObjectAlignedPointer_PolymorphicPointer ));
477
+ auto scriptClass =
478
+ static_cast <ScriptClass*>(info.This ()->GetAlignedPointerFromInternalField (
479
+ kInstanceObjectAlignedPointer_ScriptClass ));
480
+ auto & getter = ptr->getter ;
481
+
482
+ Tracer trace (scriptClass->getScriptEngine (), ptr->traceName );
483
+
484
+ Local<Value> ret = (getter)(thiz);
485
+ try {
486
+ info.GetReturnValue ().Set (toV8 (info.GetIsolate (), ret));
487
+ } catch (const Exception& e) {
488
+ v8_backend::rethrowException (e);
489
+ }
490
+ },
491
+ data, signature);
482
492
}
483
493
484
494
if (prop.setter ) {
485
- setter = [](v8::Local<v8::String> property, v8::Local<v8::Value> value,
486
- const v8::PropertyCallbackInfo<void >& info) {
487
- auto ptr = static_cast <decltype (&prop)>(info.Data ().As <v8::External>()->Value ());
488
- auto thiz = static_cast <void *>(info.This ()->GetAlignedPointerFromInternalField (
489
- kInstanceObjectAlignedPointer_PolymorphicPointer ));
490
- auto scriptClass =
491
- static_cast <ScriptClass*>(info.This ()->GetAlignedPointerFromInternalField (
492
- kInstanceObjectAlignedPointer_ScriptClass ));
493
- auto & setter = ptr->setter ;
494
-
495
- Tracer trace (scriptClass->getScriptEngine (), ptr->traceName );
496
-
497
- try {
498
- (setter)(thiz, make<Local<Value>>(value));
499
- } catch (const Exception& e) {
500
- v8_backend::rethrowException (e);
501
- }
502
- };
495
+ setter = v8::FunctionTemplate::New (
496
+ isolate_,
497
+ [](const v8::FunctionCallbackInfo<v8::Value>& info) {
498
+ auto ptr = static_cast <PropDefPtr>(info.Data ().As <v8::External>()->Value ());
499
+ auto thiz = static_cast <void *>(info.This ()->GetAlignedPointerFromInternalField (
500
+ kInstanceObjectAlignedPointer_PolymorphicPointer ));
501
+ auto scriptClass =
502
+ static_cast <ScriptClass*>(info.This ()->GetAlignedPointerFromInternalField (
503
+ kInstanceObjectAlignedPointer_ScriptClass ));
504
+ auto & setter = ptr->setter ;
505
+
506
+ Tracer trace (scriptClass->getScriptEngine (), ptr->traceName );
507
+
508
+ try {
509
+ (setter)(thiz, make<Local<Value>>(info[0 ]));
510
+ } catch (const Exception& e) {
511
+ v8_backend::rethrowException (e);
512
+ }
513
+ },
514
+ data, signature);
503
515
}
504
516
505
- auto v8Name = toV8 (isolate_, name);
506
- auto data = v8::External::New (
507
- isolate_, const_cast <typename internal::InstanceDefine::PropertyDefine*>(&prop));
508
-
509
- #if SCRIPTX_V8_VERSION_LE(10, 1) // SetAccessor AccessorSignature deprecated in 10.2 a8beac
510
- auto accessSignature = v8::AccessorSignature::New (isolate_, funcT);
511
- instanceT->SetAccessor (v8Name, getter, setter, data, v8::AccessControl::DEFAULT,
512
- v8::PropertyAttribute::DontDelete, accessSignature);
513
- #else
514
- instanceT->SetAccessor (v8Name, getter, setter, data, v8::AccessControl::DEFAULT,
515
- v8::PropertyAttribute::DontDelete);
516
- #endif
517
+ instanceT->SetAccessorProperty (v8::Local<v8::Name>::Cast (toV8 (isolate_, name)), getter, setter,
518
+ v8::PropertyAttribute::DontDelete);
517
519
}
518
520
519
521
for (auto & func : classDefine->instanceDefine .functions ) {
@@ -541,7 +543,7 @@ void V8Engine::registerNativeClassInstance(v8::Local<v8::FunctionTemplate> funcT
541
543
},
542
544
v8::External::New (isolate_, const_cast <FuncDefPtr>(&func)), signature);
543
545
if (!fn.IsEmpty ()) {
544
- funcT-> PrototypeTemplate () ->Set (toV8 (isolate_, name), fn, v8::PropertyAttribute::DontDelete);
546
+ instanceT ->Set (toV8 (isolate_, name), fn, v8::PropertyAttribute::DontDelete);
545
547
} else {
546
548
throw Exception (" can't create function for instance" );
547
549
}
0 commit comments