mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
script: Tell SpiderMonkey whether scripts are inline
Co-authored-by: atbrakhi <atbrakhi@igalia.com> Signed-off-by: Delan Azabani <dazabani@igalia.com>
This commit is contained in:
parent
048d0b0538
commit
615c9ec013
8 changed files with 41 additions and 8 deletions
|
@ -12,6 +12,7 @@ use devtools_traits::{
|
|||
NodeInfo, NodeStyle, RuleModification, TimelineMarker, TimelineMarkerType,
|
||||
};
|
||||
use ipc_channel::ipc::IpcSender;
|
||||
use js::glue::IntroductionType;
|
||||
use js::jsval::UndefinedValue;
|
||||
use js::rust::ToString;
|
||||
use servo_config::pref;
|
||||
|
@ -65,6 +66,7 @@ pub(crate) fn handle_evaluate_js(
|
|||
ScriptFetchOptions::default_classic_script(global),
|
||||
global.api_base_url(),
|
||||
can_gc,
|
||||
IntroductionType::Undefined,
|
||||
);
|
||||
|
||||
if rval.is_undefined() {
|
||||
|
|
|
@ -14,6 +14,7 @@ use std::rc::Rc;
|
|||
use deny_public_fields::DenyPublicFields;
|
||||
use dom_struct::dom_struct;
|
||||
use fnv::FnvHasher;
|
||||
use js::glue::IntroductionType;
|
||||
use js::jsapi::JS_GetFunctionObject;
|
||||
use js::jsval::JSVal;
|
||||
use js::rust::wrappers::CompileFunction;
|
||||
|
@ -642,7 +643,12 @@ impl EventTarget {
|
|||
|
||||
let cx = GlobalScope::get_cx();
|
||||
let options = unsafe {
|
||||
CompileOptionsWrapper::new(*cx, &handler.url.to_string(), handler.line as u32)
|
||||
CompileOptionsWrapper::new(
|
||||
*cx,
|
||||
&handler.url.to_string(),
|
||||
handler.line as u32,
|
||||
IntroductionType::Undefined,
|
||||
)
|
||||
};
|
||||
|
||||
// Step 3.9, subsection Scope steps 1-6
|
||||
|
|
|
@ -28,7 +28,7 @@ use dom_struct::dom_struct;
|
|||
use embedder_traits::EmbedderMsg;
|
||||
use ipc_channel::ipc::{self, IpcSender};
|
||||
use ipc_channel::router::ROUTER;
|
||||
use js::glue::{IsWrapper, UnwrapObjectDynamic};
|
||||
use js::glue::{IntroductionType, IsWrapper, UnwrapObjectDynamic};
|
||||
use js::jsapi::{
|
||||
Compile1, CurrentGlobalOrNull, GetNonCCWObjectGlobal, HandleObject, Heap,
|
||||
InstantiateGlobalStencil, InstantiateOptions, JSContext, JSObject, JSScript, SetScriptPrivate,
|
||||
|
@ -2768,6 +2768,7 @@ impl GlobalScope {
|
|||
fetch_options,
|
||||
script_base_url,
|
||||
can_gc,
|
||||
IntroductionType::Undefined,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -2783,6 +2784,7 @@ impl GlobalScope {
|
|||
fetch_options: ScriptFetchOptions,
|
||||
script_base_url: ServoUrl,
|
||||
can_gc: CanGc,
|
||||
introduction_type: IntroductionType,
|
||||
) -> bool {
|
||||
let cx = GlobalScope::get_cx();
|
||||
|
||||
|
@ -2794,7 +2796,8 @@ impl GlobalScope {
|
|||
rooted!(in(*cx) let mut compiled_script = std::ptr::null_mut::<JSScript>());
|
||||
match code {
|
||||
SourceCode::Text(text_code) => {
|
||||
let options = CompileOptionsWrapper::new(*cx, filename, line_number);
|
||||
let options =
|
||||
CompileOptionsWrapper::new(*cx, filename, line_number, introduction_type);
|
||||
|
||||
debug!("compiling dom string");
|
||||
compiled_script.set(Compile1(
|
||||
|
|
|
@ -18,6 +18,7 @@ use encoding_rs::Encoding;
|
|||
use html5ever::serialize::TraversalScope;
|
||||
use html5ever::{LocalName, Prefix, local_name, namespace_url, ns};
|
||||
use ipc_channel::ipc;
|
||||
use js::glue::IntroductionType;
|
||||
use js::jsval::UndefinedValue;
|
||||
use js::rust::{CompileOptionsWrapper, HandleObject, Stencil, transform_str_to_source_text};
|
||||
use net_traits::http_status::HttpStatus;
|
||||
|
@ -1111,6 +1112,11 @@ impl HTMLScriptElement {
|
|||
// Step 6.
|
||||
let document = self.owner_document();
|
||||
let old_script = document.GetCurrentScript();
|
||||
let introduction_type = if script.external {
|
||||
IntroductionType::Undefined
|
||||
} else {
|
||||
IntroductionType::InlineScript
|
||||
};
|
||||
|
||||
match script.type_ {
|
||||
ScriptType::Classic => {
|
||||
|
@ -1119,7 +1125,7 @@ impl HTMLScriptElement {
|
|||
} else {
|
||||
document.set_current_script(Some(self))
|
||||
}
|
||||
self.run_a_classic_script(&script, can_gc);
|
||||
self.run_a_classic_script(&script, can_gc, introduction_type);
|
||||
document.set_current_script(old_script.as_deref());
|
||||
},
|
||||
ScriptType::Module => {
|
||||
|
@ -1145,7 +1151,12 @@ impl HTMLScriptElement {
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#run-a-classic-script
|
||||
pub(crate) fn run_a_classic_script(&self, script: &ScriptOrigin, can_gc: CanGc) {
|
||||
pub(crate) fn run_a_classic_script(
|
||||
&self,
|
||||
script: &ScriptOrigin,
|
||||
can_gc: CanGc,
|
||||
introduction_type: IntroductionType,
|
||||
) {
|
||||
// TODO use a settings object rather than this element's document/window
|
||||
// Step 2
|
||||
let document = self.owner_document();
|
||||
|
@ -1171,6 +1182,7 @@ impl HTMLScriptElement {
|
|||
script.fetch_options.clone(),
|
||||
script.url.clone(),
|
||||
can_gc,
|
||||
introduction_type,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
use std::rc::Rc;
|
||||
|
||||
use js::glue::IntroductionType;
|
||||
use js::jsval::UndefinedValue;
|
||||
use script_bindings::root::DomRoot;
|
||||
|
||||
|
@ -39,6 +40,7 @@ pub(crate) fn load_script(head: &HTMLHeadElement) {
|
|||
ScriptFetchOptions::default_classic_script(global_scope),
|
||||
global_scope.api_base_url(),
|
||||
CanGc::note(),
|
||||
IntroductionType::Undefined,
|
||||
);
|
||||
}
|
||||
}));
|
||||
|
|
|
@ -17,6 +17,7 @@ use crossbeam_channel::Receiver;
|
|||
use devtools_traits::{DevtoolScriptControlMsg, WorkerId};
|
||||
use dom_struct::dom_struct;
|
||||
use ipc_channel::ipc::IpcSender;
|
||||
use js::glue::IntroductionType;
|
||||
use js::jsval::UndefinedValue;
|
||||
use js::panic::maybe_resume_unwind;
|
||||
use js::rust::{HandleValue, MutableHandleValue, ParentRuntime};
|
||||
|
@ -433,6 +434,7 @@ impl WorkerGlobalScopeMethods<crate::DomTypeHolder> for WorkerGlobalScope {
|
|||
url.as_str(),
|
||||
1,
|
||||
rval.handle_mut(),
|
||||
IntroductionType::Undefined,
|
||||
);
|
||||
|
||||
maybe_resume_unwind();
|
||||
|
@ -645,6 +647,7 @@ impl WorkerGlobalScope {
|
|||
self.worker_url.borrow().as_str(),
|
||||
1,
|
||||
rval.handle_mut(),
|
||||
IntroductionType::Undefined,
|
||||
) {
|
||||
Ok(_) => (),
|
||||
Err(_) => {
|
||||
|
|
|
@ -16,6 +16,7 @@ use headers::{HeaderMapExt, ReferrerPolicy as ReferrerPolicyHeader};
|
|||
use html5ever::local_name;
|
||||
use hyper_serde::Serde;
|
||||
use indexmap::{IndexMap, IndexSet};
|
||||
use js::glue::IntroductionType;
|
||||
use js::jsapi::{
|
||||
CompileModule1, ExceptionStackBehavior, FinishDynamicModuleImport, GetModuleRequestSpecifier,
|
||||
GetModuleResolveHook, GetRequestedModuleSpecifier, GetRequestedModulesCount,
|
||||
|
@ -468,11 +469,13 @@ impl ModuleTree {
|
|||
mut module_script: RustMutableHandleObject,
|
||||
inline: bool,
|
||||
can_gc: CanGc,
|
||||
introduction_type: IntroductionType,
|
||||
) -> Result<(), RethrowError> {
|
||||
let cx = GlobalScope::get_cx();
|
||||
let _ac = JSAutoRealm::new(*cx, *global.reflector().get_jsobject());
|
||||
|
||||
let compile_options = unsafe { CompileOptionsWrapper::new(*cx, url.as_str(), 1) };
|
||||
let compile_options =
|
||||
unsafe { CompileOptionsWrapper::new(*cx, url.as_str(), 1, introduction_type) };
|
||||
let mut module_source = ModuleSource {
|
||||
source: module_script_text,
|
||||
unminified_dir: global.unminified_js_dir(),
|
||||
|
@ -1332,6 +1335,7 @@ impl FetchResponseListener for ModuleContext {
|
|||
compiled_module.handle_mut(),
|
||||
false,
|
||||
CanGc::note(),
|
||||
IntroductionType::Undefined,
|
||||
);
|
||||
|
||||
match compiled_module_result {
|
||||
|
@ -1896,6 +1900,7 @@ pub(crate) fn fetch_inline_module_script(
|
|||
compiled_module.handle_mut(),
|
||||
true,
|
||||
can_gc,
|
||||
IntroductionType::InlineScript,
|
||||
);
|
||||
|
||||
match compiled_module_result {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue