Skip to content

Implement job queue for ServiceWorkerRegistration - #13574

Merged
bors-servo merged 1 commit into
servo:masterfrom
creativcoder:job-iface
Nov 21, 2016
Merged

bors-servo merged 1 commit into
servo:masterfrom
creativcoder:job-iface

Conversation

@creativcoder

@creativcoder creativcoder commented Oct 4, 2016 •

Copy link
Copy Markdown
Contributor

Fixes #13424
As of now this PR (Work in Progress), will try to implement (partially) on algorithms namely : Schedule_Job, Run_Job, Register_Job.

An issue that needs to be addressed:
Resolving the promise value after queueing it as a dom_manipulation_task by wrapping it in a runnable RunJobHandler (which holds a TrustedPromise) and trying to call resolve_native results in a crash. stack trace

@jdm I am not sure what's causing the crash ?


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

This change is Reviewable

@highfive highfive assigned ghost Oct 4, 2016
@highfive

highfive commented Oct 4, 2016

Copy link
Copy Markdown

Heads up! This PR modifies the following files:

  • @KiChjang: components/script/dom/serviceworkerregistration.rs, components/script/dom/serviceworkerjob.rs, components/script/dom/mod.rs, components/script/dom/bindings/trace.rs, components/script/script_thread.rs, components/script/dom/serviceworkercontainer.rs, components/script/dom/webidls/ServiceWorkerContainer.webidl

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Oct 4, 2016
@highfive

highfive commented Oct 4, 2016

Copy link
Copy Markdown

warning Warning warning

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

@jdm

jdm commented Oct 4, 2016

Copy link
Copy Markdown
Member

You likely need a JSAutoCompartment in place before calling resolve_native.

@ghost ghost assigned jdm and unassigned ghost Oct 5, 2016
@bors-servo

Copy link
Copy Markdown
Contributor

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

@highfive highfive added the S-needs-rebase There are merge conflict errors. label Oct 7, 2016
@jdm

jdm commented Oct 14, 2016

Copy link
Copy Markdown
Member

@creativcoder Were you looking to have these changes reviewed at all, or just asking for help with the crash?

@jdm jdm added S-awaiting-answer Someone asked a question that requires an answer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Oct 14, 2016
@creativcoder

Copy link
Copy Markdown
Contributor Author

@jdm I am at grandma's place and we barely have internet connection here to (sync+build) since the last rebase. I'll continue with the implementation when i reach college (hopefully by 20th) and notify you of code review. :)

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Oct 20, 2016
@creativcoder
creativcoder force-pushed the job-iface branch 5 times, most recently from 6f63596 to 9616714 Compare October 24, 2016 14:56
@jdm jdm removed S-awaiting-answer Someone asked a question that requires an answer. S-needs-rebase There are merge conflict errors. labels Oct 24, 2016
@jdm jdm added the S-needs-rebase There are merge conflict errors. label Nov 1, 2016

@jdm jdm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

@@ -0,0 +1,202 @@
/* This Source Code Form is subject to the terms of the Mozilla Public

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mainly try to keep implementations of interfaces in script/dom/, so this file belongs in script/ instead.

Comment thread components/script/dom/bindings/trace.rs Outdated
no_jsmanaged_fields!(RGBA);
no_jsmanaged_fields!(EuclidLength<Unit, T>);
no_jsmanaged_fields!(Job);
no_jsmanaged_fields!(JobQueue);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks scary. Why not derive JSTraceable instead?

Comment thread components/script/dom/promise.rs Outdated

#[allow(unsafe_code)]
pub fn is_settled(&self) -> bool {
let mut _state = PromiseState::Pending;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let state = unsafe { GetPromiseState(self.promise_object()) };

fn eq(&self, other: &Self) -> bool {
let same_job = self.job_type == other.job_type;
if same_job {
return match self.job_type {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for return.

#[allow(unrooted_must_root)]
// https://w3c.github.io/ServiceWorker/#run-job-algorithm
pub fn run_job(&mut self, run_job_handler: Box<RunJobHandler>, script_thread: &ScriptThread) {
let scope_url = run_job_handler.scope_url.clone();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this clone necessary?

let container = ServiceWorkerContainer::new_inherited();
let client = Client::new(&global.as_window());
container.client.set(Some(&*client));
reflect_dom_object(box container, global, Wrap)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose we create the client first, and pass it as an argument to new_inherited instead. That should let us use JS<Client> instead.

fn set_controller(&self, active_worker: &ServiceWorker);
}

// TODO remove this trait usage

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any more details about this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting the controller attribute to an active worker needs to happen at a much later stage (not during creation of registration), probably during activate algorithm. Since we are passing the client (which can be used to set the controller) with schedule_job, we may not need this trait then. We can set it from job.client.set_controller(sw).

pub promise: Rc<Promise>,
pub equivalent_jobs: Vec<Job>,
// client can be a window client, worker client so `Client` will be an enum in future
pub client: Trusted<Client>,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's odd to use Trusted and not TrustedPromise here. Why can't we use JS<Client>?

let promise = job.promise.clone();
// Initialize to an empty vec
self.0.insert(job.scope_url.clone(), vec![]);
if !self.0.contains_key(&job.scope_url) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we use the Entry API here instead, we can get clearer code I think.

Comment thread components/script/dom/urlhelper.rs Outdated
let host = url.host_str().unwrap();
host == "127.0.0.0/8" || host == "::1/128"
// Step 5
} else { url.scheme() == "file" }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extra space before {, and move the check onto its own line.

@jdm jdm added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Nov 1, 2016
@highfive highfive removed the S-needs-code-changes Changes have not yet been made that were requested by a reviewer. label Nov 6, 2016
@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. S-needs-squash Some (or all) of the commits in the PR should be combined. labels Nov 15, 2016
@creativcoder creativcoder changed the title [WIP] Implement job queue for ServiceWorkerRegistration (Do not merge yet) Implement job queue for ServiceWorkerRegistration Nov 16, 2016
@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit 0621549 with merge b096216...

bors-servo pushed a commit that referenced this pull request Nov 16, 2016
Implement job queue for ServiceWorkerRegistration

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

Fixes #13424
As of now this PR (Work in Progress), will try to implement (partially) on algorithms namely : [Schedule_Job](https://w3c.github.io/ServiceWorker/#schedule-job-algorithm), [Run_Job](https://w3c.github.io/ServiceWorker/#run-job-algorithm), [Register_Job](https://w3c.github.io/ServiceWorker/#register-algorithm).

 An issue that needs to be addressed:
Resolving the promise value after queueing it as a `dom_manipulation_task` by wrapping it in a runnable `RunJobHandler` (which holds a `TrustedPromise`) and trying to call `resolve_native` results in a crash. [stack trace](http://paste.ofcode.org/zdjJ9npBgX6JsyWQkJjnYk)

@jdm I am not sure what's causing the crash ?

---

<!-- 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
- [ ] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- 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/13574)

<!-- Reviewable:end -->
@bors-servo

Copy link
Copy Markdown
Contributor

💔 Test failed - mac-rel-wpt2

@highfive highfive added S-tests-failed The changes caused existing tests to fail. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Nov 16, 2016
@creativcoder

Copy link
Copy Markdown
Contributor Author
Ran 4511 tests finished in 1393.0 seconds.
  • 4510 ran as expected. 1300 tests skipped.
  • 1 tests had unexpected subtest results

Tests with unexpected results:
  ▶ Unexpected subtest result in /_mozilla/mozilla/service-workers/service-worker-registration.html:
  │ FAIL [expected PASS] Test: Active Service Worker ScriptURL property
  │   → assert_equals: expected "http://web-platform.test:8000/_mozilla/mozilla/service-workers/resources/sw.js" but got "http://web-platform.test:8000/_mozilla/mozilla/service-workers/sw.js"
  │ 
  └ @http://web-platform.test:8000/_mozilla/mozilla/service-workers/service-worker-registration.html:43:5

Ah, so it took off resources from the script_url property. Lemme have a look.

@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-tests-failed The changes caused existing tests to fail. labels Nov 17, 2016
@creativcoder

creativcoder commented Nov 17, 2016 •

Copy link
Copy Markdown
Contributor Author

@jdm Ah, yes. So in the wpt tests, https://github.com/servo/servo/blob/master/tests/wpt/mozilla/tests/mozilla/service-workers/service-worker-registration.html#L18 is registered before https://github.com/servo/servo/blob/master/tests/wpt/mozilla/tests/mozilla/service-workers/service-worker-registration.html#L47 . And both have the same scope url (being an empty string). So the update algorithm just returns us, previously registered one.
The ideal behaviour is to update the script with the newer one, which is the part in the second half of update algorithm (just filed an issue #14263 for this next PR). So as of now, I have switched the order of the two tests, to make them pass.
alt text

@jdm

jdm commented Nov 21, 2016

Copy link
Copy Markdown
Member

@bors-servo: r+

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit 114c491 has been approved by jdm

@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. labels Nov 21, 2016
@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit 114c491 with merge 0ea0ade...

bors-servo pushed a commit that referenced this pull request Nov 21, 2016
Implement job queue for ServiceWorkerRegistration

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

Fixes #13424
As of now this PR (Work in Progress), will try to implement (partially) on algorithms namely : [Schedule_Job](https://w3c.github.io/ServiceWorker/#schedule-job-algorithm), [Run_Job](https://w3c.github.io/ServiceWorker/#run-job-algorithm), [Register_Job](https://w3c.github.io/ServiceWorker/#register-algorithm).

 An issue that needs to be addressed:
Resolving the promise value after queueing it as a `dom_manipulation_task` by wrapping it in a runnable `RunJobHandler` (which holds a `TrustedPromise`) and trying to call `resolve_native` results in a crash. [stack trace](http://paste.ofcode.org/zdjJ9npBgX6JsyWQkJjnYk)

@jdm I am not sure what's causing the crash ?

---

<!-- 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
- [ ] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- 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/13574)

<!-- Reviewable:end -->
@bors-servo

Copy link
Copy Markdown
Contributor

@bors-servo
bors-servo merged commit 114c491 into servo:master Nov 21, 2016
@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Nov 21, 2016
// https://w3c.github.io/webappsec-secure-contexts/#is-origin-trustworthy
pub fn is_origin_trustworthy(url: &ServoUrl) -> bool {
// Step 3
if url.scheme() == "http" || url.scheme() == "wss" {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be https instead of http?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, except that we don't support HTTPS in our automated tests yet. Certainly a FIXME comment here would be an improvement.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted. I'll add that comment

bors-servo added a commit that referenced this pull request Apr 4, 2020
Update checking origin trustworthy align to spec

While reading the [spec of ` Is origin potentially trustworthy? `](https://w3c.github.io/webappsec-secure-contexts/#is-origin-trustworthy), I found our second step is wrong; then, I found Josh said we didn't check it with `https` because we didn't support https in tests yet (#13574 (comment)).

IIRC, we've supported https wpt tests now so it might be fine to change it to align with spec.

---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because ___

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
bors-servo added a commit that referenced this pull request Apr 11, 2020
Update checking origin trustworthy align to spec

While reading the [spec of ` Is origin potentially trustworthy? `](https://w3c.github.io/webappsec-secure-contexts/#is-origin-trustworthy), I found our second step is wrong; then, I found Josh said we didn't check it with `https` because we didn't support https in tests yet (#13574 (comment)).

IIRC, we've supported https wpt tests now so it might be fine to change it to align with spec.

---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because ___

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement abstraction of a Job queue for ServiceWorkerRegistration

5 participants