Diff
Modified: trunk/LayoutTests/ChangeLog (223561 => 223562)
--- trunk/LayoutTests/ChangeLog 2017-10-17 18:39:47 UTC (rev 223561)
+++ trunk/LayoutTests/ChangeLog 2017-10-17 18:39:48 UTC (rev 223562)
@@ -1,5 +1,22 @@
2017-10-17 Youenn Fablet <you...@apple.com>
+ Add preliminary support for fetch event
+ https://bugs.webkit.org/show_bug.cgi?id=178171
+
+ Reviewed by Chris Dumez.
+
+ Skipping new tests for WK1 and GTK that do not have SW.
+
+ * http/wpt/service-workers/extendableEvent.https-expected.txt: Added.
+ * http/wpt/service-workers/extendableEvent.https.html: Added.
+ * http/wpt/service-workers/fetchEvent.https-expected.txt: Added.
+ * http/wpt/service-workers/fetchEvent.https.html: Added.
+ * platform/gtk/TestExpectations:
+ * platform/ios-wk1/TestExpectations:
+ * platform/mac-wk1/TestExpectations:
+
+2017-10-17 Youenn Fablet <you...@apple.com>
+
Cache API implementation should be able to compute storage size for WebKit client applications.
https://bugs.webkit.org/show_bug.cgi?id=178350
Added: trunk/LayoutTests/http/wpt/resources/gc.js (0 => 223562)
--- trunk/LayoutTests/http/wpt/resources/gc.js (rev 0)
+++ trunk/LayoutTests/http/wpt/resources/gc.js 2017-10-17 18:39:48 UTC (rev 223562)
@@ -0,0 +1,22 @@
+// If there is no window.gc() already defined, define one using the best
+// method we can find.
+// The slow fallback should not hit in the actual test environment.
+if (!window.gc)
+{
+ window.gc = function()
+ {
+ if (window.GCController)
+ return GCController.collect();
+
+ console.warn('Tests are running without the ability to do manual garbage collection. They will still work, but coverage will be suboptimal.');
+ function gcRec(n) {
+ if (n < 1)
+ return {};
+ var temp = {i: "ab" + i + (i / 100000)};
+ temp += "foo";
+ gcRec(n-1);
+ }
+ for (var i = 0; i < 10000; i++)
+ gcRec(10);
+ }
+}
Added: trunk/LayoutTests/http/wpt/service-workers/extendableEvent.https-expected.txt (0 => 223562)
--- trunk/LayoutTests/http/wpt/service-workers/extendableEvent.https-expected.txt (rev 0)
+++ trunk/LayoutTests/http/wpt/service-workers/extendableEvent.https-expected.txt 2017-10-17 18:39:48 UTC (rev 223562)
@@ -0,0 +1,6 @@
+
+PASS ExtendableEvent waitUntil should support non promise parameters
+PASS ExtendableEvent should wait for given promise to resolve
+PASS ExtendableEvent should wait for given promise to reject
+PASS Event constructors
+
Added: trunk/LayoutTests/http/wpt/service-workers/extendableEvent.https.html (0 => 223562)
--- trunk/LayoutTests/http/wpt/service-workers/extendableEvent.https.html (rev 0)
+++ trunk/LayoutTests/http/wpt/service-workers/extendableEvent.https.html 2017-10-17 18:39:48 UTC (rev 223562)
@@ -0,0 +1,63 @@
+<!DOCTYPE html>
+<title>Service Worker Extendable Event</title>
+<script src=""
+<script src=""
+<script>
+// FIXME: Should be run on a service worker.
+test(() => {
+ if (!window.internals)
+ return Promise.reject("test require internals");
+ var event = new ExtendableEvent('ExtendableEvent', {});
+ assert_throws('InvalidStateError', () => event.waitUntil(new Request('')));
+}, "ExtendableEvent waitUntil should support non promise parameters");
+
+promise_test(async t => {
+ if (!window.internals)
+ return Promise.reject("test require internals");
+ var event = internals.createTrustedExtendableEvent();
+ var promise = internals.waitForExtendableEventToFinish(event);
+ var shouldWait = true;
+ event.waitUntil(new Promise((resolve, reject) => {
+ setTimeout(() => {
+ shouldWait = false;
+ resolve(new Request(''));
+ }, 50);
+ }));
+ await promise;
+ assert_false(shouldWait);
+}, "ExtendableEvent should wait for given promise to resolve");
+
+promise_test(async t => {
+ if (!window.internals)
+ return Promise.reject("test require internals");
+ var event = internals.createTrustedExtendableEvent();
+ var promise = internals.waitForExtendableEventToFinish(event);
+ var shouldWait = true;
+ event.waitUntil(new Promise((resolve, reject) => {
+ setTimeout(() => {
+ shouldWait = false;
+ reject(new Request(''));
+ }, 50);
+ }));
+ await promise;
+ assert_false(shouldWait);
+}, "ExtendableEvent should wait for given promise to reject");
+
+test(function() {
+ assert_equals(
+ new ExtendableEvent('ExtendableEvent').type,
+ 'ExtendableEvent', 'Type of ExtendableEvent should be ExtendableEvent');
+ assert_equals(
+ new ExtendableEvent('ExtendableEvent', {}).type,
+ 'ExtendableEvent', 'Type of ExtendableEvent should be ExtendableEvent');
+ assert_equals(
+ new ExtendableEvent('ExtendableEvent', {}).cancelable,
+ false, 'Default ExtendableEvent.cancelable should be false');
+ assert_equals(
+ new ExtendableEvent('ExtendableEvent', {}).bubbles,
+ false, 'Default ExtendableEvent.bubbles should be false');
+ assert_equals(
+ new ExtendableEvent('ExtendableEvent', {cancelable: false}).cancelable,
+ false, 'ExtendableEvent.cancelable should be false');
+ }, 'Event constructors');
+</script>
Added: trunk/LayoutTests/http/wpt/service-workers/fetchEvent.https-expected.txt (0 => 223562)
--- trunk/LayoutTests/http/wpt/service-workers/fetchEvent.https-expected.txt (rev 0)
+++ trunk/LayoutTests/http/wpt/service-workers/fetchEvent.https-expected.txt 2017-10-17 18:39:48 UTC (rev 223562)
@@ -0,0 +1,10 @@
+
+PASS FetchEvent respondWith should throw if called twice
+PASS FetchEvent request is SameObject
+PASS FetchEvent should be in error if responding with undefined
+PASS FetchEvent should be in error if not responding with a Response
+PASS FetchEvent should be in error if responding with a Promise that does not resolve to a Response
+PASS FetchEvent should be in error if responding with a Promise that rejects
+PASS FetchEvent should resolve when responding with a Response
+PASS Event constructors
+
Added: trunk/LayoutTests/http/wpt/service-workers/fetchEvent.https.html (0 => 223562)
--- trunk/LayoutTests/http/wpt/service-workers/fetchEvent.https.html (rev 0)
+++ trunk/LayoutTests/http/wpt/service-workers/fetchEvent.https.html 2017-10-17 18:39:48 UTC (rev 223562)
@@ -0,0 +1,107 @@
+<!DOCTYPE html>
+<title>Service Worker Fetch Event</title>
+<script src=""
+<script src=""
+<script src=""
+<script>
+// FIXME: Should be run on a service worker.
+test(() => {
+ var event = new FetchEvent('FetchEvent', { request : new Request('') });
+ event.respondWith(undefined);
+ assert_throws('InvalidStateError', () => event.respondWith(undefined));
+}, "FetchEvent respondWith should throw if called twice");
+
+test(() => {
+ var event = new FetchEvent('FetchEvent', { request : new Request('test') });
+ event.request.value = 1;
+ gc();
+ assert_equals(event.request.value, 1);
+}, "FetchEvent request is SameObject");
+
+promise_test(async t => {
+ if (!window.internals)
+ return Promise.reject("test require internals");
+ var event = new FetchEvent('FetchEvent', { request : new Request('') });
+ var promise = internals.waitForFetchEventToFinish(event);
+ event.respondWith(undefined);
+ return promise_rejects(t, new TypeError, promise);
+}, "FetchEvent should be in error if responding with undefined");
+
+promise_test(async t => {
+ if (!window.internals)
+ return Promise.reject("test require internals");
+ var event = new FetchEvent('FetchEvent', { request : new Request('') });
+ var promise = internals.waitForFetchEventToFinish(event);
+ event.respondWith(new Request(''));
+ return promise_rejects(t, new TypeError, promise);
+}, "FetchEvent should be in error if not responding with a Response");
+
+promise_test(async t => {
+ if (!window.internals)
+ return Promise.reject("test require internals");
+ var event = new FetchEvent('FetchEvent', { request : new Request('') });
+ var promise = internals.waitForFetchEventToFinish(event);
+ event.respondWith(new Promise((resolve, reject) => {
+ resolve(new Request(''));
+ }));
+ return promise_rejects(t, new TypeError, promise);
+}, "FetchEvent should be in error if responding with a Promise that does not resolve to a Response");
+
+promise_test(async t => {
+ if (!window.internals)
+ return Promise.reject("test require internals");
+ var event = new FetchEvent('FetchEvent', { request : new Request('') });
+ var promise = internals.waitForFetchEventToFinish(event);
+ event.respondWith(new Promise((resolve, reject) => {
+ reject('not good');
+ }));
+ return promise_rejects(t, new TypeError, promise);
+}, "FetchEvent should be in error if responding with a Promise that rejects");
+
+promise_test(async t => {
+ if (!window.internals)
+ return Promise.reject("test require internals");
+ var event = new FetchEvent('FetchEvent', { request : new Request('') });
+ var response = new Response;
+ event.respondWith(response);
+ assert_true(response === await internals.waitForFetchEventToFinish(event));
+}, "FetchEvent should resolve when responding with a Response");
+
+// Duplicate test from WPT. To be removed once WPT service worker tests are active.
+test(function() {
+ var req = new Request('http://localhost:8800/',
+ {method: 'POST',
+ headers: [['Content-Type', 'Text/Html']]});
+ assert_equals(
+ new ExtendableEvent('ExtendableEvent').type,
+ 'ExtendableEvent', 'Type of ExtendableEvent should be ExtendableEvent');
+ assert_throws(new TypeError, function() {
+ new FetchEvent('FetchEvent');
+ }, 'FetchEvent constructor with one argument throws');
+ assert_throws(new TypeError, function() {
+ new FetchEvent('FetchEvent', {});
+ }, 'FetchEvent constructor with empty init dict throws');
+ assert_throws(new TypeError, function() {
+ new FetchEvent('FetchEvent', {request: null});
+ }, 'FetchEvent constructor with null request member throws');
+ assert_equals(
+ new FetchEvent('FetchEvent', {request: req}).type,
+ 'FetchEvent', 'Type of FetchEvent should be FetchEvent');
+ assert_equals(
+ new FetchEvent('FetchEvent', {request: req}).cancelable,
+ false, 'Default FetchEvent.cancelable should be false');
+ assert_equals(
+ new FetchEvent('FetchEvent', {request: req}).bubbles,
+ false, 'Default FetchEvent.bubbles should be false');
+ assert_equals(
+ new FetchEvent('FetchEvent', {request: req, cancelable: false}).cancelable,
+ false, 'FetchEvent.cancelable should be false');
+ assert_equals(
+ new FetchEvent('FetchEvent', {request: req, clientId : 'test-client-id'}).clientId, 'test-client-id',
+ 'FetchEvent.clientId with option {clientId : "test-client-id"} should be "test-client-id"');
+ assert_equals(
+ new FetchEvent('FetchEvent', {request : req, isReload : true}).request.url,
+ 'http://localhost:8800/',
+ 'FetchEvent.request.url should return the value it was initialized to');
+ }, 'Event constructors');
+</script>
Modified: trunk/LayoutTests/platform/ios-wk1/TestExpectations (223561 => 223562)
--- trunk/LayoutTests/platform/ios-wk1/TestExpectations 2017-10-17 18:39:47 UTC (rev 223561)
+++ trunk/LayoutTests/platform/ios-wk1/TestExpectations 2017-10-17 18:39:48 UTC (rev 223562)
@@ -9,6 +9,7 @@
# No service worker implementation for WK1
imported/w3c/web-platform-tests/service-workers [ Skip ]
+http/wpt/service-workers [ Skip ]
http/wpt/cache-storage [ Skip ]
http/tests/cache-storage [ Skip ]
Modified: trunk/LayoutTests/platform/mac-wk1/TestExpectations (223561 => 223562)
--- trunk/LayoutTests/platform/mac-wk1/TestExpectations 2017-10-17 18:39:47 UTC (rev 223561)
+++ trunk/LayoutTests/platform/mac-wk1/TestExpectations 2017-10-17 18:39:48 UTC (rev 223562)
@@ -104,6 +104,7 @@
# No service worker implementation for WK1
imported/w3c/web-platform-tests/service-workers [ Skip ]
+http/wpt/service-workers [ Skip ]
http/wpt/cache-storage [ Skip ]
http/tests/cache-storage [ Skip ]
Modified: trunk/Source/_javascript_Core/ChangeLog (223561 => 223562)
--- trunk/Source/_javascript_Core/ChangeLog 2017-10-17 18:39:47 UTC (rev 223561)
+++ trunk/Source/_javascript_Core/ChangeLog 2017-10-17 18:39:48 UTC (rev 223562)
@@ -1,3 +1,14 @@
+2017-10-17 Youenn Fablet <you...@apple.com>
+
+ Add preliminary support for fetch event
+ https://bugs.webkit.org/show_bug.cgi?id=178171
+
+ Reviewed by Chris Dumez.
+
+ Adding events
+
+ * runtime/JSPromise.h:
+
2017-10-10 Yusuke Suzuki <utatane....@gmail.com>
[JSC] __proto__ getter should be fast
Modified: trunk/Source/_javascript_Core/runtime/JSPromise.h (223561 => 223562)
--- trunk/Source/_javascript_Core/runtime/JSPromise.h 2017-10-17 18:39:47 UTC (rev 223561)
+++ trunk/Source/_javascript_Core/runtime/JSPromise.h 2017-10-17 18:39:48 UTC (rev 223562)
@@ -44,7 +44,7 @@
Rejected
};
- Status status(VM&) const;
+ JS_EXPORT_PRIVATE Status status(VM&) const;
JS_EXPORT_PRIVATE JSValue result(VM&) const;
JS_EXPORT_PRIVATE bool isHandled(VM&) const;
Modified: trunk/Source/WebCore/CMakeLists.txt (223561 => 223562)
--- trunk/Source/WebCore/CMakeLists.txt 2017-10-17 18:39:47 UTC (rev 223561)
+++ trunk/Source/WebCore/CMakeLists.txt 2017-10-17 18:39:48 UTC (rev 223562)
@@ -786,6 +786,9 @@
workers/WorkerLocation.idl
workers/WorkerType.idl
+ workers/service/ExtendableEvent.idl
+ workers/service/ExtendableEventInit.idl
+ workers/service/FetchEvent.idl
workers/service/ServiceWorker.idl
workers/service/ServiceWorkerContainer.idl
workers/service/ServiceWorkerGlobalScope.idl
@@ -1287,6 +1290,7 @@
bindings/js/JSDOMGlobalObjectTask.cpp
bindings/js/JSDOMGuardedObject.cpp
bindings/js/JSDOMMapLike.cpp
+ bindings/js/JSDOMPromise.cpp
bindings/js/JSDOMPromiseDeferred.cpp
bindings/js/JSDOMWindowBase.cpp
bindings/js/JSDOMWindowCustom.cpp
@@ -3075,6 +3079,8 @@
workers/WorkerScriptLoader.cpp
workers/WorkerThread.cpp
+ workers/service/ExtendableEvent.cpp
+ workers/service/FetchEvent.cpp
workers/service/ServiceWorker.cpp
workers/service/ServiceWorkerContainer.cpp
workers/service/ServiceWorkerGlobalScope.cpp
Modified: trunk/Source/WebCore/ChangeLog (223561 => 223562)
--- trunk/Source/WebCore/ChangeLog 2017-10-17 18:39:47 UTC (rev 223561)
+++ trunk/Source/WebCore/ChangeLog 2017-10-17 18:39:48 UTC (rev 223562)
@@ -1,3 +1,63 @@
+2017-10-17 Youenn Fablet <you...@apple.com>
+
+ Add preliminary support for fetch event
+ https://bugs.webkit.org/show_bug.cgi?id=178171
+
+ Reviewed by Chris Dumez.
+
+ Test: http/wpt/service-workers/fetchEvent.https.html
+ http/wpt/service-workers/extendableEvent.https.html
+
+ Adding support for ExtendableEvent and FetchEvent as per
+ https://w3c.github.io/ServiceWorker/v1/#extendableevent-interface and
+ https://w3c.github.io/ServiceWorker/v1/#fetchevent-interface.
+
+ Both events need to handle promises as method parameters.
+ Beefing up DOMPromise for that purpose by exposing status, result and being able to call then.
+ Adding a new DOMPromise create method that would be the base for https://heycam.github.io/webidl/#es-promise
+ which might be implemented in the binding generator as a follow-up.
+
+ This patch makes them exposed on Window for test purposes until they can be fully tested on ServiceWorker environment.
+ It is also adding two internal methods for the same reason. These should be removed once events can be tested in its environment.
+
+ * CMakeLists.txt:
+ * DerivedSources.make:
+ * Modules/fetch/FetchResponse.idl:
+ * WebCore.xcodeproj/project.pbxproj:
+ * bindings/js/JSDOMPromise.cpp: Added.
+ (WebCore::callFunction):
+ (WebCore::DOMPromise::create):
+ (WebCore::DOMPromise::whenSettled):
+ (WebCore::DOMPromise::result const):
+ (WebCore::DOMPromise::status const):
+ * bindings/js/JSDOMPromise.h:
+ * bindings/js/WebCoreBuiltinNames.h:
+ * dom/EventNames.in:
+ * testing/Internals.cpp:
+ (WebCore::Internals::waitFetchEventToFinish):
+ (WebCore::Internals::waitExtendableEventToFinish):
+ * testing/Internals.h:
+ * testing/Internals.idl:
+ * workers/service/ExtendableEvent.cpp: Added.
+ (WebCore::ExtendableEvent::ExtendableEvent):
+ (WebCore::ExtendableEvent::waitUntil):
+ (WebCore::ExtendableEvent::addPendingPromise):
+ * workers/service/ExtendableEvent.h:
+ (WebCore::ExtendableEvent::onFinishedWaiting):
+ (WebCore::ExtendableEvent::promiseSettled):
+ * workers/service/ExtendableEvent.idl: Added.
+ * workers/service/ExtendableEventInit.h: Added.
+ * workers/service/ExtendableEventInit.idl: Added.
+ * workers/service/FetchEvent.cpp: Added.
+ (WebCore::FetchEvent::FetchEvent):
+ (WebCore::FetchEvent::respondWith):
+ (WebCore::FetchEvent::onResponse):
+ (WebCore::FetchEvent::respondWithError):
+ (WebCore::FetchEvent::processResponse):
+ (WebCore::FetchEvent::promiseSettled):
+ * workers/service/FetchEvent.h:
+ * workers/service/FetchEvent.idl:
+
2017-10-17 Jer Noble <jer.no...@apple.com>
Leak of one AVSampleCursor inside ImageDecoderAVFObjC::createFrameImageAtIndex()
Modified: trunk/Source/WebCore/DerivedSources.make (223561 => 223562)
--- trunk/Source/WebCore/DerivedSources.make 2017-10-17 18:39:47 UTC (rev 223561)
+++ trunk/Source/WebCore/DerivedSources.make 2017-10-17 18:39:48 UTC (rev 223562)
@@ -910,6 +910,9 @@
$(WebCore)/workers/WorkerGlobalScope.idl \
$(WebCore)/workers/WorkerLocation.idl \
$(WebCore)/workers/WorkerType.idl \
+ $(WebCore)/workers/service/ExtendableEvent.idl \
+ $(WebCore)/workers/service/ExtendableEventInit.idl \
+ $(WebCore)/workers/service/FetchEvent.idl \
$(WebCore)/workers/service/ServiceWorker.idl \
$(WebCore)/workers/service/ServiceWorkerContainer.idl \
$(WebCore)/workers/service/ServiceWorkerGlobalScope.idl \
Modified: trunk/Source/WebCore/Modules/fetch/FetchRequest.idl (223561 => 223562)
--- trunk/Source/WebCore/Modules/fetch/FetchRequest.idl 2017-10-17 18:39:47 UTC (rev 223561)
+++ trunk/Source/WebCore/Modules/fetch/FetchRequest.idl 2017-10-17 18:39:48 UTC (rev 223562)
@@ -39,6 +39,7 @@
ConstructorCallWith=ScriptExecutionContext,
EnabledAtRuntime=FetchAPI,
Exposed=(Window,Worker),
+ GenerateIsReachable=Impl,
InterfaceName=Request,
] interface FetchRequest {
readonly attribute ByteString method;
Modified: trunk/Source/WebCore/Modules/fetch/FetchResponse.idl (223561 => 223562)
--- trunk/Source/WebCore/Modules/fetch/FetchResponse.idl 2017-10-17 18:39:47 UTC (rev 223561)
+++ trunk/Source/WebCore/Modules/fetch/FetchResponse.idl 2017-10-17 18:39:48 UTC (rev 223562)
@@ -43,7 +43,7 @@
ConstructorCallWith=ScriptExecutionContext,
ConstructorMayThrowException,
EnabledAtRuntime=FetchAPI,
- ExportToWrappedFunction,
+ ExportMacro=WEBCORE_EXPORT,
Exposed=(Window,Worker),
InterfaceName=Response,
] interface FetchResponse {
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (223561 => 223562)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2017-10-17 18:39:47 UTC (rev 223561)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2017-10-17 18:39:48 UTC (rev 223562)
@@ -1693,6 +1693,7 @@
4129DF861BB5B80C00322A16 /* JSReadableStreamPrivateConstructors.h in Headers */ = {isa = PBXBuildFile; fileRef = 4129DF841BB5B7F700322A16 /* JSReadableStreamPrivateConstructors.h */; settings = {ATTRIBUTES = (Private, ); }; };
413015D91C7B571400091C6E /* FetchResponse.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 413015D51C7B570400091C6E /* FetchResponse.cpp */; };
413015D91C7B571400091C6F /* FetchBodySource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 413015D51C7B570400091C6F /* FetchBodySource.cpp */; };
+ 4131F3B31F9552860059995A /* JSFetchEventCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4131F3B11F9552810059995A /* JSFetchEventCustom.cpp */; };
41380C261F3436A600155FDA /* DOMCache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41380C201F34368A00155FDA /* DOMCache.cpp */; };
41380C271F3436AC00155FDA /* DOMCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 41380C251F34369A00155FDA /* DOMCache.h */; };
41380C281F3436AC00155FDA /* DOMCacheStorage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41380C211F34368D00155FDA /* DOMCacheStorage.cpp */; };
@@ -1776,6 +1777,9 @@
41ABE67B1D0580DB006D862D /* CrossOriginPreflightChecker.h in Headers */ = {isa = PBXBuildFile; fileRef = 41ABE67A1D0580D5006D862D /* CrossOriginPreflightChecker.h */; };
41ABE67C1D0580E0006D862D /* CrossOriginPreflightChecker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41ABE6791D0580D5006D862D /* CrossOriginPreflightChecker.cpp */; };
41AD753A1CEF6BD100A31486 /* FetchOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 41AD75391CEF6BCE00A31486 /* FetchOptions.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ 41AF37991F8DADAA00111C31 /* ExtendableEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41AF37921F8DA48A00111C31 /* ExtendableEvent.cpp */; };
+ 41AF379B1F8DADAE00111C31 /* FetchEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41AF37941F8DA49500111C31 /* FetchEvent.cpp */; };
+ 41AF379D1F8DB1B500111C31 /* JSDOMPromise.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41AF379C1F8DB1B100111C31 /* JSDOMPromise.cpp */; };
41B28B141F8501A600FB52AC /* MediaEndpointConfiguration.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41B28B131F8501A400FB52AC /* MediaEndpointConfiguration.cpp */; };
41B28B151F8501D300FB52AC /* MediaEndpointConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = 41B28B121F8501A300FB52AC /* MediaEndpointConfiguration.h */; };
41B28B391F860BD600FB52AC /* LibWebRTCProviderCocoa.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41B28B381F860BD100FB52AC /* LibWebRTCProviderCocoa.cpp */; };
@@ -3406,8 +3410,13 @@
7E474E2012494DC900235364 /* SQLiteDatabaseTracker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7E474E1D12494DC900235364 /* SQLiteDatabaseTracker.cpp */; };
7E4C96DC1AD4483500365A50 /* JSFetchRequest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7E4C96D81AD4483500365A50 /* JSFetchRequest.cpp */; };
7E4C96DC1AD4483500365A51 /* JSReadableStreamSource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7E4C96D81AD4483500365A51 /* JSReadableStreamSource.cpp */; };
+ 7E4C96DC1AD4483500365A52 /* WebCore/JSFetchEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7E4C96D81AD4483500365A52 /* WebCore/JSFetchEvent.cpp */; };
+ 7E4C96DC1AD4483500365A53 /* WebCore/JSExtendableEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7E4C96D81AD4483500365A53 /* WebCore/JSExtendableEvent.cpp */; };
+ 7E4C96DC1AD4483500365A54 /* WebCore/JSExtendableEventInit.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7E4C96D81AD4483500365A54 /* WebCore/JSExtendableEventInit.cpp */; };
7E4C96DD1AD4483500365A50 /* JSFetchRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E4C96D91AD4483500365A50 /* JSFetchRequest.h */; };
7E4C96DD1AD4483500365A51 /* JSReadableStreamSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E4C96D91AD4483500365A51 /* JSReadableStreamSource.h */; };
+ 7E4C96DD1AD4483500365A52 /* JSFetchEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E4C96D91AD4483500365A52 /* JSFetchEvent.h */; };
+ 7E4C96DD1AD4483500365A53 /* JSExtendableEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E4C96D91AD4483500365A53 /* JSExtendableEvent.h */; };
7E4DE10D198B10B60051CB02 /* DiskCacheMonitorCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7E4DE10C198B10B60051CB02 /* DiskCacheMonitorCocoa.mm */; };
7E5D7A76161D3F8F00896C34 /* OESElementIndexUint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7E5D7A73161D3F8F00896C34 /* OESElementIndexUint.cpp */; };
7E5D7A77161D3F8F00896C34 /* OESElementIndexUint.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E5D7A74161D3F8F00896C34 /* OESElementIndexUint.h */; };
@@ -9496,6 +9505,9 @@
413015D61C7B570400091C6E /* FetchResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FetchResponse.h; sourceTree = "<group>"; };
413015D61C7B570400091C6F /* FetchBodySource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FetchBodySource.h; sourceTree = "<group>"; };
413015D71C7B570400091C6E /* FetchResponse.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = FetchResponse.idl; sourceTree = "<group>"; };
+ 4131F3B11F9552810059995A /* JSFetchEventCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSFetchEventCustom.cpp; sourceTree = "<group>"; };
+ 4131F3B41F955BC30059995A /* ExtendableEventInit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExtendableEventInit.h; sourceTree = "<group>"; };
+ 4131F3B51F955BC50059995A /* ExtendableEventInit.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ExtendableEventInit.idl; sourceTree = "<group>"; };
41380C201F34368A00155FDA /* DOMCache.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = DOMCache.cpp; path = Modules/cache/DOMCache.cpp; sourceTree = SOURCE_ROOT; };
41380C211F34368D00155FDA /* DOMCacheStorage.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = DOMCacheStorage.cpp; path = Modules/cache/DOMCacheStorage.cpp; sourceTree = SOURCE_ROOT; };
41380C221F34369000155FDA /* DOMCacheStorage.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = DOMCacheStorage.h; path = Modules/cache/DOMCacheStorage.h; sourceTree = SOURCE_ROOT; };
@@ -9598,6 +9610,13 @@
41ABE6791D0580D5006D862D /* CrossOriginPreflightChecker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CrossOriginPreflightChecker.cpp; sourceTree = "<group>"; };
41ABE67A1D0580D5006D862D /* CrossOriginPreflightChecker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CrossOriginPreflightChecker.h; sourceTree = "<group>"; };
41AD75391CEF6BCE00A31486 /* FetchOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FetchOptions.h; sourceTree = "<group>"; };
+ 41AF37881F8C1E7900111C31 /* FetchEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FetchEvent.h; sourceTree = "<group>"; };
+ 41AF378A1F8C1E7A00111C31 /* ExtendableEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExtendableEvent.h; sourceTree = "<group>"; };
+ 41AF378D1F8C1E7B00111C31 /* FetchEvent.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = FetchEvent.idl; sourceTree = "<group>"; };
+ 41AF378E1F8C1E7C00111C31 /* ExtendableEvent.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ExtendableEvent.idl; sourceTree = "<group>"; };
+ 41AF37921F8DA48A00111C31 /* ExtendableEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ExtendableEvent.cpp; sourceTree = "<group>"; };
+ 41AF37941F8DA49500111C31 /* FetchEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FetchEvent.cpp; sourceTree = "<group>"; };
+ 41AF379C1F8DB1B100111C31 /* JSDOMPromise.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDOMPromise.cpp; sourceTree = "<group>"; };
41B28B121F8501A300FB52AC /* MediaEndpointConfiguration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaEndpointConfiguration.h; sourceTree = "<group>"; };
41B28B131F8501A400FB52AC /* MediaEndpointConfiguration.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MediaEndpointConfiguration.cpp; sourceTree = "<group>"; };
41B28B361F860BD000FB52AC /* LibWebRTCProviderCocoa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LibWebRTCProviderCocoa.h; path = libwebrtc/LibWebRTCProviderCocoa.h; sourceTree = "<group>"; };
@@ -11693,8 +11712,13 @@
7E474E1D12494DC900235364 /* SQLiteDatabaseTracker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SQLiteDatabaseTracker.cpp; sourceTree = "<group>"; };
7E4C96D81AD4483500365A50 /* JSFetchRequest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSFetchRequest.cpp; sourceTree = "<group>"; };
7E4C96D81AD4483500365A51 /* JSReadableStreamSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSReadableStreamSource.cpp; sourceTree = "<group>"; };
+ 7E4C96D81AD4483500365A52 /* WebCore/JSFetchEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebCore/JSFetchEvent.cpp; sourceTree = "<group>"; };
+ 7E4C96D81AD4483500365A53 /* WebCore/JSExtendableEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebCore/JSExtendableEvent.cpp; sourceTree = "<group>"; };
+ 7E4C96D81AD4483500365A54 /* WebCore/JSExtendableEventInit.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebCore/JSExtendableEventInit.cpp; sourceTree = "<group>"; };
7E4C96D91AD4483500365A50 /* JSFetchRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSFetchRequest.h; sourceTree = "<group>"; };
7E4C96D91AD4483500365A51 /* JSReadableStreamSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSReadableStreamSource.h; sourceTree = "<group>"; };
+ 7E4C96D91AD4483500365A52 /* JSFetchEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSFetchEvent.h; sourceTree = "<group>"; };
+ 7E4C96D91AD4483500365A53 /* JSExtendableEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSExtendableEvent.h; sourceTree = "<group>"; };
7E4DE10C198B10B60051CB02 /* DiskCacheMonitorCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DiskCacheMonitorCocoa.mm; sourceTree = "<group>"; };
7E5D7A73161D3F8F00896C34 /* OESElementIndexUint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = OESElementIndexUint.cpp; sourceTree = "<group>"; };
7E5D7A74161D3F8F00896C34 /* OESElementIndexUint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OESElementIndexUint.h; sourceTree = "<group>"; };
@@ -19102,6 +19126,8 @@
5182C24C1F3142090059BA7C /* ServiceWorkers */ = {
isa = PBXGroup;
children = (
+ 7E4C96D91AD4483500365A53 /* JSExtendableEvent.h */,
+ 7E4C96D91AD4483500365A52 /* JSFetchEvent.h */,
51F886BE1F32920700C193EF /* JSNavigatorServiceWorker.cpp */,
51F886BF1F32920700C193EF /* JSNavigatorServiceWorker.h */,
5182C2531F3142500059BA7C /* JSServiceWorker.cpp */,
@@ -19114,6 +19140,9 @@
5182C2501F3142500059BA7C /* JSServiceWorkerRegistration.h */,
51F175001F358B3600C74950 /* JSServiceWorkerUpdateViaCache.cpp */,
51F175011F358B3600C74950 /* JSServiceWorkerUpdateViaCache.h */,
+ 7E4C96D81AD4483500365A53 /* WebCore/JSExtendableEvent.cpp */,
+ 7E4C96D81AD4483500365A54 /* WebCore/JSExtendableEventInit.cpp */,
+ 7E4C96D81AD4483500365A52 /* WebCore/JSFetchEvent.cpp */,
);
name = ServiceWorkers;
path = DerivedSources;
@@ -19181,6 +19210,14 @@
children = (
517C87071F8E8FF200EB8076 /* context */,
517A52EC1F47532D00DCDC0A /* server */,
+ 41AF37921F8DA48A00111C31 /* ExtendableEvent.cpp */,
+ 41AF378A1F8C1E7A00111C31 /* ExtendableEvent.h */,
+ 41AF378E1F8C1E7C00111C31 /* ExtendableEvent.idl */,
+ 4131F3B41F955BC30059995A /* ExtendableEventInit.h */,
+ 4131F3B51F955BC50059995A /* ExtendableEventInit.idl */,
+ 41AF37941F8DA49500111C31 /* FetchEvent.cpp */,
+ 41AF37881F8C1E7900111C31 /* FetchEvent.h */,
+ 41AF378D1F8C1E7B00111C31 /* FetchEvent.idl */,
51F1755B1F3EBC0C00C74950 /* ServiceWorker.cpp */,
51F1755A1F3EBC0C00C74950 /* ServiceWorker.h */,
51F175591F3EBC0C00C74950 /* ServiceWorker.idl */,
@@ -20361,6 +20398,7 @@
isa = PBXGroup;
children = (
DEC2975D1B4DEB2A005F5945 /* JSCustomEventCustom.cpp */,
+ 4131F3B11F9552810059995A /* JSFetchEventCustom.cpp */,
BCE7B1920D4E86960075A539 /* JSHistoryCustom.cpp */,
410B7E711045FAB000D8224F /* JSMessageEventCustom.cpp */,
A85F22081430377D007CC884 /* JSPopStateEventCustom.cpp */,
@@ -24248,6 +24286,7 @@
41DEFCB41E56C1B9000D9E5F /* JSDOMMapLike.h */,
7C8139A41ED6281D00CE26E8 /* JSDOMOperation.h */,
7C8139A51ED6281D00CE26E8 /* JSDOMOperationReturningPromise.h */,
+ 41AF379C1F8DB1B100111C31 /* JSDOMPromise.cpp */,
E37C864F1EB63E2D0087C6CA /* JSDOMPromise.h */,
E172AF8D1811BC3700FBADB9 /* JSDOMPromiseDeferred.cpp */,
E172AF8E1811BC3700FBADB9 /* JSDOMPromiseDeferred.h */,
@@ -28685,6 +28724,7 @@
5FC7DC26CFE2563200B85AE4 /* JSEventTarget.h in Headers */,
46B63F6C1C6E8D19002E914B /* JSEventTargetCustom.h in Headers */,
724ED3321A3A8B2300F5F13C /* JSEXTBlendMinMax.h in Headers */,
+ 7E4C96DD1AD4483500365A53 /* JSExtendableEvent.h in Headers */,
5C4304B6191AEF46000E2BC0 /* JSEXTShaderTextureLOD.h in Headers */,
7728698414FD9ADA00F484DC /* JSEXTTextureFilterAnisotropic.h in Headers */,
77D50FF61ED4D99B00DA4C87 /* JSFederatedCredential.h in Headers */,
@@ -28691,6 +28731,7 @@
77D50FF41ED4D98D00DA4C87 /* JSFederatedCredentialInit.h in Headers */,
77D510131ED5F4ED00DA4C87 /* JSFederatedCredentialRequestOptions.h in Headers */,
7F4C96DD1AD4483500365A50 /* JSFetchBody.h in Headers */,
+ 7E4C96DD1AD4483500365A52 /* JSFetchEvent.h in Headers */,
7D4C96DD1AD4483500365A50 /* JSFetchHeaders.h in Headers */,
7CE191711F2ABE7100272F78 /* JSFetchReferrerPolicy.h in Headers */,
7E4C96DD1AD4483500365A50 /* JSFetchRequest.h in Headers */,
@@ -31994,6 +32035,7 @@
262EC41D1D110B9000BA78FC /* EventTrackingRegions.cpp in Sources */,
51F645A41F4C001700B54DED /* ExceptionData.cpp in Sources */,
724ED32C1A3A7E5400F5F13C /* EXTBlendMinMax.cpp in Sources */,
+ 41AF37991F8DADAA00111C31 /* ExtendableEvent.cpp in Sources */,
31DCDF431DA1C45400EA5B93 /* ExtendedColor.cpp in Sources */,
6E67D2A61280E8A4008758F7 /* Extensions3DOpenGL.cpp in Sources */,
44DAB5B115A623580097C1E4 /* Extensions3DOpenGLCommon.cpp in Sources */,
@@ -32022,6 +32064,7 @@
41CF8BE71D46226700707DC9 /* FetchBodyConsumer.cpp in Sources */,
4147E2B81C89912F00A7E715 /* FetchBodyOwner.cpp in Sources */,
413015D91C7B571400091C6F /* FetchBodySource.cpp in Sources */,
+ 41AF379B1F8DADAE00111C31 /* FetchEvent.cpp in Sources */,
41F54F8D1C50C50800338488 /* FetchHeaders.cpp in Sources */,
4147E2B71C89912C00A7E715 /* FetchLoader.cpp in Sources */,
41F54F8E1C50C50C00338488 /* FetchRequest.cpp in Sources */,
@@ -32670,6 +32713,7 @@
0F4966AA1DB40C4300A274BB /* JSDOMPoint.cpp in Sources */,
0F4966AC1DB40C4300A274BB /* JSDOMPointInit.cpp in Sources */,
0F4966AE1DB40C4300A274BB /* JSDOMPointReadOnly.cpp in Sources */,
+ 41AF379D1F8DB1B500111C31 /* JSDOMPromise.cpp in Sources */,
E172AF8F1811BC3700FBADB9 /* JSDOMPromiseDeferred.cpp in Sources */,
0FF3B9281EE3B6DE00B84144 /* JSDOMQuad.cpp in Sources */,
0F94A3961EF1B10500FBAFFB /* JSDOMQuadCustom.cpp in Sources */,
@@ -32718,6 +32762,7 @@
77D50FF51ED4D99100DA4C87 /* JSFederatedCredentialInit.cpp in Sources */,
77D510141ED5F4F100DA4C87 /* JSFederatedCredentialRequestOptions.cpp in Sources */,
7F4C96DC1AD4483500365A50 /* JSFetchBody.cpp in Sources */,
+ 4131F3B31F9552860059995A /* JSFetchEventCustom.cpp in Sources */,
7D4C96DC1AD4483500365A50 /* JSFetchHeaders.cpp in Sources */,
7CE191701F2ABE7100272F78 /* JSFetchReferrerPolicy.cpp in Sources */,
7E4C96DC1AD4483500365A50 /* JSFetchRequest.cpp in Sources */,
@@ -34582,6 +34627,9 @@
9B9299B21F6796A4006723C2 /* WebContentReaderCocoa.mm in Sources */,
9B0811241F67CDC00074BDE2 /* WebContentReaderIOS.mm in Sources */,
9B9299AE1F67865B006723C2 /* WebContentReaderMac.mm in Sources */,
+ 7E4C96DC1AD4483500365A53 /* WebCore/JSExtendableEvent.cpp in Sources */,
+ 7E4C96DC1AD4483500365A54 /* WebCore/JSExtendableEventInit.cpp in Sources */,
+ 7E4C96DC1AD4483500365A52 /* WebCore/JSFetchEvent.cpp in Sources */,
CD7E05221651C28200C1201F /* WebCoreAVFResourceLoader.mm in Sources */,
2D3EF44B1917915C00034184 /* WebCoreCALayerExtras.mm in Sources */,
515F79531CFCA3D000CCED93 /* WebCoreCrossThreadCopier.cpp in Sources */,
Added: trunk/Source/WebCore/bindings/js/JSDOMPromise.cpp (0 => 223562)
--- trunk/Source/WebCore/bindings/js/JSDOMPromise.cpp (rev 0)
+++ trunk/Source/WebCore/bindings/js/JSDOMPromise.cpp 2017-10-17 18:39:48 UTC (rev 223562)
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * 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. AND ITS CONTRIBUTORS ``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 ITS 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.
+ */
+
+#include "config.h"
+#include "JSDOMPromise.h"
+
+#include "DOMWindow.h"
+#include "JSDOMWindow.h"
+#include <builtins/BuiltinNames.h>
+#include <runtime/CatchScope.h>
+#include <runtime/Exception.h>
+#include <runtime/JSNativeStdFunction.h>
+#include <runtime/JSPromiseConstructor.h>
+
+using namespace JSC;
+
+namespace WebCore {
+
+static inline JSC::JSValue callFunction(JSC::ExecState& state, JSC::JSValue jsFunction, JSC::JSValue thisValue, const JSC::ArgList& arguments)
+{
+ auto scope = DECLARE_CATCH_SCOPE(state.vm());
+ JSC::CallData callData;
+ auto callType = JSC::getCallData(jsFunction, callData);
+ ASSERT(callType != JSC::CallType::None);
+ auto result = call(&state, jsFunction, callType, callData, thisValue, arguments);
+ scope.assertNoException();
+ return result;
+}
+
+Ref<DOMPromise> DOMPromise::create(JSC::ExecState& state, JSC::JSValue value)
+{
+ auto& globalObject = *JSC::jsCast<JSDOMGlobalObject*>(state.lexicalGlobalObject());
+
+ auto promiseConstructor = globalObject.promiseConstructor();
+ auto resolveFunction = promiseConstructor->get(&state, state.vm().propertyNames->builtinNames().resolvePrivateName());
+ ASSERT(resolveFunction.isFunction());
+
+ JSC::MarkedArgumentBuffer arguments;
+ arguments.append(value);
+ auto result = callFunction(state, resolveFunction, promiseConstructor, arguments);
+
+ auto* promise = JSC::jsCast<JSC::JSPromise*>(result);
+ ASSERT(promise);
+
+ return create(globalObject, *promise);
+}
+
+void DOMPromise::whenSettled(std::function<void()>&& callback)
+{
+ auto& state = *globalObject()->globalExec();
+ auto& vm = state.vm();
+ auto* handler = JSC::JSNativeStdFunction::create(vm, globalObject(), 1, String { }, [callback = WTFMove(callback)] (ExecState*) mutable {
+ callback();
+ return JSC::JSValue::encode(JSC::jsUndefined());
+ });
+
+ const JSC::Identifier& privateName = vm.propertyNames->builtinNames().thenPrivateName();
+ auto* promise = this->promise();
+ auto thenFunction = promise->get(&state, privateName);
+ ASSERT(thenFunction.isFunction());
+
+ JSC::MarkedArgumentBuffer arguments;
+ arguments.append(handler);
+ arguments.append(handler);
+ callFunction(state, thenFunction, promise, arguments);
+}
+
+JSC::JSValue DOMPromise::result() const
+{
+ return promise()->result(m_globalObject->globalExec()->vm());
+}
+
+DOMPromise::Status DOMPromise::status() const
+{
+ switch (promise()->status(m_globalObject->globalExec()->vm())) {
+ case JSC::JSPromise::Status::Pending:
+ return Status::Pending;
+ case JSC::JSPromise::Status::Fulfilled:
+ return Status::Fulfilled;
+ case JSC::JSPromise::Status::Rejected:
+ return Status::Rejected;
+ };
+ ASSERT_NOT_REACHED();
+ return Status::Rejected;
+}
+
+}
Modified: trunk/Source/WebCore/bindings/js/JSDOMPromise.h (223561 => 223562)
--- trunk/Source/WebCore/bindings/js/JSDOMPromise.h 2017-10-17 18:39:47 UTC (rev 223561)
+++ trunk/Source/WebCore/bindings/js/JSDOMPromise.h 2017-10-17 18:39:48 UTC (rev 223562)
@@ -33,6 +33,7 @@
class DOMPromise : public DOMGuarded<JSC::JSPromise> {
public:
+ static Ref<DOMPromise> create(JSC::ExecState&, JSC::JSValue);
static Ref<DOMPromise> create(JSDOMGlobalObject& globalObject, JSC::JSPromise& promise)
{
return adoptRef(*new DOMPromise(globalObject, promise));
@@ -44,6 +45,12 @@
return guarded();
}
+ void whenSettled(std::function<void()>&&);
+ JSC::JSValue result() const;
+
+ enum class Status { Pending, Fulfilled, Rejected };
+ Status status() const;
+
private:
DOMPromise(JSDOMGlobalObject& globalObject, JSC::JSPromise& promise)
: DOMGuarded<JSC::JSPromise>(globalObject, promise)
Added: trunk/Source/WebCore/bindings/js/JSFetchEventCustom.cpp (0 => 223562)
--- trunk/Source/WebCore/bindings/js/JSFetchEventCustom.cpp (rev 0)
+++ trunk/Source/WebCore/bindings/js/JSFetchEventCustom.cpp 2017-10-17 18:39:48 UTC (rev 223562)
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * 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.
+ */
+
+#include "config.h"
+#include "JSFetchEvent.h"
+
+namespace WebCore {
+
+void JSFetchEvent::visitAdditionalChildren(JSC::SlotVisitor& visitor)
+{
+ visitor.addOpaqueRoot(&wrapped().request());
+}
+
+}
Modified: trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h (223561 => 223562)
--- trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h 2017-10-17 18:39:47 UTC (rev 223561)
+++ trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h 2017-10-17 18:39:48 UTC (rev 223562)
@@ -43,7 +43,9 @@
macro(DataTransferItem) \
macro(DataTransferItemList) \
macro(DocumentTimeline) \
+ macro(ExtendableEvent) \
macro(FederatedCredential) \
+ macro(FetchEvent) \
macro(FileSystem) \
macro(FileSystemDirectoryEntry) \
macro(FileSystemDirectoryReader) \
Modified: trunk/Source/WebCore/dom/EventNames.in (223561 => 223562)
--- trunk/Source/WebCore/dom/EventNames.in 2017-10-17 18:39:47 UTC (rev 223561)
+++ trunk/Source/WebCore/dom/EventNames.in 2017-10-17 18:39:48 UTC (rev 223562)
@@ -10,7 +10,9 @@
CloseEvent
CompositionEvent
CustomEvent
+ExtendableEvent conditional=SERVICE_WORKER
ErrorEvent
+FetchEvent conditional=SERVICE_WORKER
FocusEvent
HashChangeEvent
InputEvent
Modified: trunk/Source/WebCore/testing/Internals.cpp (223561 => 223562)
--- trunk/Source/WebCore/testing/Internals.cpp 2017-10-17 18:39:47 UTC (rev 223561)
+++ trunk/Source/WebCore/testing/Internals.cpp 2017-10-17 18:39:48 UTC (rev 223562)
@@ -57,8 +57,9 @@
#include "Editor.h"
#include "Element.h"
#include "EventHandler.h"
+#include "ExtendableEvent.h"
#include "ExtensionStyleSheets.h"
-#include "FetchResponse.h"
+#include "FetchEvent.h"
#include "File.h"
#include "FontCache.h"
#include "FormController.h"
@@ -87,6 +88,7 @@
#include "InstrumentingAgents.h"
#include "IntRect.h"
#include "InternalSettings.h"
+#include "JSFetchResponse.h"
#include "JSImageData.h"
#include "LibWebRTCProvider.h"
#include "MainFrame.h"
@@ -4195,4 +4197,28 @@
return response.bodySizeWithPadding();
}
+#if ENABLE(SERVICE_WORKER)
+void Internals::waitForFetchEventToFinish(FetchEvent& event, DOMPromiseDeferred<IDLInterface<FetchResponse>>&& promise)
+{
+ event.onResponse([promise = WTFMove(promise), event = makeRef(event)] () mutable {
+ if (auto* response = event->response())
+ promise.resolve(*response);
+ else
+ promise.reject(TypeError, ASCIILiteral("fetch event responded with error"));
+ });
+}
+
+void Internals::waitForExtendableEventToFinish(ExtendableEvent& event, DOMPromiseDeferred<void>&& promise)
+{
+ event.onFinishedWaitingForTesting([promise = WTFMove(promise)] () mutable {
+ promise.resolve();
+ });
+}
+
+Ref<ExtendableEvent> Internals::createTrustedExtendableEvent()
+{
+ return ExtendableEvent::create("ExtendableEvent", { }, Event::IsTrusted::Yes);
+}
+#endif
+
} // namespace WebCore
Modified: trunk/Source/WebCore/testing/Internals.h (223561 => 223562)
--- trunk/Source/WebCore/testing/Internals.h 2017-10-17 18:39:47 UTC (rev 223561)
+++ trunk/Source/WebCore/testing/Internals.h 2017-10-17 18:39:48 UTC (rev 223562)
@@ -50,6 +50,8 @@
class DOMWindow;
class Document;
class Element;
+class ExtendableEvent;
+class FetchEvent;
class FetchResponse;
class File;
class Frame;
@@ -606,6 +608,12 @@
void setConsoleMessageListener(RefPtr<StringCallback>&&);
+#if ENABLE(SERVICE_WORKER)
+ void waitForFetchEventToFinish(FetchEvent&, DOMPromiseDeferred<IDLInterface<FetchResponse>>&&);
+ void waitForExtendableEventToFinish(ExtendableEvent&, DOMPromiseDeferred<void>&&);
+ Ref<ExtendableEvent> createTrustedExtendableEvent();
+#endif
+
private:
explicit Internals(Document&);
Document* contextDocument() const;
Modified: trunk/Source/WebCore/testing/Internals.idl (223561 => 223562)
--- trunk/Source/WebCore/testing/Internals.idl 2017-10-17 18:39:47 UTC (rev 223561)
+++ trunk/Source/WebCore/testing/Internals.idl 2017-10-17 18:39:48 UTC (rev 223562)
@@ -553,4 +553,8 @@
void setConsoleMessageListener(StringCallback callback);
DOMString audioSessionCategory();
+
+ [Conditional=SERVICE_WORKER] Promise<Response> waitForFetchEventToFinish(FetchEvent event);
+ [Conditional=SERVICE_WORKER] Promise<void> waitForExtendableEventToFinish(ExtendableEvent event);
+ [Conditional=SERVICE_WORKER] ExtendableEvent createTrustedExtendableEvent();
};
Added: trunk/Source/WebCore/workers/service/ExtendableEvent.cpp (0 => 223562)
--- trunk/Source/WebCore/workers/service/ExtendableEvent.cpp (rev 0)
+++ trunk/Source/WebCore/workers/service/ExtendableEvent.cpp 2017-10-17 18:39:48 UTC (rev 223562)
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * 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. AND ITS CONTRIBUTORS ``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 ITS 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.
+ */
+
+#include "config.h"
+#include "ExtendableEvent.h"
+
+#if ENABLE(SERVICE_WORKER)
+
+namespace WebCore {
+
+ExtendableEvent::ExtendableEvent(const AtomicString& type, const ExtendableEventInit& initializer, IsTrusted isTrusted)
+ : Event(type, initializer, isTrusted)
+{
+}
+
+ExceptionOr<void> ExtendableEvent::waitUntil(JSC::ExecState& state, JSC::JSValue promise)
+{
+ if (!isTrusted())
+ return Exception { InvalidStateError, ASCIILiteral("Event is not trusted") };
+
+ if (m_pendingPromises.isEmpty() && isBeingDispatched())
+ return Exception { InvalidStateError, ASCIILiteral("Event is being dispatched") };
+
+ addPendingPromise(DOMPromise::create(state, promise));
+
+ return { };
+}
+
+void ExtendableEvent::onFinishedWaitingForTesting(WTF::Function<void()>&& callback)
+{
+ ASSERT(!m_onFinishedWaitingForTesting);
+ m_onFinishedWaitingForTesting = WTFMove(callback);
+}
+
+void ExtendableEvent::addPendingPromise(Ref<DOMPromise>&& promise)
+{
+ promise->whenSettled([this, weakThis = createWeakPtr(), settledPromise = promise.ptr()] () {
+ if (!weakThis)
+ return;
+
+ auto promise = m_pendingPromises.take(*settledPromise);
+
+ // FIXME: Implement registration handling as per https://w3c.github.io/ServiceWorker/v1/#dom-extendableevent-waituntil.
+
+ if (!m_pendingPromises.isEmpty())
+ return;
+
+ if (auto callback = WTFMove(m_onFinishedWaitingForTesting))
+ callback();
+ });
+ m_pendingPromises.add(WTFMove(promise));
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(SERVICE_WORKER)
Copied: trunk/Source/WebCore/workers/service/ExtendableEvent.h (from rev 223560, trunk/Source/WebCore/bindings/js/JSDOMPromise.h) (0 => 223562)
--- trunk/Source/WebCore/workers/service/ExtendableEvent.h (rev 0)
+++ trunk/Source/WebCore/workers/service/ExtendableEvent.h 2017-10-17 18:39:48 UTC (rev 223562)
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * 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. AND ITS CONTRIBUTORS ``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 ITS 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.
+ */
+
+#pragma once
+
+#if ENABLE(SERVICE_WORKER)
+
+#include "Event.h"
+#include "ExtendableEventInit.h"
+#include "JSDOMPromise.h"
+#include <wtf/WeakPtr.h>
+
+namespace WebCore {
+
+class ExtendableEvent : public Event {
+public:
+ static Ref<ExtendableEvent> create(const AtomicString& type, const ExtendableEventInit& initializer, IsTrusted isTrusted = IsTrusted::No)
+ {
+ return adoptRef(*new ExtendableEvent(type, initializer, isTrusted));
+ }
+
+ EventInterface eventInterface() const override { return ExtendableEventInterfaceType; }
+
+ ExceptionOr<void> waitUntil(JSC::ExecState&, JSC::JSValue);
+
+ WEBCORE_EXPORT void onFinishedWaitingForTesting(WTF::Function<void()>&&);
+
+protected:
+ WEBCORE_EXPORT ExtendableEvent(const AtomicString&, const ExtendableEventInit&, IsTrusted);
+
+ WeakPtr<ExtendableEvent> createWeakPtr() { return m_weakPtrFactory.createWeakPtr(*this); }
+
+ void addPendingPromise(Ref<DOMPromise>&&);
+
+private:
+ HashSet<Ref<DOMPromise>> m_pendingPromises;
+ WeakPtrFactory<ExtendableEvent> m_weakPtrFactory;
+ WTF::Function<void()> m_onFinishedWaitingForTesting;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(SERVICE_WORKER)
Added: trunk/Source/WebCore/workers/service/ExtendableEvent.idl (0 => 223562)
--- trunk/Source/WebCore/workers/service/ExtendableEvent.idl (rev 0)
+++ trunk/Source/WebCore/workers/service/ExtendableEvent.idl 2017-10-17 18:39:48 UTC (rev 223562)
@@ -0,0 +1,38 @@
+/*
+* Copyright (C) 2017 Apple Inc. All rights reserved.
+*
+* 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. AND ITS CONTRIBUTORS ``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 ITS 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.
+*/
+
+//FIXME: Should be exposed on ServiceWorker only.
+[
+ Constructor(DOMString type, optional ExtendableEventInit eventInitDict),
+ Conditional=SERVICE_WORKER,
+ EnabledAtRuntime=ServiceWorker,
+ Exposed=(ServiceWorker,Worker,Window),
+ ExportMacro=WEBCORE_EXPORT,
+ JSGenerateToNativeObject,
+]
+interface ExtendableEvent : Event {
+ // FIXME: Binding generator should be able to wrap any non Promise value into a promise and pass it to waitUntil.
+ [CallWith=ScriptState, MayThrowException] void waitUntil(any f);
+};
Copied: trunk/Source/WebCore/workers/service/ExtendableEventInit.h (from rev 223560, trunk/Source/WebCore/bindings/js/JSDOMPromise.h) (0 => 223562)
--- trunk/Source/WebCore/workers/service/ExtendableEventInit.h (rev 0)
+++ trunk/Source/WebCore/workers/service/ExtendableEventInit.h 2017-10-17 18:39:48 UTC (rev 223562)
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * 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. AND ITS CONTRIBUTORS ``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 ITS 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.
+ */
+
+#pragma once
+
+#if ENABLE(SERVICE_WORKER)
+
+#include "Event.h"
+
+namespace WebCore {
+
+struct ExtendableEventInit : EventInit {
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(SERVICE_WORKER)
Copied: trunk/Source/WebCore/workers/service/ExtendableEventInit.idl (from rev 223560, trunk/Source/WebCore/bindings/js/JSDOMPromise.h) (0 => 223562)
--- trunk/Source/WebCore/workers/service/ExtendableEventInit.idl (rev 0)
+++ trunk/Source/WebCore/workers/service/ExtendableEventInit.idl 2017-10-17 18:39:48 UTC (rev 223562)
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * 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. AND ITS CONTRIBUTORS ``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 ITS 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=SERVICE_WORKER,
+]
+dictionary ExtendableEventInit : EventInit {
+};
Added: trunk/Source/WebCore/workers/service/FetchEvent.cpp (0 => 223562)
--- trunk/Source/WebCore/workers/service/FetchEvent.cpp (rev 0)
+++ trunk/Source/WebCore/workers/service/FetchEvent.cpp 2017-10-17 18:39:48 UTC (rev 223562)
@@ -0,0 +1,148 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * 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. AND ITS CONTRIBUTORS ``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 ITS 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.
+ */
+
+#include "config.h"
+#include "FetchEvent.h"
+
+#include "JSFetchResponse.h"
+
+#if ENABLE(SERVICE_WORKER)
+
+namespace WebCore {
+
+FetchEvent::FetchEvent(const AtomicString& type, Init&& initializer, IsTrusted isTrusted)
+ : ExtendableEvent(type, initializer, isTrusted)
+ , m_request(initializer.request.releaseNonNull())
+ , m_clientId(WTFMove(initializer.clientId))
+ , m_reservedClientId(WTFMove(initializer.reservedClientId))
+ , m_targetClientId(WTFMove(initializer.targetClientId))
+{
+}
+
+ExceptionOr<void> FetchEvent::respondWith(JSC::ExecState& state, JSC::JSValue promise)
+{
+ if (isBeingDispatched())
+ return Exception { InvalidStateError, ASCIILiteral("Event is being dispatched") };
+
+ if (m_respondWithEntered)
+ return Exception { InvalidStateError, ASCIILiteral("Event respondWith flag is set") };
+
+ m_respondPromise = DOMPromise::create(state, promise);
+ addPendingPromise(*m_respondPromise);
+
+ m_respondPromise->whenSettled([this, weakThis = createWeakPtr()] () {
+ if (!weakThis)
+ return;
+ promiseIsSettled();
+ });
+
+ stopPropagation();
+ stopImmediatePropagation();
+
+ m_respondWithEntered = true;
+ m_waitToRespond = true;
+
+ return { };
+}
+
+void FetchEvent::onResponse(WTF::Function<void()>&& callback)
+{
+ ASSERT(!m_onResponse);
+ m_onResponse = WTFMove(callback);
+}
+
+void FetchEvent::respondWithError()
+{
+ m_respondWithError = true;
+ processResponse();
+}
+
+void FetchEvent::processResponse()
+{
+ m_respondPromise = nullptr;
+ m_waitToRespond = false;
+ if (auto callback = WTFMove(m_onResponse))
+ callback();
+}
+
+void FetchEvent::promiseIsSettled()
+{
+ if (m_respondPromise->status() == DOMPromise::Status::Rejected) {
+ respondWithError();
+ return;
+ }
+
+ ASSERT(m_respondPromise->status() == DOMPromise::Status::Fulfilled);
+ auto response = JSFetchResponse::toWrapped(m_respondPromise->globalObject()->globalExec()->vm(), m_respondPromise->result());
+ if (!response) {
+ respondWithError();
+ return;
+ }
+
+ if (response->isDisturbedOrLocked()) {
+ respondWithError();
+ return;
+ }
+
+ m_response = WTFMove(response);
+
+ // FIXME: We should process the response and send the body in streaming.
+ if (m_response->hasReadableStreamBody()) {
+ m_response->consumeBodyFromReadableStream([this, protectedThis = makeRef(*this)] (ExceptionOr<RefPtr<SharedBuffer>>&& result) mutable {
+ if (result.hasException()) {
+ respondWithError();
+ return;
+ }
+ m_responseBody = result.releaseReturnValue();
+ processResponse();
+ });
+ return;
+ }
+ if (m_response->isLoading()) {
+ m_response->consumeBodyWhenLoaded([this, protectedThis = makeRef(*this)] (ExceptionOr<RefPtr<SharedBuffer>>&& result) mutable {
+ if (result.hasException()) {
+ respondWithError();
+ return;
+ }
+ m_responseBody = result.releaseReturnValue();
+ processResponse();
+ });
+ return;
+ }
+
+ auto body = m_response->consumeBody();
+ WTF::switchOn(body, [this] (Ref<FormData>&) {
+ // FIXME: Support FormData response bodies.
+ }, [this] (Ref<SharedBuffer>& buffer) {
+ m_responseBody = WTFMove(buffer);
+ }, [] (std::nullptr_t&) {
+ });
+
+ processResponse();
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(SERVICE_WORKER)
Added: trunk/Source/WebCore/workers/service/FetchEvent.h (0 => 223562)
--- trunk/Source/WebCore/workers/service/FetchEvent.h (rev 0)
+++ trunk/Source/WebCore/workers/service/FetchEvent.h 2017-10-17 18:39:48 UTC (rev 223562)
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * 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. AND ITS CONTRIBUTORS ``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 ITS 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.
+ */
+
+#pragma once
+
+#if ENABLE(SERVICE_WORKER)
+
+#include "ExtendableEvent.h"
+#include "FetchRequest.h"
+#include "FetchResponse.h"
+
+namespace WebCore {
+
+class FetchEvent final : public ExtendableEvent {
+public:
+ struct Init : ExtendableEventInit {
+ RefPtr<FetchRequest> request;
+ String clientId;
+ String reservedClientId;
+ String targetClientId;
+ };
+
+ static Ref<FetchEvent> create(const AtomicString& type, Init&& initializer, IsTrusted isTrusted = IsTrusted::No)
+ {
+ return adoptRef(*new FetchEvent(type, WTFMove(initializer), isTrusted));
+ }
+
+ EventInterface eventInterface() const final { return FetchEventInterfaceType; }
+
+ ExceptionOr<void> respondWith(JSC::ExecState&, JSC::JSValue);
+
+ WEBCORE_EXPORT void onResponse(WTF::Function<void()>&&);
+
+ FetchRequest& request() { return m_request.get(); }
+ const String& clientId() const { return m_clientId; }
+ const String& reservedClientId() const { return m_reservedClientId; }
+ const String& targetClientId() const { return m_targetClientId; }
+
+ FetchResponse* response() { return m_response.get(); }
+
+private:
+ FetchEvent(const AtomicString&, Init&&, IsTrusted);
+
+ void promiseIsSettled();
+ void processResponse();
+ void respondWithError();
+
+ Ref<FetchRequest> m_request;
+ String m_clientId;
+ String m_reservedClientId;
+ String m_targetClientId;
+
+ bool m_respondWithEntered { false };
+ bool m_waitToRespond { false };
+ bool m_respondWithError { false };
+ RefPtr<DOMPromise> m_respondPromise;
+
+ WTF::Function<void()> m_onResponse;
+ RefPtr<FetchResponse> m_response;
+ RefPtr<SharedBuffer> m_responseBody;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(SERVICE_WORKER)
Added: trunk/Source/WebCore/workers/service/FetchEvent.idl (0 => 223562)
--- trunk/Source/WebCore/workers/service/FetchEvent.idl (rev 0)
+++ trunk/Source/WebCore/workers/service/FetchEvent.idl 2017-10-17 18:39:48 UTC (rev 223562)
@@ -0,0 +1,51 @@
+/*
+* Copyright (C) 2017 Apple Inc. All rights reserved.
+*
+* 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. AND ITS CONTRIBUTORS ``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 ITS 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.
+*/
+
+//FIXME: Should be exposed on ServiceWorker only.
+[
+ Constructor(DOMString type, FetchEventInit eventInitDict),
+ Conditional=SERVICE_WORKER,
+ JSCustomMarkFunction,
+ EnabledAtRuntime=ServiceWorker,
+ Exposed=(ServiceWorker,Worker,Window),
+ ExportToWrappedFunction,
+ JSGenerateToNativeObject
+]
+interface FetchEvent : ExtendableEvent {
+ [SameObject] readonly attribute FetchRequest request;
+ readonly attribute DOMString clientId;
+ readonly attribute DOMString reservedClientId;
+ readonly attribute DOMString targetClientId;
+
+ // FIXME: Binding generator should be able to wrap any non Promise value into a promise and pass it to respondWith.
+ [CallWith=ScriptState, MayThrowException] void respondWith(any r);
+};
+
+dictionary FetchEventInit : ExtendableEventInit {
+ required FetchRequest request;
+ DOMString clientId = "";
+ DOMString reservedClientId = "";
+ DOMString targetClientId = "";
+};