Changeset 203641 in webkit


Ignore:
Timestamp:
Jul 23, 2016 1:55:38 AM (8 years ago)
Author:
commit-queue@webkit.org
Message:

[Fetch API] Request should be created with any HeadersInit data
https://bugs.webkit.org/show_bug.cgi?id=159672

Patch by Youenn Fablet <youenn@apple.com> on 2016-07-23
Reviewed by Sam Weinig.

LayoutTests/imported/w3c:

  • imported/w3c/web-platform-tests/fetch/api/credentials/authentication-basic-expected.txt: Test was previously

failing due to lack of support for HeadersInit data in Request constructor.

  • platform/mac-wk1/imported/w3c/web-platform-tests/fetch/api/credentials/authentication-basic-expected.txt: Removed.
  • web-platform-tests/fetch/api/request/request-headers-expected.txt:
  • web-platform-tests/fetch/api/request/request-headers.html: Adding new test.

Source/JavaScriptCore:

  • Scripts/builtins/builtins_generator.py:

(WK_lcfirst): Synchronized with CodeGenerator.pm version.

Source/WebCore:

Made Request use JSBuiltinConstructor.
This allows initializing newly created Request with a JS built-in function, initializeFetchRequest.
initializeFetchRequest can call @fillFetchHeaders internal built-in to handle any HeadersInit data.
Future effort should be made to migrate more initialization code in initializeFetchRequest.

Made window and worker fetch function as a JS built-in.
This becomes more handy as these new functions can construct the Request object.
They can then call a single private function that takes a Request object as input.
Updated DOMWindowFetch and WorkerGlobalScopeFetch code accordingly.

To enable this, the binding generator is updated to support runtime-enabled JS built-in functions and
private functions atttached to global objects.

Covered by existing and modified tests.
Binding generator test covered by updated binding tests.

  • CMakeLists.txt: Adding DOMWindowFetch.js, FetchRequest.js and WorkerGlobalScopeFetch.js built-in files.
  • DerivedSources.make: Ditto.
  • Modules/fetch/DOMWindowFetch.cpp: Removed overloaded fetch and updated according new signature.

(WebCore::DOMWindowFetch::fetch):

  • Modules/fetch/DOMWindowFetch.h: Ditto.
  • Modules/fetch/DOMWindowFetch.idl: Making fetch a JS built-in and adding a @fetchRequest private function.
  • Modules/fetch/DOMWindowFetch.js: Added.

(fetch):

  • Modules/fetch/FetchHeaders.h:

(WebCore::FetchHeaders::setGuard): Used by FetchRequest when initializing headers.

  • Modules/fetch/FetchRequest.cpp:

(WebCore::buildHeaders): Removed as implemented in JS.
(WebCore::FetchRequest::initializeOptions): Added to handle most of the dictionary initialization.
(WebCore::FetchRequest::initializeWith): Method called from built-in constructor function.
(WebCore::FetchRequest::setBody): Corresponding to @setBody private method.
(WebCore::buildBody): Deleted.

  • Modules/fetch/FetchRequest.h:
  • Modules/fetch/FetchRequest.idl:
  • Modules/fetch/FetchRequest.js: Added.

(initializeFetchRequest): Implements fetch Request(input, init) constructor.

  • Modules/fetch/FetchResponse.cpp:

(WebCore::FetchResponse::fetch): Removed the construction of FetchRequest in fetch method since it is done by JS built-in code.

  • Modules/fetch/FetchResponse.h:
  • Modules/fetch/WorkerGlobalScopeFetch.cpp: Removed overloaded fetch and updated according new signature.

(WebCore::WorkerGlobalScopeFetch::fetch):

  • Modules/fetch/WorkerGlobalScopeFetch.h: Ditto.
  • Modules/fetch/WorkerGlobalScopeFetch.idl: Making fetch a JS built-in and adding a @fetchRequest private function.
  • Modules/fetch/WorkerGlobalScopeFetch.js: Added.

(fetch):

  • bindings/js/WebCoreBuiltinNames.h: Adding fetchRequest, setBody and Request private identifiers.
  • bindings/scripts/CodeGenerator.pm:

(WK_lcfirst): Replacing dOM by dom.

  • bindings/scripts/CodeGeneratorJS.pm:

(GenerateImplementation): Adding support for runtime-enabled built-in methods and private methods.

  • bindings/scripts/test/JS/JSTestGlobalObject.cpp:

(WebCore::JSTestGlobalObject::finishCreation):
(WebCore::jsTestGlobalObjectInstanceFunctionTestPrivateFunction):

  • bindings/scripts/test/ObjC/DOMTestGlobalObject.mm:

(-[DOMTestGlobalObject testJSBuiltinFunction]):

  • bindings/scripts/test/TestGlobalObject.idl: Adding tests for runtime-enabled global built-in methods and private methods.
Location:
trunk
Files:
1 deleted
27 edited
3 copied

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r203638 r203641  
     12016-07-23  Youenn Fablet  <youenn@apple.com>
     2
     3        [Fetch API] Request should be created with any HeadersInit data
     4        https://bugs.webkit.org/show_bug.cgi?id=159672
     5
     6        Reviewed by Sam Weinig.
     7
     8        * imported/w3c/web-platform-tests/fetch/api/credentials/authentication-basic-expected.txt: Test was previously
     9        failing due to lack of support for HeadersInit data in Request constructor.
     10        * platform/mac-wk1/imported/w3c/web-platform-tests/fetch/api/credentials/authentication-basic-expected.txt: Removed.
     11        * web-platform-tests/fetch/api/request/request-headers-expected.txt:
     12        * web-platform-tests/fetch/api/request/request-headers.html: Adding new test.
     13
    1142016-07-23  Youenn Fablet  <youenn@apple.com>
    215
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/credentials/authentication-basic-expected.txt

    r200195 r203641  
    1 localhost:8800 - didReceiveAuthenticationChallenge - Simulating cancelled authentication sheet
    2 localhost:8800 - didReceiveAuthenticationChallenge - Simulating cancelled authentication sheet
    3 localhost:8800 - didReceiveAuthenticationChallenge - Simulating cancelled authentication sheet
    41
    5 FAIL User-added Authorization header with include mode assert_equals: HTTP status is 200 expected 200 but got 401
    6 FAIL User-added Authorization header with same-origin mode assert_equals: HTTP status is 200 expected 200 but got 401
    7 FAIL User-added Authorization header with omit mode assert_equals: HTTP status is 200 expected 200 but got 401
     2PASS User-added Authorization header with include mode
     3PASS User-added Authorization header with same-origin mode
     4PASS User-added Authorization header with omit mode
    85
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-headers-expected.txt

    r195954 r203641  
    5454PASS Request should get its content-type from the body if none is provided
    5555PASS Request should get its content-type from init headers if one is provided
     56PASS Testing request header creations with various objects
    5657
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-headers.html

    r195954 r203641  
    146146      }, "Request should get its content-type from init headers if one is provided");
    147147
     148      test(function() {
     149        var array = [["hello", "worldAHH"]];
     150        var object = {"hello": 'worldOOH'};
     151        var headers = new Headers(array);
     152
     153        assert_equals(headers.get("hello"), "worldAHH");
     154
     155        var request1 = new Request("", {"headers": headers});
     156        var request2 = new Request("", {"headers": array});
     157        var request3 = new Request("", {"headers": object});
     158
     159        assert_equals(request1.headers.get("hello"), "worldAHH");
     160        assert_equals(request2.headers.get("hello"), "worldAHH");
     161        assert_equals(request3.headers.get("hello"), "worldOOH");
     162      }, "Testing request header creations with various objects");
     163
    148164    </script>
    149165  </body>
  • trunk/Source/JavaScriptCore/ChangeLog

    r203621 r203641  
     12016-07-23  Youenn Fablet  <youenn@apple.com>
     2
     3        [Fetch API] Request should be created with any HeadersInit data
     4        https://bugs.webkit.org/show_bug.cgi?id=159672
     5
     6        Reviewed by Sam Weinig.
     7
     8        * Scripts/builtins/builtins_generator.py:
     9        (WK_lcfirst): Synchronized with CodeGenerator.pm version.
     10
    1112016-07-21  Filip Pizlo  <fpizlo@apple.com>
    212
  • trunk/Source/JavaScriptCore/Scripts/builtins/builtins_generator.py

    r202975 r203641  
    3939def WK_lcfirst(str):
    4040    str = str[:1].lower() + str[1:]
    41     str = str.replace('hTML', 'html')
     41    str = str.replace('dOM', 'dom')
    4242    str = str.replace('uRL', 'url')
    4343    str = str.replace('jS', 'js')
  • trunk/Source/WebCore/CMakeLists.txt

    r203632 r203641  
    37113711
    37123712set(WebCore_BUILTINS_SOURCES
     3713    ${WEBCORE_DIR}/Modules/fetch/DOMWindowFetch.js
    37133714    ${WEBCORE_DIR}/Modules/fetch/FetchHeaders.js
    37143715    ${WEBCORE_DIR}/Modules/fetch/FetchInternals.js
     3716    ${WEBCORE_DIR}/Modules/fetch/FetchRequest.js
    37153717    ${WEBCORE_DIR}/Modules/fetch/FetchResponse.js
     3718    ${WEBCORE_DIR}/Modules/fetch/WorkerGlobalScopeFetch.js
    37163719    ${WEBCORE_DIR}/Modules/mediastream/MediaDevices.js
    37173720    ${WEBCORE_DIR}/Modules/mediastream/NavigatorUserMedia.js
  • trunk/Source/WebCore/ChangeLog

    r203640 r203641  
     12016-07-23  Youenn Fablet  <youenn@apple.com>
     2
     3        [Fetch API] Request should be created with any HeadersInit data
     4        https://bugs.webkit.org/show_bug.cgi?id=159672
     5
     6        Reviewed by Sam Weinig.
     7
     8        Made Request use JSBuiltinConstructor.
     9        This allows initializing newly created Request with a JS built-in function, initializeFetchRequest.
     10        initializeFetchRequest can call @fillFetchHeaders internal built-in to handle any HeadersInit data.
     11        Future effort should be made to migrate more initialization code in initializeFetchRequest.
     12
     13        Made window and worker fetch function as a JS built-in.
     14        This becomes more handy as these new functions can construct the Request object.
     15        They can then call a single private function that takes a Request object as input.
     16        Updated DOMWindowFetch and WorkerGlobalScopeFetch code accordingly.
     17
     18        To enable this, the binding generator is updated to support runtime-enabled JS built-in functions and
     19        private functions atttached to global objects.
     20
     21        Covered by existing and modified tests.
     22        Binding generator test covered by updated binding tests.
     23
     24        * CMakeLists.txt: Adding DOMWindowFetch.js, FetchRequest.js and WorkerGlobalScopeFetch.js built-in files.
     25        * DerivedSources.make: Ditto.
     26        * Modules/fetch/DOMWindowFetch.cpp: Removed overloaded fetch and updated according new signature.
     27        (WebCore::DOMWindowFetch::fetch):
     28        * Modules/fetch/DOMWindowFetch.h: Ditto.
     29        * Modules/fetch/DOMWindowFetch.idl: Making fetch a JS built-in and adding a @fetchRequest private function.
     30        * Modules/fetch/DOMWindowFetch.js: Added.
     31        (fetch):
     32        * Modules/fetch/FetchHeaders.h:
     33        (WebCore::FetchHeaders::setGuard): Used by FetchRequest when initializing headers.
     34        * Modules/fetch/FetchRequest.cpp:
     35        (WebCore::buildHeaders): Removed as implemented in JS.
     36        (WebCore::FetchRequest::initializeOptions): Added to handle most of the dictionary initialization.
     37        (WebCore::FetchRequest::initializeWith): Method called from built-in constructor function.
     38        (WebCore::FetchRequest::setBody): Corresponding to @setBody private method.
     39        (WebCore::buildBody): Deleted.
     40        * Modules/fetch/FetchRequest.h:
     41        * Modules/fetch/FetchRequest.idl:
     42        * Modules/fetch/FetchRequest.js: Added.
     43        (initializeFetchRequest): Implements fetch Request(input, init) constructor.
     44        * Modules/fetch/FetchResponse.cpp:
     45        (WebCore::FetchResponse::fetch): Removed the construction of FetchRequest in fetch method since it is done by JS built-in code.
     46        * Modules/fetch/FetchResponse.h:
     47        * Modules/fetch/WorkerGlobalScopeFetch.cpp: Removed overloaded fetch and updated according new signature.
     48        (WebCore::WorkerGlobalScopeFetch::fetch):
     49        * Modules/fetch/WorkerGlobalScopeFetch.h: Ditto.
     50        * Modules/fetch/WorkerGlobalScopeFetch.idl: Making fetch a JS built-in and adding a @fetchRequest private function.
     51        * Modules/fetch/WorkerGlobalScopeFetch.js: Added.
     52        (fetch):
     53        * bindings/js/WebCoreBuiltinNames.h: Adding fetchRequest, setBody and Request private identifiers.
     54        * bindings/scripts/CodeGenerator.pm:
     55        (WK_lcfirst): Replacing dOM by dom.
     56        * bindings/scripts/CodeGeneratorJS.pm:
     57        (GenerateImplementation): Adding support for runtime-enabled built-in methods and private methods.
     58        * bindings/scripts/test/JS/JSTestGlobalObject.cpp:
     59        (WebCore::JSTestGlobalObject::finishCreation):
     60        (WebCore::jsTestGlobalObjectInstanceFunctionTestPrivateFunction):
     61        * bindings/scripts/test/ObjC/DOMTestGlobalObject.mm:
     62        (-[DOMTestGlobalObject testJSBuiltinFunction]):
     63        * bindings/scripts/test/TestGlobalObject.idl: Adding tests for runtime-enabled global built-in methods and private methods.
     64
    1652016-07-23  Frederic Wang  <fwang@igalia.com>
    266
  • trunk/Source/WebCore/DerivedSources.make

    r203554 r203641  
    12841284
    12851285WebCore_BUILTINS_SOURCES = \
     1286    ${WebCore}/Modules/fetch/DOMWindowFetch.js \
    12861287    $(WebCore)/Modules/fetch/FetchHeaders.js \
    12871288    $(WebCore)/Modules/fetch/FetchInternals.js \
     1289    $(WebCore)/Modules/fetch/FetchRequest.js \
    12881290    $(WebCore)/Modules/fetch/FetchResponse.js \
     1291    ${WebCore}/Modules/fetch/WorkerGlobalScopeFetch.js \
    12891292    $(WebCore)/Modules/mediastream/MediaDevices.js \
    12901293    $(WebCore)/Modules/mediastream/NavigatorUserMedia.js \
  • trunk/Source/WebCore/Modules/fetch/DOMWindowFetch.cpp

    r198891 r203641  
    3838namespace WebCore {
    3939
    40 void DOMWindowFetch::fetch(DOMWindow& window, FetchRequest& input, const Dictionary& dictionary, DeferredWrapper&& promise)
     40void DOMWindowFetch::fetch(DOMWindow& window, FetchRequest& request, DeferredWrapper&& promise)
    4141{
    4242    if (!window.scriptExecutionContext())
    4343        return;
    44     FetchResponse::fetch(*window.scriptExecutionContext(), input, dictionary, WTFMove(promise));
    45 }
    46 
    47 void DOMWindowFetch::fetch(DOMWindow& window, const String& url, const Dictionary& dictionary, DeferredWrapper&& promise)
    48 {
    49     if (!window.scriptExecutionContext())
    50         return;
    51     FetchResponse::fetch(*window.scriptExecutionContext(), url, dictionary, WTFMove(promise));
     44    FetchResponse::fetch(*window.scriptExecutionContext(), request, WTFMove(promise));
    5245}
    5346
  • trunk/Source/WebCore/Modules/fetch/DOMWindowFetch.h

    r198833 r203641  
    2626 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 #ifndef DOMWindowFetch_h
    29 #define DOMWindowFetch_h
     28
     29#pragma once
    3030
    3131#if ENABLE(FETCH_API)
     
    4242class DOMWindowFetch {
    4343public:
    44     static void fetch(DOMWindow&, FetchRequest&, const Dictionary&, DeferredWrapper&&);
    45     static void fetch(DOMWindow&, const String&, const Dictionary&, DeferredWrapper&&);
     44    static void fetch(DOMWindow&, FetchRequest&, DeferredWrapper&&);
    4645};
    4746
     
    4948
    5049#endif // ENABLE(FETCH_API)
    51 
    52 #endif // DOMWindowFetch_h
  • trunk/Source/WebCore/Modules/fetch/DOMWindowFetch.idl

    r199081 r203641  
    3131    EnabledAtRuntime=FetchAPI,
    3232] partial interface DOMWindow {
    33     Promise fetch(FetchRequest input, optional Dictionary init);
    34     Promise fetch(DOMString input, optional Dictionary init);
     33    [JSBuiltin] Promise fetch(any input, optional Dictionary init);
     34
     35    [PrivateIdentifier, ImplementedAs=fetch] Promise fetchRequest(FetchRequest request);
    3536};
  • trunk/Source/WebCore/Modules/fetch/DOMWindowFetch.js

    r203640 r203641  
    11/*
    2  * Copyright (C) 2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2016 Apple Inc.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 // This interface is recognized as a global object by the bindings generator.
    27 interface TestGlobalObject {
    28     attribute DOMString regularAttribute;
    29     [PrivateIdentifier, PublicIdentifier] attribute DOMString publicAndPrivateAttribute;
    30     [Conditional=TEST_FEATURE, PrivateIdentifier, PublicIdentifier] attribute DOMString publicAndPrivateConditionalAttribute;
    31     [Conditional=TEST_FEATURE, EnabledAtRuntime=TestFeature] attribute DOMString enabledAtRuntimeAttribute;
    32     void regularOperation(DOMString testParam);
    33     [Conditional=TEST_FEATURE, EnabledAtRuntime=TestFeature] void enabledAtRuntimeOperation(DOMString testParam);
    34     [Conditional=TEST_FEATURE, EnabledAtRuntime=TestFeature] void enabledAtRuntimeOperation(long testParam);
    35 };
     26// @conditional=ENABLE(FETCH_API)
     27
     28function fetch(input, init)
     29{
     30    "use strict";
     31
     32    try {
     33        return @fetchRequest(new @Request(input, init));
     34    } catch(e) {
     35        return @Promise.@reject(e);
     36    }
     37}
  • trunk/Source/WebCore/Modules/fetch/FetchHeaders.h

    r200546 r203641  
    2727 */
    2828
    29 #ifndef FetchHeaders_h
    30 #define FetchHeaders_h
     29#pragma once
    3130
    3231#if ENABLE(FETCH_API)
     
    8079    const HTTPHeaderMap& internalHeaders() const { return m_headers; }
    8180
     81    void setGuard(Guard);
     82
    8283private:
    8384    FetchHeaders(Guard guard) : m_guard(guard) { }
     
    8889};
    8990
     91inline void FetchHeaders::setGuard(Guard guard)
     92{
     93    ASSERT(!m_headers.size());
     94    m_guard = guard;
     95}
     96
    9097} // namespace WebCore
    9198
    9299#endif // ENABLE(FETCH_API)
    93 
    94 #endif // FetchHeaders_h
  • trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp

    r203221 r203641  
    194194}
    195195
    196 static RefPtr<FetchHeaders> buildHeaders(const Dictionary& init, const FetchRequest::InternalRequest& request, const FetchHeaders* inputHeaders = nullptr)
    197 {
    198     FetchHeaders::Guard guard = FetchHeaders::Guard::Request;
    199     if (request.options.mode == FetchOptions::Mode::NoCors) {
    200         const String& method = request.request.httpMethod();
    201         if (method != "GET" && method != "POST" && method != "HEAD")
    202             return nullptr;
    203         if (!request.integrity.isEmpty())
    204             return nullptr;
    205         guard = FetchHeaders::Guard::RequestNoCors;
    206     }
    207 
    208     RefPtr<FetchHeaders> initialHeaders;
    209     RefPtr<FetchHeaders> headers = FetchHeaders::create(guard);
    210     headers->fill(init.get("headers", initialHeaders) ? initialHeaders.get() : inputHeaders);
    211 
    212     return headers;
    213 }
    214 
    215 static FetchBody buildBody(const Dictionary& init, FetchHeaders& headers, FetchBody* inputBody = nullptr)
    216 {
    217     JSC::JSValue value;
    218     bool hasInitBody = init.get("body", value);
    219     FetchBody body = hasInitBody ? FetchBody::extract(*init.execState(), value) : FetchBody::extractFromBody(inputBody);
    220 
    221     String type = headers.fastGet(HTTPHeaderName::ContentType);
    222     if (hasInitBody && type.isEmpty() && !body.mimeType().isEmpty()) {
    223         type = body.mimeType();
    224         headers.fastSet(HTTPHeaderName::ContentType, type);
    225     }
    226     body.setMimeType(type);
    227     return body;
    228 }
    229 
    230196static bool validateBodyAndMethod(const FetchBody& body, const FetchRequest::InternalRequest& internalRequest)
    231197{
     
    235201}
    236202
    237 RefPtr<FetchRequest> FetchRequest::create(ScriptExecutionContext& context, const String& url, const Dictionary& init, ExceptionCode& ec)
    238 {
     203void FetchRequest::initializeOptions(const Dictionary& init, ExceptionCode& ec)
     204{
     205    ASSERT(scriptExecutionContext());
     206    if (!buildOptions(m_internalRequest, *scriptExecutionContext(), init)) {
     207        ec = TypeError;
     208        return;
     209    }
     210
     211    if (m_internalRequest.options.mode == FetchOptions::Mode::NoCors) {
     212        const String& method = m_internalRequest.request.httpMethod();
     213        if (method != "GET" && method != "POST" && method != "HEAD") {
     214            ec = TypeError;
     215            return;
     216        }
     217        if (!m_internalRequest.integrity.isEmpty()) {
     218            ec = TypeError;
     219            return;
     220        }
     221        m_headers->setGuard(FetchHeaders::Guard::RequestNoCors);
     222    }
     223}
     224
     225FetchHeaders* FetchRequest::initializeWith(const String& url, const Dictionary& init, ExceptionCode& ec)
     226{
     227    ASSERT(scriptExecutionContext());
    239228    // FIXME: Tighten the URL parsing algorithm according https://url.spec.whatwg.org/#concept-url-parser.
    240     URL requestURL = context.completeURL(url);
     229    URL requestURL = scriptExecutionContext()->completeURL(url);
    241230    if (!requestURL.isValid() || !requestURL.user().isEmpty() || !requestURL.pass().isEmpty()) {
    242231        ec = TypeError;
     
    244233    }
    245234
    246     FetchRequest::InternalRequest internalRequest;
    247     internalRequest.options.mode = Mode::Cors;
    248     internalRequest.options.credentials = Credentials::Omit;
    249     internalRequest.referrer = ASCIILiteral("client");
    250     internalRequest.request.setURL(requestURL);
    251 
    252     if (!buildOptions(internalRequest, context, init)) {
     235    m_internalRequest.options.mode = Mode::Cors;
     236    m_internalRequest.options.credentials = Credentials::Omit;
     237    m_internalRequest.referrer = ASCIILiteral("client");
     238    m_internalRequest.request.setURL(requestURL);
     239
     240    initializeOptions(init, ec);
     241    return m_headers.ptr();
     242}
     243
     244FetchHeaders* FetchRequest::initializeWith(FetchRequest& input, const Dictionary& init, ExceptionCode& ec)
     245{
     246    if (input.isDisturbed()) {
    253247        ec = TypeError;
    254248        return nullptr;
    255249    }
    256250
    257     RefPtr<FetchHeaders> headers = buildHeaders(init, internalRequest);
    258     if (!headers) {
    259         ec = TypeError;
    260         return nullptr;
    261     }
    262 
    263     FetchBody body = buildBody(init, *headers);
    264     if (!validateBodyAndMethod(body, internalRequest)) {
    265         ec = TypeError;
    266         return nullptr;
    267     }
    268 
    269     return adoptRef(*new FetchRequest(context, WTFMove(body), headers.releaseNonNull(), WTFMove(internalRequest)));
    270 }
    271 
    272 RefPtr<FetchRequest> FetchRequest::create(ScriptExecutionContext& context, FetchRequest& input, const Dictionary& init, ExceptionCode& ec)
    273 {
    274     if (input.isDisturbed()) {
    275         ec = TypeError;
    276         return nullptr;
    277     }
    278 
    279     FetchRequest::InternalRequest internalRequest(input.m_internalRequest);
    280 
    281     if (!buildOptions(internalRequest, context, init)) {
    282         ec = TypeError;
    283         return nullptr;
    284     }
    285 
    286     RefPtr<FetchHeaders> headers = buildHeaders(init, internalRequest, input.m_headers.ptr());
    287     if (!headers) {
    288         ec = TypeError;
    289         return nullptr;
    290     }
    291 
    292     FetchBody body = buildBody(init, *headers, &input.m_body);
    293     if (!validateBodyAndMethod(body, internalRequest)) {
    294         ec = TypeError;
    295         return nullptr;
    296     }
    297 
    298     if (!input.m_body.isEmpty())
    299         input.setDisturbed();
    300 
    301     return adoptRef(*new FetchRequest(context, WTFMove(body), headers.releaseNonNull(), WTFMove(internalRequest)));
     251    m_internalRequest = input.m_internalRequest;
     252
     253    initializeOptions(init, ec);
     254    return m_headers.ptr();
     255}
     256
     257void FetchRequest::setBody(JSC::ExecState& execState, JSC::JSValue body, FetchRequest* request, ExceptionCode& ec)
     258{
     259    if (!body.isNull())
     260        m_body = FetchBody::extract(execState, body);
     261    else if (request && !request->m_body.isEmpty()) {
     262        m_body = FetchBody::extractFromBody(&request->m_body);
     263        request->setDisturbed();
     264    }
     265
     266    String type = m_headers->fastGet(HTTPHeaderName::ContentType);
     267    if (!body.isUndefined() && type.isEmpty() && !m_body.mimeType().isEmpty()) {
     268        type = m_body.mimeType();
     269        m_headers->fastSet(HTTPHeaderName::ContentType, type);
     270    }
     271    m_body.setMimeType(type);
     272    if (!validateBodyAndMethod(m_body, m_internalRequest))
     273        ec = TypeError;
    302274}
    303275
  • trunk/Source/WebCore/Modules/fetch/FetchRequest.h

    r203221 r203641  
    4646class FetchRequest final : public FetchBodyOwner {
    4747public:
    48     static RefPtr<FetchRequest> create(ScriptExecutionContext&, FetchRequest&, const Dictionary&, ExceptionCode&);
    49     static RefPtr<FetchRequest> create(ScriptExecutionContext&, const String&, const Dictionary&, ExceptionCode&);
     48    static Ref<FetchRequest> create(ScriptExecutionContext& context) { return adoptRef(*new FetchRequest(context, { }, FetchHeaders::create(FetchHeaders::Guard::Request), { })); }
     49
     50    FetchHeaders* initializeWith(FetchRequest&, const Dictionary&, ExceptionCode&);
     51    FetchHeaders* initializeWith(const String&, const Dictionary&, ExceptionCode&);
     52    void setBody(JSC::ExecState&, JSC::JSValue, FetchRequest*, ExceptionCode&);
    5053
    5154    const String& method() const { return m_internalRequest.request.httpMethod(); }
     
    9295private:
    9396    FetchRequest(ScriptExecutionContext&, FetchBody&&, Ref<FetchHeaders>&&, InternalRequest&&);
     97
     98    void initializeOptions(const Dictionary&, ExceptionCode&);
    9499
    95100    // ActiveDOMObject API.
  • trunk/Source/WebCore/Modules/fetch/FetchRequest.idl

    r202323 r203641  
    3838    ActiveDOMObject,
    3939    Conditional=FETCH_API,
     40    Constructor(any input, optional Dictionary init),
    4041    EnabledAtRuntime=FetchAPI,
    41     ConstructorCallWith=ScriptExecutionContext,
    42     ConstructorRaisesException,
    43     Constructor(FetchRequest input, optional Dictionary init),
    44     Constructor(DOMString input, optional Dictionary init),
    4542    Exposed=(Window,Worker),
    46     InterfaceName=Request
     43    InterfaceName=Request,
     44    JSBuiltinConstructor,
     45    PrivateIdentifier,
     46    PublicIdentifier,
    4747]
    4848interface FetchRequest {
     
    6262
    6363    [NewObject, CallWith=ScriptExecutionContext, RaisesException] FetchRequest clone();
     64
     65    [PrivateIdentifier, RaisesException] FetchHeaders initializeWith(FetchRequest input, Dictionary init);
     66    [PrivateIdentifier, RaisesException] FetchHeaders initializeWith(DOMString input, Dictionary init);
     67    [PrivateIdentifier, RaisesException, CallWith=ScriptState] void setBody(any body, FetchRequest? request);
    6468};
    6569FetchRequest implements FetchBody;
  • trunk/Source/WebCore/Modules/fetch/FetchRequest.js

    r203640 r203641  
    11/*
    2  * Copyright (C) 2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2016 Apple Inc.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 // This interface is recognized as a global object by the bindings generator.
    27 interface TestGlobalObject {
    28     attribute DOMString regularAttribute;
    29     [PrivateIdentifier, PublicIdentifier] attribute DOMString publicAndPrivateAttribute;
    30     [Conditional=TEST_FEATURE, PrivateIdentifier, PublicIdentifier] attribute DOMString publicAndPrivateConditionalAttribute;
    31     [Conditional=TEST_FEATURE, EnabledAtRuntime=TestFeature] attribute DOMString enabledAtRuntimeAttribute;
    32     void regularOperation(DOMString testParam);
    33     [Conditional=TEST_FEATURE, EnabledAtRuntime=TestFeature] void enabledAtRuntimeOperation(DOMString testParam);
    34     [Conditional=TEST_FEATURE, EnabledAtRuntime=TestFeature] void enabledAtRuntimeOperation(long testParam);
    35 };
     26// @conditional=ENABLE(FETCH_API)
     27
     28function initializeFetchRequest(input, init)
     29{
     30    "use strict";
     31
     32    if (init === @undefined)
     33        init = { };
     34    else if (!@isObject(init))
     35        throw new @TypeError("Request init must be an object");
     36
     37    let headers = this.@initializeWith(input, init);
     38    @assert(headers instanceof @Headers);
     39
     40    let inputIsRequest = input instanceof @Request;
     41    if ("headers" in init)
     42        @fillFetchHeaders(headers, init.headers)
     43    else if (inputIsRequest)
     44        @fillFetchHeaders(headers, input.headers)
     45
     46    let hasInitBody = init.body !== @undefined && init.body !== null;
     47    this.@setBody(hasInitBody ? init.body : null, inputIsRequest ? input : null);
     48
     49    return this;
     50}
  • trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp

    r203637 r203641  
    103103}
    104104
    105 void FetchResponse::startFetching(ScriptExecutionContext& context, const FetchRequest& request, FetchPromise&& promise)
     105void FetchResponse::fetch(ScriptExecutionContext& context, FetchRequest& request, FetchPromise&& promise)
    106106{
    107107    auto response = adoptRef(*new FetchResponse(context, FetchBody::loadingBody(), FetchHeaders::create(FetchHeaders::Guard::Immutable), { }));
     
    115115}
    116116
    117 void FetchResponse::fetch(ScriptExecutionContext& context, FetchRequest& input, const Dictionary& dictionary, FetchPromise&& promise)
    118 {
    119     ExceptionCode ec = 0;
    120     RefPtr<FetchRequest> fetchRequest = FetchRequest::create(context, input, dictionary, ec);
    121     if (ec) {
    122         promise.reject(ec);
    123         return;
    124     }
    125     ASSERT(fetchRequest);
    126     startFetching(context, *fetchRequest, WTFMove(promise));
    127 }
    128 
    129117const String& FetchResponse::url() const
    130118{
     
    132120        m_responseURL = m_response.url().serialize(true);
    133121    return m_responseURL;
    134 }
    135 
    136 void FetchResponse::fetch(ScriptExecutionContext& context, const String& url, const Dictionary& dictionary, FetchPromise&& promise)
    137 {
    138     ExceptionCode ec = 0;
    139     RefPtr<FetchRequest> fetchRequest = FetchRequest::create(context, url, dictionary, ec);
    140     if (ec) {
    141         promise.reject(ec);
    142         return;
    143     }
    144     ASSERT(fetchRequest);
    145     startFetching(context, *fetchRequest, WTFMove(promise));
    146122}
    147123
  • trunk/Source/WebCore/Modules/fetch/FetchResponse.h

    r203445 r203641  
    5858
    5959    using FetchPromise = DOMPromise<FetchResponse>;
    60     static void fetch(ScriptExecutionContext&, FetchRequest&, const Dictionary&, FetchPromise&&);
    61     static void fetch(ScriptExecutionContext&, const String&, const Dictionary&, FetchPromise&&);
    62 
     60    static void fetch(ScriptExecutionContext&, FetchRequest&, FetchPromise&&);
    6361
    6462    void setStatus(int, const String&, ExceptionCode&);
  • trunk/Source/WebCore/Modules/fetch/WorkerGlobalScopeFetch.cpp

    r198891 r203641  
    3737namespace WebCore {
    3838
    39 void WorkerGlobalScopeFetch::fetch(WorkerGlobalScope& scope, FetchRequest& input, const Dictionary& dictionary, DeferredWrapper&& promise)
     39void WorkerGlobalScopeFetch::fetch(WorkerGlobalScope& scope, FetchRequest& request, DeferredWrapper&& promise)
    4040{
    4141    if (!scope.scriptExecutionContext())
    4242        return;
    43     FetchResponse::fetch(*scope.scriptExecutionContext(), input, dictionary, WTFMove(promise));
    44 }
    45 
    46 void WorkerGlobalScopeFetch::fetch(WorkerGlobalScope& scope, const String& url, const Dictionary& dictionary, DeferredWrapper&& promise)
    47 {
    48     if (!scope.scriptExecutionContext())
    49         return;
    50     FetchResponse::fetch(*scope.scriptExecutionContext(), url, dictionary, WTFMove(promise));
     43    FetchResponse::fetch(*scope.scriptExecutionContext(), request, WTFMove(promise));
    5144}
    5245
  • trunk/Source/WebCore/Modules/fetch/WorkerGlobalScopeFetch.h

    r198891 r203641  
    2626 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 #ifndef WorkerGlobalScopeFetch_h
    29 #define WorkerGlobalScopeFetch_h
     28
     29#pragma once
    3030
    3131#if ENABLE(FETCH_API)
     
    3838class WorkerGlobalScope;
    3939class DeferredWrapper;
    40 class Dictionary;
    4140class FetchRequest;
    4241
    4342class WorkerGlobalScopeFetch {
    4443public:
    45     static void fetch(WorkerGlobalScope&, FetchRequest&, const Dictionary&, DeferredWrapper&&);
    46     static void fetch(WorkerGlobalScope&, const String&, const Dictionary&, DeferredWrapper&&);
     44    static void fetch(WorkerGlobalScope&, FetchRequest&, DeferredWrapper&&);
    4745};
    4846
     
    5048
    5149#endif // ENABLE(FETCH_API)
    52 
    53 #endif // WorkerGlobalScopeFetch_h
  • trunk/Source/WebCore/Modules/fetch/WorkerGlobalScopeFetch.idl

    r199081 r203641  
    3131    EnabledAtRuntime=FetchAPI,
    3232] partial interface WorkerGlobalScope {
    33     Promise fetch(DOMString input, optional Dictionary init);
    34     Promise fetch(FetchRequest input, optional Dictionary init);
     33    [JSBuiltin] Promise fetch(any input, optional Dictionary init);
     34
     35    [PrivateIdentifier, ImplementedAs=fetch] Promise fetchRequest(FetchRequest request);
    3536};
  • trunk/Source/WebCore/Modules/fetch/WorkerGlobalScopeFetch.js

    r203640 r203641  
    11/*
    2  * Copyright (C) 2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2016 Apple Inc.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 // This interface is recognized as a global object by the bindings generator.
    27 interface TestGlobalObject {
    28     attribute DOMString regularAttribute;
    29     [PrivateIdentifier, PublicIdentifier] attribute DOMString publicAndPrivateAttribute;
    30     [Conditional=TEST_FEATURE, PrivateIdentifier, PublicIdentifier] attribute DOMString publicAndPrivateConditionalAttribute;
    31     [Conditional=TEST_FEATURE, EnabledAtRuntime=TestFeature] attribute DOMString enabledAtRuntimeAttribute;
    32     void regularOperation(DOMString testParam);
    33     [Conditional=TEST_FEATURE, EnabledAtRuntime=TestFeature] void enabledAtRuntimeOperation(DOMString testParam);
    34     [Conditional=TEST_FEATURE, EnabledAtRuntime=TestFeature] void enabledAtRuntimeOperation(long testParam);
    35 };
     26// @conditional=ENABLE(FETCH_API)
     27
     28function fetch(input, init)
     29{
     30    "use strict";
     31
     32    try {
     33        return @fetchRequest(new @Request(input, init));
     34    } catch(e) {
     35        return @Promise.@reject(e);
     36    }
     37}
  • trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h

    r203632 r203641  
    4242    macro(createReadableStreamSource) \
    4343    macro(disturbed) \
     44    macro(fetchRequest) \
    4445    macro(fillFromJS) \
    4546    macro(firstReadCallback) \
     
    6970    macro(retrieveResponse) \
    7071    macro(response) \
     72    macro(setBody) \
    7173    macro(setStatus) \
    7274    macro(state) \
     
    9092    macro(ReadableStreamReader) \
    9193    macro(ReadableStreamController) \
     94    macro(Request) \
    9295    macro(Response) \
    9396    macro(RTCIceCandidate) \
  • trunk/Source/WebCore/bindings/scripts/CodeGenerator.pm

    r203337 r203641  
    560560    my ($object, $param) = @_;
    561561    my $ret = lcfirst($param);
     562    $ret =~ s/dOM/dom/ if $ret =~ /^dOM/;
    562563    $ret =~ s/hTML/html/ if $ret =~ /^hTML/;
    563564    $ret =~ s/uRL/url/ if $ret =~ /^uRL/;
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm

    r203463 r203641  
    24202420            my $jsAttributes = ComputeFunctionSpecial($interface, $function);
    24212421            push(@implContent, "    if (${enable_function}())\n");
    2422             push(@implContent, "        putDirectNativeFunction(vm, this, vm.propertyNames->$functionName, $functionLength, $implementationFunction, NoIntrinsic, attributesForStructure($jsAttributes));\n");
     2422
     2423            my $propertyName = "vm.propertyNames->$functionName";
     2424            if ($function->signature->extendedAttributes->{"PrivateIdentifier"}) {
     2425                $propertyName = "static_cast<JSVMClientData*>(vm.clientData)->builtinNames()." . $functionName . "PrivateName()";
     2426            }
     2427            if (IsJSBuiltin($interface, $function)) {
     2428                push(@implContent, "        putDirectBuiltinFunction(vm, this, $propertyName, $implementationFunction(vm), attributesForStructure($jsAttributes));\n");
     2429            } else {
     2430                push(@implContent, "        putDirectNativeFunction(vm, this, $propertyName, $functionLength, $implementationFunction, NoIntrinsic, attributesForStructure($jsAttributes));\n");
     2431            }
    24232432            push(@implContent, "#endif\n") if $conditionalString;
    24242433        }
    24252434        push(@implContent, "}\n\n");
    24262435    }
    2427    
     2436
    24282437    unless (ShouldUseGlobalObjectPrototype($interface)) {
    24292438        push(@implContent, "JSObject* ${className}::createPrototype(VM& vm, JSGlobalObject* globalObject)\n");
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestGlobalObject.cpp

    r202551 r203641  
    3434#include <wtf/GetPtr.h>
    3535
     36#if ENABLE(TEST_FEATURE)
     37#include "TestGlobalObjectBuiltins.h"
     38#endif
     39
    3640using namespace JSC;
    3741
     
    4347#if ENABLE(TEST_FEATURE)
    4448JSC::EncodedJSValue JSC_HOST_CALL jsTestGlobalObjectInstanceFunctionEnabledAtRuntimeOperation(JSC::ExecState*);
     49#endif
     50#if ENABLE(TEST_FEATURE)
     51JSC::EncodedJSValue JSC_HOST_CALL jsTestGlobalObjectInstanceFunctionTestPrivateFunction(JSC::ExecState*);
    4552#endif
    4653
     
    154161    if (RuntimeEnabledFeatures::sharedFeatures().testFeatureEnabled())
    155162        putDirectNativeFunction(vm, this, vm.propertyNames->enabledAtRuntimeOperation, 1, jsTestGlobalObjectInstanceFunctionEnabledAtRuntimeOperation, NoIntrinsic, attributesForStructure(JSC::Function));
     163#endif
     164#if ENABLE(TEST_FEATURE)
     165    if (RuntimeEnabledFeatures::sharedFeatures().testFeatureEnabled())
     166        putDirectNativeFunction(vm, this, static_cast<JSVMClientData*>(vm.clientData)->builtinNames().testPrivateFunctionPrivateName(), 0, jsTestGlobalObjectInstanceFunctionTestPrivateFunction, NoIntrinsic, attributesForStructure(JSC::Function));
     167#endif
     168#if ENABLE(TEST_FEATURE)
     169    if (RuntimeEnabledFeatures::sharedFeatures().testFeatureEnabled())
     170        putDirectBuiltinFunction(vm, this, vm.propertyNames->testJSBuiltinFunction, testGlobalObjectTestJSBuiltinFunctionCodeGenerator(vm), attributesForStructure(JSC::Builtin));
    156171#endif
    157172}
     
    398413    return throwVMTypeError(state);
    399414}
     415
     416#if ENABLE(TEST_FEATURE)
     417EncodedJSValue JSC_HOST_CALL jsTestGlobalObjectInstanceFunctionTestPrivateFunction(ExecState* state)
     418{
     419    JSValue thisValue = state->thisValue();
     420    auto castedThis = jsDynamicCast<JSTestGlobalObject*>(thisValue);
     421    if (UNLIKELY(!castedThis))
     422        return throwThisTypeError(*state, "TestGlobalObject", "testPrivateFunction");
     423    ASSERT_GC_OBJECT_INHERITS(castedThis, JSTestGlobalObject::info());
     424    auto& impl = castedThis->wrapped();
     425    impl.testPrivateFunction();
     426    return JSValue::encode(jsUndefined());
     427}
     428
     429#endif
    400430
    401431bool JSTestGlobalObjectOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor)
  • trunk/Source/WebCore/bindings/scripts/test/ObjC/DOMTestGlobalObject.mm

    r202551 r203641  
    133133#endif
    134134
     135
     136#if ENABLE(TEST_FEATURE)
     137- (void)testJSBuiltinFunction
     138{
     139    WebCore::JSMainThreadNullState state;
     140    IMPL->testJSBuiltinFunction();
     141}
     142
     143#endif
     144
    135145@end
    136146
  • trunk/Source/WebCore/bindings/scripts/test/TestGlobalObject.idl

    r202551 r203641  
    3333    [Conditional=TEST_FEATURE, EnabledAtRuntime=TestFeature] void enabledAtRuntimeOperation(DOMString testParam);
    3434    [Conditional=TEST_FEATURE, EnabledAtRuntime=TestFeature] void enabledAtRuntimeOperation(long testParam);
     35
     36    [PrivateIdentifier, Conditional=TEST_FEATURE, EnabledAtRuntime=TestFeature] void testPrivateFunction();
     37    [JSBuiltin, Conditional=TEST_FEATURE, EnabledAtRuntime=TestFeature] void testJSBuiltinFunction();
    3538};
Note: See TracChangeset for help on using the changeset viewer.