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>
This commit is contained in:
AbhishekSharma102 2020-07-13 06:04:00 +00:00 committed by Josh Matthews
parent bfb7bea704
commit 1119dd119e
8 changed files with 310 additions and 85 deletions

View file

@ -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);
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(code),
)
);
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());
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 _),
);
}
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");