diff options
author | AbhishekSharma102 <20724848+AbhishekSharma102@users.noreply.github.com> | 2020-07-13 06:04:00 +0000 |
---|---|---|
committer | Josh Matthews <josh@joshmatthews.net> | 2020-07-21 16:20:51 -0400 |
commit | 1119dd119ed335b6d6e448290b56e0eeab6de25f (patch) | |
tree | c1d2ae2b369a20923cfe8e24496193896c4ad473 /components/script/dom/globalscope.rs | |
parent | bfb7bea704340e19583b04fb02b444fadd35e9e1 (diff) | |
download | servo-1119dd119ed335b6d6e448290b56e0eeab6de25f.tar.gz servo-1119dd119ed335b6d6e448290b56e0eeab6de25f.zip |
Added off thread compilation
Co-authored-by: Gregory Terzian <2792687+gterzian@users.noreply.github.com>
Co-authored-by: Abhishek Sharma <20724848+AbhishekSharma102@users.noreply.github.com>
Diffstat (limited to 'components/script/dom/globalscope.rs')
-rw-r--r-- | components/script/dom/globalscope.rs | 99 |
1 files changed, 55 insertions, 44 deletions
diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs index a6427224882..9917d602ab3 100644 --- a/components/script/dom/globalscope.rs +++ b/components/script/dom/globalscope.rs @@ -38,7 +38,7 @@ use crate::dom::file::File; use crate::dom::gpudevice::GPUDevice; use crate::dom::gpuoutofmemoryerror::GPUOutOfMemoryError; use crate::dom::gpuvalidationerror::GPUValidationError; -use crate::dom::htmlscriptelement::ScriptId; +use crate::dom::htmlscriptelement::{ScriptId, SourceCode}; use crate::dom::identityhub::Identities; use crate::dom::imagebitmap::ImageBitmap; use crate::dom::messageevent::MessageEvent; @@ -91,9 +91,9 @@ use js::jsval::PrivateValue; use js::jsval::{JSVal, UndefinedValue}; use js::panic::maybe_resume_unwind; use js::rust::transform_str_to_source_text; -use js::rust::wrappers::{JS_ExecuteScript, JS_GetScriptPrivate}; +use js::rust::wrappers::{JS_ExecuteScript, JS_ExecuteScript1, JS_GetScriptPrivate}; use js::rust::{get_object_class, CompileOptionsWrapper, ParentRuntime, Runtime}; -use js::rust::{HandleValue, MutableHandleValue}; +use js::rust::{HandleScript, HandleValue, MutableHandleValue}; use js::{JSCLASS_IS_DOMJSCLASS, JSCLASS_IS_GLOBAL}; use msg::constellation_msg::{ BlobId, BroadcastChannelRouterId, MessagePortId, MessagePortRouterId, PipelineId, @@ -2552,8 +2552,9 @@ impl GlobalScope { fetch_options: ScriptFetchOptions, script_base_url: ServoUrl, ) -> bool { + let source_code = SourceCode::Text(Rc::new(DOMString::from_string((*code).to_string()))); self.evaluate_script_on_global_with_result( - code, + &source_code, "", rval, 1, @@ -2566,7 +2567,7 @@ impl GlobalScope { #[allow(unsafe_code)] pub fn evaluate_script_on_global_with_result( &self, - code: &str, + code: &SourceCode, filename: &str, rval: MutableHandleValue, line_number: u32, @@ -2595,48 +2596,58 @@ impl GlobalScope { let _aes = AutoEntryScript::new(self); unsafe { - let options = CompileOptionsWrapper::new(*cx, filename.as_ptr(), line_number); - - debug!("compiling Dom string"); - rooted!(in(*cx) let compiled_script = - Compile1( - *cx, - options.ptr, - &mut transform_str_to_source_text(code), - ) - ); + let result = match code { + SourceCode::Text(text_code) => { + let options = + CompileOptionsWrapper::new(*cx, filename.as_ptr(), line_number); + + debug!("compiling Dom string"); + rooted!(in(*cx) let compiled_script = + 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)); - return false; - } + if compiled_script.is_null() { + debug!("error compiling Dom string"); + report_pending_exception(*cx, true, InRealm::Entered(&ar)); + return false; + } - 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); - - 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 _), - ); - } + 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); + + 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 _), + ); + } - debug!("evaluating Dom string"); - let result = JS_ExecuteScript(*cx, compiled_script.handle(), rval); + debug!("evaluating Dom string"); + JS_ExecuteScript(*cx, compiled_script.handle(), rval) + }, + SourceCode::Compiled(compiled_script) => { + let script = compiled_script.source_code.get(); + let script_handle = HandleScript::new(&script); + JS_ExecuteScript1(*cx, script_handle) + }, + }; if !result { debug!("error evaluating Dom string"); |