Bug 165795 - Use JSValue::toWTFString instead of calling toString(exec) and value(exec)
Summary: Use JSValue::toWTFString instead of calling toString(exec) and value(exec)
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Yusuke Suzuki
URL:
Keywords:
Depends on: 165841
Blocks:
  Show dependency treegraph
 
Reported: 2016-12-13 01:45 PST by Yusuke Suzuki
Modified: 2016-12-15 01:15 PST (History)
4 users (show)

See Also:


Attachments
Patch (67.33 KB, patch)
2016-12-13 01:48 PST, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (67.30 KB, patch)
2016-12-13 01:49 PST, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (67.41 KB, patch)
2016-12-13 02:00 PST, Yusuke Suzuki
saam: review+
Details | Formatted Diff | Diff
Patch (64.18 KB, patch)
2016-12-13 23:52 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 Yusuke Suzuki 2016-12-13 01:45:33 PST
Use JSValue::toWTFString instead of calling toString(exec) and value(exec)
Comment 1 Yusuke Suzuki 2016-12-13 01:48:03 PST
Created attachment 296996 [details]
Patch
Comment 2 Yusuke Suzuki 2016-12-13 01:49:03 PST
Created attachment 296997 [details]
Patch
Comment 3 Yusuke Suzuki 2016-12-13 02:00:27 PST
Created attachment 296999 [details]
Patch
Comment 4 Saam Barati 2016-12-13 19:27:47 PST
Comment on attachment 296999 [details]
Patch

Looks like you have some build issues but r=me if it builds.
Comment 5 Yusuke Suzuki 2016-12-13 23:03:25 PST
Committed r209792: <http://trac.webkit.org/changeset/209792>
Comment 6 WebKit Commit Bot 2016-12-13 23:17:59 PST
Re-opened since this is blocked by bug 165841
Comment 7 Yusuke Suzuki 2016-12-13 23:52:04 PST
Created attachment 297070 [details]
Patch

Patch for landing
Comment 8 Yusuke Suzuki 2016-12-14 08:05:10 PST
Committed r209801: <http://trac.webkit.org/changeset/209801>
Comment 9 Darin Adler 2016-12-14 09:04:16 PST
So glad you did this Yusuke! Now I can delete my local git branch named "ToWTFString", or maybe I will merge it to see if I had any changes there on something you missed?
Comment 10 Yusuke Suzuki 2016-12-14 09:47:01 PST
(In reply to comment #9)
> So glad you did this Yusuke! Now I can delete my local git branch named
> "ToWTFString", or maybe I will merge it to see if I had any changes there on
> something you missed?

Nice! Can you check whether I missed something in your branch?
If your branch find a missed one, that's super awesome!
Comment 11 Darin Adler 2016-12-15 00:15:57 PST
Turns out my patch still has valuable changes, but it's hard to merge so I am not sure what I am going to do. Maybe just do the work below again.

I found quite a few call sites that were calling JSValue::isString first, then calling JSValue::toString or JSValue::toWTFString. Those could call JSValue::getString instead, which should be a bit more efficient. That has an additional benefit because we know those call sites cannot generate exceptions, so we can remove unneeded RETURN_IF_EXCEPTION or any other branching based on the exception.

In a couple other places, I did something similar except that I changed code to use the asString function rather than JSValue::getString.

At call sites that were calling Identifier::toString on the result, I changed them to call JSString::toIdentifier instead of JSString::value or JSValue::toWTFString, hoping to save on allocating a string that already exists in the atomic string table.

Another thing the patch had was that I had changed toWTFString to return a null string any time there is an exception, so the caller could check the string for null instead of checking the ExecState for an exception. That was possibly a valuable optimization back when I originally wrote this before we started using ThrowScope, but presumably is not needed now.

One other thing the patch had is that I also noticed that WebCore::Dictionary::getWithUndefinedOrNullCheck will return true when it encounters an exception in toWTFString, and I am not sure that is what we want, so I made it return false in that case in the patch.
Comment 12 Darin Adler 2016-12-15 01:15:43 PST
(In reply to comment #11)
> I found quite a few call sites that were calling JSValue::isString first

Patch in bug 165895 now.