WebGLRenderingContextBase.bufferData() should use a union instead of overloading
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 22 Oct 2016 20:46:34 +0000 (20:46 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 22 Oct 2016 20:46:34 +0000 (20:46 +0000)
https://bugs.webkit.org/show_bug.cgi?id=163795

Reviewed by Darin Adler.

Source/JavaScriptCore:

* runtime/ArrayBufferView.h:
(JSC::ArrayBufferView::data):
Add a data() method which aliases baseAddress() to align the API with
ArrayBuffer and reduce special handling at call sites.

* runtime/JSArrayBuffer.h:
(JSC::toArrayBuffer):
(JSC::JSArrayBuffer::toWrapped):
Add toWrapped() method similarly with WebCore wrapper types to
reduce special handling of JSArrayBuffer type.

* runtime/JSArrayBufferView.cpp:
(JSC::JSArrayBufferView::toWrapped):
* runtime/JSArrayBufferView.h:
Add toWrapped() method similarly with WebCore wrapper types to
reduce special handling of JSArrayBufferView type.

Source/WebCore:

WebGLRenderingContextBase.bufferData() / bufferSubData() should use a union
instead of overloading:
- https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14

No new tests, no web-exposed behavior change.

* bindings/js/JSDOMConvert.h:
(WebCore::Converter<IDLInterface<T>>::convert):
* bindings/scripts/CodeGeneratorJS.pm:
(GenerateHeader):
* bindings/scripts/test/JS/JSInterfaceName.h:
* bindings/scripts/test/JS/JSTestActiveDOMObject.h:
* bindings/scripts/test/JS/JSTestCEReactions.h:
* bindings/scripts/test/JS/JSTestCEReactionsStringifier.h:
* bindings/scripts/test/JS/JSTestClassWithJSBuiltinConstructor.h:
* bindings/scripts/test/JS/JSTestCustomConstructorWithNoInterfaceObject.h:
* bindings/scripts/test/JS/JSTestCustomNamedGetter.h:
* bindings/scripts/test/JS/JSTestEventConstructor.h:
* bindings/scripts/test/JS/JSTestEventTarget.h:
* bindings/scripts/test/JS/JSTestException.h:
* bindings/scripts/test/JS/JSTestGenerateIsReachable.h:
* bindings/scripts/test/JS/JSTestGlobalObject.h:
* bindings/scripts/test/JS/JSTestInterface.h:
* bindings/scripts/test/JS/JSTestIterable.h:
* bindings/scripts/test/JS/JSTestMediaQueryListListener.h:
* bindings/scripts/test/JS/JSTestNamedConstructor.h:
* bindings/scripts/test/JS/JSTestNode.h:
* bindings/scripts/test/JS/JSTestNondeterministic.h:
* bindings/scripts/test/JS/JSTestObj.h:
* bindings/scripts/test/JS/JSTestOverloadedConstructors.h:
* bindings/scripts/test/JS/JSTestOverloadedConstructorsWithSequence.h:
* bindings/scripts/test/JS/JSTestOverrideBuiltins.h:
* bindings/scripts/test/JS/JSTestSerialization.h:
* bindings/scripts/test/JS/JSTestSerializedScriptValueInterface.h:
* bindings/scripts/test/JS/JSTestTypedefs.h:
* bindings/scripts/test/JS/JSattribute.h:
* bindings/scripts/test/JS/JSreadonly.h:
* html/canvas/WebGL2RenderingContext.cpp:
(WebCore::WebGL2RenderingContext::bufferData):
(WebCore::WebGL2RenderingContext::bufferSubData):
* html/canvas/WebGLRenderingContextBase.cpp:
(WebCore::WebGLRenderingContextBase::bufferData):
(WebCore::WebGLRenderingContextBase::bufferSubData):
* html/canvas/WebGLRenderingContextBase.h:
* html/canvas/WebGLRenderingContextBase.idl:

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

39 files changed:
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/ArrayBufferView.h
Source/JavaScriptCore/runtime/JSArrayBuffer.h
Source/JavaScriptCore/runtime/JSArrayBufferView.cpp
Source/JavaScriptCore/runtime/JSArrayBufferView.h
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSDOMConvert.h
Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
Source/WebCore/bindings/scripts/test/JS/JSInterfaceName.h
Source/WebCore/bindings/scripts/test/JS/JSTestActiveDOMObject.h
Source/WebCore/bindings/scripts/test/JS/JSTestCEReactions.h
Source/WebCore/bindings/scripts/test/JS/JSTestCEReactionsStringifier.h
Source/WebCore/bindings/scripts/test/JS/JSTestClassWithJSBuiltinConstructor.h
Source/WebCore/bindings/scripts/test/JS/JSTestCustomConstructorWithNoInterfaceObject.h
Source/WebCore/bindings/scripts/test/JS/JSTestCustomNamedGetter.h
Source/WebCore/bindings/scripts/test/JS/JSTestEventConstructor.h
Source/WebCore/bindings/scripts/test/JS/JSTestEventTarget.h
Source/WebCore/bindings/scripts/test/JS/JSTestException.h
Source/WebCore/bindings/scripts/test/JS/JSTestGenerateIsReachable.h
Source/WebCore/bindings/scripts/test/JS/JSTestGlobalObject.h
Source/WebCore/bindings/scripts/test/JS/JSTestInterface.h
Source/WebCore/bindings/scripts/test/JS/JSTestIterable.h
Source/WebCore/bindings/scripts/test/JS/JSTestMediaQueryListListener.h
Source/WebCore/bindings/scripts/test/JS/JSTestNamedConstructor.h
Source/WebCore/bindings/scripts/test/JS/JSTestNode.h
Source/WebCore/bindings/scripts/test/JS/JSTestNondeterministic.h
Source/WebCore/bindings/scripts/test/JS/JSTestObj.h
Source/WebCore/bindings/scripts/test/JS/JSTestOverloadedConstructors.h
Source/WebCore/bindings/scripts/test/JS/JSTestOverloadedConstructorsWithSequence.h
Source/WebCore/bindings/scripts/test/JS/JSTestOverrideBuiltins.h
Source/WebCore/bindings/scripts/test/JS/JSTestSerialization.h
Source/WebCore/bindings/scripts/test/JS/JSTestSerializedScriptValueInterface.h
Source/WebCore/bindings/scripts/test/JS/JSTestTypedefs.h
Source/WebCore/bindings/scripts/test/JS/JSattribute.h
Source/WebCore/bindings/scripts/test/JS/JSreadonly.h
Source/WebCore/html/canvas/WebGL2RenderingContext.cpp
Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp
Source/WebCore/html/canvas/WebGLRenderingContextBase.h
Source/WebCore/html/canvas/WebGLRenderingContextBase.idl

index 429d0a3..81f3f80 100644 (file)
@@ -1,3 +1,27 @@
+2016-10-22  Chris Dumez  <cdumez@apple.com>
+
+        WebGLRenderingContextBase.bufferData() should use a union instead of overloading
+        https://bugs.webkit.org/show_bug.cgi?id=163795
+
+        Reviewed by Darin Adler.
+
+        * runtime/ArrayBufferView.h:
+        (JSC::ArrayBufferView::data):
+        Add a data() method which aliases baseAddress() to align the API with
+        ArrayBuffer and reduce special handling at call sites.
+
+        * runtime/JSArrayBuffer.h:
+        (JSC::toArrayBuffer):
+        (JSC::JSArrayBuffer::toWrapped):
+        Add toWrapped() method similarly with WebCore wrapper types to
+        reduce special handling of JSArrayBuffer type.
+
+        * runtime/JSArrayBufferView.cpp:
+        (JSC::JSArrayBufferView::toWrapped):
+        * runtime/JSArrayBufferView.h:
+        Add toWrapped() method similarly with WebCore wrapper types to
+        reduce special handling of JSArrayBufferView type.
+
 2016-10-21  Filip Pizlo  <fpizlo@apple.com>
 
         Slow and big Heap methods should not be inline
index e52a8df..befd94f 100644 (file)
@@ -62,6 +62,8 @@ public:
         return m_baseAddress;
     }
 
+    void* data() const { return baseAddress(); }
+
     unsigned byteOffset() const
     {
         if (isNeutered())
index 0881862..ab8ad38 100644 (file)
@@ -46,6 +46,8 @@ public:
     ArrayBuffer* impl() const { return m_impl; }
     
     static Structure* createStructure(VM&, JSGlobalObject*, JSValue prototype);
+
+    static ArrayBuffer* toWrapped(JSValue);
     
     DECLARE_EXPORT_INFO;
     
@@ -67,8 +69,13 @@ inline ArrayBuffer* toArrayBuffer(JSValue value)
 {
     JSArrayBuffer* wrapper = jsDynamicCast<JSArrayBuffer*>(value);
     if (!wrapper)
-        return 0;
+        return nullptr;
     return wrapper->impl();
 }
 
+inline ArrayBuffer* JSArrayBuffer::toWrapped(JSValue value)
+{
+    return toArrayBuffer(value);
+}
+
 } // namespace JSC
index b0120f4..912673a 100644 (file)
@@ -186,6 +186,14 @@ void JSArrayBufferView::finalize(JSCell* cell)
         fastFree(thisObject->m_vector.get());
 }
 
+RefPtr<ArrayBufferView> JSArrayBufferView::toWrapped(JSValue value)
+{
+    auto* wrapper = jsDynamicCast<JSArrayBufferView*>(value);
+    if (!wrapper)
+        return nullptr;
+    return wrapper->impl();
+}
+
 } // namespace JSC
 
 namespace WTF {
index 4c03c0c..b866636 100644 (file)
@@ -174,6 +174,8 @@ public:
     static ptrdiff_t offsetOfLength() { return OBJECT_OFFSETOF(JSArrayBufferView, m_length); }
     static ptrdiff_t offsetOfMode() { return OBJECT_OFFSETOF(JSArrayBufferView, m_mode); }
 
+    JS_EXPORT_PRIVATE static RefPtr<ArrayBufferView> toWrapped(JSValue);
+
 private:
     static void finalize(JSCell*);
 
index f11f1f2..4914d47 100644 (file)
@@ -1,3 +1,56 @@
+2016-10-22  Chris Dumez  <cdumez@apple.com>
+
+        WebGLRenderingContextBase.bufferData() should use a union instead of overloading
+        https://bugs.webkit.org/show_bug.cgi?id=163795
+
+        Reviewed by Darin Adler.
+
+        WebGLRenderingContextBase.bufferData() / bufferSubData() should use a union
+        instead of overloading:
+        - https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14
+
+        No new tests, no web-exposed behavior change.
+
+        * bindings/js/JSDOMConvert.h:
+        (WebCore::Converter<IDLInterface<T>>::convert):
+        * bindings/scripts/CodeGeneratorJS.pm:
+        (GenerateHeader):
+        * bindings/scripts/test/JS/JSInterfaceName.h:
+        * bindings/scripts/test/JS/JSTestActiveDOMObject.h:
+        * bindings/scripts/test/JS/JSTestCEReactions.h:
+        * bindings/scripts/test/JS/JSTestCEReactionsStringifier.h:
+        * bindings/scripts/test/JS/JSTestClassWithJSBuiltinConstructor.h:
+        * bindings/scripts/test/JS/JSTestCustomConstructorWithNoInterfaceObject.h:
+        * bindings/scripts/test/JS/JSTestCustomNamedGetter.h:
+        * bindings/scripts/test/JS/JSTestEventConstructor.h:
+        * bindings/scripts/test/JS/JSTestEventTarget.h:
+        * bindings/scripts/test/JS/JSTestException.h:
+        * bindings/scripts/test/JS/JSTestGenerateIsReachable.h:
+        * bindings/scripts/test/JS/JSTestGlobalObject.h:
+        * bindings/scripts/test/JS/JSTestInterface.h:
+        * bindings/scripts/test/JS/JSTestIterable.h:
+        * bindings/scripts/test/JS/JSTestMediaQueryListListener.h:
+        * bindings/scripts/test/JS/JSTestNamedConstructor.h:
+        * bindings/scripts/test/JS/JSTestNode.h:
+        * bindings/scripts/test/JS/JSTestNondeterministic.h:
+        * bindings/scripts/test/JS/JSTestObj.h:
+        * bindings/scripts/test/JS/JSTestOverloadedConstructors.h:
+        * bindings/scripts/test/JS/JSTestOverloadedConstructorsWithSequence.h:
+        * bindings/scripts/test/JS/JSTestOverrideBuiltins.h:
+        * bindings/scripts/test/JS/JSTestSerialization.h:
+        * bindings/scripts/test/JS/JSTestSerializedScriptValueInterface.h:
+        * bindings/scripts/test/JS/JSTestTypedefs.h:
+        * bindings/scripts/test/JS/JSattribute.h:
+        * bindings/scripts/test/JS/JSreadonly.h:
+        * html/canvas/WebGL2RenderingContext.cpp:
+        (WebCore::WebGL2RenderingContext::bufferData):
+        (WebCore::WebGL2RenderingContext::bufferSubData):
+        * html/canvas/WebGLRenderingContextBase.cpp:
+        (WebCore::WebGLRenderingContextBase::bufferData):
+        (WebCore::WebGLRenderingContextBase::bufferSubData):
+        * html/canvas/WebGLRenderingContextBase.h:
+        * html/canvas/WebGLRenderingContextBase.idl:
+
 2016-10-22  Darin Adler  <darin@apple.com>
 
         [Cocoa] REGRESSION (r204508): Crash in init_WebCreateFragment when pasting (seen in multiple apps using legacy WebKit)
index 6ecd31f..7dc050b 100644 (file)
@@ -104,25 +104,36 @@ template<> struct Converter<IDLBoolean> : DefaultConverter<IDLBoolean> {
     }
 };
 
+// ArrayBuffer support.
+template<> struct JSDOMWrapperConverterTraits<JSC::ArrayBuffer> {
+    using WrapperClass = JSC::JSArrayBuffer;
+    using ToWrappedReturnType = JSC::ArrayBuffer*;
+};
+
+// ArrayBufferView support.
+template<> struct JSDOMWrapperConverterTraits<JSC::ArrayBufferView> {
+    using WrapperClass = JSC::JSArrayBufferView;
+    using ToWrappedReturnType = RefPtr<ArrayBufferView>;
+};
+
 // MARK: -
 // MARK: Interface type
 
 template<typename T> struct Converter<IDLInterface<T>> : DefaultConverter<IDLInterface<T>> {
-    using ReturnType = T*;
+    using ReturnType = typename JSDOMWrapperConverterTraits<T>::ToWrappedReturnType;
     using WrapperType = typename JSDOMWrapperConverterTraits<T>::WrapperClass;
 
-    static T* convert(JSC::ExecState& state, JSC::JSValue value)
+    static ReturnType convert(JSC::ExecState& state, JSC::JSValue value)
     {
         JSC::VM& vm = state.vm();
         auto scope = DECLARE_THROW_SCOPE(vm);
-        T* object = WrapperType::toWrapped(value);
+        ReturnType object = WrapperType::toWrapped(value);
         if (!object)
             throwTypeError(&state, scope);
         return object;
     }
 };
 
-
 // Typed arrays support.
 
 template<typename Adaptor> struct IDLInterface<JSC::GenericTypedArrayView<Adaptor>> : IDLType<Ref<JSC::GenericTypedArrayView<Adaptor>>> {
@@ -540,7 +551,7 @@ struct Converter<IDLUnion<T...>> : DefaultConverter<IDLUnion<T...>>
                 using ImplementationType = typename WTF::RemoveCVAndReference<decltype(type)>::type::type::RawType;
                 using WrapperType = typename JSDOMWrapperConverterTraits<ImplementationType>::WrapperClass;
 
-                auto* castedValue = WrapperType::toWrapped(value);
+                auto castedValue = WrapperType::toWrapped(value);
                 if (!castedValue)
                     return;
                 
index c071e27..fbfacca 100644 (file)
@@ -1732,6 +1732,7 @@ sub GenerateHeader
     if (NeedsImplementationClass($interface)) {
         push(@headerContent, "template<> struct JSDOMWrapperConverterTraits<${implType}> {\n");
         push(@headerContent, "    using WrapperClass = ${className};\n");
+        push(@headerContent, "    using ToWrappedReturnType = ${implType}*;\n");
         push(@headerContent, "};\n");
     }
 
index b672951..32efa7b 100644 (file)
@@ -87,6 +87,7 @@ inline JSC::JSValue toJSNewlyCreated(JSC::ExecState* state, JSDOMGlobalObject* g
 
 template<> struct JSDOMWrapperConverterTraits<InterfaceName> {
     using WrapperClass = JSInterfaceName;
+    using ToWrappedReturnType = InterfaceName*;
 };
 
 } // namespace WebCore
index 40d5a27..565d3eb 100644 (file)
@@ -86,6 +86,7 @@ inline JSC::JSValue toJSNewlyCreated(JSC::ExecState* state, JSDOMGlobalObject* g
 
 template<> struct JSDOMWrapperConverterTraits<TestActiveDOMObject> {
     using WrapperClass = JSTestActiveDOMObject;
+    using ToWrappedReturnType = TestActiveDOMObject*;
 };
 
 } // namespace WebCore
index 725a0ff..1099b2d 100644 (file)
@@ -84,6 +84,7 @@ inline JSC::JSValue toJSNewlyCreated(JSC::ExecState* state, JSDOMGlobalObject* g
 
 template<> struct JSDOMWrapperConverterTraits<TestCEReactions> {
     using WrapperClass = JSTestCEReactions;
+    using ToWrappedReturnType = TestCEReactions*;
 };
 
 } // namespace WebCore
index 53bd02a..944bc1a 100644 (file)
@@ -84,6 +84,7 @@ inline JSC::JSValue toJSNewlyCreated(JSC::ExecState* state, JSDOMGlobalObject* g
 
 template<> struct JSDOMWrapperConverterTraits<TestCEReactionsStringifier> {
     using WrapperClass = JSTestCEReactionsStringifier;
+    using ToWrappedReturnType = TestCEReactionsStringifier*;
 };
 
 } // namespace WebCore
index 9c825ab..1aae23b 100644 (file)
@@ -86,6 +86,7 @@ inline JSC::JSValue toJSNewlyCreated(JSC::ExecState* state, JSDOMGlobalObject* g
 
 template<> struct JSDOMWrapperConverterTraits<TestClassWithJSBuiltinConstructor> {
     using WrapperClass = JSTestClassWithJSBuiltinConstructor;
+    using ToWrappedReturnType = TestClassWithJSBuiltinConstructor*;
 };
 
 } // namespace WebCore
index 17b9ca8..076330b 100644 (file)
@@ -86,6 +86,7 @@ JSC::EncodedJSValue JSC_HOST_CALL constructJSTestCustomConstructorWithNoInterfac
 
 template<> struct JSDOMWrapperConverterTraits<TestCustomConstructorWithNoInterfaceObject> {
     using WrapperClass = JSTestCustomConstructorWithNoInterfaceObject;
+    using ToWrappedReturnType = TestCustomConstructorWithNoInterfaceObject*;
 };
 
 } // namespace WebCore
index 9a2d64d..a5fd45f 100644 (file)
@@ -90,6 +90,7 @@ inline JSC::JSValue toJSNewlyCreated(JSC::ExecState* state, JSDOMGlobalObject* g
 
 template<> struct JSDOMWrapperConverterTraits<TestCustomNamedGetter> {
     using WrapperClass = JSTestCustomNamedGetter;
+    using ToWrappedReturnType = TestCustomNamedGetter*;
 };
 
 } // namespace WebCore
index 6e5daec..48a5c44 100644 (file)
@@ -70,6 +70,7 @@ inline JSC::JSValue toJSNewlyCreated(JSC::ExecState* state, JSDOMGlobalObject* g
 
 template<> struct JSDOMWrapperConverterTraits<TestEventConstructor> {
     using WrapperClass = JSTestEventConstructor;
+    using ToWrappedReturnType = TestEventConstructor*;
 };
 template<> TestEventConstructor::Init convertDictionary<TestEventConstructor::Init>(JSC::ExecState&, JSC::JSValue);
 
index 2231b4b..f9d0571 100644 (file)
@@ -80,6 +80,7 @@ inline JSC::JSValue toJSNewlyCreated(JSC::ExecState* state, JSDOMGlobalObject* g
 
 template<> struct JSDOMWrapperConverterTraits<TestEventTarget> {
     using WrapperClass = JSTestEventTarget;
+    using ToWrappedReturnType = TestEventTarget*;
 };
 
 } // namespace WebCore
index 372e5d4..045cbf6 100644 (file)
@@ -87,6 +87,7 @@ inline JSC::JSValue toJSNewlyCreated(JSC::ExecState* state, JSDOMGlobalObject* g
 
 template<> struct JSDOMWrapperConverterTraits<TestException> {
     using WrapperClass = JSTestException;
+    using ToWrappedReturnType = TestException*;
 };
 
 } // namespace WebCore
index 6c42c60..53a8541 100644 (file)
@@ -84,6 +84,7 @@ inline JSC::JSValue toJSNewlyCreated(JSC::ExecState* state, JSDOMGlobalObject* g
 
 template<> struct JSDOMWrapperConverterTraits<TestGenerateIsReachable> {
     using WrapperClass = JSTestGenerateIsReachable;
+    using ToWrappedReturnType = TestGenerateIsReachable*;
 };
 
 } // namespace WebCore
index 27842e1..57b0dbb 100644 (file)
@@ -114,6 +114,7 @@ public:
 
 template<> struct JSDOMWrapperConverterTraits<TestGlobalObject> {
     using WrapperClass = JSTestGlobalObject;
+    using ToWrappedReturnType = TestGlobalObject*;
 };
 
 } // namespace WebCore
index bd63a94..ad66242 100644 (file)
@@ -111,6 +111,7 @@ inline JSC::JSValue toJSNewlyCreated(JSC::ExecState* state, JSDOMGlobalObject* g
 
 template<> struct JSDOMWrapperConverterTraits<TestInterface> {
     using WrapperClass = JSTestInterface;
+    using ToWrappedReturnType = TestInterface*;
 };
 
 } // namespace WebCore
index 87022d5..4ac7105 100644 (file)
@@ -84,6 +84,7 @@ inline JSC::JSValue toJSNewlyCreated(JSC::ExecState* state, JSDOMGlobalObject* g
 
 template<> struct JSDOMWrapperConverterTraits<TestIterable> {
     using WrapperClass = JSTestIterable;
+    using ToWrappedReturnType = TestIterable*;
 };
 
 } // namespace WebCore
index 3f5f426..ebcc913 100644 (file)
@@ -84,6 +84,7 @@ inline JSC::JSValue toJSNewlyCreated(JSC::ExecState* state, JSDOMGlobalObject* g
 
 template<> struct JSDOMWrapperConverterTraits<TestMediaQueryListListener> {
     using WrapperClass = JSTestMediaQueryListListener;
+    using ToWrappedReturnType = TestMediaQueryListListener*;
 };
 
 } // namespace WebCore
index 802415d..3aaa145 100644 (file)
@@ -85,6 +85,7 @@ inline JSC::JSValue toJSNewlyCreated(JSC::ExecState* state, JSDOMGlobalObject* g
 
 template<> struct JSDOMWrapperConverterTraits<TestNamedConstructor> {
     using WrapperClass = JSTestNamedConstructor;
+    using ToWrappedReturnType = TestNamedConstructor*;
 };
 
 } // namespace WebCore
index 3863dbf..803d957 100644 (file)
@@ -71,6 +71,7 @@ inline JSC::JSValue toJSNewlyCreated(JSC::ExecState* state, JSDOMGlobalObject* g
 
 template<> struct JSDOMWrapperConverterTraits<TestNode> {
     using WrapperClass = JSTestNode;
+    using ToWrappedReturnType = TestNode*;
 };
 
 } // namespace WebCore
index f96cb76..a3421a5 100644 (file)
@@ -84,6 +84,7 @@ inline JSC::JSValue toJSNewlyCreated(JSC::ExecState* state, JSDOMGlobalObject* g
 
 template<> struct JSDOMWrapperConverterTraits<TestNondeterministic> {
     using WrapperClass = JSTestNondeterministic;
+    using ToWrappedReturnType = TestNondeterministic*;
 };
 
 } // namespace WebCore
index bfba481..2bc847c 100644 (file)
@@ -104,6 +104,7 @@ inline JSC::JSValue toJSNewlyCreated(JSC::ExecState* state, JSDOMGlobalObject* g
 
 template<> struct JSDOMWrapperConverterTraits<TestObj> {
     using WrapperClass = JSTestObj;
+    using ToWrappedReturnType = TestObj*;
 };
 JSC::JSString* jsStringWithCache(JSC::ExecState*, TestObj::EnumType);
 
index 065de5f..c6ba32d 100644 (file)
@@ -84,6 +84,7 @@ inline JSC::JSValue toJSNewlyCreated(JSC::ExecState* state, JSDOMGlobalObject* g
 
 template<> struct JSDOMWrapperConverterTraits<TestOverloadedConstructors> {
     using WrapperClass = JSTestOverloadedConstructors;
+    using ToWrappedReturnType = TestOverloadedConstructors*;
 };
 
 } // namespace WebCore
index a4ce64b..9b897e5 100644 (file)
@@ -84,6 +84,7 @@ inline JSC::JSValue toJSNewlyCreated(JSC::ExecState* state, JSDOMGlobalObject* g
 
 template<> struct JSDOMWrapperConverterTraits<TestOverloadedConstructorsWithSequence> {
     using WrapperClass = JSTestOverloadedConstructorsWithSequence;
+    using ToWrappedReturnType = TestOverloadedConstructorsWithSequence*;
 };
 
 } // namespace WebCore
index fbc23b5..ed5fae1 100644 (file)
@@ -91,6 +91,7 @@ inline JSC::JSValue toJSNewlyCreated(JSC::ExecState* state, JSDOMGlobalObject* g
 
 template<> struct JSDOMWrapperConverterTraits<TestOverrideBuiltins> {
     using WrapperClass = JSTestOverrideBuiltins;
+    using ToWrappedReturnType = TestOverrideBuiltins*;
 };
 
 } // namespace WebCore
index 19fda47..667f69d 100644 (file)
@@ -84,6 +84,7 @@ inline JSC::JSValue toJSNewlyCreated(JSC::ExecState* state, JSDOMGlobalObject* g
 
 template<> struct JSDOMWrapperConverterTraits<TestSerialization> {
     using WrapperClass = JSTestSerialization;
+    using ToWrappedReturnType = TestSerialization*;
 };
 
 } // namespace WebCore
index 49e5b46..f17f17d 100644 (file)
@@ -90,6 +90,7 @@ inline JSC::JSValue toJSNewlyCreated(JSC::ExecState* state, JSDOMGlobalObject* g
 
 template<> struct JSDOMWrapperConverterTraits<TestSerializedScriptValueInterface> {
     using WrapperClass = JSTestSerializedScriptValueInterface;
+    using ToWrappedReturnType = TestSerializedScriptValueInterface*;
 };
 
 } // namespace WebCore
index b1d36bf..6e9b609 100644 (file)
@@ -86,6 +86,7 @@ inline JSC::JSValue toJSNewlyCreated(JSC::ExecState* state, JSDOMGlobalObject* g
 
 template<> struct JSDOMWrapperConverterTraits<TestTypedefs> {
     using WrapperClass = JSTestTypedefs;
+    using ToWrappedReturnType = TestTypedefs*;
 };
 
 } // namespace WebCore
index c9c8cd8..4a8cb4d 100644 (file)
@@ -87,6 +87,7 @@ inline JSC::JSValue toJSNewlyCreated(JSC::ExecState* state, JSDOMGlobalObject* g
 
 template<> struct JSDOMWrapperConverterTraits<attribute> {
     using WrapperClass = JSattribute;
+    using ToWrappedReturnType = attribute*;
 };
 
 } // namespace WebCore
index 80f3095..c242d2f 100644 (file)
@@ -84,6 +84,7 @@ inline JSC::JSValue toJSNewlyCreated(JSC::ExecState* state, JSDOMGlobalObject* g
 
 template<> struct JSDOMWrapperConverterTraits<readonly> {
     using WrapperClass = JSreadonly;
+    using ToWrappedReturnType = readonly*;
 };
 
 } // namespace WebCore
index 5652e51..727ef33 100644 (file)
@@ -99,7 +99,7 @@ void WebGL2RenderingContext::bufferData(GC3Denum target, ArrayBufferView& data,
         synthesizeGLError(GraphicsContext3D::OUT_OF_MEMORY, "bufferData", "Could not create intermediate ArrayBufferView");
         return;
     }
-    WebGLRenderingContextBase::bufferData(target, slice.get(), usage);
+    WebGLRenderingContextBase::bufferData(target, BufferDataSource(slice.get()), usage);
 }
 
 void WebGL2RenderingContext::bufferSubData(GC3Denum target, long long offset, ArrayBufferView& data, GC3Duint srcOffset, GC3Duint length)
@@ -113,7 +113,7 @@ void WebGL2RenderingContext::bufferSubData(GC3Denum target, long long offset, Ar
         synthesizeGLError(GraphicsContext3D::OUT_OF_MEMORY, "bufferData", "Could not create intermediate ArrayBufferView");
         return;
     }
-    WebGLRenderingContextBase::bufferSubData(target, offset, slice);
+    WebGLRenderingContextBase::bufferSubData(target, offset, BufferDataSource(slice.get()));
 }
 
 void WebGL2RenderingContext::copyBufferSubData(GC3Denum, GC3Denum, GC3Dint64, GC3Dint64, GC3Dint64)
index 96c2590..9283bec 100644 (file)
@@ -1075,7 +1075,7 @@ void WebGLRenderingContextBase::bufferData(GC3Denum target, long long size, GC3D
     }
 }
 
-void WebGLRenderingContextBase::bufferData(GC3Denum target, ArrayBuffer* data, GC3Denum usage)
+void WebGLRenderingContextBase::bufferData(GC3Denum target, Optional<BufferDataSource>&& data, GC3Denum usage)
 {
     if (isContextLostOrPending())
         return;
@@ -1086,76 +1086,25 @@ void WebGLRenderingContextBase::bufferData(GC3Denum target, ArrayBuffer* data, G
     WebGLBuffer* buffer = validateBufferDataParameters("bufferData", target, usage);
     if (!buffer)
         return;
-    if (!isErrorGeneratedOnOutOfBoundsAccesses()) {
-        if (!buffer->associateBufferData(data)) {
-            synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "bufferData", "invalid buffer");
-            return;
-        }
-    }
-
-    m_context->moveErrorsToSyntheticErrorList();
-    m_context->bufferData(target, data->byteLength(), data->data(), usage);
-    if (m_context->moveErrorsToSyntheticErrorList()) {
-        // The bufferData function failed. Tell the buffer it doesn't have the data it thinks it does.
-        buffer->disassociateBufferData();
-    }
-}
 
-void WebGLRenderingContextBase::bufferData(GC3Denum target, RefPtr<ArrayBufferView>&& data, GC3Denum usage)
-{
-    if (isContextLostOrPending())
-        return;
-    if (!data) {
-        synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "bufferData", "null data");
-        return;
-    }
-    WebGLBuffer* buffer = validateBufferDataParameters("bufferData", target, usage);
-    if (!buffer)
-        return;
-    if (!isErrorGeneratedOnOutOfBoundsAccesses()) {
-        if (!buffer->associateBufferData(data.get())) {
-            synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "bufferData", "invalid buffer");
-            return;
+    WTF::visit([&](auto& data) {
+        if (!this->isErrorGeneratedOnOutOfBoundsAccesses()) {
+            if (!buffer->associateBufferData(data.get())) {
+                this->synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "bufferData", "invalid buffer");
+                return;
+            }
         }
-    }
-
-    m_context->moveErrorsToSyntheticErrorList();
-    m_context->bufferData(target, data->byteLength(), data->baseAddress(), usage);
-    if (m_context->moveErrorsToSyntheticErrorList()) {
-        // The bufferData function failed. Tell the buffer it doesn't have the data it thinks it does.
-        buffer->disassociateBufferData();
-    }
-}
 
-void WebGLRenderingContextBase::bufferSubData(GC3Denum target, long long offset, ArrayBuffer* data)
-{
-    if (isContextLostOrPending())
-        return;
-    WebGLBuffer* buffer = validateBufferDataParameters("bufferSubData", target, GraphicsContext3D::STATIC_DRAW);
-    if (!buffer)
-        return;
-    if (offset < 0) {
-        synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "bufferSubData", "offset < 0");
-        return;
-    }
-    if (!data)
-        return;
-    if (!isErrorGeneratedOnOutOfBoundsAccesses()) {
-        if (!buffer->associateBufferSubData(static_cast<GC3Dintptr>(offset), data)) {
-            synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "bufferSubData", "offset out of range");
-            return;
+        m_context->moveErrorsToSyntheticErrorList();
+        m_context->bufferData(target, data->byteLength(), data->data(), usage);
+        if (m_context->moveErrorsToSyntheticErrorList()) {
+            // The bufferData function failed. Tell the buffer it doesn't have the data it thinks it does.
+            buffer->disassociateBufferData();
         }
-    }
-
-    m_context->moveErrorsToSyntheticErrorList();
-    m_context->bufferSubData(target, static_cast<GC3Dintptr>(offset), data->byteLength(), data->data());
-    if (m_context->moveErrorsToSyntheticErrorList()) {
-        // The bufferSubData function failed. Tell the buffer it doesn't have the data it thinks it does.
-        buffer->disassociateBufferData();
-    }
+    }, data.value());
 }
 
-void WebGLRenderingContextBase::bufferSubData(GC3Denum target, long long offset, RefPtr<ArrayBufferView>&& data)
+void WebGLRenderingContextBase::bufferSubData(GC3Denum target, long long offset, Optional<BufferDataSource>&& data)
 {
     if (isContextLostOrPending())
         return;
@@ -1168,19 +1117,22 @@ void WebGLRenderingContextBase::bufferSubData(GC3Denum target, long long offset,
     }
     if (!data)
         return;
-    if (!isErrorGeneratedOnOutOfBoundsAccesses()) {
-        if (!buffer->associateBufferSubData(static_cast<GC3Dintptr>(offset), data.get())) {
-            synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "bufferSubData", "offset out of range");
-            return;
+
+    WTF::visit([&](auto& data) {
+        if (!this->isErrorGeneratedOnOutOfBoundsAccesses()) {
+            if (!buffer->associateBufferSubData(static_cast<GC3Dintptr>(offset), data.get())) {
+                this->synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "bufferSubData", "offset out of range");
+                return;
+            }
         }
-    }
 
-    m_context->moveErrorsToSyntheticErrorList();
-    m_context->bufferSubData(target, static_cast<GC3Dintptr>(offset), data->byteLength(), data->baseAddress());
-    if (m_context->moveErrorsToSyntheticErrorList()) {
-        // The bufferSubData function failed. Tell the buffer it doesn't have the data it thinks it does.
-        buffer->disassociateBufferData();
-    }
+        m_context->moveErrorsToSyntheticErrorList();
+        m_context->bufferSubData(target, static_cast<GC3Dintptr>(offset), data->byteLength(), data->data());
+        if (m_context->moveErrorsToSyntheticErrorList()) {
+            // The bufferSubData function failed. Tell the buffer it doesn't have the data it thinks it does.
+            buffer->disassociateBufferData();
+        }
+    }, data.value());
 }
 
 GC3Denum WebGLRenderingContextBase::checkFramebufferStatus(GC3Denum target)
index 56f8b19..2247482 100644 (file)
@@ -37,6 +37,7 @@
 #include <memory>
 #include <runtime/Float32Array.h>
 #include <runtime/Int32Array.h>
+#include <wtf/Variant.h>
 #include <wtf/text/WTFString.h>
 
 namespace WebCore {
@@ -138,11 +139,10 @@ public:
     void blendFunc(GC3Denum sfactor, GC3Denum dfactor);
     void blendFuncSeparate(GC3Denum srcRGB, GC3Denum dstRGB, GC3Denum srcAlpha, GC3Denum dstAlpha);
 
+    using BufferDataSource = WTF::Variant<RefPtr<ArrayBuffer>, RefPtr<ArrayBufferView>>;
     void bufferData(GC3Denum target, long long size, GC3Denum usage);
-    void bufferData(GC3Denum target, ArrayBuffer* data, GC3Denum usage);
-    void bufferData(GC3Denum target, RefPtr<ArrayBufferView>&& data, GC3Denum usage);
-    void bufferSubData(GC3Denum target, long long offset, ArrayBuffer* data);
-    void bufferSubData(GC3Denum target, long long offset, RefPtr<ArrayBufferView>&& data);
+    void bufferData(GC3Denum target, Optional<BufferDataSource>&&, GC3Denum usage);
+    void bufferSubData(GC3Denum target, long long offset, Optional<BufferDataSource>&&);
 
     GC3Denum checkFramebufferStatus(GC3Denum target);
     virtual void clear(GC3Dbitfield mask) = 0;
index b5214ae..7ea280d 100644 (file)
@@ -37,6 +37,7 @@ typedef unsigned short GLushort;
 typedef unsigned long  GLuint;
 typedef unrestricted float GLfloat;
 typedef unrestricted float GLclampf;
+typedef (ArrayBuffer or ArrayBufferView) BufferDataSource;
 
 [
     Conditional=WEBGL,
@@ -484,11 +485,9 @@ typedef unrestricted float GLclampf;
     void blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha);
     void blendFunc(GLenum sfactor, GLenum dfactor);
     void blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha);
-    void bufferData(GLenum target, ArrayBuffer? data, GLenum usage);
-    void bufferData(GLenum target, ArrayBufferView? data, GLenum usage);
+    void bufferData(GLenum target, BufferDataSource? data, GLenum usage);
     void bufferData(GLenum target, GLsizeiptr size, GLenum usage);
-    void bufferSubData(GLenum target, GLintptr offset, ArrayBuffer? data);
-    void bufferSubData(GLenum target, GLintptr offset, ArrayBufferView? data);
+    void bufferSubData(GLenum target, GLintptr offset, BufferDataSource? data);
 
     GLenum checkFramebufferStatus(GLenum target);
     void clear(GLbitfield mask);