mirror of
https://github.com/servo/servo.git
synced 2025-08-09 15:35:34 +01:00
script: Tell SpiderMonkey whether scripts are inline (#38363)
to use the [SpiderMonkey Debugger API](https://firefox-source-docs.mozilla.org/js/Debugger/) as the single source of truth about scripts and their sources for devtools purposes (servo/servo#38334), the debugger script needs to be able to distinguish inline scripts from other scripts, because inline scripts are a special case where the source contents need to come from the Servo parser. the mechanism for this is [Debugger.Script.prototype.**introductionType**](https://firefox-source-docs.mozilla.org/js/Debugger/Debugger.Source.html#introductiontype), which is `inlineScript` for inline scripts or a variety of other values for other kinds of scripts, but only the embedder can provide this information. this patch bumps mozjs to servo/mozjs#603, which expands on CompileOptionsWrapper, making it a safe wrapper around CompileOptions. to construct one from safe code, use Runtime::new_compile_options(). then you can call `set_introduction_type(&'static CStr)` on the new instance. we also make Runtime::evaluate_script() take a CompileOptionsWrapper from the caller, instead of constructing one internally. in this patch, we set the introductionType to `c"inlineScript"` when calling run_a_classic_script() and compile_module_script() for inline scripts, and leave it unset all other cases. Testing: will undergo automated tests in #38334 Fixes: part of #36027, part of servo/servo#38378 --------- Signed-off-by: Delan Azabani <dazabani@igalia.com> Co-authored-by: atbrakhi <atbrakhi@igalia.com>
This commit is contained in:
parent
0bf8676345
commit
3eddfeaee2
8 changed files with 52 additions and 13 deletions
|
@ -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(_) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue