Auto merge of #27365 - jdm:offthread-fixes, r=cybai

Fixes for off-thread compilation of scripts

Fixes #27355. Fixes #27349.
This commit is contained in:
bors-servo 2020-07-22 22:30:52 -04:00 committed by GitHub
commit 7b01d40a64
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 44 deletions

View file

@ -86,14 +86,14 @@ use js::jsapi::Compile1;
use js::jsapi::SetScriptPrivate;
use js::jsapi::{CurrentGlobalOrNull, GetNonCCWObjectGlobal};
use js::jsapi::{HandleObject, Heap};
use js::jsapi::{JSContext, JSObject};
use js::jsapi::{JSContext, JSObject, JSScript};
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_ExecuteScript1, JS_GetScriptPrivate};
use js::rust::wrappers::{JS_ExecuteScript, JS_GetScriptPrivate};
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 msg::constellation_msg::{
BlobId, BroadcastChannelRouterId, MessagePortId, MessagePortRouterId, PipelineId,
@ -2596,25 +2596,31 @@ impl GlobalScope {
let _aes = AutoEntryScript::new(self);
unsafe {
let result = match code {
rooted!(in(*cx) let mut compiled_script = std::ptr::null_mut::<JSScript>());
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(
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));
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());
JS_GetScriptPrivate(*compiled_script, script_private.handle_mut());
@ -2639,15 +2645,7 @@ impl GlobalScope {
);
}
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)
},
};
let result = JS_ExecuteScript(*cx, compiled_script.handle(), rval);
if !result {
debug!("error evaluating Dom string");

View file

@ -58,6 +58,7 @@ use servo_config::pref;
use servo_url::ImmutableOrigin;
use servo_url::ServoUrl;
use std::cell::Cell;
use std::ffi::CString;
use std::fs::{create_dir_all, read_to_string, File};
use std::io::{Read, Seek, Write};
use std::mem::replace;
@ -424,8 +425,8 @@ impl FetchResponseListener for ClassicContext {
let cx = global.get_cx();
let _ar = enter_realm(&*global);
let options =
unsafe { CompileOptionsWrapper::new(*cx, final_url.as_str().as_ptr() as *const i8, 1) };
let final_url_c_str = CString::new(final_url.as_str()).unwrap();
let options = unsafe { CompileOptionsWrapper::new(*cx, final_url_c_str.as_ptr(), 1) };
let can_compile_off_thread = pref!(dom.script.asynch) &&
unsafe { CanCompileOffThread(*cx, options.ptr as *const _, source_text.len()) };