[WebIDL] Remove custom bindings that require non-caching JS strings
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Jul 2017 03:52:23 +0000 (03:52 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Jul 2017 03:52:23 +0000 (03:52 +0000)
https://bugs.webkit.org/show_bug.cgi?id=174552

Patch by Sam Weinig <sam@webkit.org> on 2017-07-17
Reviewed by Darin Adler.

Source/WebCore:

Adds two new types, UncachedString and OwnedString (both of which
are simple structs that wrap a String) to communicate to the bindings
layer which function to use when converting to a JS string.

* bindings/IDLTypes.h:
(WebCore::IDLString::isNullValue):
Add overloads of isNullValue for UncachedString and OwnedString.

* bindings/js/JSDOMConvertStrings.h:
(WebCore::JSConverter<IDLDOMString>::convert):
(WebCore::JSConverter<IDLByteString>::convert):
(WebCore::JSConverter<IDLUSVString>::convert):
Add overloads of convert for UncachedString that uses JSC::jsString
and for OwnedString that uses JSC::jsOwnedString.

* bindings/js/JSHTMLCanvasElementCustom.cpp:
(WebCore::JSHTMLCanvasElement::toDataURL): Deleted.
Remove custom binding for toDataURL.

* bindings/js/JSXMLHttpRequestCustom.cpp:
(WebCore::JSXMLHttpRequest::retrieveResponse):
(WebCore::JSXMLHttpRequest::responseText): Deleted.
Remove custom binding for responseText. Replace the caller of the
binding function with a simple conversion that will do the same thing.

* bindings/js/StringAdaptors.h: Added.
Add UncachedString and OwnedString adaptors.

* html/HTMLCanvasElement.cpp:
(WebCore::HTMLCanvasElement::toDataURL):
Move quality conversion here, matching toBlob and the spec. Return a UncachedString
to instruct the bindings to use JSC::jsString and not JSC::jsStringWithCache.

(WebCore::HTMLCanvasElement::toBlob):
Use asNumber() rather than toNumber(), since we just checked that it is a number.

* html/HTMLCanvasElement.h:
Update header to account for returning an UncachedString.

* html/HTMLCanvasElement.idl:
Remove [Custom] and make the signature of toDataURL match the spec (and what we have been doing).

* inspector/InspectorCanvasAgent.cpp:
(WebCore::InspectorCanvasAgent::requestContent):
Update to account for UncachedString.

* xml/XMLHttpRequest.cpp:
(WebCore::XMLHttpRequest::responseText):
* xml/XMLHttpRequest.h:
Update responseText to return OwnedString. OwnedString instruct the bindings to
use JSC::jsOwnedString and not JSC::jsStringWithCache.

* xml/XMLHttpRequest.idl:
Remove [CustomGetter].

Source/WebKitLegacy/mac:

* DOM/DOMHTMLCanvasElement.mm:
(-[DOMHTMLCanvasElement toDataURL:]):
Update to account for implementation now returning an UncachedString.

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

16 files changed:
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/IDLTypes.h
Source/WebCore/bindings/js/JSDOMConvertStrings.h
Source/WebCore/bindings/js/JSHTMLCanvasElementCustom.cpp
Source/WebCore/bindings/js/JSXMLHttpRequestCustom.cpp
Source/WebCore/bindings/js/StringAdaptors.h [new file with mode: 0644]
Source/WebCore/html/HTMLCanvasElement.cpp
Source/WebCore/html/HTMLCanvasElement.h
Source/WebCore/html/HTMLCanvasElement.idl
Source/WebCore/inspector/InspectorCanvasAgent.cpp
Source/WebCore/xml/XMLHttpRequest.cpp
Source/WebCore/xml/XMLHttpRequest.h
Source/WebCore/xml/XMLHttpRequest.idl
Source/WebKitLegacy/mac/ChangeLog
Source/WebKitLegacy/mac/DOM/DOMHTMLCanvasElement.mm

index 3e78690..0a370d0 100644 (file)
@@ -1,3 +1,65 @@
+2017-07-17  Sam Weinig  <sam@webkit.org>
+
+        [WebIDL] Remove custom bindings that require non-caching JS strings
+        https://bugs.webkit.org/show_bug.cgi?id=174552
+
+        Reviewed by Darin Adler.
+
+        Adds two new types, UncachedString and OwnedString (both of which
+        are simple structs that wrap a String) to communicate to the bindings
+        layer which function to use when converting to a JS string.
+
+        * bindings/IDLTypes.h:
+        (WebCore::IDLString::isNullValue):
+        Add overloads of isNullValue for UncachedString and OwnedString.
+
+        * bindings/js/JSDOMConvertStrings.h:
+        (WebCore::JSConverter<IDLDOMString>::convert):
+        (WebCore::JSConverter<IDLByteString>::convert):
+        (WebCore::JSConverter<IDLUSVString>::convert):
+        Add overloads of convert for UncachedString that uses JSC::jsString 
+        and for OwnedString that uses JSC::jsOwnedString.
+
+        * bindings/js/JSHTMLCanvasElementCustom.cpp:
+        (WebCore::JSHTMLCanvasElement::toDataURL): Deleted.
+        Remove custom binding for toDataURL.
+
+        * bindings/js/JSXMLHttpRequestCustom.cpp:
+        (WebCore::JSXMLHttpRequest::retrieveResponse):
+        (WebCore::JSXMLHttpRequest::responseText): Deleted.
+        Remove custom binding for responseText. Replace the caller of the 
+        binding function with a simple conversion that will do the same thing.
+
+        * bindings/js/StringAdaptors.h: Added.
+        Add UncachedString and OwnedString adaptors.
+
+        * html/HTMLCanvasElement.cpp:
+        (WebCore::HTMLCanvasElement::toDataURL):
+        Move quality conversion here, matching toBlob and the spec. Return a UncachedString
+        to instruct the bindings to use JSC::jsString and not JSC::jsStringWithCache.
+
+        (WebCore::HTMLCanvasElement::toBlob):
+        Use asNumber() rather than toNumber(), since we just checked that it is a number.
+
+        * html/HTMLCanvasElement.h:
+        Update header to account for returning an UncachedString.
+
+        * html/HTMLCanvasElement.idl:
+        Remove [Custom] and make the signature of toDataURL match the spec (and what we have been doing).
+
+        * inspector/InspectorCanvasAgent.cpp:
+        (WebCore::InspectorCanvasAgent::requestContent):
+        Update to account for UncachedString.
+
+        * xml/XMLHttpRequest.cpp:
+        (WebCore::XMLHttpRequest::responseText):
+        * xml/XMLHttpRequest.h:
+        Update responseText to return OwnedString. OwnedString instruct the bindings to 
+        use JSC::jsOwnedString and not JSC::jsStringWithCache.
+
+        * xml/XMLHttpRequest.idl:
+        Remove [CustomGetter].
+
 2017-07-17  Daniel Bates  <dabates@apple.com>
 
         Cleanup: Use OptionSet to represent marker types
index 53f3043..11d3f72 100644 (file)
                7C52229D1E1DAE47002CB8F7 /* RuntimeEnabledFeatures.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C52229B1E1DAE47002CB8F7 /* RuntimeEnabledFeatures.cpp */; };
                7C52229E1E1DAE47002CB8F7 /* RuntimeEnabledFeatures.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C52229C1E1DAE47002CB8F7 /* RuntimeEnabledFeatures.h */; settings = {ATTRIBUTES = (Private, ); }; };
                7C522D4B15B477E8009B7C95 /* InspectorOverlay.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C522D4915B477E8009B7C95 /* InspectorOverlay.cpp */; };
+               7C5266981F1B0302000F068B /* StringAdaptors.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C5266961F1B02FC000F068B /* StringAdaptors.h */; settings = {ATTRIBUTES = (Private, ); }; };
                7C5343FC17B74B63004232F0 /* JSMediaQueryListListener.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C5343FA17B74B63004232F0 /* JSMediaQueryListListener.cpp */; };
                7C5343FD17B74B63004232F0 /* JSMediaQueryListListener.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C5343FB17B74B63004232F0 /* JSMediaQueryListListener.h */; };
                7C57BFE71EDE2F6100534A48 /* JSDOMAbstractOperations.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C57BFE61EDE2F5B00534A48 /* JSDOMAbstractOperations.h */; settings = {ATTRIBUTES = (Private, ); }; };
                7C52229C1E1DAE47002CB8F7 /* RuntimeEnabledFeatures.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RuntimeEnabledFeatures.h; sourceTree = "<group>"; };
                7C522D4915B477E8009B7C95 /* InspectorOverlay.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorOverlay.cpp; sourceTree = "<group>"; };
                7C522D4A15B478B2009B7C95 /* InspectorOverlay.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorOverlay.h; sourceTree = "<group>"; };
+               7C5266961F1B02FC000F068B /* StringAdaptors.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringAdaptors.h; sourceTree = "<group>"; };
                7C5343FA17B74B63004232F0 /* JSMediaQueryListListener.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSMediaQueryListListener.cpp; sourceTree = "<group>"; };
                7C5343FB17B74B63004232F0 /* JSMediaQueryListListener.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = JSMediaQueryListListener.h; sourceTree = "<group>"; };
                7C57BFE61EDE2F5B00534A48 /* JSDOMAbstractOperations.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDOMAbstractOperations.h; sourceTree = "<group>"; };
                                1400D7A717136EA70077CE05 /* ScriptWrappableInlines.h */,
                                A75E497510752ACB00C9B896 /* SerializedScriptValue.cpp */,
                                A75E497410752ACB00C9B896 /* SerializedScriptValue.h */,
+                               7C5266961F1B02FC000F068B /* StringAdaptors.h */,
                                414B82021D6DF0D90077EBE3 /* StructuredClone.cpp */,
                                414B82031D6DF0D90077EBE3 /* StructuredClone.h */,
                                419BE7521BC7F3DB00E1C85B /* WebCoreBuiltinNames.h */,
                                1C21E57D183ED1FF001C289D /* IOSurfacePool.h in Headers */,
                                44DFF6431A6FF92700D45EEC /* IOSurfaceSPI.h in Headers */,
                                44EFF6431A6FF92700D45EEC /* IOTypesSPI.h in Headers */,
+                               7C5266981F1B0302000F068B /* StringAdaptors.h in Headers */,
                                07AC47021952102100EE9723 /* ISOVTTCue.h in Headers */,
                                418F88050FF957AF0080F045 /* JSAbstractWorker.h in Headers */,
                                5704405A1E53936200356601 /* JSAesCbcCfbParams.h in Headers */,
index d0df9ef..838e5f8 100644 (file)
@@ -25,6 +25,7 @@
 
 #pragma once
 
+#include "StringAdaptors.h"
 #include <heap/HandleTypes.h>
 #include <wtf/Brigand.h>
 #include <wtf/HashMap.h>
@@ -121,6 +122,8 @@ template<typename StringType> struct IDLString : IDLType<StringType> {
     using NullableType = StringType;
     static StringType nullValue() { return StringType(); }
     static bool isNullValue(const StringType& value) { return value.isNull(); }
+    static bool isNullValue(const UncachedString& value) { return value.string.isNull(); }
+    static bool isNullValue(const OwnedString& value) { return value.string.isNull(); }
     template <typename U> static U&& extractValueFromNullable(U&& value) { return std::forward<U>(value); }
 };
 struct IDLDOMString : IDLString<String> { };
index 5284c0c..dc89cbf 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "IDLTypes.h"
 #include "JSDOMConvertBase.h"
+#include "StringAdaptors.h"
 
 namespace WebCore {
 
@@ -64,6 +65,16 @@ template<> struct JSConverter<IDLDOMString> {
     {
         return JSC::jsStringWithCache(&state, value);
     }
+
+    static JSC::JSValue convert(JSC::ExecState& state, const UncachedString& value)
+    {
+        return JSC::jsString(&state, value.string);
+    }
+
+    static JSC::JSValue convert(JSC::ExecState& state, const OwnedString& value)
+    {
+        return JSC::jsOwnedString(&state, value.string);
+    }
 };
 
 template<> struct Converter<IDLByteString> : DefaultConverter<IDLByteString> {
@@ -81,6 +92,16 @@ template<> struct JSConverter<IDLByteString> {
     {
         return JSC::jsStringWithCache(&state, value);
     }
+
+    static JSC::JSValue convert(JSC::ExecState& state, const UncachedString& value)
+    {
+        return JSC::jsString(&state, value.string);
+    }
+
+    static JSC::JSValue convert(JSC::ExecState& state, const OwnedString& value)
+    {
+        return JSC::jsOwnedString(&state, value.string);
+    }
 };
 
 template<> struct Converter<IDLUSVString> : DefaultConverter<IDLUSVString> {
@@ -98,6 +119,16 @@ template<> struct JSConverter<IDLUSVString> {
     {
         return JSC::jsStringWithCache(&state, value);
     }
+
+    static JSC::JSValue convert(JSC::ExecState& state, const UncachedString& value)
+    {
+        return JSC::jsString(&state, value.string);
+    }
+
+    static JSC::JSValue convert(JSC::ExecState& state, const OwnedString& value)
+    {
+        return JSC::jsOwnedString(&state, value.string);
+    }
 };
 
 // MARK: -
index 6d68b14..ccddd02 100644 (file)
@@ -87,27 +87,4 @@ JSValue JSHTMLCanvasElement::getContext(ExecState& state)
     return jsNull();
 }
 
-JSValue JSHTMLCanvasElement::toDataURL(ExecState& state)
-{
-    VM& vm = state.vm();
-    auto scope = DECLARE_THROW_SCOPE(vm);
-
-    auto type = convert<IDLNullable<IDLDOMString>>(state, state.argument(0));
-    RETURN_IF_EXCEPTION(scope, JSC::JSValue());
-
-    std::optional<double> quality;
-    auto qualityValue = state.argument(1);
-    if (qualityValue.isNumber())
-        quality = qualityValue.toNumber(&state);
-
-    // We would use toJS<IDLString> here, but it uses jsStringWithCache and we historically
-    // did not cache here, presumably because results are likely to be differing long strings.
-    auto result = wrapped().toDataURL(type, quality);
-    if (result.hasException()) {
-        propagateException(state, scope, result.releaseException());
-        return { };
-    }
-    return jsString(&state, result.releaseReturnValue());
-}
-
 } // namespace WebCore
index 76b6da4..9a46c29 100644 (file)
 #include "JSDOMConvertBufferSource.h"
 #include "JSDOMConvertInterface.h"
 #include "JSDOMConvertJSON.h"
+#include "JSDOMConvertNullable.h"
+#include "JSDOMConvertStrings.h"
 #include "JSDocument.h"
-#include <runtime/ArrayBuffer.h>
-#include <runtime/JSArrayBuffer.h>
-#include <runtime/JSArrayBufferView.h>
 
 using namespace JSC;
 
@@ -51,34 +50,16 @@ void JSXMLHttpRequest::visitAdditionalChildren(SlotVisitor& visitor)
         visitor.addOpaqueRoot(responseDocument);
 }
 
-JSValue JSXMLHttpRequest::responseText(ExecState& state) const
-{
-    auto result = wrapped().responseText();
-
-    if (UNLIKELY(result.hasException())) {
-        auto& vm = state.vm();
-        auto scope = DECLARE_THROW_SCOPE(vm);
-        propagateException(state, scope, result.releaseException());
-        return { };
-    }
-
-    auto resultValue = result.releaseReturnValue();
-    if (resultValue.isNull())
-        return jsNull();
-
-    // See JavaScriptCore for explanation: Should be used for any string that is already owned by another
-    // object, to let the engine know that collecting the JSString wrapper is unlikely to save memory.
-    return jsOwnedString(&state, resultValue);
-}
-
 JSValue JSXMLHttpRequest::retrieveResponse(ExecState& state)
 {
     auto type = wrapped().responseType();
 
     switch (type) {
     case XMLHttpRequest::ResponseType::EmptyString:
-    case XMLHttpRequest::ResponseType::Text:
-        return responseText(state);
+    case XMLHttpRequest::ResponseType::Text: {
+        auto scope = DECLARE_THROW_SCOPE(state.vm());
+        return toJS<IDLNullable<IDLUSVString>>(state, scope, wrapped().responseText());
+    }
     default:
         break;
     }
diff --git a/Source/WebCore/bindings/js/StringAdaptors.h b/Source/WebCore/bindings/js/StringAdaptors.h
new file mode 100644 (file)
index 0000000..cceaa3a
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2017 Apple Inc. 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. AND ITS CONTRIBUTORS ``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 ITS 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.
+ */
+
+#pragma once
+
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+// This exists to communicate to the bindings that this string is not a good candidate
+// for caching.
+// Forces the use of the jsString() converter (rather than the normal jsStringWithCache()).
+struct UncachedString {
+    String string;
+};
+
+// This exists to communicate to the bindings that this string is owned by another
+// object and therefore that collecting the JSString wrapper is unlikely to save memory.
+// Forces the use of the jsOwnedString() converter (rather than the normal jsStringWithCache()).
+struct OwnedString {
+    String string;
+};
+
+}
index 1390f3e..d755ba4 100644 (file)
@@ -51,6 +51,7 @@
 #include "RuntimeEnabledFeatures.h"
 #include "ScriptController.h"
 #include "Settings.h"
+#include "StringAdaptors.h"
 #include <math.h>
 #include <runtime/JSCInlines.h>
 #include <runtime/JSLock.h>
@@ -531,32 +532,51 @@ void HTMLCanvasElement::setSurfaceSize(const IntSize& size)
     clearCopiedImage();
 }
 
-String HTMLCanvasElement::toEncodingMimeType(const String& mimeType)
+static String toEncodingMimeType(const String& mimeType)
 {
     if (!MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType))
         return ASCIILiteral("image/png");
     return mimeType.convertToASCIILowercase();
 }
 
-ExceptionOr<String> HTMLCanvasElement::toDataURL(const String& mimeType, std::optional<double> quality)
+// https://html.spec.whatwg.org/multipage/canvas.html#a-serialisation-of-the-bitmap-as-a-file
+static std::optional<double> qualityFromJSValue(JSC::JSValue qualityValue)
+{
+    if (!qualityValue.isNumber())
+        return std::nullopt;
+
+    double qualityNumber = qualityValue.asNumber();
+    if (qualityNumber < 0 || qualityNumber > 1)
+        return std::nullopt;
+
+    return qualityNumber;
+}
+
+ExceptionOr<UncachedString> HTMLCanvasElement::toDataURL(const String& mimeType, JSC::JSValue qualityValue)
 {
     if (!m_originClean)
         return Exception { SECURITY_ERR };
 
     if (m_size.isEmpty() || !buffer())
-        return String { ASCIILiteral { "data:," } };
+        return UncachedString { ASCIILiteral { "data:," } };
 
-    String encodingMIMEType = toEncodingMimeType(mimeType);
+    auto encodingMIMEType = toEncodingMimeType(mimeType);
+    auto quality = qualityFromJSValue(qualityValue);
 
 #if USE(CG)
     // Try to get ImageData first, as that may avoid lossy conversions.
     if (auto imageData = getImageData())
-        return dataURL(*imageData, encodingMIMEType, quality);
+        return UncachedString { dataURL(*imageData, encodingMIMEType, quality) };
 #endif
 
     makeRenderingResultsAvailable();
 
-    return buffer()->toDataURL(encodingMIMEType, quality);
+    return UncachedString { buffer()->toDataURL(encodingMIMEType, quality) };
+}
+
+ExceptionOr<UncachedString> HTMLCanvasElement::toDataURL(const String& mimeType)
+{
+    return toDataURL(mimeType, { });
 }
 
 ExceptionOr<void> HTMLCanvasElement::toBlob(ScriptExecutionContext& context, Ref<BlobCallback>&& callback, const String& mimeType, JSC::JSValue qualityValue)
@@ -569,10 +589,8 @@ ExceptionOr<void> HTMLCanvasElement::toBlob(ScriptExecutionContext& context, Ref
         return { };
     }
 
-    String encodingMIMEType = toEncodingMimeType(mimeType);
-    std::optional<double> quality;
-    if (qualityValue.isNumber())
-        quality = qualityValue.toNumber(context.execState());
+    auto encodingMIMEType = toEncodingMimeType(mimeType);
+    auto quality = qualityFromJSValue(qualityValue);
 
 #if USE(CG)
     if (auto imageData = getImageData()) {
index 796db06..05d7fef 100644 (file)
@@ -50,6 +50,7 @@ class ImageBuffer;
 class ImageData;
 class MediaSample;
 class MediaStream;
+struct UncachedString;
 
 namespace DisplayList {
 using AsTextFlags = unsigned;
@@ -109,10 +110,9 @@ public:
     CanvasRenderingContext* getContextWebGPU(const String&);
 #endif
 
-    static String toEncodingMimeType(const String& mimeType);
-    WEBCORE_EXPORT ExceptionOr<String> toDataURL(const String& mimeType, std::optional<double> quality);
-    ExceptionOr<String> toDataURL(const String& mimeType) { return toDataURL(mimeType, std::nullopt); }
-    ExceptionOr<void> toBlob(ScriptExecutionContext&, Ref<BlobCallback>&&, const String& mimeType, JSC::JSValue qualityValue);
+    WEBCORE_EXPORT ExceptionOr<UncachedString> toDataURL(const String& mimeType, JSC::JSValue quality);
+    WEBCORE_EXPORT ExceptionOr<UncachedString> toDataURL(const String& mimeType);
+    ExceptionOr<void> toBlob(ScriptExecutionContext&, Ref<BlobCallback>&&, const String& mimeType, JSC::JSValue quality);
 
     // Used for rendering
     void didDraw(const FloatRect&);
index ee38b55..40302eb 100644 (file)
@@ -36,7 +36,7 @@ typedef (CanvasRenderingContext2D or WebGLRenderingContextBase) RenderingContext
 
     [Custom] RenderingContext? getContext(DOMString contextId, any... arguments);
 
-    [Custom, MayThrowException] DOMString toDataURL(optional DOMString? type);
+    [MayThrowException] DOMString toDataURL(optional DOMString type, optional any quality);
     [CallWith=ScriptExecutionContext, MayThrowException] void toBlob(BlobCallback callback, optional DOMString type, optional any quality);
 
     [Conditional=MEDIA_STREAM, CallWith=ScriptExecutionContext, MayThrowException, NewObject] MediaStream captureStream(optional double frameRequestRate);
index 20f0baa..c1647ea 100644 (file)
@@ -26,7 +26,6 @@
 #include "config.h"
 #include "InspectorCanvasAgent.h"
 
-#include "CanvasRenderingContext.h"
 #include "CanvasRenderingContext2D.h"
 #include "Document.h"
 #include "Element.h"
@@ -38,6 +37,7 @@
 #include "JSMainThreadExecState.h"
 #include "MainFrame.h"
 #include "ScriptState.h"
+#include "StringAdaptors.h"
 #include <inspector/IdentifiersFactory.h>
 #include <inspector/InjectedScript.h>
 #include <inspector/InjectedScriptManager.h>
 
 #if ENABLE(WEBGL)
 #include "JSWebGLRenderingContext.h"
-#include "WebGLContextAttributes.h"
-#include "WebGLRenderingContext.h"
-#include "WebGLRenderingContextBase.h"
 #endif
 
 #if ENABLE(WEBGL2)
 #include "JSWebGL2RenderingContext.h"
-#include "WebGL2RenderingContext.h"
 #endif
 
 #if ENABLE(WEBGPU)
 #include "JSWebGPURenderingContext.h"
-#include "WebGPURenderingContext.h"
 #endif
 
 using namespace Inspector;
@@ -144,26 +139,26 @@ void InspectorCanvasAgent::requestContent(ErrorString& errorString, const String
 
     CanvasRenderingContext* context = canvasEntry->element->renderingContext();
     if (is<CanvasRenderingContext2D>(context)) {
-        ExceptionOr<String> result = canvasEntry->element->toDataURL(ASCIILiteral("image/png"));
+        auto result = canvasEntry->element->toDataURL(ASCIILiteral("image/png"));
         if (result.hasException()) {
             errorString = result.releaseException().releaseMessage();
             return;
         }
-        *content = result.releaseReturnValue();
+        *content = result.releaseReturnValue().string;
     }
 #if ENABLE(WEBGL)
     else if (is<WebGLRenderingContextBase>(context)) {
         WebGLRenderingContextBase* gl = downcast<WebGLRenderingContextBase>(context);
 
         gl->setPreventBufferClearForInspector(true);
-        ExceptionOr<String> result = canvasEntry->element->toDataURL(ASCIILiteral("image/png"));
+        auto result = canvasEntry->element->toDataURL(ASCIILiteral("image/png"));
         gl->setPreventBufferClearForInspector(false);
 
         if (result.hasException()) {
             errorString = result.releaseException().releaseMessage();
             return;
         }
-        *content = result.releaseReturnValue();
+        *content = result.releaseReturnValue().string;
     }
 #endif
     // FIXME: <https://webkit.org/b/173621> Web Inspector: Support getting the content of WebGPU contexts
index deb16b5..f9b39f5 100644 (file)
@@ -48,6 +48,7 @@
 #include "SecurityOriginPolicy.h"
 #include "Settings.h"
 #include "SharedBuffer.h"
+#include "StringAdaptors.h"
 #include "TextResourceDecoder.h"
 #include "ThreadableLoader.h"
 #include "XMLDocument.h"
@@ -156,11 +157,11 @@ XMLHttpRequest::State XMLHttpRequest::readyState() const
     return m_state;
 }
 
-ExceptionOr<String> XMLHttpRequest::responseText()
+ExceptionOr<OwnedString> XMLHttpRequest::responseText()
 {
     if (m_responseType != ResponseType::EmptyString && m_responseType != ResponseType::Text)
         return Exception { INVALID_STATE_ERR };
-    return responseTextIgnoringResponseType();
+    return OwnedString { responseTextIgnoringResponseType() };
 }
 
 void XMLHttpRequest::didCacheResponse()
index f6d9594..97bc6c6 100644 (file)
@@ -48,6 +48,7 @@ class SharedBuffer;
 class TextResourceDecoder;
 class ThreadableLoader;
 class XMLHttpRequestUpload;
+struct OwnedString;
 
 class XMLHttpRequest final : public RefCounted<XMLHttpRequest>, public XMLHttpRequestEventTarget, private ThreadableLoaderClient, public ActiveDOMObject {
     WTF_MAKE_FAST_ALLOCATED;
@@ -86,7 +87,7 @@ public:
     bool doneWithoutErrors() const { return !m_error && m_state == DONE; }
     String getAllResponseHeaders() const;
     String getResponseHeader(const String& name) const;
-    ExceptionOr<String> responseText();
+    ExceptionOr<OwnedString> responseText();
     String responseTextIgnoringResponseType() const { return m_responseBuilder.toStringPreserveCapacity(); }
     String responseMIMEType() const;
 
index e4e7390..569fd26 100644 (file)
@@ -80,7 +80,7 @@ enum XMLHttpRequestResponseType {
     [MayThrowException] void overrideMimeType(DOMString mime);
     [SetterMayThrowException] attribute XMLHttpRequestResponseType responseType;
     [JSBuiltin] readonly attribute any response;
-    [GetterMayThrowException, CustomGetter] readonly attribute USVString? responseText;
+    [GetterMayThrowException] readonly attribute USVString responseText;
     // FIXME: responseXML should be annotated with [Exposed=Window].
     [GetterMayThrowException] readonly attribute Document? responseXML;
 
index 8d443ed..a219eb1 100644 (file)
@@ -1,3 +1,14 @@
+2017-07-17  Sam Weinig  <sam@webkit.org>
+
+        [WebIDL] Remove custom bindings that require non-caching JS strings
+        https://bugs.webkit.org/show_bug.cgi?id=174552
+
+        Reviewed by Darin Adler.
+
+        * DOM/DOMHTMLCanvasElement.mm:
+        (-[DOMHTMLCanvasElement toDataURL:]):
+        Update to account for implementation now returning an UncachedString.
+
 2017-07-17  Darin Adler  <darin@apple.com>
 
         Improve use of NeverDestroyed
index b05f22d..3e371ee 100644 (file)
@@ -29,6 +29,7 @@
 #import "ExceptionHandlers.h"
 #import <WebCore/HTMLCanvasElement.h>
 #import <WebCore/JSMainThreadExecState.h>
+#import <WebCore/StringAdaptors.h>
 #import <WebCore/ThreadCheck.h>
 #import <WebCore/URL.h>
 #import <WebCore/WebScriptObjectPrivate.h>
 - (NSString *)toDataURL:(NSString *)type
 {
     WebCore::JSMainThreadNullState state;
-    return raiseOnDOMError(IMPL->toDataURL(type));
+
+    auto exceptionOrReturnValue = IMPL->toDataURL(type);
+    if (exceptionOrReturnValue.hasException())
+        raiseDOMErrorException(exceptionOrReturnValue.releaseException());
+
+    return exceptionOrReturnValue.releaseReturnValue().string;
 }
 
 @end