@@ -41,8 +41,6 @@ bool NativeStreamSource::stream_is_body(JSContext *cx, JS::HandleObject stream)
4141
4242namespace builtins ::web::fetch {
4343
44- static api::Engine *ENGINE;
45-
4644bool error_stream_controller_with_pending_exception (JSContext *cx, HandleObject controller) {
4745 RootedValue exn (cx);
4846 if (!JS_GetPendingException (cx, &exn))
@@ -466,7 +464,8 @@ bool finish_outgoing_body_streaming(JSContext* cx, HandleObject body_owner) {
466464 .toPrivate ());
467465 SetReservedSlot (body_owner, static_cast <uint32_t >(Request::Slots::PendingResponseHandle),
468466 PrivateValue (nullptr ));
469- ENGINE->queue_async_task (new ResponseFutureTask (body_owner, pending_handle));
467+ api::Engine::from_context (cx)
468+ .queue_async_task (new ResponseFutureTask (body_owner, pending_handle));
470469 }
471470
472471 return true ;
@@ -476,9 +475,10 @@ bool RequestOrResponse::append_body(JSContext *cx, JS::HandleObject self, JS::Ha
476475 MOZ_ASSERT (!body_used (source));
477476 MOZ_ASSERT (!body_used (self));
478477 MOZ_ASSERT (self != source);
478+ auto engine = api::Engine::from_context (cx);
479479 host_api::HttpIncomingBody *source_body = incoming_body_handle (source);
480480 host_api::HttpOutgoingBody *dest_body = outgoing_body_handle (self);
481- auto res = dest_body->append (ENGINE , source_body, finish_outgoing_body_streaming, self);
481+ auto res = dest_body->append (&engine , source_body, finish_outgoing_body_streaming, self);
482482 if (auto *err = res.to_err ()) {
483483 HANDLE_ERROR (cx, *err);
484484 return false ;
@@ -892,7 +892,7 @@ bool RequestOrResponse::body_source_pull_algorithm(JSContext *cx, CallArgs args,
892892 }
893893 }
894894
895- ENGINE-> queue_async_task (new BodyFutureTask (source));
895+ api::Engine::from_context (cx). queue_async_task (new BodyFutureTask (source));
896896
897897 args.rval ().setUndefined ();
898898 return true ;
@@ -945,7 +945,7 @@ bool reader_for_outgoing_body_then_handler(JSContext *cx, JS::HandleObject body_
945945 // Uint8Array?
946946 fprintf (stderr, " Error: read operation on body ReadableStream didn't respond with a "
947947 " Uint8Array. Received value: " );
948- ENGINE-> dump_value (val, stderr);
948+ api::Engine::from_context (cx). dump_value (val, stderr);
949949 return false ;
950950 }
951951
@@ -985,7 +985,7 @@ bool reader_for_outgoing_body_catch_handler(JSContext *cx, JS::HandleObject body
985985 // stream errored during the streaming send. Not much we can do, but at least
986986 // close the stream, and warn.
987987 fprintf (stderr, " Warning: body ReadableStream closed during body streaming. Exception: " );
988- ENGINE-> dump_value (args.get (0 ), stderr);
988+ api::Engine::from_context (cx). dump_value (args.get (0 ), stderr);
989989
990990 return finish_outgoing_body_streaming (cx, body_owner);
991991}
@@ -1004,7 +1004,8 @@ bool RequestOrResponse::maybe_stream_body(JSContext *cx, JS::HandleObject body_o
10041004 if (is_incoming (body_owner)) {
10051005 auto *source_body = incoming_body_handle (body_owner);
10061006 auto *dest_body = destination->body ().unwrap ();
1007- auto res = dest_body->append (ENGINE, source_body, finish_outgoing_body_streaming, nullptr );
1007+ auto engine = api::Engine::from_context (cx);
1008+ auto res = dest_body->append (&engine, source_body, finish_outgoing_body_streaming, nullptr );
10081009 if (auto *err = res.to_err ()) {
10091010 HANDLE_ERROR (cx, *err);
10101011 return false ;
@@ -1233,7 +1234,7 @@ bool Request::clone(JSContext *cx, unsigned argc, JS::Value *vp) {
12331234 Value url_val = GetReservedSlot (self, static_cast <uint32_t >(Slots::URL));
12341235 SetReservedSlot (new_request, static_cast <uint32_t >(Slots::URL), url_val);
12351236 Value method_val = JS::StringValue (method (self));
1236- ENGINE-> dump_value (method_val, stderr);
1237+ api::Engine::from_context (cx). dump_value (method_val, stderr);
12371238 SetReservedSlot (new_request, static_cast <uint32_t >(Slots::Method), method_val);
12381239
12391240 // clone operation step 2.
@@ -2459,8 +2460,6 @@ JSObject * Response::create_incoming(JSContext *cx, host_api::HttpIncomingRespon
24592460namespace request_response {
24602461
24612462bool install (api::Engine *engine) {
2462- ENGINE = engine;
2463-
24642463 if (!Request::init_class (engine->cx (), engine->global ()))
24652464 return false ;
24662465 if (!Response::init_class (engine->cx (), engine->global ()))
0 commit comments