@@ -26,6 +26,9 @@ using v8::HandleScope;
26
26
using v8::Integer;
27
27
using v8::Isolate;
28
28
using v8::Local;
29
+ using v8::MaybeLocal;
30
+ using v8::Name;
31
+ using v8::NamedPropertyHandlerConfiguration;
29
32
using v8::None;
30
33
using v8::Object;
31
34
using v8::ObjectTemplate;
@@ -202,12 +205,14 @@ class ContextifyContext {
202
205
203
206
Local<ObjectTemplate> object_template =
204
207
function_template->InstanceTemplate ();
205
- object_template->SetNamedPropertyHandler (GlobalPropertyGetterCallback,
208
+
209
+ NamedPropertyHandlerConfiguration config (GlobalPropertyGetterCallback,
206
210
GlobalPropertySetterCallback,
207
211
GlobalPropertyQueryCallback,
208
212
GlobalPropertyDeleterCallback,
209
213
GlobalPropertyEnumeratorCallback,
210
214
CreateDataWrapper (env));
215
+ object_template->SetHandler (config);
211
216
212
217
Local<Context> ctx = Context::New (env->isolate (), nullptr , object_template);
213
218
if (!ctx.IsEmpty ())
@@ -342,7 +347,7 @@ class ContextifyContext {
342
347
343
348
344
349
static void GlobalPropertyGetterCallback (
345
- Local<String > property,
350
+ Local<Name > property,
346
351
const PropertyCallbackInfo<Value>& args) {
347
352
Isolate* isolate = args.GetIsolate ();
348
353
HandleScope scope (isolate);
@@ -351,22 +356,27 @@ class ContextifyContext {
351
356
Unwrap<ContextifyContext>(args.Data ().As <Object>());
352
357
353
358
Local<Object> sandbox = PersistentToLocal (isolate, ctx->sandbox_ );
354
- Local<Value> rv = sandbox->GetRealNamedProperty (property);
359
+ MaybeLocal<Value> rv =
360
+ sandbox->GetRealNamedProperty (ctx->context (), property);
355
361
if (rv.IsEmpty ()) {
356
362
Local<Object> proxy_global = PersistentToLocal (isolate,
357
363
ctx->proxy_global_ );
358
- rv = proxy_global->GetRealNamedProperty (property);
359
- }
360
- if (!rv.IsEmpty () && rv == ctx->sandbox_ ) {
361
- rv = PersistentToLocal (isolate, ctx->proxy_global_ );
364
+ rv = proxy_global->GetRealNamedProperty (ctx->context (), property);
362
365
}
363
366
364
- args.GetReturnValue ().Set (rv);
367
+ Local<Value> localRV;
368
+ if (rv.ToLocal (&localRV)) {
369
+ if (localRV == ctx->sandbox_ ) {
370
+ localRV = PersistentToLocal (isolate, ctx->proxy_global_ );
371
+ }
372
+
373
+ args.GetReturnValue ().Set (localRV);
374
+ }
365
375
}
366
376
367
377
368
378
static void GlobalPropertySetterCallback (
369
- Local<String > property,
379
+ Local<Name > property,
370
380
Local<Value> value,
371
381
const PropertyCallbackInfo<Value>& args) {
372
382
Isolate* isolate = args.GetIsolate ();
@@ -380,7 +390,7 @@ class ContextifyContext {
380
390
381
391
382
392
static void GlobalPropertyQueryCallback (
383
- Local<String > property,
393
+ Local<Name > property,
384
394
const PropertyCallbackInfo<Integer>& args) {
385
395
Isolate* isolate = args.GetIsolate ();
386
396
HandleScope scope (isolate);
@@ -392,31 +402,43 @@ class ContextifyContext {
392
402
Local<Object> proxy_global = PersistentToLocal (isolate,
393
403
ctx->proxy_global_ );
394
404
395
- if (sandbox->HasRealNamedProperty (property)) {
396
- PropertyAttribute propAttr =
397
- sandbox->GetRealNamedPropertyAttributes (property).FromJust ();
398
- args.GetReturnValue ().Set (propAttr);
399
- } else if (proxy_global->HasRealNamedProperty (property)) {
405
+ bool in_sandbox =
406
+ sandbox->HasRealNamedProperty (ctx->context (), property).FromMaybe (false );
407
+
408
+ if (in_sandbox) {
400
409
PropertyAttribute propAttr =
401
- proxy_global->GetRealNamedPropertyAttributes (property).FromJust ();
410
+ sandbox->
411
+ GetRealNamedPropertyAttributes (ctx->context (), property).FromJust ();
402
412
args.GetReturnValue ().Set (propAttr);
403
413
} else {
404
- args.GetReturnValue ().Set (None);
414
+ bool in_proxy_global =
415
+ proxy_global->HasRealNamedProperty (ctx->context (), property)
416
+ .FromMaybe (false );
417
+ if (in_proxy_global) {
418
+ PropertyAttribute propAttr =
419
+ proxy_global->
420
+ GetRealNamedPropertyAttributes (ctx->context (), property)
421
+ .FromJust ();
422
+ args.GetReturnValue ().Set (propAttr);
423
+ }
424
+ else {
425
+ args.GetReturnValue ().Set (None);
426
+ }
405
427
}
406
428
}
407
429
408
430
409
431
static void GlobalPropertyDeleterCallback (
410
- Local<String > property,
432
+ Local<Name > property,
411
433
const PropertyCallbackInfo<Boolean >& args) {
412
434
Isolate* isolate = args.GetIsolate ();
413
435
HandleScope scope (isolate);
414
436
415
437
ContextifyContext* ctx =
416
438
Unwrap<ContextifyContext>(args.Data ().As <Object>());
439
+ Local<Object> sandbox = PersistentToLocal (isolate, ctx->sandbox_ );
417
440
418
- bool success = PersistentToLocal (isolate,
419
- ctx->sandbox_ )->Delete (property);
441
+ bool success = sandbox->Delete (ctx->context (), property).FromMaybe (false );
420
442
args.GetReturnValue ().Set (success);
421
443
}
422
444
0 commit comments