eval, globalThis, NaN, Infinity, undefined, etc. are valid names for bindings (i.e., they are not keywords) and exist as such on the global object (the last three as non-configurable and non-writable). However, several implementations seem to treat them specially in ways that violate the specification (as seen below for Hermes and Moddable XS and QuickJS). Test262 should have coverage for such cases, although I'm never quite sure where in the hierarchy to put this kind of broad syntax verification... maybe generated tests in test/language/reserved-words?
print('START'); const %s = 1;
This should succeed with all names except NaN/Infinity/undefined, for which there should be a SyntaxError before anything happens because ScriptEvaluation starts with GlobalDeclarationInstantiation, which tests each lexically declared name against Global Environment Record HasRestrictedGlobalProperty and enforces that «A global lexical binding may not be created that has the same name as a non-configurable property of the global object… The global property "undefined" is an example of such a property».
But Hermes fails to throw the required SyntaxError (although it does not create observable changes).
```console
## Source
print('START');
const NaN = 1;
const Infinity = 1;
const undefined = 1;
print([NaN, Infinity, undefined].some(v => v === 1) ? 'FAIL WITH EFFECTS' : 'FAIL WITHOUT EFFECTS');
#### Hermes
START
FAIL WITHOUT EFFECTS
```
Within a block, there should be no restrictions on these names.
But Hermes fails to create the NaN/Infinity/undefined bindings (i.e., it does not shadow the global property), as does Moddable XS (but only when the name is undefined), and QuickJS throws a SyntaxError before evaluating anything when the name is undefined.
eval
,globalThis
,NaN
,Infinity
,undefined
, etc. are valid names for bindings (i.e., they are not keywords) and exist as such on the global object (the last three as non-configurable and non-writable). However, several implementations seem to treat them specially in ways that violate the specification (as seen below for Hermes and Moddable XS and QuickJS). Test262 should have coverage for such cases, although I'm never quite sure where in the hierarchy to put this kind of broad syntax verification... maybe generated tests in test/language/reserved-words?print('START'); const %s = 1;
This should succeed with all names except
NaN
/Infinity
/undefined
, for which there should be a SyntaxError before anything happens because ScriptEvaluation starts with GlobalDeclarationInstantiation, which tests each lexically declared name against Global Environment Record HasRestrictedGlobalProperty and enforces that «A global lexical binding may not be created that has the same name as a non-configurable property of the global object… The global property "undefined" is an example of such a property».But Hermes fails to throw the required SyntaxError (although it does not create observable changes).
{ const %s = 1; print(%s === 1 ? 'PASS' : 'FAIL'); }
Within a block, there should be no restrictions on these names.
But Hermes fails to create the
NaN
/Infinity
/undefined
bindings (i.e., it does not shadow the global property), as does Moddable XS (but only when the name isundefined
), and QuickJS throws a SyntaxError before evaluating anything when the name isundefined
.(function(%s) { print(%s === 1 ? 'PASS' : 'FAIL'); })(1);
Use as a simple function parameter name should be allowed.
But Moddable XS does not bind the argument value to a parameter named
undefined
.(function({ %s }) { print(%s === 1 ? 'PASS' : 'FAIL'); })({ %s: 1 });
Use as a destructured function parameter name should be allowed.
But Moddable XS does not bind the argument value to a parameter named
undefined
.