Title: [229799] trunk
Revision
229799
Author
[email protected]
Date
2018-03-21 01:44:03 -0700 (Wed, 21 Mar 2018)

Log Message

[GTK][WPE] JSC bindings not introspectable
https://bugs.webkit.org/show_bug.cgi?id=136989

Reviewed by Michael Catanzaro.

Source/_javascript_Core:

Make it possible to include individual headers when building WebKit layer.

* API/glib/JSCAutocleanups.h:
* API/glib/JSCClass.h:
* API/glib/JSCContext.h:
* API/glib/JSCException.h:
* API/glib/JSCValue.h:
* API/glib/JSCVersion.h.in:
* API/glib/JSCVirtualMachine.h:

Source/WebKit:

Deprecate the functions that are not introspectable due to JSC C API in GTK+ port and remove them in WPE
port. Add alternative functions using the new JSC GLib API. We no longer need to keep a global context attached
to every view. We can simply create a temporary global context on demand and release it after 1 second. This
also allows us to remove WebPageProxy::_javascript_GlobalContext() and all the related code.

* PlatformGTK.cmake:
* PlatformWPE.cmake:
* UIProcess/API/glib/WebKitJavascriptResult.cpp:
(_WebKitJavascriptResult::_WebKitJavascriptResult):
(webkitJavascriptResultCreate):
(webkit_javascript_result_get_global_context):
(webkit_javascript_result_get_value):
(webkit_javascript_result_get_js_value):
* UIProcess/API/glib/WebKitJavascriptResultPrivate.h:
(SharedJavascriptContext::singleton):
(SharedJavascriptContext::SharedJavascriptContext):
(SharedJavascriptContext::getOrCreateContext):
(SharedJavascriptContext::releaseContext):
* UIProcess/API/glib/WebKitUserContentManager.cpp:
* UIProcess/API/glib/WebKitWebView.cpp:
(webkit_web_view_get_javascript_global_context):
(webkitWebViewRunJavaScriptCallback):
* UIProcess/API/gtk/PageClientImpl.cpp:
* UIProcess/API/gtk/PageClientImpl.h:
* UIProcess/API/gtk/WebKitJavascriptResult.h:
* UIProcess/API/gtk/WebKitWebView.h:
* UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt:
* UIProcess/API/wpe/APIViewClient.h:
(API::ViewClient::handleDownloadRequest):
* UIProcess/API/wpe/PageClientImpl.cpp:
* UIProcess/API/wpe/PageClientImpl.h:
* UIProcess/API/wpe/WPEView.cpp:
* UIProcess/API/wpe/WPEView.h:
* UIProcess/API/wpe/WebKitJavascriptResult.h:
* UIProcess/API/wpe/WebKitWebView.h:
* UIProcess/PageClient.h:
* UIProcess/WebPageProxy.h:
* UIProcess/gtk/WebPageProxyGtk.cpp:
* UIProcess/wpe/WebPageProxyWPE.cpp:
* WebProcess/InjectedBundle/API/glib/WebKitFrame.cpp:
(webkit_frame_get_js_context):
(webkit_frame_get_js_context_for_script_world):
* WebProcess/InjectedBundle/API/gtk/WebKitFrame.h:
* WebProcess/InjectedBundle/API/wpe/WebKitFrame.h:

Tools:

Use the new API instead of the deprecated one.

* MiniBrowser/gtk/main.c:
(aboutDataScriptMessageReceivedCallback):
* TestWebKitAPI/Tests/WebKitGLib/FrameTest.cpp:
(WebKitFrameTest::testJavaScriptContext):
* TestWebKitAPI/Tests/WebKitGLib/TestWebKitWebView.cpp:
(testWebViewRunJavaScript):
* TestWebKitAPI/Tests/WebKitGLib/WebExtensionTest.cpp:
(consoleMessageSentCallback):
(echoCallback):
(windowObjectCleared):
(methodCallCallback):
* TestWebKitAPI/Tests/WebKitGLib/WebProcessTest.cpp:
(runTest):
(webProcessTestRunnerFinalize):
(windowObjectClearedCallback):
* TestWebKitAPI/glib/PlatformGTK.cmake:
* TestWebKitAPI/glib/WebKitGLib/WebViewTest.cpp:
(WebViewTest::_javascript_ResultToCString):
(WebViewTest::_javascript_ResultToNumber):
(WebViewTest::_javascript_ResultToBoolean):
(WebViewTest::_javascript_ResultIsNull):
(WebViewTest::_javascript_ResultIsUndefined):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/API/glib/JSCAutocleanups.h (229798 => 229799)


--- trunk/Source/_javascript_Core/API/glib/JSCAutocleanups.h	2018-03-21 08:42:08 UTC (rev 229798)
+++ trunk/Source/_javascript_Core/API/glib/JSCAutocleanups.h	2018-03-21 08:44:03 UTC (rev 229799)
@@ -17,7 +17,7 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#if !defined(__JSC_H_INSIDE__) && !defined(JSC_COMPILATION)
+#if !defined(__JSC_H_INSIDE__) && !defined(JSC_COMPILATION) && !defined(WEBKIT2_COMPILATION)
 #error "Only <jsc/jsc.h> can be included directly."
 #endif
 

Modified: trunk/Source/_javascript_Core/API/glib/JSCClass.h (229798 => 229799)


--- trunk/Source/_javascript_Core/API/glib/JSCClass.h	2018-03-21 08:42:08 UTC (rev 229798)
+++ trunk/Source/_javascript_Core/API/glib/JSCClass.h	2018-03-21 08:44:03 UTC (rev 229799)
@@ -17,7 +17,7 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#if !defined(__JSC_H_INSIDE__) && !defined(JSC_COMPILATION)
+#if !defined(__JSC_H_INSIDE__) && !defined(JSC_COMPILATION) && !defined(WEBKIT2_COMPILATION)
 #error "Only <jsc/jsc.h> can be included directly."
 #endif
 

Modified: trunk/Source/_javascript_Core/API/glib/JSCContext.h (229798 => 229799)


--- trunk/Source/_javascript_Core/API/glib/JSCContext.h	2018-03-21 08:42:08 UTC (rev 229798)
+++ trunk/Source/_javascript_Core/API/glib/JSCContext.h	2018-03-21 08:44:03 UTC (rev 229799)
@@ -17,7 +17,7 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#if !defined(__JSC_H_INSIDE__) && !defined(JSC_COMPILATION)
+#if !defined(__JSC_H_INSIDE__) && !defined(JSC_COMPILATION) && !defined(WEBKIT2_COMPILATION)
 #error "Only <jsc/jsc.h> can be included directly."
 #endif
 

Modified: trunk/Source/_javascript_Core/API/glib/JSCException.h (229798 => 229799)


--- trunk/Source/_javascript_Core/API/glib/JSCException.h	2018-03-21 08:42:08 UTC (rev 229798)
+++ trunk/Source/_javascript_Core/API/glib/JSCException.h	2018-03-21 08:44:03 UTC (rev 229799)
@@ -17,7 +17,7 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#if !defined(__JSC_H_INSIDE__) && !defined(JSC_COMPILATION)
+#if !defined(__JSC_H_INSIDE__) && !defined(JSC_COMPILATION) && !defined(WEBKIT2_COMPILATION)
 #error "Only <jsc/jsc.h> can be included directly."
 #endif
 

Modified: trunk/Source/_javascript_Core/API/glib/JSCValue.h (229798 => 229799)


--- trunk/Source/_javascript_Core/API/glib/JSCValue.h	2018-03-21 08:42:08 UTC (rev 229798)
+++ trunk/Source/_javascript_Core/API/glib/JSCValue.h	2018-03-21 08:44:03 UTC (rev 229799)
@@ -17,7 +17,7 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#if !defined(__JSC_H_INSIDE__) && !defined(JSC_COMPILATION)
+#if !defined(__JSC_H_INSIDE__) && !defined(JSC_COMPILATION) && !defined(WEBKIT2_COMPILATION)
 #error "Only <jsc/jsc.h> can be included directly."
 #endif
 

Modified: trunk/Source/_javascript_Core/API/glib/JSCVersion.h.in (229798 => 229799)


--- trunk/Source/_javascript_Core/API/glib/JSCVersion.h.in	2018-03-21 08:42:08 UTC (rev 229798)
+++ trunk/Source/_javascript_Core/API/glib/JSCVersion.h.in	2018-03-21 08:44:03 UTC (rev 229799)
@@ -17,7 +17,7 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#if !defined(__JSC_H_INSIDE__) && !defined(JSC_COMPILATION)
+#if !defined(__JSC_H_INSIDE__) && !defined(JSC_COMPILATION) && !defined(WEBKIT2_COMPILATION)
 #error "Only <jsc/jsc.h> can be included directly."
 #endif
 

Modified: trunk/Source/_javascript_Core/API/glib/JSCVirtualMachine.h (229798 => 229799)


--- trunk/Source/_javascript_Core/API/glib/JSCVirtualMachine.h	2018-03-21 08:42:08 UTC (rev 229798)
+++ trunk/Source/_javascript_Core/API/glib/JSCVirtualMachine.h	2018-03-21 08:44:03 UTC (rev 229799)
@@ -17,7 +17,7 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#if !defined(__JSC_H_INSIDE__) && !defined(JSC_COMPILATION)
+#if !defined(__JSC_H_INSIDE__) && !defined(JSC_COMPILATION) && !defined(WEBKIT2_COMPILATION)
 #error "Only <jsc/jsc.h> can be included directly."
 #endif
 

Modified: trunk/Source/_javascript_Core/ChangeLog (229798 => 229799)


--- trunk/Source/_javascript_Core/ChangeLog	2018-03-21 08:42:08 UTC (rev 229798)
+++ trunk/Source/_javascript_Core/ChangeLog	2018-03-21 08:44:03 UTC (rev 229799)
@@ -1,5 +1,22 @@
 2018-03-21  Carlos Garcia Campos  <[email protected]>
 
+        [GTK][WPE] JSC bindings not introspectable
+        https://bugs.webkit.org/show_bug.cgi?id=136989
+
+        Reviewed by Michael Catanzaro.
+
+        Make it possible to include individual headers when building WebKit layer.
+
+        * API/glib/JSCAutocleanups.h:
+        * API/glib/JSCClass.h:
+        * API/glib/JSCContext.h:
+        * API/glib/JSCException.h:
+        * API/glib/JSCValue.h:
+        * API/glib/JSCVersion.h.in:
+        * API/glib/JSCVirtualMachine.h:
+
+2018-03-21  Carlos Garcia Campos  <[email protected]>
+
         [GTK][WPE] Initial implementation of _javascript_Core glib bindings
         https://bugs.webkit.org/show_bug.cgi?id=164061
 

Modified: trunk/Source/WebKit/ChangeLog (229798 => 229799)


--- trunk/Source/WebKit/ChangeLog	2018-03-21 08:42:08 UTC (rev 229798)
+++ trunk/Source/WebKit/ChangeLog	2018-03-21 08:44:03 UTC (rev 229799)
@@ -1,5 +1,57 @@
 2018-03-21  Carlos Garcia Campos  <[email protected]>
 
+        [GTK][WPE] JSC bindings not introspectable
+        https://bugs.webkit.org/show_bug.cgi?id=136989
+
+        Reviewed by Michael Catanzaro.
+
+        Deprecate the functions that are not introspectable due to JSC C API in GTK+ port and remove them in WPE
+        port. Add alternative functions using the new JSC GLib API. We no longer need to keep a global context attached
+        to every view. We can simply create a temporary global context on demand and release it after 1 second. This
+        also allows us to remove WebPageProxy::_javascript_GlobalContext() and all the related code.
+
+        * PlatformGTK.cmake:
+        * PlatformWPE.cmake:
+        * UIProcess/API/glib/WebKitJavascriptResult.cpp:
+        (_WebKitJavascriptResult::_WebKitJavascriptResult):
+        (webkitJavascriptResultCreate):
+        (webkit_javascript_result_get_global_context):
+        (webkit_javascript_result_get_value):
+        (webkit_javascript_result_get_js_value):
+        * UIProcess/API/glib/WebKitJavascriptResultPrivate.h:
+        (SharedJavascriptContext::singleton):
+        (SharedJavascriptContext::SharedJavascriptContext):
+        (SharedJavascriptContext::getOrCreateContext):
+        (SharedJavascriptContext::releaseContext):
+        * UIProcess/API/glib/WebKitUserContentManager.cpp:
+        * UIProcess/API/glib/WebKitWebView.cpp:
+        (webkit_web_view_get_javascript_global_context):
+        (webkitWebViewRunJavaScriptCallback):
+        * UIProcess/API/gtk/PageClientImpl.cpp:
+        * UIProcess/API/gtk/PageClientImpl.h:
+        * UIProcess/API/gtk/WebKitJavascriptResult.h:
+        * UIProcess/API/gtk/WebKitWebView.h:
+        * UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt:
+        * UIProcess/API/wpe/APIViewClient.h:
+        (API::ViewClient::handleDownloadRequest):
+        * UIProcess/API/wpe/PageClientImpl.cpp:
+        * UIProcess/API/wpe/PageClientImpl.h:
+        * UIProcess/API/wpe/WPEView.cpp:
+        * UIProcess/API/wpe/WPEView.h:
+        * UIProcess/API/wpe/WebKitJavascriptResult.h:
+        * UIProcess/API/wpe/WebKitWebView.h:
+        * UIProcess/PageClient.h:
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/gtk/WebPageProxyGtk.cpp:
+        * UIProcess/wpe/WebPageProxyWPE.cpp:
+        * WebProcess/InjectedBundle/API/glib/WebKitFrame.cpp:
+        (webkit_frame_get_js_context):
+        (webkit_frame_get_js_context_for_script_world):
+        * WebProcess/InjectedBundle/API/gtk/WebKitFrame.h:
+        * WebProcess/InjectedBundle/API/wpe/WebKitFrame.h:
+
+2018-03-21  Carlos Garcia Campos  <[email protected]>
+
         [GTK][WPE] Initial implementation of _javascript_Core glib bindings
         https://bugs.webkit.org/show_bug.cgi?id=164061
 

Modified: trunk/Source/WebKit/PlatformGTK.cmake (229798 => 229799)


--- trunk/Source/WebKit/PlatformGTK.cmake	2018-03-21 08:42:08 UTC (rev 229798)
+++ trunk/Source/WebKit/PlatformGTK.cmake	2018-03-21 08:44:03 UTC (rev 229799)
@@ -366,6 +366,9 @@
 )
 
 list(APPEND WebKit_INCLUDE_DIRECTORIES
+    "${DERIVED_SOURCES_JAVASCRIPCOREGTK_DIR}"
+    "${FORWARDING_HEADERS_DIR}/_javascript_Core/"
+    "${FORWARDING_HEADERS_DIR}/_javascript_Core/glib"
     "${WEBKIT_DIR}/PluginProcess/unix"
     "${WEBKIT_DIR}/NetworkProcess/CustomProtocols/soup"
     "${WEBKIT_DIR}/NetworkProcess/Downloads/soup"
@@ -762,7 +765,9 @@
             -I${WEBKIT_DIR}
             -I${DERIVED_SOURCES_DIR}
             -I${DERIVED_SOURCES_WEBKIT2GTK_DIR}
+            -I${DERIVED_SOURCES_JAVASCRIPCOREGTK_DIR}
             -I${FORWARDING_HEADERS_DIR}
+            -I${FORWARDING_HEADERS_DIR}/_javascript_Core/glib
             -I${FORWARDING_HEADERS_WEBKIT2GTK_DIR}
             ${WebKit2GTK_INSTALLED_HEADERS}
             ${WEBKIT_DIR}/Shared/API/glib/*.cpp
@@ -806,7 +811,9 @@
             -I${WEBKIT_DIR}
             -I${DERIVED_SOURCES_DIR}
             -I${DERIVED_SOURCES_WEBKIT2GTK_DIR}
+            -I${DERIVED_SOURCES_JAVASCRIPCOREGTK_DIR}
             -I${FORWARDING_HEADERS_DIR}
+            -I${FORWARDING_HEADERS_DIR}/_javascript_Core/glib
             -I${FORWARDING_HEADERS_WEBKIT2GTK_DIR}
             -I${FORWARDING_HEADERS_WEBKIT2GTK_EXTENSION_DIR}
             -I${WEBKIT_DIR}/WebProcess/InjectedBundle/API/gtk

Modified: trunk/Source/WebKit/PlatformWPE.cmake (229798 => 229799)


--- trunk/Source/WebKit/PlatformWPE.cmake	2018-03-21 08:42:08 UTC (rev 229798)
+++ trunk/Source/WebKit/PlatformWPE.cmake	2018-03-21 08:44:03 UTC (rev 229799)
@@ -178,7 +178,10 @@
 )
 
 list(APPEND WebKit_INCLUDE_DIRECTORIES
+    "${DERIVED_SOURCES_JAVASCRIPCOREWPE_DIR}"
     "${FORWARDING_HEADERS_DIR}"
+    "${FORWARDING_HEADERS_DIR}/_javascript_Core/"
+    "${FORWARDING_HEADERS_DIR}/_javascript_Core/glib"
     "${FORWARDING_HEADERS_WPE_DIR}"
     "${FORWARDING_HEADERS_WPE_EXTENSION_DIR}"
     "${DERIVED_SOURCES_DIR}"

Modified: trunk/Source/WebKit/UIProcess/API/glib/WebKitJavascriptResult.cpp (229798 => 229799)


--- trunk/Source/WebKit/UIProcess/API/glib/WebKitJavascriptResult.cpp	2018-03-21 08:42:08 UTC (rev 229798)
+++ trunk/Source/WebKit/UIProcess/API/glib/WebKitJavascriptResult.cpp	2018-03-21 08:44:03 UTC (rev 229799)
@@ -22,29 +22,27 @@
 
 #include "APISerializedScriptValue.h"
 #include "WebKitJavascriptResultPrivate.h"
-#include <_javascript_Core/JSRetainPtr.h>
-#include <wtf/glib/GRefPtr.h>
+#include <jsc/JSCContextPrivate.h>
+#include <jsc/JSCValuePrivate.h>
 
 struct _WebKitJavascriptResult {
-    _WebKitJavascriptResult(JSGlobalContextRef jsContext, WebCore::SerializedScriptValue& serializedScriptValue)
-        : _javascript_GlobalContext(jsContext)
-        , referenceCount(1)
+    explicit _WebKitJavascriptResult(WebCore::SerializedScriptValue& serializedScriptValue)
     {
-        value = serializedScriptValue.deserialize(_javascript_GlobalContext.get(), nullptr);
+        auto* jsContext = SharedJavascriptContext::singleton().getOrCreateContext();
+        jsValue = jscContextGetOrCreateValue(jsContext, serializedScriptValue.deserialize(jscContextGetJSContext(jsContext), nullptr));
     }
 
-    JSRetainPtr<JSGlobalContextRef> _javascript_GlobalContext;
-    JSValueRef value;
+    GRefPtr<JSCValue> jsValue;
 
-    int referenceCount;
+    int referenceCount { 1 };
 };
 
 G_DEFINE_BOXED_TYPE(WebKitJavascriptResult, webkit_javascript_result, webkit_javascript_result_ref, webkit_javascript_result_unref)
 
-WebKitJavascriptResult* webkitJavascriptResultCreate(JSGlobalContextRef _javascript_GlobalContext, WebCore::SerializedScriptValue& serializedScriptValue)
+WebKitJavascriptResult* webkitJavascriptResultCreate(WebCore::SerializedScriptValue& serializedScriptValue)
 {
     WebKitJavascriptResult* result = static_cast<WebKitJavascriptResult*>(fastMalloc(sizeof(WebKitJavascriptResult)));
-    new (result) WebKitJavascriptResult(_javascript_GlobalContext, serializedScriptValue);
+    new (result) WebKitJavascriptResult(serializedScriptValue);
     return result;
 }
 
@@ -80,6 +78,7 @@
     }
 }
 
+#if PLATFORM(GTK)
 /**
  * webkit_javascript_result_get_global_context:
  * @js_result: a #WebKitJavascriptResult
@@ -88,10 +87,13 @@
  * <function>JSValueRef</function> returned by webkit_javascript_result_get_value().
  *
  * Returns: the <function>JSGlobalContextRef</function> for the #WebKitJavascriptResult
+ *
+ * Deprecated: 2.22: Use jsc_value_get_context() instead.
  */
 JSGlobalContextRef webkit_javascript_result_get_global_context(WebKitJavascriptResult* _javascript_Result)
 {
-    return _javascript_Result->_javascript_GlobalContext.get();
+    g_return_val_if_fail(_javascript_Result, nullptr);
+    return jscContextGetJSContext(jsc_value_get_context(_javascript_Result->jsValue.get()));
 }
 
 /**
@@ -102,8 +104,28 @@
  * returned by webkit_javascript_result_get_global_context() to use the <function>JSValueRef</function>.
  *
  * Returns: the <function>JSValueRef</function> of the #WebKitJavascriptResult
+ *
+ * Deprecated: 2.22: Use webkit_javascript_result_get_js_value() instead.
  */
 JSValueRef webkit_javascript_result_get_value(WebKitJavascriptResult* _javascript_Result)
 {
-    return _javascript_Result->value;
+    g_return_val_if_fail(_javascript_Result, nullptr);
+    return jscValueGetJSValue(_javascript_Result->jsValue.get());
 }
+#endif
+
+/**
+ * webkit_javascript_result_get_js_value:
+ * @js_result: a #WebKitJavascriptResult
+ *
+ * Get the #JSCValue of @js_result.
+ *
+ * Returns: (transfer none): the #JSCValue of the #WebKitJavascriptResult
+ *
+ * Since: 2.22
+ */
+JSCValue* webkit_javascript_result_get_js_value(WebKitJavascriptResult* _javascript_Result)
+{
+    g_return_val_if_fail(_javascript_Result, nullptr);
+    return _javascript_Result->jsValue.get();
+}

Modified: trunk/Source/WebKit/UIProcess/API/glib/WebKitJavascriptResultPrivate.h (229798 => 229799)


--- trunk/Source/WebKit/UIProcess/API/glib/WebKitJavascriptResultPrivate.h	2018-03-21 08:42:08 UTC (rev 229798)
+++ trunk/Source/WebKit/UIProcess/API/glib/WebKitJavascriptResultPrivate.h	2018-03-21 08:44:03 UTC (rev 229799)
@@ -21,5 +21,40 @@
 
 #include <WebCore/SerializedScriptValue.h>
 #include "WebKitJavascriptResult.h"
+#include <wtf/NeverDestroyed.h>
+#include <wtf/RunLoop.h>
+#include <wtf/glib/GRefPtr.h>
 
-WebKitJavascriptResult* webkitJavascriptResultCreate(JSGlobalContextRef, WebCore::SerializedScriptValue&);
+class SharedJavascriptContext {
+public:
+    static SharedJavascriptContext& singleton()
+    {
+        static NeverDestroyed<SharedJavascriptContext> context;
+        return context;
+    }
+
+    SharedJavascriptContext()
+        : m_timer(RunLoop::main(), this, &SharedJavascriptContext::releaseContext)
+    {
+    }
+
+    JSCContext* getOrCreateContext()
+    {
+        if (!m_context) {
+            m_context = adoptGRef(jsc_context_new());
+            m_timer.startOneShot(1_s);
+        }
+        return m_context.get();
+    }
+
+private:
+    void releaseContext()
+    {
+        m_context = nullptr;
+    }
+
+    GRefPtr<JSCContext> m_context;
+    RunLoop::Timer<SharedJavascriptContext> m_timer;
+};
+
+WebKitJavascriptResult* webkitJavascriptResultCreate(WebCore::SerializedScriptValue&);

Modified: trunk/Source/WebKit/UIProcess/API/glib/WebKitUserContentManager.cpp (229798 => 229799)


--- trunk/Source/WebKit/UIProcess/API/glib/WebKitUserContentManager.cpp	2018-03-21 08:42:08 UTC (rev 229798)
+++ trunk/Source/WebKit/UIProcess/API/glib/WebKitUserContentManager.cpp	2018-03-21 08:44:03 UTC (rev 229799)
@@ -188,9 +188,9 @@
     {
     }
 
-    void didPostMessage(WebPageProxy& page, const FrameInfoData&, WebCore::SerializedScriptValue& serializedScriptValue) override
+    void didPostMessage(WebPageProxy&, const FrameInfoData&, WebCore::SerializedScriptValue& serializedScriptValue) override
     {
-        WebKitJavascriptResult* jsResult = webkitJavascriptResultCreate(page._javascript_GlobalContext(), serializedScriptValue);
+        WebKitJavascriptResult* jsResult = webkitJavascriptResultCreate(serializedScriptValue);
         g_signal_emit(m_manager, signals[SCRIPT_MESSAGE_RECEIVED], m_handlerName, jsResult);
         webkit_javascript_result_unref(jsResult);
     }

Modified: trunk/Source/WebKit/UIProcess/API/glib/WebKitWebView.cpp (229798 => 229799)


--- trunk/Source/WebKit/UIProcess/API/glib/WebKitWebView.cpp	2018-03-21 08:42:08 UTC (rev 229798)
+++ trunk/Source/WebKit/UIProcess/API/glib/WebKitWebView.cpp	2018-03-21 08:44:03 UTC (rev 229799)
@@ -62,6 +62,7 @@
 #include "WebKitWindowPropertiesPrivate.h"
 #include <_javascript_Core/APICast.h>
 #include <_javascript_Core/JSRetainPtr.h>
+#include <jsc/JSCContextPrivate.h>
 #include <WebCore/CertificateInfo.h>
 #include <WebCore/GUniquePtrSoup.h>
 #include <WebCore/JSDOMExceptionHandling.h>
@@ -228,7 +229,6 @@
     WebEvent::Modifiers mouseTargetModifiers;
 
     GRefPtr<WebKitFindController> findController;
-    JSRetainPtr<JSGlobalContextRef> _javascript_GlobalContext;
 
     GRefPtr<WebKitWebResource> mainResource;
     LoadingResourcesMap loadingResourcesMap;
@@ -236,6 +236,8 @@
     WebKitScriptDialog* currentScriptDialog;
 
 #if PLATFORM(GTK)
+    GRefPtr<JSCContext> jsContext;
+
     GRefPtr<WebKitWebInspector> inspector;
 
     RefPtr<cairo_surface_t> favicon;
@@ -367,11 +369,6 @@
         webkitWebViewHandleDownloadRequest(m_webView, &downloadProxy);
     }
 
-    JSGlobalContextRef _javascript_GlobalContext() override
-    {
-        return webkit_web_view_get_javascript_global_context(m_webView);
-    }
-
     WebKitWebView* m_webView;
 };
 #endif
@@ -3250,6 +3247,7 @@
     return webView->priv->findController.get();
 }
 
+#if PLATFORM(GTK)
 /**
  * webkit_web_view_get_javascript_global_context:
  * @web_view: a #WebKitWebView
@@ -3259,15 +3257,20 @@
  *
  * Returns: the <function>JSGlobalContextRef</function> used by @web_view to deserialize
  *    the result values of scripts.
+ *
+ * Deprecated: 2.22: Use jsc_value_get_context() instead.
  */
 JSGlobalContextRef webkit_web_view_get_javascript_global_context(WebKitWebView* webView)
 {
     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), nullptr);
 
-    if (!webView->priv->_javascript_GlobalContext)
-        webView->priv->_javascript_GlobalContext = adopt(JSGlobalContextCreate(nullptr));
-    return webView->priv->_javascript_GlobalContext.get();
+    // We keep a reference to the js context in the view only when this method is called
+    // for backwards compatibility.
+    if (!webView->priv->jsContext)
+        webView->priv->jsContext = SharedJavascriptContext::singleton().getOrCreateContext();
+    return jscContextGetJSContext(webView->priv->jsContext.get());
 }
+#endif
 
 static void webkitWebViewRunJavaScriptCallback(API::SerializedScriptValue* wkSerializedScriptValue, const ExceptionDetails& exceptionDetails, GTask* task)
 {
@@ -3294,9 +3297,7 @@
         return;
     }
 
-    auto* jsContext = webkit_web_view_get_javascript_global_context(WEBKIT_WEB_VIEW(g_task_get_source_object(task)));
-    g_task_return_pointer(task, webkitJavascriptResultCreate(jsContext,
-        wkSerializedScriptValue->internalRepresentation()),
+    g_task_return_pointer(task, webkitJavascriptResultCreate(wkSerializedScriptValue->internalRepresentation()),
         reinterpret_cast<GDestroyNotify>(webkit_javascript_result_unref));
 }
 
@@ -3343,8 +3344,7 @@
  *                               gpointer      user_data)
  * {
  *     WebKitJavascriptResult *js_result;
- *     JSValueRef              value;
- *     JSGlobalContextRef      context;
+ *     JSCValue               *value;
  *     GError                 *error = NULL;
  *
  *     js_result = webkit_web_view_run_javascript_finish (WEBKIT_WEB_VIEW (object), result, &error);
@@ -3354,19 +3354,17 @@
  *         return;
  *     }
  *
- *     context = webkit_javascript_result_get_global_context (js_result);
- *     value = webkit_javascript_result_get_value (js_result);
- *     if (JSValueIsString (context, value)) {
- *         JSStringRef js_str_value;
- *         gchar      *str_value;
- *         gsize       str_length;
+ *     value = webkit_javascript_result_get_js_value (js_result);
+ *     if (jsc_value_is_string (value)) {
+ *         JSCException *exception;
+ *         gchar        *str_value;
  *
- *         js_str_value = JSValueToStringCopy (context, value, NULL);
- *         str_length = JSStringGetMaximumUTF8CStringSize (js_str_value);
- *         str_value = (gchar *)g_malloc (str_length);
- *         JSStringGetUTF8CString (js_str_value, str_value, str_length);
- *         JSStringRelease (js_str_value);
- *         g_print ("Script result: %s\n", str_value);
+ *         str_value = jsc_value_to_string (value);
+ *         exception = jsc_context_get_exception (jsc_value_get_context (value));
+ *         if (exception)
+ *             g_warning ("Error running _javascript_: %s", jsc_exception_get_message (exception));
+ *         else
+ *             g_print ("Script result: %s\n", str_value);
  *         g_free (str_value);
  *     } else {
  *         g_warning ("Error running _javascript_: unexpected return value");

Modified: trunk/Source/WebKit/UIProcess/API/gtk/PageClientImpl.cpp (229798 => 229799)


--- trunk/Source/WebKit/UIProcess/API/gtk/PageClientImpl.cpp	2018-03-21 08:42:08 UTC (rev 229798)
+++ trunk/Source/WebKit/UIProcess/API/gtk/PageClientImpl.cpp	2018-03-21 08:44:03 UTC (rev 229799)
@@ -474,14 +474,6 @@
 }
 #endif
 
-JSGlobalContextRef PageClientImpl::_javascript_GlobalContext()
-{
-    if (!WEBKIT_IS_WEB_VIEW(m_viewWidget))
-        return nullptr;
-
-    return webkit_web_view_get_javascript_global_context(WEBKIT_WEB_VIEW(m_viewWidget));
-}
-
 void PageClientImpl::zoom(double zoomLevel)
 {
     if (WEBKIT_IS_WEB_VIEW(m_viewWidget)) {

Modified: trunk/Source/WebKit/UIProcess/API/gtk/PageClientImpl.h (229798 => 229799)


--- trunk/Source/WebKit/UIProcess/API/gtk/PageClientImpl.h	2018-03-21 08:42:08 UTC (rev 229798)
+++ trunk/Source/WebKit/UIProcess/API/gtk/PageClientImpl.h	2018-03-21 08:44:03 UTC (rev 229799)
@@ -149,8 +149,6 @@
 
     WebCore::UserInterfaceLayoutDirection userInterfaceLayoutDirection() override { return WebCore::UserInterfaceLayoutDirection::LTR; }
 
-    JSGlobalContextRef _javascript_GlobalContext() override;
-
     // Members of PageClientImpl class
     GtkWidget* m_viewWidget;
     DefaultUndoController m_undoController;

Modified: trunk/Source/WebKit/UIProcess/API/gtk/WebKitJavascriptResult.h (229798 => 229799)


--- trunk/Source/WebKit/UIProcess/API/gtk/WebKitJavascriptResult.h	2018-03-21 08:42:08 UTC (rev 229798)
+++ trunk/Source/WebKit/UIProcess/API/gtk/WebKitJavascriptResult.h	2018-03-21 08:44:03 UTC (rev 229799)
@@ -25,6 +25,7 @@
 #define WebKitJavascriptResult_h
 
 #include <_javascript_Core/JSBase.h>
+#include <jsc/jsc.h>
 #include <glib-object.h>
 #include <webkit2/WebKitDefines.h>
 
@@ -44,12 +45,15 @@
 WEBKIT_API void
 webkit_javascript_result_unref              (WebKitJavascriptResult *js_result);
 
-WEBKIT_API JSGlobalContextRef
+WEBKIT_DEPRECATED JSGlobalContextRef
 webkit_javascript_result_get_global_context (WebKitJavascriptResult *js_result);
 
-WEBKIT_API JSValueRef
+WEBKIT_DEPRECATED_FOR(webkit_javascript_result_get_js_value) JSValueRef
 webkit_javascript_result_get_value          (WebKitJavascriptResult *js_result);
 
+WEBKIT_API JSCValue *
+webkit_javascript_result_get_js_value       (WebKitJavascriptResult *js_result);
+
 G_END_DECLS
 
 #endif

Modified: trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebView.h (229798 => 229799)


--- trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebView.h	2018-03-21 08:42:08 UTC (rev 229798)
+++ trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebView.h	2018-03-21 08:44:03 UTC (rev 229799)
@@ -430,7 +430,7 @@
 WEBKIT_API WebKitFindController *
 webkit_web_view_get_find_controller                  (WebKitWebView             *web_view);
 
-WEBKIT_API JSGlobalContextRef
+WEBKIT_DEPRECATED JSGlobalContextRef
 webkit_web_view_get_javascript_global_context        (WebKitWebView             *web_view);
 
 WEBKIT_API void

Modified: trunk/Source/WebKit/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt (229798 => 229799)


--- trunk/Source/WebKit/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt	2018-03-21 08:42:08 UTC (rev 229798)
+++ trunk/Source/WebKit/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt	2018-03-21 08:44:03 UTC (rev 229799)
@@ -232,6 +232,7 @@
 webkit_javascript_result_unref
 webkit_javascript_result_get_global_context
 webkit_javascript_result_get_value
+webkit_javascript_result_get_js_value
 
 <SUBSECTION WebKitScriptDialog>
 WebKitScriptDialog
@@ -1487,6 +1488,8 @@
 webkit_frame_get_uri
 webkit_frame_get_javascript_global_context
 webkit_frame_get_javascript_context_for_script_world
+webkit_frame_get_js_context
+webkit_frame_get_js_context_for_script_world
 
 <SUBSECTION Standard>
 WebKitFrameClass

Modified: trunk/Source/WebKit/UIProcess/API/wpe/APIViewClient.h (229798 => 229799)


--- trunk/Source/WebKit/UIProcess/API/wpe/APIViewClient.h	2018-03-21 08:42:08 UTC (rev 229798)
+++ trunk/Source/WebKit/UIProcess/API/wpe/APIViewClient.h	2018-03-21 08:44:03 UTC (rev 229799)
@@ -43,7 +43,6 @@
 
     virtual void frameDisplayed(WKWPE::View&) { }
     virtual void handleDownloadRequest(WKWPE::View&, WebKit::DownloadProxy&) { }
-    virtual JSGlobalContextRef _javascript_GlobalContext() { return nullptr; }
 };
 
 } // namespace API

Modified: trunk/Source/WebKit/UIProcess/API/wpe/PageClientImpl.cpp (229798 => 229799)


--- trunk/Source/WebKit/UIProcess/API/wpe/PageClientImpl.cpp	2018-03-21 08:42:08 UTC (rev 229798)
+++ trunk/Source/WebKit/UIProcess/API/wpe/PageClientImpl.cpp	2018-03-21 08:44:03 UTC (rev 229799)
@@ -321,9 +321,4 @@
     return WebCore::UserInterfaceLayoutDirection::LTR;
 }
 
-JSGlobalContextRef PageClientImpl::_javascript_GlobalContext()
-{
-    return m_view._javascript_GlobalContext();
-}
-
 } // namespace WebKit

Modified: trunk/Source/WebKit/UIProcess/API/wpe/PageClientImpl.h (229798 => 229799)


--- trunk/Source/WebKit/UIProcess/API/wpe/PageClientImpl.h	2018-03-21 08:42:08 UTC (rev 229798)
+++ trunk/Source/WebKit/UIProcess/API/wpe/PageClientImpl.h	2018-03-21 08:44:03 UTC (rev 229799)
@@ -119,8 +119,6 @@
 
     WebCore::UserInterfaceLayoutDirection userInterfaceLayoutDirection() override;
 
-    JSGlobalContextRef _javascript_GlobalContext() override;
-
     WKWPE::View& m_view;
 
     std::unique_ptr<ScrollGestureController> m_scrollGestureController;

Modified: trunk/Source/WebKit/UIProcess/API/wpe/WPEView.cpp (229798 => 229799)


--- trunk/Source/WebKit/UIProcess/API/wpe/WPEView.cpp	2018-03-21 08:42:08 UTC (rev 229798)
+++ trunk/Source/WebKit/UIProcess/API/wpe/WPEView.cpp	2018-03-21 08:44:03 UTC (rev 229799)
@@ -35,7 +35,6 @@
 #include "NativeWebWheelEvent.h"
 #include "WebPageGroup.h"
 #include "WebProcessPool.h"
-#include <_javascript_Core/JSBase.h>
 #include <wpe/view-backend.h>
 
 using namespace WebKit;
@@ -156,11 +155,6 @@
     m_client->handleDownloadRequest(*this, download);
 }
 
-JSGlobalContextRef View::_javascript_GlobalContext()
-{
-    return m_client->_javascript_GlobalContext();
-}
-
 void View::setSize(const WebCore::IntSize& size)
 {
     m_size = size;

Modified: trunk/Source/WebKit/UIProcess/API/wpe/WPEView.h (229798 => 229799)


--- trunk/Source/WebKit/UIProcess/API/wpe/WPEView.h	2018-03-21 08:42:08 UTC (rev 229798)
+++ trunk/Source/WebKit/UIProcess/API/wpe/WPEView.h	2018-03-21 08:44:03 UTC (rev 229799)
@@ -60,7 +60,6 @@
     void setClient(std::unique_ptr<API::ViewClient>&&);
     void frameDisplayed();
     void handleDownloadRequest(WebKit::DownloadProxy&);
-    JSGlobalContextRef _javascript_GlobalContext();
 
     WebKit::WebPageProxy& page() { return *m_pageProxy; }
 

Modified: trunk/Source/WebKit/UIProcess/API/wpe/WebKitJavascriptResult.h (229798 => 229799)


--- trunk/Source/WebKit/UIProcess/API/wpe/WebKitJavascriptResult.h	2018-03-21 08:42:08 UTC (rev 229798)
+++ trunk/Source/WebKit/UIProcess/API/wpe/WebKitJavascriptResult.h	2018-03-21 08:44:03 UTC (rev 229799)
@@ -24,8 +24,8 @@
 #ifndef WebKitJavascriptResult_h
 #define WebKitJavascriptResult_h
 
-#include <_javascript_Core/JSBase.h>
 #include <glib-object.h>
+#include <jsc/jsc.h>
 #include <wpe/WebKitDefines.h>
 
 G_BEGIN_DECLS
@@ -44,12 +44,9 @@
 WEBKIT_API void
 webkit_javascript_result_unref              (WebKitJavascriptResult *js_result);
 
-WEBKIT_API JSGlobalContextRef
-webkit_javascript_result_get_global_context (WebKitJavascriptResult *js_result);
+WEBKIT_API JSCValue *
+webkit_javascript_result_get_js_value       (WebKitJavascriptResult *js_result);
 
-WEBKIT_API JSValueRef
-webkit_javascript_result_get_value          (WebKitJavascriptResult *js_result);
-
 G_END_DECLS
 
 #endif

Modified: trunk/Source/WebKit/UIProcess/API/wpe/WebKitWebView.h (229798 => 229799)


--- trunk/Source/WebKit/UIProcess/API/wpe/WebKitWebView.h	2018-03-21 08:42:08 UTC (rev 229798)
+++ trunk/Source/WebKit/UIProcess/API/wpe/WebKitWebView.h	2018-03-21 08:44:03 UTC (rev 229799)
@@ -28,7 +28,6 @@
 #ifndef WebKitWebView_h
 #define WebKitWebView_h
 
-#include <_javascript_Core/JSBase.h>
 #include <wpe/WebKitAuthenticationRequest.h>
 #include <wpe/WebKitBackForwardList.h>
 #include <wpe/WebKitContextMenu.h>
@@ -400,9 +399,6 @@
 WEBKIT_API WebKitFindController *
 webkit_web_view_get_find_controller                  (WebKitWebView             *web_view);
 
-WEBKIT_API JSGlobalContextRef
-webkit_web_view_get_javascript_global_context        (WebKitWebView             *web_view);
-
 WEBKIT_API void
 webkit_web_view_run_javascript                       (WebKitWebView             *web_view,
                                                       const gchar               *script,

Modified: trunk/Source/WebKit/UIProcess/PageClient.h (229798 => 229799)


--- trunk/Source/WebKit/UIProcess/PageClient.h	2018-03-21 08:42:08 UTC (rev 229798)
+++ trunk/Source/WebKit/UIProcess/PageClient.h	2018-03-21 08:44:03 UTC (rev 229799)
@@ -387,10 +387,6 @@
     virtual void didInsertAttachment(const String& identifier, const String& source) { }
     virtual void didRemoveAttachment(const String& identifier) { }
 #endif
-
-#if PLATFORM(GTK) || PLATFORM(WPE)
-    virtual JSGlobalContextRef _javascript_GlobalContext() { return nullptr; }
-#endif
 };
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (229798 => 229799)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.h	2018-03-21 08:42:08 UTC (rev 229798)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h	2018-03-21 08:44:03 UTC (rev 229799)
@@ -687,10 +687,6 @@
     void setBackgroundColor(const WebCore::Color& color) { m_backgroundColor = color; }
 #endif
 
-#if PLATFORM(GTK) || PLATFORM(WPE)
-    JSGlobalContextRef _javascript_GlobalContext();
-#endif
-
     void handleMouseEvent(const NativeWebMouseEvent&);
     void handleWheelEvent(const NativeWebWheelEvent&);
     void handleKeyboardEvent(const NativeWebKeyboardEvent&);

Modified: trunk/Source/WebKit/UIProcess/gtk/WebPageProxyGtk.cpp (229798 => 229799)


--- trunk/Source/WebKit/UIProcess/gtk/WebPageProxyGtk.cpp	2018-03-21 08:42:08 UTC (rev 229798)
+++ trunk/Source/WebKit/UIProcess/gtk/WebPageProxyGtk.cpp	2018-03-21 08:44:03 UTC (rev 229799)
@@ -50,11 +50,6 @@
     return static_cast<PageClientImpl&>(m_pageClient).viewWidget();
 }
 
-JSGlobalContextRef WebPageProxy::_javascript_GlobalContext()
-{
-    return m_pageClient._javascript_GlobalContext();
-}
-
 String WebPageProxy::standardUserAgent(const String& applicationNameForUserAgent)
 {
     return WebCore::standardUserAgent(applicationNameForUserAgent);

Modified: trunk/Source/WebKit/UIProcess/wpe/WebPageProxyWPE.cpp (229798 => 229799)


--- trunk/Source/WebKit/UIProcess/wpe/WebPageProxyWPE.cpp	2018-03-21 08:42:08 UTC (rev 229798)
+++ trunk/Source/WebKit/UIProcess/wpe/WebPageProxyWPE.cpp	2018-03-21 08:44:03 UTC (rev 229799)
@@ -38,11 +38,6 @@
     notImplemented();
 }
 
-JSGlobalContextRef WebPageProxy::_javascript_GlobalContext()
-{
-    return m_pageClient._javascript_GlobalContext();
-}
-
 String WebPageProxy::standardUserAgent(const String& applicationNameForUserAgent)
 {
     return WebCore::standardUserAgent(applicationNameForUserAgent);

Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/API/glib/WebKitFrame.cpp (229798 => 229799)


--- trunk/Source/WebKit/WebProcess/InjectedBundle/API/glib/WebKitFrame.cpp	2018-03-21 08:42:08 UTC (rev 229798)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/API/glib/WebKitFrame.cpp	2018-03-21 08:44:03 UTC (rev 229799)
@@ -22,6 +22,7 @@
 
 #include "WebKitFramePrivate.h"
 #include "WebKitScriptWorldPrivate.h"
+#include <jsc/JSCContextPrivate.h>
 #include <wtf/glib/WTFGType.h>
 #include <wtf/text/CString.h>
 
@@ -90,6 +91,7 @@
     return frame->priv->uri.data();
 }
 
+#if PLATFORM(GTK)
 /**
  * webkit_frame_get_javascript_global_context:
  * @frame: a #WebKitFrame
@@ -100,6 +102,8 @@
  * Returns: (transfer none): the global _javascript_ context of @frame
  *
  * Since: 2.2
+ *
+ * Deprecated: 2.22: Use webkit_frame_get_js_context() instead.
  */
 JSGlobalContextRef webkit_frame_get_javascript_global_context(WebKitFrame* frame)
 {
@@ -118,6 +122,8 @@
  * Returns: (transfer none): the _javascript_ context of @frame for @world
  *
  * Since: 2.2
+ *
+ * Deprecated: 2.22: Use webkit_frame_get_js_context_for_script_world() instead.
  */
 JSGlobalContextRef webkit_frame_get_javascript_context_for_script_world(WebKitFrame* frame, WebKitScriptWorld* world)
 {
@@ -126,3 +132,41 @@
 
     return frame->priv->webFrame->jsContextForWorld(webkitScriptWorldGetInjectedBundleScriptWorld(world));
 }
+#endif
+
+/**
+ * webkit_frame_get_js_context:
+ * @frame: a #WebKitFrame
+ *
+ * Get the _javascript_ execution context of @frame. Use this function to bridge
+ * between the WebKit and _javascript_Core APIs.
+ *
+ * Returns: (transfer full): the #JSCContext for the _javascript_ execution context of @frame.
+ *
+ * Since: 2.22
+ */
+JSCContext* webkit_frame_get_js_context(WebKitFrame* frame)
+{
+    g_return_val_if_fail(WEBKIT_IS_FRAME(frame), nullptr);
+
+    return jscContextGetOrCreate(frame->priv->webFrame->jsContext()).leakRef();
+}
+
+/**
+ * webkit_frame_get_js_context_for_script_world:
+ * @frame: a #WebKitFrame
+ * @world: a #WebKitScriptWorld
+ *
+ * Get the _javascript_ execution context of @frame for the given #WebKitScriptWorld.
+ *
+ * Returns: (transfer full): the #JSCContext for the _javascript_ execution context of @frame for @world.
+ *
+ * Since: 2.22
+ */
+JSCContext* webkit_frame_get_js_context_for_script_world(WebKitFrame* frame, WebKitScriptWorld* world)
+{
+    g_return_val_if_fail(WEBKIT_IS_FRAME(frame), nullptr);
+    g_return_val_if_fail(WEBKIT_IS_SCRIPT_WORLD(world), nullptr);
+
+    return jscContextGetOrCreate(frame->priv->webFrame->jsContextForWorld(webkitScriptWorldGetInjectedBundleScriptWorld(world))).leakRef();
+}

Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/API/gtk/WebKitFrame.h (229798 => 229799)


--- trunk/Source/WebKit/WebProcess/InjectedBundle/API/gtk/WebKitFrame.h	2018-03-21 08:42:08 UTC (rev 229798)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/API/gtk/WebKitFrame.h	2018-03-21 08:44:03 UTC (rev 229799)
@@ -26,6 +26,7 @@
 
 #include <_javascript_Core/JSBase.h>
 #include <glib-object.h>
+#include <jsc/jsc.h>
 #include <webkit2/WebKitDefines.h>
 #include <webkit2/WebKitScriptWorld.h>
 
@@ -61,13 +62,20 @@
 WEBKIT_API const gchar *
 webkit_frame_get_uri                                 (WebKitFrame       *frame);
 
-WEBKIT_API JSGlobalContextRef
+WEBKIT_DEPRECATED_FOR(webkit_frame_get_js_context) JSGlobalContextRef
 webkit_frame_get_javascript_global_context           (WebKitFrame       *frame);
 
-WEBKIT_API JSGlobalContextRef
+WEBKIT_DEPRECATED_FOR(webkit_frame_get_js_context_for_script_world) JSGlobalContextRef
 webkit_frame_get_javascript_context_for_script_world (WebKitFrame       *frame,
                                                       WebKitScriptWorld *world);
 
+WEBKIT_API JSCContext *
+webkit_frame_get_js_context                          (WebKitFrame       *frame);
+
+WEBKIT_API JSCContext *
+webkit_frame_get_js_context_for_script_world         (WebKitFrame       *frame,
+                                                      WebKitScriptWorld *world);
+
 G_END_DECLS
 
 #endif

Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/API/wpe/WebKitFrame.h (229798 => 229799)


--- trunk/Source/WebKit/WebProcess/InjectedBundle/API/wpe/WebKitFrame.h	2018-03-21 08:42:08 UTC (rev 229798)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/API/wpe/WebKitFrame.h	2018-03-21 08:44:03 UTC (rev 229799)
@@ -24,8 +24,8 @@
 #ifndef WebKitFrame_h
 #define WebKitFrame_h
 
-#include <_javascript_Core/JSBase.h>
 #include <glib-object.h>
+#include <jsc/jsc.h>
 #include <wpe/WebKitDefines.h>
 #include <wpe/WebKitScriptWorld.h>
 
@@ -53,20 +53,20 @@
 };
 
 WEBKIT_API GType
-webkit_frame_get_type                                (void);
+webkit_frame_get_type                        (void);
 
 WEBKIT_API gboolean
-webkit_frame_is_main_frame                           (WebKitFrame       *frame);
+webkit_frame_is_main_frame                   (WebKitFrame       *frame);
 
 WEBKIT_API const gchar *
-webkit_frame_get_uri                                 (WebKitFrame       *frame);
+webkit_frame_get_uri                         (WebKitFrame       *frame);
 
-WEBKIT_API JSGlobalContextRef
-webkit_frame_get_javascript_global_context           (WebKitFrame       *frame);
+WEBKIT_API JSCContext *
+webkit_frame_get_js_context                  (WebKitFrame       *frame);
 
-WEBKIT_API JSGlobalContextRef
-webkit_frame_get_javascript_context_for_script_world (WebKitFrame       *frame,
-                                                      WebKitScriptWorld *world);
+WEBKIT_API JSCContext *
+webkit_frame_get_js_context_for_script_world (WebKitFrame       *frame,
+                                              WebKitScriptWorld *world);
 
 G_END_DECLS
 

Modified: trunk/Tools/ChangeLog (229798 => 229799)


--- trunk/Tools/ChangeLog	2018-03-21 08:42:08 UTC (rev 229798)
+++ trunk/Tools/ChangeLog	2018-03-21 08:44:03 UTC (rev 229799)
@@ -1,5 +1,37 @@
 2018-03-21  Carlos Garcia Campos  <[email protected]>
 
+        [GTK][WPE] JSC bindings not introspectable
+        https://bugs.webkit.org/show_bug.cgi?id=136989
+
+        Reviewed by Michael Catanzaro.
+
+        Use the new API instead of the deprecated one.
+
+        * MiniBrowser/gtk/main.c:
+        (aboutDataScriptMessageReceivedCallback):
+        * TestWebKitAPI/Tests/WebKitGLib/FrameTest.cpp:
+        (WebKitFrameTest::testJavaScriptContext):
+        * TestWebKitAPI/Tests/WebKitGLib/TestWebKitWebView.cpp:
+        (testWebViewRunJavaScript):
+        * TestWebKitAPI/Tests/WebKitGLib/WebExtensionTest.cpp:
+        (consoleMessageSentCallback):
+        (echoCallback):
+        (windowObjectCleared):
+        (methodCallCallback):
+        * TestWebKitAPI/Tests/WebKitGLib/WebProcessTest.cpp:
+        (runTest):
+        (webProcessTestRunnerFinalize):
+        (windowObjectClearedCallback):
+        * TestWebKitAPI/glib/PlatformGTK.cmake:
+        * TestWebKitAPI/glib/WebKitGLib/WebViewTest.cpp:
+        (WebViewTest::_javascript_ResultToCString):
+        (WebViewTest::_javascript_ResultToNumber):
+        (WebViewTest::_javascript_ResultToBoolean):
+        (WebViewTest::_javascript_ResultIsNull):
+        (WebViewTest::_javascript_ResultIsUndefined):
+
+2018-03-21  Carlos Garcia Campos  <[email protected]>
+
         [GTK][WPE] Initial implementation of _javascript_Core glib bindings
         https://bugs.webkit.org/show_bug.cgi?id=164061
 

Modified: trunk/Tools/MiniBrowser/gtk/main.c (229798 => 229799)


--- trunk/Tools/MiniBrowser/gtk/main.c	2018-03-21 08:42:08 UTC (rev 229798)
+++ trunk/Tools/MiniBrowser/gtk/main.c	2018-03-21 08:44:03 UTC (rev 229799)
@@ -28,7 +28,6 @@
 #include "cmakeconfig.h"
 
 #include "BrowserWindow.h"
-#include <_javascript_Core/_javascript_.h>
 #include <errno.h>
 #include <gst/gst.h>
 #include <gtk/gtk.h>
@@ -297,17 +296,7 @@
 
 static void aboutDataScriptMessageReceivedCallback(WebKitUserContentManager *userContentManager, WebKitJavascriptResult *message, WebKitWebContext *webContext)
 {
-    JSValueRef jsValue = webkit_javascript_result_get_value(message);
-    JSStringRef jsString = JSValueToStringCopy(webkit_javascript_result_get_global_context(message), jsValue, NULL);
-    size_t maxSize = JSStringGetMaximumUTF8CStringSize(jsString);
-    if (!maxSize) {
-        JSStringRelease(jsString);
-        return;
-    }
-    char *messageString = g_malloc(maxSize);
-    JSStringGetUTF8CString(jsString, messageString, maxSize);
-    JSStringRelease(jsString);
-
+    char *messageString = jsc_value_to_string(webkit_javascript_result_get_js_value(message));
     char **tokens = g_strsplit(messageString, ":", 3);
     g_free(messageString);
 

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/FrameTest.cpp (229798 => 229799)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/FrameTest.cpp	2018-03-21 08:42:08 UTC (rev 229798)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/FrameTest.cpp	2018-03-21 08:44:03 UTC (rev 229799)
@@ -49,8 +49,16 @@
     {
         WebKitFrame* frame = webkit_web_page_get_main_frame(page);
         g_assert(WEBKIT_IS_FRAME(frame));
+#if PLATFORM(GTK)
+        G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
         g_assert(webkit_frame_get_javascript_global_context(frame));
+        G_GNUC_END_IGNORE_DEPRECATIONS;
+#endif
 
+        GRefPtr<JSCContext> jsContext = adoptGRef(webkit_frame_get_js_context(frame));
+        g_assert(JSC_IS_CONTEXT(jsContext.get()));
+        assertObjectIsDeletedWhenTestFinishes(G_OBJECT(jsContext.get()));
+
         return true;
     }
 

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebKitWebView.cpp (229798 => 229799)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebKitWebView.cpp	2018-03-21 08:42:08 UTC (rev 229798)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebKitWebView.cpp	2018-03-21 08:44:03 UTC (rev 229799)
@@ -21,8 +21,6 @@
 #include "config.h"
 #include "WebKitTestServer.h"
 #include "WebViewTest.h"
-#include <_javascript_Core/JSStringRef.h>
-#include <_javascript_Core/JSValueRef.h>
 #include <glib/gstdio.h>
 #include <wtf/glib/GRefPtr.h>
 
@@ -287,6 +285,7 @@
     GUniqueOutPtr<GError> error;
     WebKitJavascriptResult* _javascript_Result = test->runJavaScriptAndWaitUntilFinished("window.document.getElementById('WebKitLink').title;", &error.outPtr());
     g_assert(_javascript_Result);
+    test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(webkit_javascript_result_get_js_value(_javascript_Result)));
     g_assert(!error.get());
     GUniquePtr<char> valueString(WebViewTest::_javascript_ResultToCString(_javascript_Result));
     g_assert_cmpstr(valueString.get(), ==, "WebKitGTK+ Title");
@@ -293,6 +292,7 @@
 
     _javascript_Result = test->runJavaScriptAndWaitUntilFinished("window.document.getElementById('WebKitLink').href;", &error.outPtr());
     g_assert(_javascript_Result);
+    test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(webkit_javascript_result_get_js_value(_javascript_Result)));
     g_assert(!error.get());
     valueString.reset(WebViewTest::_javascript_ResultToCString(_javascript_Result));
     g_assert_cmpstr(valueString.get(), ==, "http://www.webkitgtk.org/");
@@ -299,6 +299,7 @@
 
     _javascript_Result = test->runJavaScriptAndWaitUntilFinished("window.document.getElementById('WebKitLink').textContent", &error.outPtr());
     g_assert(_javascript_Result);
+    test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(webkit_javascript_result_get_js_value(_javascript_Result)));
     g_assert(!error.get());
     valueString.reset(WebViewTest::_javascript_ResultToCString(_javascript_Result));
     g_assert_cmpstr(valueString.get(), ==, "WebKitGTK+ Website");
@@ -305,36 +306,43 @@
 
     _javascript_Result = test->runJavaScriptAndWaitUntilFinished("a = 25;", &error.outPtr());
     g_assert(_javascript_Result);
+    test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(webkit_javascript_result_get_js_value(_javascript_Result)));
     g_assert(!error.get());
     g_assert_cmpfloat(WebViewTest::_javascript_ResultToNumber(_javascript_Result), ==, 25);
 
     _javascript_Result = test->runJavaScriptAndWaitUntilFinished("a = 2.5;", &error.outPtr());
     g_assert(_javascript_Result);
+    test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(webkit_javascript_result_get_js_value(_javascript_Result)));
     g_assert(!error.get());
     g_assert_cmpfloat(WebViewTest::_javascript_ResultToNumber(_javascript_Result), ==, 2.5);
 
     _javascript_Result = test->runJavaScriptAndWaitUntilFinished("a = true", &error.outPtr());
     g_assert(_javascript_Result);
+    test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(webkit_javascript_result_get_js_value(_javascript_Result)));
     g_assert(!error.get());
     g_assert(WebViewTest::_javascript_ResultToBoolean(_javascript_Result));
 
     _javascript_Result = test->runJavaScriptAndWaitUntilFinished("a = false", &error.outPtr());
     g_assert(_javascript_Result);
+    test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(webkit_javascript_result_get_js_value(_javascript_Result)));
     g_assert(!error.get());
     g_assert(!WebViewTest::_javascript_ResultToBoolean(_javascript_Result));
 
     _javascript_Result = test->runJavaScriptAndWaitUntilFinished("a = null", &error.outPtr());
     g_assert(_javascript_Result);
+    test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(webkit_javascript_result_get_js_value(_javascript_Result)));
     g_assert(!error.get());
     g_assert(WebViewTest::_javascript_ResultIsNull(_javascript_Result));
 
     _javascript_Result = test->runJavaScriptAndWaitUntilFinished("function Foo() { a = 25; } Foo();", &error.outPtr());
     g_assert(_javascript_Result);
+    test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(webkit_javascript_result_get_js_value(_javascript_Result)));
     g_assert(!error.get());
     g_assert(WebViewTest::_javascript_ResultIsUndefined(_javascript_Result));
 
     _javascript_Result = test->runJavaScriptFromGResourceAndWaitUntilFinished("/org/webkit/glib/tests/link-title.js", &error.outPtr());
     g_assert(_javascript_Result);
+    test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(webkit_javascript_result_get_js_value(_javascript_Result)));
     g_assert(!error.get());
     valueString.reset(WebViewTest::_javascript_ResultToCString(_javascript_Result));
     g_assert_cmpstr(valueString.get(), ==, "WebKitGTK+ Title");

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/WebExtensionTest.cpp (229798 => 229799)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/WebExtensionTest.cpp	2018-03-21 08:42:08 UTC (rev 229798)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/WebExtensionTest.cpp	2018-03-21 08:44:03 UTC (rev 229799)
@@ -25,6 +25,7 @@
 #if USE(GSTREAMER)
 #include <gst/gst.h>
 #endif
+#include <jsc/jsc.h>
 #include <stdlib.h>
 #include <string.h>
 #include <wtf/Deque.h>
@@ -299,9 +300,8 @@
     }
     *dest = '\0';
     GUniquePtr<char> script(g_strdup_printf("window.webkit.messageHandlers.console.postMessage(\"%s\");", escapedMessageString.get()));
-    JSGlobalContextRef jsContext = webkit_frame_get_javascript_global_context(webkit_web_page_get_main_frame(webPage));
-    JSRetainPtr<JSStringRef> jsScript(Adopt, JSStringCreateWithUTF8CString(script.get()));
-    JSEvaluateScript(jsContext, jsScript.get(), nullptr, nullptr, 1, nullptr);
+    GRefPtr<JSCContext> jsContext = adoptGRef(webkit_frame_get_js_context(webkit_web_page_get_main_frame(webPage)));
+    GRefPtr<JSCValue> result = adoptGRef(jsc_context_evaluate(jsContext.get(), script.get()));
 #endif
 }
 
@@ -409,25 +409,17 @@
 #endif
 }
 
-static JSValueRef echoCallback(JSContextRef jsContext, JSObjectRef, JSObjectRef, size_t argumentCount, const JSValueRef arguments[], JSValueRef*)
+static char* echoCallback(const char* message)
 {
-    if (argumentCount <= 0)
-        return JSValueMakeUndefined(jsContext);
-
-    JSRetainPtr<JSStringRef> string(Adopt, JSValueToStringCopy(jsContext, arguments[0], 0));
-    return JSValueMakeString(jsContext, string.get());
+    return g_strdup(message);
 }
 
 static void windowObjectCleared(WebKitScriptWorld* world, WebKitWebPage* page, WebKitFrame* frame, gpointer)
 {
-    JSGlobalContextRef jsContext = webkit_frame_get_javascript_context_for_script_world(frame, world);
-    g_assert(jsContext);
-    JSObjectRef globalObject = JSContextGetGlobalObject(jsContext);
-    g_assert(globalObject);
-
-    JSRetainPtr<JSStringRef> functionName(Adopt, JSStringCreateWithUTF8CString("echo"));
-    JSObjectRef function = JSObjectMakeFunctionWithCallback(jsContext, functionName.get(), echoCallback);
-    JSObjectSetProperty(jsContext, globalObject, functionName.get(), function, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly, 0);
+    GRefPtr<JSCContext> jsContext = adoptGRef(webkit_frame_get_js_context_for_script_world(frame, world));
+    g_assert(JSC_IS_CONTEXT(jsContext.get()));
+    GRefPtr<JSCValue> function = adoptGRef(jsc_value_new_function(jsContext.get(), "echo", G_CALLBACK(echoCallback), NULL, NULL, G_TYPE_STRING, 1, G_TYPE_STRING));
+    jsc_context_set_value(jsContext.get(), "echo", function.get());
 }
 
 static WebKitWebPage* getWebPage(WebKitWebExtension* extension, uint64_t pageID, GDBusMethodInvocation* invocation)
@@ -475,9 +467,8 @@
         GRefPtr<WebKitScriptWorld> world = adoptGRef(webkit_script_world_new());
         g_assert(webkit_script_world_get_default() != world.get());
         WebKitFrame* frame = webkit_web_page_get_main_frame(page);
-        JSGlobalContextRef jsContext = webkit_frame_get_javascript_context_for_script_world(frame, world.get());
-        JSRetainPtr<JSStringRef> jsScript(Adopt, JSStringCreateWithUTF8CString(script));
-        JSEvaluateScript(jsContext, jsScript.get(), 0, 0, 0, 0);
+        GRefPtr<JSCContext> jsContext = adoptGRef(webkit_frame_get_js_context_for_script_world(frame, world.get()));
+        GRefPtr<JSCValue> result = adoptGRef(jsc_context_evaluate(jsContext.get(), script));
         g_dbus_method_invocation_return_value(invocation, 0);
     } else if (!g_strcmp0(methodName, "AbortProcess")) {
         abort();

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/WebProcessTest.cpp (229798 => 229799)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/WebProcessTest.cpp	2018-03-21 08:42:08 UTC (rev 229798)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/WebProcessTest.cpp	2018-03-21 08:44:03 UTC (rev 229799)
@@ -21,8 +21,8 @@
 #include "WebProcessTest.h"
 
 #include "WebKitWebExtensionPrivate.h"
-#include <_javascript_Core/JSRetainPtr.h>
 #include <gio/gio.h>
+#include <jsc/jsc.h>
 #include <wtf/HashSet.h>
 #include <wtf/NeverDestroyed.h>
 #include <wtf/glib/GUniquePtr.h>
@@ -55,32 +55,20 @@
     return testsMap().get(testName)();
 }
 
-static JSValueRef runTest(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+static gboolean runTest(WebKitWebPage* webPage, const char* testPath)
 {
-    JSRetainPtr<JSStringRef> stringValue(Adopt, JSValueToStringCopy(context, arguments[0], nullptr));
-    g_assert(stringValue);
-    size_t testPathLength = JSStringGetMaximumUTF8CStringSize(stringValue.get());
-    GUniquePtr<char> testPath(static_cast<char*>(g_malloc(testPathLength)));
-    JSStringGetUTF8CString(stringValue.get(), testPath.get(), testPathLength);
-
-    WebKitWebPage* webPage = WEBKIT_WEB_PAGE(JSObjectGetPrivate(thisObject));
     g_assert(WEBKIT_IS_WEB_PAGE(webPage));
     WebProcessTest::assertObjectIsDeletedWhenTestFinishes(G_OBJECT(webPage));
+    g_assert(testPath);
 
-    std::unique_ptr<WebProcessTest> test = WebProcessTest::create(String::fromUTF8(testPath.get()));
-    return JSValueMakeBoolean(context, test->runTest(g_strrstr(testPath.get(), "/") + 1, webPage));
+    std::unique_ptr<WebProcessTest> test = WebProcessTest::create(String::fromUTF8(testPath));
+    return test->runTest(g_strrstr(testPath, "/") + 1, webPage);
 }
 
-static const JSStaticFunction webProcessTestRunnerStaticFunctions[] =
+static void webProcessTestRunnerFinalize(WebKitWebPage* webPage)
 {
-    { "runTest", runTest, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
-    { nullptr, nullptr, 0 }
-};
+    g_object_unref(webPage);
 
-static void webProcessTestRunnerFinalize(JSObjectRef object)
-{
-    g_object_unref(JSObjectGetPrivate(object));
-
     if (s_watchedObjects.isEmpty())
         return;
 
@@ -97,19 +85,14 @@
     if (g_strcmp0(webkit_web_page_get_uri(webPage), "webprocess://test"))
         return;
 
-    JSGlobalContextRef context = webkit_frame_get_javascript_context_for_script_world(frame, world);
-    JSObjectRef globalObject = JSContextGetGlobalObject(context);
-
-    JSClassDefinition classDefinition = kJSClassDefinitionEmpty;
-    classDefinition.className = "WebProcessTestRunner";
-    classDefinition.staticFunctions = webProcessTestRunnerStaticFunctions;
-    classDefinition.finalize = webProcessTestRunnerFinalize;
-
-    JSClassRef jsClass = JSClassCreate(&classDefinition);
-    JSObjectRef classObject = JSObjectMake(context, jsClass, g_object_ref(webPage));
-    JSRetainPtr<JSStringRef> propertyString(Adopt, JSStringCreateWithUTF8CString("WebProcessTestRunner"));
-    JSObjectSetProperty(context, globalObject, propertyString.get(), classObject, kJSPropertyAttributeNone, nullptr);
-    JSClassRelease(jsClass);
+    GRefPtr<JSCContext> context = adoptGRef(webkit_frame_get_js_context_for_script_world(frame, world));
+    WebProcessTest::assertObjectIsDeletedWhenTestFinishes(G_OBJECT(context.get()));
+    auto* jsClass = jsc_context_register_class(context.get(), "WebProcessTestRunner", nullptr, reinterpret_cast<GDestroyNotify>(webProcessTestRunnerFinalize));
+    WebProcessTest::assertObjectIsDeletedWhenTestFinishes(G_OBJECT(jsClass));
+    jsc_class_add_method(jsClass, "runTest", G_CALLBACK(runTest), NULL, NULL, G_TYPE_BOOLEAN, 1, G_TYPE_STRING);
+    GRefPtr<JSCValue> testRunner = adoptGRef(jsc_value_new_object(context.get(), g_object_ref(webPage), jsClass));
+    WebProcessTest::assertObjectIsDeletedWhenTestFinishes(G_OBJECT(testRunner.get()));
+    jsc_context_set_value(context.get(), "WebProcessTestRunner", testRunner.get());
 }
 
 extern "C" void webkit_web_extension_initialize(WebKitWebExtension* extension)

Modified: trunk/Tools/TestWebKitAPI/glib/PlatformGTK.cmake (229798 => 229799)


--- trunk/Tools/TestWebKitAPI/glib/PlatformGTK.cmake	2018-03-21 08:42:08 UTC (rev 229798)
+++ trunk/Tools/TestWebKitAPI/glib/PlatformGTK.cmake	2018-03-21 08:44:03 UTC (rev 229799)
@@ -6,6 +6,7 @@
 )
 
 list(APPEND WebKitGLibAPITests_INCLUDE_DIRECTORIES
+    ${DERIVED_SOURCES_JAVASCRIPCOREGTK_DIR}
     ${DERIVED_SOURCES_WEBKIT2GTK_DIR}
     ${FORWARDING_HEADERS_WEBKIT2GTK_DIR}
     ${FORWARDING_HEADERS_WEBKIT2GTK_EXTENSION_DIR}

Modified: trunk/Tools/TestWebKitAPI/glib/WebKitGLib/WebViewTest.cpp (229798 => 229799)


--- trunk/Tools/TestWebKitAPI/glib/WebKitGLib/WebViewTest.cpp	2018-03-21 08:42:08 UTC (rev 229798)
+++ trunk/Tools/TestWebKitAPI/glib/WebKitGLib/WebViewTest.cpp	2018-03-21 08:44:03 UTC (rev 229799)
@@ -312,67 +312,42 @@
     return m_javascriptResult;
 }
 
-static char* jsValueToCString(JSGlobalContextRef context, JSValueRef value)
-{
-    g_assert(value);
-    g_assert(JSValueIsString(context, value));
-
-    JSRetainPtr<JSStringRef> stringValue(Adopt, JSValueToStringCopy(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);
-    return cString;
-}
-
 char* WebViewTest::_javascript_ResultToCString(WebKitJavascriptResult* _javascript_Result)
 {
-    JSGlobalContextRef context = webkit_javascript_result_get_global_context(_javascript_Result);
-    g_assert(context);
-    return jsValueToCString(context, webkit_javascript_result_get_value(_javascript_Result));
+    auto* value = webkit_javascript_result_get_js_value(_javascript_Result);
+    g_assert(JSC_IS_VALUE(value));
+    g_assert(jsc_value_is_string(value));
+    return jsc_value_to_string(value);
 }
 
 double WebViewTest::_javascript_ResultToNumber(WebKitJavascriptResult* _javascript_Result)
 {
-    JSGlobalContextRef context = webkit_javascript_result_get_global_context(_javascript_Result);
-    g_assert(context);
-    JSValueRef value = webkit_javascript_result_get_value(_javascript_Result);
-    g_assert(value);
-    g_assert(JSValueIsNumber(context, value));
-
-    return JSValueToNumber(context, value, 0);
+    auto* value = webkit_javascript_result_get_js_value(_javascript_Result);
+    g_assert(JSC_IS_VALUE(value));
+    g_assert(jsc_value_is_number(value));
+    return jsc_value_to_double(value);
 }
 
 bool WebViewTest::_javascript_ResultToBoolean(WebKitJavascriptResult* _javascript_Result)
 {
-    JSGlobalContextRef context = webkit_javascript_result_get_global_context(_javascript_Result);
-    g_assert(context);
-    JSValueRef value = webkit_javascript_result_get_value(_javascript_Result);
-    g_assert(value);
-    g_assert(JSValueIsBoolean(context, value));
-
-    return JSValueToBoolean(context, value);
+    auto* value = webkit_javascript_result_get_js_value(_javascript_Result);
+    g_assert(JSC_IS_VALUE(value));
+    g_assert(jsc_value_is_boolean(value));
+    return jsc_value_to_boolean(value);
 }
 
 bool WebViewTest::_javascript_ResultIsNull(WebKitJavascriptResult* _javascript_Result)
 {
-    JSGlobalContextRef context = webkit_javascript_result_get_global_context(_javascript_Result);
-    g_assert(context);
-    JSValueRef value = webkit_javascript_result_get_value(_javascript_Result);
-    g_assert(value);
-
-    return JSValueIsNull(context, value);
+    auto* value = webkit_javascript_result_get_js_value(_javascript_Result);
+    g_assert(JSC_IS_VALUE(value));
+    return jsc_value_is_null(value);
 }
 
 bool WebViewTest::_javascript_ResultIsUndefined(WebKitJavascriptResult* _javascript_Result)
 {
-    JSGlobalContextRef context = webkit_javascript_result_get_global_context(_javascript_Result);
-    g_assert(context);
-    JSValueRef value = webkit_javascript_result_get_value(_javascript_Result);
-    g_assert(value);
-
-    return JSValueIsUndefined(context, value);
+    auto* value = webkit_javascript_result_get_js_value(_javascript_Result);
+    g_assert(JSC_IS_VALUE(value));
+    return jsc_value_is_undefined(value);
 }
 
 #if PLATFORM(GTK)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to