[Webkit-unassigned] [Bug 75543] [GTK] Add webkit_web_view_run_javascript() to WebKit2 GTK+
bugzilla-daemon at webkit.org
bugzilla-daemon at webkit.org
Sat Feb 18 00:45:31 PST 2012
https://bugs.webkit.org/show_bug.cgi?id=75543
--- Comment #7 from Carlos Garcia Campos <cgarcia at igalia.com> 2012-02-18 00:45:31 PST ---
(In reply to comment #5)
> (From update of attachment 126740 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=126740&action=review
>
> Looks pretty good, but it's an error to access JavaScript values with a different global context.
You mean from a different global context than the one executing the script? because the context where the script executes is in the web process.
> > Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp:1399
> > + JSGlobalContextRef scriptContext = JSGlobalContextCreate(0);
> > + JSValueRef scriptValue = WKSerializedScriptValueDeserialize(wkSerializedScriptValue, scriptContext, 0);
> > + g_simple_async_result_set_op_res_gpointer(result.get(), const_cast<OpaqueJSValue*>(scriptValue), 0);
> > + g_simple_async_result_complete(result.get());
> > + JSGlobalContextRelease(scriptContext);
>
> Instead of creating a temporary JSGlobalContext, it would probably be better to create one with the WebView, so that JavaScriptCore values can stay alive longer.
Ah, so the JSValueRef we return is actually a temp value because it's destroyed by the global context, right? So, is it correct to use the same global context for different scripts? Not that I don't know anything about javascript :-P
> > Source/WebKit2/UIProcess/API/gtk/tests/ScriptContext.cpp:45
> > + JSRetainPtr<JSStringRef> stringValue(Adopt, JSValueToStringCopy(m_context, value, 0));
> > + g_assert(stringValue);
> > +
> > + size_t cStringLength = JSStringGetMaximumUTF8CStringSize(stringValue.get());
> > + char* cString = static_cast<char*>(g_malloc(cStringLength));
> > + JSStringGetUTF8CString(stringValue.get(), cString, cStringLength);
>
> It's important to access the value with the same JSC context that created the value.
Ah, ok you mean the context that deserialized the value, not where the script executed.
> Thus it should probably be passed as property of the AsyncResult or kept as a property of the WebKitWebView.
So, if understand this correctly, we want to use a different context for every javascript execution, to make sure JSValueRefs are accessed with the same context that the one that created deserialized the value. So, I think we could make webkit_web_view_run_javascript_finish return a WebKitJavascripResult object containing the context, the value and the exception. That way the value will be alive until the WebKitJavaScript result is destroyed.
--
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
More information about the webkit-unassigned
mailing list