-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
src: don't overwrite non-writable vm globals #10227
Conversation
LGTM. I was trying to mirror when V8 does not set the property. https://github.com/v8/v8/blob/master/src/objects.cc#L4812 I think we don't need |
vm.runInContext('x = 0', ctx); // Does not throw but x... | ||
assert.strictEqual(vm.runInContext('x', ctx), 42); // ...should be unaltered. | ||
assert.throws(() => vm.runInContext('"use strict"; x = 0', ctx), | ||
/Cannot assign to read only property 'x'/); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure checking the error string is a great idea here as it might change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, but we can update the test when it does. I opted to be specific because it needs to throw this particular exception. Any other exception probably means something is broken.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough
Check that the property doesn't have the read-only flag set before overwriting it. Fixes: nodejs#10223 PR-URL: nodejs#10227 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
Landed in 524f693, thanks for reviewing. |
Check that the property doesn't have the read-only flag set before overwriting it. Fixes: #10223 PR-URL: #10227 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
This appears to have broken console logging with jsdom |
See jestjs/jest#2457 (comment) for @thealphanerd's repro. This also applies to globals like |
This reverts commit 524f693. Fixes: nodejs#10806 Fixes: nodejs#10492 Ref: nodejs#10227
due to the revert I am opting to label this as do not land. |
This reverts commit 524f693. Fixes: #10806 Fixes: #10492 Ref: #10227 PR-URL: #10920 Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
This reverts commit 524f693. Fixes: #10806 Fixes: #10492 Ref: #10227 PR-URL: #10920 Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
This reverts commit 524f693. Fixes: nodejs#10806 Fixes: nodejs#10492 Ref: nodejs#10227 PR-URL: nodejs#10920 Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
This reverts commit 524f693. Fixes: nodejs#10806 Fixes: nodejs#10492 Ref: nodejs#10227 PR-URL: nodejs#10920 Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
@bnoordhuis, I know this is long closed and reverted, but I figured out what This test would rely on it, if it weren't for the |
Check that the property doesn't have the read-only flag set before overwriting it. This is Ben Noordhuis previous commit, but keeping is_contextual_store. is_contextual_store describes whether this.foo = 42 or foo = 42 was called. The second is contextual and will fail in strict mode if foo is used without declaration. Therefore only do an early return if it is a contextual store. In particular, don't do an early return for Object.defineProperty(this, ...). Fixes: nodejs#10223 Refs: nodejs#10227
Check that the property doesn't have the read-only flag set before overwriting it. This is Ben Noordhuis previous commit, but keeping is_contextual_store. is_contextual_store describes whether this.foo = 42 or foo = 42 was called. The second is contextual and will fail in strict mode if foo is used without declaration. Therefore only do an early return if it is a contextual store. In particular, don't do an early return for Object.defineProperty(this, ...). Fixes: #10223 Refs: #10227 PR-URL: #11109 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
Check that the property doesn't have the read-only flag set before overwriting it. This is Ben Noordhuis previous commit, but keeping is_contextual_store. is_contextual_store describes whether this.foo = 42 or foo = 42 was called. The second is contextual and will fail in strict mode if foo is used without declaration. Therefore only do an early return if it is a contextual store. In particular, don't do an early return for Object.defineProperty(this, ...). Fixes: nodejs#10223 Refs: nodejs#10227 PR-URL: nodejs#11109 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
Check that the property doesn't have the read-only flag set before overwriting it. This is Ben Noordhuis previous commit, but keeping is_contextual_store. is_contextual_store describes whether this.foo = 42 or foo = 42 was called. The second is contextual and will fail in strict mode if foo is used without declaration. Therefore only do an early return if it is a contextual store. In particular, don't do an early return for Object.defineProperty(this, ...). Fixes: nodejs#10223 Refs: nodejs#10227 PR-URL: nodejs#11109 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
Check that the property doesn't have the read-only flag set before overwriting it. This is Ben Noordhuis previous commit, but keeping is_contextual_store. is_contextual_store describes whether this.foo = 42 or foo = 42 was called. The second is contextual and will fail in strict mode if foo is used without declaration. Therefore only do an early return if it is a contextual store. In particular, don't do an early return for Object.defineProperty(this, ...). Fixes: nodejs#10223 Refs: nodejs#10227 PR-URL: nodejs#11109 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
@fhinkel Can you take a look? I couldn't figure out what
is_contextual_store
is needed for. Tests pass without it.CI: https://ci.nodejs.org/job/node-test-pull-request/5357/