[WebIDL] Simplify XMLHttpRequest bindings by removing built-ins
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 22 Jul 2017 03:54:16 +0000 (03:54 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 22 Jul 2017 03:54:16 +0000 (03:54 +0000)
https://bugs.webkit.org/show_bug.cgi?id=174740

Patch by Sam Weinig <sam@webkit.org> on 2017-07-21
Reviewed by Chris Dumez.

The behavior we were getting from XMLHttpRequest.js can be implemented
with the [CachedAttribute] extended attribute. This reduces the number
of JS -> C++ jumps required and makes the code more similar to other
bindings that need caching of an IDL any value.

* CMakeLists.txt:
* DerivedSources.make:
* xml/XMLHttpRequest.js: Removed.
Remove XMLHttpRequest.js.

* bindings/js/JSXMLHttpRequestCustom.cpp:
(WebCore::JSXMLHttpRequest::response):
(WebCore::JSXMLHttpRequest::retrieveResponse): Deleted.
* xml/XMLHttpRequest.idl:
Replace builtin with a [CachedAttribute] and [CustomGetter]
for the response property.

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

Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/DerivedSources.make
Source/WebCore/bindings/js/JSXMLHttpRequestCustom.cpp
Source/WebCore/xml/XMLHttpRequest.idl
Source/WebCore/xml/XMLHttpRequest.js [deleted file]

index 9adc7d6..1ea7535 100644 (file)
@@ -3843,7 +3843,6 @@ set(WebCore_BUILTINS_SOURCES
     ${WEBCORE_DIR}/Modules/streams/WritableStream.js
     ${WEBCORE_DIR}/Modules/streams/WritableStreamInternals.js
     ${WEBCORE_DIR}/bindings/js/JSDOMBindingInternals.js
-    ${WEBCORE_DIR}/xml/XMLHttpRequest.js
 )
 
 set(BUILTINS_GENERATOR_SCRIPTS
index 2facacf..c5462b6 100644 (file)
@@ -1,3 +1,27 @@
+2017-07-21  Sam Weinig  <sam@webkit.org>
+
+        [WebIDL] Simplify XMLHttpRequest bindings by removing built-ins
+        https://bugs.webkit.org/show_bug.cgi?id=174740
+
+        Reviewed by Chris Dumez.
+
+        The behavior we were getting from XMLHttpRequest.js can be implemented
+        with the [CachedAttribute] extended attribute. This reduces the number
+        of JS -> C++ jumps required and makes the code more similar to other
+        bindings that need caching of an IDL any value.
+
+        * CMakeLists.txt:
+        * DerivedSources.make:
+        * xml/XMLHttpRequest.js: Removed.
+        Remove XMLHttpRequest.js.
+
+        * bindings/js/JSXMLHttpRequestCustom.cpp:
+        (WebCore::JSXMLHttpRequest::response):
+        (WebCore::JSXMLHttpRequest::retrieveResponse): Deleted.
+        * xml/XMLHttpRequest.idl:
+        Replace builtin with a [CachedAttribute] and [CustomGetter]
+        for the response property.
+
 2017-07-21  Timothy Horton  <timothy_horton@apple.com>
 
         Drag and Drop preview image for Twitter link is the wrong shape
index c27b84d..547edda 100644 (file)
@@ -1398,7 +1398,6 @@ WebCore_BUILTINS_SOURCES = \
     $(WebCore)/Modules/streams/WritableStream.js \
     $(WebCore)/Modules/streams/WritableStreamInternals.js \
     $(WebCore)/bindings/js/JSDOMBindingInternals.js \
-    $(WebCore)/xml/XMLHttpRequest.js \
 #
 
 BUILTINS_GENERATOR_SCRIPTS = \
index 9a46c29..3d77506 100644 (file)
@@ -50,22 +50,31 @@ void JSXMLHttpRequest::visitAdditionalChildren(SlotVisitor& visitor)
         visitor.addOpaqueRoot(responseDocument);
 }
 
-JSValue JSXMLHttpRequest::retrieveResponse(ExecState& state)
+JSValue JSXMLHttpRequest::response(ExecState& state) const
 {
+    auto cacheResult = [&] (JSValue value) -> JSValue {
+        m_response.set(state.vm(), this, value);
+        return value;
+    };
+
+
+    if (wrapped().responseCacheIsValid())
+        return m_response.get();
+
     auto type = wrapped().responseType();
 
     switch (type) {
     case XMLHttpRequest::ResponseType::EmptyString:
     case XMLHttpRequest::ResponseType::Text: {
         auto scope = DECLARE_THROW_SCOPE(state.vm());
-        return toJS<IDLNullable<IDLUSVString>>(state, scope, wrapped().responseText());
+        return cacheResult(toJS<IDLNullable<IDLUSVString>>(state, scope, wrapped().responseText()));
     }
     default:
         break;
     }
 
     if (!wrapped().doneWithoutErrors())
-        return jsNull();
+        return cacheResult(jsNull());
 
     JSValue value;
     switch (type) {
@@ -97,7 +106,7 @@ JSValue JSXMLHttpRequest::retrieveResponse(ExecState& state)
     }
 
     wrapped().didCacheResponse();
-    return value;
+    return cacheResult(value);
 }
 
 } // namespace WebCore
index 569fd26..4b44e2a 100644 (file)
@@ -47,8 +47,6 @@ enum XMLHttpRequestResponseType {
     JSCustomMarkFunction,
     JSGenerateToJSObject,
     JSGenerateToNativeObject,
-    PrivateIdentifier,
-    PublicIdentifier,
 ] interface XMLHttpRequest : XMLHttpRequestEventTarget {
     // event handler
     attribute EventHandler onreadystatechange;
@@ -79,13 +77,8 @@ enum XMLHttpRequestResponseType {
     ByteString getAllResponseHeaders();
     [MayThrowException] void overrideMimeType(DOMString mime);
     [SetterMayThrowException] attribute XMLHttpRequestResponseType responseType;
-    [JSBuiltin] readonly attribute any response;
+    [CachedAttribute, CustomGetter] readonly attribute any response;
     [GetterMayThrowException] readonly attribute USVString responseText;
     // FIXME: responseXML should be annotated with [Exposed=Window].
     [GetterMayThrowException] readonly attribute Document? responseXML;
-
-    // internals
-    [PrivateIdentifier] boolean responseCacheIsValid();
-    [PrivateIdentifier, Custom] any retrieveResponse();
-
 };
diff --git a/Source/WebCore/xml/XMLHttpRequest.js b/Source/WebCore/xml/XMLHttpRequest.js
deleted file mode 100644 (file)
index 6ae546b..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (C) 2016 Apple Inc.
- *
- * 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.
- */
-
-function response()
-{
-    "use strict";
-
-    // FIXME: Add a helper routine for that kind of checks.
-    if (!(this instanceof @XMLHttpRequest))
-        @throwTypeError("The XMLHttpRequest.response getter can only be used on instances of XMLHttpRequest");
-
-    if (@XMLHttpRequest.prototype.@responseCacheIsValid.@call(this))
-        return this.@response;
-
-    this.@response = @XMLHttpRequest.prototype.@retrieveResponse.@call(this);
-    return this.@response;
-}