diff options
author | 2023-06-02 22:03:16 -0400 | |
---|---|---|
committer | 2023-06-02 19:03:16 -0700 | |
commit | f798a0cfe8372e7df62d9514e6785e6f16549d25 (patch) | |
tree | 81204276db9636ae4b10ae9de859900da6b6b437 /src/js | |
parent | 51846d0277aa58a69557668cb930448bd62de0bf (diff) | |
download | bun-f798a0cfe8372e7df62d9514e6785e6f16549d25.tar.gz bun-f798a0cfe8372e7df62d9514e6785e6f16549d25.tar.zst bun-f798a0cfe8372e7df62d9514e6785e6f16549d25.zip |
fix readableStreamToArrayBuffer (#3181)
* fix discord.js again
* remove one of the async hooks warnings
* clarify hardcoded modules docs
Diffstat (limited to 'src/js')
-rw-r--r-- | src/js/builtins/ReadableStream.ts | 10 | ||||
-rw-r--r-- | src/js/node/async_hooks.js | 17 | ||||
-rw-r--r-- | src/js/out/WebCoreJSBuiltins.cpp | 4 |
3 files changed, 12 insertions, 19 deletions
diff --git a/src/js/builtins/ReadableStream.ts b/src/js/builtins/ReadableStream.ts index 613f869e5..26b85fb6b 100644 --- a/src/js/builtins/ReadableStream.ts +++ b/src/js/builtins/ReadableStream.ts @@ -132,12 +132,14 @@ export function readableStreamToArrayBuffer(stream: ReadableStream<ArrayBuffer>) return $readableStreamToArrayBufferDirect(stream, underlyingSource); } - var array = Bun.readableStreamToArray(stream); - if ($isPromise(array)) { - return array.$then(Bun.concatArrayBuffers); + var result = Bun.readableStreamToArray(stream); + if ($isPromise(result)) { + // `result` is an InternalPromise, which doesn't have a `.$then` method + // but `.then` isn't user-overridable, so we can use it safely. + return result.then(Bun.concatArrayBuffers); } - return Bun.concatArrayBuffers(array); + return Bun.concatArrayBuffers(result); } $linkTimeConstant; diff --git a/src/js/node/async_hooks.js b/src/js/node/async_hooks.js index c5b0c8fe5..c68a15dbe 100644 --- a/src/js/node/async_hooks.js +++ b/src/js/node/async_hooks.js @@ -5,7 +5,9 @@ var drainMicrotasks = () => { }; var notImplemented = () => { - console.warn("[bun]: async_hooks has not been implemented yet. See https://github.com/oven-sh/bun/issues/1832"); + console.warn( + "[bun] Warning: async_hooks has not been implemented yet. See https://github.com/oven-sh/bun/issues/1832", + ); notImplemented = () => {}; }; @@ -146,19 +148,11 @@ class AsyncResource { constructor(type, triggerAsyncId) { this.type = type; this.triggerAsyncId = triggerAsyncId; - - if (AsyncResource.allowedRunInAsyncScope.has(type)) { - this.runInAsyncScope = this.#runInAsyncScope; - } } type; triggerAsyncId; - // We probably will not fully support AsyncResource - // But some packages in the wild do depend on it - static allowedRunInAsyncScope = new Set(["prisma-client-request"]); - emitBefore() { return true; } @@ -169,10 +163,7 @@ class AsyncResource { emitDestroy() {} - runInAsyncScope; - - #runInAsyncScope(fn, ...args) { - notImplemented(); + runInAsyncScope(fn, ...args) { var result, err; process.nextTick(fn => { try { diff --git a/src/js/out/WebCoreJSBuiltins.cpp b/src/js/out/WebCoreJSBuiltins.cpp index f0df6a9e4..b57e346b5 100644 --- a/src/js/out/WebCoreJSBuiltins.cpp +++ b/src/js/out/WebCoreJSBuiltins.cpp @@ -2420,9 +2420,9 @@ const char* const s_readableStreamReadableStreamToTextCode = "(function (p){\"us const JSC::ConstructAbility s_readableStreamReadableStreamToArrayBufferCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_readableStreamReadableStreamToArrayBufferCodeConstructorKind = JSC::ConstructorKind::None; const JSC::ImplementationVisibility s_readableStreamReadableStreamToArrayBufferCodeImplementationVisibility = JSC::ImplementationVisibility::Private; -const int s_readableStreamReadableStreamToArrayBufferCodeLength = 271; +const int s_readableStreamReadableStreamToArrayBufferCodeLength = 270; static const JSC::Intrinsic s_readableStreamReadableStreamToArrayBufferCodeIntrinsic = JSC::NoIntrinsic; -const char* const s_readableStreamReadableStreamToArrayBufferCode = "(function (_){\"use strict\";var b=@getByIdDirectPrivate(_,\"underlyingSource\");if(b!==@undefined)return @readableStreamToArrayBufferDirect(_,b);var p=@Bun.readableStreamToArray(_);if(@isPromise(p))return p.@then(@Bun.concatArrayBuffers);return @Bun.concatArrayBuffers(p)})\n"; +const char* const s_readableStreamReadableStreamToArrayBufferCode = "(function (_){\"use strict\";var b=@getByIdDirectPrivate(_,\"underlyingSource\");if(b!==@undefined)return @readableStreamToArrayBufferDirect(_,b);var p=@Bun.readableStreamToArray(_);if(@isPromise(p))return p.then(@Bun.concatArrayBuffers);return @Bun.concatArrayBuffers(p)})\n"; // readableStreamToJSON const JSC::ConstructAbility s_readableStreamReadableStreamToJSONCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |