Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ServiceWorkerContainer::Promise #13419

Merged
merged 1 commit into from Oct 31, 2016
Merged

ServiceWorkerContainer::Promise #13419

merged 1 commit into from Oct 31, 2016

Conversation

@Coder206
Copy link
Contributor

Coder206 commented Sep 26, 2016

The purpose of the code changes is to enable the use of promises in the Service Worker container. I also modified the Service Worker test in order to support the promises.

  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #13409 (github issue number if applicable).
  • There are tests for these changes

This change is Reviewable

@highfive
Copy link

highfive commented Sep 26, 2016

Heads up! This PR modifies the following files:

  • @wafflespeanut: python/servo/package_commands.py
  • @KiChjang: components/script/dom/serviceworkercontainer.rs, components/script/dom/webidls/ServiceWorkerContainer.webidl
@highfive
Copy link

highfive commented Sep 26, 2016

warning Warning warning

  • These commits modify script code, but no tests are modified. Please consider adding a test!

// New Step 1

let p = dom::promise::Promise

This comment has been minimized.

Copy link
@Coder206

Coder206 Sep 26, 2016

Author Contributor

Is this right?

This comment has been minimized.

Copy link
@jdm

jdm Sep 26, 2016

Member

I recommend looking for uses of Promise::new in the codebase to base your changes off of.

@@ -6,21 +6,21 @@
[Pref="dom.serviceworker.enabled", Exposed=(Window,Worker)]
interface ServiceWorkerContainer : EventTarget {
[Unforgeable] readonly attribute ServiceWorker? controller;
//[SameObject] readonly attribute Promise<ServiceWorkerRegistration> ready;
[SameObject] readonly attribute Promise<ServiceWorkerRegistration> ready;

This comment has been minimized.

Copy link
@Coder206

Coder206 Sep 26, 2016

Author Contributor

Just preparing for eventual functionality

This comment has been minimized.

Copy link
@jdm

jdm Sep 26, 2016

Member

This should be replacing the register underneath it.

@Coder206
Copy link
Contributor Author

Coder206 commented Sep 26, 2016

It's the first time I do one of these, I am new to the process and I am having trouble understanding how to translate the pseudo code from Service Worker Nightly Container:Register into Rust for Servo

@Coder206
Copy link
Contributor Author

Coder206 commented Sep 26, 2016

I think this PR is for @jdm

Copy link
Member

jdm left a comment

You will definitely need to be able to build Servo locally to be able to make these changes effectively.

@@ -6,21 +6,21 @@
[Pref="dom.serviceworker.enabled", Exposed=(Window,Worker)]
interface ServiceWorkerContainer : EventTarget {
[Unforgeable] readonly attribute ServiceWorker? controller;
//[SameObject] readonly attribute Promise<ServiceWorkerRegistration> ready;
[SameObject] readonly attribute Promise<ServiceWorkerRegistration> ready;

This comment has been minimized.

Copy link
@jdm

jdm Sep 26, 2016

Member

This should be replacing the register underneath it.

Let scopeURL be null.
If options.scope is present, set scopeURL to the result of parsing options.scope with the context object’s relevant settings object’s API base URL.
Invoke Start Register with scopeURL, scriptURL, p, client, client’s creation URL and options.type.
Return p. */

This comment has been minimized.

Copy link
@jdm

jdm Sep 26, 2016

Member

As mentioned in #13409, I don't think there's any need to focus on the specification. It's enough to know that it says to create a promise and return it, and either resolve it with a successful service worker or else reject it with an error (instead of returning error values directly).

//[NewObject] /*Promise<any>*/ any getRegistration(optional USVString clientURL = "");
//[NewObject] /* Promise */<sequence<ServiceWorkerRegistration>> getRegistrations();
[NewObject] Promise<any> any getRegistration(optional USVString clientURL = "");
[NewObject] Promise <sequence<ServiceWorkerRegistration>> getRegistrations();

This comment has been minimized.

Copy link
@jdm

jdm Sep 26, 2016

Member

We shouldn't be modifying any other methods or properties in this file for the purposes of these changes.

//[SameObject] readonly attribute Promise<ServiceWorkerRegistration> ready;

[NewObject, Throws] ServiceWorkerRegistration register(USVString scriptURL, optional RegistrationOptions options);
[SameObject] readonly attribute Promise<ServiceWorkerRegistration> ready;

This comment has been minimized.

Copy link
@Coder206

Coder206 Sep 26, 2016

Author Contributor

@jdm When running ./mach build -d, I am seeing this error:

WebIDL.WebIDLError: error: Unresolved type '<unresolved scope>::Promise'., /home/user/servo/components/script/dom/webidls/ServiceWorkerContainer.webidl line 9:34
  [SameObject] readonly attribute Promise<ServiceWorkerRegistration> ready;

I am not sure how to solve it. Do you have any ideas?

This comment has been minimized.

Copy link
@jdm

jdm Sep 26, 2016

Member

Your branch is based off of a master commit from Sept 6. You need to be using 2b1a39c or more recent instead.

This comment has been minimized.

Copy link
@creativcoder

creativcoder Sep 26, 2016

Contributor

@Coder206 As an added note, We shouldn't be needing to make changes to the ready method for the relevant issue. You just have to make changes to the register api declaration from:

[NewObject, Throws] ServiceWorkerRegistration register(USVString scriptURL, optional RegistrationOptions options);

to

[NewObject] Promise<ServiceWorkerRegistration> register(USVString scriptURL, optional RegistrationOptions options);

This will result in a compilation error notifying you that, register method should return a Rc<Promise> type. So after that you need to use a combination of resolve_native and reject_error method to make the register method return a resolved/reject promise. Correct me if am wrong @jdm

Rebase your current branch to the master branch before making these changes as mentioned by jdm

This comment has been minimized.

Copy link
@Coder206

Coder206 Sep 27, 2016

Author Contributor

@creativcoder I am not sure how to get started with resolve_native and reject_error. How do I implement that in my code? (does it go in the return)

This comment has been minimized.

Copy link
@creativcoder

creativcoder Sep 27, 2016

Contributor

We don't need to implement those methods, they are already implemented. In the Register method we just need to call reject_error on places where we return an Err value and resolve_native at places where we return an Ok value on the promise object.

You can have a look at my branch here, for how that is being done.

@Coder206
Copy link
Contributor Author

Coder206 commented Sep 26, 2016

@jdm So I need to rebase my code to the newest commit?

@jdm
Copy link
Member

jdm commented Sep 26, 2016

@Coder206 That would be easiest, yes.

@Coder206
Copy link
Contributor Author

Coder206 commented Sep 27, 2016

Looks like an extra commit was added here. I am going to remove it as soon as possible.

@jdm
Copy link
Member

jdm commented Sep 27, 2016

The test file mentioned in the original issue still needs modifying, too.

@Coder206
Copy link
Contributor Author

Coder206 commented Sep 27, 2016

@jdm Thanks for the reminder

}
// Step 12
if scope.path().to_ascii_lowercase().contains("%2f") ||
scope.path().to_ascii_lowercase().contains("%5c") {
return Err(Error::Type("Scope URL contains forbidden characters".to_owned()));
return {

This comment has been minimized.

Copy link
@KiChjang

KiChjang Sep 27, 2016

Member

What's the purpose of this return keyword here and the block?

This comment has been minimized.

Copy link
@jdm

jdm Oct 13, 2016

Member

This should still be addressed.

@bors-servo
Copy link
Contributor

bors-servo commented Sep 28, 2016

The latest upstream changes (presumably #13474) made this pull request unmergeable. Please resolve the merge conflicts.

Copy link
Member

jdm left a comment

This looks good with a few point addressed.

console.log("Registered script source: "+ navigator.serviceWorker.controller.scriptURL);
document.getElementById('iframe_sw').src = 'demo_iframe.html';
post_message('/demo_iframe');
/* global navigator */

This comment has been minimized.

Copy link
@jdm

jdm Oct 4, 2016

Member

I'm not sure what this comment means.

console.log("From client worker registered: ", navigator.serviceWorker.controller);
console.log("Registered script source: "+ navigator.serviceWorker.controller.scriptURL);
}).catch(function(error) {
console.log("Error in loading: " + navigator.serviceWorker.controller.scriptURL);

This comment has been minimized.

Copy link
@jdm

jdm Oct 4, 2016

Member

Same as previous.

console.log("Registered script source: "+ navigator.serviceWorker.controller.scriptURL);
post_message('/dashboard');
}).catch(function(error) {
console.log("Error in loading: " + navigator.serviceWorker.controller.scriptURL);

This comment has been minimized.

Copy link
@jdm

jdm Oct 4, 2016

Member

Same.

console.log("Registered script source: "+ navigator.serviceWorker.controller.scriptURL);
post_message('/profile');
}).catch(function(error) {
console.log("Error in loading: " + navigator.serviceWorker.controller.scriptURL);

This comment has been minimized.

Copy link
@jdm

jdm Oct 4, 2016

Member

Same.

@jdm
Copy link
Member

jdm commented Oct 27, 2016

@Coder206 Did you run the test after making the changes? My assumption when people make changes to test code is that the tests pass before they push their changes.

@Coder206
Copy link
Contributor Author

Coder206 commented Oct 27, 2016

@jdm Yes, that's when I received the error from above. I haven't rebased though with the new changes. The next push will have the tests verified with the new master.

@Coder206
Copy link
Contributor Author

Coder206 commented Oct 27, 2016

Sorry for the inconvenience.

@Coder206
Copy link
Contributor Author

Coder206 commented Oct 30, 2016

I am unable to get the error messages that @KiChjang has shared with me. Here is the output of my attempt to test my changes. Please note, this is the result despite I only corrected the first error mentioned above:

page-shot-2016-10-30 novnc

Errors I am unsure what they mean:

▶ Unexpected subtest result in /_mozilla/mozilla/service-workers/service-worker-registration.html:
  │ FAIL [expected PASS] Test: Throws Error when Invalid Url Path
  │   → promise.then is not a function
  │ 
  │ promise_rejects@http://web-platform.test:8000/resources/testharness.js:547:16
  │ @http://web-platform.test:8000/_mozilla/mozilla/service-workers/service-worker-registration.html:34:10
  │ Test.prototype.step@http://web-platform.test:8000/resources/testharness.js:1401:20
  └ promise_test/tests.promise_tests<@http://web-platform.test:8000/resources/testharness.js:530:36

  ▶ Unexpected subtest result in /_mozilla/mozilla/service-workers/service-worker-registration.html:
  │ FAIL [expected PASS] Test: Throws Error when Invalid Scope
  │   → promise.then is not a function
  │ 
  │ promise_rejects@http://web-platform.test:8000/resources/testharness.js:547:16
  │ @http://web-platform.test:8000/_mozilla/mozilla/service-workers/service-worker-registration.html:40:10
  │ Test.prototype.step@http://web-platform.test:8000/resources/testharness.js:1401:20
  └ promise_test/tests.promise_tests<@http://web-platform.test:8000/resources/testharness.js:530:36

Any ideas or suggestions?

@jdm
Copy link
Member

jdm commented Oct 30, 2016

@Coder206 The main problem you're seeing is due to using the test directory (which doesn't exist) instead of tests (which does exist).

function() { var sw_reg = register_sw('./in%5Csome%5fdir/sw.js'); },
"Invalid URL Path");
promise_test(function (p) {
promise_rejects(p, new TypeError(), register_sw('./in%5Csome%5fdir/sw.js'));

This comment has been minimized.

Copy link
@Coder206

Coder206 Oct 30, 2016

Author Contributor

@jdm I don't fancy an inline code like this but the code below would fail:

promise_test(function (p) {
  promise_rejects(p, new TypeError(), function () {
    register_sw('./in%5Csome%5fdir/sw.js');
  });
}, "Test: Throws Error when Invalid Url Path");

This comment has been minimized.

Copy link
@jdm

jdm Oct 30, 2016

Member

That's because it needs to return the result of register_sw.

This comment has been minimized.

Copy link
@Coder206

Coder206 Oct 31, 2016

Author Contributor

@jdm I am still getting promise.then() is not a function when I return, I am trying to figure out why and how to correct it from the testharness.js from the web platfor test folder

function() { var sw_reg = register_sw('sw.js', './mal%5fformed/sco%5Cpe/'); },
"Invalid URL Path");
promise_test(function (p) {
return promise_rejects(p, new TypeError(), register_sw('sw.js', './mal%5fformed/sco%5Cpe/'));

This comment has been minimized.

Copy link
@Coder206

Coder206 Oct 30, 2016

Author Contributor

@jdm Same for this one.

Copy link
Member

jdm left a comment

One teeny tiny change and then we can merge this!

}, "Test: Active Service Worker ScriptURL property");

function bar() {

This comment has been minimized.

Copy link
@jdm

jdm Oct 31, 2016

Member

This function isn't used anywhere.

This comment has been minimized.

Copy link
@Coder206

Coder206 Oct 31, 2016

Author Contributor

@jdm Yes, sorry it was test code that escaped... Will remove it asap.

The purpose of the code changes is to enable the use of promises in the Service Worker container. I also modified the Service Worker test in order to support the promises.
@Coder206
Copy link
Contributor Author

Coder206 commented Oct 31, 2016

@jdm So I made the last changes requested and tested mach build -d and ./mach test-wpt tests/wpt/mozilla/tests/mozilla/service-workers/service-worker-registration.html both yielded success. Anything else to test or fix?

@jdm
Copy link
Member

jdm commented Oct 31, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Oct 31, 2016

📌 Commit e6b8790 has been approved by jdm

@bors-servo
Copy link
Contributor

bors-servo commented Oct 31, 2016

Testing commit e6b8790 with merge 0d46c7c...

bors-servo added a commit that referenced this pull request Oct 31, 2016
ServiceWorkerContainer::Promise

<!-- Please describe your changes on the following line: -->

<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #13409  (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---

This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13419)

<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Oct 31, 2016

💔 Test failed - linux-rel-wpt

@highfive
Copy link

highfive commented Oct 31, 2016

  ▶ FAIL [expected PASS] /_mozilla/css/incremental_trailing_whitespace_a.html
  └   → /_mozilla/css/incremental_trailing_whitespace_a.html da54041086f2975f8e3c776d2283ad6609e6862a
/_mozilla/css/incremental_trailing_whitespace_ref.html f5d0147c8bddbdc772a7e5e86c7c9e433fcd486b
Testing da54041086f2975f8e3c776d2283ad6609e6862a == f5d0147c8bddbdc772a7e5e86c7c9e433fcd486b
@jdm
Copy link
Member

jdm commented Oct 31, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Oct 31, 2016

Previous build results for arm32, arm64, linux-dev, linux-rel-css, mac-dev-unit, mac-rel-css, mac-rel-wpt1, mac-rel-wpt2, windows-dev are reusable. Rebuilding only linux-rel-wpt...

@bors-servo
Copy link
Contributor

bors-servo commented Oct 31, 2016

@bors-servo bors-servo merged commit e6b8790 into servo:master Oct 31, 2016
2 of 3 checks passed
2 of 3 checks passed
continuous-integration/appveyor/pr AppVeyor build failed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

7 participants
You can’t perform that action at this time.