diff --git a/src/node_http2.cc b/src/node_http2.cc index af7698797278e4..4ccd2fe269a8f2 100644 --- a/src/node_http2.cc +++ b/src/node_http2.cc @@ -426,8 +426,13 @@ Http2Priority::Http2Priority(Environment* env, Local weight, Local exclusive) { Local context = env->context(); - int32_t parent_ = parent->Int32Value(context).ToChecked(); - int32_t weight_ = weight->Int32Value(context).ToChecked(); + int32_t parent_; + int32_t weight_; + if (!parent->Int32Value(context).To(&parent_) || + !weight->Int32Value(context).To(&weight_)) { + nghttp2_priority_spec_init(this, 0, 0, 0); + return; + } bool exclusive_ = exclusive->IsTrue(); Debug(env, DebugCategory::HTTP2STREAM, "Http2Priority: parent: %d, weight: %d, exclusive: %s\n", @@ -2715,11 +2720,12 @@ void Http2Stream::DecrementAvailableOutboundLength(size_t amount) { // back to JS land void HttpErrorString(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); - uint32_t val = args[0]->Uint32Value(env->context()).ToChecked(); - args.GetReturnValue().Set( - OneByteString( - env->isolate(), - reinterpret_cast(nghttp2_strerror(val)))); + uint32_t val; + if (args[0]->Uint32Value(env->context()).To(&val)) { + args.GetReturnValue().Set( + OneByteString(env->isolate(), + reinterpret_cast(nghttp2_strerror(val)))); + } } @@ -2744,7 +2750,10 @@ void Http2Session::SetNextStreamID(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); Http2Session* session; ASSIGN_OR_RETURN_UNWRAP(&session, args.This()); - int32_t id = args[0]->Int32Value(env->context()).ToChecked(); + int32_t id; + if (!args[0]->Int32Value(env->context()).To(&id)) { + return; + } if (nghttp2_session_set_next_stream_id(session->session(), id) < 0) { Debug(session, "failed to set next stream id to %d", id); return args.GetReturnValue().Set(false); @@ -2762,7 +2771,10 @@ void Http2Session::SetLocalWindowSize( Http2Session* session; ASSIGN_OR_RETURN_UNWRAP(&session, args.This()); - int32_t window_size = args[0]->Int32Value(env->context()).ToChecked(); + int32_t window_size; + if (!args[0]->Int32Value(env->context()).To(&window_size)) { + return; + } int result = nghttp2_session_set_local_window_size( session->session(), NGHTTP2_FLAG_NONE, 0, window_size); @@ -2822,8 +2834,11 @@ void Http2Session::New(const FunctionCallbackInfo& args) { Http2State* state = realm->GetBindingData(); CHECK(args.IsConstructCall()); - SessionType type = static_cast( - args[0]->Int32Value(realm->context()).ToChecked()); + int32_t val; + if (!args[0]->Int32Value(realm->context()).To(&val)) { + return; + } + SessionType type = static_cast(val); Http2Session* session = new Http2Session(state, args.This(), type); Debug(session, "session created"); } @@ -2845,7 +2860,10 @@ void Http2Session::Destroy(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); Local context = env->context(); - uint32_t code = args[0]->Uint32Value(context).ToChecked(); + uint32_t code; + if (!args[0]->Uint32Value(context).To(&code)) { + return; + } session->Close(code, args[1]->IsTrue()); } @@ -2857,7 +2875,10 @@ void Http2Session::Request(const FunctionCallbackInfo& args) { Environment* env = session->env(); Local headers = args[0].As(); - int32_t options = args[1]->Int32Value(env->context()).ToChecked(); + int32_t options; + if (!args[1]->Int32Value(env->context()).To(&options)) { + return; + } Debug(session, "request submitted"); @@ -2906,8 +2927,14 @@ void Http2Session::Goaway(const FunctionCallbackInfo& args) { Http2Session* session; ASSIGN_OR_RETURN_UNWRAP(&session, args.This()); - uint32_t code = args[0]->Uint32Value(context).ToChecked(); - int32_t lastStreamID = args[1]->Int32Value(context).ToChecked(); + uint32_t code; + if (!args[0]->Uint32Value(context).To(&code)) { + return; + } + int32_t lastStreamID; + if (!args[1]->Int32Value(context).To(&lastStreamID)) { + return; + } ArrayBufferViewContents opaque_data; if (args[2]->IsArrayBufferView()) { @@ -2945,7 +2972,10 @@ void Http2Stream::RstStream(const FunctionCallbackInfo& args) { Local context = env->context(); Http2Stream* stream; ASSIGN_OR_RETURN_UNWRAP(&stream, args.This()); - uint32_t code = args[0]->Uint32Value(context).ToChecked(); + uint32_t code; + if (!args[0]->Uint32Value(context).To(&code)) { + return; + } Debug(stream, "sending rst_stream with code %d", code); stream->SubmitRstStream(code); } @@ -2958,7 +2988,10 @@ void Http2Stream::Respond(const FunctionCallbackInfo& args) { ASSIGN_OR_RETURN_UNWRAP(&stream, args.This()); Local headers = args[0].As(); - int32_t options = args[1]->Int32Value(env->context()).ToChecked(); + int32_t options; + if (!args[1]->Int32Value(env->context()).To(&options)) { + return; + } args.GetReturnValue().Set( stream->SubmitResponse( @@ -3013,7 +3046,10 @@ void Http2Stream::PushPromise(const FunctionCallbackInfo& args) { ASSIGN_OR_RETURN_UNWRAP(&parent, args.This()); Local headers = args[0].As(); - int32_t options = args[1]->Int32Value(env->context()).ToChecked(); + int32_t options; + if (!args[1]->Int32Value(env->context()).To(&options)) { + return; + } Debug(parent, "creating push promise"); @@ -3108,7 +3144,10 @@ void Http2Session::AltSvc(const FunctionCallbackInfo& args) { Http2Session* session; ASSIGN_OR_RETURN_UNWRAP(&session, args.This()); - int32_t id = args[0]->Int32Value(env->context()).ToChecked(); + int32_t id; + if (!args[0]->Int32Value(env->context()).To(&id)) { + return; + } // origin and value are both required to be ASCII, handle them as such. Local origin_str; @@ -3142,9 +3181,12 @@ void Http2Session::Origin(const FunctionCallbackInfo& args) { ASSIGN_OR_RETURN_UNWRAP(&session, args.This()); Local origin_string = args[0].As(); - size_t count = args[1]->Int32Value(context).ToChecked(); + int32_t count; + if (!args[1]->Int32Value(context).To(&count)) { + return; + } - session->Origin(Origins(env, origin_string, count)); + session->Origin(Origins(env, origin_string, static_cast(count))); } // Submits a PING frame to be sent to the connected peer.