Ensure scripts compiled off-thread can import modules.

This commit is contained in:
Josh Matthews 2020-07-22 12:29:19 -04:00
parent a271ed9150
commit e3f0989e1c

View file

@ -86,14 +86,14 @@ use js::jsapi::Compile1;
use js::jsapi::SetScriptPrivate; use js::jsapi::SetScriptPrivate;
use js::jsapi::{CurrentGlobalOrNull, GetNonCCWObjectGlobal}; use js::jsapi::{CurrentGlobalOrNull, GetNonCCWObjectGlobal};
use js::jsapi::{HandleObject, Heap}; use js::jsapi::{HandleObject, Heap};
use js::jsapi::{JSContext, JSObject}; use js::jsapi::{JSContext, JSObject, JSScript};
use js::jsval::PrivateValue; use js::jsval::PrivateValue;
use js::jsval::{JSVal, UndefinedValue}; use js::jsval::{JSVal, UndefinedValue};
use js::panic::maybe_resume_unwind; use js::panic::maybe_resume_unwind;
use js::rust::transform_str_to_source_text; use js::rust::transform_str_to_source_text;
use js::rust::wrappers::{JS_ExecuteScript, JS_ExecuteScript1, JS_GetScriptPrivate}; use js::rust::wrappers::{JS_ExecuteScript, JS_GetScriptPrivate};
use js::rust::{get_object_class, CompileOptionsWrapper, ParentRuntime, Runtime}; use js::rust::{get_object_class, CompileOptionsWrapper, ParentRuntime, Runtime};
use js::rust::{HandleScript, HandleValue, MutableHandleValue}; use js::rust::{HandleValue, MutableHandleValue};
use js::{JSCLASS_IS_DOMJSCLASS, JSCLASS_IS_GLOBAL}; use js::{JSCLASS_IS_DOMJSCLASS, JSCLASS_IS_GLOBAL};
use msg::constellation_msg::{ use msg::constellation_msg::{
BlobId, BroadcastChannelRouterId, MessagePortId, MessagePortRouterId, PipelineId, BlobId, BroadcastChannelRouterId, MessagePortId, MessagePortRouterId, PipelineId,
@ -2596,25 +2596,31 @@ impl GlobalScope {
let _aes = AutoEntryScript::new(self); let _aes = AutoEntryScript::new(self);
unsafe { unsafe {
let result = match code { rooted!(in(*cx) let mut compiled_script = std::ptr::null_mut::<JSScript>());
match code {
SourceCode::Text(text_code) => { SourceCode::Text(text_code) => {
let options = let options =
CompileOptionsWrapper::new(*cx, filename.as_ptr(), line_number); CompileOptionsWrapper::new(*cx, filename.as_ptr(), line_number);
debug!("compiling Dom string"); debug!("compiling dom string");
rooted!(in(*cx) let compiled_script = compiled_script.set(Compile1(
Compile1(
*cx, *cx,
options.ptr, options.ptr,
&mut transform_str_to_source_text(text_code), &mut transform_str_to_source_text(text_code),
) ));
);
if compiled_script.is_null() { if compiled_script.is_null() {
debug!("error compiling Dom string"); debug!("error compiling Dom string");
report_pending_exception(*cx, true, InRealm::Entered(&ar)); report_pending_exception(*cx, true, InRealm::Entered(&ar));
return false; return false;
} }
},
SourceCode::Compiled(pre_compiled_script) => {
compiled_script.set(pre_compiled_script.source_code.get());
},
};
assert!(!compiled_script.is_null());
rooted!(in(*cx) let mut script_private = UndefinedValue()); rooted!(in(*cx) let mut script_private = UndefinedValue());
JS_GetScriptPrivate(*compiled_script, script_private.handle_mut()); JS_GetScriptPrivate(*compiled_script, script_private.handle_mut());
@ -2639,15 +2645,7 @@ impl GlobalScope {
); );
} }
debug!("evaluating Dom string"); let result = JS_ExecuteScript(*cx, compiled_script.handle(), rval);
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 { if !result {
debug!("error evaluating Dom string"); debug!("error evaluating Dom string");