diff options
author | 2022-11-02 13:44:37 -0700 | |
---|---|---|
committer | 2022-11-02 13:44:37 -0700 | |
commit | 1a3a0adc6304df09414b39ee3e19b91668b5883d (patch) | |
tree | 1ddfe49839a8a1ba96ba70d7d2286fdd8601dcc1 | |
parent | 006a2f37ddb133f61c6fa672652663204c2d2e54 (diff) | |
download | bun-1a3a0adc6304df09414b39ee3e19b91668b5883d.tar.gz bun-1a3a0adc6304df09414b39ee3e19b91668b5883d.tar.zst bun-1a3a0adc6304df09414b39ee3e19b91668b5883d.zip |
Add way to know if JSCallback is threadsafe
-rw-r--r-- | src/bun.js/ffi.exports.js | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/bun.js/ffi.exports.js b/src/bun.js/ffi.exports.js index 922920577..41e93f8ff 100644 --- a/src/bun.js/ffi.exports.js +++ b/src/bun.js/ffi.exports.js @@ -20,10 +20,16 @@ export class JSCallback { const { ctx, ptr } = nativeCallback(options, cb); this.#ctx = ctx; this.ptr = ptr; + this.#threadsafe = !!options?.threadsafe; } ptr; #ctx; + #threadsafe; + + get threadsafe() { + return true; + } [Symbol.toPrimitive]() { const { ptr } = this; @@ -236,10 +242,9 @@ ffiWrappers[FFIType.function] = function functionType(val) { return Number(val); } - // we overwrote Symbol.toPrimitive - var ptr = +val; + var ptr = val && val.ptr; - if (!Number.isFinite(ptr) || ptr === 0) { + if (!ptr) { throw new Error("Expected function to be a JSCallback or a number"); } |