From 3f96e5a29a88afafcef0f17458b2800b2db316ee Mon Sep 17 00:00:00 2001 From: ud2 Date: Fri, 8 Dec 2023 00:04:44 +0800 Subject: [PATCH] fix(ext/node): include non-enumerable keys in `Reflect.ownKeys(globalThis)` (#21485) Closes #21484. --- cli/tests/testdata/npm/compare_globals/main.out | 1 + cli/tests/testdata/npm/compare_globals/main.ts | 2 ++ ext/node/global.rs | 11 ++++++++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/cli/tests/testdata/npm/compare_globals/main.out b/cli/tests/testdata/npm/compare_globals/main.out index 31fcedda3d..0e366fae75 100644 --- a/cli/tests/testdata/npm/compare_globals/main.out +++ b/cli/tests/testdata/npm/compare_globals/main.out @@ -25,3 +25,4 @@ false false bar bar +true diff --git a/cli/tests/testdata/npm/compare_globals/main.ts b/cli/tests/testdata/npm/compare_globals/main.ts index 8d3ae1ea03..6f7b9ef8e8 100644 --- a/cli/tests/testdata/npm/compare_globals/main.ts +++ b/cli/tests/testdata/npm/compare_globals/main.ts @@ -48,3 +48,5 @@ globals.checkWindowGlobal(); (globalThis as any).foo = "bar"; console.log((globalThis as any).foo); console.log(globals.getFoo()); + +console.log(Reflect.ownKeys(globalThis).includes("console")); // non-enumerable keys are included diff --git a/ext/node/global.rs b/ext/node/global.rs index fd2f5a7cb3..994155359c 100644 --- a/ext/node/global.rs +++ b/ext/node/global.rs @@ -432,9 +432,14 @@ pub fn enumerator<'s>( }; let inner = v8::Local::new(scope, inner); - let Some(array) = - inner.get_property_names(scope, GetPropertyNamesArgs::default()) - else { + let Some(array) = inner.get_property_names( + scope, + GetPropertyNamesArgs { + mode: v8::KeyCollectionMode::OwnOnly, + property_filter: v8::PropertyFilter::ALL_PROPERTIES, + ..Default::default() + }, + ) else { return; };