forked from denoland/deno
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ext/ffi): Avoid keeping JsRuntimeState RefCell borrowed for event…
… loop middleware calls (denoland#15116)
- Loading branch information
Showing
6 changed files
with
132 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
const targetDir = Deno.execPath().replace(/[^\/\\]+$/, ""); | ||
const [libPrefix, libSuffix] = { | ||
darwin: ["lib", "dylib"], | ||
linux: ["lib", "so"], | ||
windows: ["", "dll"], | ||
}[Deno.build.os]; | ||
const libPath = `${targetDir}/${libPrefix}test_ffi.${libSuffix}`; | ||
|
||
const dylib = Deno.dlopen( | ||
libPath, | ||
{ | ||
store_function: { | ||
parameters: ["function"], | ||
result: "void", | ||
}, | ||
call_stored_function: { | ||
parameters: [], | ||
result: "void", | ||
}, | ||
call_stored_function_thread_safe_and_log: { | ||
parameters: [], | ||
result: "void", | ||
}, | ||
} as const, | ||
); | ||
|
||
const tripleLogCallback = () => { | ||
console.log("Sync"); | ||
Promise.resolve().then(() => { | ||
console.log("Async"); | ||
callback.unref(); | ||
}); | ||
setTimeout(() => { | ||
console.log("Timeout"); | ||
callback.unref(); | ||
}, 10); | ||
}; | ||
|
||
const callback = new Deno.UnsafeCallback( | ||
{ | ||
parameters: [], | ||
result: "void", | ||
} as const, | ||
tripleLogCallback, | ||
); | ||
|
||
// Store function | ||
dylib.symbols.store_function(callback.pointer); | ||
|
||
// Synchronous callback logging | ||
console.log("SYNCHRONOUS"); | ||
dylib.symbols.call_stored_function(); | ||
console.log("STORED_FUNCTION called"); | ||
|
||
// Wait to make sure synch logging and async logging | ||
await new Promise((res) => setTimeout(res, 100)); | ||
|
||
// Ref twice to make sure both `Promise.resolve().then()` and `setTimeout()` | ||
// must resolve before isolate exists. | ||
callback.ref(); | ||
callback.ref(); | ||
|
||
console.log("THREAD SAFE"); | ||
dylib.symbols.call_stored_function_thread_safe_and_log(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters