logo

etc_portage

Unnamed repository; edit this file 'description' to name the repository. git clone https://hacktivis.me/git/etc_portage.git

webkit-gtk-2.24.3-fix-glib-crash-js-object.patch (11739B)


  1. Index: trunk/Source/JavaScriptCore/API/glib/JSCCallbackFunction.cpp
  2. ===================================================================
  3. --- trunk/Source/JavaScriptCore/API/glib/JSCCallbackFunction.cpp (revision 245513)
  4. +++ trunk/Source/JavaScriptCore/API/glib/JSCCallbackFunction.cpp (revision 245514)
  5. @@ -208,5 +208,5 @@
  6. case G_TYPE_OBJECT:
  7. if (auto* ptr = returnValue.data[0].v_pointer)
  8. - return toRef(jscClassGetOrCreateJSWrapper(m_class.get(), ptr));
  9. + return toRef(jscClassGetOrCreateJSWrapper(m_class.get(), context.get(), ptr));
  10. *exception = toRef(JSC::createTypeError(toJS(jsContext), "constructor returned null"_s));
  11. break;
  12. Index: trunk/Source/JavaScriptCore/API/glib/JSCClass.cpp
  13. ===================================================================
  14. --- trunk/Source/JavaScriptCore/API/glib/JSCClass.cpp (revision 245513)
  15. +++ trunk/Source/JavaScriptCore/API/glib/JSCClass.cpp (revision 245514)
  16. @@ -57,5 +57,5 @@
  17. typedef struct _JSCClassPrivate {
  18. - JSCContext* context;
  19. + JSGlobalContextRef context;
  20. CString name;
  21. JSClassRef jsClass;
  22. @@ -64,5 +64,4 @@
  23. JSCClass* parentClass;
  24. JSC::Weak<JSC::JSObject> prototype;
  25. - HashMap<CString, JSC::Weak<JSC::JSObject>> constructors;
  26. } JSCClassPrivate;
  27. @@ -284,7 +283,4 @@
  28. switch (propID) {
  29. - case PROP_CONTEXT:
  30. - g_value_set_object(value, jscClass->priv->context);
  31. - break;
  32. case PROP_NAME:
  33. g_value_set_string(value, jscClass->priv->name.data());
  34. @@ -304,5 +300,5 @@
  35. switch (propID) {
  36. case PROP_CONTEXT:
  37. - jscClass->priv->context = JSC_CONTEXT(g_value_get_object(value));
  38. + jscClass->priv->context = jscContextGetJSContext(JSC_CONTEXT(g_value_get_object(value)));
  39. break;
  40. case PROP_NAME:
  41. @@ -348,5 +344,5 @@
  42. "JSC Context",
  43. JSC_TYPE_CONTEXT,
  44. - static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)));
  45. + static_cast<GParamFlags>(WEBKIT_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)));
  46. /**
  47. @@ -493,9 +489,9 @@
  48. prototypeDefinition.className = prototypeName.get();
  49. JSClassRef prototypeClass = JSClassCreate(&prototypeDefinition);
  50. - priv->prototype = jscContextGetOrCreateJSWrapper(priv->context, prototypeClass);
  51. + priv->prototype = jscContextGetOrCreateJSWrapper(context, prototypeClass);
  52. JSClassRelease(prototypeClass);
  53. if (priv->parentClass)
  54. - JSObjectSetPrototype(jscContextGetJSContext(priv->context), toRef(priv->prototype.get()), toRef(priv->parentClass->priv->prototype.get()));
  55. + JSObjectSetPrototype(jscContextGetJSContext(context), toRef(priv->prototype.get()), toRef(priv->parentClass->priv->prototype.get()));
  56. return jscClass;
  57. }
  58. @@ -506,14 +502,14 @@
  59. }
  60. -JSC::JSObject* jscClassGetOrCreateJSWrapper(JSCClass* jscClass, gpointer wrappedObject)
  61. +JSC::JSObject* jscClassGetOrCreateJSWrapper(JSCClass* jscClass, JSCContext* context, gpointer wrappedObject)
  62. {
  63. JSCClassPrivate* priv = jscClass->priv;
  64. - return jscContextGetOrCreateJSWrapper(priv->context, priv->jsClass, toRef(priv->prototype.get()), wrappedObject, priv->destroyFunction);
  65. -}
  66. -
  67. -JSGlobalContextRef jscClassCreateContextWithJSWrapper(JSCClass* jscClass, gpointer wrappedObject)
  68. + return jscContextGetOrCreateJSWrapper(context, priv->jsClass, toRef(priv->prototype.get()), wrappedObject, priv->destroyFunction);
  69. +}
  70. +
  71. +JSGlobalContextRef jscClassCreateContextWithJSWrapper(JSCClass* jscClass, JSCContext* context, gpointer wrappedObject)
  72. {
  73. JSCClassPrivate* priv = jscClass->priv;
  74. - return jscContextCreateContextWithJSWrapper(priv->context, priv->jsClass, toRef(priv->prototype.get()), wrappedObject, priv->destroyFunction);
  75. + return jscContextCreateContextWithJSWrapper(context, priv->jsClass, toRef(priv->prototype.get()), wrappedObject, priv->destroyFunction);
  76. }
  77. @@ -563,15 +559,15 @@
  78. closure = adoptGRef(g_cclosure_new(callback, userData, reinterpret_cast<GClosureNotify>(reinterpret_cast<GCallback>(destroyNotify))));
  79. JSCClassPrivate* priv = jscClass->priv;
  80. - JSC::ExecState* exec = toJS(jscContextGetJSContext(priv->context));
  81. + JSC::ExecState* exec = toJS(priv->context);
  82. JSC::VM& vm = exec->vm();
  83. JSC::JSLockHolder locker(vm);
  84. auto* functionObject = JSC::JSCCallbackFunction::create(vm, exec->lexicalGlobalObject(), String::fromUTF8(name),
  85. JSC::JSCCallbackFunction::Type::Constructor, jscClass, WTFMove(closure), returnType, WTFMove(parameters));
  86. - auto constructor = jscContextGetOrCreateValue(priv->context, toRef(functionObject));
  87. - GRefPtr<JSCValue> prototype = jscContextGetOrCreateValue(priv->context, toRef(priv->prototype.get()));
  88. + auto context = jscContextGetOrCreate(priv->context);
  89. + auto constructor = jscContextGetOrCreateValue(context.get(), toRef(functionObject));
  90. + GRefPtr<JSCValue> prototype = jscContextGetOrCreateValue(context.get(), toRef(priv->prototype.get()));
  91. auto nonEnumerable = static_cast<JSCValuePropertyFlags>(JSC_VALUE_PROPERTY_CONFIGURABLE | JSC_VALUE_PROPERTY_WRITABLE);
  92. jsc_value_object_define_property_data(constructor.get(), "prototype", nonEnumerable, prototype.get());
  93. jsc_value_object_define_property_data(prototype.get(), "constructor", nonEnumerable, constructor.get());
  94. - priv->constructors.set(name, functionObject);
  95. return constructor;
  96. }
  97. @@ -712,11 +708,12 @@
  98. JSCClassPrivate* priv = jscClass->priv;
  99. GRefPtr<GClosure> closure = adoptGRef(g_cclosure_new(callback, userData, reinterpret_cast<GClosureNotify>(reinterpret_cast<GCallback>(destroyNotify))));
  100. - JSC::ExecState* exec = toJS(jscContextGetJSContext(priv->context));
  101. + JSC::ExecState* exec = toJS(priv->context);
  102. JSC::VM& vm = exec->vm();
  103. JSC::JSLockHolder locker(vm);
  104. auto* functionObject = toRef(JSC::JSCCallbackFunction::create(vm, exec->lexicalGlobalObject(), String::fromUTF8(name),
  105. JSC::JSCCallbackFunction::Type::Method, jscClass, WTFMove(closure), returnType, WTFMove(parameters)));
  106. - auto method = jscContextGetOrCreateValue(priv->context, functionObject);
  107. - GRefPtr<JSCValue> prototype = jscContextGetOrCreateValue(priv->context, toRef(priv->prototype.get()));
  108. + auto context = jscContextGetOrCreate(priv->context);
  109. + auto method = jscContextGetOrCreateValue(context.get(), functionObject);
  110. + GRefPtr<JSCValue> prototype = jscContextGetOrCreateValue(context.get(), toRef(priv->prototype.get()));
  111. auto nonEnumerable = static_cast<JSCValuePropertyFlags>(JSC_VALUE_PROPERTY_CONFIGURABLE | JSC_VALUE_PROPERTY_WRITABLE);
  112. jsc_value_object_define_property_data(prototype.get(), name, nonEnumerable, method.get());
  113. @@ -863,5 +860,6 @@
  114. g_return_if_fail(priv->context);
  115. - GRefPtr<JSCValue> prototype = jscContextGetOrCreateValue(priv->context, toRef(priv->prototype.get()));
  116. + auto context = jscContextGetOrCreate(priv->context);
  117. + GRefPtr<JSCValue> prototype = jscContextGetOrCreateValue(context.get(), toRef(priv->prototype.get()));
  118. jsc_value_object_define_property_accessor(prototype.get(), name, JSC_VALUE_PROPERTY_CONFIGURABLE, propertyType, getter, setter, userData, destroyNotify);
  119. }
  120. Index: trunk/Source/JavaScriptCore/API/glib/JSCClassPrivate.h
  121. ===================================================================
  122. --- trunk/Source/JavaScriptCore/API/glib/JSCClassPrivate.h (revision 245513)
  123. +++ trunk/Source/JavaScriptCore/API/glib/JSCClassPrivate.h (revision 245514)
  124. @@ -28,5 +28,5 @@
  125. GRefPtr<JSCClass> jscClassCreate(JSCContext*, const char*, JSCClass*, JSCClassVTable*, GDestroyNotify);
  126. JSClassRef jscClassGetJSClass(JSCClass*);
  127. -JSC::JSObject* jscClassGetOrCreateJSWrapper(JSCClass*, gpointer);
  128. -JSGlobalContextRef jscClassCreateContextWithJSWrapper(JSCClass*, gpointer);
  129. +JSC::JSObject* jscClassGetOrCreateJSWrapper(JSCClass*, JSCContext*, gpointer);
  130. +JSGlobalContextRef jscClassCreateContextWithJSWrapper(JSCClass*, JSCContext*, gpointer);
  131. void jscClassInvalidate(JSCClass*);
  132. Index: trunk/Source/JavaScriptCore/API/glib/JSCContext.cpp
  133. ===================================================================
  134. --- trunk/Source/JavaScriptCore/API/glib/JSCContext.cpp (revision 245513)
  135. +++ trunk/Source/JavaScriptCore/API/glib/JSCContext.cpp (revision 245514)
  136. @@ -879,5 +879,5 @@
  137. JSRetainPtr<JSGlobalContextRef> objectContext(Adopt,
  138. - instance ? jscClassCreateContextWithJSWrapper(objectClass, instance) : JSGlobalContextCreateInGroup(jscVirtualMachineGetContextGroup(context->priv->vm.get()), nullptr));
  139. + instance ? jscClassCreateContextWithJSWrapper(objectClass, context, instance) : JSGlobalContextCreateInGroup(jscVirtualMachineGetContextGroup(context->priv->vm.get()), nullptr));
  140. JSC::ExecState* exec = toJS(objectContext.get());
  141. JSC::VM& vm = exec->vm();
  142. Index: trunk/Source/JavaScriptCore/API/glib/JSCValue.cpp
  143. ===================================================================
  144. --- trunk/Source/JavaScriptCore/API/glib/JSCValue.cpp (revision 245513)
  145. +++ trunk/Source/JavaScriptCore/API/glib/JSCValue.cpp (revision 245514)
  146. @@ -603,5 +603,5 @@
  147. g_return_val_if_fail(!instance || JSC_IS_CLASS(jscClass), nullptr);
  148. - return jscContextGetOrCreateValue(context, instance ? toRef(jscClassGetOrCreateJSWrapper(jscClass, instance)) : JSObjectMake(jscContextGetJSContext(context), nullptr, nullptr)).leakRef();
  149. + return jscContextGetOrCreateValue(context, instance ? toRef(jscClassGetOrCreateJSWrapper(jscClass, context, instance)) : JSObjectMake(jscContextGetJSContext(context), nullptr, nullptr)).leakRef();
  150. }
  151. Index: trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebExtensions.cpp
  152. ===================================================================
  153. --- trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebExtensions.cpp (revision 245513)
  154. +++ trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebExtensions.cpp (revision 245514)
  155. @@ -180,4 +180,11 @@
  156. GUniquePtr<char> valueString(WebViewTest::javascriptResultToCString(javascriptResult));
  157. g_assert_cmpstr(valueString.get(), ==, "Foo");
  158. +
  159. + javascriptResult = test->runJavaScriptAndWaitUntilFinished("var f = new GFile('.'); f.path();", &error.outPtr());
  160. + g_assert_nonnull(javascriptResult);
  161. + g_assert_no_error(error.get());
  162. + valueString.reset(WebViewTest::javascriptResultToCString(javascriptResult));
  163. + GUniquePtr<char> currentDirectory(g_get_current_dir());
  164. + g_assert_cmpstr(valueString.get(), ==, currentDirectory.get());
  165. }
  166. Index: trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/WebExtensionTest.cpp
  167. ===================================================================
  168. --- trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/WebExtensionTest.cpp (revision 245513)
  169. +++ trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/WebExtensionTest.cpp (revision 245514)
  170. @@ -428,4 +428,9 @@
  171. GRefPtr<JSCValue> function = adoptGRef(jsc_value_new_function(jsContext.get(), "echo", G_CALLBACK(echoCallback), NULL, NULL, G_TYPE_STRING, 1, G_TYPE_STRING));
  172. jsc_context_set_value(jsContext.get(), "echo", function.get());
  173. +
  174. + auto* fileClass = jsc_context_register_class(jsContext.get(), "GFile", nullptr, nullptr, static_cast<GDestroyNotify>(g_object_unref));
  175. + 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));
  176. + jsc_class_add_method(fileClass, "path", G_CALLBACK(g_file_get_path), nullptr, nullptr, G_TYPE_STRING, 0, G_TYPE_NONE);
  177. + jsc_context_set_value(jsContext.get(), "GFile", constructor.get());
  178. }