diff options
-rw-r--r-- | src/bun.js/bindings/webcore/AbortAlgorithm.h | 2 | ||||
-rw-r--r-- | src/bun.js/bindings/webcore/AbortSignal.cpp | 20 | ||||
-rw-r--r-- | src/bun.js/bindings/webcore/AbortSignal.h | 2 | ||||
-rw-r--r-- | src/bun.js/bindings/webcore/EventTarget.cpp | 2 | ||||
-rw-r--r-- | src/bun.js/bindings/webcore/JSAbortAlgorithm.cpp | 3 | ||||
-rw-r--r-- | src/bun.js/bindings/webcore/JSAbortAlgorithm.h | 2 | ||||
-rw-r--r-- | src/bun.js/builtins/cpp/ReadableStreamInternalsBuiltins.cpp | 15 | ||||
-rw-r--r-- | src/bun.js/builtins/cpp/StreamInternalsBuiltins.cpp | 16 | ||||
-rw-r--r-- | src/bun.js/builtins/js/ReadableStreamInternals.js | 13 |
9 files changed, 38 insertions, 37 deletions
diff --git a/src/bun.js/bindings/webcore/AbortAlgorithm.h b/src/bun.js/bindings/webcore/AbortAlgorithm.h index 26dd666b4..85cba42b7 100644 --- a/src/bun.js/bindings/webcore/AbortAlgorithm.h +++ b/src/bun.js/bindings/webcore/AbortAlgorithm.h @@ -35,7 +35,7 @@ class AbortAlgorithm : public ThreadSafeRefCounted<AbortAlgorithm>, public Activ public: using ActiveDOMCallback::ActiveDOMCallback; - virtual CallbackResult<void> handleEvent() = 0; + virtual CallbackResult<void> handleEvent(JSC::JSValue) = 0; }; } // namespace WebCore diff --git a/src/bun.js/bindings/webcore/AbortSignal.cpp b/src/bun.js/bindings/webcore/AbortSignal.cpp index 8554b3b83..822595064 100644 --- a/src/bun.js/bindings/webcore/AbortSignal.cpp +++ b/src/bun.js/bindings/webcore/AbortSignal.cpp @@ -103,7 +103,7 @@ void AbortSignal::signalAbort(JSC::JSValue reason) Ref protectedThis { *this }; auto algorithms = std::exchange(m_algorithms, {}); for (auto& algorithm : algorithms) - algorithm(); + algorithm(reason); // 5. Fire an event named abort at signal. dispatchEvent(Event::create(eventNames().abortEvent, Event::CanBubble::No, Event::IsCancelable::No)); @@ -122,9 +122,15 @@ void AbortSignal::signalFollow(AbortSignal& signal) ASSERT(!m_followingSignal); m_followingSignal = signal; - signal.addAlgorithm([weakThis = WeakPtr { this }] { - if (weakThis) - weakThis->signalAbort(weakThis->m_followingSignal ? weakThis->m_followingSignal->reason().getValue() : JSC::jsUndefined()); + signal.addAlgorithm([weakThis = WeakPtr { this }](JSC::JSValue reason) { + if (weakThis) { + if (reason.isEmpty() || reason.isUndefined()) { + weakThis->signalAbort(weakThis->m_followingSignal ? weakThis->m_followingSignal->reason().getValue() + : JSC::jsUndefined()); + } else { + weakThis->signalAbort(reason); + } + } }); } @@ -136,11 +142,11 @@ void AbortSignal::eventListenersDidChange() bool AbortSignal::whenSignalAborted(AbortSignal& signal, Ref<AbortAlgorithm>&& algorithm) { if (signal.aborted()) { - algorithm->handleEvent(); + algorithm->handleEvent(signal.m_reason.getValue()); return true; } - signal.addAlgorithm([algorithm = WTFMove(algorithm)]() mutable { - algorithm->handleEvent(); + signal.addAlgorithm([algorithm = WTFMove(algorithm)](JSC::JSValue value) mutable { + algorithm->handleEvent(value); }); return false; } diff --git a/src/bun.js/bindings/webcore/AbortSignal.h b/src/bun.js/bindings/webcore/AbortSignal.h index 24f893f22..05e64ca82 100644 --- a/src/bun.js/bindings/webcore/AbortSignal.h +++ b/src/bun.js/bindings/webcore/AbortSignal.h @@ -63,7 +63,7 @@ public: using RefCounted::deref; using RefCounted::ref; - using Algorithm = Function<void()>; + using Algorithm = Function<void(JSValue)>; void addAlgorithm(Algorithm&& algorithm) { m_algorithms.append(WTFMove(algorithm)); } bool isFollowingSignal() const { return !!m_followingSignal; } diff --git a/src/bun.js/bindings/webcore/EventTarget.cpp b/src/bun.js/bindings/webcore/EventTarget.cpp index 3b7128b7a..cc2113ec9 100644 --- a/src/bun.js/bindings/webcore/EventTarget.cpp +++ b/src/bun.js/bindings/webcore/EventTarget.cpp @@ -98,7 +98,7 @@ bool EventTarget::addEventListener(const AtomString& eventType, Ref<EventListene return false; if (options.signal) { - options.signal->addAlgorithm([weakThis = WeakPtr { *this }, eventType, listener = WeakPtr { listener }, capture = options.capture] { + options.signal->addAlgorithm([weakThis = WeakPtr { *this }, eventType, listener = WeakPtr { listener }, capture = options.capture](JSC::JSValue value) { if (weakThis && listener) weakThis->removeEventListener(eventType, *listener, capture); }); diff --git a/src/bun.js/bindings/webcore/JSAbortAlgorithm.cpp b/src/bun.js/bindings/webcore/JSAbortAlgorithm.cpp index 81310bbd5..d3e2fadfd 100644 --- a/src/bun.js/bindings/webcore/JSAbortAlgorithm.cpp +++ b/src/bun.js/bindings/webcore/JSAbortAlgorithm.cpp @@ -49,7 +49,7 @@ JSAbortAlgorithm::~JSAbortAlgorithm() #endif } -CallbackResult<typename IDLUndefined::ImplementationType> JSAbortAlgorithm::handleEvent() +CallbackResult<typename IDLUndefined::ImplementationType> JSAbortAlgorithm::handleEvent(JSValue value) { if (!canInvokeCallback()) return CallbackResultType::UnableToExecute; @@ -63,6 +63,7 @@ CallbackResult<typename IDLUndefined::ImplementationType> JSAbortAlgorithm::hand auto& lexicalGlobalObject = globalObject; JSValue thisValue = jsUndefined(); MarkedArgumentBuffer args; + args.append(value); ASSERT(!args.hasOverflowed()); NakedPtr<JSC::Exception> returnedException; diff --git a/src/bun.js/bindings/webcore/JSAbortAlgorithm.h b/src/bun.js/bindings/webcore/JSAbortAlgorithm.h index 9193ac7e6..441bfe8cc 100644 --- a/src/bun.js/bindings/webcore/JSAbortAlgorithm.h +++ b/src/bun.js/bindings/webcore/JSAbortAlgorithm.h @@ -40,7 +40,7 @@ public: JSCallbackDataStrong* callbackData() { return m_data; } // Functions - CallbackResult<typename IDLUndefined::ImplementationType> handleEvent() override; + CallbackResult<typename IDLUndefined::ImplementationType> handleEvent(JSValue) override; private: JSAbortAlgorithm(JSC::VM&, JSC::JSObject* callback); diff --git a/src/bun.js/builtins/cpp/ReadableStreamInternalsBuiltins.cpp b/src/bun.js/builtins/cpp/ReadableStreamInternalsBuiltins.cpp index 4e08d5f38..8431b9fb7 100644 --- a/src/bun.js/builtins/cpp/ReadableStreamInternalsBuiltins.cpp +++ b/src/bun.js/builtins/cpp/ReadableStreamInternalsBuiltins.cpp @@ -336,7 +336,7 @@ const char* const s_readableStreamInternalsReadableStreamDefaultControllerStartC const JSC::ConstructAbility s_readableStreamInternalsReadableStreamPipeToWritableStreamCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_readableStreamInternalsReadableStreamPipeToWritableStreamCodeConstructorKind = JSC::ConstructorKind::None; const JSC::ImplementationVisibility s_readableStreamInternalsReadableStreamPipeToWritableStreamCodeImplementationVisibility = JSC::ImplementationVisibility::Public; -const int s_readableStreamInternalsReadableStreamPipeToWritableStreamCodeLength = 3326; +const int s_readableStreamInternalsReadableStreamPipeToWritableStreamCodeLength = 3229; static const JSC::Intrinsic s_readableStreamInternalsReadableStreamPipeToWritableStreamCodeIntrinsic = JSC::NoIntrinsic; const char* const s_readableStreamInternalsReadableStreamPipeToWritableStreamCode = "(function (\n" \ @@ -385,14 +385,9 @@ const char* const s_readableStreamInternalsReadableStreamPipeToWritableStreamCod " pipeState.pendingWritePromise = @Promise.@resolve();\n" \ "\n" \ " if (signal !== @undefined) {\n" \ - " const algorithm = () => {\n" \ + " const algorithm = (reason) => {\n" \ " if (pipeState.finalized) return;\n" \ "\n" \ - " const error = @makeDOMException(\n" \ - " \"AbortError\",\n" \ - " \"abort pipeTo from signal\"\n" \ - " );\n" \ - "\n" \ " @pipeToShutdownWithAction(\n" \ " pipeState,\n" \ " () => {\n" \ @@ -401,7 +396,7 @@ const char* const s_readableStreamInternalsReadableStreamPipeToWritableStreamCod " @getByIdDirectPrivate(pipeState.destination, \"state\") ===\n" \ " \"writable\";\n" \ " const promiseDestination = shouldAbortDestination\n" \ - " ? @writableStreamAbort(pipeState.destination, error)\n" \ + " ? @writableStreamAbort(pipeState.destination, reason)\n" \ " : @Promise.@resolve();\n" \ "\n" \ " const shouldAbortSource =\n" \ @@ -409,7 +404,7 @@ const char* const s_readableStreamInternalsReadableStreamPipeToWritableStreamCod " @getByIdDirectPrivate(pipeState.source, \"state\") ===\n" \ " @streamReadable;\n" \ " const promiseSource = shouldAbortSource\n" \ - " ? @readableStreamCancel(pipeState.source, error)\n" \ + " ? @readableStreamCancel(pipeState.source, reason)\n" \ " : @Promise.@resolve();\n" \ "\n" \ " let promiseCapability = @newPromiseCapability(@Promise);\n" \ @@ -431,7 +426,7 @@ const char* const s_readableStreamInternalsReadableStreamPipeToWritableStreamCod " promiseSource.@then(handleResolvedPromise, handleRejectedPromise);\n" \ " return promiseCapability.@promise;\n" \ " },\n" \ - " error\n" \ + " reason\n" \ " );\n" \ " };\n" \ " if (@whenSignalAborted(signal, algorithm))\n" \ diff --git a/src/bun.js/builtins/cpp/StreamInternalsBuiltins.cpp b/src/bun.js/builtins/cpp/StreamInternalsBuiltins.cpp index a957a7c2b..c231091b6 100644 --- a/src/bun.js/builtins/cpp/StreamInternalsBuiltins.cpp +++ b/src/bun.js/builtins/cpp/StreamInternalsBuiltins.cpp @@ -392,14 +392,16 @@ const char* const s_streamInternalsResetQueueCode = const JSC::ConstructAbility s_streamInternalsExtractSizeAlgorithmCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_streamInternalsExtractSizeAlgorithmCodeConstructorKind = JSC::ConstructorKind::None; const JSC::ImplementationVisibility s_streamInternalsExtractSizeAlgorithmCodeImplementationVisibility = JSC::ImplementationVisibility::Public; -const int s_streamInternalsExtractSizeAlgorithmCodeLength = 288; +const int s_streamInternalsExtractSizeAlgorithmCodeLength = 294; static const JSC::Intrinsic s_streamInternalsExtractSizeAlgorithmCodeIntrinsic = JSC::NoIntrinsic; const char* const s_streamInternalsExtractSizeAlgorithmCode = "(function (strategy)\n" \ "{\n" \ - " if (!(\"size\" in strategy))\n" \ + " const sizeAlgorithm = strategy.size;\n" \ + "\n" \ + " if (sizeAlgorithm === @undefined)\n" \ " return () => 1;\n" \ - " const sizeAlgorithm = strategy[\"size\"];\n" \ + "\n" \ " if (typeof sizeAlgorithm !== \"function\")\n" \ " @throwTypeError(\"strategy.size must be a function\");\n" \ "\n" \ @@ -410,14 +412,16 @@ const char* const s_streamInternalsExtractSizeAlgorithmCode = const JSC::ConstructAbility s_streamInternalsExtractHighWaterMarkCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_streamInternalsExtractHighWaterMarkCodeConstructorKind = JSC::ConstructorKind::None; const JSC::ImplementationVisibility s_streamInternalsExtractHighWaterMarkCodeImplementationVisibility = JSC::ImplementationVisibility::Public; -const int s_streamInternalsExtractHighWaterMarkCodeLength = 325; +const int s_streamInternalsExtractHighWaterMarkCodeLength = 322; static const JSC::Intrinsic s_streamInternalsExtractHighWaterMarkCodeIntrinsic = JSC::NoIntrinsic; const char* const s_streamInternalsExtractHighWaterMarkCode = "(function (strategy, defaultHWM)\n" \ "{\n" \ - " if (!(\"highWaterMark\" in strategy))\n" \ + " const highWaterMark = strategy.highWaterMark;\n" \ + "\n" \ + " if (highWaterMark === @undefined)\n" \ " return defaultHWM;\n" \ - " const highWaterMark = strategy[\"highWaterMark\"];\n" \ + "\n" \ " if (@isNaN(highWaterMark) || highWaterMark < 0)\n" \ " @throwRangeError(\"highWaterMark value is negative or not a number\");\n" \ "\n" \ diff --git a/src/bun.js/builtins/js/ReadableStreamInternals.js b/src/bun.js/builtins/js/ReadableStreamInternals.js index 15042baa5..f317eeaec 100644 --- a/src/bun.js/builtins/js/ReadableStreamInternals.js +++ b/src/bun.js/builtins/js/ReadableStreamInternals.js @@ -304,14 +304,9 @@ function readableStreamPipeToWritableStream( pipeState.pendingWritePromise = @Promise.@resolve(); if (signal !== @undefined) { - const algorithm = () => { + const algorithm = (reason) => { if (pipeState.finalized) return; - const error = @makeDOMException( - "AbortError", - "abort pipeTo from signal" - ); - @pipeToShutdownWithAction( pipeState, () => { @@ -320,7 +315,7 @@ function readableStreamPipeToWritableStream( @getByIdDirectPrivate(pipeState.destination, "state") === "writable"; const promiseDestination = shouldAbortDestination - ? @writableStreamAbort(pipeState.destination, error) + ? @writableStreamAbort(pipeState.destination, reason) : @Promise.@resolve(); const shouldAbortSource = @@ -328,7 +323,7 @@ function readableStreamPipeToWritableStream( @getByIdDirectPrivate(pipeState.source, "state") === @streamReadable; const promiseSource = shouldAbortSource - ? @readableStreamCancel(pipeState.source, error) + ? @readableStreamCancel(pipeState.source, reason) : @Promise.@resolve(); let promiseCapability = @newPromiseCapability(@Promise); @@ -350,7 +345,7 @@ function readableStreamPipeToWritableStream( promiseSource.@then(handleResolvedPromise, handleRejectedPromise); return promiseCapability.@promise; }, - error + reason ); }; if (@whenSignalAborted(signal, algorithm)) |