Skip to content

script: Move BlobMethods to &mut JSContext#43215

Merged
Gae24 merged 3 commits into
servo:mainfrom
Uiniel:context_blob_first_half
Mar 12, 2026
Merged

script: Move BlobMethods to &mut JSContext#43215
Gae24 merged 3 commits into
servo:mainfrom
Uiniel:context_blob_first_half

Conversation

@Uiniel

@Uiniel Uiniel commented Mar 12, 2026

Copy link
Copy Markdown
Contributor

Move from CanGc to &mut js::context:JSContext. ArrayBuffer and Bytes require many changes in dom/stream for which I'm going to create a seperate pull request before porting the two methods.

Testing: Just a refactor, ./mach test-unit still passes.
Fixes: Part of #42638

Signed-off-by: Uiniel <174327181+uiniel@users.noreply.github.com>
@Uiniel Uiniel requested a review from gterzian as a code owner March 12, 2026 13:48
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Mar 12, 2026
Comment thread components/script/dom/blob.rs Outdated
let in_realm_proof = AlreadyInRealm::assert::<crate::DomTypeHolder>();
let p = Promise::new_in_current_realm(InRealm::Already(&in_realm_proof), can_gc);
let p =
Promise::new_in_current_realm(InRealm::Already(&in_realm_proof), CanGc::from_cx(cx));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
Promise::new_in_current_realm(InRealm::Already(&in_realm_proof), CanGc::from_cx(cx));
Promise::new_in_realm(cx);

'canGc': ['Slice', 'Text', 'ArrayBuffer', 'Stream', 'Bytes'],
'canGc': ['ArrayBuffer', 'Bytes'],
'inRealms': ['Bytes', 'ArrayBuffer'],
'cx': ['Stream', 'Slice', 'Text', 'Constructor']

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since Text creates a Promise we need to move it to 'realm': ['Text']

Comment thread components/script/dom/globalscope.rs Outdated
let task = task!(resolve_promise: move || {
let task = task!(resolve_promise: move |cx| {
let promise = trusted_promise.root();
let _ac = enter_realm(&*promise.global());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's call enter_auto_realm(cx, promise.global()) here.

@Uiniel Uiniel Mar 12, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This change would result in two mutable borrows of cx, because _ac is dropped after the call to callback. I'm also not familiar enough with the code to understand why enter_realm is needed here or if it is still needed after changing CanGc::note to CanGc::from_cx in the callback.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we still need it, you can fix the borrow issue by doing

        let mut realm = enter_auto_realm(cx, promise.global());
        let cx = &mut realm;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah right thanks! I forgot that realms can also be used as a context.

Comment thread components/script/dom/globalscope.rs Outdated
self.task_source.queue(task!(reject_promise: move || {
self.task_source.queue(task!(reject_promise: move |cx| {
let promise = trusted_promise.root();
let _ac = enter_realm(&*promise.global());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same here.

Uiniel added 2 commits March 12, 2026 17:57
Signed-off-by: Uiniel <174327181+uiniel@users.noreply.github.com>
Signed-off-by: Uiniel <174327181+uiniel@users.noreply.github.com>

@Gae24 Gae24 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you!

@servo-highfive servo-highfive removed the S-awaiting-review There is new code that needs to be reviewed. label Mar 12, 2026
@Gae24 Gae24 added this pull request to the merge queue Mar 12, 2026
@servo-highfive servo-highfive added the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Mar 12, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Mar 12, 2026
@servo-highfive servo-highfive added S-tests-failed The changes caused existing tests to fail. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Mar 12, 2026
@Gae24 Gae24 added this pull request to the merge queue Mar 12, 2026
@servo-highfive servo-highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-tests-failed The changes caused existing tests to fail. labels Mar 12, 2026
Merged via the queue into servo:main with commit 0f5e020 Mar 12, 2026
36 checks passed
@servo-highfive servo-highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Mar 12, 2026
offline-ant pushed a commit to offline-ant/havi that referenced this pull request Jun 4, 2026
Move from CanGc to &mut js::context:JSContext. `ArrayBuffer` and `Bytes`
require many changes in `dom/stream` for which I'm going to create a
seperate pull request before porting the two methods.

Testing: Just a refactor, `./mach test-unit` still passes.
Fixes: Part of servo#42638

---------

Signed-off-by: Uiniel <174327181+uiniel@users.noreply.github.com>
(cherry picked from commit 0f5e020)
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.

3 participants