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
* 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
* 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
* 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
* 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
* 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
* 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
* 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
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
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
)
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"
-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
-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
)
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}"
#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;
}
}
}
+#if PLATFORM(GTK)
/**
* webkit_javascript_result_get_global_context:
* @js_result: a #WebKitJavascriptResult
* <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()));
}
/**
* 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();
}
#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&);
{
}
- 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);
}
#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>
WebEvent::Modifiers mouseTargetModifiers;
GRefPtr<WebKitFindController> findController;
- JSRetainPtr<JSGlobalContextRef> javascriptGlobalContext;
GRefPtr<WebKitWebResource> mainResource;
LoadingResourcesMap loadingResourcesMap;
WebKitScriptDialog* currentScriptDialog;
#if PLATFORM(GTK)
+ GRefPtr<JSCContext> jsContext;
+
GRefPtr<WebKitWebInspector> inspector;
RefPtr<cairo_surface_t> favicon;
webkitWebViewHandleDownloadRequest(m_webView, &downloadProxy);
}
- JSGlobalContextRef javascriptGlobalContext() override
- {
- return webkit_web_view_get_javascript_global_context(m_webView);
- }
-
WebKitWebView* m_webView;
};
#endif
return webView->priv->findController.get();
}
+#if PLATFORM(GTK)
/**
* webkit_web_view_get_javascript_global_context:
* @web_view: a #WebKitWebView
*
* 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)
{
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));
}
* 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);
* 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");
}
#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)) {
WebCore::UserInterfaceLayoutDirection userInterfaceLayoutDirection() override { return WebCore::UserInterfaceLayoutDirection::LTR; }
- JSGlobalContextRef javascriptGlobalContext() override;
-
// Members of PageClientImpl class
GtkWidget* m_viewWidget;
DefaultUndoController m_undoController;
#define WebKitJavascriptResult_h
#include <JavaScriptCore/JSBase.h>
+#include <jsc/jsc.h>
#include <glib-object.h>
#include <webkit2/WebKitDefines.h>
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
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
webkit_javascript_result_unref
webkit_javascript_result_get_global_context
webkit_javascript_result_get_value
+webkit_javascript_result_get_js_value
<SUBSECTION WebKitScriptDialog>
WebKitScriptDialog
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
virtual void frameDisplayed(WKWPE::View&) { }
virtual void handleDownloadRequest(WKWPE::View&, WebKit::DownloadProxy&) { }
- virtual JSGlobalContextRef javascriptGlobalContext() { return nullptr; }
};
} // namespace API
return WebCore::UserInterfaceLayoutDirection::LTR;
}
-JSGlobalContextRef PageClientImpl::javascriptGlobalContext()
-{
- return m_view.javascriptGlobalContext();
-}
-
} // namespace WebKit
WebCore::UserInterfaceLayoutDirection userInterfaceLayoutDirection() override;
- JSGlobalContextRef javascriptGlobalContext() override;
-
WKWPE::View& m_view;
std::unique_ptr<ScrollGestureController> m_scrollGestureController;
#include "NativeWebWheelEvent.h"
#include "WebPageGroup.h"
#include "WebProcessPool.h"
-#include <JavaScriptCore/JSBase.h>
#include <wpe/view-backend.h>
using namespace WebKit;
m_client->handleDownloadRequest(*this, download);
}
-JSGlobalContextRef View::javascriptGlobalContext()
-{
- return m_client->javascriptGlobalContext();
-}
-
void View::setSize(const WebCore::IntSize& size)
{
m_size = size;
void setClient(std::unique_ptr<API::ViewClient>&&);
void frameDisplayed();
void handleDownloadRequest(WebKit::DownloadProxy&);
- JSGlobalContextRef javascriptGlobalContext();
WebKit::WebPageProxy& page() { return *m_pageProxy; }
#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
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
#ifndef WebKitWebView_h
#define WebKitWebView_h
-#include <JavaScriptCore/JSBase.h>
#include <wpe/WebKitAuthenticationRequest.h>
#include <wpe/WebKitBackForwardList.h>
#include <wpe/WebKitContextMenu.h>
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,
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
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&);
return static_cast<PageClientImpl&>(m_pageClient).viewWidget();
}
-JSGlobalContextRef WebPageProxy::javascriptGlobalContext()
-{
- return m_pageClient.javascriptGlobalContext();
-}
-
String WebPageProxy::standardUserAgent(const String& applicationNameForUserAgent)
{
return WebCore::standardUserAgent(applicationNameForUserAgent);
notImplemented();
}
-JSGlobalContextRef WebPageProxy::javascriptGlobalContext()
-{
- return m_pageClient.javascriptGlobalContext();
-}
-
String WebPageProxy::standardUserAgent(const String& applicationNameForUserAgent)
{
return WebCore::standardUserAgent(applicationNameForUserAgent);
#include "WebKitFramePrivate.h"
#include "WebKitScriptWorldPrivate.h"
+#include <jsc/JSCContextPrivate.h>
#include <wtf/glib/WTFGType.h>
#include <wtf/text/CString.h>
return frame->priv->uri.data();
}
+#if PLATFORM(GTK)
/**
* webkit_frame_get_javascript_global_context:
* @frame: a #WebKitFrame
* 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)
{
* 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)
{
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();
+}
#include <JavaScriptCore/JSBase.h>
#include <glib-object.h>
+#include <jsc/jsc.h>
#include <webkit2/WebKitDefines.h>
#include <webkit2/WebKitScriptWorld.h>
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
#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>
};
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
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
#include "cmakeconfig.h"
#include "BrowserWindow.h"
-#include <JavaScriptCore/JavaScript.h>
#include <errno.h>
#include <gst/gst.h>
#include <gtk/gtk.h>
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);
{
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;
}
#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>
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");
#if USE(GSTREAMER)
#include <gst/gst.h>
#endif
+#include <jsc/jsc.h>
#include <stdlib.h>
#include <string.h>
#include <wtf/Deque.h>
}
*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
}
#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)
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();
#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>
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;
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)
)
list(APPEND WebKitGLibAPITests_INCLUDE_DIRECTORIES
+ ${DERIVED_SOURCES_JAVASCRIPCOREGTK_DIR}
${DERIVED_SOURCES_WEBKIT2GTK_DIR}
${FORWARDING_HEADERS_WEBKIT2GTK_DIR}
${FORWARDING_HEADERS_WEBKIT2GTK_EXTENSION_DIR}
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)