Set private reference for classic script

Web developers can use `Dynamic Import` in a classic script; thus, we
need to save the script's private reference so that we can reuse it when
we're going to fetch a dynamic import module for a classic script.

Besides, because it's possible to use different executing context for a
dynamic import module (like `dynamic-import/string-compilation-other-document.html` WPT test),
we can't initialize a module owner at the timing of `SetScriptPrivate`;
thus, if the private module script doesn't hold an owner, we'll use a
DynamicImport owner for it.
This commit is contained in:
CYBAI 2020-07-11 22:44:21 +09:00
parent 99e832a345
commit d1715918f0
10 changed files with 204 additions and 71 deletions

View file

@ -16,6 +16,7 @@ use crate::dom::element::Element;
use crate::dom::globalscope::GlobalScope; use crate::dom::globalscope::GlobalScope;
use crate::dom::node::{window_from_node, Node, ShadowIncluding}; use crate::dom::node::{window_from_node, Node, ShadowIncluding};
use crate::realms::enter_realm; use crate::realms::enter_realm;
use crate::script_module::ScriptFetchOptions;
use crate::script_thread::Documents; use crate::script_thread::Documents;
use devtools_traits::{AutoMargins, ComputedNodeLayout, TimelineMarkerType}; use devtools_traits::{AutoMargins, ComputedNodeLayout, TimelineMarkerType};
use devtools_traits::{EvaluateJSReply, Modification, NodeInfo, TimelineMarker}; use devtools_traits::{EvaluateJSReply, Modification, NodeInfo, TimelineMarker};
@ -34,7 +35,14 @@ pub fn handle_evaluate_js(global: &GlobalScope, eval: String, reply: IpcSender<E
let cx = global.get_cx(); let cx = global.get_cx();
let _ac = enter_realm(global); let _ac = enter_realm(global);
rooted!(in(*cx) let mut rval = UndefinedValue()); rooted!(in(*cx) let mut rval = UndefinedValue());
global.evaluate_script_on_global_with_result(&eval, "<eval>", rval.handle_mut(), 1); global.evaluate_script_on_global_with_result(
&eval,
"<eval>",
rval.handle_mut(),
1,
ScriptFetchOptions::default_classic_script(&global),
global.api_base_url(),
);
if rval.is_undefined() { if rval.is_undefined() {
EvaluateJSReply::VoidValue EvaluateJSReply::VoidValue

View file

@ -95,7 +95,7 @@ use msg::constellation_msg::{ServiceWorkerId, ServiceWorkerRegistrationId};
use net_traits::filemanager_thread::RelativePos; use net_traits::filemanager_thread::RelativePos;
use net_traits::image::base::{Image, ImageMetadata}; use net_traits::image::base::{Image, ImageMetadata};
use net_traits::image_cache::{ImageCache, PendingImageId}; use net_traits::image_cache::{ImageCache, PendingImageId};
use net_traits::request::{Referrer, Request, RequestBuilder}; use net_traits::request::{CredentialsMode, ParserMetadata, Referrer, Request, RequestBuilder};
use net_traits::response::HttpsState; use net_traits::response::HttpsState;
use net_traits::response::{Response, ResponseBody}; use net_traits::response::{Response, ResponseBody};
use net_traits::storage_thread::StorageType; use net_traits::storage_thread::StorageType;
@ -556,6 +556,8 @@ unsafe_no_jsmanaged_fields!(StyleSharedRwLock);
unsafe_no_jsmanaged_fields!(USVString); unsafe_no_jsmanaged_fields!(USVString);
unsafe_no_jsmanaged_fields!(Referrer); unsafe_no_jsmanaged_fields!(Referrer);
unsafe_no_jsmanaged_fields!(ReferrerPolicy); unsafe_no_jsmanaged_fields!(ReferrerPolicy);
unsafe_no_jsmanaged_fields!(CredentialsMode);
unsafe_no_jsmanaged_fields!(ParserMetadata);
unsafe_no_jsmanaged_fields!(Response); unsafe_no_jsmanaged_fields!(Response);
unsafe_no_jsmanaged_fields!(ResponseBody); unsafe_no_jsmanaged_fields!(ResponseBody);
unsafe_no_jsmanaged_fields!(ResourceThreads); unsafe_no_jsmanaged_fields!(ResourceThreads);

View file

@ -52,6 +52,7 @@ use crate::dom::workletglobalscope::WorkletGlobalScope;
use crate::microtask::{Microtask, MicrotaskQueue, UserMicrotask}; use crate::microtask::{Microtask, MicrotaskQueue, UserMicrotask};
use crate::realms::{enter_realm, AlreadyInRealm, InRealm}; use crate::realms::{enter_realm, AlreadyInRealm, InRealm};
use crate::script_module::{DynamicModuleList, ModuleTree}; use crate::script_module::{DynamicModuleList, ModuleTree};
use crate::script_module::{ModuleScript, ScriptFetchOptions};
use crate::script_runtime::{ use crate::script_runtime::{
CommonScriptMsg, ContextForRequestInterrupt, JSContext as SafeJSContext, ScriptChan, ScriptPort, CommonScriptMsg, ContextForRequestInterrupt, JSContext as SafeJSContext, ScriptChan, ScriptPort,
}; };
@ -79,8 +80,10 @@ use ipc_channel::router::ROUTER;
use js::glue::{IsWrapper, UnwrapObjectDynamic}; use js::glue::{IsWrapper, UnwrapObjectDynamic};
use js::jsapi::Compile1; use js::jsapi::Compile1;
use js::jsapi::{CurrentGlobalOrNull, GetNonCCWObjectGlobal}; use js::jsapi::{CurrentGlobalOrNull, GetNonCCWObjectGlobal};
use js::jsapi::{GetScriptPrivate, SetScriptPrivate};
use js::jsapi::{HandleObject, Heap}; use js::jsapi::{HandleObject, Heap};
use js::jsapi::{JSContext, JSObject}; use js::jsapi::{JSContext, JSObject};
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;
@ -2533,8 +2536,21 @@ impl GlobalScope {
} }
/// Evaluate JS code on this global scope. /// Evaluate JS code on this global scope.
pub fn evaluate_js_on_global_with_result(&self, code: &str, rval: MutableHandleValue) -> bool { pub fn evaluate_js_on_global_with_result(
self.evaluate_script_on_global_with_result(code, "", rval, 1) &self,
code: &str,
rval: MutableHandleValue,
fetch_options: ScriptFetchOptions,
script_base_url: ServoUrl,
) -> bool {
self.evaluate_script_on_global_with_result(
code,
"",
rval,
1,
fetch_options,
script_base_url,
)
} }
/// Evaluate a JS script on this global scope. /// Evaluate a JS script on this global scope.
@ -2545,6 +2561,8 @@ impl GlobalScope {
filename: &str, filename: &str,
rval: MutableHandleValue, rval: MutableHandleValue,
line_number: u32, line_number: u32,
fetch_options: ScriptFetchOptions,
script_base_url: ServoUrl,
) -> bool { ) -> bool {
let metadata = profile_time::TimerMetadata { let metadata = profile_time::TimerMetadata {
url: if filename.is_empty() { url: if filename.is_empty() {
@ -2566,33 +2584,56 @@ impl GlobalScope {
let ar = enter_realm(&*self); let ar = enter_realm(&*self);
let _aes = AutoEntryScript::new(self); let _aes = AutoEntryScript::new(self);
let options =
unsafe { CompileOptionsWrapper::new(*cx, filename.as_ptr(), line_number) };
rooted!(in(*cx) let compiled_script = unsafe { unsafe {
Compile1( let options = CompileOptionsWrapper::new(*cx, filename.as_ptr(), line_number);
*cx,
options.ptr,
&mut transform_str_to_source_text(code),
)
});
if compiled_script.is_null() { debug!("compiling Dom string");
debug!("error compiling Dom string"); rooted!(in(*cx) let compiled_script =
report_pending_exception(*cx, true, InRealm::Entered(&ar)); Compile1(
return false; *cx,
options.ptr,
&mut transform_str_to_source_text(code),
)
);
if compiled_script.is_null() {
debug!("error compiling Dom string");
report_pending_exception(*cx, true, InRealm::Entered(&ar));
return false;
}
// When `ScriptPrivate` for the compiled script is undefined,
// we need to set it so that it can be used in dynamic import context.
if GetScriptPrivate(*compiled_script).is_undefined() {
debug!("Set script private for {}", script_base_url);
let module_script_data = Box::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(Box::into_raw(module_script_data) as *const _),
);
}
debug!("evaluating Dom string");
let result = JS_ExecuteScript(*cx, compiled_script.handle(), rval);
if !result {
debug!("error evaluating Dom string");
report_pending_exception(*cx, true, InRealm::Entered(&ar));
}
maybe_resume_unwind();
result
} }
debug!("evaluating Dom string");
let result = unsafe { JS_ExecuteScript(*cx, compiled_script.handle(), rval) };
if !result {
debug!("error evaluating Dom string");
unsafe { report_pending_exception(*cx, true, InRealm::Entered(&ar)) };
}
maybe_resume_unwind();
result
}, },
) )
} }

View file

@ -156,24 +156,37 @@ pub struct ScriptOrigin {
text: Rc<DOMString>, text: Rc<DOMString>,
url: ServoUrl, url: ServoUrl,
external: bool, external: bool,
fetch_options: ScriptFetchOptions,
type_: ScriptType, type_: ScriptType,
} }
impl ScriptOrigin { impl ScriptOrigin {
pub fn internal(text: Rc<DOMString>, url: ServoUrl, type_: ScriptType) -> ScriptOrigin { pub fn internal(
text: Rc<DOMString>,
url: ServoUrl,
fetch_options: ScriptFetchOptions,
type_: ScriptType,
) -> ScriptOrigin {
ScriptOrigin { ScriptOrigin {
text: text, text: text,
url: url, url: url,
external: false, external: false,
fetch_options,
type_, type_,
} }
} }
pub fn external(text: Rc<DOMString>, url: ServoUrl, type_: ScriptType) -> ScriptOrigin { pub fn external(
text: Rc<DOMString>,
url: ServoUrl,
fetch_options: ScriptFetchOptions,
type_: ScriptType,
) -> ScriptOrigin {
ScriptOrigin { ScriptOrigin {
text: text, text: text,
url: url, url: url,
external: true, external: true,
fetch_options,
type_, type_,
} }
} }
@ -202,6 +215,8 @@ struct ClassicContext {
url: ServoUrl, url: ServoUrl,
/// Indicates whether the request failed, and why /// Indicates whether the request failed, and why
status: Result<(), NetworkError>, status: Result<(), NetworkError>,
/// The fetch options of the script
fetch_options: ScriptFetchOptions,
/// Timing object for this resource /// Timing object for this resource
resource_timing: ResourceFetchTiming, resource_timing: ResourceFetchTiming,
} }
@ -262,6 +277,7 @@ impl FetchResponseListener for ClassicContext {
ScriptOrigin::external( ScriptOrigin::external(
Rc::new(DOMString::from(source_text)), Rc::new(DOMString::from(source_text)),
metadata.final_url, metadata.final_url,
self.fetch_options.clone(),
ScriptType::Classic, ScriptType::Classic,
) )
}); });
@ -358,7 +374,7 @@ fn fetch_a_classic_script(
cors_setting, cors_setting,
doc.origin().immutable().clone(), doc.origin().immutable().clone(),
script.global().pipeline_id(), script.global().pipeline_id(),
options, options.clone(),
); );
// TODO: Step 3, Add custom steps to perform fetch // TODO: Step 3, Add custom steps to perform fetch
@ -371,6 +387,7 @@ fn fetch_a_classic_script(
metadata: None, metadata: None,
url: url.clone(), url: url.clone(),
status: Ok(()), status: Ok(()),
fetch_options: options,
resource_timing: ResourceFetchTiming::new(ResourceTimingType::Resource), resource_timing: ResourceFetchTiming::new(ResourceTimingType::Resource),
})); }));
@ -630,6 +647,7 @@ impl HTMLScriptElement {
let result = Ok(ScriptOrigin::internal( let result = Ok(ScriptOrigin::internal(
Rc::clone(&text_rc), Rc::clone(&text_rc),
base_url.clone(), base_url.clone(),
options.clone(),
script_type.clone(), script_type.clone(),
)); ));
@ -866,6 +884,8 @@ impl HTMLScriptElement {
script.url.as_str(), script.url.as_str(),
rval.handle_mut(), rval.handle_mut(),
line_number, line_number,
script.fetch_options.clone(),
script.url.clone(),
); );
} }

View file

@ -7,6 +7,7 @@ use crate::dom::bindings::refcounted::Trusted;
use crate::dom::globalscope::GlobalScope; use crate::dom::globalscope::GlobalScope;
use crate::dom::htmlheadelement::HTMLHeadElement; use crate::dom::htmlheadelement::HTMLHeadElement;
use crate::dom::node::document_from_node; use crate::dom::node::document_from_node;
use crate::script_module::ScriptFetchOptions;
use js::jsval::UndefinedValue; use js::jsval::UndefinedValue;
use std::fs::{read_dir, File}; use std::fs::{read_dir, File};
use std::io::Read; use std::io::Read;
@ -38,13 +39,15 @@ pub fn load_script(head: &HTMLHeadElement) {
let mut contents = vec![]; let mut contents = vec![];
f.read_to_end(&mut contents).unwrap(); f.read_to_end(&mut contents).unwrap();
let script_text = String::from_utf8_lossy(&contents); let script_text = String::from_utf8_lossy(&contents);
win.upcast::<GlobalScope>() let global = win.upcast::<GlobalScope>();
.evaluate_script_on_global_with_result( global.evaluate_script_on_global_with_result(
&script_text, &script_text,
&file.to_string_lossy(), &file.to_string_lossy(),
rval.handle_mut(), rval.handle_mut(),
1, 1,
); ScriptFetchOptions::default_classic_script(&global),
global.api_base_url(),
);
} }
})); }));
} }

View file

@ -11,6 +11,7 @@ use crate::dom::paintworkletglobalscope::PaintWorkletTask;
use crate::dom::testworkletglobalscope::TestWorkletGlobalScope; use crate::dom::testworkletglobalscope::TestWorkletGlobalScope;
use crate::dom::testworkletglobalscope::TestWorkletTask; use crate::dom::testworkletglobalscope::TestWorkletTask;
use crate::dom::worklet::WorkletExecutor; use crate::dom::worklet::WorkletExecutor;
use crate::script_module::ScriptFetchOptions;
use crate::script_runtime::JSContext; use crate::script_runtime::JSContext;
use crate::script_thread::MainThreadScriptMsg; use crate::script_thread::MainThreadScriptMsg;
use crossbeam_channel::Sender; use crossbeam_channel::Sender;
@ -88,10 +89,14 @@ impl WorkletGlobalScope {
/// Evaluate a JS script in this global. /// Evaluate a JS script in this global.
pub fn evaluate_js(&self, script: &str) -> bool { pub fn evaluate_js(&self, script: &str) -> bool {
debug!("Evaluating Dom."); debug!("Evaluating Dom in a worklet.");
rooted!(in (*self.globalscope.get_cx()) let mut rval = UndefinedValue()); rooted!(in (*self.globalscope.get_cx()) let mut rval = UndefinedValue());
self.globalscope self.globalscope.evaluate_js_on_global_with_result(
.evaluate_js_on_global_with_result(&*script, rval.handle_mut()) &*script,
rval.handle_mut(),
ScriptFetchOptions::default_classic_script(&self.globalscope),
self.globalscope.api_base_url(),
)
} }
/// Register a paint worklet to the script thread. /// Register a paint worklet to the script thread.

View file

@ -111,10 +111,24 @@ impl Clone for RethrowError {
} }
} }
struct ModuleScript { pub(crate) struct ModuleScript {
base_url: ServoUrl, base_url: ServoUrl,
options: ScriptFetchOptions, options: ScriptFetchOptions,
owner: ModuleOwner, owner: Option<ModuleOwner>,
}
impl ModuleScript {
pub fn new(
base_url: ServoUrl,
options: ScriptFetchOptions,
owner: Option<ModuleOwner>,
) -> Self {
ModuleScript {
base_url,
options,
owner,
}
}
} }
/// Identity for a module which will be /// Identity for a module which will be
@ -312,15 +326,21 @@ impl ModuleTree {
// We just leverage the power of Promise to run the task for `finish` the owner. // We just leverage the power of Promise to run the task for `finish` the owner.
// Thus, we will always `resolve` it and no need to register a callback for `reject` // Thus, we will always `resolve` it and no need to register a callback for `reject`
fn append_handler(&self, owner: ModuleOwner, module_identity: ModuleIdentity) { fn append_handler(
&self,
owner: ModuleOwner,
module_identity: ModuleIdentity,
fetch_options: ScriptFetchOptions,
) {
let this = owner.clone(); let this = owner.clone();
let identity = module_identity.clone(); let identity = module_identity.clone();
let options = fetch_options.clone();
let handler = PromiseNativeHandler::new( let handler = PromiseNativeHandler::new(
&owner.global(), &owner.global(),
Some(ModuleHandler::new(Box::new( Some(ModuleHandler::new(Box::new(
task!(fetched_resolve: move || { task!(fetched_resolve: move || {
this.notify_owner_to_finish(identity.clone()); this.notify_owner_to_finish(identity, options);
}), }),
))), ))),
None, None,
@ -429,11 +449,7 @@ impl ModuleTree {
)))); ))));
} }
let module_script_data = Box::new(ModuleScript { let module_script_data = Box::new(ModuleScript::new(url.clone(), options, Some(owner)));
base_url: url.clone(),
options,
owner,
});
SetModulePrivate( SetModulePrivate(
module_script.get(), module_script.get(),
@ -885,7 +901,11 @@ impl ModuleOwner {
} }
} }
pub fn notify_owner_to_finish(&self, module_identity: ModuleIdentity) { pub fn notify_owner_to_finish(
&self,
module_identity: ModuleIdentity,
fetch_options: ScriptFetchOptions,
) {
match &self { match &self {
ModuleOwner::Worker(_) => unimplemented!(), ModuleOwner::Worker(_) => unimplemented!(),
ModuleOwner::DynamicModule(_) => unimplemented!(), ModuleOwner::DynamicModule(_) => unimplemented!(),
@ -904,11 +924,13 @@ impl ModuleOwner {
ModuleIdentity::ModuleUrl(script_src) => Ok(ScriptOrigin::external( ModuleIdentity::ModuleUrl(script_src) => Ok(ScriptOrigin::external(
Rc::clone(&module_tree.get_text().borrow()), Rc::clone(&module_tree.get_text().borrow()),
script_src.clone(), script_src.clone(),
fetch_options,
ScriptType::Module, ScriptType::Module,
)), )),
ModuleIdentity::ScriptId(_) => Ok(ScriptOrigin::internal( ModuleIdentity::ScriptId(_) => Ok(ScriptOrigin::internal(
Rc::clone(&module_tree.get_text().borrow()), Rc::clone(&module_tree.get_text().borrow()),
document.base_url().clone(), document.base_url().clone(),
fetch_options,
ScriptType::Module, ScriptType::Module,
)), )),
}, },
@ -1106,6 +1128,7 @@ impl FetchResponseListener for ModuleContext {
Ok(ScriptOrigin::external( Ok(ScriptOrigin::external(
Rc::new(DOMString::from(source_text)), Rc::new(DOMString::from(source_text)),
meta.final_url, meta.final_url,
self.options.clone(),
ScriptType::Module, ScriptType::Module,
)) ))
}); });
@ -1239,9 +1262,9 @@ pub unsafe extern "C" fn host_import_module_dynamically(
true true
} }
#[derive(Clone)] #[derive(Clone, JSTraceable, MallocSizeOf)]
/// <https://html.spec.whatwg.org/multipage/#script-fetch-options> /// <https://html.spec.whatwg.org/multipage/#script-fetch-options>
pub(crate) struct ScriptFetchOptions { pub struct ScriptFetchOptions {
pub referrer: Referrer, pub referrer: Referrer,
pub integrity_metadata: String, pub integrity_metadata: String,
pub credentials_mode: CredentialsMode, pub credentials_mode: CredentialsMode,
@ -1252,7 +1275,7 @@ pub(crate) struct ScriptFetchOptions {
impl ScriptFetchOptions { impl ScriptFetchOptions {
/// <https://html.spec.whatwg.org/multipage/#default-classic-script-fetch-options> /// <https://html.spec.whatwg.org/multipage/#default-classic-script-fetch-options>
fn default_classic_script(global: &GlobalScope) -> ScriptFetchOptions { pub fn default_classic_script(global: &GlobalScope) -> ScriptFetchOptions {
Self { Self {
cryptographic_nonce: String::new(), cryptographic_nonce: String::new(),
integrity_metadata: String::new(), integrity_metadata: String::new(),
@ -1310,8 +1333,8 @@ fn fetch_an_import_module_script_graph(
// Step 3. // Step 3.
let owner = match unsafe { module_script_from_reference_private(&reference_private) } { let owner = match unsafe { module_script_from_reference_private(&reference_private) } {
Some(module_data) => module_data.owner.clone(), Some(module_data) if module_data.owner.is_some() => module_data.owner.clone().unwrap(),
None => ModuleOwner::DynamicModule(Trusted::new(&DynamicModuleOwner::new( _ => ModuleOwner::DynamicModule(Trusted::new(&DynamicModuleOwner::new(
global, global,
promise.clone(), promise.clone(),
dynamic_module_id.clone(), dynamic_module_id.clone(),
@ -1529,8 +1552,11 @@ fn fetch_single_module_script(
ModuleIdentity::ModuleUrl(url.clone()), ModuleIdentity::ModuleUrl(url.clone()),
module, module,
), ),
None if top_level_module_fetch => module_tree None if top_level_module_fetch => module_tree.append_handler(
.append_handler(owner.clone(), ModuleIdentity::ModuleUrl(url.clone())), owner.clone(),
ModuleIdentity::ModuleUrl(url.clone()),
options,
),
// do nothing if it's neither a dynamic module nor a top level module // do nothing if it's neither a dynamic module nor a top level module
None => {}, None => {},
} }
@ -1566,9 +1592,11 @@ fn fetch_single_module_script(
ModuleIdentity::ModuleUrl(url.clone()), ModuleIdentity::ModuleUrl(url.clone()),
module, module,
), ),
None if top_level_module_fetch => { None if top_level_module_fetch => module_tree.append_handler(
module_tree.append_handler(owner.clone(), ModuleIdentity::ModuleUrl(url.clone())) owner.clone(),
}, ModuleIdentity::ModuleUrl(url.clone()),
options.clone(),
),
// do nothing if it's neither a dynamic module nor a top level module // do nothing if it's neither a dynamic module nor a top level module
None => {}, None => {},
} }
@ -1670,7 +1698,11 @@ pub(crate) fn fetch_inline_module_script(
match compiled_module { match compiled_module {
Ok(record) => { Ok(record) => {
module_tree.append_handler(owner.clone(), ModuleIdentity::ScriptId(script_id.clone())); module_tree.append_handler(
owner.clone(),
ModuleIdentity::ScriptId(script_id.clone()),
options.clone(),
);
module_tree.set_record(record); module_tree.set_record(record);
// We need to set `module_tree` into inline module map in case // We need to set `module_tree` into inline module map in case
@ -1695,7 +1727,7 @@ pub(crate) fn fetch_inline_module_script(
module_tree.set_rethrow_error(exception); module_tree.set_rethrow_error(exception);
module_tree.set_status(ModuleStatus::Finished); module_tree.set_status(ModuleStatus::Finished);
global.set_inline_module_map(script_id.clone(), module_tree); global.set_inline_module_map(script_id.clone(), module_tree);
owner.notify_owner_to_finish(ModuleIdentity::ScriptId(script_id)); owner.notify_owner_to_finish(ModuleIdentity::ScriptId(script_id), options);
}, },
} }
} }

View file

@ -63,6 +63,7 @@ use crate::dom::workletglobalscope::WorkletGlobalScopeInit;
use crate::fetch::FetchCanceller; use crate::fetch::FetchCanceller;
use crate::microtask::{Microtask, MicrotaskQueue}; use crate::microtask::{Microtask, MicrotaskQueue};
use crate::realms::enter_realm; use crate::realms::enter_realm;
use crate::script_module::ScriptFetchOptions;
use crate::script_runtime::{ use crate::script_runtime::{
get_reports, new_rt_and_cx, ContextForRequestInterrupt, JSContext, Runtime, ScriptPort, get_reports, new_rt_and_cx, ContextForRequestInterrupt, JSContext, Runtime, ScriptPort,
}; };
@ -3702,7 +3703,12 @@ impl ScriptThread {
// Script source is ready to be evaluated (11.) // Script source is ready to be evaluated (11.)
let _ac = enter_realm(global_scope); let _ac = enter_realm(global_scope);
rooted!(in(*global_scope.get_cx()) let mut jsval = UndefinedValue()); rooted!(in(*global_scope.get_cx()) let mut jsval = UndefinedValue());
global_scope.evaluate_js_on_global_with_result(&script_source, jsval.handle_mut()); global_scope.evaluate_js_on_global_with_result(
&script_source,
jsval.handle_mut(),
ScriptFetchOptions::default_classic_script(&global_scope),
global_scope.api_base_url(),
);
load_data.js_eval_result = if jsval.get().is_string() { load_data.js_eval_result = if jsval.get().is_string() {
unsafe { unsafe {

View file

@ -12,6 +12,7 @@ use crate::dom::eventsource::EventSourceTimeoutCallback;
use crate::dom::globalscope::GlobalScope; use crate::dom::globalscope::GlobalScope;
use crate::dom::testbinding::TestBindingCallback; use crate::dom::testbinding::TestBindingCallback;
use crate::dom::xmlhttprequest::XHRTimeoutCallback; use crate::dom::xmlhttprequest::XHRTimeoutCallback;
use crate::script_module::ScriptFetchOptions;
use crate::script_thread::ScriptThread; use crate::script_thread::ScriptThread;
use euclid::Length; use euclid::Length;
use ipc_channel::ipc::IpcSender; use ipc_channel::ipc::IpcSender;
@ -541,7 +542,13 @@ impl JsTimerTask {
let global = this.global(); let global = this.global();
let cx = global.get_cx(); let cx = global.get_cx();
rooted!(in(*cx) let mut rval = UndefinedValue()); rooted!(in(*cx) let mut rval = UndefinedValue());
global.evaluate_js_on_global_with_result(code_str, rval.handle_mut()); // FIXME(cybai): Use base url properly by saving private reference for timers (#27260)
global.evaluate_js_on_global_with_result(
code_str,
rval.handle_mut(),
ScriptFetchOptions::default_classic_script(&global),
global.api_base_url(),
);
}, },
InternalTimerCallback::FunctionTimerCallback(ref function, ref arguments) => { InternalTimerCallback::FunctionTimerCallback(ref function, ref arguments) => {
let arguments = self.collect_heap_args(arguments); let arguments = self.collect_heap_args(arguments);

View file

@ -38,6 +38,7 @@ use crate::dom::nodelist::NodeList;
use crate::dom::window::Window; use crate::dom::window::Window;
use crate::dom::xmlserializer::XMLSerializer; use crate::dom::xmlserializer::XMLSerializer;
use crate::realms::enter_realm; use crate::realms::enter_realm;
use crate::script_module::ScriptFetchOptions;
use crate::script_runtime::JSContext as SafeJSContext; use crate::script_runtime::JSContext as SafeJSContext;
use crate::script_thread::{Documents, ScriptThread}; use crate::script_thread::{Documents, ScriptThread};
use cookie::Cookie; use cookie::Cookie;
@ -297,9 +298,13 @@ pub fn handle_execute_script(
let result = unsafe { let result = unsafe {
let cx = window.get_cx(); let cx = window.get_cx();
rooted!(in(*cx) let mut rval = UndefinedValue()); rooted!(in(*cx) let mut rval = UndefinedValue());
window let global = window.upcast::<GlobalScope>();
.upcast::<GlobalScope>() global.evaluate_js_on_global_with_result(
.evaluate_js_on_global_with_result(&eval, rval.handle_mut()); &eval,
rval.handle_mut(),
ScriptFetchOptions::default_classic_script(&global),
global.api_base_url(),
);
jsval_to_webdriver(*cx, &window.upcast::<GlobalScope>(), rval.handle()) jsval_to_webdriver(*cx, &window.upcast::<GlobalScope>(), rval.handle())
}; };
@ -323,9 +328,13 @@ pub fn handle_execute_async_script(
let cx = window.get_cx(); let cx = window.get_cx();
window.set_webdriver_script_chan(Some(reply)); window.set_webdriver_script_chan(Some(reply));
rooted!(in(*cx) let mut rval = UndefinedValue()); rooted!(in(*cx) let mut rval = UndefinedValue());
window let global = window.upcast::<GlobalScope>();
.upcast::<GlobalScope>() global.evaluate_js_on_global_with_result(
.evaluate_js_on_global_with_result(&eval, rval.handle_mut()); &eval,
rval.handle_mut(),
ScriptFetchOptions::default_classic_script(&global),
global.api_base_url(),
);
}, },
None => { None => {
reply reply