WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
Bug 146416
WKWebView evaluateJavaScript:completionHandler: should reuse its JSContext instance
https://bugs.webkit.org/show_bug.cgi?id=146416
Summary
WKWebView evaluateJavaScript:completionHandler: should reuse its JSContext in...
Mihai Parparita
Reported
2015-06-29 12:01:24 PDT
Similar to the fix made in
bug 146358
, evaluateJavaScript:completionHandler: in WKWebView creates a new JSContext every time it parses the return value (see
http://trac.webkit.org/browser/trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm#L640
). This is inefficient and could benefit from the same caching added by
http://trac.webkit.org/changeset/186010
I reported this via Radar in
rdar://17956460
during the iOS 8 beta period.
Attachments
the patch.
(11.41 KB, patch)
2015-07-01 13:39 PDT
,
Mark Lam
no flags
Details
Formatted Diff
Diff
patch 2: fixed missing semi-colon
(11.41 KB, patch)
2015-07-01 14:17 PDT
,
Mark Lam
no flags
Details
Formatted Diff
Diff
patch 3: applied Geoff's feedback
(12.20 KB, patch)
2015-07-01 19:17 PDT
,
Mark Lam
andersca
: review+
Details
Formatted Diff
Diff
Show Obsolete
(2)
View All
Add attachment
proposed patch, testcase, etc.
Mihai Parparita
Comment 1
2015-06-29 12:02:27 PDT
Mark, any chance you could look at this, since it's very similar to the work you did for
bug 146358
?
Mark Lam
Comment 2
2015-06-29 12:09:16 PDT
(In reply to
comment #1
)
> Mark, any chance you could look at this, since it's very similar to the work > you did for
bug 146358
?
Will take a look.
Mark Lam
Comment 3
2015-07-01 13:39:04 PDT
Created
attachment 255949
[details]
the patch.
WebKit Commit Bot
Comment 4
2015-07-01 13:41:27 PDT
Thanks for the patch. If this patch contains new public API please make sure it follows the guidelines for new WebKit2 GTK+ API. See
http://trac.webkit.org/wiki/WebKitGTK/AddingNewWebKit2API
Mark Lam
Comment 5
2015-07-01 13:45:03 PDT
<
rdar://problem/17956460
>
Mark Lam
Comment 6
2015-07-01 14:17:28 PDT
Created
attachment 255952
[details]
patch 2: fixed missing semi-colon
Geoffrey Garen
Comment 7
2015-07-01 14:41:39 PDT
Comment on
attachment 255952
[details]
patch 2: fixed missing semi-colon View in context:
https://bugs.webkit.org/attachment.cgi?id=255952&action=review
> Source/WebKit2/UIProcess/API/Cocoa/APISerializedScriptValueCocoa.mm:38 > + static JSContext* context = [[JSContext alloc] init];
I don't think it's OK to leak this context forever. Instead, you should use a timer to cache it for a short amount of time and then destroy it.
> Source/WebKit2/UIProcess/API/Cocoa/APISerializedScriptValueCocoa.mm:42 > + if (exception && *exception) > + return nil;
What happens in the case where our caller pass a null exception out parameter? In that case, we have no way to check for exceptions, which seems bad. Can we check valueRef instead, or use some other strategy that allow us to check for exceptions even if exception is null?
Mark Lam
Comment 8
2015-07-01 19:17:03 PDT
Created
attachment 255982
[details]
patch 3: applied Geoff's feedback
Mark Lam
Comment 9
2015-07-02 10:39:32 PDT
(In reply to
comment #8
)
> Created
attachment 255982
[details]
> patch 3: applied Geoff's feedback
For the record, the Win EWS failure is unrelated to this patch.
Anders Carlsson
Comment 10
2015-07-02 10:48:36 PDT
Comment on
attachment 255982
[details]
patch 3: applied Geoff's feedback View in context:
https://bugs.webkit.org/attachment.cgi?id=255982&action=review
> Source/WebKit2/UIProcess/API/Cocoa/APISerializedScriptValueCocoa.mm:65 > + ASSERT(isUIThread());
I think asserting RunLoop::isMain() is better here.
Mark Lam
Comment 11
2015-07-02 11:40:30 PDT
(In reply to
comment #10
)
> > Source/WebKit2/UIProcess/API/Cocoa/APISerializedScriptValueCocoa.mm:65 > > + ASSERT(isUIThread()); > > I think asserting RunLoop::isMain() is better here.
I've applied this change, and re-tested. Landed in
r186229
: <
http://trac.webkit.org/r186229
>.
Chris Dumez
Comment 12
2015-07-02 15:01:26 PDT
(In reply to
comment #11
)
> (In reply to
comment #10
) > > > Source/WebKit2/UIProcess/API/Cocoa/APISerializedScriptValueCocoa.mm:65 > > > + ASSERT(isUIThread()); > > > > I think asserting RunLoop::isMain() is better here. > > I've applied this change, and re-tested. Landed in
r186229
: > <
http://trac.webkit.org/r186229
>.
Broke the build:
https://build.webkit.org/builders/Apple%20Yosemite%20Release%20%2832-bit%20Build%29/builds/4205/steps/compile-webkit/logs/stdio
Chris Dumez
Comment 13
2015-07-02 15:10:57 PDT
Comment on
attachment 255982
[details]
patch 3: applied Geoff's feedback View in context:
https://bugs.webkit.org/attachment.cgi?id=255982&action=review
> Source/WebKit2/UIProcess/API/Cocoa/APISerializedScriptValueCocoa.mm:44 > + JSContext* ensureContext()
Isn't JSContext in JSC namespace?
> Source/WebKit2/UIProcess/API/Cocoa/APISerializedScriptValueCocoa.mm:73 > + JSValue *value = [JSValue valueWithJSValueRef:valueRef inContext:context];
ditto for JSValue.
Anders Carlsson
Comment 14
2015-07-02 15:20:17 PDT
(In reply to
comment #13
)
> Comment on
attachment 255982
[details]
> patch 3: applied Geoff's feedback > > View in context: >
https://bugs.webkit.org/attachment.cgi?id=255982&action=review
> > > Source/WebKit2/UIProcess/API/Cocoa/APISerializedScriptValueCocoa.mm:44 > > + JSContext* ensureContext() > > Isn't JSContext in JSC namespace? > > > Source/WebKit2/UIProcess/API/Cocoa/APISerializedScriptValueCocoa.mm:73 > > + JSValue *value = [JSValue valueWithJSValueRef:valueRef inContext:context]; > > ditto for JSValue.
No, these are the Objective-C types.
Mark Lam
Comment 15
2015-07-02 16:34:06 PDT
Fix for 32-bit build landed in
r186243
: <
http://trac.webkit.org/r186243
>.
Simon Taylor
Comment 16
2020-04-23 10:20:09 PDT
I've added
bug 210920
to request some further improvements here - the shared JSContext used for deserialization is only cached for 1 second from creation, which is non-optimal for heavier users of these APIs and causes some annoyances for debugging.
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug