Bug 260324 - Incorrect error message in accidental function call
Summary: Incorrect error message in accidental function call
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: Safari 16
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Mark Lam
URL:
Keywords: BrowserCompat, InRadar
Depends on:
Blocks:
 
Reported: 2023-08-16 19:09 PDT by SheetJS
Modified: 2024-01-19 12:07 PST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.