Bug 247787

Summary: Order between tdz error and others in `for` statement or class
Product: WebKit Reporter: Kanguk Lee <p51lee>
Component: JavaScriptCoreAssignee: David Degazio <d_degazio>
Status: RESOLVED FIXED    
Severity: Normal CC: mark.lam, webkit-bug-importer, ysuzuki
Priority: P2 Keywords: InRadar
Version: WebKit Local Build   
Hardware: Unspecified   
OS: Unspecified   

Description Kanguk Lee 2022-11-11 01:13:07 PST
// case 1
// input1.js
for ( let x in x = new 0 ) ;

// case 2
// input2.js
class x { [ x = new 0 ] ; } 
____________________________

Hello,

Executing the input.js using JSC throws ReferenceError, but TypeError is expected.

Running the input1.js and input2.js with JSC results in:

---
$ jsc input1.js
Exception: ReferenceError: Cannot access uninitialized variable.
global code@input1.js:1:25

$ jsc input2.js
Exception: ReferenceError: Cannot access uninitialized variable.
global code@input2.js:1:1
---

while other engines behave like:

---
# V8 (used console.log)
$ node input1.js
input1.js:1
for ( let x in x = new 0 ) ;
                   ^

TypeError: 0 is not a constructor
...

$ node input2.js
input2.js:1
class x { [ x = new 0 ] ; }
                ^

TypeError: number 0 is not a constructor
...
Node.js v18.11.0

# GraalJS
$ js input1.js
TypeError: 0 is not a constructor
	at <js> :program(input1.js:1:19-23)
$ js input2.js
TypeError: 0 is not a constructor
	at <js> :program(input2.js:1:16-20)
---


WebKit version: 615.1.10
Comment 1 Radar WebKit Bug Importer 2022-11-14 09:38:43 PST
<rdar://problem/102324888>
Comment 2 David Degazio 2022-11-15 15:04:03 PST
Pull request: https://github.com/WebKit/WebKit/pull/6532
Comment 3 EWS 2022-11-16 10:21:49 PST
Committed 256743@main (876accfa73f6): <https://commits.webkit.org/256743@main>

Reviewed commits have been landed. Closing PR #6532 and removing active labels.