Add preliminary support for fetch event
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Oct 2017 18:39:48 +0000 (18:39 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Oct 2017 18:39:48 +0000 (18:39 +0000)
https://bugs.webkit.org/show_bug.cgi?id=178171

Patch by Youenn Fablet <youenn@apple.com> on 2017-10-17
Reviewed by Chris Dumez.

Source/JavaScriptCore:

Adding events

* runtime/JSPromise.h:

Source/WebCore:

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:

LayoutTests:

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:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@223562 268f45cc-cd09-0410-ab3c-d52691b4dbfc

32 files changed:
LayoutTests/ChangeLog
LayoutTests/http/wpt/resources/gc.js [new file with mode: 0644]
LayoutTests/http/wpt/service-workers/extendableEvent.https-expected.txt [new file with mode: 0644]
LayoutTests/http/wpt/service-workers/extendableEvent.https.html [new file with mode: 0644]
LayoutTests/http/wpt/service-workers/fetchEvent.https-expected.txt [new file with mode: 0644]
LayoutTests/http/wpt/service-workers/fetchEvent.https.html [new file with mode: 0644]
LayoutTests/platform/ios-wk1/TestExpectations
LayoutTests/platform/mac-wk1/TestExpectations
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/JSPromise.h
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/DerivedSources.make
Source/WebCore/Modules/fetch/FetchRequest.idl
Source/WebCore/Modules/fetch/FetchResponse.idl
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/js/JSDOMPromise.cpp [new file with mode: 0644]
Source/WebCore/bindings/js/JSDOMPromise.h
Source/WebCore/bindings/js/JSFetchEventCustom.cpp [new file with mode: 0644]
Source/WebCore/bindings/js/WebCoreBuiltinNames.h
Source/WebCore/dom/EventNames.in
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl
Source/WebCore/workers/service/ExtendableEvent.cpp [new file with mode: 0644]
Source/WebCore/workers/service/ExtendableEvent.h [new file with mode: 0644]
Source/WebCore/workers/service/ExtendableEvent.idl [new file with mode: 0644]
Source/WebCore/workers/service/ExtendableEventInit.h [new file with mode: 0644]
Source/WebCore/workers/service/ExtendableEventInit.idl [new file with mode: 0644]
Source/WebCore/workers/service/FetchEvent.cpp [new file with mode: 0644]
Source/WebCore/workers/service/FetchEvent.h [new file with mode: 0644]
Source/WebCore/workers/service/FetchEvent.idl [new file with mode: 0644]

index a7c1a2f8a6cc4098f4849c1c57e186a335c5d2e1..f333b356365b9ea334bba6a7747150839190fb4c 100644 (file)
@@ -1,3 +1,20 @@
+2017-10-17  Youenn Fablet  <youenn@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  <youenn@apple.com>
 
         Cache API implementation should be able to compute storage size for WebKit client applications.
diff --git a/LayoutTests/http/wpt/resources/gc.js b/LayoutTests/http/wpt/resources/gc.js
new file mode 100644 (file)
index 0000000..bd35110
--- /dev/null
@@ -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);
+    }
+}
diff --git a/LayoutTests/http/wpt/service-workers/extendableEvent.https-expected.txt b/LayoutTests/http/wpt/service-workers/extendableEvent.https-expected.txt
new file mode 100644 (file)
index 0000000..5f7f6c0
--- /dev/null
@@ -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 
+
diff --git a/LayoutTests/http/wpt/service-workers/extendableEvent.https.html b/LayoutTests/http/wpt/service-workers/extendableEvent.https.html
new file mode 100644 (file)
index 0000000..1637b47
--- /dev/null
@@ -0,0 +1,63 @@
+<!DOCTYPE html>
+<title>Service Worker Extendable Event</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<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>
diff --git a/LayoutTests/http/wpt/service-workers/fetchEvent.https-expected.txt b/LayoutTests/http/wpt/service-workers/fetchEvent.https-expected.txt
new file mode 100644 (file)
index 0000000..9e2beaa
--- /dev/null
@@ -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 
+
diff --git a/LayoutTests/http/wpt/service-workers/fetchEvent.https.html b/LayoutTests/http/wpt/service-workers/fetchEvent.https.html
new file mode 100644 (file)
index 0000000..8a39458
--- /dev/null
@@ -0,0 +1,107 @@
+<!DOCTYPE html>
+<title>Service Worker Fetch Event</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/WebKit/resources/gc.js"></script>
+<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>
index 1e8ba4950d580bc3d26f81475c5bfeb3081f0bf4..2e45ab4ea50c03934aaf00d0fc48d106a993f3be 100644 (file)
@@ -9,6 +9,7 @@ editing/input/focus-change-with-marked-text.html [ Pass ]
 
 # 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 ]
 
index 43a1c4a39f21f18aa84d2c97afbeda104fb357d9..01e98d4bfceb6e7584369b0d8a23d3dc83cc6878 100644 (file)
@@ -104,6 +104,7 @@ http/tests/ssl/media-stream
 
 # 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 ]
 
index 719b3c50518c2c2d2bc3984dac9eea210f83f9d3..ac730b7c3bb257547c66d3e8a3965c2aa79d5c53 100644 (file)
@@ -1,3 +1,14 @@
+2017-10-17  Youenn Fablet  <youenn@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.tea@gmail.com>
 
         [JSC] __proto__ getter should be fast
index e83672cbbacb994626a6f7575994baecf4d75122..7056eb9ba14d729d1c54b751d094e4f2117aed5a 100644 (file)
@@ -44,7 +44,7 @@ public:
         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;
 
index 921b73a2dd387379e3b9a0e562282957eee761dd..6038974e940eec323cff3c223c5527a3ff4a9fa7 100644 (file)
@@ -786,6 +786,9 @@ set(WebCore_NON_SVG_IDL_FILES
     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 @@ set(WebCore_SOURCES
     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 @@ set(WebCore_SOURCES
     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
index edbdf270a0a12e3fdc0d46468915be515ac45077..1320f1dacc118c5724b9702baf345fb716ba06ef 100644 (file)
@@ -1,3 +1,63 @@
+2017-10-17  Youenn Fablet  <youenn@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.noble@apple.com>
 
         Leak of one AVSampleCursor inside ImageDecoderAVFObjC::createFrameImageAtIndex()
index aa54576c0630c74d256b433adc0eebe5ee1d813d..021d2bb7c6039e04497da12bd68cb1f2c2486cdf 100644 (file)
@@ -910,6 +910,9 @@ JS_BINDING_IDLS = \
     $(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 \
index 181c02acf4d9ca95ec09b11e64248d3e7bdab128..f39fd4cd98fdc6d8587e06400f54fecd3dadd010 100644 (file)
@@ -39,6 +39,7 @@ typedef (Blob or BufferSource or DOMFormData or URLSearchParams or ReadableStrea
     ConstructorCallWith=ScriptExecutionContext,
     EnabledAtRuntime=FetchAPI,
     Exposed=(Window,Worker),
+    GenerateIsReachable=Impl,
     InterfaceName=Request,
 ] interface FetchRequest {
     readonly attribute ByteString method;
index a063b2703a2354d04af2e40bbae420758e306311..335b78fa75318e197f708c3e9cad2aed4d483c5f 100644 (file)
@@ -43,7 +43,7 @@ dictionary FetchResponseInit {
     ConstructorCallWith=ScriptExecutionContext,
     ConstructorMayThrowException,
     EnabledAtRuntime=FetchAPI,
-    ExportToWrappedFunction,
+    ExportMacro=WEBCORE_EXPORT,
     Exposed=(Window,Worker),
     InterfaceName=Response,
 ] interface FetchResponse {
index 09b023b095c2c2419759235edf6aacdb3971c4b3..1bb0858bb97bba766534c94b8f1deb0740094032 100644 (file)
                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 */; };
                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 */; };
                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 */; };
                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; };
                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>"; };
                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>"; };
                5182C24C1F3142090059BA7C /* ServiceWorkers */ = {
                        isa = PBXGroup;
                        children = (
+                               7E4C96D91AD4483500365A53 /* JSExtendableEvent.h */,
+                               7E4C96D91AD4483500365A52 /* JSFetchEvent.h */,
                                51F886BE1F32920700C193EF /* JSNavigatorServiceWorker.cpp */,
                                51F886BF1F32920700C193EF /* JSNavigatorServiceWorker.h */,
                                5182C2531F3142500059BA7C /* JSServiceWorker.cpp */,
                                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;
                        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 */,
                        isa = PBXGroup;
                        children = (
                                DEC2975D1B4DEB2A005F5945 /* JSCustomEventCustom.cpp */,
+                               4131F3B11F9552810059995A /* JSFetchEventCustom.cpp */,
                                BCE7B1920D4E86960075A539 /* JSHistoryCustom.cpp */,
                                410B7E711045FAB000D8224F /* JSMessageEventCustom.cpp */,
                                A85F22081430377D007CC884 /* JSPopStateEventCustom.cpp */,
                                41DEFCB41E56C1B9000D9E5F /* JSDOMMapLike.h */,
                                7C8139A41ED6281D00CE26E8 /* JSDOMOperation.h */,
                                7C8139A51ED6281D00CE26E8 /* JSDOMOperationReturningPromise.h */,
+                               41AF379C1F8DB1B100111C31 /* JSDOMPromise.cpp */,
                                E37C864F1EB63E2D0087C6CA /* JSDOMPromise.h */,
                                E172AF8D1811BC3700FBADB9 /* JSDOMPromiseDeferred.cpp */,
                                E172AF8E1811BC3700FBADB9 /* JSDOMPromiseDeferred.h */,
                                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 */,
                                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 */,
                                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 */,
                                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 */,
                                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 */,
                                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 */,
                                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 */,
diff --git a/Source/WebCore/bindings/js/JSDOMPromise.cpp b/Source/WebCore/bindings/js/JSDOMPromise.cpp
new file mode 100644 (file)
index 0000000..5943cf9
--- /dev/null
@@ -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;
+}
+
+}
index 85d614db7214b1956f5d152525286fef633734c0..a36850783540670949b480f6f106daa15af482f4 100644 (file)
@@ -33,6 +33,7 @@ namespace WebCore {
 
 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 @@ public:
         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)
diff --git a/Source/WebCore/bindings/js/JSFetchEventCustom.cpp b/Source/WebCore/bindings/js/JSFetchEventCustom.cpp
new file mode 100644 (file)
index 0000000..47ef6b1
--- /dev/null
@@ -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());
+}
+
+}
index 2cd79c1cdd3039bca67b8c6954f7764d810f3444..5e3dc543b70ba140b5f140e8ffe93282c7213ec3 100644 (file)
@@ -43,7 +43,9 @@ namespace WebCore {
     macro(DataTransferItem) \
     macro(DataTransferItemList) \
     macro(DocumentTimeline) \
+    macro(ExtendableEvent) \
     macro(FederatedCredential) \
+    macro(FetchEvent) \
     macro(FileSystem) \
     macro(FileSystemDirectoryEntry) \
     macro(FileSystemDirectoryReader) \
index 79ff3fcacf8788540d6ef90ae8b0c6ca337199a4..e842bd390a64d1705ec3b9c81685490955f1fb75 100644 (file)
@@ -10,7 +10,9 @@ ClipboardEvent
 CloseEvent
 CompositionEvent
 CustomEvent
+ExtendableEvent conditional=SERVICE_WORKER
 ErrorEvent
+FetchEvent conditional=SERVICE_WORKER
 FocusEvent
 HashChangeEvent
 InputEvent
index 2b3a197a708abbc187b9819773a045197da98511..2c6d54792422163902e5f8403a91776ef5dc91b9 100644 (file)
@@ -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 @@ uint64_t Internals::responseSizeWithPadding(FetchResponse& response) const
     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
index 16696682abba3256f8345de3149e7a70c6a1f9bb..bd4904554027cff4dcacec3e71bba54c458503cc 100644 (file)
@@ -50,6 +50,8 @@ class DOMURL;
 class DOMWindow;
 class Document;
 class Element;
+class ExtendableEvent;
+class FetchEvent;
 class FetchResponse;
 class File;
 class Frame;
@@ -606,6 +608,12 @@ public:
 
     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;
index 82de510c6401faf8becb4645822bb1054420fdda..15acb7c98d7b69384522db362eea57b3181139e3 100644 (file)
@@ -553,4 +553,8 @@ enum EventThrottlingBehavior {
     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();
 };
diff --git a/Source/WebCore/workers/service/ExtendableEvent.cpp b/Source/WebCore/workers/service/ExtendableEvent.cpp
new file mode 100644 (file)
index 0000000..d761003
--- /dev/null
@@ -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)
diff --git a/Source/WebCore/workers/service/ExtendableEvent.h b/Source/WebCore/workers/service/ExtendableEvent.h
new file mode 100644 (file)
index 0000000..6ea39f8
--- /dev/null
@@ -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)
diff --git a/Source/WebCore/workers/service/ExtendableEvent.idl b/Source/WebCore/workers/service/ExtendableEvent.idl
new file mode 100644 (file)
index 0000000..57ef5d0
--- /dev/null
@@ -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);
+};
diff --git a/Source/WebCore/workers/service/ExtendableEventInit.h b/Source/WebCore/workers/service/ExtendableEventInit.h
new file mode 100644 (file)
index 0000000..d9cf34b
--- /dev/null
@@ -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)
diff --git a/Source/WebCore/workers/service/ExtendableEventInit.idl b/Source/WebCore/workers/service/ExtendableEventInit.idl
new file mode 100644 (file)
index 0000000..5279d9f
--- /dev/null
@@ -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 {
+};
diff --git a/Source/WebCore/workers/service/FetchEvent.cpp b/Source/WebCore/workers/service/FetchEvent.cpp
new file mode 100644 (file)
index 0000000..ba95b84
--- /dev/null
@@ -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)
diff --git a/Source/WebCore/workers/service/FetchEvent.h b/Source/WebCore/workers/service/FetchEvent.h
new file mode 100644 (file)
index 0000000..57a174f
--- /dev/null
@@ -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)
diff --git a/Source/WebCore/workers/service/FetchEvent.idl b/Source/WebCore/workers/service/FetchEvent.idl
new file mode 100644 (file)
index 0000000..d428d45
--- /dev/null
@@ -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 = "";
+};