[GTK][WPE] JSC bindings not introspectable
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Mar 2018 08:44:03 +0000 (08:44 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Mar 2018 08:44:03 +0000 (08:44 +0000)
https://bugs.webkit.org/show_bug.cgi?id=136989

Reviewed by Michael Catanzaro.

Source/JavaScriptCore:

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::javascriptGlobalContext() 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::javascriptResultToCString):
(WebViewTest::javascriptResultToNumber):
(WebViewTest::javascriptResultToBoolean):
(WebViewTest::javascriptResultIsNull):
(WebViewTest::javascriptResultIsUndefined):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@229799 268f45cc-cd09-0410-ab3c-d52691b4dbfc

42 files changed:
Source/JavaScriptCore/API/glib/JSCAutocleanups.h
Source/JavaScriptCore/API/glib/JSCClass.h
Source/JavaScriptCore/API/glib/JSCContext.h
Source/JavaScriptCore/API/glib/JSCException.h
Source/JavaScriptCore/API/glib/JSCValue.h
Source/JavaScriptCore/API/glib/JSCVersion.h.in
Source/JavaScriptCore/API/glib/JSCVirtualMachine.h
Source/JavaScriptCore/ChangeLog
Source/WebKit/ChangeLog
Source/WebKit/PlatformGTK.cmake
Source/WebKit/PlatformWPE.cmake
Source/WebKit/UIProcess/API/glib/WebKitJavascriptResult.cpp
Source/WebKit/UIProcess/API/glib/WebKitJavascriptResultPrivate.h
Source/WebKit/UIProcess/API/glib/WebKitUserContentManager.cpp
Source/WebKit/UIProcess/API/glib/WebKitWebView.cpp
Source/WebKit/UIProcess/API/gtk/PageClientImpl.cpp
Source/WebKit/UIProcess/API/gtk/PageClientImpl.h
Source/WebKit/UIProcess/API/gtk/WebKitJavascriptResult.h
Source/WebKit/UIProcess/API/gtk/WebKitWebView.h
Source/WebKit/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt
Source/WebKit/UIProcess/API/wpe/APIViewClient.h
Source/WebKit/UIProcess/API/wpe/PageClientImpl.cpp
Source/WebKit/UIProcess/API/wpe/PageClientImpl.h
Source/WebKit/UIProcess/API/wpe/WPEView.cpp
Source/WebKit/UIProcess/API/wpe/WPEView.h
Source/WebKit/UIProcess/API/wpe/WebKitJavascriptResult.h
Source/WebKit/UIProcess/API/wpe/WebKitWebView.h
Source/WebKit/UIProcess/PageClient.h
Source/WebKit/UIProcess/WebPageProxy.h
Source/WebKit/UIProcess/gtk/WebPageProxyGtk.cpp
Source/WebKit/UIProcess/wpe/WebPageProxyWPE.cpp
Source/WebKit/WebProcess/InjectedBundle/API/glib/WebKitFrame.cpp
Source/WebKit/WebProcess/InjectedBundle/API/gtk/WebKitFrame.h
Source/WebKit/WebProcess/InjectedBundle/API/wpe/WebKitFrame.h
Tools/ChangeLog
Tools/MiniBrowser/gtk/main.c
Tools/TestWebKitAPI/Tests/WebKitGLib/FrameTest.cpp
Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebKitWebView.cpp
Tools/TestWebKitAPI/Tests/WebKitGLib/WebExtensionTest.cpp
Tools/TestWebKitAPI/Tests/WebKitGLib/WebProcessTest.cpp
Tools/TestWebKitAPI/glib/PlatformGTK.cmake
Tools/TestWebKitAPI/glib/WebKitGLib/WebViewTest.cpp

index 6d9178e..9dfa93f 100644 (file)
@@ -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
 
index df5c6a8..d8411da 100644 (file)
@@ -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
 
index 365c67a..d574fd3 100644 (file)
@@ -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
 
index 2fd57fa..2bee606 100644 (file)
@@ -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
 
index 05f1f97..10ed966 100644 (file)
@@ -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
 
index 079f953..c445f45 100644 (file)
@@ -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
 
index 25c643e..083c6a9 100644 (file)
@@ -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
 
index 5fb18f1..da9527f 100644 (file)
@@ -1,5 +1,22 @@
 2018-03-21  Carlos Garcia Campos  <cgarcia@igalia.com>
 
+        [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  <cgarcia@igalia.com>
+
         [GTK][WPE] Initial implementation of JavaScriptCore glib bindings
         https://bugs.webkit.org/show_bug.cgi?id=164061
 
index 2bd27db..c49369b 100644 (file)
@@ -1,5 +1,57 @@
 2018-03-21  Carlos Garcia Campos  <cgarcia@igalia.com>
 
+        [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::javascriptGlobalContext() 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  <cgarcia@igalia.com>
+
         [GTK][WPE] Initial implementation of JavaScriptCore glib bindings
         https://bugs.webkit.org/show_bug.cgi?id=164061
 
index 0435fcc..4adcffb 100644 (file)
@@ -366,6 +366,9 @@ list(INSERT WebKit_INCLUDE_DIRECTORIES 0
 )
 
 list(APPEND WebKit_INCLUDE_DIRECTORIES
+    "${DERIVED_SOURCES_JAVASCRIPCOREGTK_DIR}"
+    "${FORWARDING_HEADERS_DIR}/JavaScriptCore/"
+    "${FORWARDING_HEADERS_DIR}/JavaScriptCore/glib"
     "${WEBKIT_DIR}/PluginProcess/unix"
     "${WEBKIT_DIR}/NetworkProcess/CustomProtocols/soup"
     "${WEBKIT_DIR}/NetworkProcess/Downloads/soup"
@@ -762,7 +765,9 @@ if (ENABLE_INTROSPECTION)
             -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}/JavaScriptCore/glib
             -I${FORWARDING_HEADERS_WEBKIT2GTK_DIR}
             ${WebKit2GTK_INSTALLED_HEADERS}
             ${WEBKIT_DIR}/Shared/API/glib/*.cpp
@@ -806,7 +811,9 @@ if (ENABLE_INTROSPECTION)
             -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}/JavaScriptCore/glib
             -I${FORWARDING_HEADERS_WEBKIT2GTK_DIR}
             -I${FORWARDING_HEADERS_WEBKIT2GTK_EXTENSION_DIR}
             -I${WEBKIT_DIR}/WebProcess/InjectedBundle/API/gtk
index 2b41aca..03e7e1d 100644 (file)
@@ -178,7 +178,10 @@ add_custom_command(
 )
 
 list(APPEND WebKit_INCLUDE_DIRECTORIES
+    "${DERIVED_SOURCES_JAVASCRIPCOREWPE_DIR}"
     "${FORWARDING_HEADERS_DIR}"
+    "${FORWARDING_HEADERS_DIR}/JavaScriptCore/"
+    "${FORWARDING_HEADERS_DIR}/JavaScriptCore/glib"
     "${FORWARDING_HEADERS_WPE_DIR}"
     "${FORWARDING_HEADERS_WPE_EXTENSION_DIR}"
     "${DERIVED_SOURCES_DIR}"
index 010805c..10bb112 100644 (file)
 
 #include "APISerializedScriptValue.h"
 #include "WebKitJavascriptResultPrivate.h"
-#include <JavaScriptCore/JSRetainPtr.h>
-#include <wtf/glib/GRefPtr.h>
+#include <jsc/JSCContextPrivate.h>
+#include <jsc/JSCValuePrivate.h>
 
 struct _WebKitJavascriptResult {
-    _WebKitJavascriptResult(JSGlobalContextRef jsContext, WebCore::SerializedScriptValue& serializedScriptValue)
-        : javascriptGlobalContext(jsContext)
-        , referenceCount(1)
+    explicit _WebKitJavascriptResult(WebCore::SerializedScriptValue& serializedScriptValue)
     {
-        value = serializedScriptValue.deserialize(javascriptGlobalContext.get(), nullptr);
+        auto* jsContext = SharedJavascriptContext::singleton().getOrCreateContext();
+        jsValue = jscContextGetOrCreateValue(jsContext, serializedScriptValue.deserialize(jscContextGetJSContext(jsContext), nullptr));
     }
 
-    JSRetainPtr<JSGlobalContextRef> javascriptGlobalContext;
-    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 javascriptGlobalContext, WebCore::SerializedScriptValue& serializedScriptValue)
+WebKitJavascriptResult* webkitJavascriptResultCreate(WebCore::SerializedScriptValue& serializedScriptValue)
 {
     WebKitJavascriptResult* result = static_cast<WebKitJavascriptResult*>(fastMalloc(sizeof(WebKitJavascriptResult)));
-    new (result) WebKitJavascriptResult(javascriptGlobalContext, serializedScriptValue);
+    new (result) WebKitJavascriptResult(serializedScriptValue);
     return result;
 }
 
@@ -80,6 +78,7 @@ void webkit_javascript_result_unref(WebKitJavascriptResult* javascriptResult)
     }
 }
 
+#if PLATFORM(GTK)
 /**
  * webkit_javascript_result_get_global_context:
  * @js_result: a #WebKitJavascriptResult
@@ -88,10 +87,13 @@ void webkit_javascript_result_unref(WebKitJavascriptResult* javascriptResult)
  * <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* javascriptResult)
 {
-    return javascriptResult->javascriptGlobalContext.get();
+    g_return_val_if_fail(javascriptResult, nullptr);
+    return jscContextGetJSContext(jsc_value_get_context(javascriptResult->jsValue.get()));
 }
 
 /**
@@ -102,8 +104,28 @@ JSGlobalContextRef webkit_javascript_result_get_global_context(WebKitJavascriptR
  * 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* javascriptResult)
 {
-    return javascriptResult->value;
+    g_return_val_if_fail(javascriptResult, nullptr);
+    return jscValueGetJSValue(javascriptResult->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* javascriptResult)
+{
+    g_return_val_if_fail(javascriptResult, nullptr);
+    return javascriptResult->jsValue.get();
 }
index e753fb2..e190894 100644 (file)
 
 #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&);
index 2283260..acae9e1 100644 (file)
@@ -188,9 +188,9 @@ public:
     {
     }
 
-    void didPostMessage(WebPageProxy& page, const FrameInfoData&, WebCore::SerializedScriptValue& serializedScriptValue) override
+    void didPostMessage(WebPageProxy&, const FrameInfoData&, WebCore::SerializedScriptValue& serializedScriptValue) override
     {
-        WebKitJavascriptResult* jsResult = webkitJavascriptResultCreate(page.javascriptGlobalContext(), serializedScriptValue);
+        WebKitJavascriptResult* jsResult = webkitJavascriptResultCreate(serializedScriptValue);
         g_signal_emit(m_manager, signals[SCRIPT_MESSAGE_RECEIVED], m_handlerName, jsResult);
         webkit_javascript_result_unref(jsResult);
     }
index 51ccd77..a27f9ec 100644 (file)
@@ -62,6 +62,7 @@
 #include "WebKitWindowPropertiesPrivate.h"
 #include <JavaScriptCore/APICast.h>
 #include <JavaScriptCore/JSRetainPtr.h>
+#include <jsc/JSCContextPrivate.h>
 #include <WebCore/CertificateInfo.h>
 #include <WebCore/GUniquePtrSoup.h>
 #include <WebCore/JSDOMExceptionHandling.h>
@@ -228,7 +229,6 @@ struct _WebKitWebViewPrivate {
     WebEvent::Modifiers mouseTargetModifiers;
 
     GRefPtr<WebKitFindController> findController;
-    JSRetainPtr<JSGlobalContextRef> javascriptGlobalContext;
 
     GRefPtr<WebKitWebResource> mainResource;
     LoadingResourcesMap loadingResourcesMap;
@@ -236,6 +236,8 @@ struct _WebKitWebViewPrivate {
     WebKitScriptDialog* currentScriptDialog;
 
 #if PLATFORM(GTK)
+    GRefPtr<JSCContext> jsContext;
+
     GRefPtr<WebKitWebInspector> inspector;
 
     RefPtr<cairo_surface_t> favicon;
@@ -367,11 +369,6 @@ private:
         webkitWebViewHandleDownloadRequest(m_webView, &downloadProxy);
     }
 
-    JSGlobalContextRef javascriptGlobalContext() override
-    {
-        return webkit_web_view_get_javascript_global_context(m_webView);
-    }
-
     WebKitWebView* m_webView;
 };
 #endif
@@ -3250,6 +3247,7 @@ WebKitFindController* webkit_web_view_get_find_controller(WebKitWebView* webView
     return webView->priv->findController.get();
 }
 
+#if PLATFORM(GTK)
 /**
  * webkit_web_view_get_javascript_global_context:
  * @web_view: a #WebKitWebView
@@ -3259,15 +3257,20 @@ WebKitFindController* webkit_web_view_get_find_controller(WebKitWebView* webView
  *
  * 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->javascriptGlobalContext)
-        webView->priv->javascriptGlobalContext = adopt(JSGlobalContextCreate(nullptr));
-    return webView->priv->javascriptGlobalContext.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 @@ static void webkitWebViewRunJavaScriptCallback(API::SerializedScriptValue* wkSer
         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 @@ void webkit_web_view_run_javascript(WebKitWebView* webView, const gchar* script,
  *                               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 @@ void webkit_web_view_run_javascript(WebKitWebView* webView, const gchar* script,
  *         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;
- *
- *         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);
+ *     value = webkit_javascript_result_get_js_value (js_result);
+ *     if (jsc_value_is_string (value)) {
+ *         JSCException *exception;
+ *         gchar        *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");
index 3ed5be9..c9f2034 100644 (file)
@@ -474,14 +474,6 @@ bool PageClientImpl::decidePolicyForInstallMissingMediaPluginsPermissionRequest(
 }
 #endif
 
-JSGlobalContextRef PageClientImpl::javascriptGlobalContext()
-{
-    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)) {
index 6dfdc2c..5305057 100644 (file)
@@ -149,8 +149,6 @@ private:
 
     WebCore::UserInterfaceLayoutDirection userInterfaceLayoutDirection() override { return WebCore::UserInterfaceLayoutDirection::LTR; }
 
-    JSGlobalContextRef javascriptGlobalContext() override;
-
     // Members of PageClientImpl class
     GtkWidget* m_viewWidget;
     DefaultUndoController m_undoController;
index 5a9f738..daccdeb 100644 (file)
@@ -25,6 +25,7 @@
 #define WebKitJavascriptResult_h
 
 #include <JavaScriptCore/JSBase.h>
+#include <jsc/jsc.h>
 #include <glib-object.h>
 #include <webkit2/WebKitDefines.h>
 
@@ -44,12 +45,15 @@ webkit_javascript_result_ref                (WebKitJavascriptResult *js_result);
 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
index c369653..03dfea5 100644 (file)
@@ -430,7 +430,7 @@ webkit_web_view_execute_editing_command_with_argument(WebKitWebView
 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
index 20896f3..e952231 100644 (file)
@@ -232,6 +232,7 @@ webkit_javascript_result_ref
 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_is_main_frame
 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
index ed5a9e3..4adaf46 100644 (file)
@@ -43,7 +43,6 @@ public:
 
     virtual void frameDisplayed(WKWPE::View&) { }
     virtual void handleDownloadRequest(WKWPE::View&, WebKit::DownloadProxy&) { }
-    virtual JSGlobalContextRef javascriptGlobalContext() { return nullptr; }
 };
 
 } // namespace API
index d50ee82..59ccb40 100644 (file)
@@ -321,9 +321,4 @@ WebCore::UserInterfaceLayoutDirection PageClientImpl::userInterfaceLayoutDirecti
     return WebCore::UserInterfaceLayoutDirection::LTR;
 }
 
-JSGlobalContextRef PageClientImpl::javascriptGlobalContext()
-{
-    return m_view.javascriptGlobalContext();
-}
-
 } // namespace WebKit
index 780c884..167e565 100644 (file)
@@ -119,8 +119,6 @@ private:
 
     WebCore::UserInterfaceLayoutDirection userInterfaceLayoutDirection() override;
 
-    JSGlobalContextRef javascriptGlobalContext() override;
-
     WKWPE::View& m_view;
 
     std::unique_ptr<ScrollGestureController> m_scrollGestureController;
index 49b6424..3e5ddc4 100644 (file)
@@ -35,7 +35,6 @@
 #include "NativeWebWheelEvent.h"
 #include "WebPageGroup.h"
 #include "WebProcessPool.h"
-#include <JavaScriptCore/JSBase.h>
 #include <wpe/view-backend.h>
 
 using namespace WebKit;
@@ -156,11 +155,6 @@ void View::handleDownloadRequest(DownloadProxy& download)
     m_client->handleDownloadRequest(*this, download);
 }
 
-JSGlobalContextRef View::javascriptGlobalContext()
-{
-    return m_client->javascriptGlobalContext();
-}
-
 void View::setSize(const WebCore::IntSize& size)
 {
     m_size = size;
index ff82fbe..a8ce831 100644 (file)
@@ -60,7 +60,6 @@ public:
     void setClient(std::unique_ptr<API::ViewClient>&&);
     void frameDisplayed();
     void handleDownloadRequest(WebKit::DownloadProxy&);
-    JSGlobalContextRef javascriptGlobalContext();
 
     WebKit::WebPageProxy& page() { return *m_pageProxy; }
 
index 263422e..1fee2ef 100644 (file)
@@ -24,8 +24,8 @@
 #ifndef WebKitJavascriptResult_h
 #define WebKitJavascriptResult_h
 
-#include <JavaScriptCore/JSBase.h>
 #include <glib-object.h>
+#include <jsc/jsc.h>
 #include <wpe/WebKitDefines.h>
 
 G_BEGIN_DECLS
@@ -44,11 +44,8 @@ webkit_javascript_result_ref                (WebKitJavascriptResult *js_result);
 WEBKIT_API void
 webkit_javascript_result_unref              (WebKitJavascriptResult *js_result);
 
-WEBKIT_API JSGlobalContextRef
-webkit_javascript_result_get_global_context (WebKitJavascriptResult *js_result);
-
-WEBKIT_API JSValueRef
-webkit_javascript_result_get_value          (WebKitJavascriptResult *js_result);
+WEBKIT_API JSCValue *
+webkit_javascript_result_get_js_value       (WebKitJavascriptResult *js_result);
 
 G_END_DECLS
 
index fbb4f80..3c02f0d 100644 (file)
@@ -28,7 +28,6 @@
 #ifndef WebKitWebView_h
 #define WebKitWebView_h
 
-#include <JavaScriptCore/JSBase.h>
 #include <wpe/WebKitAuthenticationRequest.h>
 #include <wpe/WebKitBackForwardList.h>
 #include <wpe/WebKitContextMenu.h>
@@ -400,9 +399,6 @@ webkit_web_view_execute_editing_command_with_argument(WebKitWebView
 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,
index 4dcac57..24fa7c5 100644 (file)
@@ -387,10 +387,6 @@ public:
     virtual void didInsertAttachment(const String& identifier, const String& source) { }
     virtual void didRemoveAttachment(const String& identifier) { }
 #endif
-
-#if PLATFORM(GTK) || PLATFORM(WPE)
-    virtual JSGlobalContextRef javascriptGlobalContext() { return nullptr; }
-#endif
 };
 
 } // namespace WebKit
index 2d09435..ac6adc4 100644 (file)
@@ -687,10 +687,6 @@ public:
     void setBackgroundColor(const WebCore::Color& color) { m_backgroundColor = color; }
 #endif
 
-#if PLATFORM(GTK) || PLATFORM(WPE)
-    JSGlobalContextRef javascriptGlobalContext();
-#endif
-
     void handleMouseEvent(const NativeWebMouseEvent&);
     void handleWheelEvent(const NativeWebWheelEvent&);
     void handleKeyboardEvent(const NativeWebKeyboardEvent&);
index 94cd84c..15a631d 100644 (file)
@@ -50,11 +50,6 @@ GtkWidget* WebPageProxy::viewWidget()
     return static_cast<PageClientImpl&>(m_pageClient).viewWidget();
 }
 
-JSGlobalContextRef WebPageProxy::javascriptGlobalContext()
-{
-    return m_pageClient.javascriptGlobalContext();
-}
-
 String WebPageProxy::standardUserAgent(const String& applicationNameForUserAgent)
 {
     return WebCore::standardUserAgent(applicationNameForUserAgent);
index 35b66f2..68f3c58 100644 (file)
@@ -38,11 +38,6 @@ void WebPageProxy::platformInitialize()
     notImplemented();
 }
 
-JSGlobalContextRef WebPageProxy::javascriptGlobalContext()
-{
-    return m_pageClient.javascriptGlobalContext();
-}
-
 String WebPageProxy::standardUserAgent(const String& applicationNameForUserAgent)
 {
     return WebCore::standardUserAgent(applicationNameForUserAgent);
index 1953333..0477100 100644 (file)
@@ -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 @@ const gchar* webkit_frame_get_uri(WebKitFrame* frame)
     return frame->priv->uri.data();
 }
 
+#if PLATFORM(GTK)
 /**
  * webkit_frame_get_javascript_global_context:
  * @frame: a #WebKitFrame
@@ -100,6 +102,8 @@ const gchar* webkit_frame_get_uri(WebKitFrame* frame)
  * 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 @@ JSGlobalContextRef webkit_frame_get_javascript_global_context(WebKitFrame* frame
  * 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 @@ JSGlobalContextRef webkit_frame_get_javascript_context_for_script_world(WebKitFr
 
     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 JavaScriptCore 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();
+}
index 5059300..6c54a24 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <JavaScriptCore/JSBase.h>
 #include <glib-object.h>
+#include <jsc/jsc.h>
 #include <webkit2/WebKitDefines.h>
 #include <webkit2/WebKitScriptWorld.h>
 
@@ -61,13 +62,20 @@ webkit_frame_is_main_frame                           (WebKitFrame       *frame);
 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
index 23da0ae..94f0d00 100644 (file)
@@ -24,8 +24,8 @@
 #ifndef WebKitFrame_h
 #define WebKitFrame_h
 
-#include <JavaScriptCore/JSBase.h>
 #include <glib-object.h>
+#include <jsc/jsc.h>
 #include <wpe/WebKitDefines.h>
 #include <wpe/WebKitScriptWorld.h>
 
@@ -53,20 +53,20 @@ struct _WebKitFrameClass {
 };
 
 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
 
index 7f50174..7e7e33c 100644 (file)
@@ -1,5 +1,37 @@
 2018-03-21  Carlos Garcia Campos  <cgarcia@igalia.com>
 
+        [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::javascriptResultToCString):
+        (WebViewTest::javascriptResultToNumber):
+        (WebViewTest::javascriptResultToBoolean):
+        (WebViewTest::javascriptResultIsNull):
+        (WebViewTest::javascriptResultIsUndefined):
+
+2018-03-21  Carlos Garcia Campos  <cgarcia@igalia.com>
+
         [GTK][WPE] Initial implementation of JavaScriptCore glib bindings
         https://bugs.webkit.org/show_bug.cgi?id=164061
 
index 19e806f..881602e 100644 (file)
@@ -28,7 +28,6 @@
 #include "cmakeconfig.h"
 
 #include "BrowserWindow.h"
-#include <JavaScriptCore/JavaScript.h>
 #include <errno.h>
 #include <gst/gst.h>
 #include <gtk/gtk.h>
@@ -297,17 +296,7 @@ static void websiteDataClearedCallback(WebKitWebsiteDataManager *manager, GAsync
 
 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);
 
index 99673e4..880c103 100644 (file)
@@ -49,7 +49,15 @@ private:
     {
         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;
     }
index fe0c2cc..5411434 100644 (file)
@@ -21,8 +21,6 @@
 #include "config.h"
 #include "WebKitTestServer.h"
 #include "WebViewTest.h"
-#include <JavaScriptCore/JSStringRef.h>
-#include <JavaScriptCore/JSValueRef.h>
 #include <glib/gstdio.h>
 #include <wtf/glib/GRefPtr.h>
 
@@ -287,54 +285,64 @@ static void testWebViewRunJavaScript(WebViewTest* test, gconstpointer)
     GUniqueOutPtr<GError> error;
     WebKitJavascriptResult* javascriptResult = test->runJavaScriptAndWaitUntilFinished("window.document.getElementById('WebKitLink').title;", &error.outPtr());
     g_assert(javascriptResult);
+    test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(webkit_javascript_result_get_js_value(javascriptResult)));
     g_assert(!error.get());
     GUniquePtr<char> valueString(WebViewTest::javascriptResultToCString(javascriptResult));
     g_assert_cmpstr(valueString.get(), ==, "WebKitGTK+ Title");
 
     javascriptResult = test->runJavaScriptAndWaitUntilFinished("window.document.getElementById('WebKitLink').href;", &error.outPtr());
     g_assert(javascriptResult);
+    test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(webkit_javascript_result_get_js_value(javascriptResult)));
     g_assert(!error.get());
     valueString.reset(WebViewTest::javascriptResultToCString(javascriptResult));
     g_assert_cmpstr(valueString.get(), ==, "http://www.webkitgtk.org/");
 
     javascriptResult = test->runJavaScriptAndWaitUntilFinished("window.document.getElementById('WebKitLink').textContent", &error.outPtr());
     g_assert(javascriptResult);
+    test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(webkit_javascript_result_get_js_value(javascriptResult)));
     g_assert(!error.get());
     valueString.reset(WebViewTest::javascriptResultToCString(javascriptResult));
     g_assert_cmpstr(valueString.get(), ==, "WebKitGTK+ Website");
 
     javascriptResult = test->runJavaScriptAndWaitUntilFinished("a = 25;", &error.outPtr());
     g_assert(javascriptResult);
+    test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(webkit_javascript_result_get_js_value(javascriptResult)));
     g_assert(!error.get());
     g_assert_cmpfloat(WebViewTest::javascriptResultToNumber(javascriptResult), ==, 25);
 
     javascriptResult = test->runJavaScriptAndWaitUntilFinished("a = 2.5;", &error.outPtr());
     g_assert(javascriptResult);
+    test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(webkit_javascript_result_get_js_value(javascriptResult)));
     g_assert(!error.get());
     g_assert_cmpfloat(WebViewTest::javascriptResultToNumber(javascriptResult), ==, 2.5);
 
     javascriptResult = test->runJavaScriptAndWaitUntilFinished("a = true", &error.outPtr());
     g_assert(javascriptResult);
+    test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(webkit_javascript_result_get_js_value(javascriptResult)));
     g_assert(!error.get());
     g_assert(WebViewTest::javascriptResultToBoolean(javascriptResult));
 
     javascriptResult = test->runJavaScriptAndWaitUntilFinished("a = false", &error.outPtr());
     g_assert(javascriptResult);
+    test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(webkit_javascript_result_get_js_value(javascriptResult)));
     g_assert(!error.get());
     g_assert(!WebViewTest::javascriptResultToBoolean(javascriptResult));
 
     javascriptResult = test->runJavaScriptAndWaitUntilFinished("a = null", &error.outPtr());
     g_assert(javascriptResult);
+    test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(webkit_javascript_result_get_js_value(javascriptResult)));
     g_assert(!error.get());
     g_assert(WebViewTest::javascriptResultIsNull(javascriptResult));
 
     javascriptResult = test->runJavaScriptAndWaitUntilFinished("function Foo() { a = 25; } Foo();", &error.outPtr());
     g_assert(javascriptResult);
+    test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(webkit_javascript_result_get_js_value(javascriptResult)));
     g_assert(!error.get());
     g_assert(WebViewTest::javascriptResultIsUndefined(javascriptResult));
 
     javascriptResult = test->runJavaScriptFromGResourceAndWaitUntilFinished("/org/webkit/glib/tests/link-title.js", &error.outPtr());
     g_assert(javascriptResult);
+    test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(webkit_javascript_result_get_js_value(javascriptResult)));
     g_assert(!error.get());
     valueString.reset(WebViewTest::javascriptResultToCString(javascriptResult));
     g_assert_cmpstr(valueString.get(), ==, "WebKitGTK+ Title");
index ed49184..474511e 100644 (file)
@@ -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 @@ static void consoleMessageSentCallback(WebKitWebPage* webPage, WebKitConsoleMess
     }
     *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 @@ static void pageCreatedCallback(WebKitWebExtension* extension, WebKitWebPage* we
 #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 @@ static void methodCallCallback(GDBusConnection* connection, const char* sender,
         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();
index e35f779..230fe8b 100644 (file)
@@ -21,8 +21,8 @@
 #include "WebProcessTest.h"
 
 #include "WebKitWebExtensionPrivate.h"
-#include <JavaScriptCore/JSRetainPtr.h>
 #include <gio/gio.h>
+#include <jsc/jsc.h>
 #include <wtf/HashSet.h>
 #include <wtf/NeverDestroyed.h>
 #include <wtf/glib/GUniquePtr.h>
@@ -55,31 +55,19 @@ std::unique_ptr<WebProcessTest> WebProcessTest::create(const String& testName)
     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[] =
-{
-    { "runTest", runTest, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
-    { nullptr, nullptr, 0 }
-};
-
-static void webProcessTestRunnerFinalize(JSObjectRef object)
+static void webProcessTestRunnerFinalize(WebKitWebPage* webPage)
 {
-    g_object_unref(JSObjectGetPrivate(object));
+    g_object_unref(webPage);
 
     if (s_watchedObjects.isEmpty())
         return;
@@ -97,19 +85,14 @@ static void windowObjectClearedCallback(WebKitScriptWorld* world, WebKitWebPage*
     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)
index d8d678f..df6a267 100644 (file)
@@ -6,6 +6,7 @@ list(APPEND WebKitGLibAPITests_SOURCES
 )
 
 list(APPEND WebKitGLibAPITests_INCLUDE_DIRECTORIES
+    ${DERIVED_SOURCES_JAVASCRIPCOREGTK_DIR}
     ${DERIVED_SOURCES_WEBKIT2GTK_DIR}
     ${FORWARDING_HEADERS_WEBKIT2GTK_DIR}
     ${FORWARDING_HEADERS_WEBKIT2GTK_EXTENSION_DIR}
index f60a20e..2ee7df9 100644 (file)
@@ -312,67 +312,42 @@ WebKitJavascriptResult* WebViewTest::runJavaScriptFromGResourceAndWaitUntilFinis
     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::javascriptResultToCString(WebKitJavascriptResult* javascriptResult)
 {
-    JSGlobalContextRef context = webkit_javascript_result_get_global_context(javascriptResult);
-    g_assert(context);
-    return jsValueToCString(context, webkit_javascript_result_get_value(javascriptResult));
+    auto* value = webkit_javascript_result_get_js_value(javascriptResult);
+    g_assert(JSC_IS_VALUE(value));
+    g_assert(jsc_value_is_string(value));
+    return jsc_value_to_string(value);
 }
 
 double WebViewTest::javascriptResultToNumber(WebKitJavascriptResult* javascriptResult)
 {
-    JSGlobalContextRef context = webkit_javascript_result_get_global_context(javascriptResult);
-    g_assert(context);
-    JSValueRef value = webkit_javascript_result_get_value(javascriptResult);
-    g_assert(value);
-    g_assert(JSValueIsNumber(context, value));
-
-    return JSValueToNumber(context, value, 0);
+    auto* value = webkit_javascript_result_get_js_value(javascriptResult);
+    g_assert(JSC_IS_VALUE(value));
+    g_assert(jsc_value_is_number(value));
+    return jsc_value_to_double(value);
 }
 
 bool WebViewTest::javascriptResultToBoolean(WebKitJavascriptResult* javascriptResult)
 {
-    JSGlobalContextRef context = webkit_javascript_result_get_global_context(javascriptResult);
-    g_assert(context);
-    JSValueRef value = webkit_javascript_result_get_value(javascriptResult);
-    g_assert(value);
-    g_assert(JSValueIsBoolean(context, value));
-
-    return JSValueToBoolean(context, value);
+    auto* value = webkit_javascript_result_get_js_value(javascriptResult);
+    g_assert(JSC_IS_VALUE(value));
+    g_assert(jsc_value_is_boolean(value));
+    return jsc_value_to_boolean(value);
 }
 
 bool WebViewTest::javascriptResultIsNull(WebKitJavascriptResult* javascriptResult)
 {
-    JSGlobalContextRef context = webkit_javascript_result_get_global_context(javascriptResult);
-    g_assert(context);
-    JSValueRef value = webkit_javascript_result_get_value(javascriptResult);
-    g_assert(value);
-
-    return JSValueIsNull(context, value);
+    auto* value = webkit_javascript_result_get_js_value(javascriptResult);
+    g_assert(JSC_IS_VALUE(value));
+    return jsc_value_is_null(value);
 }
 
 bool WebViewTest::javascriptResultIsUndefined(WebKitJavascriptResult* javascriptResult)
 {
-    JSGlobalContextRef context = webkit_javascript_result_get_global_context(javascriptResult);
-    g_assert(context);
-    JSValueRef value = webkit_javascript_result_get_value(javascriptResult);
-    g_assert(value);
-
-    return JSValueIsUndefined(context, value);
+    auto* value = webkit_javascript_result_get_js_value(javascriptResult);
+    g_assert(JSC_IS_VALUE(value));
+    return jsc_value_is_undefined(value);
 }
 
 #if PLATFORM(GTK)