webkit-gtk-2.24.3-fix-glib-crash-js-object.patch (11739B)
- Index: trunk/Source/JavaScriptCore/API/glib/JSCCallbackFunction.cpp
- ===================================================================
- --- trunk/Source/JavaScriptCore/API/glib/JSCCallbackFunction.cpp (revision 245513)
- +++ trunk/Source/JavaScriptCore/API/glib/JSCCallbackFunction.cpp (revision 245514)
- @@ -208,5 +208,5 @@
- case G_TYPE_OBJECT:
- if (auto* ptr = returnValue.data[0].v_pointer)
- - return toRef(jscClassGetOrCreateJSWrapper(m_class.get(), ptr));
- + return toRef(jscClassGetOrCreateJSWrapper(m_class.get(), context.get(), ptr));
- *exception = toRef(JSC::createTypeError(toJS(jsContext), "constructor returned null"_s));
- break;
- Index: trunk/Source/JavaScriptCore/API/glib/JSCClass.cpp
- ===================================================================
- --- trunk/Source/JavaScriptCore/API/glib/JSCClass.cpp (revision 245513)
- +++ trunk/Source/JavaScriptCore/API/glib/JSCClass.cpp (revision 245514)
- @@ -57,5 +57,5 @@
- typedef struct _JSCClassPrivate {
- - JSCContext* context;
- + JSGlobalContextRef context;
- CString name;
- JSClassRef jsClass;
- @@ -64,5 +64,4 @@
- JSCClass* parentClass;
- JSC::Weak<JSC::JSObject> prototype;
- - HashMap<CString, JSC::Weak<JSC::JSObject>> constructors;
- } JSCClassPrivate;
- @@ -284,7 +283,4 @@
- switch (propID) {
- - case PROP_CONTEXT:
- - g_value_set_object(value, jscClass->priv->context);
- - break;
- case PROP_NAME:
- g_value_set_string(value, jscClass->priv->name.data());
- @@ -304,5 +300,5 @@
- switch (propID) {
- case PROP_CONTEXT:
- - jscClass->priv->context = JSC_CONTEXT(g_value_get_object(value));
- + jscClass->priv->context = jscContextGetJSContext(JSC_CONTEXT(g_value_get_object(value)));
- break;
- case PROP_NAME:
- @@ -348,5 +344,5 @@
- "JSC Context",
- JSC_TYPE_CONTEXT,
- - static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)));
- + static_cast<GParamFlags>(WEBKIT_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)));
- /**
- @@ -493,9 +489,9 @@
- prototypeDefinition.className = prototypeName.get();
- JSClassRef prototypeClass = JSClassCreate(&prototypeDefinition);
- - priv->prototype = jscContextGetOrCreateJSWrapper(priv->context, prototypeClass);
- + priv->prototype = jscContextGetOrCreateJSWrapper(context, prototypeClass);
- JSClassRelease(prototypeClass);
- if (priv->parentClass)
- - JSObjectSetPrototype(jscContextGetJSContext(priv->context), toRef(priv->prototype.get()), toRef(priv->parentClass->priv->prototype.get()));
- + JSObjectSetPrototype(jscContextGetJSContext(context), toRef(priv->prototype.get()), toRef(priv->parentClass->priv->prototype.get()));
- return jscClass;
- }
- @@ -506,14 +502,14 @@
- }
- -JSC::JSObject* jscClassGetOrCreateJSWrapper(JSCClass* jscClass, gpointer wrappedObject)
- +JSC::JSObject* jscClassGetOrCreateJSWrapper(JSCClass* jscClass, JSCContext* context, gpointer wrappedObject)
- {
- JSCClassPrivate* priv = jscClass->priv;
- - return jscContextGetOrCreateJSWrapper(priv->context, priv->jsClass, toRef(priv->prototype.get()), wrappedObject, priv->destroyFunction);
- -}
- -
- -JSGlobalContextRef jscClassCreateContextWithJSWrapper(JSCClass* jscClass, gpointer wrappedObject)
- + return jscContextGetOrCreateJSWrapper(context, priv->jsClass, toRef(priv->prototype.get()), wrappedObject, priv->destroyFunction);
- +}
- +
- +JSGlobalContextRef jscClassCreateContextWithJSWrapper(JSCClass* jscClass, JSCContext* context, gpointer wrappedObject)
- {
- JSCClassPrivate* priv = jscClass->priv;
- - return jscContextCreateContextWithJSWrapper(priv->context, priv->jsClass, toRef(priv->prototype.get()), wrappedObject, priv->destroyFunction);
- + return jscContextCreateContextWithJSWrapper(context, priv->jsClass, toRef(priv->prototype.get()), wrappedObject, priv->destroyFunction);
- }
- @@ -563,15 +559,15 @@
- closure = adoptGRef(g_cclosure_new(callback, userData, reinterpret_cast<GClosureNotify>(reinterpret_cast<GCallback>(destroyNotify))));
- JSCClassPrivate* priv = jscClass->priv;
- - JSC::ExecState* exec = toJS(jscContextGetJSContext(priv->context));
- + JSC::ExecState* exec = toJS(priv->context);
- JSC::VM& vm = exec->vm();
- JSC::JSLockHolder locker(vm);
- auto* functionObject = JSC::JSCCallbackFunction::create(vm, exec->lexicalGlobalObject(), String::fromUTF8(name),
- JSC::JSCCallbackFunction::Type::Constructor, jscClass, WTFMove(closure), returnType, WTFMove(parameters));
- - auto constructor = jscContextGetOrCreateValue(priv->context, toRef(functionObject));
- - GRefPtr<JSCValue> prototype = jscContextGetOrCreateValue(priv->context, toRef(priv->prototype.get()));
- + auto context = jscContextGetOrCreate(priv->context);
- + auto constructor = jscContextGetOrCreateValue(context.get(), toRef(functionObject));
- + GRefPtr<JSCValue> prototype = jscContextGetOrCreateValue(context.get(), toRef(priv->prototype.get()));
- auto nonEnumerable = static_cast<JSCValuePropertyFlags>(JSC_VALUE_PROPERTY_CONFIGURABLE | JSC_VALUE_PROPERTY_WRITABLE);
- jsc_value_object_define_property_data(constructor.get(), "prototype", nonEnumerable, prototype.get());
- jsc_value_object_define_property_data(prototype.get(), "constructor", nonEnumerable, constructor.get());
- - priv->constructors.set(name, functionObject);
- return constructor;
- }
- @@ -712,11 +708,12 @@
- JSCClassPrivate* priv = jscClass->priv;
- GRefPtr<GClosure> closure = adoptGRef(g_cclosure_new(callback, userData, reinterpret_cast<GClosureNotify>(reinterpret_cast<GCallback>(destroyNotify))));
- - JSC::ExecState* exec = toJS(jscContextGetJSContext(priv->context));
- + JSC::ExecState* exec = toJS(priv->context);
- JSC::VM& vm = exec->vm();
- JSC::JSLockHolder locker(vm);
- auto* functionObject = toRef(JSC::JSCCallbackFunction::create(vm, exec->lexicalGlobalObject(), String::fromUTF8(name),
- JSC::JSCCallbackFunction::Type::Method, jscClass, WTFMove(closure), returnType, WTFMove(parameters)));
- - auto method = jscContextGetOrCreateValue(priv->context, functionObject);
- - GRefPtr<JSCValue> prototype = jscContextGetOrCreateValue(priv->context, toRef(priv->prototype.get()));
- + auto context = jscContextGetOrCreate(priv->context);
- + auto method = jscContextGetOrCreateValue(context.get(), functionObject);
- + GRefPtr<JSCValue> prototype = jscContextGetOrCreateValue(context.get(), toRef(priv->prototype.get()));
- auto nonEnumerable = static_cast<JSCValuePropertyFlags>(JSC_VALUE_PROPERTY_CONFIGURABLE | JSC_VALUE_PROPERTY_WRITABLE);
- jsc_value_object_define_property_data(prototype.get(), name, nonEnumerable, method.get());
- @@ -863,5 +860,6 @@
- g_return_if_fail(priv->context);
- - GRefPtr<JSCValue> prototype = jscContextGetOrCreateValue(priv->context, toRef(priv->prototype.get()));
- + auto context = jscContextGetOrCreate(priv->context);
- + GRefPtr<JSCValue> prototype = jscContextGetOrCreateValue(context.get(), toRef(priv->prototype.get()));
- jsc_value_object_define_property_accessor(prototype.get(), name, JSC_VALUE_PROPERTY_CONFIGURABLE, propertyType, getter, setter, userData, destroyNotify);
- }
- Index: trunk/Source/JavaScriptCore/API/glib/JSCClassPrivate.h
- ===================================================================
- --- trunk/Source/JavaScriptCore/API/glib/JSCClassPrivate.h (revision 245513)
- +++ trunk/Source/JavaScriptCore/API/glib/JSCClassPrivate.h (revision 245514)
- @@ -28,5 +28,5 @@
- GRefPtr<JSCClass> jscClassCreate(JSCContext*, const char*, JSCClass*, JSCClassVTable*, GDestroyNotify);
- JSClassRef jscClassGetJSClass(JSCClass*);
- -JSC::JSObject* jscClassGetOrCreateJSWrapper(JSCClass*, gpointer);
- -JSGlobalContextRef jscClassCreateContextWithJSWrapper(JSCClass*, gpointer);
- +JSC::JSObject* jscClassGetOrCreateJSWrapper(JSCClass*, JSCContext*, gpointer);
- +JSGlobalContextRef jscClassCreateContextWithJSWrapper(JSCClass*, JSCContext*, gpointer);
- void jscClassInvalidate(JSCClass*);
- Index: trunk/Source/JavaScriptCore/API/glib/JSCContext.cpp
- ===================================================================
- --- trunk/Source/JavaScriptCore/API/glib/JSCContext.cpp (revision 245513)
- +++ trunk/Source/JavaScriptCore/API/glib/JSCContext.cpp (revision 245514)
- @@ -879,5 +879,5 @@
- JSRetainPtr<JSGlobalContextRef> objectContext(Adopt,
- - instance ? jscClassCreateContextWithJSWrapper(objectClass, instance) : JSGlobalContextCreateInGroup(jscVirtualMachineGetContextGroup(context->priv->vm.get()), nullptr));
- + instance ? jscClassCreateContextWithJSWrapper(objectClass, context, instance) : JSGlobalContextCreateInGroup(jscVirtualMachineGetContextGroup(context->priv->vm.get()), nullptr));
- JSC::ExecState* exec = toJS(objectContext.get());
- JSC::VM& vm = exec->vm();
- Index: trunk/Source/JavaScriptCore/API/glib/JSCValue.cpp
- ===================================================================
- --- trunk/Source/JavaScriptCore/API/glib/JSCValue.cpp (revision 245513)
- +++ trunk/Source/JavaScriptCore/API/glib/JSCValue.cpp (revision 245514)
- @@ -603,5 +603,5 @@
- g_return_val_if_fail(!instance || JSC_IS_CLASS(jscClass), nullptr);
- - return jscContextGetOrCreateValue(context, instance ? toRef(jscClassGetOrCreateJSWrapper(jscClass, instance)) : JSObjectMake(jscContextGetJSContext(context), nullptr, nullptr)).leakRef();
- + return jscContextGetOrCreateValue(context, instance ? toRef(jscClassGetOrCreateJSWrapper(jscClass, context, instance)) : JSObjectMake(jscContextGetJSContext(context), nullptr, nullptr)).leakRef();
- }
- Index: trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebExtensions.cpp
- ===================================================================
- --- trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebExtensions.cpp (revision 245513)
- +++ trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebExtensions.cpp (revision 245514)
- @@ -180,4 +180,11 @@
- GUniquePtr<char> valueString(WebViewTest::javascriptResultToCString(javascriptResult));
- g_assert_cmpstr(valueString.get(), ==, "Foo");
- +
- + javascriptResult = test->runJavaScriptAndWaitUntilFinished("var f = new GFile('.'); f.path();", &error.outPtr());
- + g_assert_nonnull(javascriptResult);
- + g_assert_no_error(error.get());
- + valueString.reset(WebViewTest::javascriptResultToCString(javascriptResult));
- + GUniquePtr<char> currentDirectory(g_get_current_dir());
- + g_assert_cmpstr(valueString.get(), ==, currentDirectory.get());
- }
- Index: trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/WebExtensionTest.cpp
- ===================================================================
- --- trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/WebExtensionTest.cpp (revision 245513)
- +++ trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/WebExtensionTest.cpp (revision 245514)
- @@ -428,4 +428,9 @@
- 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());
- +
- + auto* fileClass = jsc_context_register_class(jsContext.get(), "GFile", nullptr, nullptr, static_cast<GDestroyNotify>(g_object_unref));
- + GRefPtr<JSCValue> constructor = adoptGRef(jsc_class_add_constructor(fileClass, "GFile", G_CALLBACK(g_file_new_for_path), nullptr, nullptr, G_TYPE_OBJECT, 1, G_TYPE_STRING));
- + jsc_class_add_method(fileClass, "path", G_CALLBACK(g_file_get_path), nullptr, nullptr, G_TYPE_STRING, 0, G_TYPE_NONE);
- + jsc_context_set_value(jsContext.get(), "GFile", constructor.get());
- }