Skip to content

Allow embedder to indicate whether scripts are inline#603

Merged
delan merged 6 commits into
mainfrom
introductionType
Aug 5, 2025
Merged

Allow embedder to indicate whether scripts are inline#603
delan merged 6 commits into
mainfrom
introductionType

Conversation

@delan
Copy link
Copy Markdown
Member

@delan delan commented Jul 30, 2025

to use the SpiderMonkey Debugger API 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, 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 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.

Servo patch: servo/servo#38363
Fixes: part of servo/servo#38378

Comment thread mozjs-sys/src/jsglue.cpp Outdated
delan and others added 2 commits August 5, 2025 17:39
@delan delan force-pushed the introductionType branch from f10a895 to 4b431cc Compare August 5, 2025 09:53
Co-authored-by: atbrakhi <[email protected]>
Signed-off-by: Delan Azabani <[email protected]>
@delan delan force-pushed the introductionType branch from a1c5a9d to 64604b0 Compare August 5, 2025 10:06
@delan delan requested a review from sagudev August 5, 2025 11:05
Comment thread mozjs/src/rust.rs Outdated
Copy link
Copy Markdown
Member

@sagudev sagudev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise this looks good to go.

Co-authored-by: atbrakhi <[email protected]>
Signed-off-by: Delan Azabani <[email protected]>
@delan delan force-pushed the introductionType branch from 194072d to c8ecb34 Compare August 5, 2025 11:12
@delan
Copy link
Copy Markdown
Member Author

delan commented Aug 5, 2025

thanks for the feedback! i’ll update servo/servo#38363 and wait until we can land them together :)

Copy link
Copy Markdown
Member

@sagudev sagudev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is even better.

@delan delan enabled auto-merge August 5, 2025 11:58
@delan delan added this pull request to the merge queue Aug 5, 2025
Merged via the queue into main with commit eb4268a Aug 5, 2025
32 checks passed
github-merge-queue Bot pushed a commit to servo/servo that referenced this pull request Aug 5, 2025
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
(#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 #38378

---------

Signed-off-by: Delan Azabani <[email protected]>
Co-authored-by: atbrakhi <[email protected]>
@delan delan deleted the introductionType branch August 5, 2025 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants