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