summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoonchild <mcwerewolf@gmail.com>2018-07-05 22:23:02 +0200
committerGitHub <noreply@github.com>2018-07-05 22:23:02 +0200
commit52d608c670c5c485cfe1139c40ec06d8ef460a26 (patch)
tree91d27a6911b77ae9e70ca3ba64929a92d6ea14ed
parentc3fe7f59c8b6c1a23f5ae85f0697470fad560d68 (diff)
parent3815302230bc043f98667c1ee0de6dee15969034 (diff)
downloaduxp-52d608c670c5c485cfe1139c40ec06d8ef460a26.tar.gz
Merge pull request #599 from janekptacijarabaci/dom_fetch_request_navigate_1
Added support for Request constructor with "mode: navigate"
-rw-r--r--dom/fetch/Request.cpp18
-rw-r--r--dom/tests/mochitest/fetch/test_request.js9
-rw-r--r--dom/workers/test/serviceworkers/fetch_event_worker.js23
-rw-r--r--dom/xhr/XMLHttpRequestWorker.cpp8
4 files changed, 20 insertions, 38 deletions
diff --git a/dom/fetch/Request.cpp b/dom/fetch/Request.cpp
index d3836cda10..7ca5b43c4f 100644
--- a/dom/fetch/Request.cpp
+++ b/dom/fetch/Request.cpp
@@ -338,8 +338,7 @@ Request::Constructor(const GlobalObject& aGlobal,
if (mode == RequestMode::Navigate ||
(aInit.IsAnyMemberPresent() && request->Mode() == RequestMode::Navigate)) {
- aRv.ThrowTypeError<MSG_INVALID_REQUEST_MODE>(NS_LITERAL_STRING("navigate"));
- return nullptr;
+ mode = RequestMode::Same_origin;
}
if (aInit.IsAnyMemberPresent()) {
@@ -374,11 +373,7 @@ Request::Constructor(const GlobalObject& aGlobal,
nsresult rv = principal->CheckMayLoad(uri, /* report */ false,
/* allowIfInheritsPrincipal */ false);
if (NS_FAILED(rv)) {
- nsAutoCString globalOrigin;
- principal->GetOrigin(globalOrigin);
- aRv.ThrowTypeError<MSG_CROSS_ORIGIN_REFERRER_URL>(referrer,
- NS_ConvertUTF8toUTF16(globalOrigin));
- return nullptr;
+ referrerURL.AssignLiteral(kFETCH_CLIENT_REFERRER_STR);
}
}
}
@@ -403,11 +398,10 @@ Request::Constructor(const GlobalObject& aGlobal,
// this work in a single sync loop.
RefPtr<ReferrerSameOriginChecker> checker =
new ReferrerSameOriginChecker(worker, referrerURL, rv);
- checker->Dispatch(Terminating, aRv);
- if (aRv.Failed() || NS_FAILED(rv)) {
- aRv.ThrowTypeError<MSG_CROSS_ORIGIN_REFERRER_URL>(referrer,
- worker->GetLocationInfo().mOrigin);
- return nullptr;
+ IgnoredErrorResult error;
+ checker->Dispatch(Terminating, error);
+ if (error.Failed() || NS_FAILED(rv)) {
+ referrerURL.AssignLiteral(kFETCH_CLIENT_REFERRER_STR);
}
}
}
diff --git a/dom/tests/mochitest/fetch/test_request.js b/dom/tests/mochitest/fetch/test_request.js
index 5be361a463..405767b50a 100644
--- a/dom/tests/mochitest/fetch/test_request.js
+++ b/dom/tests/mochitest/fetch/test_request.js
@@ -152,12 +152,9 @@ function testHeaderGuard() {
}
function testMode() {
- try {
- var req = new Request("http://example.com", {mode: "navigate"});
- ok(false, "Creating a Request with navigate RequestMode should throw a TypeError");
- } catch(e) {
- is(e.name, "TypeError", "Creating a Request with navigate RequestMode should throw a TypeError");
- }
+ var req = new Request("http://example.com", {mode: "navigate"});
+ ok(true, "Creating a Request with navigate RequestMode should not throw.");
+ is(req.mode, "same-origin", "Request mode becomes same-origin");
}
function testMethod() {
diff --git a/dom/workers/test/serviceworkers/fetch_event_worker.js b/dom/workers/test/serviceworkers/fetch_event_worker.js
index 1caef71e89..895128e2c6 100644
--- a/dom/workers/test/serviceworkers/fetch_event_worker.js
+++ b/dom/workers/test/serviceworkers/fetch_event_worker.js
@@ -148,28 +148,21 @@ onfetch = function(ev) {
}
else if (ev.request.url.includes("navigate.html")) {
- var navigateModeCorrectlyChecked = false;
var requests = [ // should not throw
new Request(ev.request),
new Request(ev.request, undefined),
new Request(ev.request, null),
new Request(ev.request, {}),
new Request(ev.request, {someUnrelatedProperty: 42}),
+ new Request(ev.request, {method: "GET"}),
];
- try {
- var request3 = new Request(ev.request, {method: "GET"}); // should throw
- } catch(e) {
- navigateModeCorrectlyChecked = requests[0].mode == "navigate";
- }
- if (navigateModeCorrectlyChecked) {
- ev.respondWith(Promise.resolve(
- new Response("<script>window.frameElement.test_result = true;</script>", {
- headers : {
- "Content-Type": "text/html"
- }
- })
- ));
- }
+ ev.respondWith(Promise.resolve(
+ new Response("<script>window.frameElement.test_result = true;</script>", {
+ headers : {
+ "Content-Type": "text/html"
+ }
+ })
+ ));
}
else if (ev.request.url.includes("nonexistent_worker_script.js")) {
diff --git a/dom/xhr/XMLHttpRequestWorker.cpp b/dom/xhr/XMLHttpRequestWorker.cpp
index b5f853a507..c9e892f26a 100644
--- a/dom/xhr/XMLHttpRequestWorker.cpp
+++ b/dom/xhr/XMLHttpRequestWorker.cpp
@@ -1633,12 +1633,10 @@ XMLHttpRequestWorker::ReleaseProxy(ReleaseType aType)
new SyncTeardownRunnable(mWorkerPrivate, mProxy);
mProxy = nullptr;
- ErrorResult forAssertionsOnly;
+ IgnoredErrorResult forAssertionsOnly;
// This runnable _must_ be executed.
- runnable->Dispatch(Killing, forAssertionsOnly);
- if (forAssertionsOnly.Failed()) {
- NS_ERROR("Failed to dispatch teardown runnable!");
- }
+ runnable->Dispatch(Dead, forAssertionsOnly);
+ MOZ_DIAGNOSTIC_ASSERT(!forAssertionsOnly.Failed());
}
}
}