Skip to content
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

Assignment of global variables deleted by their RHS in strict mode is permitted #2093

Closed
bakkot opened this issue Jul 14, 2020 · 1 comment · Fixed by #2094
Closed

Assignment of global variables deleted by their RHS in strict mode is permitted #2093

bakkot opened this issue Jul 14, 2020 · 1 comment · Fixed by #2094

Comments

@bakkot
Copy link
Contributor

bakkot commented Jul 14, 2020

(Copying from bugzilla; see discussion in esdiscuss.)

In short, it is possible to have a Reference to a global variable or object-environment-record property which has been deleted. Normally, bare assignments to undeclared variables in strict mode cause ReferenceErrors. However, calling PutValue on a reference to a global variable which has been deleted since the reference was created does not throw a ReferenceError in strict mode, even though, at the time of writing, that variable does not exist.

This circumvents a protection which strict mode is intended to provide.

For example, in

var global = this;
Object.defineProperty(this, "x", {
  configurable: true,
  value: 1
});

(function() {
  "use strict";
  x = (delete global.x, 2);
})();

the x = goes through PutValue, which in step 5 performs IsUnresolvableReference, which returns false because the Reference was resolvable when it was created. Hence no error is thrown.

However, Firefox, Chrome, and Safari all throw for the above code, in violation of the spec.

I would regard this as a (normative) bug in the spec.

@bakkot
Copy link
Contributor Author

bakkot commented Jul 14, 2020

See also #467, though in this case the right answer is clearer, I think.

leobalter added a commit to leobalter/ecma262 that referenced this issue Jul 14, 2020
In PutValue, verify if the Reference is still preserved in its base in Strict Mode.

Ref tc39#2093
leobalter added a commit to leobalter/ecma262 that referenced this issue Jul 14, 2020
leobalter added a commit to leobalter/ecma262 that referenced this issue Jul 14, 2020
In PutValue, verify if the Reference is still preserved in its base in Strict Mode.

Ref tc39#2093
leobalter added a commit to leobalter/ecma262 that referenced this issue Jul 14, 2020
leobalter added a commit to leobalter/ecma262 that referenced this issue Jul 30, 2020
In PutValue, verify if the Reference is still preserved in its base in Strict Mode.

Ref tc39#2093
leobalter added a commit to leobalter/ecma262 that referenced this issue Jul 30, 2020
@ljharb ljharb closed this as completed in 019d498 Jul 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant