From af8436c9be4c69c07265ab1095f89982b48cdd00 Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Mon, 3 Apr 2017 14:35:57 -0500 Subject: Implemented Houdini worklets. --- components/script/script_runtime.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index c4f90edf8ea..8c243b18695 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -74,6 +74,7 @@ pub enum ScriptThreadEventCategory { UpdateReplacedElement, WebSocketEvent, WorkerEvent, + WorkletEvent, ServiceWorkerEvent, EnterFullscreen, ExitFullscreen, -- cgit v1.2.3 From a47e94c8f6b37de9845c824c6a8a488728a1d0c1 Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Tue, 13 Jun 2017 10:46:59 -0500 Subject: Added Debug implementations. --- components/script/script_runtime.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 8c243b18695..efbdb6bdc40 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -27,6 +27,7 @@ use script_thread::{Runnable, STACK_ROOTS, trace_thread}; use servo_config::opts; use servo_config::prefs::PREFS; use std::cell::Cell; +use std::fmt; use std::io::{Write, stdout}; use std::marker::PhantomData; use std::os; @@ -45,6 +46,15 @@ pub enum CommonScriptMsg { RunnableMsg(ScriptThreadEventCategory, Box), } +impl fmt::Debug for CommonScriptMsg { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match *self { + CommonScriptMsg::CollectReports(_) => write!(f, "CollectReports(...)"), + CommonScriptMsg::RunnableMsg(category, _) => write!(f, "RunnableMsg({:?}, ...)", category), + } + } +} + /// A cloneable interface for communicating with an event loop. pub trait ScriptChan: JSTraceable { /// Send a message to the associated event loop. -- cgit v1.2.3 From fb843c251aff388c31f22d668319e04ad52d9663 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Jim=C3=A9nez=20Moreno?= Date: Wed, 30 Aug 2017 17:52:18 +0200 Subject: Make Performance Timeline API work in Workers --- components/script/script_runtime.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index efbdb6bdc40..7236bc96ecc 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -88,7 +88,8 @@ pub enum ScriptThreadEventCategory { ServiceWorkerEvent, EnterFullscreen, ExitFullscreen, - WebVREvent + WebVREvent, + PerformanceTimelineTask, } /// An interface for receiving ScriptMsg values in an event loop. Used for synchronous DOM -- cgit v1.2.3 From 7ca52152a63615b38cecd9e149032bba712d3bc5 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Sat, 16 Sep 2017 01:25:51 +0200 Subject: Put the name of runnables in Debug for CommonScriptMsg --- components/script/script_runtime.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 7236bc96ecc..d0473d2469c 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -50,7 +50,9 @@ impl fmt::Debug for CommonScriptMsg { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { CommonScriptMsg::CollectReports(_) => write!(f, "CollectReports(...)"), - CommonScriptMsg::RunnableMsg(category, _) => write!(f, "RunnableMsg({:?}, ...)", category), + CommonScriptMsg::RunnableMsg(ref category, ref runnable) => { + f.debug_tuple("RunnableMsg").field(category).field(runnable).finish() + }, } } } -- cgit v1.2.3 From 56117d31856be46d7df417e659a4406305b4e258 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Sat, 16 Sep 2017 02:09:26 +0200 Subject: Rename Runnable to Task The changes are: * `*Runnable` -> `*Task`; * `RunnableMsg` -> `Task`; * `RunnableWrapper` -> `TaskCanceller`; * `MainThreadRunnable` -> `MainThreadTask`; * `wrap_runnable` -> `wrap_task`; * `get_runnable_wrapper` -> `task_canceller`; * `handler` -> `run`; * `main_thread_handler` -> `run_with_script_thread`. --- components/script/script_runtime.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index d0473d2469c..b12649668e5 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -23,7 +23,7 @@ use js::panic::wrap_panic; use js::rust::Runtime; use microtask::{EnqueuedPromiseCallback, Microtask}; use profile_traits::mem::{Report, ReportKind, ReportsChan}; -use script_thread::{Runnable, STACK_ROOTS, trace_thread}; +use script_thread::{STACK_ROOTS, Task, trace_thread}; use servo_config::opts; use servo_config::prefs::PREFS; use std::cell::Cell; @@ -43,15 +43,15 @@ pub enum CommonScriptMsg { /// supplied channel. CollectReports(ReportsChan), /// Generic message that encapsulates event handling. - RunnableMsg(ScriptThreadEventCategory, Box), + Task(ScriptThreadEventCategory, Box), } impl fmt::Debug for CommonScriptMsg { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { CommonScriptMsg::CollectReports(_) => write!(f, "CollectReports(...)"), - CommonScriptMsg::RunnableMsg(ref category, ref runnable) => { - f.debug_tuple("RunnableMsg").field(category).field(runnable).finish() + CommonScriptMsg::Task(ref category, ref task) => { + f.debug_tuple("Task").field(category).field(task).finish() }, } } -- cgit v1.2.3 From 46628fba05a548c1c2141d7c709b6e5d812f3114 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Sun, 17 Sep 2017 16:41:54 +0200 Subject: Move Task to its own module --- components/script/script_runtime.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index b12649668e5..270dd0cdafe 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -23,7 +23,7 @@ use js::panic::wrap_panic; use js::rust::Runtime; use microtask::{EnqueuedPromiseCallback, Microtask}; use profile_traits::mem::{Report, ReportKind, ReportsChan}; -use script_thread::{STACK_ROOTS, Task, trace_thread}; +use script_thread::{STACK_ROOTS, trace_thread}; use servo_config::opts; use servo_config::prefs::PREFS; use std::cell::Cell; @@ -35,6 +35,7 @@ use std::os::raw::c_void; use std::panic::AssertUnwindSafe; use std::ptr; use style::thread_state; +use task::Task; use time::{Tm, now}; /// Common messages used to control the event loops in both the script and the worker -- cgit v1.2.3 From f088b708c93e0a131cbfccf5c9b3797018f1c4ee Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Wed, 20 Sep 2017 09:40:53 +0200 Subject: Make Task require Send --- components/script/script_runtime.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 270dd0cdafe..45f3d6a7ea3 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -44,7 +44,7 @@ pub enum CommonScriptMsg { /// supplied channel. CollectReports(ReportsChan), /// Generic message that encapsulates event handling. - Task(ScriptThreadEventCategory, Box), + Task(ScriptThreadEventCategory, Box), } impl fmt::Debug for CommonScriptMsg { -- cgit v1.2.3 From 52527d6f9dfaae13458059243d975f5336bdead4 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Wed, 20 Sep 2017 09:59:52 +0200 Subject: Rename Task to TaskBox --- components/script/script_runtime.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 45f3d6a7ea3..be5acd33a6a 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -35,7 +35,7 @@ use std::os::raw::c_void; use std::panic::AssertUnwindSafe; use std::ptr; use style::thread_state; -use task::Task; +use task::TaskBox; use time::{Tm, now}; /// Common messages used to control the event loops in both the script and the worker @@ -44,7 +44,7 @@ pub enum CommonScriptMsg { /// supplied channel. CollectReports(ReportsChan), /// Generic message that encapsulates event handling. - Task(ScriptThreadEventCategory, Box), + Task(ScriptThreadEventCategory, Box), } impl fmt::Debug for CommonScriptMsg { -- cgit v1.2.3 From 0e3c54c1911ba2c3bf305ee04f04fcd9bf2fc2fe Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Mon, 25 Sep 2017 23:30:24 +0200 Subject: Rename dom::bindings::js to dom::bindings::root --- components/script/script_runtime.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index be5acd33a6a..e437e1a6001 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -6,8 +6,8 @@ //! script thread, the dom, and the worker threads. use dom::bindings::codegen::Bindings::PromiseBinding::PromiseJobCallback; -use dom::bindings::js::{RootCollection, RootCollectionPtr, trace_roots}; use dom::bindings::refcounted::{LiveDOMReferences, trace_refcounted_objects}; +use dom::bindings::root::{RootCollection, RootCollectionPtr, trace_roots}; use dom::bindings::settings_stack; use dom::bindings::trace::{JSTraceable, trace_traceables}; use dom::bindings::utils::DOM_CALLBACKS; -- cgit v1.2.3 From 8d566fbc3c1954b2da0b0e185e224d5bde99b8e3 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Wed, 27 Sep 2017 13:58:59 +0200 Subject: Move script_runtime::StackRootTLS to root::ThreadLocalStackRoots --- components/script/script_runtime.rs | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index e437e1a6001..7985f562cbe 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -7,7 +7,7 @@ use dom::bindings::codegen::Bindings::PromiseBinding::PromiseJobCallback; use dom::bindings::refcounted::{LiveDOMReferences, trace_refcounted_objects}; -use dom::bindings::root::{RootCollection, RootCollectionPtr, trace_roots}; +use dom::bindings::root::trace_roots; use dom::bindings::settings_stack; use dom::bindings::trace::{JSTraceable, trace_traceables}; use dom::bindings::utils::DOM_CALLBACKS; @@ -23,13 +23,12 @@ use js::panic::wrap_panic; use js::rust::Runtime; use microtask::{EnqueuedPromiseCallback, Microtask}; use profile_traits::mem::{Report, ReportKind, ReportsChan}; -use script_thread::{STACK_ROOTS, trace_thread}; +use script_thread::trace_thread; use servo_config::opts; use servo_config::prefs::PREFS; use std::cell::Cell; use std::fmt; use std::io::{Write, stdout}; -use std::marker::PhantomData; use std::os; use std::os::raw::c_void; use std::panic::AssertUnwindSafe; @@ -102,23 +101,6 @@ pub trait ScriptPort { fn recv(&self) -> Result; } -pub struct StackRootTLS<'a>(PhantomData<&'a u32>); - -impl<'a> StackRootTLS<'a> { - pub fn new(roots: &'a RootCollection) -> StackRootTLS<'a> { - STACK_ROOTS.with(|ref r| { - r.set(Some(RootCollectionPtr(roots as *const _))) - }); - StackRootTLS(PhantomData) - } -} - -impl<'a> Drop for StackRootTLS<'a> { - fn drop(&mut self) { - STACK_ROOTS.with(|ref r| r.set(None)); - } -} - /// SM callback for promise job resolution. Adds a promise callback to the current /// global's microtask queue. #[allow(unsafe_code)] -- cgit v1.2.3 From c075372739004ac8f9452755f060e2b8919ae61f Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Thu, 19 Oct 2017 10:15:44 -0400 Subject: Do not trace Rust values when thread is shutting down. --- components/script/script_runtime.rs | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 7985f562cbe..7d3e5e60e1c 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -20,7 +20,7 @@ use js::jsapi::{JSGCMode, JSGCParamKey, JS_SetGCParameter, JS_SetGlobalJitCompil use js::jsapi::{JSJitCompilerOption, JS_SetOffthreadIonCompilationEnabled, JS_SetParallelParsingEnabled}; use js::jsapi::{JSObject, RuntimeOptionsRef, SetPreserveWrapperCallback, SetEnqueuePromiseJobCallback}; use js::panic::wrap_panic; -use js::rust::Runtime; +use js::rust::Runtime as RustRuntime; use microtask::{EnqueuedPromiseCallback, Microtask}; use profile_traits::mem::{Report, ReportKind, ReportsChan}; use script_thread::trace_thread; @@ -29,6 +29,7 @@ use servo_config::prefs::PREFS; use std::cell::Cell; use std::fmt; use std::io::{Write, stdout}; +use std::ops::Deref; use std::os; use std::os::raw::c_void; use std::panic::AssertUnwindSafe; @@ -120,13 +121,28 @@ unsafe extern "C" fn enqueue_job(cx: *mut JSContext, }), false) } +#[derive(JSTraceable)] +pub struct Runtime(RustRuntime); + +impl Drop for Runtime { + fn drop(&mut self) { + THREAD_ACTIVE.with(|t| t.set(false)); + } +} + +impl Deref for Runtime { + type Target = RustRuntime; + fn deref(&self) -> &RustRuntime { + &self.0 + } +} + #[allow(unsafe_code)] pub unsafe fn new_rt_and_cx() -> Runtime { LiveDOMReferences::initialize(); - let runtime = Runtime::new().unwrap(); + let runtime = RustRuntime::new().unwrap(); JS_AddExtraGCRootsTracer(runtime.rt(), Some(trace_rust_roots), ptr::null_mut()); - JS_AddExtraGCRootsTracer(runtime.rt(), Some(trace_refcounted_objects), ptr::null_mut()); // Needed for debug assertions about whether GC is running. if cfg!(debug_assertions) { @@ -293,7 +309,7 @@ pub unsafe fn new_rt_and_cx() -> Runtime { } } - runtime + Runtime(runtime) } #[allow(unsafe_code)] @@ -399,12 +415,20 @@ unsafe extern "C" fn debug_gc_callback(_rt: *mut JSRuntime, status: JSGCStatus, } } +thread_local!( + static THREAD_ACTIVE: Cell = Cell::new(true); +); + #[allow(unsafe_code)] unsafe extern fn trace_rust_roots(tr: *mut JSTracer, _data: *mut os::raw::c_void) { + if !THREAD_ACTIVE.with(|t| t.get()) { + return; + } debug!("starting custom root handler"); trace_thread(tr); trace_traceables(tr); trace_roots(tr); + trace_refcounted_objects(tr); settings_stack::trace(tr); debug!("done custom root handler"); } -- cgit v1.2.3 From 2ffbe5398970e54ad55d3e53b495ee6651b64f4c Mon Sep 17 00:00:00 2001 From: ddh Date: Mon, 2 Oct 2017 14:52:39 +0100 Subject: added time to interactive metrics, refactored metrics to use traits changed task macro to take pipeline info --- components/script/script_runtime.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 7d3e5e60e1c..57e1bbd0755 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -22,6 +22,7 @@ use js::jsapi::{JSObject, RuntimeOptionsRef, SetPreserveWrapperCallback, SetEnqu use js::panic::wrap_panic; use js::rust::Runtime as RustRuntime; use microtask::{EnqueuedPromiseCallback, Microtask}; +use msg::constellation_msg::PipelineId; use profile_traits::mem::{Report, ReportKind, ReportsChan}; use script_thread::trace_thread; use servo_config::opts; @@ -44,14 +45,14 @@ pub enum CommonScriptMsg { /// supplied channel. CollectReports(ReportsChan), /// Generic message that encapsulates event handling. - Task(ScriptThreadEventCategory, Box), + Task(ScriptThreadEventCategory, Box, Option), } impl fmt::Debug for CommonScriptMsg { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { CommonScriptMsg::CollectReports(_) => write!(f, "CollectReports(...)"), - CommonScriptMsg::Task(ref category, ref task) => { + CommonScriptMsg::Task(ref category, ref task, _) => { f.debug_tuple("Task").field(category).field(task).finish() }, } -- cgit v1.2.3 From 29b4eec14187c96a1518af6a954bd00194375382 Mon Sep 17 00:00:00 2001 From: Bastien Orivel Date: Mon, 30 Oct 2017 12:15:30 +0100 Subject: Bump bitflags to 1.0 in every servo crate --- components/script/script_runtime.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 57e1bbd0755..ee089a2ee77 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -35,7 +35,7 @@ use std::os; use std::os::raw::c_void; use std::panic::AssertUnwindSafe; use std::ptr; -use style::thread_state; +use style::thread_state::{self, ThreadState}; use task::TaskBox; use time::{Tm, now}; @@ -411,8 +411,8 @@ unsafe extern "C" fn gc_slice_callback(_rt: *mut JSRuntime, progress: GCProgress #[allow(unsafe_code)] unsafe extern "C" fn debug_gc_callback(_rt: *mut JSRuntime, status: JSGCStatus, _data: *mut os::raw::c_void) { match status { - JSGCStatus::JSGC_BEGIN => thread_state::enter(thread_state::IN_GC), - JSGCStatus::JSGC_END => thread_state::exit(thread_state::IN_GC), + JSGCStatus::JSGC_BEGIN => thread_state::enter(ThreadState::IN_GC), + JSGCStatus::JSGC_END => thread_state::exit(ThreadState::IN_GC), } } -- cgit v1.2.3 From 7b0b2aae7791d0f08fe82cb85d348ec3ffe2c2d9 Mon Sep 17 00:00:00 2001 From: Adrian Wielgosik Date: Sat, 6 Jan 2018 23:11:02 +0100 Subject: Remove js.mem.gc.refresh_frame_slices.enabled pref Clean up after gecko bug 1421358 --- components/script/script_runtime.rs | 1 - 1 file changed, 1 deletion(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index ee089a2ee77..cf42b47c5bb 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -260,7 +260,6 @@ pub unsafe fn new_rt_and_cx() -> Runtime { if let Some(val) = PREFS.get("js.mem.gc.dynamic_mark_slice.enabled").as_boolean() { JS_SetGCParameter(runtime.rt(), JSGCParamKey::JSGC_DYNAMIC_MARK_SLICE, val as u32); } - // TODO: handle js.mem.gc.refresh_frame_slices.enabled if let Some(val) = PREFS.get("js.mem.gc.dynamic_heap_growth.enabled").as_boolean() { JS_SetGCParameter(runtime.rt(), JSGCParamKey::JSGC_DYNAMIC_HEAP_GROWTH, val as u32); } -- cgit v1.2.3 From 7f7fc917586fa5ea9c0681f7a479c7ec8ad69019 Mon Sep 17 00:00:00 2001 From: Anthony Weston Date: Sun, 18 Mar 2018 21:20:20 -0400 Subject: Pass new method in CollectServoSizes for accurate DOM heap use reporting --- components/script/script_runtime.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index cf42b47c5bb..f758a1131c0 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -6,6 +6,8 @@ //! script thread, the dom, and the worker threads. use dom::bindings::codegen::Bindings::PromiseBinding::PromiseJobCallback; +use dom::bindings::conversions::get_dom_class; +use dom::bindings::conversions::private_from_object; use dom::bindings::refcounted::{LiveDOMReferences, trace_refcounted_objects}; use dom::bindings::root::trace_roots; use dom::bindings::settings_stack; @@ -21,6 +23,7 @@ use js::jsapi::{JSJitCompilerOption, JS_SetOffthreadIonCompilationEnabled, JS_Se use js::jsapi::{JSObject, RuntimeOptionsRef, SetPreserveWrapperCallback, SetEnqueuePromiseJobCallback}; use js::panic::wrap_panic; use js::rust::Runtime as RustRuntime; +use malloc_size_of::MallocSizeOfOps; use microtask::{EnqueuedPromiseCallback, Microtask}; use msg::constellation_msg::PipelineId; use profile_traits::mem::{Report, ReportKind, ReportsChan}; @@ -312,6 +315,24 @@ pub unsafe fn new_rt_and_cx() -> Runtime { Runtime(runtime) } +#[allow(unsafe_code)] +unsafe extern "C" fn get_size(obj: *mut JSObject) -> usize { + match get_dom_class(obj) { + Ok(v) => { + let dom_object = private_from_object(obj) as *const c_void; + + if dom_object.is_null() { + return 0; + } + let mut ops = MallocSizeOfOps::new(::servo_allocator::usable_size, None, None); + (v.malloc_size_of)(&mut ops, dom_object) + } + Err(_e) => { + return 0; + } + } +} + #[allow(unsafe_code)] pub fn get_reports(cx: *mut JSContext, path_seg: String) -> Vec { let mut reports = vec![]; @@ -319,7 +340,7 @@ pub fn get_reports(cx: *mut JSContext, path_seg: String) -> Vec { unsafe { let rt = JS_GetRuntime(cx); let mut stats = ::std::mem::zeroed(); - if CollectServoSizes(rt, &mut stats) { + if CollectServoSizes(rt, &mut stats, Some(get_size)) { let mut report = |mut path_suffix, kind, size| { let mut path = path![path_seg, "js"]; path.append(&mut path_suffix); -- cgit v1.2.3 From 74c1e00d8163f255bb4141ff3549bbdedd7ea766 Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Fri, 1 Jun 2018 17:24:25 -0500 Subject: Upgraded to SM 60 --- components/script/script_runtime.rs | 125 +++++++++++++++++++++--------------- 1 file changed, 75 insertions(+), 50 deletions(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index f758a1131c0..b5d598d1c79 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -15,12 +15,15 @@ use dom::bindings::trace::{JSTraceable, trace_traceables}; use dom::bindings::utils::DOM_CALLBACKS; use dom::globalscope::GlobalScope; use js::glue::CollectServoSizes; +use js::glue::SetBuildId; use js::jsapi::{DisableIncrementalGC, GCDescription, GCProgress, HandleObject}; -use js::jsapi::{JSContext, JS_GetRuntime, JSRuntime, JSTracer, SetDOMCallbacks, SetGCSliceCallback}; +use js::jsapi::{JSContext, JSTracer, SetDOMCallbacks, SetGCSliceCallback}; use js::jsapi::{JSGCInvocationKind, JSGCStatus, JS_AddExtraGCRootsTracer, JS_SetGCCallback}; use js::jsapi::{JSGCMode, JSGCParamKey, JS_SetGCParameter, JS_SetGlobalJitCompilerOption}; use js::jsapi::{JSJitCompilerOption, JS_SetOffthreadIonCompilationEnabled, JS_SetParallelParsingEnabled}; -use js::jsapi::{JSObject, RuntimeOptionsRef, SetPreserveWrapperCallback, SetEnqueuePromiseJobCallback}; +use js::jsapi::{JSObject, SetPreserveWrapperCallback, SetEnqueuePromiseJobCallback}; +use js::jsapi::{SetBuildIdOp, BuildIdCharVector}; +use js::jsapi::ContextOptionsRef; use js::panic::wrap_panic; use js::rust::Runtime as RustRuntime; use malloc_size_of::MallocSizeOfOps; @@ -112,6 +115,7 @@ pub trait ScriptPort { unsafe extern "C" fn enqueue_job(cx: *mut JSContext, job: HandleObject, _allocation_site: HandleObject, + _incumbent_global: HandleObject, _data: *mut c_void) -> bool { wrap_panic(AssertUnwindSafe(|| { //XXXjdm - use a different global now? @@ -145,52 +149,68 @@ impl Deref for Runtime { pub unsafe fn new_rt_and_cx() -> Runtime { LiveDOMReferences::initialize(); let runtime = RustRuntime::new().unwrap(); + let cx = runtime.cx(); - JS_AddExtraGCRootsTracer(runtime.rt(), Some(trace_rust_roots), ptr::null_mut()); + JS_AddExtraGCRootsTracer(cx, Some(trace_rust_roots), ptr::null_mut()); // Needed for debug assertions about whether GC is running. if cfg!(debug_assertions) { - JS_SetGCCallback(runtime.rt(), Some(debug_gc_callback), ptr::null_mut()); + JS_SetGCCallback(cx, Some(debug_gc_callback), ptr::null_mut()); } if opts::get().gc_profile { - SetGCSliceCallback(runtime.rt(), Some(gc_slice_callback)); + SetGCSliceCallback(cx, Some(gc_slice_callback)); } unsafe extern "C" fn empty_wrapper_callback(_: *mut JSContext, _: *mut JSObject) -> bool { true } - SetDOMCallbacks(runtime.rt(), &DOM_CALLBACKS); - SetPreserveWrapperCallback(runtime.rt(), Some(empty_wrapper_callback)); + SetDOMCallbacks(cx, &DOM_CALLBACKS); + SetPreserveWrapperCallback(cx, Some(empty_wrapper_callback)); // Pre barriers aren't working correctly at the moment - DisableIncrementalGC(runtime.rt()); + DisableIncrementalGC(cx); - SetEnqueuePromiseJobCallback(runtime.rt(), Some(enqueue_job), ptr::null_mut()); + SetEnqueuePromiseJobCallback(cx, Some(enqueue_job), ptr::null_mut()); - set_gc_zeal_options(runtime.rt()); + set_gc_zeal_options(cx); // Enable or disable the JITs. - let rt_opts = &mut *RuntimeOptionsRef(runtime.rt()); + let cx_opts = &mut *ContextOptionsRef(cx); if let Some(val) = PREFS.get("js.baseline.enabled").as_boolean() { - rt_opts.set_baseline_(val); + cx_opts.set_baseline_(val); } if let Some(val) = PREFS.get("js.ion.enabled").as_boolean() { - rt_opts.set_ion_(val); + cx_opts.set_ion_(val); } if let Some(val) = PREFS.get("js.asmjs.enabled").as_boolean() { - rt_opts.set_asmJS_(val); + cx_opts.set_asmJS_(val); + } + if let Some(val) = PREFS.get("js.wasm.enabled").as_boolean() { + cx_opts.set_wasm_(val); + if val { + // If WASM is enabled without setting the buildIdOp, + // initializing a module will report an out of memory error. + // https://dxr.mozilla.org/mozilla-central/source/js/src/wasm/WasmTypes.cpp#458 + SetBuildIdOp(cx, Some(servo_build_id)); + } + } + if let Some(val) = PREFS.get("js.wasm.baseline.enabled").as_boolean() { + cx_opts.set_wasmBaseline_(val); + } + if let Some(val) = PREFS.get("js.wasm.ion.enabled").as_boolean() { + cx_opts.set_wasmIon_(val); } if let Some(val) = PREFS.get("js.strict.enabled").as_boolean() { - rt_opts.set_extraWarnings_(val); + cx_opts.set_extraWarnings_(val); } // TODO: handle js.strict.debug.enabled // TODO: handle js.throw_on_asmjs_validation_failure (needs new Spidermonkey) if let Some(val) = PREFS.get("js.native_regexp.enabled").as_boolean() { - rt_opts.set_nativeRegExp_(val); + cx_opts.set_nativeRegExp_(val); } if let Some(val) = PREFS.get("js.parallel_parsing.enabled").as_boolean() { - JS_SetParallelParsingEnabled(runtime.rt(), val); + JS_SetParallelParsingEnabled(cx, val); } if let Some(val) = PREFS.get("js.offthread_compilation_enabled").as_boolean() { - JS_SetOffthreadIonCompilationEnabled(runtime.rt(), val); + JS_SetOffthreadIonCompilationEnabled(cx, val); } if let Some(val) = PREFS.get("js.baseline.unsafe_eager_compilation.enabled").as_boolean() { let trigger: i32 = if val { @@ -198,7 +218,7 @@ pub unsafe fn new_rt_and_cx() -> Runtime { } else { -1 }; - JS_SetGlobalJitCompilerOption(runtime.rt(), + JS_SetGlobalJitCompilerOption(cx, JSJitCompilerOption::JSJITCOMPILER_BASELINE_WARMUP_TRIGGER, trigger as u32); } @@ -208,7 +228,7 @@ pub unsafe fn new_rt_and_cx() -> Runtime { } else { -1 }; - JS_SetGlobalJitCompilerOption(runtime.rt(), + JS_SetGlobalJitCompilerOption(cx, JSJitCompilerOption::JSJITCOMPILER_ION_WARMUP_TRIGGER, trigger as u32); } @@ -217,11 +237,11 @@ pub unsafe fn new_rt_and_cx() -> Runtime { // TODO: handle js.throw_on_debugee_would_run (needs new Spidermonkey) // TODO: handle js.dump_stack_on_debugee_would_run (needs new Spidermonkey) if let Some(val) = PREFS.get("js.werror.enabled").as_boolean() { - rt_opts.set_werror_(val); + cx_opts.set_werror_(val); } // TODO: handle js.shared_memory.enabled if let Some(val) = PREFS.get("js.mem.high_water_mark").as_i64() { - JS_SetGCParameter(runtime.rt(), JSGCParamKey::JSGC_MAX_MALLOC_BYTES, val as u32 * 1024 * 1024); + JS_SetGCParameter(cx, JSGCParamKey::JSGC_MAX_MALLOC_BYTES, val as u32 * 1024 * 1024); } if let Some(val) = PREFS.get("js.mem.max").as_i64() { let max = if val <= 0 || val >= 0x1000 { @@ -229,11 +249,11 @@ pub unsafe fn new_rt_and_cx() -> Runtime { } else { val * 1024 * 1024 }; - JS_SetGCParameter(runtime.rt(), JSGCParamKey::JSGC_MAX_BYTES, max as u32); + JS_SetGCParameter(cx, JSGCParamKey::JSGC_MAX_BYTES, max as u32); } // NOTE: This is disabled above, so enabling it here will do nothing for now. if let Some(val) = PREFS.get("js.mem.gc.incremental.enabled").as_boolean() { - let compartment = if let Some(val) = PREFS.get("js.mem.gc.per_compartment.enabled").as_boolean() { + let compartment = if let Some(val) = PREFS.get("js.mem.gc.per_zone.enabled").as_boolean() { val } else { false @@ -241,74 +261,74 @@ pub unsafe fn new_rt_and_cx() -> Runtime { let mode = if val { JSGCMode::JSGC_MODE_INCREMENTAL } else if compartment { - JSGCMode::JSGC_MODE_COMPARTMENT + JSGCMode::JSGC_MODE_ZONE } else { JSGCMode::JSGC_MODE_GLOBAL }; - JS_SetGCParameter(runtime.rt(), JSGCParamKey::JSGC_MODE, mode as u32); + JS_SetGCParameter(cx, JSGCParamKey::JSGC_MODE, mode as u32); } if let Some(val) = PREFS.get("js.mem.gc.incremental.slice_ms").as_i64() { if val >= 0 && val < 100000 { - JS_SetGCParameter(runtime.rt(), JSGCParamKey::JSGC_SLICE_TIME_BUDGET, val as u32); + JS_SetGCParameter(cx, JSGCParamKey::JSGC_SLICE_TIME_BUDGET, val as u32); } } if let Some(val) = PREFS.get("js.mem.gc.compacting.enabled").as_boolean() { - JS_SetGCParameter(runtime.rt(), JSGCParamKey::JSGC_COMPACTING_ENABLED, val as u32); + JS_SetGCParameter(cx, JSGCParamKey::JSGC_COMPACTING_ENABLED, val as u32); } if let Some(val) = PREFS.get("js.mem.gc.high_frequency_time_limit_ms").as_i64() { if val >= 0 && val < 10000 { - JS_SetGCParameter(runtime.rt(), JSGCParamKey::JSGC_HIGH_FREQUENCY_TIME_LIMIT, val as u32); + JS_SetGCParameter(cx, JSGCParamKey::JSGC_HIGH_FREQUENCY_TIME_LIMIT, val as u32); } } if let Some(val) = PREFS.get("js.mem.gc.dynamic_mark_slice.enabled").as_boolean() { - JS_SetGCParameter(runtime.rt(), JSGCParamKey::JSGC_DYNAMIC_MARK_SLICE, val as u32); + JS_SetGCParameter(cx, JSGCParamKey::JSGC_DYNAMIC_MARK_SLICE, val as u32); } if let Some(val) = PREFS.get("js.mem.gc.dynamic_heap_growth.enabled").as_boolean() { - JS_SetGCParameter(runtime.rt(), JSGCParamKey::JSGC_DYNAMIC_HEAP_GROWTH, val as u32); + JS_SetGCParameter(cx, JSGCParamKey::JSGC_DYNAMIC_HEAP_GROWTH, val as u32); } if let Some(val) = PREFS.get("js.mem.gc.low_frequency_heap_growth").as_i64() { if val >= 0 && val < 10000 { - JS_SetGCParameter(runtime.rt(), JSGCParamKey::JSGC_LOW_FREQUENCY_HEAP_GROWTH, val as u32); + JS_SetGCParameter(cx, JSGCParamKey::JSGC_LOW_FREQUENCY_HEAP_GROWTH, val as u32); } } if let Some(val) = PREFS.get("js.mem.gc.high_frequency_heap_growth_min").as_i64() { if val >= 0 && val < 10000 { - JS_SetGCParameter(runtime.rt(), JSGCParamKey::JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MIN, val as u32); + JS_SetGCParameter(cx, JSGCParamKey::JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MIN, val as u32); } } if let Some(val) = PREFS.get("js.mem.gc.high_frequency_heap_growth_max").as_i64() { if val >= 0 && val < 10000 { - JS_SetGCParameter(runtime.rt(), JSGCParamKey::JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MAX, val as u32); + JS_SetGCParameter(cx, JSGCParamKey::JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MAX, val as u32); } } if let Some(val) = PREFS.get("js.mem.gc.high_frequency_low_limit_mb").as_i64() { if val >= 0 && val < 10000 { - JS_SetGCParameter(runtime.rt(), JSGCParamKey::JSGC_HIGH_FREQUENCY_LOW_LIMIT, val as u32); + JS_SetGCParameter(cx, JSGCParamKey::JSGC_HIGH_FREQUENCY_LOW_LIMIT, val as u32); } } if let Some(val) = PREFS.get("js.mem.gc.high_frequency_high_limit_mb").as_i64() { if val >= 0 && val < 10000 { - JS_SetGCParameter(runtime.rt(), JSGCParamKey::JSGC_HIGH_FREQUENCY_HIGH_LIMIT, val as u32); + JS_SetGCParameter(cx, JSGCParamKey::JSGC_HIGH_FREQUENCY_HIGH_LIMIT, val as u32); } } - if let Some(val) = PREFS.get("js.mem.gc.allocation_threshold_mb").as_i64() { + if let Some(val) = PREFS.get("js.mem.gc.allocation_threshold_factor").as_i64() { if val >= 0 && val < 10000 { - JS_SetGCParameter(runtime.rt(), JSGCParamKey::JSGC_ALLOCATION_THRESHOLD, val as u32); + JS_SetGCParameter(cx, JSGCParamKey::JSGC_ALLOCATION_THRESHOLD_FACTOR, val as u32); } } - if let Some(val) = PREFS.get("js.mem.gc.decommit_threshold_mb").as_i64() { + if let Some(val) = PREFS.get("js.mem.gc.allocation_threshold_avoid_interrupt_factor").as_i64() { if val >= 0 && val < 10000 { - JS_SetGCParameter(runtime.rt(), JSGCParamKey::JSGC_DECOMMIT_THRESHOLD, val as u32); + JS_SetGCParameter(cx, JSGCParamKey::JSGC_ALLOCATION_THRESHOLD_FACTOR_AVOID_INTERRUPT, val as u32); } } if let Some(val) = PREFS.get("js.mem.gc.empty_chunk_count_min").as_i64() { if val >= 0 && val < 10000 { - JS_SetGCParameter(runtime.rt(), JSGCParamKey::JSGC_MIN_EMPTY_CHUNK_COUNT, val as u32); + JS_SetGCParameter(cx, JSGCParamKey::JSGC_MIN_EMPTY_CHUNK_COUNT, val as u32); } } if let Some(val) = PREFS.get("js.mem.gc.empty_chunk_count_max").as_i64() { if val >= 0 && val < 10000 { - JS_SetGCParameter(runtime.rt(), JSGCParamKey::JSGC_MAX_EMPTY_CHUNK_COUNT, val as u32); + JS_SetGCParameter(cx, JSGCParamKey::JSGC_MAX_EMPTY_CHUNK_COUNT, val as u32); } } @@ -338,9 +358,8 @@ pub fn get_reports(cx: *mut JSContext, path_seg: String) -> Vec { let mut reports = vec![]; unsafe { - let rt = JS_GetRuntime(cx); let mut stats = ::std::mem::zeroed(); - if CollectServoSizes(rt, &mut stats, Some(get_size)) { + if CollectServoSizes(cx, &mut stats, Some(get_size)) { let mut report = |mut path_suffix, kind, size| { let mut path = path![path_seg, "js"]; path.append(&mut path_suffix); @@ -388,7 +407,7 @@ thread_local!(static GC_CYCLE_START: Cell> = Cell::new(None)); thread_local!(static GC_SLICE_START: Cell> = Cell::new(None)); #[allow(unsafe_code)] -unsafe extern "C" fn gc_slice_callback(_rt: *mut JSRuntime, progress: GCProgress, desc: *const GCDescription) { +unsafe extern "C" fn gc_slice_callback(_cx: *mut JSContext, progress: GCProgress, desc: *const GCDescription) { match progress { GCProgress::GC_CYCLE_BEGIN => { GC_CYCLE_START.with(|start| { @@ -423,13 +442,13 @@ unsafe extern "C" fn gc_slice_callback(_rt: *mut JSRuntime, progress: GCProgress JSGCInvocationKind::GC_NORMAL => "GC_NORMAL", JSGCInvocationKind::GC_SHRINK => "GC_SHRINK", }; - println!(" isCompartment={}, invocation_kind={}", desc.isCompartment_, invocation_kind); + println!(" isZone={}, invocation_kind={}", desc.isZone_, invocation_kind); } let _ = stdout().flush(); } #[allow(unsafe_code)] -unsafe extern "C" fn debug_gc_callback(_rt: *mut JSRuntime, status: JSGCStatus, _data: *mut os::raw::c_void) { +unsafe extern "C" fn debug_gc_callback(_cx: *mut JSContext, status: JSGCStatus, _data: *mut os::raw::c_void) { match status { JSGCStatus::JSGC_BEGIN => thread_state::enter(ThreadState::IN_GC), JSGCStatus::JSGC_END => thread_state::exit(ThreadState::IN_GC), @@ -454,9 +473,15 @@ unsafe extern fn trace_rust_roots(tr: *mut JSTracer, _data: *mut os::raw::c_void debug!("done custom root handler"); } +#[allow(unsafe_code)] +unsafe extern "C" fn servo_build_id(build_id: *mut BuildIdCharVector) -> bool { + let servo_id = b"Servo\0"; + SetBuildId(build_id, &servo_id[0], servo_id.len()) +} + #[allow(unsafe_code)] #[cfg(feature = "debugmozjs")] -unsafe fn set_gc_zeal_options(rt: *mut JSRuntime) { +unsafe fn set_gc_zeal_options(cx: *mut JSContext) { use js::jsapi::{JS_DEFAULT_ZEAL_FREQ, JS_SetGCZeal}; let level = match PREFS.get("js.mem.gc.zeal.level").as_i64() { @@ -467,9 +492,9 @@ unsafe fn set_gc_zeal_options(rt: *mut JSRuntime) { Some(frequency) if frequency >= 0 => frequency as u32, _ => JS_DEFAULT_ZEAL_FREQ, }; - JS_SetGCZeal(rt, level, frequency); + JS_SetGCZeal(cx, level, frequency); } #[allow(unsafe_code)] #[cfg(not(feature = "debugmozjs"))] -unsafe fn set_gc_zeal_options(_: *mut JSRuntime) {} +unsafe fn set_gc_zeal_options(_: *mut JSContext) {} -- cgit v1.2.3 From e286fdcc536df0cae9020a677380ffe2fa494566 Mon Sep 17 00:00:00 2001 From: Agustin Chiappe Berrini Date: Sun, 2 Sep 2018 08:18:22 -0400 Subject: Add the TaskSourceName to CommonScriptMsg::Task Update QueuedTaskConversion and the TaskQueue to use it --- components/script/script_runtime.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index b5d598d1c79..6758e3bd852 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -43,6 +43,7 @@ use std::panic::AssertUnwindSafe; use std::ptr; use style::thread_state::{self, ThreadState}; use task::TaskBox; +use task_source::TaskSourceName; use time::{Tm, now}; /// Common messages used to control the event loops in both the script and the worker @@ -51,14 +52,14 @@ pub enum CommonScriptMsg { /// supplied channel. CollectReports(ReportsChan), /// Generic message that encapsulates event handling. - Task(ScriptThreadEventCategory, Box, Option), + Task(ScriptThreadEventCategory, Box, Option, TaskSourceName), } impl fmt::Debug for CommonScriptMsg { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { CommonScriptMsg::CollectReports(_) => write!(f, "CollectReports(...)"), - CommonScriptMsg::Task(ref category, ref task, _) => { + CommonScriptMsg::Task(ref category, ref task, _, _) => { f.debug_tuple("Task").field(category).field(task).finish() }, } -- cgit v1.2.3 From c37a345dc9f4dda6ea29c42f96f6c7201c42cbac Mon Sep 17 00:00:00 2001 From: chansuke Date: Tue, 18 Sep 2018 23:24:15 +0900 Subject: Format script component --- components/script/script_runtime.rs | 270 ++++++++++++++++++++++-------------- 1 file changed, 166 insertions(+), 104 deletions(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 6758e3bd852..18138dcc2b0 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -52,7 +52,12 @@ pub enum CommonScriptMsg { /// supplied channel. CollectReports(ReportsChan), /// Generic message that encapsulates event handling. - Task(ScriptThreadEventCategory, Box, Option, TaskSourceName), + Task( + ScriptThreadEventCategory, + Box, + Option, + TaskSourceName, + ), } impl fmt::Debug for CommonScriptMsg { @@ -113,21 +118,26 @@ pub trait ScriptPort { /// SM callback for promise job resolution. Adds a promise callback to the current /// global's microtask queue. #[allow(unsafe_code)] -unsafe extern "C" fn enqueue_job(cx: *mut JSContext, - job: HandleObject, - _allocation_site: HandleObject, - _incumbent_global: HandleObject, - _data: *mut c_void) -> bool { - wrap_panic(AssertUnwindSafe(|| { - //XXXjdm - use a different global now? - let global = GlobalScope::from_object(job.get()); - let pipeline = global.pipeline_id(); - global.enqueue_microtask(Microtask::Promise(EnqueuedPromiseCallback { - callback: PromiseJobCallback::new(cx, job.get()), - pipeline: pipeline, - })); - true - }), false) +unsafe extern "C" fn enqueue_job( + cx: *mut JSContext, + job: HandleObject, + _allocation_site: HandleObject, + _incumbent_global: HandleObject, + _data: *mut c_void, +) -> bool { + wrap_panic( + AssertUnwindSafe(|| { + //XXXjdm - use a different global now? + let global = GlobalScope::from_object(job.get()); + let pipeline = global.pipeline_id(); + global.enqueue_microtask(Microtask::Promise(EnqueuedPromiseCallback { + callback: PromiseJobCallback::new(cx, job.get()), + pipeline: pipeline, + })); + true + }), + false, + ) } #[derive(JSTraceable)] @@ -163,7 +173,9 @@ pub unsafe fn new_rt_and_cx() -> Runtime { SetGCSliceCallback(cx, Some(gc_slice_callback)); } - unsafe extern "C" fn empty_wrapper_callback(_: *mut JSContext, _: *mut JSObject) -> bool { true } + unsafe extern "C" fn empty_wrapper_callback(_: *mut JSContext, _: *mut JSObject) -> bool { + true + } SetDOMCallbacks(cx, &DOM_CALLBACKS); SetPreserveWrapperCallback(cx, Some(empty_wrapper_callback)); // Pre barriers aren't working correctly at the moment @@ -213,25 +225,27 @@ pub unsafe fn new_rt_and_cx() -> Runtime { if let Some(val) = PREFS.get("js.offthread_compilation_enabled").as_boolean() { JS_SetOffthreadIonCompilationEnabled(cx, val); } - if let Some(val) = PREFS.get("js.baseline.unsafe_eager_compilation.enabled").as_boolean() { - let trigger: i32 = if val { - 0 - } else { - -1 - }; - JS_SetGlobalJitCompilerOption(cx, - JSJitCompilerOption::JSJITCOMPILER_BASELINE_WARMUP_TRIGGER, - trigger as u32); - } - if let Some(val) = PREFS.get("js.ion.unsafe_eager_compilation.enabled").as_boolean() { - let trigger: i64 = if val { - 0 - } else { - -1 - }; - JS_SetGlobalJitCompilerOption(cx, - JSJitCompilerOption::JSJITCOMPILER_ION_WARMUP_TRIGGER, - trigger as u32); + if let Some(val) = PREFS + .get("js.baseline.unsafe_eager_compilation.enabled") + .as_boolean() + { + let trigger: i32 = if val { 0 } else { -1 }; + JS_SetGlobalJitCompilerOption( + cx, + JSJitCompilerOption::JSJITCOMPILER_BASELINE_WARMUP_TRIGGER, + trigger as u32, + ); + } + if let Some(val) = PREFS + .get("js.ion.unsafe_eager_compilation.enabled") + .as_boolean() + { + let trigger: i64 = if val { 0 } else { -1 }; + JS_SetGlobalJitCompilerOption( + cx, + JSJitCompilerOption::JSJITCOMPILER_ION_WARMUP_TRIGGER, + trigger as u32, + ); } // TODO: handle js.discard_system_source.enabled // TODO: handle js.asyncstack.enabled (needs new Spidermonkey) @@ -242,7 +256,11 @@ pub unsafe fn new_rt_and_cx() -> Runtime { } // TODO: handle js.shared_memory.enabled if let Some(val) = PREFS.get("js.mem.high_water_mark").as_i64() { - JS_SetGCParameter(cx, JSGCParamKey::JSGC_MAX_MALLOC_BYTES, val as u32 * 1024 * 1024); + JS_SetGCParameter( + cx, + JSGCParamKey::JSGC_MAX_MALLOC_BYTES, + val as u32 * 1024 * 1024, + ); } if let Some(val) = PREFS.get("js.mem.max").as_i64() { let max = if val <= 0 || val >= 0x1000 { @@ -281,10 +299,16 @@ pub unsafe fn new_rt_and_cx() -> Runtime { JS_SetGCParameter(cx, JSGCParamKey::JSGC_HIGH_FREQUENCY_TIME_LIMIT, val as u32); } } - if let Some(val) = PREFS.get("js.mem.gc.dynamic_mark_slice.enabled").as_boolean() { + if let Some(val) = PREFS + .get("js.mem.gc.dynamic_mark_slice.enabled") + .as_boolean() + { JS_SetGCParameter(cx, JSGCParamKey::JSGC_DYNAMIC_MARK_SLICE, val as u32); } - if let Some(val) = PREFS.get("js.mem.gc.dynamic_heap_growth.enabled").as_boolean() { + if let Some(val) = PREFS + .get("js.mem.gc.dynamic_heap_growth.enabled") + .as_boolean() + { JS_SetGCParameter(cx, JSGCParamKey::JSGC_DYNAMIC_HEAP_GROWTH, val as u32); } if let Some(val) = PREFS.get("js.mem.gc.low_frequency_heap_growth").as_i64() { @@ -292,14 +316,28 @@ pub unsafe fn new_rt_and_cx() -> Runtime { JS_SetGCParameter(cx, JSGCParamKey::JSGC_LOW_FREQUENCY_HEAP_GROWTH, val as u32); } } - if let Some(val) = PREFS.get("js.mem.gc.high_frequency_heap_growth_min").as_i64() { + if let Some(val) = PREFS + .get("js.mem.gc.high_frequency_heap_growth_min") + .as_i64() + { if val >= 0 && val < 10000 { - JS_SetGCParameter(cx, JSGCParamKey::JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MIN, val as u32); + JS_SetGCParameter( + cx, + JSGCParamKey::JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MIN, + val as u32, + ); } } - if let Some(val) = PREFS.get("js.mem.gc.high_frequency_heap_growth_max").as_i64() { + if let Some(val) = PREFS + .get("js.mem.gc.high_frequency_heap_growth_max") + .as_i64() + { if val >= 0 && val < 10000 { - JS_SetGCParameter(cx, JSGCParamKey::JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MAX, val as u32); + JS_SetGCParameter( + cx, + JSGCParamKey::JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MAX, + val as u32, + ); } } if let Some(val) = PREFS.get("js.mem.gc.high_frequency_low_limit_mb").as_i64() { @@ -314,12 +352,23 @@ pub unsafe fn new_rt_and_cx() -> Runtime { } if let Some(val) = PREFS.get("js.mem.gc.allocation_threshold_factor").as_i64() { if val >= 0 && val < 10000 { - JS_SetGCParameter(cx, JSGCParamKey::JSGC_ALLOCATION_THRESHOLD_FACTOR, val as u32); + JS_SetGCParameter( + cx, + JSGCParamKey::JSGC_ALLOCATION_THRESHOLD_FACTOR, + val as u32, + ); } } - if let Some(val) = PREFS.get("js.mem.gc.allocation_threshold_avoid_interrupt_factor").as_i64() { + if let Some(val) = PREFS + .get("js.mem.gc.allocation_threshold_avoid_interrupt_factor") + .as_i64() + { if val >= 0 && val < 10000 { - JS_SetGCParameter(cx, JSGCParamKey::JSGC_ALLOCATION_THRESHOLD_FACTOR_AVOID_INTERRUPT, val as u32); + JS_SetGCParameter( + cx, + JSGCParamKey::JSGC_ALLOCATION_THRESHOLD_FACTOR_AVOID_INTERRUPT, + val as u32, + ); } } if let Some(val) = PREFS.get("js.mem.gc.empty_chunk_count_min").as_i64() { @@ -347,10 +396,10 @@ unsafe extern "C" fn get_size(obj: *mut JSObject) -> usize { } let mut ops = MallocSizeOfOps::new(::servo_allocator::usable_size, None, None); (v.malloc_size_of)(&mut ops, dom_object) - } + }, Err(_e) => { return 0; - } + }, } } @@ -375,30 +424,42 @@ pub fn get_reports(cx: *mut JSContext, path_seg: String) -> Vec { // mmap/VirtualAlloc, which means it's not on the malloc "heap", so we use // `ExplicitNonHeapSize` as its kind. - report(path!["gc-heap", "used"], - ReportKind::ExplicitNonHeapSize, - stats.gcHeapUsed); - - report(path!["gc-heap", "unused"], - ReportKind::ExplicitNonHeapSize, - stats.gcHeapUnused); - - report(path!["gc-heap", "admin"], - ReportKind::ExplicitNonHeapSize, - stats.gcHeapAdmin); - - report(path!["gc-heap", "decommitted"], - ReportKind::ExplicitNonHeapSize, - stats.gcHeapDecommitted); + report( + path!["gc-heap", "used"], + ReportKind::ExplicitNonHeapSize, + stats.gcHeapUsed, + ); + + report( + path!["gc-heap", "unused"], + ReportKind::ExplicitNonHeapSize, + stats.gcHeapUnused, + ); + + report( + path!["gc-heap", "admin"], + ReportKind::ExplicitNonHeapSize, + stats.gcHeapAdmin, + ); + + report( + path!["gc-heap", "decommitted"], + ReportKind::ExplicitNonHeapSize, + stats.gcHeapDecommitted, + ); // SpiderMonkey uses the system heap, not jemalloc. - report(path!["malloc-heap"], - ReportKind::ExplicitSystemHeapSize, - stats.mallocHeap); - - report(path!["non-heap"], - ReportKind::ExplicitNonHeapSize, - stats.nonHeap); + report( + path!["malloc-heap"], + ReportKind::ExplicitSystemHeapSize, + stats.mallocHeap, + ); + + report( + path!["non-heap"], + ReportKind::ExplicitNonHeapSize, + stats.nonHeap, + ); } } reports @@ -408,34 +469,30 @@ thread_local!(static GC_CYCLE_START: Cell> = Cell::new(None)); thread_local!(static GC_SLICE_START: Cell> = Cell::new(None)); #[allow(unsafe_code)] -unsafe extern "C" fn gc_slice_callback(_cx: *mut JSContext, progress: GCProgress, desc: *const GCDescription) { +unsafe extern "C" fn gc_slice_callback( + _cx: *mut JSContext, + progress: GCProgress, + desc: *const GCDescription, +) { match progress { - GCProgress::GC_CYCLE_BEGIN => { - GC_CYCLE_START.with(|start| { - start.set(Some(now())); - println!("GC cycle began"); - }) - }, - GCProgress::GC_SLICE_BEGIN => { - GC_SLICE_START.with(|start| { - start.set(Some(now())); - println!("GC slice began"); - }) - }, - GCProgress::GC_SLICE_END => { - GC_SLICE_START.with(|start| { - let dur = now() - start.get().unwrap(); - start.set(None); - println!("GC slice ended: duration={}", dur); - }) - }, - GCProgress::GC_CYCLE_END => { - GC_CYCLE_START.with(|start| { - let dur = now() - start.get().unwrap(); - start.set(None); - println!("GC cycle ended: duration={}", dur); - }) - }, + GCProgress::GC_CYCLE_BEGIN => GC_CYCLE_START.with(|start| { + start.set(Some(now())); + println!("GC cycle began"); + }), + GCProgress::GC_SLICE_BEGIN => GC_SLICE_START.with(|start| { + start.set(Some(now())); + println!("GC slice began"); + }), + GCProgress::GC_SLICE_END => GC_SLICE_START.with(|start| { + let dur = now() - start.get().unwrap(); + start.set(None); + println!("GC slice ended: duration={}", dur); + }), + GCProgress::GC_CYCLE_END => GC_CYCLE_START.with(|start| { + let dur = now() - start.get().unwrap(); + start.set(None); + println!("GC cycle ended: duration={}", dur); + }), }; if !desc.is_null() { let desc: &GCDescription = &*desc; @@ -443,25 +500,30 @@ unsafe extern "C" fn gc_slice_callback(_cx: *mut JSContext, progress: GCProgress JSGCInvocationKind::GC_NORMAL => "GC_NORMAL", JSGCInvocationKind::GC_SHRINK => "GC_SHRINK", }; - println!(" isZone={}, invocation_kind={}", desc.isZone_, invocation_kind); + println!( + " isZone={}, invocation_kind={}", + desc.isZone_, invocation_kind + ); } let _ = stdout().flush(); } #[allow(unsafe_code)] -unsafe extern "C" fn debug_gc_callback(_cx: *mut JSContext, status: JSGCStatus, _data: *mut os::raw::c_void) { +unsafe extern "C" fn debug_gc_callback( + _cx: *mut JSContext, + status: JSGCStatus, + _data: *mut os::raw::c_void, +) { match status { JSGCStatus::JSGC_BEGIN => thread_state::enter(ThreadState::IN_GC), - JSGCStatus::JSGC_END => thread_state::exit(ThreadState::IN_GC), + JSGCStatus::JSGC_END => thread_state::exit(ThreadState::IN_GC), } } -thread_local!( - static THREAD_ACTIVE: Cell = Cell::new(true); -); +thread_local!(static THREAD_ACTIVE: Cell = Cell::new(true);); #[allow(unsafe_code)] -unsafe extern fn trace_rust_roots(tr: *mut JSTracer, _data: *mut os::raw::c_void) { +unsafe extern "C" fn trace_rust_roots(tr: *mut JSTracer, _data: *mut os::raw::c_void) { if !THREAD_ACTIVE.with(|t| t.get()) { return; } -- cgit v1.2.3 From 924a78c6c678e9448df9983bb370ff40910465bd Mon Sep 17 00:00:00 2001 From: CYBAI Date: Mon, 7 May 2018 20:36:18 +0800 Subject: Implement unhandledrejection event --- components/script/script_runtime.rs | 128 ++++++++++++++++++++++++++++++++++-- 1 file changed, 124 insertions(+), 4 deletions(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 18138dcc2b0..276a913647a 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -8,24 +8,34 @@ use dom::bindings::codegen::Bindings::PromiseBinding::PromiseJobCallback; use dom::bindings::conversions::get_dom_class; use dom::bindings::conversions::private_from_object; +use dom::bindings::inheritance::Castable; use dom::bindings::refcounted::{LiveDOMReferences, trace_refcounted_objects}; +use dom::bindings::refcounted::{Trusted, TrustedPromise}; +use dom::bindings::reflector::DomObject; use dom::bindings::root::trace_roots; use dom::bindings::settings_stack; use dom::bindings::trace::{JSTraceable, trace_traceables}; use dom::bindings::utils::DOM_CALLBACKS; +use dom::event::{Event, EventBubbles, EventCancelable, EventStatus}; +use dom::eventtarget::EventTarget; use dom::globalscope::GlobalScope; +use dom::promise::Promise; +use dom::promiserejectionevent::PromiseRejectionEvent; use js::glue::CollectServoSizes; use js::glue::SetBuildId; -use js::jsapi::{DisableIncrementalGC, GCDescription, GCProgress, HandleObject}; +use js::jsapi::{BuildIdCharVector, DisableIncrementalGC, GCDescription, GCProgress}; +use js::jsapi::{Heap, HandleObject}; use js::jsapi::{JSContext, JSTracer, SetDOMCallbacks, SetGCSliceCallback}; use js::jsapi::{JSGCInvocationKind, JSGCStatus, JS_AddExtraGCRootsTracer, JS_SetGCCallback}; use js::jsapi::{JSGCMode, JSGCParamKey, JS_SetGCParameter, JS_SetGlobalJitCompilerOption}; use js::jsapi::{JSJitCompilerOption, JS_SetOffthreadIonCompilationEnabled, JS_SetParallelParsingEnabled}; -use js::jsapi::{JSObject, SetPreserveWrapperCallback, SetEnqueuePromiseJobCallback}; -use js::jsapi::{SetBuildIdOp, BuildIdCharVector}; +use js::jsapi::{JSObject, PromiseRejectionHandlingState, SetPreserveWrapperCallback}; +use js::jsapi::{SetBuildIdOp, SetEnqueuePromiseJobCallback, SetPromiseRejectionTrackerCallback}; use js::jsapi::ContextOptionsRef; use js::panic::wrap_panic; +use js::rust::Handle; use js::rust::Runtime as RustRuntime; +use js::rust::wrappers::{GetPromiseIsHandled, GetPromiseResult}; use malloc_size_of::MallocSizeOfOps; use microtask::{EnqueuedPromiseCallback, Microtask}; use msg::constellation_msg::PipelineId; @@ -43,7 +53,7 @@ use std::panic::AssertUnwindSafe; use std::ptr; use style::thread_state::{self, ThreadState}; use task::TaskBox; -use task_source::TaskSourceName; +use task_source::{TaskSource, TaskSourceName}; use time::{Tm, now}; /// Common messages used to control the event loops in both the script and the worker @@ -140,6 +150,115 @@ unsafe extern "C" fn enqueue_job( ) } +#[allow(unsafe_code)] +/// https://html.spec.whatwg.org/multipage/#the-hostpromiserejectiontracker-implementation +unsafe extern "C" fn promise_rejection_tracker( + cx: *mut JSContext, + promise: HandleObject, + state: PromiseRejectionHandlingState, + _data: *mut c_void +) { + // TODO: Step 2 - If script's muted errors is true, terminate these steps. + + // Step 3. + let global = GlobalScope::from_context(cx); + + wrap_panic(AssertUnwindSafe(|| { + match state { + // Step 4. + PromiseRejectionHandlingState::Unhandled => { + global.add_uncaught_rejection(promise); + }, + // Step 5. + PromiseRejectionHandlingState::Handled => { + // Step 5-1. + if global.get_uncaught_rejections().borrow().contains(&Heap::boxed(promise.get())) { + global.remove_uncaught_rejection(promise); + return; + } + + // Step 5-2. + if !global.get_consumed_rejections().borrow().contains(&Heap::boxed(promise.get())) { + global.add_consumed_rejection(promise); + return; + } + + // Step 5-3. + global.remove_consumed_rejection(promise); + + // TODO: Step 5-4 - Queue a task to fire `rejectionhandled` event + } + }; + }), ()); +} + +#[allow(unsafe_code, unrooted_must_root)] +/// https://html.spec.whatwg.org/multipage/#notify-about-rejected-promises +pub fn notify_about_rejected_promises(global: &GlobalScope) { + unsafe { + let cx = global.get_cx(); + + // Step 2. + if global.get_uncaught_rejections().borrow().len() > 0 { + // Step 1. + let uncaught_rejections: Vec = global.get_uncaught_rejections() + .borrow() + .iter() + .map(|promise| { + let promise = Promise::new_with_js_promise(Handle::from_raw(promise.handle()), cx); + + TrustedPromise::new(promise) + }) + .collect(); + + // Step 3. + global.get_uncaught_rejections().borrow_mut().clear(); + + let target = Trusted::new(global.upcast::()); + + // Step 4. + global.as_window().dom_manipulation_task_source().queue( + task!(unhandled_rejection_event: move || { + let target = target.root(); + let cx = target.global().get_cx(); + + for promise in uncaught_rejections { + let promise = promise.root(); + + // Step 4-1. + let promise_is_handled = GetPromiseIsHandled(promise.reflector().get_jsobject()); + if promise_is_handled { + continue; + } + + // Step 4-2. + rooted!(in(cx) let reason = GetPromiseResult(promise.reflector().get_jsobject())); + + let event = PromiseRejectionEvent::new( + &target.global(), + atom!("unhandledrejection"), + EventBubbles::DoesNotBubble, + EventCancelable::Cancelable, + promise, + reason.handle() + ); + + let event_status = event.upcast::().fire(&target); + + // Step 4-3. + if event_status == EventStatus::Canceled { + // TODO: The promise rejection is not handled; we need to add it back to the list. + } + + // TODO: Step 4-4 - If [[PromiseIsHandled]] is false, add promise to consumed_rejections + } + }), + global.upcast(), + ).unwrap(); + } + } +} + #[derive(JSTraceable)] pub struct Runtime(RustRuntime); @@ -182,6 +301,7 @@ pub unsafe fn new_rt_and_cx() -> Runtime { DisableIncrementalGC(cx); SetEnqueuePromiseJobCallback(cx, Some(enqueue_job), ptr::null_mut()); + SetPromiseRejectionTrackerCallback(cx, Some(promise_rejection_tracker), ptr::null_mut()); set_gc_zeal_options(cx); -- cgit v1.2.3 From 42903412c768f289558554419add125ce908e342 Mon Sep 17 00:00:00 2001 From: CYBAI Date: Sun, 10 Jun 2018 21:02:11 +0800 Subject: Make first argument of DOMManipulationTaskSource as a Box We don't have `window` for `workers`. So, if we use `global.as_window()` to get the DOMManipulationTaskSource, it will make worker panic. Instead, we should get the DOMManipulationTaskSource from each own thread. Ref: https://github.com/servo/servo/pull/20755#discussion_r193557746 --- components/script/script_runtime.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 276a913647a..b128e3e54b5 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -217,7 +217,7 @@ pub fn notify_about_rejected_promises(global: &GlobalScope) { let target = Trusted::new(global.upcast::()); // Step 4. - global.as_window().dom_manipulation_task_source().queue( + global.dom_manipulation_task_source().queue( task!(unhandled_rejection_event: move || { let target = target.root(); let cx = target.global().get_cx(); -- cgit v1.2.3 From f952d7ce0a1fcae485fa6728b9c3237f7e5f9e66 Mon Sep 17 00:00:00 2001 From: CYBAI Date: Sun, 24 Jun 2018 18:32:17 +0800 Subject: Clear consumed rejections and add FIXME comments --- components/script/script_runtime.rs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index b128e3e54b5..2ab4ef986f0 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -256,6 +256,13 @@ pub fn notify_about_rejected_promises(global: &GlobalScope) { global.upcast(), ).unwrap(); } + + if global.get_consumed_rejections().borrow().len() > 0 { + // FIXME(cybai): Implement `rejectionhandled` event instead of clearing the whole + // consumed rejections + // https://html.spec.whatwg.org/multipage/#the-hostpromiserejectiontracker-implementation + global.get_consumed_rejections().borrow_mut().clear(); + } } } -- cgit v1.2.3 From bca951d79ed9d356c1a9f5a5f4d1ad5a943a3df2 Mon Sep 17 00:00:00 2001 From: CYBAI Date: Sun, 21 Oct 2018 21:30:19 +0800 Subject: Drop `TrustedPromise` before dropping JSRuntime --- components/script/script_runtime.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 18138dcc2b0..865382f091f 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -145,7 +145,10 @@ pub struct Runtime(RustRuntime); impl Drop for Runtime { fn drop(&mut self) { - THREAD_ACTIVE.with(|t| t.set(false)); + THREAD_ACTIVE.with(|t| { + LiveDOMReferences::destruct(); + t.set(false); + }); } } -- cgit v1.2.3 From 45f7199eee82c66637ec68287eafa40a651001c4 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Thu, 1 Nov 2018 23:45:06 +0100 Subject: `cargo fix --edition` --- components/script/script_runtime.rs | 40 ++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 77990b0dc52..5b475b639c6 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -5,22 +5,22 @@ //! The script runtime contains common traits and structs commonly used by the //! script thread, the dom, and the worker threads. -use dom::bindings::codegen::Bindings::PromiseBinding::PromiseJobCallback; -use dom::bindings::conversions::get_dom_class; -use dom::bindings::conversions::private_from_object; -use dom::bindings::inheritance::Castable; -use dom::bindings::refcounted::{LiveDOMReferences, trace_refcounted_objects}; -use dom::bindings::refcounted::{Trusted, TrustedPromise}; -use dom::bindings::reflector::DomObject; -use dom::bindings::root::trace_roots; -use dom::bindings::settings_stack; -use dom::bindings::trace::{JSTraceable, trace_traceables}; -use dom::bindings::utils::DOM_CALLBACKS; -use dom::event::{Event, EventBubbles, EventCancelable, EventStatus}; -use dom::eventtarget::EventTarget; -use dom::globalscope::GlobalScope; -use dom::promise::Promise; -use dom::promiserejectionevent::PromiseRejectionEvent; +use crate::dom::bindings::codegen::Bindings::PromiseBinding::PromiseJobCallback; +use crate::dom::bindings::conversions::get_dom_class; +use crate::dom::bindings::conversions::private_from_object; +use crate::dom::bindings::inheritance::Castable; +use crate::dom::bindings::refcounted::{LiveDOMReferences, trace_refcounted_objects}; +use crate::dom::bindings::refcounted::{Trusted, TrustedPromise}; +use crate::dom::bindings::reflector::DomObject; +use crate::dom::bindings::root::trace_roots; +use crate::dom::bindings::settings_stack; +use crate::dom::bindings::trace::{JSTraceable, trace_traceables}; +use crate::dom::bindings::utils::DOM_CALLBACKS; +use crate::dom::event::{Event, EventBubbles, EventCancelable, EventStatus}; +use crate::dom::eventtarget::EventTarget; +use crate::dom::globalscope::GlobalScope; +use crate::dom::promise::Promise; +use crate::dom::promiserejectionevent::PromiseRejectionEvent; use js::glue::CollectServoSizes; use js::glue::SetBuildId; use js::jsapi::{BuildIdCharVector, DisableIncrementalGC, GCDescription, GCProgress}; @@ -37,10 +37,10 @@ use js::rust::Handle; use js::rust::Runtime as RustRuntime; use js::rust::wrappers::{GetPromiseIsHandled, GetPromiseResult}; use malloc_size_of::MallocSizeOfOps; -use microtask::{EnqueuedPromiseCallback, Microtask}; +use crate::microtask::{EnqueuedPromiseCallback, Microtask}; use msg::constellation_msg::PipelineId; use profile_traits::mem::{Report, ReportKind, ReportsChan}; -use script_thread::trace_thread; +use crate::script_thread::trace_thread; use servo_config::opts; use servo_config::prefs::PREFS; use std::cell::Cell; @@ -52,8 +52,8 @@ use std::os::raw::c_void; use std::panic::AssertUnwindSafe; use std::ptr; use style::thread_state::{self, ThreadState}; -use task::TaskBox; -use task_source::{TaskSource, TaskSourceName}; +use crate::task::TaskBox; +use crate::task_source::{TaskSource, TaskSourceName}; use time::{Tm, now}; /// Common messages used to control the event loops in both the script and the worker -- cgit v1.2.3 From 76e59a46d3aff701b2e8dfbaf047f6d5c3edcced Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Thu, 1 Nov 2018 17:23:56 +0100 Subject: Sort `use` statements --- components/script/script_runtime.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 5b475b639c6..560e3fe571d 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -21,6 +21,10 @@ use crate::dom::eventtarget::EventTarget; use crate::dom::globalscope::GlobalScope; use crate::dom::promise::Promise; use crate::dom::promiserejectionevent::PromiseRejectionEvent; +use crate::microtask::{EnqueuedPromiseCallback, Microtask}; +use crate::script_thread::trace_thread; +use crate::task::TaskBox; +use crate::task_source::{TaskSource, TaskSourceName}; use js::glue::CollectServoSizes; use js::glue::SetBuildId; use js::jsapi::{BuildIdCharVector, DisableIncrementalGC, GCDescription, GCProgress}; @@ -37,10 +41,8 @@ use js::rust::Handle; use js::rust::Runtime as RustRuntime; use js::rust::wrappers::{GetPromiseIsHandled, GetPromiseResult}; use malloc_size_of::MallocSizeOfOps; -use crate::microtask::{EnqueuedPromiseCallback, Microtask}; use msg::constellation_msg::PipelineId; use profile_traits::mem::{Report, ReportKind, ReportsChan}; -use crate::script_thread::trace_thread; use servo_config::opts; use servo_config::prefs::PREFS; use std::cell::Cell; @@ -52,8 +54,6 @@ use std::os::raw::c_void; use std::panic::AssertUnwindSafe; use std::ptr; use style::thread_state::{self, ThreadState}; -use crate::task::TaskBox; -use crate::task_source::{TaskSource, TaskSourceName}; use time::{Tm, now}; /// Common messages used to control the event loops in both the script and the worker -- cgit v1.2.3 From cb07debcb6f3d3561177ce536c320986720791b7 Mon Sep 17 00:00:00 2001 From: Pyfisch Date: Tue, 6 Nov 2018 13:01:35 +0100 Subject: Format remaining files --- components/script/script_runtime.rs | 73 ++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 30 deletions(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 560e3fe571d..2625bb4d3ce 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -156,40 +156,51 @@ unsafe extern "C" fn promise_rejection_tracker( cx: *mut JSContext, promise: HandleObject, state: PromiseRejectionHandlingState, - _data: *mut c_void + _data: *mut c_void, ) { // TODO: Step 2 - If script's muted errors is true, terminate these steps. // Step 3. let global = GlobalScope::from_context(cx); - wrap_panic(AssertUnwindSafe(|| { - match state { - // Step 4. - PromiseRejectionHandlingState::Unhandled => { - global.add_uncaught_rejection(promise); - }, - // Step 5. - PromiseRejectionHandlingState::Handled => { - // Step 5-1. - if global.get_uncaught_rejections().borrow().contains(&Heap::boxed(promise.get())) { - global.remove_uncaught_rejection(promise); - return; - } - - // Step 5-2. - if !global.get_consumed_rejections().borrow().contains(&Heap::boxed(promise.get())) { - global.add_consumed_rejection(promise); - return; - } - - // Step 5-3. - global.remove_consumed_rejection(promise); - - // TODO: Step 5-4 - Queue a task to fire `rejectionhandled` event - } - }; - }), ()); + wrap_panic( + AssertUnwindSafe(|| { + match state { + // Step 4. + PromiseRejectionHandlingState::Unhandled => { + global.add_uncaught_rejection(promise); + }, + // Step 5. + PromiseRejectionHandlingState::Handled => { + // Step 5-1. + if global + .get_uncaught_rejections() + .borrow() + .contains(&Heap::boxed(promise.get())) + { + global.remove_uncaught_rejection(promise); + return; + } + + // Step 5-2. + if !global + .get_consumed_rejections() + .borrow() + .contains(&Heap::boxed(promise.get())) + { + global.add_consumed_rejection(promise); + return; + } + + // Step 5-3. + global.remove_consumed_rejection(promise); + + // TODO: Step 5-4 - Queue a task to fire `rejectionhandled` event + }, + }; + }), + (), + ); } #[allow(unsafe_code, unrooted_must_root)] @@ -201,11 +212,13 @@ pub fn notify_about_rejected_promises(global: &GlobalScope) { // Step 2. if global.get_uncaught_rejections().borrow().len() > 0 { // Step 1. - let uncaught_rejections: Vec = global.get_uncaught_rejections() + let uncaught_rejections: Vec = global + .get_uncaught_rejections() .borrow() .iter() .map(|promise| { - let promise = Promise::new_with_js_promise(Handle::from_raw(promise.handle()), cx); + let promise = + Promise::new_with_js_promise(Handle::from_raw(promise.handle()), cx); TrustedPromise::new(promise) }) -- cgit v1.2.3 From 9e92eb205a2a12fe0be883e42cb7f82deebc9031 Mon Sep 17 00:00:00 2001 From: Pyfisch Date: Tue, 6 Nov 2018 20:38:02 +0100 Subject: Reorder imports --- components/script/script_runtime.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 2625bb4d3ce..8647c48d1ce 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -9,12 +9,12 @@ use crate::dom::bindings::codegen::Bindings::PromiseBinding::PromiseJobCallback; use crate::dom::bindings::conversions::get_dom_class; use crate::dom::bindings::conversions::private_from_object; use crate::dom::bindings::inheritance::Castable; -use crate::dom::bindings::refcounted::{LiveDOMReferences, trace_refcounted_objects}; +use crate::dom::bindings::refcounted::{trace_refcounted_objects, LiveDOMReferences}; use crate::dom::bindings::refcounted::{Trusted, TrustedPromise}; use crate::dom::bindings::reflector::DomObject; use crate::dom::bindings::root::trace_roots; use crate::dom::bindings::settings_stack; -use crate::dom::bindings::trace::{JSTraceable, trace_traceables}; +use crate::dom::bindings::trace::{trace_traceables, JSTraceable}; use crate::dom::bindings::utils::DOM_CALLBACKS; use crate::dom::event::{Event, EventBubbles, EventCancelable, EventStatus}; use crate::dom::eventtarget::EventTarget; @@ -27,19 +27,21 @@ use crate::task::TaskBox; use crate::task_source::{TaskSource, TaskSourceName}; use js::glue::CollectServoSizes; use js::glue::SetBuildId; +use js::jsapi::ContextOptionsRef; use js::jsapi::{BuildIdCharVector, DisableIncrementalGC, GCDescription, GCProgress}; -use js::jsapi::{Heap, HandleObject}; +use js::jsapi::{HandleObject, Heap}; use js::jsapi::{JSContext, JSTracer, SetDOMCallbacks, SetGCSliceCallback}; use js::jsapi::{JSGCInvocationKind, JSGCStatus, JS_AddExtraGCRootsTracer, JS_SetGCCallback}; use js::jsapi::{JSGCMode, JSGCParamKey, JS_SetGCParameter, JS_SetGlobalJitCompilerOption}; -use js::jsapi::{JSJitCompilerOption, JS_SetOffthreadIonCompilationEnabled, JS_SetParallelParsingEnabled}; +use js::jsapi::{ + JSJitCompilerOption, JS_SetOffthreadIonCompilationEnabled, JS_SetParallelParsingEnabled, +}; use js::jsapi::{JSObject, PromiseRejectionHandlingState, SetPreserveWrapperCallback}; use js::jsapi::{SetBuildIdOp, SetEnqueuePromiseJobCallback, SetPromiseRejectionTrackerCallback}; -use js::jsapi::ContextOptionsRef; use js::panic::wrap_panic; +use js::rust::wrappers::{GetPromiseIsHandled, GetPromiseResult}; use js::rust::Handle; use js::rust::Runtime as RustRuntime; -use js::rust::wrappers::{GetPromiseIsHandled, GetPromiseResult}; use malloc_size_of::MallocSizeOfOps; use msg::constellation_msg::PipelineId; use profile_traits::mem::{Report, ReportKind, ReportsChan}; @@ -47,14 +49,14 @@ use servo_config::opts; use servo_config::prefs::PREFS; use std::cell::Cell; use std::fmt; -use std::io::{Write, stdout}; +use std::io::{stdout, Write}; use std::ops::Deref; use std::os; use std::os::raw::c_void; use std::panic::AssertUnwindSafe; use std::ptr; use style::thread_state::{self, ThreadState}; -use time::{Tm, now}; +use time::{now, Tm}; /// Common messages used to control the event loops in both the script and the worker pub enum CommonScriptMsg { @@ -688,7 +690,7 @@ unsafe extern "C" fn servo_build_id(build_id: *mut BuildIdCharVector) -> bool { #[allow(unsafe_code)] #[cfg(feature = "debugmozjs")] unsafe fn set_gc_zeal_options(cx: *mut JSContext) { - use js::jsapi::{JS_DEFAULT_ZEAL_FREQ, JS_SetGCZeal}; + use js::jsapi::{JS_SetGCZeal, JS_DEFAULT_ZEAL_FREQ}; let level = match PREFS.get("js.mem.gc.zeal.level").as_i64() { Some(level @ 0...14) => level as u8, -- cgit v1.2.3 From 2012be4a8bd97f2fd69f986c8fffb1af1eec21dc Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Thu, 1 Nov 2018 21:43:04 +0100 Subject: `cargo fix --edition-idioms` --- components/script/script_runtime.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 8647c48d1ce..f0cdd8ccad0 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -66,7 +66,7 @@ pub enum CommonScriptMsg { /// Generic message that encapsulates event handling. Task( ScriptThreadEventCategory, - Box, + Box, Option, TaskSourceName, ), @@ -88,7 +88,7 @@ pub trait ScriptChan: JSTraceable { /// Send a message to the associated event loop. fn send(&self, msg: CommonScriptMsg) -> Result<(), ()>; /// Clone this handle. - fn clone(&self) -> Box; + fn clone(&self) -> Box; } #[derive(Clone, Copy, Debug, Eq, Hash, JSTraceable, PartialEq)] @@ -539,7 +539,7 @@ unsafe extern "C" fn get_size(obj: *mut JSObject) -> usize { if dom_object.is_null() { return 0; } - let mut ops = MallocSizeOfOps::new(::servo_allocator::usable_size, None, None); + let mut ops = MallocSizeOfOps::new(servo_allocator::usable_size, None, None); (v.malloc_size_of)(&mut ops, dom_object) }, Err(_e) => { -- cgit v1.2.3 From 23a4d646ce779b0e13ea0441bfad081fcaf97928 Mon Sep 17 00:00:00 2001 From: CYBAI Date: Sun, 4 Nov 2018 14:35:17 +0800 Subject: Introduce rejectionhandled event --- components/script/script_runtime.rs | 45 +++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 12 deletions(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index f0cdd8ccad0..8cda22d6288 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -41,6 +41,7 @@ use js::jsapi::{SetBuildIdOp, SetEnqueuePromiseJobCallback, SetPromiseRejectionT use js::panic::wrap_panic; use js::rust::wrappers::{GetPromiseIsHandled, GetPromiseResult}; use js::rust::Handle; +use js::rust::IntoHandle; use js::rust::Runtime as RustRuntime; use malloc_size_of::MallocSizeOfOps; use msg::constellation_msg::PipelineId; @@ -152,7 +153,7 @@ unsafe extern "C" fn enqueue_job( ) } -#[allow(unsafe_code)] +#[allow(unsafe_code, unrooted_must_root)] /// https://html.spec.whatwg.org/multipage/#the-hostpromiserejectiontracker-implementation unsafe extern "C" fn promise_rejection_tracker( cx: *mut JSContext, @@ -190,14 +191,38 @@ unsafe extern "C" fn promise_rejection_tracker( .borrow() .contains(&Heap::boxed(promise.get())) { - global.add_consumed_rejection(promise); return; } // Step 5-3. global.remove_consumed_rejection(promise); - // TODO: Step 5-4 - Queue a task to fire `rejectionhandled` event + let target = Trusted::new(global.upcast::()); + let promise = Promise::new_with_js_promise(Handle::from_raw(promise), cx); + let trusted_promise = TrustedPromise::new(promise.clone()); + + // Step 5-4. + global.dom_manipulation_task_source().queue( + task!(rejection_handled_event: move || { + let target = target.root(); + let cx = target.global().get_cx(); + let root_promise = trusted_promise.root(); + + rooted!(in(cx) let reason = GetPromiseResult(root_promise.reflector().get_jsobject())); + + let event = PromiseRejectionEvent::new( + &target.global(), + atom!("rejectionhandled"), + EventBubbles::DoesNotBubble, + EventCancelable::Cancelable, + root_promise, + reason.handle() + ); + + event.upcast::().fire(&target); + }), + global.upcast(), + ).unwrap(); }, }; }), @@ -254,7 +279,7 @@ pub fn notify_about_rejected_promises(global: &GlobalScope) { atom!("unhandledrejection"), EventBubbles::DoesNotBubble, EventCancelable::Cancelable, - promise, + promise.clone(), reason.handle() ); @@ -265,19 +290,15 @@ pub fn notify_about_rejected_promises(global: &GlobalScope) { // TODO: The promise rejection is not handled; we need to add it back to the list. } - // TODO: Step 4-4 - If [[PromiseIsHandled]] is false, add promise to consumed_rejections + // Step 4-4. + if !promise_is_handled { + target.global().add_consumed_rejection(promise.reflector().get_jsobject().into_handle()); + } } }), global.upcast(), ).unwrap(); } - - if global.get_consumed_rejections().borrow().len() > 0 { - // FIXME(cybai): Implement `rejectionhandled` event instead of clearing the whole - // consumed rejections - // https://html.spec.whatwg.org/multipage/#the-hostpromiserejectiontracker-implementation - global.get_consumed_rejections().borrow_mut().clear(); - } } } -- cgit v1.2.3 From 14bc8ab7542287a18ecdede1ca7ee2af077eb8a9 Mon Sep 17 00:00:00 2001 From: Agustin Chiappe Berrini Date: Thu, 27 Sep 2018 18:43:22 -0400 Subject: Implement TaskSource for HistoryTraversal And remove the method in window that returns it, because it isn't used so far. --- components/script/script_runtime.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index f0cdd8ccad0..a3fb1c800f4 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -100,6 +100,7 @@ pub enum ScriptThreadEventCategory { DomEvent, FileRead, FormPlannedNavigation, + HistoryEvent, ImageCacheMsg, InputEvent, NetworkEvent, -- cgit v1.2.3 From a1a14459c141afc6ac6771b8a6c9ca374537edf2 Mon Sep 17 00:00:00 2001 From: Jan Andre Ikenmeyer Date: Mon, 19 Nov 2018 14:47:12 +0100 Subject: Update MPL license to https (part 3) --- components/script/script_runtime.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 83ff0836ee2..1558e0fffb7 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -1,6 +1,6 @@ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ //! The script runtime contains common traits and structs commonly used by the //! script thread, the dom, and the worker threads. -- cgit v1.2.3 From be69f9c3e6a6f5efb5ba1edd50955cb12c111bf8 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Fri, 14 Dec 2018 08:31:30 +0100 Subject: Rustfmt has changed its default style :/ --- components/script/script_runtime.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 1558e0fffb7..d10b95a068e 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -687,7 +687,9 @@ unsafe extern "C" fn debug_gc_callback( } } -thread_local!(static THREAD_ACTIVE: Cell = Cell::new(true);); +thread_local!( + static THREAD_ACTIVE: Cell = Cell::new(true); +); #[allow(unsafe_code)] unsafe extern "C" fn trace_rust_roots(tr: *mut JSTracer, _data: *mut os::raw::c_void) { -- cgit v1.2.3 From 644101e1e42a98996ff98c4cb8fb3cb6dd18be94 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Sun, 2 Dec 2018 14:23:09 -0500 Subject: Update to new JS runtime creation APIs. --- components/script/script_runtime.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index d10b95a068e..29be8114e35 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -42,6 +42,7 @@ use js::panic::wrap_panic; use js::rust::wrappers::{GetPromiseIsHandled, GetPromiseResult}; use js::rust::Handle; use js::rust::IntoHandle; +use js::rust::JSEngine; use js::rust::Runtime as RustRuntime; use malloc_size_of::MallocSizeOfOps; use msg::constellation_msg::PipelineId; @@ -56,6 +57,7 @@ use std::os; use std::os::raw::c_void; use std::panic::AssertUnwindSafe; use std::ptr; +use std::sync::Arc; use style::thread_state::{self, ThreadState}; use time::{now, Tm}; @@ -322,10 +324,14 @@ impl Deref for Runtime { } } +lazy_static! { + static ref JS_ENGINE: Arc = JSEngine::init().unwrap(); +} + #[allow(unsafe_code)] pub unsafe fn new_rt_and_cx() -> Runtime { LiveDOMReferences::initialize(); - let runtime = RustRuntime::new().unwrap(); + let runtime = RustRuntime::new(JS_ENGINE.clone()); let cx = runtime.cx(); JS_AddExtraGCRootsTracer(cx, Some(trace_rust_roots), ptr::null_mut()); -- cgit v1.2.3 From 367014a4ea5b3fff5e4f33df199db0fdb7a95925 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Sun, 2 Dec 2018 14:58:15 -0500 Subject: Reintroduce parent runtimes for worker threads. --- components/script/script_runtime.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 29be8114e35..2ee27ab38bb 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -43,6 +43,7 @@ use js::rust::wrappers::{GetPromiseIsHandled, GetPromiseResult}; use js::rust::Handle; use js::rust::IntoHandle; use js::rust::JSEngine; +use js::rust::ParentRuntime; use js::rust::Runtime as RustRuntime; use malloc_size_of::MallocSizeOfOps; use msg::constellation_msg::PipelineId; @@ -329,9 +330,23 @@ lazy_static! { } #[allow(unsafe_code)] -pub unsafe fn new_rt_and_cx() -> Runtime { +pub unsafe fn new_child_runtime(parent: ParentRuntime) -> Runtime { + new_rt_and_cx_with_parent(Some(parent)) +} + +#[allow(unsafe_code)] +pub fn new_rt_and_cx() -> Runtime { + unsafe { new_rt_and_cx_with_parent(None) } +} + +#[allow(unsafe_code)] +unsafe fn new_rt_and_cx_with_parent(parent: Option) -> Runtime { LiveDOMReferences::initialize(); - let runtime = RustRuntime::new(JS_ENGINE.clone()); + let runtime = if let Some(parent) = parent { + RustRuntime::create_with_parent(parent) + } else { + RustRuntime::new(JS_ENGINE.clone()) + }; let cx = runtime.cx(); JS_AddExtraGCRootsTracer(cx, Some(trace_rust_roots), ptr::null_mut()); -- cgit v1.2.3 From 8bfd4dc1e2f9c71ff3d1f9964565c43a6ae02278 Mon Sep 17 00:00:00 2001 From: Peter Hall Date: Thu, 14 Feb 2019 12:53:59 +0000 Subject: #8539 Config preferences backend restructure --- components/script/script_runtime.rs | 305 +++++++++++++++--------------------- 1 file changed, 126 insertions(+), 179 deletions(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 2ee27ab38bb..6cad5d4238e 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -49,7 +49,7 @@ use malloc_size_of::MallocSizeOfOps; use msg::constellation_msg::PipelineId; use profile_traits::mem::{Report, ReportKind, ReportsChan}; use servo_config::opts; -use servo_config::prefs::PREFS; +use servo_config::pref; use std::cell::Cell; use std::fmt; use std::io::{stdout, Write}; @@ -375,204 +375,151 @@ unsafe fn new_rt_and_cx_with_parent(parent: Option) -> Runtime { // Enable or disable the JITs. let cx_opts = &mut *ContextOptionsRef(cx); - if let Some(val) = PREFS.get("js.baseline.enabled").as_boolean() { - cx_opts.set_baseline_(val); - } - if let Some(val) = PREFS.get("js.ion.enabled").as_boolean() { - cx_opts.set_ion_(val); - } - if let Some(val) = PREFS.get("js.asmjs.enabled").as_boolean() { - cx_opts.set_asmJS_(val); - } - if let Some(val) = PREFS.get("js.wasm.enabled").as_boolean() { - cx_opts.set_wasm_(val); - if val { - // If WASM is enabled without setting the buildIdOp, - // initializing a module will report an out of memory error. - // https://dxr.mozilla.org/mozilla-central/source/js/src/wasm/WasmTypes.cpp#458 - SetBuildIdOp(cx, Some(servo_build_id)); - } - } - if let Some(val) = PREFS.get("js.wasm.baseline.enabled").as_boolean() { - cx_opts.set_wasmBaseline_(val); - } - if let Some(val) = PREFS.get("js.wasm.ion.enabled").as_boolean() { - cx_opts.set_wasmIon_(val); - } - if let Some(val) = PREFS.get("js.strict.enabled").as_boolean() { - cx_opts.set_extraWarnings_(val); - } + cx_opts.set_baseline_(pref!(js.baseline.enabled)); + cx_opts.set_ion_(pref!(js.ion.enabled)); + cx_opts.set_asmJS_(pref!(js.asmjs.enabled)); + let wasm_enabled = pref!(js.wasm.enabled); + cx_opts.set_wasm_(wasm_enabled); + if wasm_enabled { + // If WASM is enabled without setting the buildIdOp, + // initializing a module will report an out of memory error. + // https://dxr.mozilla.org/mozilla-central/source/js/src/wasm/WasmTypes.cpp#458 + SetBuildIdOp(cx, Some(servo_build_id)); + } + cx_opts.set_wasmBaseline_(pref!(js.wasm.baseline.enabled)); + cx_opts.set_wasmIon_(pref!(js.wasm.ion.enabled)); + cx_opts.set_extraWarnings_(pref!(js.strict.enabled)); // TODO: handle js.strict.debug.enabled // TODO: handle js.throw_on_asmjs_validation_failure (needs new Spidermonkey) - if let Some(val) = PREFS.get("js.native_regexp.enabled").as_boolean() { - cx_opts.set_nativeRegExp_(val); - } - if let Some(val) = PREFS.get("js.parallel_parsing.enabled").as_boolean() { - JS_SetParallelParsingEnabled(cx, val); - } - if let Some(val) = PREFS.get("js.offthread_compilation_enabled").as_boolean() { - JS_SetOffthreadIonCompilationEnabled(cx, val); - } - if let Some(val) = PREFS - .get("js.baseline.unsafe_eager_compilation.enabled") - .as_boolean() - { - let trigger: i32 = if val { 0 } else { -1 }; - JS_SetGlobalJitCompilerOption( - cx, - JSJitCompilerOption::JSJITCOMPILER_BASELINE_WARMUP_TRIGGER, - trigger as u32, - ); - } - if let Some(val) = PREFS - .get("js.ion.unsafe_eager_compilation.enabled") - .as_boolean() - { - let trigger: i64 = if val { 0 } else { -1 }; - JS_SetGlobalJitCompilerOption( - cx, - JSJitCompilerOption::JSJITCOMPILER_ION_WARMUP_TRIGGER, - trigger as u32, - ); - } + cx_opts.set_nativeRegExp_(pref!(js.native_regex.enabled)); + JS_SetParallelParsingEnabled(cx, pref!(js.parallel_parsing.enabled)); + JS_SetOffthreadIonCompilationEnabled(cx, pref!(js.offthread_compilation.enabled)); + JS_SetGlobalJitCompilerOption( + cx, + JSJitCompilerOption::JSJITCOMPILER_BASELINE_WARMUP_TRIGGER, + if pref!(js.baseline.unsafe_eager_compilation.enabled) { + 0 + } else { + u32::max_value() + }, + ); + JS_SetGlobalJitCompilerOption( + cx, + JSJitCompilerOption::JSJITCOMPILER_ION_WARMUP_TRIGGER, + if pref!(js.ion.unsafe_eager_compilation.enabled) { + 0 + } else { + u32::max_value() + }, + ); // TODO: handle js.discard_system_source.enabled // TODO: handle js.asyncstack.enabled (needs new Spidermonkey) // TODO: handle js.throw_on_debugee_would_run (needs new Spidermonkey) // TODO: handle js.dump_stack_on_debugee_would_run (needs new Spidermonkey) - if let Some(val) = PREFS.get("js.werror.enabled").as_boolean() { - cx_opts.set_werror_(val); - } + cx_opts.set_werror_(pref!(js.werror.enabled)); // TODO: handle js.shared_memory.enabled - if let Some(val) = PREFS.get("js.mem.high_water_mark").as_i64() { - JS_SetGCParameter( - cx, - JSGCParamKey::JSGC_MAX_MALLOC_BYTES, - val as u32 * 1024 * 1024, - ); - } - if let Some(val) = PREFS.get("js.mem.max").as_i64() { - let max = if val <= 0 || val >= 0x1000 { - -1 - } else { - val * 1024 * 1024 - }; - JS_SetGCParameter(cx, JSGCParamKey::JSGC_MAX_BYTES, max as u32); - } + JS_SetGCParameter( + cx, + JSGCParamKey::JSGC_MAX_MALLOC_BYTES, + (pref!(js.mem.high_water_mark) * 1024 * 1024) as u32, + ); + JS_SetGCParameter( + cx, + JSGCParamKey::JSGC_MAX_BYTES, + in_range(pref!(js.mem.max), 1, 0x100) + .map(|val| (val * 1024 * 1024) as u32) + .unwrap_or(u32::max_value()), + ); // NOTE: This is disabled above, so enabling it here will do nothing for now. - if let Some(val) = PREFS.get("js.mem.gc.incremental.enabled").as_boolean() { - let compartment = if let Some(val) = PREFS.get("js.mem.gc.per_zone.enabled").as_boolean() { - val - } else { - false - }; - let mode = if val { - JSGCMode::JSGC_MODE_INCREMENTAL - } else if compartment { - JSGCMode::JSGC_MODE_ZONE - } else { - JSGCMode::JSGC_MODE_GLOBAL - }; - JS_SetGCParameter(cx, JSGCParamKey::JSGC_MODE, mode as u32); - } - if let Some(val) = PREFS.get("js.mem.gc.incremental.slice_ms").as_i64() { - if val >= 0 && val < 100000 { - JS_SetGCParameter(cx, JSGCParamKey::JSGC_SLICE_TIME_BUDGET, val as u32); - } - } - if let Some(val) = PREFS.get("js.mem.gc.compacting.enabled").as_boolean() { - JS_SetGCParameter(cx, JSGCParamKey::JSGC_COMPACTING_ENABLED, val as u32); - } - if let Some(val) = PREFS.get("js.mem.gc.high_frequency_time_limit_ms").as_i64() { - if val >= 0 && val < 10000 { - JS_SetGCParameter(cx, JSGCParamKey::JSGC_HIGH_FREQUENCY_TIME_LIMIT, val as u32); - } - } - if let Some(val) = PREFS - .get("js.mem.gc.dynamic_mark_slice.enabled") - .as_boolean() - { - JS_SetGCParameter(cx, JSGCParamKey::JSGC_DYNAMIC_MARK_SLICE, val as u32); - } - if let Some(val) = PREFS - .get("js.mem.gc.dynamic_heap_growth.enabled") - .as_boolean() - { - JS_SetGCParameter(cx, JSGCParamKey::JSGC_DYNAMIC_HEAP_GROWTH, val as u32); + let js_gc_mode = if pref!(js.mem.gc.incremental.enabled) { + JSGCMode::JSGC_MODE_INCREMENTAL + } else if pref!(js.mem.gc.per_zone.enabled) { + JSGCMode::JSGC_MODE_ZONE + } else { + JSGCMode::JSGC_MODE_GLOBAL + }; + JS_SetGCParameter(cx, JSGCParamKey::JSGC_MODE, js_gc_mode as u32); + if let Some(val) = in_range(pref!(js.mem.gc.incremental.slice_ms), 0, 100_000) { + JS_SetGCParameter(cx, JSGCParamKey::JSGC_SLICE_TIME_BUDGET, val as u32); + } + JS_SetGCParameter( + cx, + JSGCParamKey::JSGC_COMPACTING_ENABLED, + pref!(js.mem.gc.compacting.enabled) as u32, + ); + + if let Some(val) = in_range(pref!(js.mem.gc.high_frequency_time_limit_ms), 0, 10_000) { + JS_SetGCParameter(cx, JSGCParamKey::JSGC_HIGH_FREQUENCY_TIME_LIMIT, val as u32); } - if let Some(val) = PREFS.get("js.mem.gc.low_frequency_heap_growth").as_i64() { - if val >= 0 && val < 10000 { - JS_SetGCParameter(cx, JSGCParamKey::JSGC_LOW_FREQUENCY_HEAP_GROWTH, val as u32); - } + JS_SetGCParameter( + cx, + JSGCParamKey::JSGC_DYNAMIC_MARK_SLICE, + pref!(js.mem.gc.dynamic_mark_slice.enabled) as u32, + ); + JS_SetGCParameter( + cx, + JSGCParamKey::JSGC_DYNAMIC_HEAP_GROWTH, + pref!(js.mem.gc.dynamic_heap_growth.enabled) as u32, + ); + if let Some(val) = in_range(pref!(js.mem.gc.low_frequency_heap_growth), 0, 10_000) { + JS_SetGCParameter(cx, JSGCParamKey::JSGC_LOW_FREQUENCY_HEAP_GROWTH, val as u32); } - if let Some(val) = PREFS - .get("js.mem.gc.high_frequency_heap_growth_min") - .as_i64() - { - if val >= 0 && val < 10000 { - JS_SetGCParameter( - cx, - JSGCParamKey::JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MIN, - val as u32, - ); - } + if let Some(val) = in_range(pref!(js.mem.gc.high_frequency_heap_growth_min), 0, 10_000) { + JS_SetGCParameter( + cx, + JSGCParamKey::JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MIN, + val as u32, + ); } - if let Some(val) = PREFS - .get("js.mem.gc.high_frequency_heap_growth_max") - .as_i64() - { - if val >= 0 && val < 10000 { - JS_SetGCParameter( - cx, - JSGCParamKey::JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MAX, - val as u32, - ); - } + if let Some(val) = in_range(pref!(js.mem.gc.high_frequency_heap_growth_max), 0, 10_000) { + JS_SetGCParameter( + cx, + JSGCParamKey::JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MAX, + val as u32, + ); } - if let Some(val) = PREFS.get("js.mem.gc.high_frequency_low_limit_mb").as_i64() { - if val >= 0 && val < 10000 { - JS_SetGCParameter(cx, JSGCParamKey::JSGC_HIGH_FREQUENCY_LOW_LIMIT, val as u32); - } + if let Some(val) = in_range(pref!(js.mem.gc.high_frequency_low_limit_mb), 0, 10_000) { + JS_SetGCParameter(cx, JSGCParamKey::JSGC_HIGH_FREQUENCY_LOW_LIMIT, val as u32); } - if let Some(val) = PREFS.get("js.mem.gc.high_frequency_high_limit_mb").as_i64() { - if val >= 0 && val < 10000 { - JS_SetGCParameter(cx, JSGCParamKey::JSGC_HIGH_FREQUENCY_HIGH_LIMIT, val as u32); - } + if let Some(val) = in_range(pref!(js.mem.gc.high_frequency_high_limit_mb), 0, 10_000) { + JS_SetGCParameter(cx, JSGCParamKey::JSGC_HIGH_FREQUENCY_HIGH_LIMIT, val as u32); } - if let Some(val) = PREFS.get("js.mem.gc.allocation_threshold_factor").as_i64() { - if val >= 0 && val < 10000 { - JS_SetGCParameter( - cx, - JSGCParamKey::JSGC_ALLOCATION_THRESHOLD_FACTOR, - val as u32, - ); - } + if let Some(val) = in_range(pref!(js.mem.gc.allocation_threshold_factor), 0, 10_000) { + JS_SetGCParameter( + cx, + JSGCParamKey::JSGC_ALLOCATION_THRESHOLD_FACTOR, + val as u32, + ); } - if let Some(val) = PREFS - .get("js.mem.gc.allocation_threshold_avoid_interrupt_factor") - .as_i64() - { - if val >= 0 && val < 10000 { - JS_SetGCParameter( - cx, - JSGCParamKey::JSGC_ALLOCATION_THRESHOLD_FACTOR_AVOID_INTERRUPT, - val as u32, - ); - } + if let Some(val) = in_range( + pref!(js.mem.gc.allocation_threshold_avoid_interrupt_factor), + 0, + 10_000, + ) { + JS_SetGCParameter( + cx, + JSGCParamKey::JSGC_ALLOCATION_THRESHOLD_FACTOR_AVOID_INTERRUPT, + val as u32, + ); } - if let Some(val) = PREFS.get("js.mem.gc.empty_chunk_count_min").as_i64() { - if val >= 0 && val < 10000 { - JS_SetGCParameter(cx, JSGCParamKey::JSGC_MIN_EMPTY_CHUNK_COUNT, val as u32); - } + if let Some(val) = in_range(pref!(js.mem.gc.empty_chunk_count_min), 0, 10_000) { + JS_SetGCParameter(cx, JSGCParamKey::JSGC_MIN_EMPTY_CHUNK_COUNT, val as u32); } - if let Some(val) = PREFS.get("js.mem.gc.empty_chunk_count_max").as_i64() { - if val >= 0 && val < 10000 { - JS_SetGCParameter(cx, JSGCParamKey::JSGC_MAX_EMPTY_CHUNK_COUNT, val as u32); - } + if let Some(val) = in_range(pref!(js.mem.gc.empty_chunk_count_max), 0, 10_000) { + JS_SetGCParameter(cx, JSGCParamKey::JSGC_MAX_EMPTY_CHUNK_COUNT, val as u32); } Runtime(runtime) } +fn in_range(val: T, min: T, max: T) -> Option { + if val < min || val >= max { + None + } else { + Some(val) + } +} + #[allow(unsafe_code)] unsafe extern "C" fn get_size(obj: *mut JSObject) -> usize { match get_dom_class(obj) { @@ -737,11 +684,11 @@ unsafe extern "C" fn servo_build_id(build_id: *mut BuildIdCharVector) -> bool { unsafe fn set_gc_zeal_options(cx: *mut JSContext) { use js::jsapi::{JS_SetGCZeal, JS_DEFAULT_ZEAL_FREQ}; - let level = match PREFS.get("js.mem.gc.zeal.level").as_i64() { + let level = match pref!(js.mem.gc.zeal.level) { Some(level @ 0...14) => level as u8, _ => return, }; - let frequency = match PREFS.get("js.mem.gc.zeal.frequency").as_i64() { + let frequency = match pref!(js.mem.gc.zeal.frequency) { Some(frequency) if frequency >= 0 => frequency as u32, _ => JS_DEFAULT_ZEAL_FREQ, }; -- cgit v1.2.3 From 5d7f238794c5af717a00f6410d03ca73122a4469 Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Fri, 3 May 2019 10:34:00 -0500 Subject: Fix debugmozjs build #23074 --- components/script/script_runtime.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 6cad5d4238e..80fe9cf31e5 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -685,11 +685,11 @@ unsafe fn set_gc_zeal_options(cx: *mut JSContext) { use js::jsapi::{JS_SetGCZeal, JS_DEFAULT_ZEAL_FREQ}; let level = match pref!(js.mem.gc.zeal.level) { - Some(level @ 0...14) => level as u8, + level @ 0...14 => level as u8, _ => return, }; let frequency = match pref!(js.mem.gc.zeal.frequency) { - Some(frequency) if frequency >= 0 => frequency as u32, + frequency if frequency >= 0 => frequency as u32, _ => JS_DEFAULT_ZEAL_FREQ, }; JS_SetGCZeal(cx, level, frequency); -- cgit v1.2.3 From 4328713f71d5bc389ecd47e78bfe9b8087b8c104 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Mon, 6 May 2019 11:38:34 -0400 Subject: Update to SpiderMonkey 66. --- components/script/script_runtime.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 80fe9cf31e5..ce64f363594 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -37,7 +37,9 @@ use js::jsapi::{ JSJitCompilerOption, JS_SetOffthreadIonCompilationEnabled, JS_SetParallelParsingEnabled, }; use js::jsapi::{JSObject, PromiseRejectionHandlingState, SetPreserveWrapperCallback}; -use js::jsapi::{SetBuildIdOp, SetEnqueuePromiseJobCallback, SetPromiseRejectionTrackerCallback}; +use js::jsapi::{ + SetEnqueuePromiseJobCallback, SetProcessBuildIdOp, SetPromiseRejectionTrackerCallback, +}; use js::panic::wrap_panic; use js::rust::wrappers::{GetPromiseIsHandled, GetPromiseResult}; use js::rust::Handle; @@ -137,15 +139,15 @@ pub trait ScriptPort { #[allow(unsafe_code)] unsafe extern "C" fn enqueue_job( cx: *mut JSContext, + _promise: HandleObject, job: HandleObject, _allocation_site: HandleObject, - _incumbent_global: HandleObject, + incumbent_global: HandleObject, _data: *mut c_void, ) -> bool { wrap_panic( AssertUnwindSafe(|| { - //XXXjdm - use a different global now? - let global = GlobalScope::from_object(job.get()); + let global = GlobalScope::from_object(incumbent_global.get()); let pipeline = global.pipeline_id(); global.enqueue_microtask(Microtask::Promise(EnqueuedPromiseCallback { callback: PromiseJobCallback::new(cx, job.get()), @@ -360,7 +362,7 @@ unsafe fn new_rt_and_cx_with_parent(parent: Option) -> Runtime { SetGCSliceCallback(cx, Some(gc_slice_callback)); } - unsafe extern "C" fn empty_wrapper_callback(_: *mut JSContext, _: *mut JSObject) -> bool { + unsafe extern "C" fn empty_wrapper_callback(_: *mut JSContext, _: HandleObject) -> bool { true } SetDOMCallbacks(cx, &DOM_CALLBACKS); @@ -384,7 +386,7 @@ unsafe fn new_rt_and_cx_with_parent(parent: Option) -> Runtime { // If WASM is enabled without setting the buildIdOp, // initializing a module will report an out of memory error. // https://dxr.mozilla.org/mozilla-central/source/js/src/wasm/WasmTypes.cpp#458 - SetBuildIdOp(cx, Some(servo_build_id)); + SetProcessBuildIdOp(Some(servo_build_id)); } cx_opts.set_wasmBaseline_(pref!(js.wasm.baseline.enabled)); cx_opts.set_wasmIon_(pref!(js.wasm.ion.enabled)); -- cgit v1.2.3 From 63714c90fb5bbad86f28fc188120b2ecfd3337ab Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Sun, 2 Jun 2019 23:38:12 -0400 Subject: Upgrade to Spidermonkey 67. --- components/script/script_runtime.rs | 84 +++++++++++++++++++++++++++++-------- 1 file changed, 66 insertions(+), 18 deletions(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index ce64f363594..b5119949193 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -21,15 +21,14 @@ use crate::dom::eventtarget::EventTarget; use crate::dom::globalscope::GlobalScope; use crate::dom::promise::Promise; use crate::dom::promiserejectionevent::PromiseRejectionEvent; -use crate::microtask::{EnqueuedPromiseCallback, Microtask}; +use crate::microtask::{EnqueuedPromiseCallback, Microtask, MicrotaskQueue}; use crate::script_thread::trace_thread; use crate::task::TaskBox; use crate::task_source::{TaskSource, TaskSourceName}; -use js::glue::CollectServoSizes; -use js::glue::SetBuildId; +use js::glue::{CollectServoSizes, CreateJobQueue, DeleteJobQueue, JobQueueTraps, SetBuildId}; use js::jsapi::ContextOptionsRef; use js::jsapi::{BuildIdCharVector, DisableIncrementalGC, GCDescription, GCProgress}; -use js::jsapi::{HandleObject, Heap}; +use js::jsapi::{HandleObject, Heap, JobQueue}; use js::jsapi::{JSContext, JSTracer, SetDOMCallbacks, SetGCSliceCallback}; use js::jsapi::{JSGCInvocationKind, JSGCStatus, JS_AddExtraGCRootsTracer, JS_SetGCCallback}; use js::jsapi::{JSGCMode, JSGCParamKey, JS_SetGCParameter, JS_SetGlobalJitCompilerOption}; @@ -37,9 +36,7 @@ use js::jsapi::{ JSJitCompilerOption, JS_SetOffthreadIonCompilationEnabled, JS_SetParallelParsingEnabled, }; use js::jsapi::{JSObject, PromiseRejectionHandlingState, SetPreserveWrapperCallback}; -use js::jsapi::{ - SetEnqueuePromiseJobCallback, SetProcessBuildIdOp, SetPromiseRejectionTrackerCallback, -}; +use js::jsapi::{SetJobQueue, SetProcessBuildIdOp, SetPromiseRejectionTrackerCallback}; use js::panic::wrap_panic; use js::rust::wrappers::{GetPromiseIsHandled, GetPromiseResult}; use js::rust::Handle; @@ -60,10 +57,17 @@ use std::os; use std::os::raw::c_void; use std::panic::AssertUnwindSafe; use std::ptr; +use std::rc::Rc; use std::sync::Arc; use style::thread_state::{self, ThreadState}; use time::{now, Tm}; +static JOB_QUEUE_TRAPS: JobQueueTraps = JobQueueTraps { + getIncumbentGlobal: Some(get_incumbent_global), + enqueuePromiseJob: Some(enqueue_promise_job), + empty: Some(empty), +}; + /// Common messages used to control the event loops in both the script and the worker pub enum CommonScriptMsg { /// Requests that the script thread measure its memory usage. The results are sent back via the @@ -134,25 +138,52 @@ pub trait ScriptPort { fn recv(&self) -> Result; } +#[allow(unsafe_code)] +unsafe extern "C" fn get_incumbent_global(_: *const c_void, _: *mut JSContext) -> *mut JSObject { + wrap_panic( + AssertUnwindSafe(|| { + GlobalScope::incumbent() + .map(|g| g.reflector().get_jsobject().get()) + .unwrap_or(ptr::null_mut()) + }), + ptr::null_mut(), + ) +} + +#[allow(unsafe_code)] +unsafe extern "C" fn empty(extra: *const c_void) -> bool { + wrap_panic( + AssertUnwindSafe(|| { + let microtask_queue = &*(extra as *const MicrotaskQueue); + microtask_queue.empty() + }), + false, + ) +} + /// SM callback for promise job resolution. Adds a promise callback to the current /// global's microtask queue. #[allow(unsafe_code)] -unsafe extern "C" fn enqueue_job( +unsafe extern "C" fn enqueue_promise_job( + extra: *const c_void, cx: *mut JSContext, _promise: HandleObject, job: HandleObject, _allocation_site: HandleObject, incumbent_global: HandleObject, - _data: *mut c_void, ) -> bool { wrap_panic( AssertUnwindSafe(|| { + let microtask_queue = &*(extra as *const MicrotaskQueue); let global = GlobalScope::from_object(incumbent_global.get()); let pipeline = global.pipeline_id(); - global.enqueue_microtask(Microtask::Promise(EnqueuedPromiseCallback { - callback: PromiseJobCallback::new(cx, job.get()), - pipeline: pipeline, - })); + microtask_queue.enqueue( + Microtask::Promise(EnqueuedPromiseCallback { + callback: PromiseJobCallback::new(cx, job.get()), + pipeline, + }), + cx, + ); true }), false, @@ -309,10 +340,18 @@ pub fn notify_about_rejected_promises(global: &GlobalScope) { } #[derive(JSTraceable)] -pub struct Runtime(RustRuntime); +pub struct Runtime { + rt: RustRuntime, + pub microtask_queue: Rc, + job_queue: *mut JobQueue, +} impl Drop for Runtime { + #[allow(unsafe_code)] fn drop(&mut self) { + unsafe { + DeleteJobQueue(self.job_queue); + } THREAD_ACTIVE.with(|t| { LiveDOMReferences::destruct(); t.set(false); @@ -323,7 +362,7 @@ impl Drop for Runtime { impl Deref for Runtime { type Target = RustRuntime; fn deref(&self) -> &RustRuntime { - &self.0 + &self.rt } } @@ -370,7 +409,12 @@ unsafe fn new_rt_and_cx_with_parent(parent: Option) -> Runtime { // Pre barriers aren't working correctly at the moment DisableIncrementalGC(cx); - SetEnqueuePromiseJobCallback(cx, Some(enqueue_job), ptr::null_mut()); + let microtask_queue = Rc::new(MicrotaskQueue::default()); + let job_queue = CreateJobQueue( + &JOB_QUEUE_TRAPS, + &*microtask_queue as *const _ as *const c_void, + ); + SetJobQueue(cx, job_queue); SetPromiseRejectionTrackerCallback(cx, Some(promise_rejection_tracker), ptr::null_mut()); set_gc_zeal_options(cx); @@ -407,7 +451,7 @@ unsafe fn new_rt_and_cx_with_parent(parent: Option) -> Runtime { ); JS_SetGlobalJitCompilerOption( cx, - JSJitCompilerOption::JSJITCOMPILER_ION_WARMUP_TRIGGER, + JSJitCompilerOption::JSJITCOMPILER_ION_NORMAL_WARMUP_TRIGGER, if pref!(js.ion.unsafe_eager_compilation.enabled) { 0 } else { @@ -511,7 +555,11 @@ unsafe fn new_rt_and_cx_with_parent(parent: Option) -> Runtime { JS_SetGCParameter(cx, JSGCParamKey::JSGC_MAX_EMPTY_CHUNK_COUNT, val as u32); } - Runtime(runtime) + Runtime { + rt: runtime, + microtask_queue, + job_queue, + } } fn in_range(val: T, min: T, max: T) -> Option { -- cgit v1.2.3 From 5d85f60f7df1316eca8f80714acb4ba519a1082d Mon Sep 17 00:00:00 2001 From: marmeladema Date: Sat, 20 Jul 2019 13:45:42 +0100 Subject: Rename JSContext from js::jsapi to RawJSContext --- components/script/script_runtime.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index b5119949193..6a16a79cba7 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -29,7 +29,7 @@ use js::glue::{CollectServoSizes, CreateJobQueue, DeleteJobQueue, JobQueueTraps, use js::jsapi::ContextOptionsRef; use js::jsapi::{BuildIdCharVector, DisableIncrementalGC, GCDescription, GCProgress}; use js::jsapi::{HandleObject, Heap, JobQueue}; -use js::jsapi::{JSContext, JSTracer, SetDOMCallbacks, SetGCSliceCallback}; +use js::jsapi::{JSContext as RawJSContext, JSTracer, SetDOMCallbacks, SetGCSliceCallback}; use js::jsapi::{JSGCInvocationKind, JSGCStatus, JS_AddExtraGCRootsTracer, JS_SetGCCallback}; use js::jsapi::{JSGCMode, JSGCParamKey, JS_SetGCParameter, JS_SetGlobalJitCompilerOption}; use js::jsapi::{ @@ -139,7 +139,7 @@ pub trait ScriptPort { } #[allow(unsafe_code)] -unsafe extern "C" fn get_incumbent_global(_: *const c_void, _: *mut JSContext) -> *mut JSObject { +unsafe extern "C" fn get_incumbent_global(_: *const c_void, _: *mut RawJSContext) -> *mut JSObject { wrap_panic( AssertUnwindSafe(|| { GlobalScope::incumbent() @@ -166,7 +166,7 @@ unsafe extern "C" fn empty(extra: *const c_void) -> bool { #[allow(unsafe_code)] unsafe extern "C" fn enqueue_promise_job( extra: *const c_void, - cx: *mut JSContext, + cx: *mut RawJSContext, _promise: HandleObject, job: HandleObject, _allocation_site: HandleObject, @@ -193,7 +193,7 @@ unsafe extern "C" fn enqueue_promise_job( #[allow(unsafe_code, unrooted_must_root)] /// https://html.spec.whatwg.org/multipage/#the-hostpromiserejectiontracker-implementation unsafe extern "C" fn promise_rejection_tracker( - cx: *mut JSContext, + cx: *mut RawJSContext, promise: HandleObject, state: PromiseRejectionHandlingState, _data: *mut c_void, @@ -401,7 +401,7 @@ unsafe fn new_rt_and_cx_with_parent(parent: Option) -> Runtime { SetGCSliceCallback(cx, Some(gc_slice_callback)); } - unsafe extern "C" fn empty_wrapper_callback(_: *mut JSContext, _: HandleObject) -> bool { + unsafe extern "C" fn empty_wrapper_callback(_: *mut RawJSContext, _: HandleObject) -> bool { true } SetDOMCallbacks(cx, &DOM_CALLBACKS); @@ -589,7 +589,7 @@ unsafe extern "C" fn get_size(obj: *mut JSObject) -> usize { } #[allow(unsafe_code)] -pub fn get_reports(cx: *mut JSContext, path_seg: String) -> Vec { +pub fn get_reports(cx: *mut RawJSContext, path_seg: String) -> Vec { let mut reports = vec![]; unsafe { @@ -655,7 +655,7 @@ thread_local!(static GC_SLICE_START: Cell> = Cell::new(None)); #[allow(unsafe_code)] unsafe extern "C" fn gc_slice_callback( - _cx: *mut JSContext, + _cx: *mut RawJSContext, progress: GCProgress, desc: *const GCDescription, ) { @@ -695,7 +695,7 @@ unsafe extern "C" fn gc_slice_callback( #[allow(unsafe_code)] unsafe extern "C" fn debug_gc_callback( - _cx: *mut JSContext, + _cx: *mut RawJSContext, status: JSGCStatus, _data: *mut os::raw::c_void, ) { @@ -731,7 +731,7 @@ unsafe extern "C" fn servo_build_id(build_id: *mut BuildIdCharVector) -> bool { #[allow(unsafe_code)] #[cfg(feature = "debugmozjs")] -unsafe fn set_gc_zeal_options(cx: *mut JSContext) { +unsafe fn set_gc_zeal_options(cx: *mut RawJSContext) { use js::jsapi::{JS_SetGCZeal, JS_DEFAULT_ZEAL_FREQ}; let level = match pref!(js.mem.gc.zeal.level) { @@ -747,4 +747,4 @@ unsafe fn set_gc_zeal_options(cx: *mut JSContext) { #[allow(unsafe_code)] #[cfg(not(feature = "debugmozjs"))] -unsafe fn set_gc_zeal_options(_: *mut JSContext) {} +unsafe fn set_gc_zeal_options(_: *mut RawJSContext) {} -- cgit v1.2.3 From dbcd8d7af232cd10c3a8ef751076cc7b9cd068a4 Mon Sep 17 00:00:00 2001 From: marmeladema Date: Sat, 20 Jul 2019 14:00:37 +0100 Subject: Add safe JSontext wrapper around unsafe RawJSContext --- components/script/script_runtime.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 6a16a79cba7..76691c5de79 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -748,3 +748,22 @@ unsafe fn set_gc_zeal_options(cx: *mut RawJSContext) { #[allow(unsafe_code)] #[cfg(not(feature = "debugmozjs"))] unsafe fn set_gc_zeal_options(_: *mut RawJSContext) {} + +#[derive(Clone, Copy)] +pub struct JSContext(*mut RawJSContext); + +#[allow(unsafe_code)] +impl JSContext { + pub unsafe fn from_ptr(raw_js_context: *mut RawJSContext) -> Self { + JSContext(raw_js_context) + } +} + +#[allow(unsafe_code)] +impl Deref for JSContext { + type Target = *mut RawJSContext; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} -- cgit v1.2.3 From 2fb3f1f98327ee1de698dfed83124350f58ff52a Mon Sep 17 00:00:00 2001 From: marmeladema Date: Sun, 21 Jul 2019 16:05:04 +0100 Subject: Callbacks now uses safe JSContext instead of raw JSContext --- components/script/script_runtime.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 76691c5de79..4c7953de443 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -179,7 +179,7 @@ unsafe extern "C" fn enqueue_promise_job( let pipeline = global.pipeline_id(); microtask_queue.enqueue( Microtask::Promise(EnqueuedPromiseCallback { - callback: PromiseJobCallback::new(cx, job.get()), + callback: PromiseJobCallback::new(JSContext::from_ptr(cx), job.get()), pipeline, }), cx, -- cgit v1.2.3 From 88cacfb0098e20be70c27bfde6b74cd3290f1fe4 Mon Sep 17 00:00:00 2001 From: marmeladema Date: Mon, 22 Jul 2019 22:14:11 +0100 Subject: Modify *::get_cx methods to return a safe JSContext instead of a raw one --- components/script/script_runtime.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 4c7953de443..fb94d30fafd 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -245,7 +245,7 @@ unsafe extern "C" fn promise_rejection_tracker( let cx = target.global().get_cx(); let root_promise = trusted_promise.root(); - rooted!(in(cx) let reason = GetPromiseResult(root_promise.reflector().get_jsobject())); + rooted!(in(*cx) let reason = GetPromiseResult(root_promise.reflector().get_jsobject())); let event = PromiseRejectionEvent::new( &target.global(), @@ -270,9 +270,8 @@ unsafe extern "C" fn promise_rejection_tracker( #[allow(unsafe_code, unrooted_must_root)] /// https://html.spec.whatwg.org/multipage/#notify-about-rejected-promises pub fn notify_about_rejected_promises(global: &GlobalScope) { + let cx = global.get_cx(); unsafe { - let cx = global.get_cx(); - // Step 2. if global.get_uncaught_rejections().borrow().len() > 0 { // Step 1. @@ -282,7 +281,7 @@ pub fn notify_about_rejected_promises(global: &GlobalScope) { .iter() .map(|promise| { let promise = - Promise::new_with_js_promise(Handle::from_raw(promise.handle()), cx); + Promise::new_with_js_promise(Handle::from_raw(promise.handle()), *cx); TrustedPromise::new(promise) }) @@ -309,7 +308,7 @@ pub fn notify_about_rejected_promises(global: &GlobalScope) { } // Step 4-2. - rooted!(in(cx) let reason = GetPromiseResult(promise.reflector().get_jsobject())); + rooted!(in(*cx) let reason = GetPromiseResult(promise.reflector().get_jsobject())); let event = PromiseRejectionEvent::new( &target.global(), -- cgit v1.2.3 From 28e64fc701fc4a5f2f2e2dafe841465fe87e036c Mon Sep 17 00:00:00 2001 From: CYBAI Date: Thu, 8 Aug 2019 12:29:06 +0900 Subject: Assert incumbent global is always some in get_incumbent_global hook While working on module script, I'd like to use Promise with a custom callback with type `Box` which means we didn't use web API callbacks as native handlers. However, we'll get a panic from `enqueue_promise_job` and the panic says we have a `null` incumbent global. The main problem here is, the Promise API is strongly tied to JS engine and it always assumes there's a meaningful answer for "what specific global is this promise associated with". So, when I don't use the Promise for a specific web API, our engine cannot find a proper incumbent global for us so that we get the `null` incumbent global panic. To make us catch this case easier in the future, we should add the assertion inside `get_incumbent_global` hook so that we can know this quickly next time. Ref: https://mozilla.logbot.info/servo/20190807#c16525481 --- components/script/script_runtime.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index fb94d30fafd..5a9fdb0676b 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -142,7 +142,11 @@ pub trait ScriptPort { unsafe extern "C" fn get_incumbent_global(_: *const c_void, _: *mut RawJSContext) -> *mut JSObject { wrap_panic( AssertUnwindSafe(|| { - GlobalScope::incumbent() + let incumbent_global = GlobalScope::incumbent(); + + assert!(incumbent_global.is_some()); + + incumbent_global .map(|g| g.reflector().get_jsobject().get()) .unwrap_or(ptr::null_mut()) }), -- cgit v1.2.3 From 51e22fbc2617dc0b8ccc98cc2b19c95c83daa652 Mon Sep 17 00:00:00 2001 From: marmeladema Date: Sat, 27 Jul 2019 15:20:51 +0100 Subject: Remove some usage of unsafe code in Promise --- components/script/script_runtime.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index fb94d30fafd..2303b59e4ab 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -201,7 +201,8 @@ unsafe extern "C" fn promise_rejection_tracker( // TODO: Step 2 - If script's muted errors is true, terminate these steps. // Step 3. - let global = GlobalScope::from_context(cx); + let cx = JSContext::from_ptr(cx); + let global = GlobalScope::from_context(*cx); wrap_panic( AssertUnwindSafe(|| { @@ -281,7 +282,7 @@ pub fn notify_about_rejected_promises(global: &GlobalScope) { .iter() .map(|promise| { let promise = - Promise::new_with_js_promise(Handle::from_raw(promise.handle()), *cx); + Promise::new_with_js_promise(Handle::from_raw(promise.handle()), cx); TrustedPromise::new(promise) }) -- cgit v1.2.3 From 6d444afd9e3ff4bdfb8a814ecee1d6d39f283439 Mon Sep 17 00:00:00 2001 From: marmeladema Date: Sat, 27 Jul 2019 17:45:17 +0100 Subject: Use safe JSContext in MicrotaskQueue --- components/script/script_runtime.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 2303b59e4ab..a460d1af1b5 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -172,6 +172,7 @@ unsafe extern "C" fn enqueue_promise_job( _allocation_site: HandleObject, incumbent_global: HandleObject, ) -> bool { + let cx = JSContext::from_ptr(cx); wrap_panic( AssertUnwindSafe(|| { let microtask_queue = &*(extra as *const MicrotaskQueue); @@ -179,7 +180,7 @@ unsafe extern "C" fn enqueue_promise_job( let pipeline = global.pipeline_id(); microtask_queue.enqueue( Microtask::Promise(EnqueuedPromiseCallback { - callback: PromiseJobCallback::new(JSContext::from_ptr(cx), job.get()), + callback: PromiseJobCallback::new(cx, job.get()), pipeline, }), cx, -- cgit v1.2.3 From 421001ae1a3b8f3251db1aad20eca3e1fb942f78 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Fri, 30 Aug 2019 17:29:10 -0700 Subject: Work around crash on Windows when returning JS::Value by value. --- components/script/script_runtime.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 02175fffbfc..305dd7d25b5 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -37,8 +37,9 @@ use js::jsapi::{ }; use js::jsapi::{JSObject, PromiseRejectionHandlingState, SetPreserveWrapperCallback}; use js::jsapi::{SetJobQueue, SetProcessBuildIdOp, SetPromiseRejectionTrackerCallback}; +use js::jsval::UndefinedValue; use js::panic::wrap_panic; -use js::rust::wrappers::{GetPromiseIsHandled, GetPromiseResult}; +use js::rust::wrappers::{GetPromiseIsHandled, JS_GetPromiseResult}; use js::rust::Handle; use js::rust::IntoHandle; use js::rust::JSEngine; @@ -251,7 +252,8 @@ unsafe extern "C" fn promise_rejection_tracker( let cx = target.global().get_cx(); let root_promise = trusted_promise.root(); - rooted!(in(*cx) let reason = GetPromiseResult(root_promise.reflector().get_jsobject())); + rooted!(in(*cx) let mut reason = UndefinedValue()); + JS_GetPromiseResult(root_promise.reflector().get_jsobject(), reason.handle_mut()); let event = PromiseRejectionEvent::new( &target.global(), @@ -314,7 +316,8 @@ pub fn notify_about_rejected_promises(global: &GlobalScope) { } // Step 4-2. - rooted!(in(*cx) let reason = GetPromiseResult(promise.reflector().get_jsobject())); + rooted!(in(*cx) let mut reason = UndefinedValue()); + JS_GetPromiseResult(promise.reflector().get_jsobject(), reason.handle_mut()); let event = PromiseRejectionEvent::new( &target.global(), -- cgit v1.2.3 From c3b17c1201441c9a24c4b272108aea0196fbf1b9 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Sun, 11 Dec 2016 03:52:08 -0800 Subject: begin messageport, transferable objects, impl Accept transfer argument for StructuredCloneData::write Allow structured clone reads to return a boolean Add Transferable trait Add basic skeletons to MessagePort Implement transfer and transfer-receiving steps on MessagePort Use transfer and transfer_receive in StructuredClone callbacks Implement MessageChannel Freeze the array object for the MessageEvent ports attribute Implement transfer argument on window.postMessage Use ReentrantMutex instead for MessagePortInternal Accept origin as a parameter in dispatch_jsval Fix BorrowMut crash with pending_port_message Detach port on closure and check for detached during transfer Enable webmessaging tests fix webidl fix --- components/script/script_runtime.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 305dd7d25b5..21cea763c00 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -115,6 +115,7 @@ pub enum ScriptThreadEventCategory { ImageCacheMsg, InputEvent, NetworkEvent, + PortMessage, Resize, ScriptEvent, SetScrollState, -- cgit v1.2.3 From 9fb01e879ba5fa110a171b36189e043a201a14eb Mon Sep 17 00:00:00 2001 From: Ridhim Rastogi Date: Sat, 26 Oct 2019 18:44:12 -0400 Subject: Add StreamConsumer wrapper and ReportStreamErrorCallback fn --- components/script/script_runtime.rs | 56 +++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 21cea763c00..10198050ace 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -5,6 +5,8 @@ //! The script runtime contains common traits and structs commonly used by the //! script thread, the dom, and the worker threads. +#![allow(dead_code)] + use crate::dom::bindings::codegen::Bindings::PromiseBinding::PromiseJobCallback; use crate::dom::bindings::conversions::get_dom_class; use crate::dom::bindings::conversions::private_from_object; @@ -26,7 +28,10 @@ use crate::script_thread::trace_thread; use crate::task::TaskBox; use crate::task_source::{TaskSource, TaskSourceName}; use js::glue::{CollectServoSizes, CreateJobQueue, DeleteJobQueue, JobQueueTraps, SetBuildId}; +use js::glue::{RUST_js_GetErrorMessage, StreamConsumerConsumeChunk, StreamConsumerStreamEnd}; +use js::glue::{StreamConsumerNoteResponseURLs, StreamConsumerStreamError}; use js::jsapi::ContextOptionsRef; +use js::jsapi::StreamConsumer as JSStreamConsumer; use js::jsapi::{BuildIdCharVector, DisableIncrementalGC, GCDescription, GCProgress}; use js::jsapi::{HandleObject, Heap, JobQueue}; use js::jsapi::{JSContext as RawJSContext, JSTracer, SetDOMCallbacks, SetGCSliceCallback}; @@ -51,6 +56,7 @@ use profile_traits::mem::{Report, ReportKind, ReportsChan}; use servo_config::opts; use servo_config::pref; use std::cell::Cell; +use std::ffi::CString; use std::fmt; use std::io::{stdout, Write}; use std::ops::Deref; @@ -776,3 +782,53 @@ impl Deref for JSContext { &self.0 } } + +pub struct StreamConsumer(*mut JSStreamConsumer); + +#[allow(unsafe_code)] +impl StreamConsumer { + fn consume_chunk(&self, stream: &[u8]) -> bool { + unsafe { + let stream_ptr = stream.as_ptr(); + return StreamConsumerConsumeChunk(self.0, stream_ptr, stream.len()); + } + } + + fn stream_end(&self) { + unsafe { + StreamConsumerStreamEnd(self.0); + } + } + + fn stream_error(&self, error_code: usize) { + unsafe { + StreamConsumerStreamError(self.0, error_code); + } + } + + fn note_response_urls(&self, maybe_url: Option, maybe_source_map_url: Option) { + unsafe { + let maybe_url = maybe_url.map(|url| CString::new(url).unwrap()); + let maybe_source_map_url = maybe_source_map_url.map(|url| CString::new(url).unwrap()); + + let maybe_url_param = match maybe_url.as_ref() { + Some(url) => url.as_ptr(), + None => ptr::null(), + }; + let maybe_source_map_url_param = match maybe_source_map_url.as_ref() { + Some(url) => url.as_ptr(), + None => ptr::null(), + }; + + StreamConsumerNoteResponseURLs(self.0, maybe_url_param, maybe_source_map_url_param); + } + } +} + +#[allow(unsafe_code)] +unsafe extern "C" fn report_stream_error_callback(_cx: *mut JSContext, error_code: usize) { + error!( + "Error initializing StreamConsumer: {:?}", + RUST_js_GetErrorMessage(ptr::null_mut(), error_code as u32) + ); +} -- cgit v1.2.3 From 563961826f9f526f8c5c125a23d90cd2ae165762 Mon Sep 17 00:00:00 2001 From: Ridhim Rastogi Date: Sun, 3 Nov 2019 16:47:24 -0500 Subject: Add consume stream callback --- components/script/script_runtime.rs | 109 +++++++++++++++++++++++++++++++++++- 1 file changed, 108 insertions(+), 1 deletion(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 10198050ace..f240bb170d6 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -7,9 +7,14 @@ #![allow(dead_code)] +use crate::body::BodyOperations; use crate::dom::bindings::codegen::Bindings::PromiseBinding::PromiseJobCallback; +use crate::dom::bindings::codegen::Bindings::ResponseBinding::ResponseBinding::ResponseMethods; +use crate::dom::bindings::codegen::Bindings::ResponseBinding::ResponseType as DOMResponseType; use crate::dom::bindings::conversions::get_dom_class; use crate::dom::bindings::conversions::private_from_object; +use crate::dom::bindings::conversions::root_from_handleobject; +use crate::dom::bindings::error::{throw_dom_exception, Error}; use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::refcounted::{trace_refcounted_objects, LiveDOMReferences}; use crate::dom::bindings::refcounted::{Trusted, TrustedPromise}; @@ -23,6 +28,7 @@ use crate::dom::eventtarget::EventTarget; use crate::dom::globalscope::GlobalScope; use crate::dom::promise::Promise; use crate::dom::promiserejectionevent::PromiseRejectionEvent; +use crate::dom::response::Response; use crate::microtask::{EnqueuedPromiseCallback, Microtask, MicrotaskQueue}; use crate::script_thread::trace_thread; use crate::task::TaskBox; @@ -31,6 +37,10 @@ use js::glue::{CollectServoSizes, CreateJobQueue, DeleteJobQueue, JobQueueTraps, use js::glue::{RUST_js_GetErrorMessage, StreamConsumerConsumeChunk, StreamConsumerStreamEnd}; use js::glue::{StreamConsumerNoteResponseURLs, StreamConsumerStreamError}; use js::jsapi::ContextOptionsRef; +use js::jsapi::Dispatchable; +use js::jsapi::InitConsumeStreamCallback; +use js::jsapi::InitDispatchToEventLoop; +use js::jsapi::MimeType; use js::jsapi::StreamConsumer as JSStreamConsumer; use js::jsapi::{BuildIdCharVector, DisableIncrementalGC, GCDescription, GCProgress}; use js::jsapi::{HandleObject, Heap, JobQueue}; @@ -46,6 +56,7 @@ use js::jsval::UndefinedValue; use js::panic::wrap_panic; use js::rust::wrappers::{GetPromiseIsHandled, JS_GetPromiseResult}; use js::rust::Handle; +use js::rust::HandleObject as RustHandleObject; use js::rust::IntoHandle; use js::rust::JSEngine; use js::rust::ParentRuntime; @@ -424,6 +435,16 @@ unsafe fn new_rt_and_cx_with_parent(parent: Option) -> Runtime { // Pre barriers aren't working correctly at the moment DisableIncrementalGC(cx); + unsafe extern "C" fn dispatch_to_event_loop( + _closure: *mut c_void, + _dispatchable: *mut Dispatchable, + ) -> bool { + false + } + InitDispatchToEventLoop(cx, Some(dispatch_to_event_loop), ptr::null_mut()); + + InitConsumeStreamCallback(cx, Some(consume_stream), Some(report_stream_error)); + let microtask_queue = Rc::new(MicrotaskQueue::default()); let job_queue = CreateJobQueue( &JOB_QUEUE_TRAPS, @@ -825,8 +846,94 @@ impl StreamConsumer { } } +/// Implements the steps to compile webassembly response mentioned here +/// +#[allow(unsafe_code)] +unsafe extern "C" fn consume_stream( + _cx: *mut RawJSContext, + obj: HandleObject, + _mimeType: MimeType, + _consumer: *mut JSStreamConsumer, +) -> bool { + let cx = JSContext::from_ptr(_cx); + let global = GlobalScope::from_context(*cx); + + //Step 2.1 Upon fulfillment of source, store the Response with value unwrappedSource. + if let Ok(unwrapped_source) = + root_from_handleobject::(RustHandleObject::from_raw(obj), *cx) + { + //Step 2.2 Let mimeType be the result of extracting a MIME type from response’s header list. + let mimetype = unwrapped_source.Headers().extract_mime_type(); + + //Step 2.3 If mimeType is not `application/wasm`, return with a TypeError and abort these substeps. + match &mimetype[..] { + b"application/wasm" | b"APPLICATION/wasm" | b"APPLICATION/WASM" => {}, + _ => { + throw_dom_exception( + cx, + &global, + Error::Type("Response has unsupported MIME type".to_string()), + ); + return false; + }, + } + + //Step 2.4 If response is not CORS-same-origin, return with a TypeError and abort these substeps. + match unwrapped_source.Type() { + DOMResponseType::Basic | DOMResponseType::Cors | DOMResponseType::Default => {}, + _ => { + throw_dom_exception( + cx, + &global, + Error::Type("Response.type must be 'basic', 'cors' or 'default'".to_string()), + ); + return false; + }, + } + + //Step 2.5 If response’s status is not an ok status, return with a TypeError and abort these substeps. + if !unwrapped_source.Ok() { + throw_dom_exception( + cx, + &global, + Error::Type("Response does not have ok status".to_string()), + ); + return false; + } + + // Step 2.6.1 If response body is locked, return with a TypeError and abort these substeps. + if unwrapped_source.is_locked() { + throw_dom_exception( + cx, + &global, + Error::Type("There was an error consuming the Response".to_string()), + ); + return false; + } + + // Step 2.6.2 If response body is alreaady consumed, return with a TypeError and abort these substeps. + if unwrapped_source.get_body_used() { + throw_dom_exception( + cx, + &global, + Error::Type("Response already consumed".to_string()), + ); + return false; + } + } else { + //Step 3 Upon rejection of source, return with reason. + throw_dom_exception( + cx, + &global, + Error::Type("expected Response or Promise resolving to Response".to_string()), + ); + return false; + } + return true; +} + #[allow(unsafe_code)] -unsafe extern "C" fn report_stream_error_callback(_cx: *mut JSContext, error_code: usize) { +unsafe extern "C" fn report_stream_error(_cx: *mut RawJSContext, error_code: usize) { error!( "Error initializing StreamConsumer: {:?}", RUST_js_GetErrorMessage(ptr::null_mut(), error_code as u32) -- cgit v1.2.3 From 84f16eae98fee221a1a4754c126d08b2a86a35ff Mon Sep 17 00:00:00 2001 From: Akash-Pateria Date: Sat, 16 Nov 2019 22:42:43 -0500 Subject: Bind runnable dispatching in script_runtime --- components/script/script_runtime.rs | 65 +++++++++++++++++++++++++++++-------- 1 file changed, 52 insertions(+), 13 deletions(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index f240bb170d6..20c4ae277c2 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -32,17 +32,20 @@ use crate::dom::response::Response; use crate::microtask::{EnqueuedPromiseCallback, Microtask, MicrotaskQueue}; use crate::script_thread::trace_thread; use crate::task::TaskBox; +use crate::task_source::networking::NetworkingTaskSource; use crate::task_source::{TaskSource, TaskSourceName}; -use js::glue::{CollectServoSizes, CreateJobQueue, DeleteJobQueue, JobQueueTraps, SetBuildId}; -use js::glue::{RUST_js_GetErrorMessage, StreamConsumerConsumeChunk, StreamConsumerStreamEnd}; -use js::glue::{StreamConsumerNoteResponseURLs, StreamConsumerStreamError}; +use js::glue::{CollectServoSizes, CreateJobQueue, DeleteJobQueue, DispatchableRun}; +use js::glue::{JobQueueTraps, RUST_js_GetErrorMessage, SetBuildId, StreamConsumerConsumeChunk}; +use js::glue::{ + StreamConsumerNoteResponseURLs, StreamConsumerStreamEnd, StreamConsumerStreamError, +}; use js::jsapi::ContextOptionsRef; -use js::jsapi::Dispatchable; use js::jsapi::InitConsumeStreamCallback; use js::jsapi::InitDispatchToEventLoop; use js::jsapi::MimeType; use js::jsapi::StreamConsumer as JSStreamConsumer; use js::jsapi::{BuildIdCharVector, DisableIncrementalGC, GCDescription, GCProgress}; +use js::jsapi::{Dispatchable as JSRunnable, Dispatchable_MaybeShuttingDown}; use js::jsapi::{HandleObject, Heap, JobQueue}; use js::jsapi::{JSContext as RawJSContext, JSTracer, SetDOMCallbacks, SetGCSliceCallback}; use js::jsapi::{JSGCInvocationKind, JSGCStatus, JS_AddExtraGCRootsTracer, JS_SetGCCallback}; @@ -397,17 +400,23 @@ lazy_static! { } #[allow(unsafe_code)] -pub unsafe fn new_child_runtime(parent: ParentRuntime) -> Runtime { - new_rt_and_cx_with_parent(Some(parent)) +pub unsafe fn new_child_runtime( + parent: ParentRuntime, + networking_task_source: Option, +) -> Runtime { + new_rt_and_cx_with_parent(Some(parent), networking_task_source) } #[allow(unsafe_code)] -pub fn new_rt_and_cx() -> Runtime { - unsafe { new_rt_and_cx_with_parent(None) } +pub fn new_rt_and_cx(networking_task_source: Option) -> Runtime { + unsafe { new_rt_and_cx_with_parent(None, networking_task_source) } } #[allow(unsafe_code)] -unsafe fn new_rt_and_cx_with_parent(parent: Option) -> Runtime { +unsafe fn new_rt_and_cx_with_parent( + parent: Option, + networking_task_source: Option, +) -> Runtime { LiveDOMReferences::initialize(); let runtime = if let Some(parent) = parent { RustRuntime::create_with_parent(parent) @@ -436,12 +445,26 @@ unsafe fn new_rt_and_cx_with_parent(parent: Option) -> Runtime { DisableIncrementalGC(cx); unsafe extern "C" fn dispatch_to_event_loop( - _closure: *mut c_void, - _dispatchable: *mut Dispatchable, + closure: *mut c_void, + dispatchable: *mut JSRunnable, ) -> bool { - false + let networking_task_src: &NetworkingTaskSource = &*(closure as *mut NetworkingTaskSource); + let runnable = Runnable(dispatchable); + let task = task!(dispatch_to_event_loop_message: move || { + runnable.run(RustRuntime::get(), Dispatchable_MaybeShuttingDown::NotShuttingDown); + }); + + networking_task_src.queue_unconditionally(task).is_ok() + } + + if let Some(source) = networking_task_source { + let networking_task_src = Box::new(source); + InitDispatchToEventLoop( + cx, + Some(dispatch_to_event_loop), + Box::into_raw(networking_task_src) as *mut c_void, + ); } - InitDispatchToEventLoop(cx, Some(dispatch_to_event_loop), ptr::null_mut()); InitConsumeStreamCallback(cx, Some(consume_stream), Some(report_stream_error)); @@ -939,3 +962,19 @@ unsafe extern "C" fn report_stream_error(_cx: *mut RawJSContext, error_code: usi RUST_js_GetErrorMessage(ptr::null_mut(), error_code as u32) ); } + +pub struct Runnable(*mut JSRunnable); + +#[allow(unsafe_code)] +unsafe impl Sync for Runnable {} +#[allow(unsafe_code)] +unsafe impl Send for Runnable {} + +#[allow(unsafe_code)] +impl Runnable { + fn run(&self, cx: *mut RawJSContext, maybe_shutting_down: Dispatchable_MaybeShuttingDown) { + unsafe { + DispatchableRun(cx, self.0, maybe_shutting_down); + } + } +} -- cgit v1.2.3 From 7944d9548cdac3eb18e28035378821a17076e2e5 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Mon, 25 Nov 2019 15:21:27 -0500 Subject: script: Ensure JS engine is initialized and deinitialized on the same thread. --- components/script/script_runtime.rs | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 20c4ae277c2..c95a8cdcf2a 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -61,9 +61,9 @@ use js::rust::wrappers::{GetPromiseIsHandled, JS_GetPromiseResult}; use js::rust::Handle; use js::rust::HandleObject as RustHandleObject; use js::rust::IntoHandle; -use js::rust::JSEngine; use js::rust::ParentRuntime; use js::rust::Runtime as RustRuntime; +use js::rust::{JSEngine, JSEngineHandle}; use malloc_size_of::MallocSizeOfOps; use msg::constellation_msg::PipelineId; use profile_traits::mem::{Report, ReportKind, ReportsChan}; @@ -79,7 +79,9 @@ use std::os::raw::c_void; use std::panic::AssertUnwindSafe; use std::ptr; use std::rc::Rc; -use std::sync::Arc; +use std::sync::Mutex; +use std::thread; +use std::time::Duration; use style::thread_state::{self, ThreadState}; use time::{now, Tm}; @@ -395,8 +397,28 @@ impl Deref for Runtime { } } +pub struct JSEngineSetup(JSEngine); + +impl JSEngineSetup { + pub fn new() -> Self { + let engine = JSEngine::init().unwrap(); + *JS_ENGINE.lock().unwrap() = Some(engine.handle()); + Self(engine) + } +} + +impl Drop for JSEngineSetup { + fn drop(&mut self) { + *JS_ENGINE.lock().unwrap() = None; + + while !self.0.can_shutdown() { + thread::sleep(Duration::from_millis(50)); + } + } +} + lazy_static! { - static ref JS_ENGINE: Arc = JSEngine::init().unwrap(); + static ref JS_ENGINE: Mutex> = Mutex::new(None); } #[allow(unsafe_code)] @@ -421,7 +443,7 @@ unsafe fn new_rt_and_cx_with_parent( let runtime = if let Some(parent) = parent { RustRuntime::create_with_parent(parent) } else { - RustRuntime::new(JS_ENGINE.clone()) + RustRuntime::new(JS_ENGINE.lock().unwrap().as_ref().unwrap().clone()) }; let cx = runtime.cx(); -- cgit v1.2.3 From 1c7f2d696c4c19238d1362497db3ca1b866cc3da Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Mon, 25 Nov 2019 15:26:26 -0500 Subject: Remove use of deprecated language construct. --- components/script/script_runtime.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index c95a8cdcf2a..fa02e7e564e 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -816,7 +816,7 @@ unsafe fn set_gc_zeal_options(cx: *mut RawJSContext) { use js::jsapi::{JS_SetGCZeal, JS_DEFAULT_ZEAL_FREQ}; let level = match pref!(js.mem.gc.zeal.level) { - level @ 0...14 => level as u8, + level @ 0..=14 => level as u8, _ => return, }; let frequency = match pref!(js.mem.gc.zeal.frequency) { -- cgit v1.2.3 From a5469f871073c4cf7912719c8fd47e233805e4e8 Mon Sep 17 00:00:00 2001 From: Ridhim Rastogi Date: Sat, 30 Nov 2019 00:54:11 -0500 Subject: Add StreamConsumer wrapper and methods to response --- components/script/script_runtime.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index fa02e7e564e..02a6b42b854 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -853,26 +853,30 @@ pub struct StreamConsumer(*mut JSStreamConsumer); #[allow(unsafe_code)] impl StreamConsumer { - fn consume_chunk(&self, stream: &[u8]) -> bool { + pub fn consume_chunk(&self, stream: &[u8]) -> bool { unsafe { let stream_ptr = stream.as_ptr(); return StreamConsumerConsumeChunk(self.0, stream_ptr, stream.len()); } } - fn stream_end(&self) { + pub fn stream_end(&self) { unsafe { StreamConsumerStreamEnd(self.0); } } - fn stream_error(&self, error_code: usize) { + pub fn stream_error(&self, error_code: usize) { unsafe { StreamConsumerStreamError(self.0, error_code); } } - fn note_response_urls(&self, maybe_url: Option, maybe_source_map_url: Option) { + pub fn note_response_urls( + &self, + maybe_url: Option, + maybe_source_map_url: Option, + ) { unsafe { let maybe_url = maybe_url.map(|url| CString::new(url).unwrap()); let maybe_source_map_url = maybe_source_map_url.map(|url| CString::new(url).unwrap()); @@ -965,6 +969,7 @@ unsafe extern "C" fn consume_stream( ); return false; } + unwrapped_source.set_stream_consumer(Some(StreamConsumer(_consumer))); } else { //Step 3 Upon rejection of source, return with reason. throw_dom_exception( -- cgit v1.2.3 From 1506643f9adf04c5e6f49c3a1b5ece44efe8631d Mon Sep 17 00:00:00 2001 From: Patrick Shaughnessy Date: Tue, 31 Dec 2019 18:26:45 -0500 Subject: Now using eq_ignore_case on WASM mimetype, per #25317 --- components/script/script_runtime.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 02a6b42b854..3f82e3496e6 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -915,16 +915,13 @@ unsafe extern "C" fn consume_stream( let mimetype = unwrapped_source.Headers().extract_mime_type(); //Step 2.3 If mimeType is not `application/wasm`, return with a TypeError and abort these substeps. - match &mimetype[..] { - b"application/wasm" | b"APPLICATION/wasm" | b"APPLICATION/WASM" => {}, - _ => { - throw_dom_exception( - cx, - &global, - Error::Type("Response has unsupported MIME type".to_string()), - ); - return false; - }, + if !&mimetype[..].eq_ignore_ascii_case(b"application/wasm") { + throw_dom_exception( + cx, + &global, + Error::Type("Response has unsupported MIME type".to_string()), + ); + return false; } //Step 2.4 If response is not CORS-same-origin, return with a TypeError and abort these substeps. -- cgit v1.2.3 From f2007751dd12016bc01fdbe2788322be2eae0d84 Mon Sep 17 00:00:00 2001 From: CYBAI Date: Wed, 5 Jun 2019 22:20:10 +0900 Subject: Scaffold module script --- components/script/script_runtime.rs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 3f82e3496e6..284c49312c6 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -30,6 +30,7 @@ use crate::dom::promise::Promise; use crate::dom::promiserejectionevent::PromiseRejectionEvent; use crate::dom::response::Response; use crate::microtask::{EnqueuedPromiseCallback, Microtask, MicrotaskQueue}; +use crate::script_module::EnsureModuleHooksInitialized; use crate::script_thread::trace_thread; use crate::task::TaskBox; use crate::task_source::networking::NetworkingTaskSource; @@ -498,6 +499,8 @@ unsafe fn new_rt_and_cx_with_parent( SetJobQueue(cx, job_queue); SetPromiseRejectionTrackerCallback(cx, Some(promise_rejection_tracker), ptr::null_mut()); + EnsureModuleHooksInitialized(runtime.rt()); + set_gc_zeal_options(cx); // Enable or disable the JITs. -- cgit v1.2.3 From f7db4b7f8011239f01c3ba2e5e402c866fbe68fb Mon Sep 17 00:00:00 2001 From: Kunal Mohan Date: Sat, 18 Jan 2020 01:29:26 +0530 Subject: Modify `script` to prevent further violations of snake_case --- components/script/script_runtime.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 284c49312c6..b84178a166f 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -904,7 +904,7 @@ impl StreamConsumer { unsafe extern "C" fn consume_stream( _cx: *mut RawJSContext, obj: HandleObject, - _mimeType: MimeType, + _mime_type: MimeType, _consumer: *mut JSStreamConsumer, ) -> bool { let cx = JSContext::from_ptr(_cx); -- cgit v1.2.3 From 403ffcf1eb5c659626f70dec72f76aaf7782986d Mon Sep 17 00:00:00 2001 From: CYBAI Date: Fri, 24 Jan 2020 12:43:49 +0900 Subject: Always pass InRealm to GlobalScope::from_context to avoid getting null global --- components/script/script_runtime.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index b84178a166f..3aa1d79c2d9 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -30,6 +30,7 @@ use crate::dom::promise::Promise; use crate::dom::promiserejectionevent::PromiseRejectionEvent; use crate::dom::response::Response; use crate::microtask::{EnqueuedPromiseCallback, Microtask, MicrotaskQueue}; +use crate::realms::{AlreadyInRealm, InRealm}; use crate::script_module::EnsureModuleHooksInitialized; use crate::script_thread::trace_thread; use crate::task::TaskBox; @@ -232,7 +233,8 @@ unsafe extern "C" fn promise_rejection_tracker( // Step 3. let cx = JSContext::from_ptr(cx); - let global = GlobalScope::from_context(*cx); + let in_realm_proof = AlreadyInRealm::assert_for_cx(cx); + let global = GlobalScope::from_context(*cx, InRealm::Already(&in_realm_proof)); wrap_panic( AssertUnwindSafe(|| { @@ -908,7 +910,8 @@ unsafe extern "C" fn consume_stream( _consumer: *mut JSStreamConsumer, ) -> bool { let cx = JSContext::from_ptr(_cx); - let global = GlobalScope::from_context(*cx); + let in_realm_proof = AlreadyInRealm::assert_for_cx(cx); + let global = GlobalScope::from_context(*cx, InRealm::Already(&in_realm_proof)); //Step 2.1 Upon fulfillment of source, store the Response with value unwrappedSource. if let Ok(unwrapped_source) = -- cgit v1.2.3 From 5a4f8cf93f9f674a164a0a3cfc586accef3d06f9 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Mon, 2 Mar 2020 11:16:46 +0100 Subject: Update SpiderMonkey --- components/script/script_runtime.rs | 39 +++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 19 deletions(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 3aa1d79c2d9..3cce6291d63 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -225,6 +225,7 @@ unsafe extern "C" fn enqueue_promise_job( /// https://html.spec.whatwg.org/multipage/#the-hostpromiserejectiontracker-implementation unsafe extern "C" fn promise_rejection_tracker( cx: *mut RawJSContext, + _muted_errors: bool, promise: HandleObject, state: PromiseRejectionHandlingState, _data: *mut c_void, @@ -507,8 +508,16 @@ unsafe fn new_rt_and_cx_with_parent( // Enable or disable the JITs. let cx_opts = &mut *ContextOptionsRef(cx); - cx_opts.set_baseline_(pref!(js.baseline.enabled)); - cx_opts.set_ion_(pref!(js.ion.enabled)); + JS_SetGlobalJitCompilerOption( + cx, + JSJitCompilerOption::JSJITCOMPILER_BASELINE_ENABLE, + pref!(js.baseline.enabled) as u32, + ); + JS_SetGlobalJitCompilerOption( + cx, + JSJitCompilerOption::JSJITCOMPILER_ION_ENABLE, + pref!(js.ion.enabled) as u32, + ); cx_opts.set_asmJS_(pref!(js.asmjs.enabled)); let wasm_enabled = pref!(js.wasm.enabled); cx_opts.set_wasm_(wasm_enabled); @@ -523,7 +532,11 @@ unsafe fn new_rt_and_cx_with_parent( cx_opts.set_extraWarnings_(pref!(js.strict.enabled)); // TODO: handle js.strict.debug.enabled // TODO: handle js.throw_on_asmjs_validation_failure (needs new Spidermonkey) - cx_opts.set_nativeRegExp_(pref!(js.native_regex.enabled)); + JS_SetGlobalJitCompilerOption( + cx, + JSJitCompilerOption::JSJITCOMPILER_NATIVE_REGEXP_ENABLE, + pref!(js.native_regex.enabled) as u32, + ); JS_SetParallelParsingEnabled(cx, pref!(js.parallel_parsing.enabled)); JS_SetOffthreadIonCompilationEnabled(cx, pref!(js.offthread_compilation.enabled)); JS_SetGlobalJitCompilerOption( @@ -550,11 +563,6 @@ unsafe fn new_rt_and_cx_with_parent( // TODO: handle js.dump_stack_on_debugee_would_run (needs new Spidermonkey) cx_opts.set_werror_(pref!(js.werror.enabled)); // TODO: handle js.shared_memory.enabled - JS_SetGCParameter( - cx, - JSGCParamKey::JSGC_MAX_MALLOC_BYTES, - (pref!(js.mem.high_water_mark) * 1024 * 1024) as u32, - ); JS_SetGCParameter( cx, JSGCParamKey::JSGC_MAX_BYTES, @@ -572,7 +580,7 @@ unsafe fn new_rt_and_cx_with_parent( }; JS_SetGCParameter(cx, JSGCParamKey::JSGC_MODE, js_gc_mode as u32); if let Some(val) = in_range(pref!(js.mem.gc.incremental.slice_ms), 0, 100_000) { - JS_SetGCParameter(cx, JSGCParamKey::JSGC_SLICE_TIME_BUDGET, val as u32); + JS_SetGCParameter(cx, JSGCParamKey::JSGC_SLICE_TIME_BUDGET_MS, val as u32); } JS_SetGCParameter( cx, @@ -617,22 +625,14 @@ unsafe fn new_rt_and_cx_with_parent( JS_SetGCParameter(cx, JSGCParamKey::JSGC_HIGH_FREQUENCY_HIGH_LIMIT, val as u32); } if let Some(val) = in_range(pref!(js.mem.gc.allocation_threshold_factor), 0, 10_000) { - JS_SetGCParameter( - cx, - JSGCParamKey::JSGC_ALLOCATION_THRESHOLD_FACTOR, - val as u32, - ); + JS_SetGCParameter(cx, JSGCParamKey::JSGC_NON_INCREMENTAL_FACTOR, val as u32); } if let Some(val) = in_range( pref!(js.mem.gc.allocation_threshold_avoid_interrupt_factor), 0, 10_000, ) { - JS_SetGCParameter( - cx, - JSGCParamKey::JSGC_ALLOCATION_THRESHOLD_FACTOR_AVOID_INTERRUPT, - val as u32, - ); + JS_SetGCParameter(cx, JSGCParamKey::JSGC_AVOID_INTERRUPT_FACTOR, val as u32); } if let Some(val) = in_range(pref!(js.mem.gc.empty_chunk_count_min), 0, 10_000) { JS_SetGCParameter(cx, JSGCParamKey::JSGC_MIN_EMPTY_CHUNK_COUNT, val as u32); @@ -836,6 +836,7 @@ unsafe fn set_gc_zeal_options(cx: *mut RawJSContext) { unsafe fn set_gc_zeal_options(_: *mut RawJSContext) {} #[derive(Clone, Copy)] +#[repr(transparent)] pub struct JSContext(*mut RawJSContext); #[allow(unsafe_code)] -- cgit v1.2.3 From 5621c887fd5b387c7cab80c182fe579889822212 Mon Sep 17 00:00:00 2001 From: Paul Rouget Date: Thu, 26 Mar 2020 08:36:57 +0100 Subject: Propagate user interacting flag to timers and promises --- components/script/script_runtime.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 3cce6291d63..abe411521af 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -42,9 +42,11 @@ use js::glue::{ StreamConsumerNoteResponseURLs, StreamConsumerStreamEnd, StreamConsumerStreamError, }; use js::jsapi::ContextOptionsRef; +use js::jsapi::GetPromiseUserInputEventHandlingState; use js::jsapi::InitConsumeStreamCallback; use js::jsapi::InitDispatchToEventLoop; use js::jsapi::MimeType; +use js::jsapi::PromiseUserInputEventHandlingState; use js::jsapi::StreamConsumer as JSStreamConsumer; use js::jsapi::{BuildIdCharVector, DisableIncrementalGC, GCDescription, GCProgress}; use js::jsapi::{Dispatchable as JSRunnable, Dispatchable_MaybeShuttingDown}; @@ -197,7 +199,7 @@ unsafe extern "C" fn empty(extra: *const c_void) -> bool { unsafe extern "C" fn enqueue_promise_job( extra: *const c_void, cx: *mut RawJSContext, - _promise: HandleObject, + promise: HandleObject, job: HandleObject, _allocation_site: HandleObject, incumbent_global: HandleObject, @@ -208,10 +210,18 @@ unsafe extern "C" fn enqueue_promise_job( let microtask_queue = &*(extra as *const MicrotaskQueue); let global = GlobalScope::from_object(incumbent_global.get()); let pipeline = global.pipeline_id(); + let interaction = if promise.get().is_null() { + PromiseUserInputEventHandlingState::DontCare + } else { + GetPromiseUserInputEventHandlingState(promise) + }; + let is_user_interacting = + interaction == PromiseUserInputEventHandlingState::HadUserInteractionAtCreation; microtask_queue.enqueue( Microtask::Promise(EnqueuedPromiseCallback { callback: PromiseJobCallback::new(cx, job.get()), pipeline, + is_user_interacting, }), cx, ); -- cgit v1.2.3 From 3ce61098363bd7be5a633d19ede38dcdab108502 Mon Sep 17 00:00:00 2001 From: Gregory Terzian Date: Mon, 30 Mar 2020 14:35:37 +0800 Subject: enable Atomics.wait in a dedicated worker agent --- components/script/script_runtime.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 3cce6291d63..27459d65245 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -44,6 +44,7 @@ use js::glue::{ use js::jsapi::ContextOptionsRef; use js::jsapi::InitConsumeStreamCallback; use js::jsapi::InitDispatchToEventLoop; +use js::jsapi::JS_SetFutexCanWait; use js::jsapi::MimeType; use js::jsapi::StreamConsumer as JSStreamConsumer; use js::jsapi::{BuildIdCharVector, DisableIncrementalGC, GCDescription, GCProgress}; @@ -444,12 +445,22 @@ unsafe fn new_rt_and_cx_with_parent( networking_task_source: Option, ) -> Runtime { LiveDOMReferences::initialize(); - let runtime = if let Some(parent) = parent { - RustRuntime::create_with_parent(parent) + let (cx, runtime) = if let Some(parent) = parent { + let runtime = RustRuntime::create_with_parent(parent); + let cx = runtime.cx(); + + // Note: this enables blocking on an Atomics.wait, + // which should only be enabled for an agent whose [[CanBlock]] is true. + // Currently only a dedicated worker agent uses a parent, + // and this agent can block. + // See https://html.spec.whatwg.org/multipage/#integration-with-the-javascript-agent-cluster-formalism + JS_SetFutexCanWait(cx); + + (cx, runtime) } else { - RustRuntime::new(JS_ENGINE.lock().unwrap().as_ref().unwrap().clone()) + let runtime = RustRuntime::new(JS_ENGINE.lock().unwrap().as_ref().unwrap().clone()); + (runtime.cx(), runtime) }; - let cx = runtime.cx(); JS_AddExtraGCRootsTracer(cx, Some(trace_rust_roots), ptr::null_mut()); -- cgit v1.2.3 From c611e46381c9b813aa134ac34b631145ef0c8672 Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Tue, 7 Apr 2020 16:05:36 -0500 Subject: Remove WebVR --- components/script/script_runtime.rs | 1 - 1 file changed, 1 deletion(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index c9f804596d0..b1851571d8b 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -156,7 +156,6 @@ pub enum ScriptThreadEventCategory { ServiceWorkerEvent, EnterFullscreen, ExitFullscreen, - WebVREvent, PerformanceTimelineTask, } -- cgit v1.2.3 From 39f336b5278fc2c4ab25da508245e8eb86aa9b33 Mon Sep 17 00:00:00 2001 From: Kunal Mohan Date: Fri, 22 May 2020 17:49:35 +0530 Subject: Implement client-side logic for WebGPU id recycling --- components/script/script_runtime.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index b1851571d8b..d8f6d422cd1 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -157,6 +157,7 @@ pub enum ScriptThreadEventCategory { EnterFullscreen, ExitFullscreen, PerformanceTimelineTask, + WebGPUMsg, } /// An interface for receiving ScriptMsg values in an event loop. Used for synchronous DOM -- cgit v1.2.3 From d103e06ba945030d2e5bfdb5a9f0f4b848cbf274 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Mon, 25 May 2020 20:29:18 +0200 Subject: Use dynamic dispatch in `mozjs::panic::wrap_panic` Pick up https://github.com/servo/rust-mozjs/pull/512 Fixes https://github.com/servo/servo/issues/26585 This diff is best viewed with "ignore whitespace changes", because of indentation change. --- components/script/script_runtime.rs | 197 +++++++++++++++++------------------- 1 file changed, 95 insertions(+), 102 deletions(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index d8f6d422cd1..6c725f8cbd3 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -81,7 +81,6 @@ use std::io::{stdout, Write}; use std::ops::Deref; use std::os; use std::os::raw::c_void; -use std::panic::AssertUnwindSafe; use std::ptr; use std::rc::Rc; use std::sync::Mutex; @@ -169,29 +168,27 @@ pub trait ScriptPort { #[allow(unsafe_code)] unsafe extern "C" fn get_incumbent_global(_: *const c_void, _: *mut RawJSContext) -> *mut JSObject { - wrap_panic( - AssertUnwindSafe(|| { - let incumbent_global = GlobalScope::incumbent(); + let mut result = ptr::null_mut(); + wrap_panic(&mut || { + let incumbent_global = GlobalScope::incumbent(); - assert!(incumbent_global.is_some()); + assert!(incumbent_global.is_some()); - incumbent_global - .map(|g| g.reflector().get_jsobject().get()) - .unwrap_or(ptr::null_mut()) - }), - ptr::null_mut(), - ) + result = incumbent_global + .map(|g| g.reflector().get_jsobject().get()) + .unwrap_or(ptr::null_mut()) + }); + result } #[allow(unsafe_code)] unsafe extern "C" fn empty(extra: *const c_void) -> bool { - wrap_panic( - AssertUnwindSafe(|| { - let microtask_queue = &*(extra as *const MicrotaskQueue); - microtask_queue.empty() - }), - false, - ) + let mut result = false; + wrap_panic(&mut || { + let microtask_queue = &*(extra as *const MicrotaskQueue); + result = microtask_queue.empty() + }); + result } /// SM callback for promise job resolution. Adds a promise callback to the current @@ -206,30 +203,29 @@ unsafe extern "C" fn enqueue_promise_job( incumbent_global: HandleObject, ) -> bool { let cx = JSContext::from_ptr(cx); - wrap_panic( - AssertUnwindSafe(|| { - let microtask_queue = &*(extra as *const MicrotaskQueue); - let global = GlobalScope::from_object(incumbent_global.get()); - let pipeline = global.pipeline_id(); - let interaction = if promise.get().is_null() { - PromiseUserInputEventHandlingState::DontCare - } else { - GetPromiseUserInputEventHandlingState(promise) - }; - let is_user_interacting = - interaction == PromiseUserInputEventHandlingState::HadUserInteractionAtCreation; - microtask_queue.enqueue( - Microtask::Promise(EnqueuedPromiseCallback { - callback: PromiseJobCallback::new(cx, job.get()), - pipeline, - is_user_interacting, - }), - cx, - ); - true - }), - false, - ) + let mut result = false; + wrap_panic(&mut || { + let microtask_queue = &*(extra as *const MicrotaskQueue); + let global = GlobalScope::from_object(incumbent_global.get()); + let pipeline = global.pipeline_id(); + let interaction = if promise.get().is_null() { + PromiseUserInputEventHandlingState::DontCare + } else { + GetPromiseUserInputEventHandlingState(promise) + }; + let is_user_interacting = + interaction == PromiseUserInputEventHandlingState::HadUserInteractionAtCreation; + microtask_queue.enqueue( + Microtask::Promise(EnqueuedPromiseCallback { + callback: PromiseJobCallback::new(cx, job.get()), + pipeline, + is_user_interacting, + }), + cx, + ); + result = true + }); + result } #[allow(unsafe_code, unrooted_must_root)] @@ -248,69 +244,66 @@ unsafe extern "C" fn promise_rejection_tracker( let in_realm_proof = AlreadyInRealm::assert_for_cx(cx); let global = GlobalScope::from_context(*cx, InRealm::Already(&in_realm_proof)); - wrap_panic( - AssertUnwindSafe(|| { - match state { - // Step 4. - PromiseRejectionHandlingState::Unhandled => { - global.add_uncaught_rejection(promise); - }, - // Step 5. - PromiseRejectionHandlingState::Handled => { - // Step 5-1. - if global - .get_uncaught_rejections() - .borrow() - .contains(&Heap::boxed(promise.get())) - { - global.remove_uncaught_rejection(promise); - return; - } - - // Step 5-2. - if !global - .get_consumed_rejections() - .borrow() - .contains(&Heap::boxed(promise.get())) - { - return; - } - - // Step 5-3. - global.remove_consumed_rejection(promise); - - let target = Trusted::new(global.upcast::()); - let promise = Promise::new_with_js_promise(Handle::from_raw(promise), cx); - let trusted_promise = TrustedPromise::new(promise.clone()); - - // Step 5-4. - global.dom_manipulation_task_source().queue( - task!(rejection_handled_event: move || { - let target = target.root(); - let cx = target.global().get_cx(); - let root_promise = trusted_promise.root(); + wrap_panic(&mut || { + match state { + // Step 4. + PromiseRejectionHandlingState::Unhandled => { + global.add_uncaught_rejection(promise); + }, + // Step 5. + PromiseRejectionHandlingState::Handled => { + // Step 5-1. + if global + .get_uncaught_rejections() + .borrow() + .contains(&Heap::boxed(promise.get())) + { + global.remove_uncaught_rejection(promise); + return; + } + + // Step 5-2. + if !global + .get_consumed_rejections() + .borrow() + .contains(&Heap::boxed(promise.get())) + { + return; + } + + // Step 5-3. + global.remove_consumed_rejection(promise); + + let target = Trusted::new(global.upcast::()); + let promise = Promise::new_with_js_promise(Handle::from_raw(promise), cx); + let trusted_promise = TrustedPromise::new(promise.clone()); + + // Step 5-4. + global.dom_manipulation_task_source().queue( + task!(rejection_handled_event: move || { + let target = target.root(); + let cx = target.global().get_cx(); + let root_promise = trusted_promise.root(); - rooted!(in(*cx) let mut reason = UndefinedValue()); - JS_GetPromiseResult(root_promise.reflector().get_jsobject(), reason.handle_mut()); + rooted!(in(*cx) let mut reason = UndefinedValue()); + JS_GetPromiseResult(root_promise.reflector().get_jsobject(), reason.handle_mut()); - let event = PromiseRejectionEvent::new( - &target.global(), - atom!("rejectionhandled"), - EventBubbles::DoesNotBubble, - EventCancelable::Cancelable, - root_promise, - reason.handle() - ); + let event = PromiseRejectionEvent::new( + &target.global(), + atom!("rejectionhandled"), + EventBubbles::DoesNotBubble, + EventCancelable::Cancelable, + root_promise, + reason.handle() + ); - event.upcast::().fire(&target); - }), - global.upcast(), - ).unwrap(); - }, - }; - }), - (), - ); + event.upcast::().fire(&target); + }), + global.upcast(), + ).unwrap(); + }, + }; + }) } #[allow(unsafe_code, unrooted_must_root)] -- cgit v1.2.3 From bd5796c90b8e8e066a32e7da9cfa5251d1559046 Mon Sep 17 00:00:00 2001 From: Gregory Terzian Date: Sat, 29 Feb 2020 11:59:10 +0800 Subject: integrate readablestream with fetch and blob --- components/script/script_runtime.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 6c725f8cbd3..4cf2055c649 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -7,7 +7,7 @@ #![allow(dead_code)] -use crate::body::BodyOperations; +use crate::body::BodyMixin; use crate::dom::bindings::codegen::Bindings::PromiseBinding::PromiseJobCallback; use crate::dom::bindings::codegen::Bindings::ResponseBinding::ResponseBinding::ResponseMethods; use crate::dom::bindings::codegen::Bindings::ResponseBinding::ResponseType as DOMResponseType; @@ -979,7 +979,7 @@ unsafe extern "C" fn consume_stream( } // Step 2.6.2 If response body is alreaady consumed, return with a TypeError and abort these substeps. - if unwrapped_source.get_body_used() { + if unwrapped_source.is_disturbed() { throw_dom_exception( cx, &global, -- cgit v1.2.3 From 83578265b456d53f62e1d71378b6d84fc853ca54 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Thu, 11 Jun 2020 13:32:40 -0400 Subject: Don't pretend we support SharedArrayBuffer. --- components/script/script_runtime.rs | 9 --------- 1 file changed, 9 deletions(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 4cf2055c649..dc51330cf91 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -45,7 +45,6 @@ use js::jsapi::ContextOptionsRef; use js::jsapi::GetPromiseUserInputEventHandlingState; use js::jsapi::InitConsumeStreamCallback; use js::jsapi::InitDispatchToEventLoop; -use js::jsapi::JS_SetFutexCanWait; use js::jsapi::MimeType; use js::jsapi::PromiseUserInputEventHandlingState; use js::jsapi::StreamConsumer as JSStreamConsumer; @@ -451,14 +450,6 @@ unsafe fn new_rt_and_cx_with_parent( let (cx, runtime) = if let Some(parent) = parent { let runtime = RustRuntime::create_with_parent(parent); let cx = runtime.cx(); - - // Note: this enables blocking on an Atomics.wait, - // which should only be enabled for an agent whose [[CanBlock]] is true. - // Currently only a dedicated worker agent uses a parent, - // and this agent can block. - // See https://html.spec.whatwg.org/multipage/#integration-with-the-javascript-agent-cluster-formalism - JS_SetFutexCanWait(cx); - (cx, runtime) } else { let runtime = RustRuntime::new(JS_ENGINE.lock().unwrap().as_ref().unwrap().clone()); -- cgit v1.2.3 From 2e4cee99710a5745adf2bd1df185adcd36e5104f Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Tue, 16 Jun 2020 17:21:18 -0400 Subject: dom: Avoid panic when SpiderMonkey enqueues dummy promise jobs. --- components/script/script_runtime.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 4cf2055c649..a0a771941b2 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -206,7 +206,12 @@ unsafe extern "C" fn enqueue_promise_job( let mut result = false; wrap_panic(&mut || { let microtask_queue = &*(extra as *const MicrotaskQueue); - let global = GlobalScope::from_object(incumbent_global.get()); + let global = if !incumbent_global.is_null() { + GlobalScope::from_object(incumbent_global.get()) + } else { + let realm = AlreadyInRealm::assert_for_cx(cx); + GlobalScope::from_context(*cx, InRealm::in_realm(&realm)) + }; let pipeline = global.pipeline_id(); let interaction = if promise.get().is_null() { PromiseUserInputEventHandlingState::DontCare -- cgit v1.2.3 From 44ebca72da45575df4e5970e25920c46c14aa0cb Mon Sep 17 00:00:00 2001 From: Gregory Terzian Date: Wed, 24 Jun 2020 15:07:48 +0800 Subject: ensure clean shutdown of all threads running JS --- components/script/script_runtime.rs | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 4016f3b9858..f2d8bb73947 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -52,7 +52,10 @@ use js::jsapi::{BuildIdCharVector, DisableIncrementalGC, GCDescription, GCProgre use js::jsapi::{Dispatchable as JSRunnable, Dispatchable_MaybeShuttingDown}; use js::jsapi::{HandleObject, Heap, JobQueue}; use js::jsapi::{JSContext as RawJSContext, JSTracer, SetDOMCallbacks, SetGCSliceCallback}; -use js::jsapi::{JSGCInvocationKind, JSGCStatus, JS_AddExtraGCRootsTracer, JS_SetGCCallback}; +use js::jsapi::{ + JSGCInvocationKind, JSGCStatus, JS_AddExtraGCRootsTracer, JS_RequestInterruptCallback, + JS_SetGCCallback, +}; use js::jsapi::{JSGCMode, JSGCParamKey, JS_SetGCParameter, JS_SetGlobalJitCompilerOption}; use js::jsapi::{ JSJitCompilerOption, JS_SetOffthreadIonCompilationEnabled, JS_SetParallelParsingEnabled, @@ -845,6 +848,34 @@ unsafe fn set_gc_zeal_options(cx: *mut RawJSContext) { #[cfg(not(feature = "debugmozjs"))] unsafe fn set_gc_zeal_options(_: *mut RawJSContext) {} +#[repr(transparent)] +/// A wrapper around a JSContext that is Send, +/// enabling an interrupt to be requested +/// from a thread other than the one running JS using that context. +pub struct ContextForRequestInterrupt(*mut RawJSContext); + +impl ContextForRequestInterrupt { + pub fn new(context: *mut RawJSContext) -> ContextForRequestInterrupt { + ContextForRequestInterrupt(context) + } + + #[allow(unsafe_code)] + /// Can be called from any thread, to request the callback set by + /// JS_AddInterruptCallback to be called + /// on the thread where that context is running. + pub fn request_interrupt(&self) { + unsafe { + JS_RequestInterruptCallback(self.0); + } + } +} + +#[allow(unsafe_code)] +/// It is safe to call `JS_RequestInterruptCallback(cx)` from any thread. +/// See the docs for the corresponding `requestInterrupt` method, +/// at `mozjs/js/src/vm/JSContext.h`. +unsafe impl Send for ContextForRequestInterrupt {} + #[derive(Clone, Copy)] #[repr(transparent)] pub struct JSContext(*mut RawJSContext); -- cgit v1.2.3 From 5c4939599e2793154569b19db87be8cc05ca9269 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Sun, 24 Jan 2021 14:07:10 -0500 Subject: Update mozjs. --- components/script/script_runtime.rs | 60 ++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 31 deletions(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index f2d8bb73947..f60c42f7e46 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -50,17 +50,17 @@ use js::jsapi::PromiseUserInputEventHandlingState; use js::jsapi::StreamConsumer as JSStreamConsumer; use js::jsapi::{BuildIdCharVector, DisableIncrementalGC, GCDescription, GCProgress}; use js::jsapi::{Dispatchable as JSRunnable, Dispatchable_MaybeShuttingDown}; -use js::jsapi::{HandleObject, Heap, JobQueue}; -use js::jsapi::{JSContext as RawJSContext, JSTracer, SetDOMCallbacks, SetGCSliceCallback}; use js::jsapi::{ - JSGCInvocationKind, JSGCStatus, JS_AddExtraGCRootsTracer, JS_RequestInterruptCallback, - JS_SetGCCallback, + GCReason, JSGCInvocationKind, JSGCStatus, JS_AddExtraGCRootsTracer, + JS_RequestInterruptCallback, JS_SetGCCallback, }; +use js::jsapi::{HandleObject, Heap, JobQueue}; +use js::jsapi::{JSContext as RawJSContext, JSTracer, SetDOMCallbacks, SetGCSliceCallback}; use js::jsapi::{JSGCMode, JSGCParamKey, JS_SetGCParameter, JS_SetGlobalJitCompilerOption}; use js::jsapi::{ JSJitCompilerOption, JS_SetOffthreadIonCompilationEnabled, JS_SetParallelParsingEnabled, }; -use js::jsapi::{JSObject, PromiseRejectionHandlingState, SetPreserveWrapperCallback}; +use js::jsapi::{JSObject, PromiseRejectionHandlingState, SetPreserveWrapperCallbacks}; use js::jsapi::{SetJobQueue, SetProcessBuildIdOp, SetPromiseRejectionTrackerCallback}; use js::jsval::UndefinedValue; use js::panic::wrap_panic; @@ -478,8 +478,16 @@ unsafe fn new_rt_and_cx_with_parent( unsafe extern "C" fn empty_wrapper_callback(_: *mut RawJSContext, _: HandleObject) -> bool { true } + unsafe extern "C" fn empty_has_released_callback(_: HandleObject) -> bool { + // fixme: return true when the Drop impl for a DOM object has been invoked + false + } SetDOMCallbacks(cx, &DOM_CALLBACKS); - SetPreserveWrapperCallback(cx, Some(empty_wrapper_callback)); + SetPreserveWrapperCallbacks( + cx, + Some(empty_wrapper_callback), + Some(empty_has_released_callback), + ); // Pre barriers aren't working correctly at the moment DisableIncrementalGC(cx); @@ -542,7 +550,7 @@ unsafe fn new_rt_and_cx_with_parent( } cx_opts.set_wasmBaseline_(pref!(js.wasm.baseline.enabled)); cx_opts.set_wasmIon_(pref!(js.wasm.ion.enabled)); - cx_opts.set_extraWarnings_(pref!(js.strict.enabled)); + cx_opts.set_strictMode_(pref!(js.strict.enabled)); // TODO: handle js.strict.debug.enabled // TODO: handle js.throw_on_asmjs_validation_failure (needs new Spidermonkey) JS_SetGlobalJitCompilerOption( @@ -574,7 +582,6 @@ unsafe fn new_rt_and_cx_with_parent( // TODO: handle js.asyncstack.enabled (needs new Spidermonkey) // TODO: handle js.throw_on_debugee_would_run (needs new Spidermonkey) // TODO: handle js.dump_stack_on_debugee_would_run (needs new Spidermonkey) - cx_opts.set_werror_(pref!(js.werror.enabled)); // TODO: handle js.shared_memory.enabled JS_SetGCParameter( cx, @@ -604,49 +611,39 @@ unsafe fn new_rt_and_cx_with_parent( if let Some(val) = in_range(pref!(js.mem.gc.high_frequency_time_limit_ms), 0, 10_000) { JS_SetGCParameter(cx, JSGCParamKey::JSGC_HIGH_FREQUENCY_TIME_LIMIT, val as u32); } - JS_SetGCParameter( - cx, - JSGCParamKey::JSGC_DYNAMIC_MARK_SLICE, - pref!(js.mem.gc.dynamic_mark_slice.enabled) as u32, - ); - JS_SetGCParameter( - cx, - JSGCParamKey::JSGC_DYNAMIC_HEAP_GROWTH, - pref!(js.mem.gc.dynamic_heap_growth.enabled) as u32, - ); if let Some(val) = in_range(pref!(js.mem.gc.low_frequency_heap_growth), 0, 10_000) { JS_SetGCParameter(cx, JSGCParamKey::JSGC_LOW_FREQUENCY_HEAP_GROWTH, val as u32); } if let Some(val) = in_range(pref!(js.mem.gc.high_frequency_heap_growth_min), 0, 10_000) { JS_SetGCParameter( cx, - JSGCParamKey::JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MIN, + JSGCParamKey::JSGC_HIGH_FREQUENCY_LARGE_HEAP_GROWTH, val as u32, ); } if let Some(val) = in_range(pref!(js.mem.gc.high_frequency_heap_growth_max), 0, 10_000) { JS_SetGCParameter( cx, - JSGCParamKey::JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MAX, + JSGCParamKey::JSGC_HIGH_FREQUENCY_SMALL_HEAP_GROWTH, val as u32, ); } if let Some(val) = in_range(pref!(js.mem.gc.high_frequency_low_limit_mb), 0, 10_000) { - JS_SetGCParameter(cx, JSGCParamKey::JSGC_HIGH_FREQUENCY_LOW_LIMIT, val as u32); + JS_SetGCParameter(cx, JSGCParamKey::JSGC_SMALL_HEAP_SIZE_MAX, val as u32); } if let Some(val) = in_range(pref!(js.mem.gc.high_frequency_high_limit_mb), 0, 10_000) { - JS_SetGCParameter(cx, JSGCParamKey::JSGC_HIGH_FREQUENCY_HIGH_LIMIT, val as u32); + JS_SetGCParameter(cx, JSGCParamKey::JSGC_LARGE_HEAP_SIZE_MIN, val as u32); } - if let Some(val) = in_range(pref!(js.mem.gc.allocation_threshold_factor), 0, 10_000) { + /*if let Some(val) = in_range(pref!(js.mem.gc.allocation_threshold_factor), 0, 10_000) { JS_SetGCParameter(cx, JSGCParamKey::JSGC_NON_INCREMENTAL_FACTOR, val as u32); - } - if let Some(val) = in_range( - pref!(js.mem.gc.allocation_threshold_avoid_interrupt_factor), - 0, - 10_000, - ) { - JS_SetGCParameter(cx, JSGCParamKey::JSGC_AVOID_INTERRUPT_FACTOR, val as u32); - } + }*/ + /* + // JSGC_SMALL_HEAP_INCREMENTAL_LIMIT + pref("javascript.options.mem.gc_small_heap_incremental_limit", 140); + + // JSGC_LARGE_HEAP_INCREMENTAL_LIMIT + pref("javascript.options.mem.gc_large_heap_incremental_limit", 110); + */ if let Some(val) = in_range(pref!(js.mem.gc.empty_chunk_count_min), 0, 10_000) { JS_SetGCParameter(cx, JSGCParamKey::JSGC_MIN_EMPTY_CHUNK_COUNT, val as u32); } @@ -796,6 +793,7 @@ unsafe extern "C" fn gc_slice_callback( unsafe extern "C" fn debug_gc_callback( _cx: *mut RawJSContext, status: JSGCStatus, + _reason: GCReason, _data: *mut os::raw::c_void, ) { match status { -- cgit v1.2.3 From 425057c4323fe9bf3857e2c99912dc10b79166b7 Mon Sep 17 00:00:00 2001 From: sagudev Date: Fri, 12 Mar 2021 16:26:27 +0100 Subject: Fix errors --- components/script/script_runtime.rs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index f60c42f7e46..ca57b157083 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -56,7 +56,7 @@ use js::jsapi::{ }; use js::jsapi::{HandleObject, Heap, JobQueue}; use js::jsapi::{JSContext as RawJSContext, JSTracer, SetDOMCallbacks, SetGCSliceCallback}; -use js::jsapi::{JSGCMode, JSGCParamKey, JS_SetGCParameter, JS_SetGlobalJitCompilerOption}; +use js::jsapi::{JSGCParamKey, JS_SetGCParameter, JS_SetGlobalJitCompilerOption}; use js::jsapi::{ JSJitCompilerOption, JS_SetOffthreadIonCompilationEnabled, JS_SetParallelParsingEnabled, }; @@ -591,14 +591,8 @@ unsafe fn new_rt_and_cx_with_parent( .unwrap_or(u32::max_value()), ); // NOTE: This is disabled above, so enabling it here will do nothing for now. - let js_gc_mode = if pref!(js.mem.gc.incremental.enabled) { - JSGCMode::JSGC_MODE_INCREMENTAL - } else if pref!(js.mem.gc.per_zone.enabled) { - JSGCMode::JSGC_MODE_ZONE - } else { - JSGCMode::JSGC_MODE_GLOBAL - }; - JS_SetGCParameter(cx, JSGCParamKey::JSGC_MODE, js_gc_mode as u32); + JS_SetGCParameter(cx, JSGCParamKey::JSGC_INCREMENTAL_GC_ENABLED, pref!(js.mem.gc.incremental.enabled) as u32); + JS_SetGCParameter(cx, JSGCParamKey::JSGC_PER_ZONE_GC_ENABLED, pref!(js.mem.gc.per_zone.enabled) as u32); if let Some(val) = in_range(pref!(js.mem.gc.incremental.slice_ms), 0, 100_000) { JS_SetGCParameter(cx, JSGCParamKey::JSGC_SLICE_TIME_BUDGET_MS, val as u32); } -- cgit v1.2.3 From a265a2a7e6c53eda558aa61712646382bbe129af Mon Sep 17 00:00:00 2001 From: sagudev Date: Fri, 12 Mar 2021 18:30:13 +0100 Subject: Formating --- components/script/script_runtime.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'components/script/script_runtime.rs') diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index ca57b157083..c44b4b04676 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -591,8 +591,16 @@ unsafe fn new_rt_and_cx_with_parent( .unwrap_or(u32::max_value()), ); // NOTE: This is disabled above, so enabling it here will do nothing for now. - JS_SetGCParameter(cx, JSGCParamKey::JSGC_INCREMENTAL_GC_ENABLED, pref!(js.mem.gc.incremental.enabled) as u32); - JS_SetGCParameter(cx, JSGCParamKey::JSGC_PER_ZONE_GC_ENABLED, pref!(js.mem.gc.per_zone.enabled) as u32); + JS_SetGCParameter( + cx, + JSGCParamKey::JSGC_INCREMENTAL_GC_ENABLED, + pref!(js.mem.gc.incremental.enabled) as u32, + ); + JS_SetGCParameter( + cx, + JSGCParamKey::JSGC_PER_ZONE_GC_ENABLED, + pref!(js.mem.gc.per_zone.enabled) as u32, + ); if let Some(val) = in_range(pref!(js.mem.gc.incremental.slice_ms), 0, 100_000) { JS_SetGCParameter(cx, JSGCParamKey::JSGC_SLICE_TIME_BUDGET_MS, val as u32); } -- cgit v1.2.3