@@ -290,18 +290,6 @@ BaseObjectPtr<ContextifyContext> ContextifyContext::New(
290
290
Local<Object> wrapper;
291
291
{
292
292
Context::Scope context_scope (v8_context);
293
- Local<String> ctor_name = sandbox_obj->GetConstructorName ();
294
- if (!ctor_name->Equals (v8_context, env->object_string ()).FromMaybe (false ) &&
295
- new_context_global
296
- ->DefineOwnProperty (
297
- v8_context,
298
- v8::Symbol::GetToStringTag (env->isolate ()),
299
- ctor_name,
300
- static_cast <v8::PropertyAttribute>(v8::DontEnum))
301
- .IsNothing ()) {
302
- return BaseObjectPtr<ContextifyContext>();
303
- }
304
-
305
293
// Assign host_defined_options_id to the global object so that in the
306
294
// callback of ImportModuleDynamically, we can get the
307
295
// host_defined_options_id from the v8::Context without accessing the
@@ -742,19 +730,25 @@ Intercepted ContextifyContext::PropertyDeleterCallback(
742
730
// static
743
731
void ContextifyContext::PropertyEnumeratorCallback (
744
732
const PropertyCallbackInfo<Array>& args) {
733
+ // Named enumerator will be invoked on Object.keys,
734
+ // Object.getOwnPropertyNames, Object.getOwnPropertySymbols,
735
+ // Object.getOwnPropertyDescriptors, for...in, etc. operations.
736
+ // Named enumerator should return all own non-indices property names,
737
+ // including string properties and symbol properties. V8 will filter the
738
+ // result array to match the expected symbol-only, enumerable-only with
739
+ // NamedPropertyQueryCallback.
745
740
ContextifyContext* ctx = ContextifyContext::Get (args);
746
741
747
742
// Still initializing
748
743
if (IsStillInitializing (ctx)) return ;
749
744
750
745
Local<Array> properties;
751
- // Only get named properties, exclude symbols and indices.
746
+ // Only get own named properties, exclude indices.
752
747
if (!ctx->sandbox ()
753
748
->GetPropertyNames (
754
749
ctx->context (),
755
- KeyCollectionMode::kIncludePrototypes ,
756
- static_cast <PropertyFilter>(PropertyFilter::ONLY_ENUMERABLE |
757
- PropertyFilter::SKIP_SYMBOLS),
750
+ KeyCollectionMode::kOwnOnly ,
751
+ static_cast <PropertyFilter>(PropertyFilter::ALL_PROPERTIES),
758
752
IndexFilter::kSkipIndices )
759
753
.ToLocal (&properties))
760
754
return ;
@@ -765,6 +759,12 @@ void ContextifyContext::PropertyEnumeratorCallback(
765
759
// static
766
760
void ContextifyContext::IndexedPropertyEnumeratorCallback (
767
761
const PropertyCallbackInfo<Array>& args) {
762
+ // Indexed enumerator will be invoked on Object.keys,
763
+ // Object.getOwnPropertyNames, Object.getOwnPropertyDescriptors, for...in,
764
+ // etc. operations. Indexed enumerator should return all own non-indices index
765
+ // properties. V8 will filter the result array to match the expected
766
+ // enumerable-only with IndexedPropertyQueryCallback.
767
+
768
768
Isolate* isolate = args.GetIsolate ();
769
769
HandleScope scope (isolate);
770
770
ContextifyContext* ctx = ContextifyContext::Get (args);
@@ -775,9 +775,15 @@ void ContextifyContext::IndexedPropertyEnumeratorCallback(
775
775
776
776
Local<Array> properties;
777
777
778
- // By default, GetPropertyNames returns string and number property names, and
779
- // doesn't convert the numbers to strings.
780
- if (!ctx->sandbox ()->GetPropertyNames (context).ToLocal (&properties)) return ;
778
+ // Only get own index properties.
779
+ if (!ctx->sandbox ()
780
+ ->GetPropertyNames (
781
+ context,
782
+ KeyCollectionMode::kOwnOnly ,
783
+ static_cast <PropertyFilter>(PropertyFilter::SKIP_SYMBOLS),
784
+ IndexFilter::kIncludeIndices )
785
+ .ToLocal (&properties))
786
+ return ;
781
787
782
788
std::vector<v8::Global<Value>> properties_vec;
783
789
if (FromV8Array (context, properties, &properties_vec).IsNothing ()) {
0 commit comments