aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
authorDelan Azabani <dazabani@igalia.com>2024-11-19 17:07:38 +0800
committerGitHub <noreply@github.com>2024-11-19 09:07:38 +0000
commit26748621cda6301038647b3b3f06ed9c681c5d11 (patch)
tree19cc3fadd6a18b7fe290e8a2b3b71f43fe41485f /components/script/dom
parent4a06dc53f66a1d9a7b2f8619bfe13c6ccacb28c4 (diff)
downloadservo-26748621cda6301038647b3b3f06ed9c681c5d11.tar.gz
servo-26748621cda6301038647b3b3f06ed9c681c5d11.zip
Make ScriptEvaluate count script execution in DOM events and timers (#34286)
Signed-off-by: Delan Azabani <dazabani@igalia.com>
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/bindings/settings_stack.rs4
-rw-r--r--components/script/dom/globalscope.rs144
2 files changed, 68 insertions, 80 deletions
diff --git a/components/script/dom/bindings/settings_stack.rs b/components/script/dom/bindings/settings_stack.rs
index 0e913eb3de6..7cd157a612f 100644
--- a/components/script/dom/bindings/settings_stack.rs
+++ b/components/script/dom/bindings/settings_stack.rs
@@ -42,6 +42,8 @@ pub fn is_execution_stack_empty() -> bool {
/// RAII struct that pushes and pops entries from the script settings stack.
pub struct AutoEntryScript {
global: DomRoot<GlobalScope>,
+ #[cfg(feature = "tracing")]
+ span: tracing::span::EnteredSpan,
}
impl AutoEntryScript {
@@ -56,6 +58,8 @@ impl AutoEntryScript {
});
AutoEntryScript {
global: DomRoot::from_ref(global),
+ #[cfg(feature = "tracing")]
+ span: tracing::info_span!("ScriptEvaluate", servo_profiling = true).entered(),
}
})
}
diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs
index ca5d66deb94..ac6a2b07b1e 100644
--- a/components/script/dom/globalscope.rs
+++ b/components/script/dom/globalscope.rs
@@ -52,7 +52,7 @@ use net_traits::{
fetch_async, CoreResourceMsg, CoreResourceThread, FetchResponseListener, IpcSend,
ReferrerPolicy, ResourceThreads,
};
-use profile_traits::{ipc as profile_ipc, mem as profile_mem, time as profile_time, time_profile};
+use profile_traits::{ipc as profile_ipc, mem as profile_mem, time as profile_time};
use script_traits::serializable::{BlobData, BlobImpl, FileBlob};
use script_traits::transferable::MessagePortImpl;
use script_traits::{
@@ -2677,98 +2677,82 @@ impl GlobalScope {
script_base_url: ServoUrl,
can_gc: CanGc,
) -> bool {
- let metadata = profile_time::TimerMetadata {
- url: if filename.is_empty() {
- self.get_url().as_str().into()
- } else {
- filename.into()
- },
- iframe: profile_time::TimerMetadataFrameType::RootWindow,
- incremental: profile_time::TimerMetadataReflowType::FirstReflow,
- };
- time_profile!(
- profile_time::ProfilerCategory::ScriptEvaluate,
- Some(metadata),
- self.time_profiler_chan().clone(),
- || {
- let cx = GlobalScope::get_cx();
+ let cx = GlobalScope::get_cx();
- let ar = enter_realm(self);
+ let ar = enter_realm(self);
- let _aes = AutoEntryScript::new(self);
+ let _aes = AutoEntryScript::new(self);
- unsafe {
- rooted!(in(*cx) let mut compiled_script = std::ptr::null_mut::<JSScript>());
- match code {
- SourceCode::Text(text_code) => {
- let options = CompileOptionsWrapper::new(*cx, filename, line_number);
-
- debug!("compiling dom string");
- compiled_script.set(Compile1(
- *cx,
- options.ptr,
- &mut transform_str_to_source_text(text_code),
- ));
+ unsafe {
+ rooted!(in(*cx) let mut compiled_script = std::ptr::null_mut::<JSScript>());
+ match code {
+ SourceCode::Text(text_code) => {
+ let options = CompileOptionsWrapper::new(*cx, filename, line_number);
+
+ debug!("compiling dom string");
+ compiled_script.set(Compile1(
+ *cx,
+ options.ptr,
+ &mut transform_str_to_source_text(text_code),
+ ));
- if compiled_script.is_null() {
- debug!("error compiling Dom string");
- report_pending_exception(*cx, true, InRealm::Entered(&ar), can_gc);
- return false;
- }
- },
- SourceCode::Compiled(pre_compiled_script) => {
- let options = InstantiateOptions {
- skipFilenameValidation: false,
- hideScriptFromDebugger: false,
- deferDebugMetadata: false,
- };
- let script = InstantiateGlobalStencil(
- *cx,
- &options,
- *pre_compiled_script.source_code,
- ptr::null_mut(),
- );
- compiled_script.set(script);
- },
+ if compiled_script.is_null() {
+ debug!("error compiling Dom string");
+ report_pending_exception(*cx, true, InRealm::Entered(&ar), can_gc);
+ return false;
+ }
+ },
+ SourceCode::Compiled(pre_compiled_script) => {
+ let options = InstantiateOptions {
+ skipFilenameValidation: false,
+ hideScriptFromDebugger: false,
+ deferDebugMetadata: false,
};
+ let script = InstantiateGlobalStencil(
+ *cx,
+ &options,
+ *pre_compiled_script.source_code,
+ ptr::null_mut(),
+ );
+ compiled_script.set(script);
+ },
+ };
- assert!(!compiled_script.is_null());
+ assert!(!compiled_script.is_null());
- rooted!(in(*cx) let mut script_private = UndefinedValue());
- JS_GetScriptPrivate(*compiled_script, script_private.handle_mut());
+ rooted!(in(*cx) let mut script_private = UndefinedValue());
+ JS_GetScriptPrivate(*compiled_script, script_private.handle_mut());
- // When `ScriptPrivate` for the compiled script is undefined,
- // we need to set it so that it can be used in dynamic import context.
- if script_private.is_undefined() {
- debug!("Set script private for {}", script_base_url);
+ // When `ScriptPrivate` for the compiled script is undefined,
+ // we need to set it so that it can be used in dynamic import context.
+ if script_private.is_undefined() {
+ debug!("Set script private for {}", script_base_url);
- let module_script_data = Rc::new(ModuleScript::new(
- script_base_url,
- fetch_options,
- // We can't initialize an module owner here because
- // the executing context of script might be different
- // from the dynamic import script's executing context.
- None,
- ));
+ let module_script_data = Rc::new(ModuleScript::new(
+ script_base_url,
+ fetch_options,
+ // We can't initialize an module owner here because
+ // the executing context of script might be different
+ // from the dynamic import script's executing context.
+ None,
+ ));
- SetScriptPrivate(
- *compiled_script,
- &PrivateValue(Rc::into_raw(module_script_data) as *const _),
- );
- }
+ SetScriptPrivate(
+ *compiled_script,
+ &PrivateValue(Rc::into_raw(module_script_data) as *const _),
+ );
+ }
- let result = JS_ExecuteScript(*cx, compiled_script.handle(), rval);
+ let result = JS_ExecuteScript(*cx, compiled_script.handle(), rval);
- if !result {
- debug!("error evaluating Dom string");
- report_pending_exception(*cx, true, InRealm::Entered(&ar), can_gc);
- }
+ if !result {
+ debug!("error evaluating Dom string");
+ report_pending_exception(*cx, true, InRealm::Entered(&ar), can_gc);
+ }
- maybe_resume_unwind();
- result
- }
- },
- )
+ maybe_resume_unwind();
+ result
+ }
}
/// <https://html.spec.whatwg.org/multipage/#timer-initialisation-steps>