Title: [219902] trunk/Source/WebCore
Revision
219902
Author
[email protected]
Date
2017-07-25 21:31:40 -0700 (Tue, 25 Jul 2017)

Log Message

[WebIDL] Remove custom bindings for HTMLCanvasElement
https://bugs.webkit.org/show_bug.cgi?id=174847

Reviewed by Darin Adler.

* CMakeLists.txt:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSBindingsAllInOne.cpp:
* bindings/js/JSHTMLCanvasElementCustom.cpp: Removed.
Remove JSHTMLCanvasElementCustom.

* html/HTMLCanvasElement.cpp:
(WebCore::HTMLCanvasElement::getContext):
(WebCore::HTMLCanvasElement::getContext2d):
(WebCore::HTMLCanvasElement::getContextWebGL):
(WebCore::HTMLCanvasElement::getContextWebGPU):
* html/HTMLCanvasElement.h:
* html/HTMLCanvasElement.idl:
Move context picking code to HTMLCanvasElement. Give more
exact types to remaining context getters.

Modified Paths

Removed Paths

Diff

Modified: trunk/Source/WebCore/CMakeLists.txt (219901 => 219902)


--- trunk/Source/WebCore/CMakeLists.txt	2017-07-26 02:34:56 UTC (rev 219901)
+++ trunk/Source/WebCore/CMakeLists.txt	2017-07-26 04:31:40 UTC (rev 219902)
@@ -1185,7 +1185,6 @@
     bindings/js/JSEventCustom.cpp
     bindings/js/JSEventListener.cpp
     bindings/js/JSEventTargetCustom.cpp
-    bindings/js/JSHTMLCanvasElementCustom.cpp
     bindings/js/JSHTMLCollectionCustom.cpp
     bindings/js/JSHTMLDocumentCustom.cpp
     bindings/js/JSHTMLElementCustom.cpp

Modified: trunk/Source/WebCore/ChangeLog (219901 => 219902)


--- trunk/Source/WebCore/ChangeLog	2017-07-26 02:34:56 UTC (rev 219901)
+++ trunk/Source/WebCore/ChangeLog	2017-07-26 04:31:40 UTC (rev 219902)
@@ -1,3 +1,26 @@
+2017-07-25  Sam Weinig  <[email protected]>
+
+        [WebIDL] Remove custom bindings for HTMLCanvasElement
+        https://bugs.webkit.org/show_bug.cgi?id=174847
+
+        Reviewed by Darin Adler.
+
+        * CMakeLists.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * bindings/js/JSBindingsAllInOne.cpp:
+        * bindings/js/JSHTMLCanvasElementCustom.cpp: Removed.
+        Remove JSHTMLCanvasElementCustom.
+
+        * html/HTMLCanvasElement.cpp:
+        (WebCore::HTMLCanvasElement::getContext):
+        (WebCore::HTMLCanvasElement::getContext2d):
+        (WebCore::HTMLCanvasElement::getContextWebGL):
+        (WebCore::HTMLCanvasElement::getContextWebGPU):
+        * html/HTMLCanvasElement.h:
+        * html/HTMLCanvasElement.idl:
+        Move context picking code to HTMLCanvasElement. Give more
+        exact types to remaining context getters.
+
 2017-07-25  Chris Dumez  <[email protected]>
 
         Clean up ExceptionCode enumeration

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (219901 => 219902)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2017-07-26 02:34:56 UTC (rev 219901)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2017-07-26 04:31:40 UTC (rev 219902)
@@ -3764,7 +3764,6 @@
 		9391A99C1629D70000297330 /* ScrollingTreeScrollingNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9391A99A1629D6FF00297330 /* ScrollingTreeScrollingNode.cpp */; };
 		9391A99D1629D70000297330 /* ScrollingTreeScrollingNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 9391A99B1629D70000297330 /* ScrollingTreeScrollingNode.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		9392146918A6D791000EE688 /* TextIteratorBehavior.h in Headers */ = {isa = PBXBuildFile; fileRef = 9392146818A6D791000EE688 /* TextIteratorBehavior.h */; settings = {ATTRIBUTES = (Private, ); }; };
-		9392262D1032107B006E7D5D /* JSHTMLCanvasElementCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9392262C1032107B006E7D5D /* JSHTMLCanvasElementCustom.cpp */; };
 		9392262F10321084006E7D5D /* JSCSSRuleListCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9392262E10321084006E7D5D /* JSCSSRuleListCustom.cpp */; };
 		9392F1420AD185F400691BD4 /* RenderCounter.h in Headers */ = {isa = PBXBuildFile; fileRef = 9392F1410AD185F400691BD4 /* RenderCounter.h */; };
 		9392F1440AD185FE00691BD4 /* RenderCounter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9392F1430AD185FE00691BD4 /* RenderCounter.cpp */; };
@@ -11904,7 +11903,6 @@
 		9391A99A1629D6FF00297330 /* ScrollingTreeScrollingNode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScrollingTreeScrollingNode.cpp; sourceTree = "<group>"; };
 		9391A99B1629D70000297330 /* ScrollingTreeScrollingNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollingTreeScrollingNode.h; sourceTree = "<group>"; };
 		9392146818A6D791000EE688 /* TextIteratorBehavior.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextIteratorBehavior.h; sourceTree = "<group>"; };
-		9392262C1032107B006E7D5D /* JSHTMLCanvasElementCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSHTMLCanvasElementCustom.cpp; sourceTree = "<group>"; };
 		9392262E10321084006E7D5D /* JSCSSRuleListCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSCSSRuleListCustom.cpp; sourceTree = "<group>"; };
 		9392F1410AD185F400691BD4 /* RenderCounter.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = RenderCounter.h; sourceTree = "<group>"; };
 		9392F1430AD185FE00691BD4 /* RenderCounter.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = RenderCounter.cpp; sourceTree = "<group>"; };
@@ -23510,7 +23508,6 @@
 				BCD9C25E0C17AA67005C90A2 /* JSDOMWindowCustom.cpp */,
 				652FBBBB0DE27CB60001D386 /* JSDOMWindowCustom.h */,
 				BCE7B1920D4E86960075A539 /* JSHistoryCustom.cpp */,
-				9392262C1032107B006E7D5D /* JSHTMLCanvasElementCustom.cpp */,
 				BC5823F40C0A98DF0053F1B5 /* JSHTMLElementCustom.cpp */,
 				D6F7960C166FFECE0076DD18 /* JSHTMLTemplateElementCustom.cpp */,
 				BCE1C43F0D9830F4003B02F2 /* JSLocationCustom.cpp */,
@@ -31834,7 +31831,6 @@
 				1AE2AA240A1CDAB400B42B25 /* JSHTMLBRElement.cpp in Sources */,
 				A80E7EA00A1A83E3007FB8C5 /* JSHTMLButtonElement.cpp in Sources */,
 				938E666009F09B81008A48EC /* JSHTMLCanvasElement.cpp in Sources */,
-				9392262D1032107B006E7D5D /* JSHTMLCanvasElementCustom.cpp in Sources */,
 				BCCBAD400C18C14200CE890F /* JSHTMLCollection.cpp in Sources */,
 				BCCBAD3B0C18BFF800CE890F /* JSHTMLCollectionCustom.cpp in Sources */,
 				8367587E1C56E99B008A1087 /* JSHTMLDataElement.cpp in Sources */,

Modified: trunk/Source/WebCore/bindings/js/JSBindingsAllInOne.cpp (219901 => 219902)


--- trunk/Source/WebCore/bindings/js/JSBindingsAllInOne.cpp	2017-07-26 02:34:56 UTC (rev 219901)
+++ trunk/Source/WebCore/bindings/js/JSBindingsAllInOne.cpp	2017-07-26 04:31:40 UTC (rev 219902)
@@ -62,7 +62,6 @@
 #include "JSEventCustom.cpp"
 #include "JSEventListener.cpp"
 #include "JSEventTargetCustom.cpp"
-#include "JSHTMLCanvasElementCustom.cpp"
 #include "JSHTMLCollectionCustom.cpp"
 #include "JSHTMLDocumentCustom.cpp"
 #include "JSHTMLElementCustom.cpp"

Deleted: trunk/Source/WebCore/bindings/js/JSHTMLCanvasElementCustom.cpp (219901 => 219902)


--- trunk/Source/WebCore/bindings/js/JSHTMLCanvasElementCustom.cpp	2017-07-26 02:34:56 UTC (rev 219901)
+++ trunk/Source/WebCore/bindings/js/JSHTMLCanvasElementCustom.cpp	2017-07-26 04:31:40 UTC (rev 219902)
@@ -1,90 +0,0 @@
-/*
- * Copyright (C) 2007, 2016, 2017 Apple Inc. All rights reserved.
- * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "JSHTMLCanvasElement.h"
-
-#include "HTMLCanvasElement.h"
-#include "JSCanvasRenderingContext2D.h"
-#include "JSDOMConvertDictionary.h"
-#include "JSDOMConvertNullable.h"
-#include "JSDOMConvertStrings.h"
-
-#if ENABLE(WEBGL)
-#include "JSWebGLContextAttributes.h"
-#include "JSWebGLRenderingContext.h"
-#if ENABLE(WEBGL2)
-#include "JSWebGL2RenderingContext.h"
-#endif
-#endif
-
-#if ENABLE(WEBGPU)
-#include "JSWebGPURenderingContext.h"
-#endif
-
-using namespace JSC;
-
-namespace WebCore {
-
-JSValue JSHTMLCanvasElement::getContext(ExecState& state)
-{
-    auto& vm = state.vm();
-    auto scope = DECLARE_THROW_SCOPE(vm);
-
-    if (UNLIKELY(state.argumentCount() < 1))
-        return throwException(&state, scope, createNotEnoughArgumentsError(&state));
-
-    auto contextId = convert<IDLDOMString>(state, state.uncheckedArgument(0));
-    RETURN_IF_EXCEPTION(scope, JSValue());
-
-    if (HTMLCanvasElement::is2dType(contextId))
-        return toJS<IDLNullable<IDLInterface<CanvasRenderingContext2D>>>(state, *globalObject(), static_cast<CanvasRenderingContext2D*>(wrapped().getContext2d(contextId)));
-
-#if ENABLE(WEBGL)
-    if (HTMLCanvasElement::is3dType(contextId)) {
-        auto attributes = convert<IDLDictionary<WebGLContextAttributes>>(state, state.argument(1));
-        RETURN_IF_EXCEPTION(scope, JSValue());
-
-        if (auto context = wrapped().getContextWebGL(contextId, WTFMove(attributes))) {
-            if (is<WebGLRenderingContext>(*context))
-                return toJS<IDLNullable<IDLInterface<WebGLRenderingContext>>>(state, *globalObject(), static_cast<WebGLRenderingContext*>(context));
-#if ENABLE(WEBGL2)
-            if (is<WebGL2RenderingContext>(*context))
-                return toJS<IDLNullable<IDLInterface<WebGL2RenderingContext>>>(state, *globalObject(), static_cast<WebGL2RenderingContext*>(context));
-#endif
-        }
-    }
-#endif
-
-#if ENABLE(WEBGPU)
-    if (HTMLCanvasElement::isWebGPUType(contextId))
-        return toJS<IDLNullable<IDLInterface<WebGPURenderingContext>>>(state, *globalObject(), static_cast<WebGPURenderingContext*>(wrapped().getContextWebGPU(contextId)));
-#endif
-
-    return jsNull();
-}
-
-} // namespace WebCore

Modified: trunk/Source/WebCore/html/HTMLCanvasElement.cpp (219901 => 219902)


--- trunk/Source/WebCore/html/HTMLCanvasElement.cpp	2017-07-26 02:34:56 UTC (rev 219901)
+++ trunk/Source/WebCore/html/HTMLCanvasElement.cpp	2017-07-26 04:31:40 UTC (rev 219902)
@@ -44,6 +44,7 @@
 #include "HTMLParserIdioms.h"
 #include "ImageData.h"
 #include "InspectorInstrumentation.h"
+#include "JSDOMConvertDictionary.h"
 #include "MIMETypeRegistry.h"
 #include "RenderElement.h"
 #include "RenderHTMLCanvas.h"
@@ -64,9 +65,13 @@
 
 #if ENABLE(WEBGL)
 #include "WebGLContextAttributes.h"
-#include "WebGLRenderingContextBase.h"
+#include "WebGLRenderingContext.h"
 #endif
 
+#if ENABLE(WEBGL2)
+#include "WebGL2RenderingContext.h"
+#endif
+
 #if ENABLE(WEBGPU)
 #include "WebGPURenderingContext.h"
 #endif
@@ -73,7 +78,6 @@
 
 #if PLATFORM(COCOA)
 #include "MediaSampleAVFObjC.h"
-
 #include "CoreMediaSoftLink.h"
 #endif
 
@@ -219,6 +223,44 @@
     return maxPixelMemory;
 }
 
+ExceptionOr<std::optional<RenderingContext>> HTMLCanvasElement::getContext(JSC::ExecState& state, const String& contextId, Vector<JSC::Strong<JSC::Unknown>>&& arguments)
+{
+    if (is2dType(contextId)) {
+        if (auto context = getContext2d(contextId))
+            return std::optional<RenderingContext> { RefPtr<CanvasRenderingContext2D> { context } };
+        return std::optional<RenderingContext> { std::nullopt };
+    }
+
+#if ENABLE(WEBGL)
+    if (is3dType(contextId)) {
+        auto scope = DECLARE_THROW_SCOPE(state.vm());
+        auto attributes = convert<IDLDictionary<WebGLContextAttributes>>(state, !arguments.isEmpty() ? arguments[0].get() : JSC::jsUndefined());
+        RETURN_IF_EXCEPTION(scope, Exception { ExistingExceptionError });
+
+        if (auto context = getContextWebGL(contextId, WTFMove(attributes))) {
+            if (is<WebGLRenderingContext>(*context))
+                return std::optional<RenderingContext> { RefPtr<WebGLRenderingContext> { &downcast<WebGLRenderingContext>(*context) } };
+#if ENABLE(WEBGL2)
+            if (is<WebGL2RenderingContext>(*context))
+                return std::optional<RenderingContext> { RefPtr<WebGL2RenderingContext> { &downcast<WebGL2RenderingContext>(*context) } };
+#endif
+        }
+        
+        return std::optional<RenderingContext> { std::nullopt };
+    }
+#endif
+
+#if ENABLE(WEBGPU)
+    if (isWebGPUType(contextId)) {
+        if (auto context = getContextWebGPU(contextId))
+            return std::optional<RenderingContext> { RefPtr<WebGPURenderingContext> { context } };
+        return std::optional<RenderingContext> { std::nullopt };
+    }
+#endif
+
+    return std::optional<RenderingContext> { std::nullopt };
+}
+
 CanvasRenderingContext* HTMLCanvasElement::getContext(const String& type)
 {
     if (HTMLCanvasElement::is2dType(type))
@@ -242,12 +284,13 @@
     return type == "2d";
 }
 
-CanvasRenderingContext* HTMLCanvasElement::getContext2d(const String& type)
+CanvasRenderingContext2D* HTMLCanvasElement::getContext2d(const String& type)
 {
     ASSERT_UNUSED(HTMLCanvasElement::is2dType(type), type);
 
     if (m_context && !m_context->is2d())
         return nullptr;
+
     if (!m_context) {
         bool usesDashboardCompatibilityMode = false;
 #if ENABLE(DASHBOARD_SUPPORT)
@@ -278,7 +321,7 @@
 #endif
     }
 
-    return m_context.get();
+    return static_cast<CanvasRenderingContext2D*>(m_context.get());
 }
 
 #if ENABLE(WEBGL)
@@ -312,7 +355,7 @@
         || type == "webkit-3d";
 }
 
-CanvasRenderingContext* HTMLCanvasElement::getContextWebGL(const String& type, WebGLContextAttributes&& attrs)
+WebGLRenderingContextBase* HTMLCanvasElement::getContextWebGL(const String& type, WebGLContextAttributes&& attrs)
 {
     ASSERT(HTMLCanvasElement::is3dType(type));
 
@@ -332,7 +375,7 @@
         }
     }
 
-    return m_context.get();
+    return static_cast<WebGLRenderingContextBase*>(m_context.get());
 }
 #endif
 
@@ -342,7 +385,7 @@
     return type == "webgpu";
 }
 
-CanvasRenderingContext* HTMLCanvasElement::getContextWebGPU(const String& type)
+WebGPURenderingContext* HTMLCanvasElement::getContextWebGPU(const String& type)
 {
     ASSERT_UNUSED(type, HTMLCanvasElement::isWebGPUType(type));
 
@@ -362,7 +405,7 @@
         }
     }
 
-    return m_context.get();
+    return static_cast<WebGPURenderingContext*>(m_context.get());
 }
 #endif
 

Modified: trunk/Source/WebCore/html/HTMLCanvasElement.h (219901 => 219902)


--- trunk/Source/WebCore/html/HTMLCanvasElement.h	2017-07-26 02:34:56 UTC (rev 219901)
+++ trunk/Source/WebCore/html/HTMLCanvasElement.h	2017-07-26 04:31:40 UTC (rev 219902)
@@ -41,6 +41,7 @@
 namespace WebCore {
 
 class BlobCallback;
+class CanvasRenderingContext2D;
 class CanvasRenderingContext;
 class GraphicsContext;
 class GraphicsContextStateSaver;
@@ -50,6 +51,8 @@
 class ImageData;
 class MediaSample;
 class MediaStream;
+class WebGLRenderingContextBase;
+class WebGPURenderingContext;
 struct UncachedString;
 
 namespace DisplayList {
@@ -96,18 +99,20 @@
         reset();
     }
 
+    ExceptionOr<std::optional<RenderingContext>> getContext(JSC::ExecState&, const String& contextId, Vector<JSC::Strong<JSC::Unknown>>&& arguments);
+
     CanvasRenderingContext* getContext(const String&);
 
     static bool is2dType(const String&);
-    CanvasRenderingContext* getContext2d(const String&);
+    CanvasRenderingContext2D* getContext2d(const String&);
 
 #if ENABLE(WEBGL)
     static bool is3dType(const String&);
-    CanvasRenderingContext* getContextWebGL(const String&, WebGLContextAttributes&& = { });
+    WebGLRenderingContextBase* getContextWebGL(const String&, WebGLContextAttributes&& = { });
 #endif
 #if ENABLE(WEBGPU)
     static bool isWebGPUType(const String&);
-    CanvasRenderingContext* getContextWebGPU(const String&);
+    WebGPURenderingContext* getContextWebGPU(const String&);
 #endif
 
     WEBCORE_EXPORT ExceptionOr<UncachedString> toDataURL(const String& mimeType, JSC::JSValue quality);

Modified: trunk/Source/WebCore/html/HTMLCanvasElement.idl (219901 => 219902)


--- trunk/Source/WebCore/html/HTMLCanvasElement.idl	2017-07-26 02:34:56 UTC (rev 219901)
+++ trunk/Source/WebCore/html/HTMLCanvasElement.idl	2017-07-26 04:31:40 UTC (rev 219902)
@@ -24,7 +24,17 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
-typedef (CanvasRenderingContext2D or WebGLRenderingContextBase) RenderingContext;
+ typedef (
+ #if defined(ENABLE_WEBGL) && ENABLE_WEBGL
+     WebGLRenderingContext or
+ #endif
+ #if defined(ENABLE_WEBGL2) && ENABLE_WEBGL2
+     WebGL2RenderingContext or
+ #endif
+ #if defined(ENABLE_WEBGPU) && ENABLE_WEBGPU
+     WebGPURenderingContext or
+ #endif
+     CanvasRenderingContext2D) RenderingContext;
 
 [
     JSGenerateToNativeObject,
@@ -34,7 +44,7 @@
     attribute unsigned long width;
     attribute unsigned long height;
 
-    [Custom] RenderingContext? getContext(DOMString contextId, any... arguments);
+    [CallWith=ScriptState, MayThrowException] RenderingContext? getContext(DOMString contextId, any... arguments);
 
     [MayThrowException] DOMString toDataURL(optional DOMString type, optional any quality);
     [CallWith=ScriptExecutionContext, MayThrowException] void toBlob(BlobCallback callback, optional DOMString type, optional any quality);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to