Bug 221184 - [JSC] Add @ in Error.stack if URL exists
Summary: [JSC] Add @ in Error.stack if URL exists
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: Safari 14
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Yusuke Suzuki
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-01-31 02:25 PST by John A. Bilicki III
Modified: 2021-02-01 03:05 PST (History)
12 users (show)

See Also:


Attachments
Patch (2.54 KB, patch)
2021-01-31 12:51 PST, Yusuke Suzuki
keith_miller: review+
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (3.09 KB, patch)
2021-01-31 13:03 PST, Yusuke Suzuki
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (28.06 KB, patch)
2021-02-01 01:43 PST, Yusuke Suzuki
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description John A. Bilicki III 2021-01-31 02:25:08 PST
The error object (the fifth parameter for the window.onerror event handler) should ALWAYS return an @ deliminator. Because WebKit/Safari doesn't in order to parse and clean up the error details for proper error reporting developers have to add pointless additional logic. Gecko browsers always use the @ deliminator; if no function is used the deliminator[0] index is simply empty though the deliminator[1] index is the same for all stack trace indexes. This would make the error object compatible with existing browser engines and likely the only need is to remove whatever excessive logic exists in the code that conditionally outputs the @ deliminator so this should be easy for someone familiar with the engine to fix.

The general overview of what is happening plus a prerequisite function for my platform:

function array_remove_empty(a)
{
 var k = [];
 for (var i = 0; i < a.length; i++) {if (a[i] == '') {k.push(i);}}
 var r = array_remove_keys(a,k);
 return r;
}

window.onerror = function(msg,url,line,col,error)
{
 a = array_trim(array_remove_empty(a.split('\n').reverse()));
 console.log(a);
}

The text string output:

0 "http://1.0.0.1/scripts/index.js?1612087732:7859:96"

1 "window_onload@http://1.0.0.1/scripts/index.js?1612087732:7368:5"

2 "az19@http://1.0.0.1/scripts/index.js?1612087732:7364:9"

As demonstrated [0] index lacks the @ deliminator creating pointless complications. Tested with the latest version of Safari 14 as of 2021-01-31.
Comment 1 Yusuke Suzuki 2021-01-31 12:44:53 PST
While Error.stack format is not standardized (this means any format is OK), maybe, having @ for source URL case is not so bad idea.
Comment 2 Yusuke Suzuki 2021-01-31 12:51:37 PST
Created attachment 418830 [details]
Patch
Comment 3 Keith Miller 2021-01-31 12:53:34 PST
Comment on attachment 418830 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=418830&action=review

> Source/JavaScriptCore/ChangeLog:8
> +        Append '@' if URL exists even if function name does not exist.

Can you say why you want this here?
Comment 4 Yusuke Suzuki 2021-01-31 12:55:51 PST
Comment on attachment 418830 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=418830&action=review

>> Source/JavaScriptCore/ChangeLog:8
>> +        Append '@' if URL exists even if function name does not exist.
> 
> Can you say why you want this here?

Added :)
Comment 5 Yusuke Suzuki 2021-01-31 13:03:25 PST
Created attachment 418831 [details]
Patch
Comment 6 Yusuke Suzuki 2021-02-01 01:43:34 PST
Created attachment 418843 [details]
Patch
Comment 7 EWS 2021-02-01 03:04:29 PST
Committed r272139: <https://trac.webkit.org/changeset/272139>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 418843 [details].
Comment 8 Radar WebKit Bug Importer 2021-02-01 03:05:15 PST
<rdar://problem/73823423>