Title: [250485] trunk/Source/WebCore
Revision
250485
Author
[email protected]
Date
2019-09-28 17:26:13 -0700 (Sat, 28 Sep 2019)

Log Message

[IDL] Support record<DOMString, *Callback> in bindings
https://bugs.webkit.org/show_bug.cgi?id=202326

Reviewed by Sam Weinig.

Currently, IDLRecord's converter assumes that the value type (template argument V) can be converted by passing
in only an ExecState and the JSValue, since it calls `auto typedValue = Converter<V>::convert(state, subValue)`.
However, IDLCallbackFunctions additionally require the JSDOMGlobalObject (see JSDOMConverterCallbacks.h). This
results in a compilation error in generated code, when attempting to convert the record.

To fix this, teach Converter<IDLRecord<K, V>> to accept three arguments (the ExecState, value, and global
object) in the case where V requires the global object. Additionally, let the bindings generator know that
JSValue to native object conversion requires the global object, by returning whether or not the value type of
the IDL record requires the global object, in the case where the given type is a record.

* bindings/js/JSDOMConvertRecord.h:
* bindings/scripts/CodeGeneratorJS.pm:
(JSValueToNativeDOMConvertNeedsGlobalObject):
* bindings/scripts/test/JS/JSTestObj.cpp:

Test this scenario by augmenting TestObj.idl with record<DOMString, VoidCallback>.

(WebCore::jsTestObjStringVoidCallbackRecordAttrGetter):
(WebCore::jsTestObjStringVoidCallbackRecordAttr):
(WebCore::setJSTestObjStringVoidCallbackRecordAttrSetter):
(WebCore::setJSTestObjStringVoidCallbackRecordAttr):
* bindings/scripts/test/TestObj.idl:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (250484 => 250485)


--- trunk/Source/WebCore/ChangeLog	2019-09-28 23:58:10 UTC (rev 250484)
+++ trunk/Source/WebCore/ChangeLog	2019-09-29 00:26:13 UTC (rev 250485)
@@ -1,3 +1,33 @@
+2019-09-28  Wenson Hsieh  <[email protected]>
+
+        [IDL] Support record<DOMString, *Callback> in bindings
+        https://bugs.webkit.org/show_bug.cgi?id=202326
+
+        Reviewed by Sam Weinig.
+
+        Currently, IDLRecord's converter assumes that the value type (template argument V) can be converted by passing
+        in only an ExecState and the JSValue, since it calls `auto typedValue = Converter<V>::convert(state, subValue)`.
+        However, IDLCallbackFunctions additionally require the JSDOMGlobalObject (see JSDOMConverterCallbacks.h). This
+        results in a compilation error in generated code, when attempting to convert the record.
+
+        To fix this, teach Converter<IDLRecord<K, V>> to accept three arguments (the ExecState, value, and global
+        object) in the case where V requires the global object. Additionally, let the bindings generator know that
+        JSValue to native object conversion requires the global object, by returning whether or not the value type of
+        the IDL record requires the global object, in the case where the given type is a record.
+
+        * bindings/js/JSDOMConvertRecord.h:
+        * bindings/scripts/CodeGeneratorJS.pm:
+        (JSValueToNativeDOMConvertNeedsGlobalObject):
+        * bindings/scripts/test/JS/JSTestObj.cpp:
+
+        Test this scenario by augmenting TestObj.idl with record<DOMString, VoidCallback>.
+
+        (WebCore::jsTestObjStringVoidCallbackRecordAttrGetter):
+        (WebCore::jsTestObjStringVoidCallbackRecordAttr):
+        (WebCore::setJSTestObjStringVoidCallbackRecordAttrSetter):
+        (WebCore::setJSTestObjStringVoidCallbackRecordAttr):
+        * bindings/scripts/test/TestObj.idl:
+
 2019-09-28  Zalan Bujtas  <[email protected]>
 
         [LFC][IFC] Line::InitialConstraints's heightAndBaseline should be optional

Modified: trunk/Source/WebCore/bindings/js/JSDOMConvertRecord.h (250484 => 250485)


--- trunk/Source/WebCore/bindings/js/JSDOMConvertRecord.h	2019-09-28 23:58:10 UTC (rev 250484)
+++ trunk/Source/WebCore/bindings/js/JSDOMConvertRecord.h	2019-09-29 00:26:13 UTC (rev 250485)
@@ -64,8 +64,20 @@
     using KeyType = typename K::ImplementationType;
     using ValueType = typename V::ImplementationType;
 
+    static ReturnType convert(JSC::ExecState& state, JSC::JSValue value, JSDOMGlobalObject& globalObject)
+    {
+        return convertRecord<JSDOMGlobalObject&>(state, value, globalObject);
+    }
+
     static ReturnType convert(JSC::ExecState& state, JSC::JSValue value)
     {
+        return convertRecord(state, value);
+    }
+
+private:
+    template<class...Args>
+    static ReturnType convertRecord(JSC::ExecState& state, JSC::JSValue value, Args ... args)
+    {
         auto& vm = state.vm();
         auto scope = DECLARE_THROW_SCOPE(vm);
 
@@ -111,7 +123,7 @@
                 RETURN_IF_EXCEPTION(scope, { });
 
                 // 3. Let typedValue be value converted to an IDL value of type V.
-                auto typedValue = Converter<V>::convert(state, subValue);
+                auto typedValue = Converter<V>::convert(state, subValue, args...);
                 RETURN_IF_EXCEPTION(scope, { });
                 
                 // 4. If typedKey is already a key in result, set its value to typedValue.

Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm (250484 => 250485)


--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm	2019-09-28 23:58:10 UTC (rev 250484)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm	2019-09-29 00:26:13 UTC (rev 250485)
@@ -6616,6 +6616,7 @@
 
     return 1 if $codeGenerator->IsCallbackInterface($type);
     return 1 if $codeGenerator->IsCallbackFunction($type);
+    return JSValueToNativeDOMConvertNeedsGlobalObject(@{$type->subtypes}[1]) if $codeGenerator->IsRecordType($type);
     return 1 if $type->name eq "ScheduledAction";
     return 0;
 }

Modified: trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp (250484 => 250485)


--- trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp	2019-09-28 23:58:10 UTC (rev 250484)
+++ trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp	2019-09-29 00:26:13 UTC (rev 250485)
@@ -74,6 +74,7 @@
 #include "JSTestStandaloneDictionary.h"
 #include "JSTestStandaloneEnumeration.h"
 #include "JSTestSubObj.h"
+#include "JSVoidCallback.h"
 #include "JSWindowProxy.h"
 #include "JSXPathNSResolver.h"
 #include "RuntimeEnabledFeatures.h"
@@ -1651,6 +1652,8 @@
 bool setJSTestObjStringObjRecordAttr(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
 JSC::EncodedJSValue jsTestObjStringNullableObjRecordAttr(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
 bool setJSTestObjStringNullableObjRecordAttr(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
+JSC::EncodedJSValue jsTestObjStringVoidCallbackRecordAttr(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
+bool setJSTestObjStringVoidCallbackRecordAttr(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
 JSC::EncodedJSValue jsTestObjDictionaryAttr(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
 bool setJSTestObjDictionaryAttr(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
 JSC::EncodedJSValue jsTestObjNullableDictionaryAttr(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
@@ -2020,6 +2023,7 @@
     { "usvstringLongRecordAttr", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjUsvstringLongRecordAttr), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestObjUsvstringLongRecordAttr) } },
     { "stringObjRecordAttr", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjStringObjRecordAttr), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestObjStringObjRecordAttr) } },
     { "stringNullableObjRecordAttr", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjStringNullableObjRecordAttr), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestObjStringNullableObjRecordAttr) } },
+    { "stringVoidCallbackRecordAttr", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjStringVoidCallbackRecordAttr), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestObjStringVoidCallbackRecordAttr) } },
     { "dictionaryAttr", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjDictionaryAttr), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestObjDictionaryAttr) } },
     { "nullableDictionaryAttr", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjNullableDictionaryAttr), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestObjNullableDictionaryAttr) } },
     { "annotatedTypeInUnionAttr", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjAnnotatedTypeInUnionAttr), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestObjAnnotatedTypeInUnionAttr) } },
@@ -3464,6 +3468,38 @@
     return IDLAttribute<JSTestObj>::set<setJSTestObjStringNullableObjRecordAttrSetter>(*state, thisValue, encodedValue, "stringNullableObjRecordAttr");
 }
 
+static inline JSValue jsTestObjStringVoidCallbackRecordAttrGetter(ExecState& state, JSTestObj& thisObject, ThrowScope& throwScope)
+{
+    UNUSED_PARAM(throwScope);
+    UNUSED_PARAM(state);
+    auto& impl = thisObject.wrapped();
+    JSValue result = toJS<IDLRecord<IDLDOMString, IDLCallbackFunction<JSVoidCallback>>>(state, *thisObject.globalObject(), throwScope, impl.stringVoidCallbackRecordAttr());
+    return result;
+}
+
+EncodedJSValue jsTestObjStringVoidCallbackRecordAttr(ExecState* state, EncodedJSValue thisValue, PropertyName)
+{
+    return IDLAttribute<JSTestObj>::get<jsTestObjStringVoidCallbackRecordAttrGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "stringVoidCallbackRecordAttr");
+}
+
+static inline bool setJSTestObjStringVoidCallbackRecordAttrSetter(ExecState& state, JSTestObj& thisObject, JSValue value, ThrowScope& throwScope)
+{
+    UNUSED_PARAM(state);
+    UNUSED_PARAM(throwScope);
+    auto& impl = thisObject.wrapped();
+    auto nativeValue = convert<IDLRecord<IDLDOMString, IDLCallbackFunction<JSVoidCallback>>>(state, value, *thisObject.globalObject());
+    RETURN_IF_EXCEPTION(throwScope, false);
+    AttributeSetter::call(state, throwScope, [&] {
+        return impl.setStringVoidCallbackRecordAttr(WTFMove(nativeValue));
+    });
+    return true;
+}
+
+bool setJSTestObjStringVoidCallbackRecordAttr(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
+{
+    return IDLAttribute<JSTestObj>::set<setJSTestObjStringVoidCallbackRecordAttrSetter>(*state, thisValue, encodedValue, "stringVoidCallbackRecordAttr");
+}
+
 static inline JSValue jsTestObjDictionaryAttrGetter(ExecState& state, JSTestObj& thisObject, ThrowScope& throwScope)
 {
     UNUSED_PARAM(throwScope);

Modified: trunk/Source/WebCore/bindings/scripts/test/TestObj.idl (250484 => 250485)


--- trunk/Source/WebCore/bindings/scripts/test/TestObj.idl	2019-09-28 23:58:10 UTC (rev 250484)
+++ trunk/Source/WebCore/bindings/scripts/test/TestObj.idl	2019-09-29 00:26:13 UTC (rev 250485)
@@ -83,6 +83,7 @@
     attribute record<ByteString, long> usvstringLongRecordAttr;
     attribute record<DOMString, TestObj> stringObjRecordAttr;
     attribute record<DOMString, TestObj?> stringNullableObjRecordAttr;
+    attribute record<DOMString, VoidCallback> stringVoidCallbackRecordAttr;
     attribute TestDictionary dictionaryAttr;
     attribute TestDictionary? nullableDictionaryAttr;
     attribute (DOMString or [Clamp] long) annotatedTypeInUnionAttr;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to