Changeset 203445 in webkit
- Timestamp:
- Jul 19, 2016 11:23:13 PM (8 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 10 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/CMakeLists.txt
r203396 r203445 3712 3712 set(WebCore_BUILTINS_SOURCES 3713 3713 ${WEBCORE_DIR}/Modules/fetch/FetchHeaders.js 3714 ${WEBCORE_DIR}/Modules/fetch/FetchInternals.js 3714 3715 ${WEBCORE_DIR}/Modules/fetch/FetchResponse.js 3715 3716 ${WEBCORE_DIR}/Modules/mediastream/MediaDevices.js -
trunk/Source/WebCore/ChangeLog
r203444 r203445 1 2016-07-19 Youenn Fablet <youenn@apple.com> 2 3 [Fetch API] Add a JS builtin to implement https://fetch.spec.whatwg.org/#concept-headers-fill 4 https://bugs.webkit.org/show_bug.cgi?id=159932 5 6 Reviewed by Alex Christensen. 7 8 Covered by existing tests. 9 10 Refactoring Headers initializeWith to use the new built-in internal that implements 11 https://fetch.spec.whatwg.org/#concept-headers-fill. 12 13 Refactoring Response constructor to put more checks in the JS builtin fucntion called within constructor. 14 Making use of the new built-in internal that implements https://fetch.spec.whatwg.org/#concept-headers-fill. 15 16 * CMakeLists.txt: Adding FetchHeadersInternals.js 17 * DerivedSources.make: Ditto. 18 * Modules/fetch/FetchHeaders.js: 19 (initializeFetchHeaders): Using fillFetchHeaders new built-in internal. 20 * Modules/fetch/FetchInternals.js: Added. 21 (fillFetchHeaders): 22 * Modules/fetch/FetchResponse.cpp: Refactoring to do more in the JS built-in. Splitting of initializeWith so 23 that the checks are done in the order defined by the spec. 24 (WebCore::FetchResponse::setStatus): 25 (WebCore::FetchResponse::initializeWith): 26 (WebCore::isNullBodyStatus): Deleted. 27 * Modules/fetch/FetchResponse.h: 28 * Modules/fetch/FetchResponse.idl: 29 * Modules/fetch/FetchResponse.js: 30 (initializeFetchResponse): New built-in internal. 31 * WebCore.xcodeproj/project.pbxproj: 32 * bindings/js/WebCoreBuiltinNames.h: 33 1 34 2016-07-19 Chris Dumez <cdumez@apple.com> 2 35 -
trunk/Source/WebCore/DerivedSources.make
r202975 r203445 1285 1285 WebCore_BUILTINS_SOURCES = \ 1286 1286 $(WebCore)/Modules/fetch/FetchHeaders.js \ 1287 $(WebCore)/Modules/fetch/FetchInternals.js \ 1287 1288 $(WebCore)/Modules/fetch/FetchResponse.js \ 1288 1289 $(WebCore)/Modules/mediastream/MediaDevices.js \ -
trunk/Source/WebCore/Modules/fetch/FetchHeaders.js
r203029 r203445 36 36 throw new @TypeError("headersInit must be an object"); 37 37 38 if (headersInit instanceof @Headers) { 39 this.@fillFromJS(headersInit); 40 return this; 41 } 42 43 if (@isArray(headersInit)) { 44 for (let i = 0; i < headersInit.length; i++) { 45 let header = headersInit[i]; 46 if (header.length !== 2) 47 throw new @TypeError("headersInit sequence items should contain two values"); 48 this.@appendFromJS(header[0], header[1]); 49 } 50 return this; 51 } 52 53 let propertyNames = @Object.@getOwnPropertyNames(headersInit); 54 for (let i = 0; i < propertyNames.length; ++i) { 55 let name = propertyNames[i]; 56 this.@appendFromJS(name, headersInit[name]); 57 } 38 @fillFetchHeaders(this, headersInit); 58 39 59 40 return this; -
trunk/Source/WebCore/Modules/fetch/FetchInternals.js
r203444 r203445 1 1 /* 2 * Copyright (C) 2016 CanonInc.2 * Copyright (C) 2016 Apple Inc. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 11 11 * documentation and/or other materials provided with the distribution. 12 12 * 13 * THIS SOFTWARE IS PROVIDED BY CANONINC. ``AS IS'' AND ANY13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 14 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CANONINC. OR16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 17 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, … … 25 25 26 26 // @conditional=ENABLE(FETCH_API) 27 // @internal 27 28 28 function initializeFetchHeaders(headersInit)29 function fillFetchHeaders(headers, headersInit) 29 30 { 30 31 "use strict"; 31 32 32 if (headersInit === @undefined)33 return this;34 35 if (!@isObject(headersInit))36 throw new @TypeError("headersInit must be an object");37 38 33 if (headersInit instanceof @Headers) { 39 this.@fillFromJS(headersInit);40 return this;34 @Headers.prototype.@fillFromJS.@call(headers, headersInit); 35 return; 41 36 } 42 37 … … 46 41 if (header.length !== 2) 47 42 throw new @TypeError("headersInit sequence items should contain two values"); 48 this.@appendFromJS(header[0], header[1]);43 @Headers.prototype.@appendFromJS.@call(headers, header[0], header[1]); 49 44 } 50 45 return this; … … 54 49 for (let i = 0; i < propertyNames.length; ++i) { 55 50 let name = propertyNames[i]; 56 this.@appendFromJS(name, headersInit[name]);51 @Headers.prototype.@appendFromJS.@call(headers, name, headersInit[name]); 57 52 } 58 59 return this;60 53 } -
trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp
r203221 r203445 32 32 #if ENABLE(FETCH_API) 33 33 34 #include "Dictionary.h"35 34 #include "ExceptionCode.h" 36 35 #include "FetchRequest.h" … … 46 45 } 47 46 48 static inline bool isNullBodyStatus(int status)49 {50 return status == 101 || status == 204 || status == 205 || status == 304;51 }52 53 47 Ref<FetchResponse> FetchResponse::error(ScriptExecutionContext& context) 54 48 { … … 76 70 } 77 71 78 void FetchResponse::initializeWith(const Dictionary& init, ExceptionCode& ec) 79 { 80 int status; 81 if (!init.get("status", status)) { 72 void FetchResponse::setStatus(int status, const String& statusText, ExceptionCode& ec) 73 { 74 if (!isValidReasonPhrase(statusText)) { 82 75 ec = TypeError; 83 76 return; 84 77 } 85 if (status < 200 || status > 599) {86 ec = RangeError;87 return;88 }89 90 String statusText;91 if (!init.get("statusText", statusText) || !isValidReasonPhrase(statusText)) {92 ec = TypeError;93 return;94 }95 78 m_response.setHTTPStatusCode(status); 96 79 m_response.setHTTPStatusText(statusText); 97 98 RefPtr<FetchHeaders> initialHeaders; 99 if (init.get("headers", initialHeaders)) 100 m_headers->fill(initialHeaders.get()); 101 102 JSC::JSValue body; 103 if (init.get("body", body)) { 104 if (isNullBodyStatus(status)) { 105 ec = TypeError; 106 return; 107 } 108 m_body = FetchBody::extract(*init.execState(), body); 109 if (m_headers->fastGet(HTTPHeaderName::ContentType).isEmpty() && !m_body.mimeType().isEmpty()) 110 m_headers->fastSet(HTTPHeaderName::ContentType, m_body.mimeType()); 111 } 80 } 81 82 void FetchResponse::initializeWith(JSC::ExecState& execState, JSC::JSValue body) 83 { 84 m_body = FetchBody::extract(execState, body); 85 if (m_headers->fastGet(HTTPHeaderName::ContentType).isEmpty() && !m_body.mimeType().isEmpty()) 86 m_headers->fastSet(HTTPHeaderName::ContentType, m_body.mimeType()); 112 87 } 113 88 -
trunk/Source/WebCore/Modules/fetch/FetchResponse.h
r203221 r203445 37 37 namespace JSC { 38 38 class ArrayBuffer; 39 class ExecState; 40 class JSValue; 39 41 }; 40 42 … … 59 61 static void fetch(ScriptExecutionContext&, const String&, const Dictionary&, FetchPromise&&); 60 62 61 void initializeWith(const Dictionary&, ExceptionCode&); 63 64 void setStatus(int, const String&, ExceptionCode&); 65 void initializeWith(JSC::ExecState&, JSC::JSValue); 62 66 63 67 Type type() const { return m_response.type(); } -
trunk/Source/WebCore/Modules/fetch/FetchResponse.idl
r202275 r203445 55 55 [NewObject, CallWith=ScriptExecutionContext, RaisesException] FetchResponse clone(); 56 56 57 [PrivateIdentifier, RaisesException] void initializeWith(Dictionary parameters); 57 [PrivateIdentifier, RaisesException] void setStatus(unsigned short status, DOMString statusText); 58 [CallWith=ScriptState, PrivateIdentifier] void initializeWith(any body); 58 59 }; 59 60 FetchResponse implements FetchBody; -
trunk/Source/WebCore/Modules/fetch/FetchResponse.js
r203029 r203445 30 30 "use strict"; 31 31 32 let parameters = { }; 33 if (init !== @undefined) { 34 if (!@isObject(init)) 35 throw new @TypeError("Response init must be an object"); 36 parameters.status = init.status; 37 parameters.statusText = init.statusText; 38 if (init.headers) 39 parameters.headers = (init.headers instanceof @Headers) ? init.headers : new @Headers(init.headers); 32 if (init === @undefined) 33 init = { }; 34 else if (!@isObject(init)) 35 throw new @TypeError("Response init must be an object"); 36 37 let status = (init.status !== @undefined) ? @toNumber(init.status) : 200; 38 if (status < 200 || status > 599) 39 throw new @RangeError("Status must be between 200 and 599"); 40 41 let statusText = (init.statusText !== @undefined) ? init.statusText : "OK"; 42 43 this.@setStatus(status, statusText); 44 45 if (init.headers !== @undefined) 46 @fillFetchHeaders(this.headers, init.headers); 47 48 if (body !== @undefined && body !== null) { 49 if (status == 101 || status == 204 || status == 205 || status == 304) 50 throw new @TypeError("Response cannot have a body with the given status"); 51 this.@initializeWith(body); 40 52 } 41 53 42 if (parameters.status === @undefined)43 parameters.status = 200;44 if (parameters.statusText === @undefined)45 parameters.statusText = "OK";46 47 if (body !== @undefined && body !== null)48 parameters.body = body;49 50 this.@initializeWith(parameters);51 54 return this; 52 55 } -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r203423 r203445 1597 1597 4162A4581011464700DFF3ED /* JSDedicatedWorkerGlobalScope.h in Headers */ = {isa = PBXBuildFile; fileRef = 4162A4561011464700DFF3ED /* JSDedicatedWorkerGlobalScope.h */; }; 1598 1598 416E29A6102FA962007FC14E /* WorkerReportingProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 416E29A5102FA962007FC14E /* WorkerReportingProxy.h */; }; 1599 416E6FE81BBD12DF000A6023 /* FetchInternalsBuiltins.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B03D8061BB3110D00B764B9 /* FetchInternalsBuiltins.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1599 1600 416E6FE81BBD12DF000A6033 /* StreamInternalsBuiltins.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B03D8061BB3110D00B764C9 /* StreamInternalsBuiltins.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1600 1601 416E6FE81BBD12DF000A6043 /* ReadableStreamInternalsBuiltins.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B03D8061BB3110D00B764D9 /* ReadableStreamInternalsBuiltins.h */; settings = {ATTRIBUTES = (Private, ); }; }; … … 11816 11817 9908B0FA1BCAD07D00ED0F65 /* ReadableStreamControllerBuiltins.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ReadableStreamControllerBuiltins.cpp; sourceTree = "<group>"; }; 11817 11818 9908B0FB1BCAD07D00ED0F65 /* ReadableStreamControllerBuiltins.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReadableStreamControllerBuiltins.h; sourceTree = "<group>"; }; 11819 9908B0FD1BCAD07D00ED0F45 /* FetchInternalsBuiltins.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FetchInternalsBuiltins.cpp; sourceTree = "<group>"; }; 11818 11820 9908B0FD1BCAD07D00ED0F55 /* StreamInternalsBuiltins.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StreamInternalsBuiltins.cpp; sourceTree = "<group>"; }; 11819 11821 9908B0FD1BCAD07D00ED0F65 /* ReadableStreamInternalsBuiltins.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ReadableStreamInternalsBuiltins.cpp; sourceTree = "<group>"; }; … … 11858 11860 9AB1F37E18E2489A00534743 /* CSSToLengthConversionData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSToLengthConversionData.h; sourceTree = "<group>"; }; 11859 11861 9AB1F37F18E2489A00534743 /* CSSToLengthConversionData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSToLengthConversionData.cpp; sourceTree = "<group>"; }; 11862 9B03D8061BB3110D00B764B9 /* FetchInternalsBuiltins.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FetchInternalsBuiltins.h; sourceTree = "<group>"; }; 11860 11863 9B03D8061BB3110D00B764C9 /* StreamInternalsBuiltins.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StreamInternalsBuiltins.h; sourceTree = "<group>"; }; 11861 11864 9B03D8061BB3110D00B764D8 /* ReadableStreamBuiltins.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReadableStreamBuiltins.h; sourceTree = "<group>"; }; … … 17920 17923 9908B0FA1BCAD07D00ED0F65 /* ReadableStreamControllerBuiltins.cpp */, 17921 17924 9908B0FB1BCAD07D00ED0F65 /* ReadableStreamControllerBuiltins.h */, 17925 9908B0FD1BCAD07D00ED0F45 /* FetchInternalsBuiltins.cpp */, 17922 17926 9908B0FD1BCAD07D00ED0F65 /* ReadableStreamInternalsBuiltins.cpp */, 17927 9B03D8061BB3110D00B764B9 /* FetchInternalsBuiltins.h */, 17923 17928 9B03D8061BB3110D00B764D9 /* ReadableStreamInternalsBuiltins.h */, 17924 17929 9908B0FE1BCAD07D00ED0F65 /* ReadableStreamReaderBuiltins.cpp */, … … 27854 27859 A84D827C11D333ED00972990 /* RawDataDocumentParser.h in Headers */, 27855 27860 416E6FE91BBD12E5000A6043 /* ReadableStreamBuiltins.h in Headers */, 27861 416E6FE81BBD12DF000A6023 /* FetchInternalsBuiltins.h in Headers */, 27856 27862 416E6FE81BBD12DF000A6043 /* ReadableStreamInternalsBuiltins.h in Headers */, 27857 27863 FD31603C12B0267600C1A359 /* RealtimeAnalyser.h in Headers */, -
trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h
r203162 r203445 63 63 macro(readyPromiseCapability) \ 64 64 macro(removeTrack) \ 65 macro(setStatus) \ 65 66 macro(state) \ 66 67 macro(started) \
Note: See TracChangeset
for help on using the changeset viewer.