Bug 1238213 - Make FetchEvent.request non-nullable; r=baku

This commit is contained in:
Ehsan Akhgari 2016-01-08 22:35:22 -05:00
parent f04686995e
commit ade9847331
7 changed files with 27 additions and 23 deletions

View File

@ -11,7 +11,7 @@
Func="mozilla::dom::workers::ServiceWorkerVisible",
Exposed=(ServiceWorker)]
interface FetchEvent : ExtendableEvent {
[SameObject] readonly attribute Request? request;
[SameObject] readonly attribute Request request;
readonly attribute DOMString? clientId;
readonly attribute boolean isReload;
@ -20,7 +20,7 @@ interface FetchEvent : ExtendableEvent {
};
dictionary FetchEventInit : EventInit {
Request request;
required Request request;
DOMString? clientId = null;
boolean isReload = false;
};

View File

@ -100,8 +100,7 @@ FetchEvent::Constructor(const GlobalObject& aGlobal,
bool trusted = e->Init(owner);
e->InitEvent(aType, aOptions.mBubbles, aOptions.mCancelable);
e->SetTrusted(trusted);
e->mRequest = aOptions.mRequest.WasPassed() ?
&aOptions.mRequest.Value() : nullptr;
e->mRequest = aOptions.mRequest;
e->mClientId = aOptions.mClientId;
e->mIsReload = aOptions.mIsReload;
return e.forget();

View File

@ -145,8 +145,9 @@ public:
}
Request*
GetRequest_() const
Request_() const
{
MOZ_ASSERT(mRequest);
return mRequest;
}

View File

@ -1239,8 +1239,7 @@ private:
request->Redirect() == RequestRedirect::Manual);
RootedDictionary<FetchEventInit> init(aCx);
init.mRequest.Construct();
init.mRequest.Value() = request;
init.mRequest = request;
init.mBubbles = false;
init.mCancelable = true;
if (!mClientId.IsEmpty()) {

View File

@ -393,7 +393,7 @@ fetch('fetchevent-request')
.then(function(res) {
return res.text();
}).then(function(body) {
my_ok(body == "nullable", "FetchEvent.request must be nullable");
my_ok(body == "non-nullable", "FetchEvent.request must be non-nullable");
finish();
}, function(err) {
my_ok(false, "A promise was rejected with " + err);

View File

@ -293,10 +293,15 @@ onfetch = function(ev) {
}
else if (ev.request.url.includes('fetchevent-request')) {
if ((new FetchEvent("foo")).request === null) {
ev.respondWith(new Response("nullable"));
} else {
ev.respondWith(Promise.reject());
var threw = false;
try {
new FetchEvent("foo");
} catch(e) {
if (e.name == "TypeError") {
threw = true;
}
} finally {
ev.respondWith(new Response(threw ? "non-nullable" : "nullable"));
}
}
};

View File

@ -71,36 +71,36 @@ promise_test(function(t) {
}, 'Cache');
test(function() {
var req = new Request('http://{{host}}/',
{method: 'POST',
headers: [['Content-Type', 'Text/Html']]});
assert_equals(
new ExtendableEvent('ExtendableEvent').type,
'ExtendableEvent', 'Type of ExtendableEvent should be ExtendableEvent');
assert_equals(
new FetchEvent('FetchEvent').type,
new FetchEvent('FetchEvent', {request: req}).type,
'FetchEvent', 'Type of FetchEvent should be FetchEvent');
assert_equals(
new FetchEvent('FetchEvent').cancelable,
new FetchEvent('FetchEvent', {request: req}).cancelable,
false, 'Default FetchEvent.cancelable should be false');
assert_equals(
new FetchEvent('FetchEvent').bubbles,
new FetchEvent('FetchEvent', {request: req}).bubbles,
false, 'Default FetchEvent.bubbles should be false');
assert_equals(
new FetchEvent('FetchEvent').clientId,
new FetchEvent('FetchEvent', {request: req}).clientId,
null, 'Default FetchEvent.clientId should be null');
assert_equals(
new FetchEvent('FetchEvent').isReload,
new FetchEvent('FetchEvent', {request: req}).isReload,
false, 'Default FetchEvent.isReload should be false');
assert_equals(
new FetchEvent('FetchEvent', {cancelable: false}).cancelable,
new FetchEvent('FetchEvent', {request: req, cancelable: false}).cancelable,
false, 'FetchEvent.cancelable should be false');
assert_equals(
new FetchEvent('FetchEvent', {clientId : 'test-client-id'}).clientId, 'test-client-id',
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', {isReload : true}).isReload, true,
new FetchEvent('FetchEvent', {request: req, isReload : true}).isReload, true,
'FetchEvent.isReload with option {isReload : true} should be true');
var req = new Request('http://{{host}}/',
{method: 'POST',
headers: [['Content-Type', 'Text/Html']]});
assert_equals(
new FetchEvent('FetchEvent', {request : req, isReload : true}).request.url,
'http://{{host}}/',