@@ -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,30 +348,34 @@ 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
349
355
ContextifyContext* ctx =
350
356
Unwrap<ContextifyContext>(args.Data ().As <Object>());
351
357
352
358
Local<Object> sandbox = PersistentToLocal (isolate, ctx->sandbox_ );
353
- Local<Value> rv = sandbox->GetRealNamedProperty (property);
354
- if (rv.IsEmpty ()) {
359
+ MaybeLocal<Value> maybe_rv =
360
+ sandbox->GetRealNamedProperty (ctx->context (), property);
361
+ if (maybe_rv.IsEmpty ()) {
355
362
Local<Object> proxy_global = PersistentToLocal (isolate,
356
363
ctx->proxy_global_ );
357
- rv = proxy_global->GetRealNamedProperty (property);
358
- }
359
- if (!rv.IsEmpty () && rv == ctx->sandbox_ ) {
360
- rv = PersistentToLocal (isolate, ctx->proxy_global_ );
364
+ maybe_rv = proxy_global->GetRealNamedProperty (ctx->context (), property);
361
365
}
362
366
363
- args.GetReturnValue ().Set (rv);
367
+ Local<Value> rv;
368
+ if (maybe_rv.ToLocal (&rv)) {
369
+ if (rv == ctx->sandbox_ )
370
+ rv = PersistentToLocal (isolate, ctx->proxy_global_ );
371
+
372
+ args.GetReturnValue ().Set (rv);
373
+ }
364
374
}
365
375
366
376
367
377
static void GlobalPropertySetterCallback (
368
- Local<String > property,
378
+ Local<Name > property,
369
379
Local<Value> value,
370
380
const PropertyCallbackInfo<Value>& args) {
371
381
Isolate* isolate = args.GetIsolate ();
@@ -378,42 +388,46 @@ class ContextifyContext {
378
388
379
389
380
390
static void GlobalPropertyQueryCallback (
381
- Local<String > property,
391
+ Local<Name > property,
382
392
const PropertyCallbackInfo<Integer>& args) {
383
393
Isolate* isolate = args.GetIsolate ();
384
394
385
395
ContextifyContext* ctx =
386
396
Unwrap<ContextifyContext>(args.Data ().As <Object>());
387
397
388
398
Local<Object> sandbox = PersistentToLocal (isolate, ctx->sandbox_ );
389
- Local<Object> proxy_global = PersistentToLocal (isolate,
390
- ctx->proxy_global_ );
391
-
392
- if (sandbox->HasRealNamedProperty (property)) {
393
- PropertyAttribute propAttr =
394
- sandbox->GetRealNamedPropertyAttributes (property).FromJust ();
395
- args.GetReturnValue ().Set (propAttr);
396
- } else if (proxy_global->HasRealNamedProperty (property)) {
397
- PropertyAttribute propAttr =
398
- proxy_global->GetRealNamedPropertyAttributes (property).FromJust ();
399
- args.GetReturnValue ().Set (propAttr);
400
- } else {
401
- args.GetReturnValue ().Set (None);
399
+ Maybe<PropertyAttribute> maybe_prop_attr =
400
+ sandbox->GetRealNamedPropertyAttributes (ctx->context (), property);
401
+
402
+ if (maybe_prop_attr.IsNothing ()) {
403
+ Local<Object> proxy_global = PersistentToLocal (isolate,
404
+ ctx->proxy_global_ );
405
+
406
+ maybe_prop_attr =
407
+ proxy_global->GetRealNamedPropertyAttributes (ctx->context (),
408
+ property);
409
+ }
410
+
411
+ if (maybe_prop_attr.IsJust ()) {
412
+ PropertyAttribute prop_attr = maybe_prop_attr.FromJust ();
413
+ args.GetReturnValue ().Set (prop_attr);
402
414
}
403
415
}
404
416
405
417
406
418
static void GlobalPropertyDeleterCallback (
407
- Local<String > property,
419
+ Local<Name > property,
408
420
const PropertyCallbackInfo<Boolean >& args) {
409
421
Isolate* isolate = args.GetIsolate ();
410
422
411
423
ContextifyContext* ctx =
412
424
Unwrap<ContextifyContext>(args.Data ().As <Object>());
425
+ Local<Object> sandbox = PersistentToLocal (isolate, ctx->sandbox_ );
426
+
427
+ Maybe<bool > success = sandbox->Delete (ctx->context (), property);
413
428
414
- bool success = PersistentToLocal (isolate,
415
- ctx->sandbox_ )->Delete (property);
416
- args.GetReturnValue ().Set (success);
429
+ if (success.IsJust ())
430
+ args.GetReturnValue ().Set (success.FromJust ());
417
431
}
418
432
419
433
0 commit comments