mirror of
https://github.com/servo/servo.git
synced 2025-08-07 22:45:34 +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
92a9d24a13
commit
a8574fcbd5
7 changed files with 43 additions and 10 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -5240,7 +5240,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "mozjs"
|
||||
version = "0.14.1"
|
||||
source = "git+https://github.com/servo/mozjs#903a158b36c10902a40c7fda766406d698f98bf4"
|
||||
source = "git+https://github.com/servo/mozjs#b6d7bce2bc165fb555ce3f254404aecc89627388"
|
||||
dependencies = [
|
||||
"bindgen 0.71.1",
|
||||
"cc",
|
||||
|
@ -5252,7 +5252,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "mozjs_sys"
|
||||
version = "0.128.13-3"
|
||||
source = "git+https://github.com/servo/mozjs#903a158b36c10902a40c7fda766406d698f98bf4"
|
||||
source = "git+https://github.com/servo/mozjs#b6d7bce2bc165fb555ce3f254404aecc89627388"
|
||||
dependencies = [
|
||||
"bindgen 0.71.1",
|
||||
"cc",
|
||||
|
|
|
@ -65,6 +65,7 @@ pub(crate) fn handle_evaluate_js(
|
|||
ScriptFetchOptions::default_classic_script(global),
|
||||
global.api_base_url(),
|
||||
can_gc,
|
||||
None,
|
||||
);
|
||||
|
||||
if rval.is_undefined() {
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
use std::cell::{Cell, OnceCell, Ref};
|
||||
use std::collections::hash_map::Entry;
|
||||
use std::collections::{HashMap, HashSet, VecDeque};
|
||||
use std::ffi::CStr;
|
||||
use std::ops::Index;
|
||||
use std::rc::Rc;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
|
@ -2768,6 +2769,7 @@ impl GlobalScope {
|
|||
fetch_options,
|
||||
script_base_url,
|
||||
can_gc,
|
||||
None,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -2783,6 +2785,7 @@ impl GlobalScope {
|
|||
fetch_options: ScriptFetchOptions,
|
||||
script_base_url: ServoUrl,
|
||||
can_gc: CanGc,
|
||||
introduction_type: Option<&'static CStr>,
|
||||
) -> bool {
|
||||
let cx = GlobalScope::get_cx();
|
||||
|
||||
|
@ -2794,7 +2797,10 @@ 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 mut options = CompileOptionsWrapper::new(*cx, filename, line_number);
|
||||
if let Some(introduction_type) = introduction_type {
|
||||
options.set_introduction_type(introduction_type);
|
||||
}
|
||||
|
||||
debug!("compiling dom string");
|
||||
compiled_script.set(Compile1(
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#![allow(unused_imports)]
|
||||
use core::ffi::c_void;
|
||||
use std::cell::Cell;
|
||||
use std::ffi::CStr;
|
||||
use std::fs::read_to_string;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
@ -1145,6 +1146,7 @@ impl HTMLScriptElement {
|
|||
// Step 6.
|
||||
let document = self.owner_document();
|
||||
let old_script = document.GetCurrentScript();
|
||||
let introduction_type = (!script.external).then_some(c"inlineScript");
|
||||
|
||||
match script.type_ {
|
||||
ScriptType::Classic => {
|
||||
|
@ -1153,7 +1155,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 => {
|
||||
|
@ -1179,7 +1181,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: Option<&'static CStr>,
|
||||
) {
|
||||
// TODO use a settings object rather than this element's document/window
|
||||
// Step 2
|
||||
let document = self.owner_document();
|
||||
|
@ -1205,6 +1212,7 @@ impl HTMLScriptElement {
|
|||
script.fetch_options.clone(),
|
||||
script.url.clone(),
|
||||
can_gc,
|
||||
introduction_type,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -39,6 +39,7 @@ pub(crate) fn load_script(head: &HTMLHeadElement) {
|
|||
ScriptFetchOptions::default_classic_script(global_scope),
|
||||
global_scope.api_base_url(),
|
||||
CanGc::note(),
|
||||
None,
|
||||
);
|
||||
}
|
||||
}));
|
||||
|
|
|
@ -427,12 +427,17 @@ impl WorkerGlobalScopeMethods<crate::DomTypeHolder> for WorkerGlobalScope {
|
|||
Ok((metadata, bytes)) => (metadata.final_url, String::from_utf8(bytes).unwrap()),
|
||||
};
|
||||
|
||||
let options = self
|
||||
.runtime
|
||||
.borrow()
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.new_compile_options(url.as_str(), 1);
|
||||
let result = self.runtime.borrow().as_ref().unwrap().evaluate_script(
|
||||
self.reflector().get_jsobject(),
|
||||
&source,
|
||||
url.as_str(),
|
||||
1,
|
||||
rval.handle_mut(),
|
||||
options,
|
||||
);
|
||||
|
||||
maybe_resume_unwind();
|
||||
|
@ -639,12 +644,17 @@ impl WorkerGlobalScope {
|
|||
let _aes = AutoEntryScript::new(self.upcast());
|
||||
let cx = self.runtime.borrow().as_ref().unwrap().cx();
|
||||
rooted!(in(cx) let mut rval = UndefinedValue());
|
||||
let options = self
|
||||
.runtime
|
||||
.borrow()
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.new_compile_options(self.worker_url.borrow().as_str(), 1);
|
||||
match self.runtime.borrow().as_ref().unwrap().evaluate_script(
|
||||
self.reflector().get_jsobject(),
|
||||
&source,
|
||||
self.worker_url.borrow().as_str(),
|
||||
1,
|
||||
rval.handle_mut(),
|
||||
options,
|
||||
) {
|
||||
Ok(_) => (),
|
||||
Err(_) => {
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
//! related to `type=module` for script thread or worker threads.
|
||||
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::ffi::CStr;
|
||||
use std::rc::Rc;
|
||||
use std::str::FromStr;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
@ -467,11 +468,15 @@ impl ModuleTree {
|
|||
mut module_script: RustMutableHandleObject,
|
||||
inline: bool,
|
||||
can_gc: CanGc,
|
||||
introduction_type: Option<&'static CStr>,
|
||||
) -> 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 mut compile_options = unsafe { CompileOptionsWrapper::new(*cx, url.as_str(), 1) };
|
||||
if let Some(introduction_type) = introduction_type {
|
||||
compile_options.set_introduction_type(introduction_type);
|
||||
}
|
||||
let mut module_source = ModuleSource {
|
||||
source: module_script_text,
|
||||
unminified_dir: global.unminified_js_dir(),
|
||||
|
@ -1331,6 +1336,7 @@ impl FetchResponseListener for ModuleContext {
|
|||
compiled_module.handle_mut(),
|
||||
false,
|
||||
CanGc::note(),
|
||||
None,
|
||||
);
|
||||
|
||||
match compiled_module_result {
|
||||
|
@ -1895,6 +1901,7 @@ pub(crate) fn fetch_inline_module_script(
|
|||
compiled_module.handle_mut(),
|
||||
true,
|
||||
can_gc,
|
||||
Some(c"inlineScript"),
|
||||
);
|
||||
|
||||
match compiled_module_result {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue