Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upImplement job queue for ServiceWorkerRegistration #13574
Conversation
highfive
commented
Oct 4, 2016
|
Heads up! This PR modifies the following files:
|
highfive
commented
Oct 4, 2016
|
You likely need a JSAutoCompartment in place before calling resolve_native. |
|
|
|
@creativcoder Were you looking to have these changes reviewed at all, or just asking for help with the crash? |
|
@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. :) |
6f63596
to
9616714
|
Nice work! |
| @@ -0,0 +1,202 @@ | |||
| /* This Source Code Form is subject to the terms of the Mozilla Public | |||
This comment has been minimized.
This comment has been minimized.
jdm
Nov 1, 2016
Member
I mainly try to keep implementations of interfaces in script/dom/, so this file belongs in script/ instead.
| @@ -328,6 +329,8 @@ no_jsmanaged_fields!(UntrustedNodeAddress); | |||
| no_jsmanaged_fields!(LengthOrPercentageOrAuto); | |||
| no_jsmanaged_fields!(RGBA); | |||
| no_jsmanaged_fields!(EuclidLength<Unit, T>); | |||
| no_jsmanaged_fields!(Job); | |||
| no_jsmanaged_fields!(JobQueue); | |||
This comment has been minimized.
This comment has been minimized.
| @@ -200,6 +200,16 @@ impl Promise { | |||
| } | |||
|
|
|||
| #[allow(unsafe_code)] | |||
| pub fn is_settled(&self) -> bool { | |||
| let mut _state = PromiseState::Pending; | |||
| unsafe { _state = GetPromiseState(self.promise_obj()); } | |||
This comment has been minimized.
This comment has been minimized.
| fn eq(&self, other: &Self) -> bool { | ||
| let same_job = self.job_type == other.job_type; | ||
| if same_job { | ||
| return match self.job_type { |
This comment has been minimized.
This comment has been minimized.
| #[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(); |
This comment has been minimized.
This comment has been minimized.
| let container = ServiceWorkerContainer::new_inherited(); | ||
| let client = Client::new(&global.as_window()); | ||
| container.client.set(Some(&*client)); | ||
| reflect_dom_object(box container, global, Wrap) |
This comment has been minimized.
This comment has been minimized.
jdm
Nov 1, 2016
Member
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.
| } | ||
| } | ||
|
|
||
| pub trait Controllable { | ||
| fn set_controller(&self, active_worker: &ServiceWorker); | ||
| } | ||
|
|
||
| // TODO remove this trait usage |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
creativcoder
Nov 6, 2016
Author
Contributor
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).
| #[must_root] | ||
| pub struct Job { | ||
| pub job_type: JobType, | ||
| pub scope_url: Url, | ||
| pub script_url: Url, | ||
| 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>, |
This comment has been minimized.
This comment has been minimized.
jdm
Nov 1, 2016
Member
It's odd to use Trusted and not TrustedPromise here. Why can't we use JS<Client>?
| @@ -111,12 +136,14 @@ impl JobQueue { | |||
| reg: &ServiceWorkerRegistration, | |||
| script_thread: &ScriptThread) { | |||
| 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) { | |||
This comment has been minimized.
This comment has been minimized.
| let host = url.host_str().unwrap(); | ||
| host == "127.0.0.0/8" || host == "::1/128" | ||
| // Step 5 | ||
| } else { url.scheme() == "file" } |
This comment has been minimized.
This comment has been minimized.
Ah, so it took off |
|
@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. |
|
@bors-servo: r+ |
|
|
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 -->
|
|
| // 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" { |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
jdm
Nov 23, 2016
Member
Yes, except that we don't support HTTPS in our automated tests yet. Certainly a FIXME comment here would be an improvement.
This comment has been minimized.
This comment has been minimized.
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. -->
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. -->
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. -->
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. -->
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. -->
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. -->
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. -->
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. -->
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. -->

creativcoder commentedOct 4, 2016
•
edited
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_taskby wrapping it in a runnableRunJobHandler(which holds aTrustedPromise) and trying to callresolve_nativeresults in a crash. stack trace@jdm I am not sure what's causing the crash ?
./mach build -ddoes not report any errors./mach test-tidydoes not report any errorsThis change is