Bug 260324

Summary: Incorrect error message in accidental function call
Product: WebKit Reporter: SheetJS <dev>
Component: JavaScriptCoreAssignee: Mark Lam <mark.lam>
Status: RESOLVED FIXED    
Severity: Normal CC: karlcow, mark.lam, webkit-bug-importer, ysuzuki
Priority: P2 Keywords: BrowserCompat, InRadar
Version: Safari 16   
Hardware: Unspecified   
OS: Unspecified   

Description SheetJS 2023-08-16 19:09:12 PDT
Reproduction:

```js
console.log("hi")
(async() => {
	console.log("hi");
	console.log("hi");
	console.log("hi");
	console.log("hi");
	console.log("hi");
	console.log("hi");
})();
```

This is interpreted as `console.log("hi")(/*...*/)();` and throws an error since `console.log("hi")` returns `undefined`.

.

V8 correctly diagnoses the error.  Running in the Chrome DevTools shows the error:

```
Uncaught TypeError: console.log(...) is not a function
```

.

Safari 16 and Bun 0.7.3 both misdiagnose the error:

```
TypeError: console.log is not a function. (In 'console.log("hi")', 'console.log' is undefined)
```

To be clear, `console.log` is not undefined in context.

.

This appears to be related to the size of the function body.  For example, if one of the console calls is removed:

```js
console.log("hi")
(async() => {
	console.log("hi");
	console.log("hi");
	console.log("hi");
	console.log("hi");
	console.log("hi");
})();
```

Safari and Bun both show correct error messages:

```
TypeError: console.log("hi")
 is not a function. (In 'console.log("hi")
(async() => {
	console.log("hi");
	console.log("hi");
	console.log("hi");
	console.log("hi");
	console.log("hi");
})', 'console.log("hi")
' is undefined)
```

This message is correct: `console.log("hi")` is undefined.
Comment 1 Radar WebKit Bug Importer 2023-08-23 19:10:21 PDT
<rdar://problem/114357179>
Comment 2 Mark Lam 2024-01-17 14:06:48 PST
This incorrect error message is an accidental by-product of a truncated error message.  I'll be fixing this by compressing ExpressionInfo as well as changing it to no longer discard divot info.
Comment 3 Mark Lam 2024-01-17 14:47:41 PST
Pull request: https://github.com/WebKit/WebKit/pull/22880
Comment 4 EWS 2024-01-19 12:07:02 PST
Committed 273233@main (126d2027f1ce): <https://commits.webkit.org/273233@main>

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