ecma262
ecma262 copied to clipboard
Is `null[{ toString: () => { console.log('hit') } }]` supposed to hit the `console.log`?
https://github.com/tc39/ecma262/pull/2267 changed the sequencing of the RequireObjectCoercible
-on-base / ToString
-on-property for member assignments, like a[b] = c
.
As I read the spec, it also changed the semantics for null[{ toString: () => { console.log('hit') } }]
, which by my reading is now supposed to print hit
before throwing:
- the
RequireObjectCoercible
happens only during theGetValue
call happens in the Evaluation semantics for ExpressionStatement, - which is after the
ToString
has already happened,- within the
ToPropertyKey
call - in step 2 of
EvaluatePropertyAccessWithExpressionKey
- which is called in step 4 of the Evaluation semantics for
MemberExpression : MemberExpression [ Expression ]
.
- within the
Of engines I have on hand, only ChakraCore implements this behavior.
cc @codehag
We can also observe this behavior with our implementation ESMeta, which strictly follows the spec. Currently, spec and tests are diverged.
Opened a couple of PRs on the test262 repo that fixes the corresponding tests on either case: preserve the new semantics or rollback to the old behaviour. PRs will be waiting for consensus on this.
Hopefully this reactivates the issue's discussion!
Is this actually the same issue as #3295?
Related, but not identical - that issue is much older than this one, which was only introduced in https://github.com/tc39/ecma262/pull/2267 (I think).
That said, I think the same PR might fix this as well. I'll have to walk through it carefully to confirm.