Skip to content

Conversation

@legendecas
Copy link
Member

@legendecaslegendecas commented Aug 23, 2024

Property enumerator methods like Object.getOwnPropertyNames,
Object.getOwnPropertySymbols, and Object.keys all invokes the
named property enumerator interceptor. V8 will filter the result based
on the invoked enumerator variant. Fix the enumerator interceptor to
return all potential properties.

Refs: jsdom/jsdom#3688

/cc @nodejs/vm

@nodejs-github-botnodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. vm Issues and PRs related to the vm subsystem. labels Aug 23, 2024
@joyeecheung
Copy link
Member

globalThis[Symbol.toStringTag] was unconditionally initialized
to the sandbox's constructor name, even if it is not present on the
sandbox object.

The original behavior was something like this:

function_template->SetClassName(sandbox->GetConstructorName());

When we still used a function template's instance template for the global object template. The [Symbol.toStringTag] setting was used to make it look the same while allowing different vm contexts to use different global object templates, so that contexts can share a snapshot. I am not sure how necessary it is to ensure that the globalThis in the new context has the same name as the sandbox's constructor, though. Maybe another alternative is to return something specific for this in the getter/setter/definer interceptors?

@codecov
Copy link

codecovbot commented Aug 23, 2024

Codecov Report

Attention: Patch coverage is 87.50000% with 1 line in your changes missing coverage. Please review.

Project coverage is 87.31%. Comparing base (cc26951) to head (acf009b).
Report is 354 commits behind head on main.

Files with missing linesPatch %Lines
src/node_contextify.cc87.50%1 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #54522 +/- ## ========================================== - Coverage 87.34% 87.31% -0.03%  ========================================== Files 649 649 Lines 182544 182759 +215 Branches 35030 35048 +18 ========================================== + Hits 159445 159579 +134 - Misses 16372 16459 +87 + Partials 6727 6721 -6 
Files with missing linesCoverage Δ
src/node_contextify.cc80.73% <87.50%> (+0.10%)⬆️

... and 72 files with indirect coverage changes

@legendecas
Copy link
MemberAuthor

@joyeecheungFunctionTemplate::SetClassName does not set up @@ToStringTag automatically. AFAICT, it is used as the function name and template uniqueness check.

On v18.8.0 where #44252 was not backported, the @@ToStringTag is not installed on the vm globalThis.

@joyeecheung
Copy link
Member

joyeecheung commented Aug 28, 2024

Yes, hence it was just done to keep it “look the same as before” (which matters when it gets logged by the console, etc. I don’t know how important it is though, maybe it’s fine to break the display name)

Property enumerator methods like `Object.getOwnPropertyNames`, `Object.getOwnPropertySymbols`, and `Object.keys` all invokes the named property enumerator interceptor. V8 will filter the result based on the invoked enumerator variant. Fix the enumerator interceptor to return all potential properties.
@legendecas
Copy link
MemberAuthor

I left @@toStringTag untouched being an exception as is. The breaking behavior can be a separate PR. This PR still fix inconsistency on Object.getOwnPropertyNames, Object.getOwnPropertySymbols, and Object.keys.

@nodejs/vm @joyeecheung please take a look again, thanks!

@joyeecheungjoyeecheung added the request-ci Add this label to start a Jenkins CI on a PR. label Aug 29, 2024
@github-actionsgithub-actionsbot removed the request-ci Add this label to start a Jenkins CI on a PR. label Aug 29, 2024
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@legendecaslegendecas added the commit-queue Add this label to land a pull request using GitHub Actions. label Aug 30, 2024
@nodejs-github-botnodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Aug 30, 2024
@nodejs-github-botnodejs-github-bot merged commit d2479fa into nodejs:mainAug 30, 2024
@nodejs-github-bot
Copy link
Collaborator

Landed in d2479fa

@legendecaslegendecas deleted the vm/property-enum branch August 30, 2024 11:23
RafaelGSS pushed a commit that referenced this pull request Aug 30, 2024
Property enumerator methods like `Object.getOwnPropertyNames`, `Object.getOwnPropertySymbols`, and `Object.keys` all invokes the named property enumerator interceptor. V8 will filter the result based on the invoked enumerator variant. Fix the enumerator interceptor to return all potential properties. PR-URL: #54522 Refs: jsdom/jsdom#3688 Reviewed-By: Joyee Cheung <[email protected]>
RafaelGSS pushed a commit that referenced this pull request Aug 30, 2024
Property enumerator methods like `Object.getOwnPropertyNames`, `Object.getOwnPropertySymbols`, and `Object.keys` all invokes the named property enumerator interceptor. V8 will filter the result based on the invoked enumerator variant. Fix the enumerator interceptor to return all potential properties. PR-URL: #54522 Refs: jsdom/jsdom#3688 Reviewed-By: Joyee Cheung <[email protected]>
RafaelGSS pushed a commit that referenced this pull request Aug 30, 2024
Property enumerator methods like `Object.getOwnPropertyNames`, `Object.getOwnPropertySymbols`, and `Object.keys` all invokes the named property enumerator interceptor. V8 will filter the result based on the invoked enumerator variant. Fix the enumerator interceptor to return all potential properties. PR-URL: #54522 Refs: jsdom/jsdom#3688 Reviewed-By: Joyee Cheung <[email protected]>
@RafaelGSSRafaelGSS mentioned this pull request Aug 30, 2024
sendoru pushed a commit to sendoru/node that referenced this pull request Sep 1, 2024
Property enumerator methods like `Object.getOwnPropertyNames`, `Object.getOwnPropertySymbols`, and `Object.keys` all invokes the named property enumerator interceptor. V8 will filter the result based on the invoked enumerator variant. Fix the enumerator interceptor to return all potential properties. PR-URL: nodejs#54522 Refs: jsdom/jsdom#3688 Reviewed-By: Joyee Cheung <[email protected]>
RafaelGSS pushed a commit that referenced this pull request Sep 1, 2024
Property enumerator methods like `Object.getOwnPropertyNames`, `Object.getOwnPropertySymbols`, and `Object.keys` all invokes the named property enumerator interceptor. V8 will filter the result based on the invoked enumerator variant. Fix the enumerator interceptor to return all potential properties. PR-URL: #54522 Refs: jsdom/jsdom#3688 Reviewed-By: Joyee Cheung <[email protected]>
@targostargos added the dont-land-on-v20.x PRs that should not land on the v20.x-staging branch and should not be released in v20.x. label Sep 22, 2024
louwers pushed a commit to louwers/node that referenced this pull request Nov 2, 2024
Property enumerator methods like `Object.getOwnPropertyNames`, `Object.getOwnPropertySymbols`, and `Object.keys` all invokes the named property enumerator interceptor. V8 will filter the result based on the invoked enumerator variant. Fix the enumerator interceptor to return all potential properties. PR-URL: nodejs#54522 Refs: jsdom/jsdom#3688 Reviewed-By: Joyee Cheung <[email protected]>
tpoisseau pushed a commit to tpoisseau/node that referenced this pull request Nov 21, 2024
Property enumerator methods like `Object.getOwnPropertyNames`, `Object.getOwnPropertySymbols`, and `Object.keys` all invokes the named property enumerator interceptor. V8 will filter the result based on the invoked enumerator variant. Fix the enumerator interceptor to return all potential properties. PR-URL: nodejs#54522 Refs: jsdom/jsdom#3688 Reviewed-By: Joyee Cheung <[email protected]>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++Issues and PRs that require attention from people who are familiar with C++.dont-land-on-v20.xPRs that should not land on the v20.x-staging branch and should not be released in v20.x.needs-ciPRs that need a full CI run.vmIssues and PRs related to the vm subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@legendecas@joyeecheung@nodejs-github-bot@targos