Skip to content

vm: return all own names and symbols in property enumerator - #54522

Merged
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
legendecas:vm/property-enum
Aug 30, 2024
Merged

vm: return all own names and symbols in property enumerator#54522
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
legendecas:vm/property-enum

Conversation

@legendecas

@legendecaslegendecas commented Aug 23, 2024

Copy link
Copy Markdown
Member

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
Copy Markdown
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

codecovBot commented Aug 23, 2024

Copy link
Copy Markdown

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
Copy Markdown
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

joyeecheung commented Aug 28, 2024

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
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-bot
nodejs-github-bot merged commit d2479fa into nodejs:mainAug 30, 2024
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in d2479fa

@legendecas
legendecas 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 <joyeec9h3@gmail.com>
@RafaelGSSRafaelGSS mentioned this pull request Aug 30, 2024
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 <joyeec9h3@gmail.com>
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++.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