Bug 210037 - JSC shell shouldn't treat NUL as a terminator when printing a JS string
Summary: JSC shell shouldn't treat NUL as a terminator when printing a JS string
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Ross Kirsling
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-04-05 13:45 PDT by Ross Kirsling
Modified: 2020-04-05 21:35 PDT (History)
10 users (show)

See Also:


Attachments
Patch (3.17 KB, patch)
2020-04-05 13:56 PDT, Ross Kirsling
no flags Details | Formatted Diff | Diff
Patch (6.68 KB, patch)
2020-04-05 16:06 PDT, Ross Kirsling
no flags Details | Formatted Diff | Diff
Patch for landing (7.16 KB, patch)
2020-04-05 19:29 PDT, Ross Kirsling
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ross Kirsling 2020-04-05 13:45:59 PDT
JSC shell shouldn't treat NUL as a terminator when printing a JS string
Comment 1 Ross Kirsling 2020-04-05 13:56:59 PDT
Created attachment 395525 [details]
Patch
Comment 2 Ross Kirsling 2020-04-05 14:24:56 PDT
Hmm, I suppose this would be the right opportunity to remove $vm.print too -- it's hardly used, and it doesn't do what it says.
Comment 3 Mark Lam 2020-04-05 14:29:34 PDT
(In reply to Ross Kirsling from comment #2)
> Hmm, I suppose this would be the right opportunity to remove $vm.print too
> -- it's hardly used, and it doesn't do what it says.

Do not remove $vm.print().  Its uses go beyond what it in the existing test scripts.  I use it for custom debugging tests all the time.  It comes in especially handy when I want to print from WebCore and don't want to go thru console.log().
Comment 4 Ross Kirsling 2020-04-05 14:57:14 PDT
(In reply to Mark Lam from comment #3)
> (In reply to Ross Kirsling from comment #2)
> > Hmm, I suppose this would be the right opportunity to remove $vm.print too
> > -- it's hardly used, and it doesn't do what it says.
> 
> Do not remove $vm.print().  Its uses go beyond what it in the existing test
> scripts.  I use it for custom debugging tests all the time.  It comes in
> especially handy when I want to print from WebCore and don't want to go thru
> console.log().

Ah okay, thanks for the clarification. My concern is just because $vm.print is currently effectively dataLogLn, and I'm not sure whether this same change is appropriate to apply to dataLog.
Comment 5 Mark Lam 2020-04-05 15:00:01 PDT
Why should the jsc shell treat NULL as a terminator when printing a JS string?  JS strings come with a length, and is not necessarily null terminated like a C string.  I fail to see why we would want to make this change.  In fact, it feels wrong to do so.
Comment 6 Mark Lam 2020-04-05 15:09:26 PDT
(In reply to Mark Lam from comment #5)
> Why should the jsc shell treat NULL as a terminator when printing a JS
> string?  JS strings come with a length, and is not necessarily null
> terminated like a C string.  I fail to see why we would want to make this
> change.  In fact, it feels wrong to do so.

I talked with Ross offline and clarified things.  I was mistaken above and misread the change as the opposite of what it's doing.  Sorry for that.  Carry on.

No need to worry about $vm.print() because it is purely a WebKit developer debugging tool, not a user facing tool.  User (as in the developer) beware when using it.
Comment 7 Ross Kirsling 2020-04-05 16:06:25 PDT
Created attachment 395533 [details]
Patch
Comment 8 Darin Adler 2020-04-05 16:15:15 PDT
Comment on attachment 395533 [details]
Patch

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

> Source/JavaScriptCore/jsc.cpp:1293
> +    fprintf(stderr, "--> ");

fputs?

> Source/JavaScriptCore/jsc.cpp:1295
> +    fprintf(stderr, "\n");

putc?

> Source/JavaScriptCore/jsc.cpp:2803
> +            printf("Exception: ");

puts?

> Source/JavaScriptCore/jsc.cpp:2808
> +        printf("\n");

putchar?

> JSTests/ChangeLog:11
> +        Update baseline, but ensure that \0 isn't printed to file, lest the file be treated as binary.

For testing purposes I often like the idea of replacing a NUL with something like "<NUL>" rather than just deleting it. Seems more likely to help us catch bugs and unlikely to cause confusion.
Comment 9 Ross Kirsling 2020-04-05 16:39:35 PDT
(In reply to Darin Adler from comment #8)
> > JSTests/ChangeLog:11
> > +        Update baseline, but ensure that \0 isn't printed to file, lest the file be treated as binary.
> 
> For testing purposes I often like the idea of replacing a NUL with something
> like "<NUL>" rather than just deleting it. Seems more likely to help us
> catch bugs and unlikely to cause confusion.

That's a good idea, though it's probably inappropriate that I edit this test in the first place. :-/

Given that JSTests/ChakraCore is the only subdirectory that does file diffs and only one of its tests is having this problem, it might be simpler to just map its echo function to $vm.print instead...
Comment 10 Ross Kirsling 2020-04-05 16:55:47 PDT
(In reply to Ross Kirsling from comment #9)
> Given that JSTests/ChakraCore is the only subdirectory that does file diffs
> and only one of its tests is having this problem, it might be simpler to
> just map its echo function to $vm.print instead...

Hrmm, but apparently $vm.print doesn't insert spaces between its arguments, so we'd need to either make it do so or update two dozen baselines.

That or I suppose we could just have .baseline-jsc _be_ binary for this test. It's gross, but the data is correct, and we'd avoid modifying files we shouldn't.
Comment 11 Ross Kirsling 2020-04-05 19:29:28 PDT
Created attachment 395540 [details]
Patch for landing
Comment 12 Ross Kirsling 2020-04-05 19:31:00 PDT
(In reply to Ross Kirsling from comment #10)
> That or I suppose we could just have .baseline-jsc _be_ binary for this
> test. It's gross, but the data is correct, and we'd avoid modifying files we
> shouldn't.

Seems like this works fine after all, so long as the file is marked diffable in .gitattributes.
Comment 13 EWS 2020-04-05 21:13:53 PDT
Found 1 new test failure: storage/indexeddb/value-cursor-cycle.html
Comment 14 EWS 2020-04-05 21:34:40 PDT
Committed r259564: <https://trac.webkit.org/changeset/259564>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 395540 [details].
Comment 15 Radar WebKit Bug Importer 2020-04-05 21:35:13 PDT
<rdar://problem/61328543>