Skip to content

Expose ScriptEnvironmentPreparer to Rust #598

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Expose ScriptEnvironmentPreparer to Rust #598

wants to merge 1 commit into from

Conversation

delan
Copy link
Member

@delan delan commented Jul 25, 2025

NOTE: do not merge until #597 lands

MOZ_ASSERT(JS_IsGlobalObject(global));
MOZ_ASSERT(!JS_IsExceptionPending(cx));

JSAutoRealm ar(cx, global);
Copy link
Member

Choose a reason for hiding this comment

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

This looks like you're modelling it off of the jsshell version, but I intend to use this to replicate https://searchfox.org/mozilla-central/rev/fcc0cfc7f5b1df957ae29f6b2ccfeb6df47b6be8/xpcom/base/CycleCollectedJSRuntime.cpp#2177 . Since AutoEntryScript is a Servo Rust type, can we make this class implement a hook for Rust code to invoke the closure instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

I intend to use this to replicate https://searchfox.org/mozilla-central/rev/fcc0cfc7f5b1df957ae29f6b2ccfeb6df47b6be8/xpcom/base/CycleCollectedJSRuntime.cpp#2177

can you elaborate on this? i’m not sure i follow, did you have existing plans to set up a ScriptEnvironmentPreparer for Servo?

Since AutoEntryScript is a Servo Rust type, can we make this class implement a hook for Rust code to invoke the closure instead?

yeah, that could work. would the idea be that RustEnvironmentPreparer::invoke() just passes the closure to Servo, which would enter the AutoEntryScript and call the closure?

also, what do we do with uncaught exceptions? the jsshell uses a thing called AutoReportException, but i’m not sure what the Servo counterpart is for that.

Copy link
Member

Choose a reason for hiding this comment

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

can you elaborate on this? i’m not sure i follow, did you have existing plans to set up a ScriptEnvironmentPreparer for Servo?

I didn't know it existed until this PR, but now I want to replicate the way Gecko uses it.

yeah, that could work. would the idea be that RustEnvironmentPreparer::invoke() just passes the closure to Servo, which would enter the AutoEntryScript and call the closure

Yes.

also, what do we do with uncaught exceptions? the jsshell uses a thing called AutoReportException, but i’m not sure what the Servo counterpart is for that.

We have code that calls report_pending_exception in various places right now. Gecko uses AutoJsApi, which is another thing I want to replicate.

@delan delan changed the base branch from runJobs to main July 29, 2025 07:43
@delan
Copy link
Member Author

delan commented Jul 30, 2025

heads up: this is a lower priority for us now, since it only seems to be needed for handling uncaught exceptions in the debugger script (servo/servo#38331).

@jdm
Copy link
Member

jdm commented Jul 30, 2025

That's fine. I suggest just calling report_pending_exception by hand.

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