Bug 191677

Summary: [JSC] Implement "well-formed JSON.stringify" proposal
Product: WebKit Reporter: Yusuke Suzuki <ysuzuki>
Component: New BugsAssignee: Yusuke Suzuki <ysuzuki>
Status: RESOLVED FIXED    
Severity: Normal CC: benjamin, cdumez, cmarcelo, darin, dbates, ews-watchlist, rniwa, ross.kirsling, sam, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
none
Archive of layout-test-results from ews101 for mac-sierra
none
Archive of layout-test-results from ews104 for mac-sierra-wk2
none
Archive of layout-test-results from ews114 for mac-sierra
none
Archive of layout-test-results from ews126 for ios-simulator-wk2
none
Patch
none
Archive of layout-test-results from ews102 for mac-sierra
none
Archive of layout-test-results from ews104 for mac-sierra-wk2
none
Archive of layout-test-results from ews112 for mac-sierra
none
Archive of layout-test-results from ews122 for ios-simulator-wk2
none
Archive of layout-test-results from ews126 for ios-simulator-wk2
none
Patch
none
Patch
none
Patch
none
Patch darin: review+

Description Yusuke Suzuki 2018-11-15 03:02:35 PST
[JSC] Implement "well-formed JSON.stringify" proposal
Comment 1 Yusuke Suzuki 2018-11-15 03:04:40 PST
Created attachment 354906 [details]
Patch
Comment 2 Yusuke Suzuki 2018-11-15 03:07:47 PST
Created attachment 354907 [details]
Patch
Comment 3 EWS Watchlist 2018-11-15 03:48:43 PST
Comment on attachment 354907 [details]
Patch

Attachment 354907 [details] did not pass mac-ews (mac):
Output: https://webkit-queues.webkit.org/results/10001803

New failing tests:
js/dom/JSON-stringify.html
js/dom/webidl-type-mapping.html
css3/escape-dom-api.html
Comment 4 EWS Watchlist 2018-11-15 03:48:45 PST
Created attachment 354910 [details]
Archive of layout-test-results from ews101 for mac-sierra

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: ews101  Port: mac-sierra  Platform: Mac OS X 10.12.6
Comment 5 EWS Watchlist 2018-11-15 03:57:45 PST
Comment on attachment 354907 [details]
Patch

Attachment 354907 [details] did not pass mac-wk2-ews (mac-wk2):
Output: https://webkit-queues.webkit.org/results/10001810

New failing tests:
js/dom/JSON-stringify.html
js/dom/webidl-type-mapping.html
css3/escape-dom-api.html
Comment 6 EWS Watchlist 2018-11-15 03:57:47 PST
Created attachment 354911 [details]
Archive of layout-test-results from ews104 for mac-sierra-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews104  Port: mac-sierra-wk2  Platform: Mac OS X 10.12.6
Comment 7 EWS Watchlist 2018-11-15 05:03:42 PST
Comment on attachment 354907 [details]
Patch

Attachment 354907 [details] did not pass mac-debug-ews (mac):
Output: https://webkit-queues.webkit.org/results/10002068

New failing tests:
js/dom/JSON-stringify.html
js/dom/webidl-type-mapping.html
css3/escape-dom-api.html
Comment 8 EWS Watchlist 2018-11-15 05:03:44 PST
Created attachment 354913 [details]
Archive of layout-test-results from ews114 for mac-sierra

The attached test failures were seen while running run-webkit-tests on the mac-debug-ews.
Bot: ews114  Port: mac-sierra  Platform: Mac OS X 10.12.6
Comment 9 EWS Watchlist 2018-11-15 05:07:28 PST
Comment on attachment 354907 [details]
Patch

Attachment 354907 [details] did not pass ios-sim-ews (ios-simulator-wk2):
Output: https://webkit-queues.webkit.org/results/10002075

New failing tests:
js/dom/JSON-stringify.html
js/dom/webidl-type-mapping.html
css3/escape-dom-api.html
Comment 10 EWS Watchlist 2018-11-15 05:07:30 PST
Created attachment 354915 [details]
Archive of layout-test-results from ews126 for ios-simulator-wk2

The attached test failures were seen while running run-webkit-tests on the ios-sim-ews.
Bot: ews126  Port: ios-simulator-wk2  Platform: Mac OS X 10.13.6
Comment 11 Yusuke Suzuki 2018-11-15 23:46:12 PST
Created attachment 355026 [details]
Patch
Comment 12 EWS Watchlist 2018-11-16 00:49:08 PST
Comment on attachment 355026 [details]
Patch

Attachment 355026 [details] did not pass mac-ews (mac):
Output: https://webkit-queues.webkit.org/results/10014029

New failing tests:
js/dom/JSON-stringify.html
js/dom/webidl-type-mapping.html
js/dom/JSON-parse.html
Comment 13 EWS Watchlist 2018-11-16 00:49:10 PST
Created attachment 355030 [details]
Archive of layout-test-results from ews102 for mac-sierra

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: ews102  Port: mac-sierra  Platform: Mac OS X 10.12.6
Comment 14 EWS Watchlist 2018-11-16 00:57:50 PST
Comment on attachment 355026 [details]
Patch

Attachment 355026 [details] did not pass mac-wk2-ews (mac-wk2):
Output: https://webkit-queues.webkit.org/results/10014035

New failing tests:
js/dom/JSON-stringify.html
js/dom/webidl-type-mapping.html
js/dom/JSON-parse.html
Comment 15 EWS Watchlist 2018-11-16 00:57:52 PST
Created attachment 355032 [details]
Archive of layout-test-results from ews104 for mac-sierra-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews104  Port: mac-sierra-wk2  Platform: Mac OS X 10.12.6
Comment 16 EWS Watchlist 2018-11-16 01:39:25 PST
Comment on attachment 355026 [details]
Patch

Attachment 355026 [details] did not pass mac-debug-ews (mac):
Output: https://webkit-queues.webkit.org/results/10014105

New failing tests:
js/dom/JSON-stringify.html
js/dom/webidl-type-mapping.html
Comment 17 EWS Watchlist 2018-11-16 01:39:26 PST
Created attachment 355033 [details]
Archive of layout-test-results from ews112 for mac-sierra

The attached test failures were seen while running run-webkit-tests on the mac-debug-ews.
Bot: ews112  Port: mac-sierra  Platform: Mac OS X 10.12.6
Comment 18 EWS Watchlist 2018-11-16 01:50:14 PST
Comment on attachment 355026 [details]
Patch

Attachment 355026 [details] did not pass ios-sim-ews (ios-simulator-wk2):
Output: https://webkit-queues.webkit.org/results/10014133

New failing tests:
js/dom/JSON-stringify.html
js/dom/webidl-type-mapping.html
js/dom/JSON-parse.html
Comment 19 EWS Watchlist 2018-11-16 01:50:16 PST
Created attachment 355034 [details]
Archive of layout-test-results from ews122 for ios-simulator-wk2

The attached test failures were seen while running run-webkit-tests on the ios-sim-ews.
Bot: ews122  Port: ios-simulator-wk2  Platform: Mac OS X 10.13.6
Comment 20 EWS Watchlist 2018-11-16 03:47:26 PST
Comment on attachment 355026 [details]
Patch

Attachment 355026 [details] did not pass ios-sim-ews (ios-simulator-wk2):
Output: https://webkit-queues.webkit.org/results/10014819

New failing tests:
js/dom/JSON-stringify.html
js/dom/webidl-type-mapping.html
js/dom/JSON-parse.html
Comment 21 EWS Watchlist 2018-11-16 03:47:28 PST
Created attachment 355038 [details]
Archive of layout-test-results from ews126 for ios-simulator-wk2

The attached test failures were seen while running run-webkit-tests on the ios-sim-ews.
Bot: ews126  Port: ios-simulator-wk2  Platform: Mac OS X 10.13.6
Comment 22 Yusuke Suzuki 2018-11-17 01:53:21 PST
Created attachment 355191 [details]
Patch
Comment 23 Yusuke Suzuki 2018-11-17 01:56:17 PST
Created attachment 355192 [details]
Patch
Comment 24 Yusuke Suzuki 2018-11-17 05:52:23 PST
Created attachment 355194 [details]
Patch
Comment 25 Yusuke Suzuki 2018-11-20 15:37:22 PST
Ping?
Comment 26 Yusuke Suzuki 2018-11-29 16:31:13 PST
Ping?
Comment 27 Ross Kirsling 2018-11-29 18:28:37 PST
Looks like there's a test262 test for this too, but it's newer than what's currently in the WebKit repo:
https://github.com/tc39/test262/blob/master/test/built-ins/JSON/stringify/string-escape-unicode.js
Comment 28 Yusuke Suzuki 2018-11-29 18:36:36 PST
(In reply to Ross Kirsling from comment #27)
> Looks like there's a test262 test for this too, but it's newer than what's
> currently in the WebKit repo:
> https://github.com/tc39/test262/blob/master/test/built-ins/JSON/stringify/
> string-escape-unicode.js

Yes, and this patch passes this test.
Comment 29 Yusuke Suzuki 2018-11-30 21:04:21 PST
Ping?
Comment 30 Yusuke Suzuki 2018-12-07 06:25:46 PST
Ping?
Comment 31 Ross Kirsling 2018-12-07 15:33:43 PST
Informal r+.

This seems quite straightforward (and even matches closely with the SpiderMonkey implementation).
Comment 32 Yusuke Suzuki 2018-12-10 21:11:42 PST
Ping review?
Comment 33 Yusuke Suzuki 2018-12-10 21:11:56 PST
(In reply to Ross Kirsling from comment #31)
> Informal r+.
> 
> This seems quite straightforward (and even matches closely with the
> SpiderMonkey implementation).

Thanks ;)
Comment 34 Yusuke Suzuki 2018-12-11 21:19:37 PST
Ping?
Comment 35 Darin Adler 2018-12-12 09:11:19 PST
Comment on attachment 355194 [details]
Patch

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

> Source/WTF/wtf/text/StringBuilderJSON.cpp:85
> +            uint8_t upper = static_cast<uint32_t>(character) >> 8;

I don’t understand what value the static_cast<uint32_t> has here. It seems the code would do the right thing without that.

> Source/WTF/wtf/text/StringBuilderJSON.cpp:86
> +            uint8_t lower = static_cast<uint8_t>(character);

I don’t understand what value the static_cast<uint8_t> has here. It seems the code would do the right thing without that.
Comment 36 Darin Adler 2018-12-12 09:13:29 PST
Comment on attachment 355194 [details]
Patch

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

> Source/WTF/wtf/text/StringBuilderJSON.cpp:84
> +        if (U16_IS_SURROGATE_TRAIL(character) || next == end || !U16_IS_SURROGATE_TRAIL(*next)) {

Oops, this is wrong! Details to come.
Comment 37 Darin Adler 2018-12-12 09:17:21 PST
Comment on attachment 355194 [details]
Patch

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

>> Source/WTF/wtf/text/StringBuilderJSON.cpp:84
>> +        if (U16_IS_SURROGATE_TRAIL(character) || next == end || !U16_IS_SURROGATE_TRAIL(*next)) {
> 
> Oops, this is wrong! Details to come.

This needs to use U16_IS_TRAIL, not U16_IS_SURROGATE_TRAIL, on *next. Test cases would be string where the last two characters are:

1) A surrogate head.
2) A non-surrogate character with the bit 0x400 set.

That case would work incorrectly.

I also think I would write it more like this to make the logic clearer:

    bool isValidSurrogatePair = U16_IS_SURROGATE_HEAD(character) && next != end && U16_IS_TRAIL(*next);
    if (!isValidSurrogatePair)
Comment 38 Yusuke Suzuki 2018-12-20 10:03:21 PST
(In reply to Darin Adler from comment #37)
> Comment on attachment 355194 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=355194&action=review
> 
> >> Source/WTF/wtf/text/StringBuilderJSON.cpp:84
> >> +        if (U16_IS_SURROGATE_TRAIL(character) || next == end || !U16_IS_SURROGATE_TRAIL(*next)) {
> > 
> > Oops, this is wrong! Details to come.
> 
> This needs to use U16_IS_TRAIL, not U16_IS_SURROGATE_TRAIL, on *next. Test
> cases would be string where the last two characters are:
> 
> 1) A surrogate head.
> 2) A non-surrogate character with the bit 0x400 set.
> 
> That case would work incorrectly.
> 
> I also think I would write it more like this to make the logic clearer:
> 
>     bool isValidSurrogatePair = U16_IS_SURROGATE_HEAD(character) && next !=
> end && U16_IS_TRAIL(*next);
>     if (!isValidSurrogatePair)

Oops, super nice catch! Right. I'll fix this and update the patch soon.
Comment 39 Yusuke Suzuki 2018-12-20 10:09:14 PST
Created attachment 357828 [details]
Patch
Comment 40 Yusuke Suzuki 2018-12-21 22:41:08 PST
Committed r239537: <https://trac.webkit.org/changeset/239537>
Comment 41 Radar WebKit Bug Importer 2018-12-21 22:42:34 PST
<rdar://problem/46916301>