Diff
Modified: trunk/Source/WebCore/CMakeLists.txt (203444 => 203445)
--- trunk/Source/WebCore/CMakeLists.txt 2016-07-20 05:13:06 UTC (rev 203444)
+++ trunk/Source/WebCore/CMakeLists.txt 2016-07-20 06:23:13 UTC (rev 203445)
@@ -3711,6 +3711,7 @@
set(WebCore_BUILTINS_SOURCES
${WEBCORE_DIR}/Modules/fetch/FetchHeaders.js
+ ${WEBCORE_DIR}/Modules/fetch/FetchInternals.js
${WEBCORE_DIR}/Modules/fetch/FetchResponse.js
${WEBCORE_DIR}/Modules/mediastream/MediaDevices.js
${WEBCORE_DIR}/Modules/mediastream/NavigatorUserMedia.js
Modified: trunk/Source/WebCore/ChangeLog (203444 => 203445)
--- trunk/Source/WebCore/ChangeLog 2016-07-20 05:13:06 UTC (rev 203444)
+++ trunk/Source/WebCore/ChangeLog 2016-07-20 06:23:13 UTC (rev 203445)
@@ -1,3 +1,36 @@
+2016-07-19 Youenn Fablet <you...@apple.com>
+
+ [Fetch API] Add a JS builtin to implement https://fetch.spec.whatwg.org/#concept-headers-fill
+ https://bugs.webkit.org/show_bug.cgi?id=159932
+
+ Reviewed by Alex Christensen.
+
+ Covered by existing tests.
+
+ Refactoring Headers initializeWith to use the new built-in internal that implements
+ https://fetch.spec.whatwg.org/#concept-headers-fill.
+
+ Refactoring Response constructor to put more checks in the JS builtin fucntion called within constructor.
+ Making use of the new built-in internal that implements https://fetch.spec.whatwg.org/#concept-headers-fill.
+
+ * CMakeLists.txt: Adding FetchHeadersInternals.js
+ * DerivedSources.make: Ditto.
+ * Modules/fetch/FetchHeaders.js:
+ (initializeFetchHeaders): Using fillFetchHeaders new built-in internal.
+ * Modules/fetch/FetchInternals.js: Added.
+ (fillFetchHeaders):
+ * Modules/fetch/FetchResponse.cpp: Refactoring to do more in the JS built-in. Splitting of initializeWith so
+ that the checks are done in the order defined by the spec.
+ (WebCore::FetchResponse::setStatus):
+ (WebCore::FetchResponse::initializeWith):
+ (WebCore::isNullBodyStatus): Deleted.
+ * Modules/fetch/FetchResponse.h:
+ * Modules/fetch/FetchResponse.idl:
+ * Modules/fetch/FetchResponse.js:
+ (initializeFetchResponse): New built-in internal.
+ * WebCore.xcodeproj/project.pbxproj:
+ * bindings/js/WebCoreBuiltinNames.h:
+
2016-07-19 Chris Dumez <cdu...@apple.com>
Fix null handling of SVGScriptElement.type attribute
Modified: trunk/Source/WebCore/DerivedSources.make (203444 => 203445)
--- trunk/Source/WebCore/DerivedSources.make 2016-07-20 05:13:06 UTC (rev 203444)
+++ trunk/Source/WebCore/DerivedSources.make 2016-07-20 06:23:13 UTC (rev 203445)
@@ -1284,6 +1284,7 @@
WebCore_BUILTINS_SOURCES = \
$(WebCore)/Modules/fetch/FetchHeaders.js \
+ $(WebCore)/Modules/fetch/FetchInternals.js \
$(WebCore)/Modules/fetch/FetchResponse.js \
$(WebCore)/Modules/mediastream/MediaDevices.js \
$(WebCore)/Modules/mediastream/NavigatorUserMedia.js \
Modified: trunk/Source/WebCore/Modules/fetch/FetchHeaders.js (203444 => 203445)
--- trunk/Source/WebCore/Modules/fetch/FetchHeaders.js 2016-07-20 05:13:06 UTC (rev 203444)
+++ trunk/Source/WebCore/Modules/fetch/FetchHeaders.js 2016-07-20 06:23:13 UTC (rev 203445)
@@ -35,26 +35,7 @@
if (!@isObject(headersInit))
throw new @TypeError("headersInit must be an object");
- if (headersInit instanceof @Headers) {
- this.@fillFromJS(headersInit);
- return this;
- }
+ @fillFetchHeaders(this, headersInit);
- if (@isArray(headersInit)) {
- for (let i = 0; i < headersInit.length; i++) {
- let header = headersInit[i];
- if (header.length !== 2)
- throw new @TypeError("headersInit sequence items should contain two values");
- this.@appendFromJS(header[0], header[1]);
- }
- return this;
- }
-
- let propertyNames = @Object.@getOwnPropertyNames(headersInit);
- for (let i = 0; i < propertyNames.length; ++i) {
- let name = propertyNames[i];
- this.@appendFromJS(name, headersInit[name]);
- }
-
return this;
}
Copied: trunk/Source/WebCore/Modules/fetch/FetchInternals.js (from rev 203444, trunk/Source/WebCore/Modules/fetch/FetchHeaders.js) (0 => 203445)
--- trunk/Source/WebCore/Modules/fetch/FetchInternals.js (rev 0)
+++ trunk/Source/WebCore/Modules/fetch/FetchInternals.js 2016-07-20 06:23:13 UTC (rev 203445)
@@ -0,0 +1,53 @@
+/*
+ * 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.
+ */
+
+// @conditional=ENABLE(FETCH_API)
+// @internal
+
+function fillFetchHeaders(headers, headersInit)
+{
+ "use strict";
+
+ if (headersInit instanceof @Headers) {
+ @Headers.prototype.@fillFromJS.@call(headers, headersInit);
+ return;
+ }
+
+ if (@isArray(headersInit)) {
+ for (let i = 0; i < headersInit.length; i++) {
+ let header = headersInit[i];
+ if (header.length !== 2)
+ throw new @TypeError("headersInit sequence items should contain two values");
+ @Headers.prototype.@appendFromJS.@call(headers, header[0], header[1]);
+ }
+ return this;
+ }
+
+ let propertyNames = @Object.@getOwnPropertyNames(headersInit);
+ for (let i = 0; i < propertyNames.length; ++i) {
+ let name = propertyNames[i];
+ @Headers.prototype.@appendFromJS.@call(headers, name, headersInit[name]);
+ }
+}
Modified: trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp (203444 => 203445)
--- trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp 2016-07-20 05:13:06 UTC (rev 203444)
+++ trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp 2016-07-20 06:23:13 UTC (rev 203445)
@@ -31,7 +31,6 @@
#if ENABLE(FETCH_API)
-#include "Dictionary.h"
#include "ExceptionCode.h"
#include "FetchRequest.h"
#include "HTTPParsers.h"
@@ -45,11 +44,6 @@
return status == 301 || status == 302 || status == 303 || status == 307 || status == 308;
}
-static inline bool isNullBodyStatus(int status)
-{
- return status == 101 || status == 204 || status == 205 || status == 304;
-}
-
Ref<FetchResponse> FetchResponse::error(ScriptExecutionContext& context)
{
auto response = adoptRef(*new FetchResponse(context, { }, FetchHeaders::create(FetchHeaders::Guard::Immutable), { }));
@@ -75,40 +69,21 @@
return WTFMove(redirectResponse);
}
-void FetchResponse::initializeWith(const Dictionary& init, ExceptionCode& ec)
+void FetchResponse::setStatus(int status, const String& statusText, ExceptionCode& ec)
{
- int status;
- if (!init.get("status", status)) {
+ if (!isValidReasonPhrase(statusText)) {
ec = TypeError;
return;
}
- if (status < 200 || status > 599) {
- ec = RangeError;
- return;
- }
-
- String statusText;
- if (!init.get("statusText", statusText) || !isValidReasonPhrase(statusText)) {
- ec = TypeError;
- return;
- }
m_response.setHTTPStatusCode(status);
m_response.setHTTPStatusText(statusText);
+}
- RefPtr<FetchHeaders> initialHeaders;
- if (init.get("headers", initialHeaders))
- m_headers->fill(initialHeaders.get());
-
- JSC::JSValue body;
- if (init.get("body", body)) {
- if (isNullBodyStatus(status)) {
- ec = TypeError;
- return;
- }
- m_body = FetchBody::extract(*init.execState(), body);
- if (m_headers->fastGet(HTTPHeaderName::ContentType).isEmpty() && !m_body.mimeType().isEmpty())
- m_headers->fastSet(HTTPHeaderName::ContentType, m_body.mimeType());
- }
+void FetchResponse::initializeWith(JSC::ExecState& execState, JSC::JSValue body)
+{
+ m_body = FetchBody::extract(execState, body);
+ if (m_headers->fastGet(HTTPHeaderName::ContentType).isEmpty() && !m_body.mimeType().isEmpty())
+ m_headers->fastSet(HTTPHeaderName::ContentType, m_body.mimeType());
}
FetchResponse::FetchResponse(ScriptExecutionContext& context, FetchBody&& body, Ref<FetchHeaders>&& headers, ResourceResponse&& response)
Modified: trunk/Source/WebCore/Modules/fetch/FetchResponse.h (203444 => 203445)
--- trunk/Source/WebCore/Modules/fetch/FetchResponse.h 2016-07-20 05:13:06 UTC (rev 203444)
+++ trunk/Source/WebCore/Modules/fetch/FetchResponse.h 2016-07-20 06:23:13 UTC (rev 203445)
@@ -36,6 +36,8 @@
namespace JSC {
class ArrayBuffer;
+class ExecState;
+class JSValue;
};
namespace WebCore {
@@ -58,8 +60,10 @@
static void fetch(ScriptExecutionContext&, FetchRequest&, const Dictionary&, FetchPromise&&);
static void fetch(ScriptExecutionContext&, const String&, const Dictionary&, FetchPromise&&);
- void initializeWith(const Dictionary&, ExceptionCode&);
+ void setStatus(int, const String&, ExceptionCode&);
+ void initializeWith(JSC::ExecState&, JSC::JSValue);
+
Type type() const { return m_response.type(); }
const String& url() const;
bool redirected() const { return m_response.isRedirected(); }
Modified: trunk/Source/WebCore/Modules/fetch/FetchResponse.idl (203444 => 203445)
--- trunk/Source/WebCore/Modules/fetch/FetchResponse.idl 2016-07-20 05:13:06 UTC (rev 203444)
+++ trunk/Source/WebCore/Modules/fetch/FetchResponse.idl 2016-07-20 06:23:13 UTC (rev 203445)
@@ -54,6 +54,7 @@
[NewObject, CallWith=ScriptExecutionContext, RaisesException] FetchResponse clone();
- [PrivateIdentifier, RaisesException] void initializeWith(Dictionary parameters);
+ [PrivateIdentifier, RaisesException] void setStatus(unsigned short status, DOMString statusText);
+ [CallWith=ScriptState, PrivateIdentifier] void initializeWith(any body);
};
FetchResponse implements FetchBody;
Modified: trunk/Source/WebCore/Modules/fetch/FetchResponse.js (203444 => 203445)
--- trunk/Source/WebCore/Modules/fetch/FetchResponse.js 2016-07-20 05:13:06 UTC (rev 203444)
+++ trunk/Source/WebCore/Modules/fetch/FetchResponse.js 2016-07-20 06:23:13 UTC (rev 203445)
@@ -29,24 +29,27 @@
{
"use strict";
- let parameters = { };
- if (init !== @undefined) {
- if (!@isObject(init))
- throw new @TypeError("Response init must be an object");
- parameters.status = init.status;
- parameters.statusText = init.statusText;
- if (init.headers)
- parameters.headers = (init.headers instanceof @Headers) ? init.headers : new @Headers(init.headers);
- }
+ if (init === @undefined)
+ init = { };
+ else if (!@isObject(init))
+ throw new @TypeError("Response init must be an object");
- if (parameters.status === @undefined)
- parameters.status = 200;
- if (parameters.statusText === @undefined)
- parameters.statusText = "OK";
+ let status = (init.status !== @undefined) ? @toNumber(init.status) : 200;
+ if (status < 200 || status > 599)
+ throw new @RangeError("Status must be between 200 and 599");
- if (body !== @undefined && body !== null)
- parameters.body = body;
+ let statusText = (init.statusText !== @undefined) ? init.statusText : "OK";
- this.@initializeWith(parameters);
+ this.@setStatus(status, statusText);
+
+ if (init.headers !== @undefined)
+ @fillFetchHeaders(this.headers, init.headers);
+
+ if (body !== @undefined && body !== null) {
+ if (status == 101 || status == 204 || status == 205 || status == 304)
+ throw new @TypeError("Response cannot have a body with the given status");
+ this.@initializeWith(body);
+ }
+
return this;
}
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (203444 => 203445)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2016-07-20 05:13:06 UTC (rev 203444)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2016-07-20 06:23:13 UTC (rev 203445)
@@ -1596,6 +1596,7 @@
4162A4571011464700DFF3ED /* JSDedicatedWorkerGlobalScope.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4162A4551011464700DFF3ED /* JSDedicatedWorkerGlobalScope.cpp */; };
4162A4581011464700DFF3ED /* JSDedicatedWorkerGlobalScope.h in Headers */ = {isa = PBXBuildFile; fileRef = 4162A4561011464700DFF3ED /* JSDedicatedWorkerGlobalScope.h */; };
416E29A6102FA962007FC14E /* WorkerReportingProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 416E29A5102FA962007FC14E /* WorkerReportingProxy.h */; };
+ 416E6FE81BBD12DF000A6023 /* FetchInternalsBuiltins.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B03D8061BB3110D00B764B9 /* FetchInternalsBuiltins.h */; settings = {ATTRIBUTES = (Private, ); }; };
416E6FE81BBD12DF000A6033 /* StreamInternalsBuiltins.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B03D8061BB3110D00B764C9 /* StreamInternalsBuiltins.h */; settings = {ATTRIBUTES = (Private, ); }; };
416E6FE81BBD12DF000A6043 /* ReadableStreamInternalsBuiltins.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B03D8061BB3110D00B764D9 /* ReadableStreamInternalsBuiltins.h */; settings = {ATTRIBUTES = (Private, ); }; };
416E6FE81BBD12DF000A6053 /* WritableStreamInternalsBuiltins.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B03D8061BB3110D00B764E9 /* WritableStreamInternalsBuiltins.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -11815,6 +11816,7 @@
9908B0F91BCAD07D00ED0F75 /* WritableStreamBuiltins.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WritableStreamBuiltins.cpp; sourceTree = "<group>"; };
9908B0FA1BCAD07D00ED0F65 /* ReadableStreamControllerBuiltins.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ReadableStreamControllerBuiltins.cpp; sourceTree = "<group>"; };
9908B0FB1BCAD07D00ED0F65 /* ReadableStreamControllerBuiltins.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReadableStreamControllerBuiltins.h; sourceTree = "<group>"; };
+ 9908B0FD1BCAD07D00ED0F45 /* FetchInternalsBuiltins.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FetchInternalsBuiltins.cpp; sourceTree = "<group>"; };
9908B0FD1BCAD07D00ED0F55 /* StreamInternalsBuiltins.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StreamInternalsBuiltins.cpp; sourceTree = "<group>"; };
9908B0FD1BCAD07D00ED0F65 /* ReadableStreamInternalsBuiltins.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ReadableStreamInternalsBuiltins.cpp; sourceTree = "<group>"; };
9908B0FD1BCAD07D00ED0F75 /* WritableStreamInternalsBuiltins.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WritableStreamInternalsBuiltins.cpp; sourceTree = "<group>"; };
@@ -11857,6 +11859,7 @@
9A528E8217D7F52F00AA9518 /* FloatingObjects.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FloatingObjects.h; sourceTree = "<group>"; };
9AB1F37E18E2489A00534743 /* CSSToLengthConversionData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSToLengthConversionData.h; sourceTree = "<group>"; };
9AB1F37F18E2489A00534743 /* CSSToLengthConversionData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSToLengthConversionData.cpp; sourceTree = "<group>"; };
+ 9B03D8061BB3110D00B764B9 /* FetchInternalsBuiltins.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FetchInternalsBuiltins.h; sourceTree = "<group>"; };
9B03D8061BB3110D00B764C9 /* StreamInternalsBuiltins.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StreamInternalsBuiltins.h; sourceTree = "<group>"; };
9B03D8061BB3110D00B764D8 /* ReadableStreamBuiltins.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReadableStreamBuiltins.h; sourceTree = "<group>"; };
9B03D8061BB3110D00B764D9 /* ReadableStreamInternalsBuiltins.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReadableStreamInternalsBuiltins.h; sourceTree = "<group>"; };
@@ -17919,7 +17922,9 @@
9B03D8061BB3110D00B764D8 /* ReadableStreamBuiltins.h */,
9908B0FA1BCAD07D00ED0F65 /* ReadableStreamControllerBuiltins.cpp */,
9908B0FB1BCAD07D00ED0F65 /* ReadableStreamControllerBuiltins.h */,
+ 9908B0FD1BCAD07D00ED0F45 /* FetchInternalsBuiltins.cpp */,
9908B0FD1BCAD07D00ED0F65 /* ReadableStreamInternalsBuiltins.cpp */,
+ 9B03D8061BB3110D00B764B9 /* FetchInternalsBuiltins.h */,
9B03D8061BB3110D00B764D9 /* ReadableStreamInternalsBuiltins.h */,
9908B0FE1BCAD07D00ED0F65 /* ReadableStreamReaderBuiltins.cpp */,
9908B0FF1BCAD07D00ED0F65 /* ReadableStreamReaderBuiltins.h */,
@@ -27853,6 +27858,7 @@
6E84E9E117668BF100815B68 /* RasterShape.h in Headers */,
A84D827C11D333ED00972990 /* RawDataDocumentParser.h in Headers */,
416E6FE91BBD12E5000A6043 /* ReadableStreamBuiltins.h in Headers */,
+ 416E6FE81BBD12DF000A6023 /* FetchInternalsBuiltins.h in Headers */,
416E6FE81BBD12DF000A6043 /* ReadableStreamInternalsBuiltins.h in Headers */,
FD31603C12B0267600C1A359 /* RealtimeAnalyser.h in Headers */,
4A4F65711AA997F100E38CDD /* RealtimeMediaSource.h in Headers */,
Modified: trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h (203444 => 203445)
--- trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h 2016-07-20 05:13:06 UTC (rev 203444)
+++ trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h 2016-07-20 06:23:13 UTC (rev 203445)
@@ -62,6 +62,7 @@
macro(readRequests) \
macro(readyPromiseCapability) \
macro(removeTrack) \
+ macro(setStatus) \
macro(state) \
macro(started) \
macro(startedPromise) \