Changeset 203632 in webkit


Ignore:
Timestamp:
Jul 22, 2016 11:01:15 PM (8 years ago)
Author:
commit-queue@webkit.org
Message:

Use a private property to implement FetchResponse.body getter
https://bugs.webkit.org/show_bug.cgi?id=159808

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

Covered by existing test sets.

Previously, body was handled as a CachedAttribute.
Using a private property will allow direct use of this property from JS built-ins which will allow easier
handling of ReadableStream cloning in Response.clone.
Also, this allows removing some binding custom code.

Updated redirect and error static methods to take NewObject keyword, as this removes a search into cached wrappers.
Ditto for createReadableStreamSource.

  • CMakeLists.txt: Removing JSFetchResponseCustom.cpp.
  • Modules/fetch/FetchResponse.idl: Adding createReadableStreamSource and isDisturbed private functions.

Making body getter a JSBuiltin.

  • Modules/fetch/FetchResponse.js:

(body): Adding getter which will call createReadableStreamSource if needed.

  • WebCore.xcodeproj/project.pbxproj: Removing JSFetchResponseCustom.cpp.
  • bindings/js/JSFetchResponseCustom.cpp: Removed.
  • bindings/js/ReadableStreamController.cpp:

(WebCore::createReadableStream): Deleted.
(WebCore::getReadableStreamReader): Deleted.

  • bindings/js/ReadableStreamController.h: Removing unneeded ReadableStream helper routine now that they can be

handled within JS built-in code.

  • bindings/js/WebCoreBuiltinNames.h: Adding @createReadableStreamSource, @isDisturbed and @Response identifiers.
Location:
trunk/Source/WebCore
Files:
1 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/CMakeLists.txt

    r203554 r203632  
    11491149    bindings/js/JSEventTargetCustom.cpp
    11501150    bindings/js/JSExceptionBase.cpp
    1151     bindings/js/JSFetchResponseCustom.cpp
    11521151    bindings/js/JSFileCustom.cpp
    11531152    bindings/js/JSFileReaderCustom.cpp
  • trunk/Source/WebCore/ChangeLog

    r203631 r203632  
     12016-07-22  Youenn Fablet  <youenn@apple.com>
     2
     3        Use a private property to implement FetchResponse.body getter
     4        https://bugs.webkit.org/show_bug.cgi?id=159808
     5
     6        Reviewed by Sam Weinig.
     7
     8        Covered by existing test sets.
     9
     10        Previously, body was handled as a CachedAttribute.
     11        Using a private property will allow direct use of this property from JS built-ins which will allow easier
     12        handling of ReadableStream cloning in Response.clone.
     13        Also, this allows removing some binding custom code.
     14
     15        Updated redirect and error static methods to take NewObject keyword, as this removes a search into cached wrappers.
     16        Ditto for createReadableStreamSource.
     17
     18        * CMakeLists.txt: Removing JSFetchResponseCustom.cpp.
     19        * Modules/fetch/FetchResponse.idl: Adding createReadableStreamSource and isDisturbed private functions.
     20        Making body getter a JSBuiltin.
     21        * Modules/fetch/FetchResponse.js:
     22        (body): Adding getter which will call createReadableStreamSource if needed.
     23        * WebCore.xcodeproj/project.pbxproj: Removing JSFetchResponseCustom.cpp.
     24        * bindings/js/JSFetchResponseCustom.cpp: Removed.
     25        * bindings/js/ReadableStreamController.cpp:
     26        (WebCore::createReadableStream): Deleted.
     27        (WebCore::getReadableStreamReader): Deleted.
     28        * bindings/js/ReadableStreamController.h: Removing unneeded ReadableStream helper routine now that they can be
     29        handled within JS built-in code.
     30        * bindings/js/WebCoreBuiltinNames.h: Adding @createReadableStreamSource, @isDisturbed  and @Response identifiers.
     31
    1322016-07-22  Zalan Bujtas  <zalan@apple.com>
    233
  • trunk/Source/WebCore/Modules/fetch/FetchResponse.idl

    r203445 r203632  
    3535    Exposed=(Window,Worker),
    3636    InterfaceName=Response,
    37     JSBuiltinConstructor
     37    JSBuiltinConstructor,
     38    PrivateIdentifier,
     39    PublicIdentifier
    3840]
    3941interface FetchResponse {
    40     // FIXME: NewObject does not seem to be supported for static methods.
    41     [CallWith=ScriptExecutionContext] static FetchResponse error();
    42     [CallWith=ScriptExecutionContext, RaisesException] static FetchResponse redirect(DOMString url, optional unsigned short status = 302);
     42    [NewObject, CallWith=ScriptExecutionContext] static FetchResponse error();
     43    [NewObject, CallWith=ScriptExecutionContext, RaisesException] static FetchResponse redirect(DOMString url, optional unsigned short status = 302);
    4344
    4445    readonly attribute ResponseType type;
     
    5152    // FIXME: Add support for SameObject keyword for headers
    5253    readonly attribute FetchHeaders headers;
    53     [Custom, CachedAttribute] readonly attribute ReadableStream? body;
     54    [JSBuiltin] readonly attribute ReadableStream? body;
    5455
    5556    [NewObject, CallWith=ScriptExecutionContext, RaisesException] FetchResponse clone();
     
    5758    [PrivateIdentifier, RaisesException] void setStatus(unsigned short status, DOMString statusText);
    5859    [CallWith=ScriptState, PrivateIdentifier] void initializeWith(any body);
     60    [PrivateIdentifier, NewObject] ReadableStreamSource createReadableStreamSource();
     61    [PrivateIdentifier] boolean isDisturbed();
    5962};
    6063FetchResponse implements FetchBody;
  • trunk/Source/WebCore/Modules/fetch/FetchResponse.js

    r203445 r203632  
    5454    return this;
    5555}
     56
     57function body()
     58{
     59    if (!this.@body) {
     60        if (@Response.prototype.@isDisturbed.@call(this)) {
     61            this.@body = new @ReadableStream();
     62            // Get reader to lock it.
     63            new @ReadableStreamReader(this.@body);
     64        } else {
     65            var source = @Response.prototype.@createReadableStreamSource.@call(this);
     66            this.@body = source ? new @ReadableStream(source) : null;
     67        }
     68    }
     69    return this.@body;
     70}
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r203553 r203632  
    16181618                418C39601C8F0AAE0051C8A3 /* JSReadableStreamSourceCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 418C395D1C8F0AAB0051C8A3 /* JSReadableStreamSourceCustom.cpp */; };
    16191619                418C39611C8F0AB10051C8A3 /* ReadableStreamController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 418C395E1C8F0AAB0051C8A3 /* ReadableStreamController.cpp */; };
    1620                 418C39631C8F129B0051C8A3 /* JSFetchResponseCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 418C39621C8F12970051C8A3 /* JSFetchResponseCustom.cpp */; };
    16211620                418F88040FF957AE0080F045 /* JSAbstractWorker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 418F88020FF957AE0080F045 /* JSAbstractWorker.cpp */; };
    16221621                418F88050FF957AF0080F045 /* JSAbstractWorker.h in Headers */ = {isa = PBXBuildFile; fileRef = 418F88030FF957AE0080F045 /* JSAbstractWorker.h */; };
     
    91999198                418C395E1C8F0AAB0051C8A3 /* ReadableStreamController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ReadableStreamController.cpp; sourceTree = "<group>"; };
    92009199                418C395F1C8F0AAB0051C8A3 /* ReadableStreamController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReadableStreamController.h; sourceTree = "<group>"; };
    9201                 418C39621C8F12970051C8A3 /* JSFetchResponseCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSFetchResponseCustom.cpp; sourceTree = "<group>"; };
    92029200                418F88020FF957AE0080F045 /* JSAbstractWorker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSAbstractWorker.cpp; sourceTree = "<group>"; };
    92039201                418F88030FF957AE0080F045 /* JSAbstractWorker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSAbstractWorker.h; sourceTree = "<group>"; };
     
    2256322561                                3314ACE910892086000F0E56 /* JSExceptionBase.cpp */,
    2256422562                                3314ACEA10892086000F0E56 /* JSExceptionBase.h */,
    22565                                 418C39621C8F12970051C8A3 /* JSFetchResponseCustom.cpp */,
    2256622563                                8F934D841189F1EE00508D5D /* JSMainThreadExecState.cpp */,
    2256722564                                8F934D831189F1EE00508D5D /* JSMainThreadExecState.h */,
     
    3065130648                                7E4C96DC1AD4483500365A50 /* JSFetchRequest.cpp in Sources */,
    3065230649                                8E4C96DC1AD4483500365A50 /* JSFetchResponse.cpp in Sources */,
    30653                                 418C39631C8F129B0051C8A3 /* JSFetchResponseCustom.cpp in Sources */,
    3065430650                                BC00F0140E0A189500FD04E3 /* JSFile.cpp in Sources */,
    3065530651                                516E54FA1CCB2EA80040D954 /* JSFileCustom.cpp in Sources */,
  • trunk/Source/WebCore/bindings/js/ReadableStreamController.cpp

    r202890 r203632  
    8585}
    8686
    87 JSC::JSValue createReadableStream(JSC::ExecState& state, JSDOMGlobalObject* globalObject, ReadableStreamSource* source)
    88 {
    89     JSC::JSLockHolder lock(&state);
    90 
    91     auto jsSource = source ? toJS(&state, globalObject, *source) : JSC::jsUndefined();
    92     JSC::Strong<JSC::Unknown> protect(state.vm(), jsSource);
    93 
    94     JSC::MarkedArgumentBuffer arguments;
    95     arguments.append(jsSource);
    96 
    97     auto constructor = JSReadableStream::getConstructor(state.vm(), globalObject);
    98 
    99     JSC::ConstructData constructData;
    100     auto constructType = JSC::getConstructData(constructor, constructData);
    101     ASSERT(constructType != JSC::ConstructType::None);
    102 
    103     return construct(&state, constructor, constructType, constructData, arguments);
    104 }
    105 
    106 JSC::JSValue getReadableStreamReader(JSC::ExecState& state, JSC::JSValue readableStream)
    107 {
    108     ASSERT(readableStream.isObject());
    109 
    110     auto getReader = readableStream.getObject()->get(&state, JSC::Identifier::fromString(&state, "getReader"));
    111     ASSERT(!state.hadException());
    112 
    113     auto reader = callFunction(state, getReader, readableStream, JSC::MarkedArgumentBuffer());
    114     ASSERT(!state.hadException());
    115 
    116     return reader;
    117 }
    118 
    11987} // namespace WebCore
    12088
  • trunk/Source/WebCore/bindings/js/ReadableStreamController.h

    r200235 r203632  
    6767};
    6868
    69 JSC::JSValue createReadableStream(JSC::ExecState&, JSDOMGlobalObject*, ReadableStreamSource*);
    70 JSC::JSValue getReadableStreamReader(JSC::ExecState&, JSC::JSValue);
    71 
    7269inline JSDOMGlobalObject* ReadableStreamController::globalObject() const
    7370{
  • trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h

    r203494 r203632  
    3535    macro(addTrack) \
    3636    macro(appendFromJS) \
     37    macro(body) \
    3738    macro(closeRequested) \
    3839    macro(closedPromiseCapability) \
    3940    macro(controlledReadableStream) \
    4041    macro(controller) \
     42    macro(createReadableStreamSource) \
    4143    macro(disturbed) \
    4244    macro(fillFromJS) \
     
    4749    macro(getTracks) \
    4850    macro(initializeWith) \
     51    macro(isDisturbed) \
    4952    macro(localStreams) \
    5053    macro(operations) \
     
    8790    macro(ReadableStreamReader) \
    8891    macro(ReadableStreamController) \
     92    macro(Response) \
    8993    macro(RTCIceCandidate) \
    9094    macro(RTCSessionDescription) \
Note: See TracChangeset for help on using the changeset viewer.