diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2017-05-17 16:20:42 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-17 16:20:42 -0500 |
commit | ac99a48aeaa184d3acdb39d249636a140c4b7393 (patch) | |
tree | f339b7786ad7bb5d89012c4cb9217581d9993d64 /components/script/dom/globalscope.rs | |
parent | bafaae75f47c169078132e761ed2dcfda9541a27 (diff) | |
parent | af8436c9be4c69c07265ab1095f89982b48cdd00 (diff) | |
download | servo-ac99a48aeaa184d3acdb39d249636a140c4b7393.tar.gz servo-ac99a48aeaa184d3acdb39d249636a140c4b7393.zip |
Auto merge of #16814 - asajeffrey:script-worklets, r=jdm
Implement Houdini worklets
<!-- Please describe your changes on the following line: -->
This PR implements the current draft Houdini Worklets specification (https://drafts.css-houdini.org/worklets/).
The implementation is intended to provide a responsive environment for worklet execution, and in particular to ensure that the primary worklet executor does not garbage collect, and does not block loading module code. The implementation does this by providing a thread pool, and performing GC and module loading in a backup thread, not in the primary thread.
---
<!-- 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 #16206
- [x] There are tests for these changes
<!-- 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. -->
<!-- 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/16814)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/globalscope.rs')
-rw-r--r-- | components/script/dom/globalscope.rs | 38 |
1 files changed, 29 insertions, 9 deletions
diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs index 931d1f576aa..ce81958a2cb 100644 --- a/components/script/dom/globalscope.rs +++ b/components/script/dom/globalscope.rs @@ -19,6 +19,7 @@ use dom::event::{Event, EventBubbles, EventCancelable, EventStatus}; use dom::eventtarget::EventTarget; use dom::window::Window; use dom::workerglobalscope::WorkerGlobalScope; +use dom::workletglobalscope::WorkletGlobalScope; use dom_struct::dom_struct; use ipc_channel::ipc::IpcSender; use js::{JSCLASS_IS_DOMJSCLASS, JSCLASS_IS_GLOBAL}; @@ -259,6 +260,10 @@ impl GlobalScope { // https://html.spec.whatwg.org/multipage/#script-settings-for-workers:api-base-url return worker.get_url().clone(); } + if let Some(worker) = self.downcast::<WorkletGlobalScope>() { + // https://drafts.css-houdini.org/worklets/#script-settings-for-worklets + return worker.base_url(); + } unreachable!(); } @@ -270,6 +275,10 @@ impl GlobalScope { if let Some(worker) = self.downcast::<WorkerGlobalScope>() { return worker.get_url().clone(); } + if let Some(worker) = self.downcast::<WorkletGlobalScope>() { + // TODO: is this the right URL to return? + return worker.base_url(); + } unreachable!(); } @@ -349,14 +358,14 @@ impl GlobalScope { /// Evaluate JS code on this global scope. pub fn evaluate_js_on_global_with_result( - &self, code: &str, rval: MutableHandleValue) { + &self, code: &str, rval: MutableHandleValue) -> bool { self.evaluate_script_on_global_with_result(code, "", rval, 1) } /// Evaluate a JS script on this global scope. #[allow(unsafe_code)] pub fn evaluate_script_on_global_with_result( - &self, code: &str, filename: &str, rval: MutableHandleValue, line_number: u32) { + &self, code: &str, filename: &str, rval: MutableHandleValue, line_number: u32) -> bool { let metadata = time::TimerMetadata { url: if filename.is_empty() { self.get_url().as_str().into() @@ -379,16 +388,21 @@ impl GlobalScope { let _ac = JSAutoCompartment::new(cx, globalhandle.get()); let _aes = AutoEntryScript::new(self); let options = CompileOptionsWrapper::new(cx, filename.as_ptr(), line_number); - unsafe { - if !Evaluate2(cx, options.ptr, code.as_ptr(), - code.len() as libc::size_t, - rval) { - debug!("error evaluating JS string"); - report_pending_exception(cx, true); - } + + debug!("evaluating JS string"); + let result = unsafe { + Evaluate2(cx, options.ptr, code.as_ptr(), + code.len() as libc::size_t, + rval) + }; + + if !result { + debug!("error evaluating JS string"); + unsafe { report_pending_exception(cx, true) }; } maybe_resume_unwind(); + result } ) } @@ -468,6 +482,9 @@ impl GlobalScope { if let Some(worker) = self.downcast::<WorkerGlobalScope>() { return worker.perform_a_microtask_checkpoint(); } + if let Some(worker) = self.downcast::<WorkletGlobalScope>() { + return worker.perform_a_microtask_checkpoint(); + } unreachable!(); } @@ -479,6 +496,9 @@ impl GlobalScope { if let Some(worker) = self.downcast::<WorkerGlobalScope>() { return worker.enqueue_microtask(job); } + if let Some(worker) = self.downcast::<WorkletGlobalScope>() { + return worker.enqueue_microtask(job); + } unreachable!(); } |