Bug 154927 - RegExpPrototype should check for exceptions after calling toString and doing so should not be expensive
Summary: RegExpPrototype should check for exceptions after calling toString and doing ...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Filip Pizlo
URL:
Keywords:
Depends on:
Blocks: 154901
  Show dependency treegraph
 
Reported: 2016-03-02 12:12 PST by Filip Pizlo
Modified: 2016-03-02 18:06 PST (History)
7 users (show)

See Also:


Attachments
the patch (4.46 KB, patch)
2016-03-02 12:14 PST, Filip Pizlo
sbarati: review+
Details | Formatted Diff | Diff
patch for landing (5.65 KB, patch)
2016-03-02 12:42 PST, Filip Pizlo
buildbot: commit-queue-
Details | Formatted Diff | Diff
Archive of layout-test-results from ews100 for mac-yosemite (1.36 MB, application/zip)
2016-03-02 13:41 PST, Build Bot
no flags Details
Archive of layout-test-results from ews104 for mac-yosemite-wk2 (1.13 MB, application/zip)
2016-03-02 13:41 PST, Build Bot
no flags Details
Archive of layout-test-results from ews116 for mac-yosemite (1.04 MB, application/zip)
2016-03-02 13:48 PST, Build Bot
no flags Details
the patch (6.85 KB, patch)
2016-03-02 14:17 PST, Filip Pizlo
sbarati: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Filip Pizlo 2016-03-02 12:12:44 PST
Patch forthcoming.
Comment 1 Filip Pizlo 2016-03-02 12:14:53 PST
Created attachment 272673 [details]
the patch
Comment 2 Saam Barati 2016-03-02 12:16:29 PST
Comment on attachment 272673 [details]
the patch

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

> Source/JavaScriptCore/runtime/JSCJSValue.cpp:391
>      if (exec->hadException())

this can be "vm.exception()"

> Source/JavaScriptCore/runtime/JSCJSValue.cpp:395
> +    if (exec->hadException())

this can be "vm.exception()"
Comment 3 Filip Pizlo 2016-03-02 12:17:07 PST
(In reply to comment #2)
> Comment on attachment 272673 [details]
> the patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=272673&action=review
> 
> > Source/JavaScriptCore/runtime/JSCJSValue.cpp:391
> >      if (exec->hadException())
> 
> this can be "vm.exception()"
> 
> > Source/JavaScriptCore/runtime/JSCJSValue.cpp:395
> > +    if (exec->hadException())
> 
> this can be "vm.exception()"

Thanks, fixed!
Comment 4 Filip Pizlo 2016-03-02 12:42:36 PST
Created attachment 272679 [details]
patch for landing
Comment 5 Build Bot 2016-03-02 13:41:00 PST
Comment on attachment 272679 [details]
patch for landing

Attachment 272679 [details] did not pass mac-ews (mac):
Output: http://webkit-queues.webkit.org/results/912394

Number of test failures exceeded the failure limit.
Comment 6 Build Bot 2016-03-02 13:41:03 PST
Created attachment 272682 [details]
Archive of layout-test-results from ews100 for mac-yosemite

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: ews100  Port: mac-yosemite  Platform: Mac OS X 10.10.5
Comment 7 Build Bot 2016-03-02 13:41:32 PST
Comment on attachment 272679 [details]
patch for landing

Attachment 272679 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.webkit.org/results/912390

Number of test failures exceeded the failure limit.
Comment 8 Build Bot 2016-03-02 13:41:34 PST
Created attachment 272683 [details]
Archive of layout-test-results from ews104 for mac-yosemite-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews104  Port: mac-yosemite-wk2  Platform: Mac OS X 10.10.5
Comment 9 Build Bot 2016-03-02 13:48:11 PST
Comment on attachment 272679 [details]
patch for landing

Attachment 272679 [details] did not pass mac-debug-ews (mac):
Output: http://webkit-queues.webkit.org/results/912384

Number of test failures exceeded the failure limit.
Comment 10 Build Bot 2016-03-02 13:48:14 PST
Created attachment 272684 [details]
Archive of layout-test-results from ews116 for mac-yosemite

The attached test failures were seen while running run-webkit-tests on the mac-debug-ews.
Bot: ews116  Port: mac-yosemite  Platform: Mac OS X 10.10.5
Comment 11 Filip Pizlo 2016-03-02 14:17:08 PST
Created attachment 272687 [details]
the patch

Lets try this again.
Comment 12 Saam Barati 2016-03-02 14:20:28 PST
Comment on attachment 272687 [details]
the patch

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

> Source/JavaScriptCore/runtime/RegExpPrototype.cpp:104
> +    if (!string)
> +        return JSValue::encode(jsUndefined());

It might be worth adding a debug assert that an exception was thrown to make the call site contract of toStringFast more explicit

> Source/JavaScriptCore/runtime/RegExpPrototype.cpp:115
> +        return JSValue::encode(jsUndefined());

ditto
Comment 13 Filip Pizlo 2016-03-02 14:22:27 PST
(In reply to comment #12)
> Comment on attachment 272687 [details]
> the patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=272687&action=review
> 
> > Source/JavaScriptCore/runtime/RegExpPrototype.cpp:104
> > +    if (!string)
> > +        return JSValue::encode(jsUndefined());
> 
> It might be worth adding a debug assert that an exception was thrown to make
> the call site contract of toStringFast more explicit
> 
> > Source/JavaScriptCore/runtime/RegExpPrototype.cpp:115
> > +        return JSValue::encode(jsUndefined());
> 
> ditto

I want to call toStringFast() in a lot of places.  My next patch will add several more calls.  The idea is that null-checking the return is even faster than vm.exception() in this case.

So, maybe we can either agree that "toStringFast()" means this, or we can come up with a better name for the function that does convey this meaning?  I'm fine with renaming it if the new name is not long.  If the alternatives use a word that is longer than "fast" then I think "fast" is least bad.
Comment 14 Geoffrey Garen 2016-03-02 14:32:07 PST
Comment on attachment 272687 [details]
the patch

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

> Source/JavaScriptCore/runtime/JSCJSValue.h:256
> +    JSString* toStringFast(ExecState*) const; // On exception, this returns null, to make exception checks faster.

I would call this toStringOrNull. It's two letters / one word longer than "fast" but I think it conveys the meaning, and the action required by the caller, much more clearly. So, I think it's worth it.

A shorter option, which I like less but still keeps with project naming conventions, is "tryToString".
Comment 15 Filip Pizlo 2016-03-02 14:34:13 PST
(In reply to comment #14)
> Comment on attachment 272687 [details]
> the patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=272687&action=review
> 
> > Source/JavaScriptCore/runtime/JSCJSValue.h:256
> > +    JSString* toStringFast(ExecState*) const; // On exception, this returns null, to make exception checks faster.
> 
> I would call this toStringOrNull. It's two letters / one word longer than
> "fast" but I think it conveys the meaning, and the action required by the
> caller, much more clearly. So, I think it's worth it.

OK.

> 
> A shorter option, which I like less but still keeps with project naming
> conventions, is "tryToString".

tryToString would not be consistent - that is used in other string code to mean "try to give me the string without doing anything effectful".
Comment 16 Filip Pizlo 2016-03-02 18:06:42 PST
Landed in http://trac.webkit.org/changeset/197485