Skip to content

fixing take_raw dropping the externref before resolving it.#244

Open
muenchow wants to merge 1 commit intoslowli:mainfrom
muenchow:main
Open

fixing take_raw dropping the externref before resolving it.#244
muenchow wants to merge 1 commit intoslowli:mainfrom
muenchow:main

Conversation

@muenchow
Copy link

@muenchow muenchow commented Sep 24, 2025

What?

Currently, a #[externref] function that returns a Resource<..> will always return null.
The issue lies in Resource::take_raw: it drops the resource (and frees the slot) before get_externref is called.

This means that by the time get_externref tries to retrieve the ExternRef, the underlying resource has already been dropped.

Fix

The fix is to delay dropping the Resource<..> until the end of the function.
This ensures that get_externref can lookup the ExternRef before the slot is emptied.

@ottoville
Copy link

I can confirm that the bug exist and this patch fixes it. If a function returns an owned externref to JS, its always null. Any change to get merged into main @slowli ?

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