@@ -52,8 +52,6 @@ using form_data::MultipartFormData;
5252
5353using namespace std ::literals;
5454
55- static api::Engine *ENGINE;
56-
5755bool error_stream_controller_with_pending_exception (JSContext *cx, HandleObject stream) {
5856 RootedValue exn (cx);
5957 if (!JS_GetPendingException (cx, &exn))
@@ -528,7 +526,8 @@ bool finish_outgoing_body_streaming(JSContext *cx, HandleObject body_owner) {
528526 .toPrivate ());
529527 SetReservedSlot (body_owner, static_cast <uint32_t >(Request::Slots::PendingResponseHandle),
530528 PrivateValue (nullptr ));
531- ENGINE->queue_async_task (new ResponseFutureTask (body_owner, pending_handle));
529+ api::Engine::from_context (cx)
530+ .queue_async_task (new ResponseFutureTask (body_owner, pending_handle));
532531 }
533532
534533 return true ;
@@ -538,9 +537,10 @@ bool RequestOrResponse::append_body(JSContext *cx, JS::HandleObject self, JS::Ha
538537 api::TaskCompletionCallback callback, HandleObject callback_receiver) {
539538 MOZ_ASSERT (!body_used (source));
540539 MOZ_ASSERT (self != source);
540+ auto engine = api::Engine::from_context (cx);
541541 host_api::HttpIncomingBody *source_body = incoming_body_handle (source);
542542 host_api::HttpOutgoingBody *dest_body = outgoing_body_handle (self);
543- auto res = dest_body->append (ENGINE , source_body, callback, callback_receiver);
543+ auto res = dest_body->append (&engine , source_body, callback, callback_receiver);
544544 if (auto *err = res.to_err ()) {
545545 HANDLE_ERROR (cx, *err);
546546 return false ;
@@ -1008,7 +1008,7 @@ bool do_body_source_pull(JSContext *cx, HandleObject source, HandleObject body_o
10081008 return true ;
10091009 }
10101010
1011- ENGINE-> queue_async_task (new BodyFutureTask (source));
1011+ api::Engine::from_context (cx). queue_async_task (new BodyFutureTask (source));
10121012 return true ;
10131013}
10141014
@@ -1118,7 +1118,7 @@ bool reader_for_outgoing_body_then_handler(JSContext *cx, JS::HandleObject body_
11181118 // Uint8Array?
11191119 fprintf (stderr, " Error: read operation on body ReadableStream didn't respond with a "
11201120 " Uint8Array. Received value: " );
1121- ENGINE-> dump_value (val, stderr);
1121+ api::Engine::from_context (cx). dump_value (val, stderr);
11221122 return false ;
11231123 }
11241124
@@ -1179,7 +1179,7 @@ bool reader_for_outgoing_body_catch_handler(JSContext *cx, JS::HandleObject body
11791179 // stream errored during the streaming send. Not much we can do, but at least
11801180 // close the stream, and warn.
11811181 fprintf (stderr, " Warning: body ReadableStream closed during body streaming. Exception: " );
1182- ENGINE-> dump_value (args.get (0 ), stderr);
1182+ api::Engine::from_context (cx). dump_value (args.get (0 ), stderr);
11831183
11841184 return finish_outgoing_body_streaming (cx, body_owner);
11851185}
@@ -1198,7 +1198,8 @@ bool RequestOrResponse::maybe_stream_body(JSContext *cx, JS::HandleObject body_o
11981198 if (is_incoming (body_owner)) {
11991199 auto *source_body = incoming_body_handle (body_owner);
12001200 auto *dest_body = destination->body ().unwrap ();
1201- auto res = dest_body->append (ENGINE, source_body, finish_outgoing_body_streaming, nullptr );
1201+ auto engine = api::Engine::from_context (cx);
1202+ auto res = dest_body->append (&engine, source_body, finish_outgoing_body_streaming, nullptr );
12021203 if (auto *err = res.to_err ()) {
12031204 HANDLE_ERROR (cx, *err);
12041205 return false ;
@@ -2687,8 +2688,6 @@ JSObject *Response::create_incoming(JSContext *cx, host_api::HttpIncomingRespons
26872688namespace request_response {
26882689
26892690bool install (api::Engine *engine) {
2690- ENGINE = engine;
2691-
26922691 if (!Request::init_class (engine->cx (), engine->global ()))
26932692 return false ;
26942693 if (!Response::init_class (engine->cx (), engine->global ()))
0 commit comments