@@ -353,7 +353,10 @@ bool HTMLRewritingStream::onElement(JSContext *cx, unsigned argc, JS::Value *vp)
353353
354354struct OutputContextData {
355355 JSContext *cx;
356- JSObject *self;
356+ JS::Heap<JSObject *> self;
357+ bool enqueue_failed;
358+
359+ OutputContextData (JSContext *cx, JSObject *self) : cx(cx), self(self), enqueue_failed(false ) {}
357360};
358361
359362void HTMLRewritingStream::finalize (JS::GCContext *gcx, JSObject *self) {
@@ -387,7 +390,7 @@ void HTMLRewritingStream::finalize(JS::GCContext *gcx, JSObject *self) {
387390static void output_callback (const char *chunk, size_t chunk_len, void *user_data) {
388391 auto *ctx = static_cast <OutputContextData *>(user_data);
389392 JSContext *cx = ctx->cx ;
390- JSObject * self = ctx->self ;
393+ JS::RootedObject self (cx, ctx->self ) ;
391394
392395 JS::RootedObject out_obj (cx, JS_NewUint8Array (cx, chunk_len));
393396 if (!out_obj) {
@@ -405,6 +408,7 @@ static void output_callback(const char *chunk, size_t chunk_len, void *user_data
405408 JS::RootedValue out_chunk (cx, JS::ObjectValue (*out_obj));
406409
407410 if (!TransformStreamDefaultController::Enqueue (cx, controller, out_chunk)) {
411+ ctx->enqueue_failed = true ;
408412 return ;
409413 }
410414}
@@ -468,6 +472,13 @@ bool HTMLRewritingStream::transformAlgorithm(JSContext *cx, unsigned argc, JS::V
468472 return false ;
469473 }
470474
475+ auto output_context = static_cast <OutputContextData *>(
476+ JS::GetReservedSlot (self, HTMLRewritingStream::Slots::OutputContext).toPrivate ());
477+ if (output_context->enqueue_failed ) {
478+ JS_ReportErrorASCII (cx, " Error processing HTML: output stream enqueue failed" );
479+ return false ;
480+ }
481+
471482 args.rval ().setUndefined ();
472483 return true ;
473484}
0 commit comments