mirror of
https://github.com/servo/servo.git
synced 2025-10-02 17:49:16 +01:00
script: Add line number argument to module script compilation functions (#39544)
Script: added ```line_no``` as argument to both ```fetch_inline_module_script()``` & ```compile_module_script()``` to fix the inline script reporting wrong line issue ([#39415](https://github.com/servo/servo/issues/39415)). Originally, the function ```compile_module_script()``` hardwires the value 1 when invoking ```CompileOptionsWrapper::new()```. This is fine if the script is written in separate JS file, but for inline scripts, it will cause confusion if the ```<script>``` tag doesn't start from line #1. ```line_no``` is obtained from ```line_number```, a member variable from ```HTMLScriptElement```. Credits to @jdm for actually pointing out which functions to fix. Testing: Created a WPT test for this change, specifically: ```tests/wpt/tests/html/semantics/scripting-1/the-script-element/module/evaluation-error-5.html```. Fixes: issue [#39415](https://github.com/servo/servo/issues/39415) --------- Signed-off-by: RichardTjokroutomo <richard.tjokro2@gmail.com> Signed-off-by: Rocketjumper <112361665+RichardTjokroutomo@users.noreply.github.com> Co-authored-by: Josh Matthews <josh@joshmatthews.net> Co-authored-by: Euclid Ye <yezhizhenjiakang@gmail.com>
This commit is contained in:
parent
5018cd8015
commit
91e4188a64
4 changed files with 33 additions and 4 deletions
|
@ -943,6 +943,7 @@ impl HTMLScriptElement {
|
|||
base_url.clone(),
|
||||
self.id,
|
||||
options,
|
||||
self.line_number,
|
||||
can_gc,
|
||||
);
|
||||
},
|
||||
|
|
|
@ -467,13 +467,15 @@ impl ModuleTree {
|
|||
options: ScriptFetchOptions,
|
||||
mut module_script: RustMutableHandleObject,
|
||||
inline: bool,
|
||||
can_gc: CanGc,
|
||||
line_number: u64,
|
||||
introduction_type: Option<&'static CStr>,
|
||||
can_gc: CanGc,
|
||||
) -> Result<(), RethrowError> {
|
||||
let cx = GlobalScope::get_cx();
|
||||
let _ac = JSAutoRealm::new(*cx, *global.reflector().get_jsobject());
|
||||
|
||||
let mut compile_options = unsafe { CompileOptionsWrapper::new(*cx, url.as_str(), 1) };
|
||||
let mut compile_options =
|
||||
unsafe { CompileOptionsWrapper::new(*cx, url.as_str(), line_number as u32) };
|
||||
if let Some(introduction_type) = introduction_type {
|
||||
compile_options.set_introduction_type(introduction_type);
|
||||
}
|
||||
|
@ -1341,8 +1343,9 @@ impl FetchResponseListener for ModuleContext {
|
|||
self.options.clone(),
|
||||
compiled_module.handle_mut(),
|
||||
false,
|
||||
CanGc::note(),
|
||||
1, // external scripts start at the first line of the file
|
||||
self.introduction_type,
|
||||
CanGc::note(),
|
||||
);
|
||||
|
||||
match compiled_module_result {
|
||||
|
@ -1890,6 +1893,7 @@ pub(crate) fn fetch_inline_module_script(
|
|||
url: ServoUrl,
|
||||
script_id: ScriptId,
|
||||
options: ScriptFetchOptions,
|
||||
line_number: u64,
|
||||
can_gc: CanGc,
|
||||
) {
|
||||
let global = owner.global();
|
||||
|
@ -1906,8 +1910,9 @@ pub(crate) fn fetch_inline_module_script(
|
|||
options.clone(),
|
||||
compiled_module.handle_mut(),
|
||||
true,
|
||||
can_gc,
|
||||
line_number,
|
||||
Some(IntroductionType::INLINE_SCRIPT),
|
||||
can_gc,
|
||||
);
|
||||
|
||||
match compiled_module_result {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue