@@ -426,8 +426,13 @@ Http2Priority::Http2Priority(Environment* env,
426
426
Local<Value> weight,
427
427
Local<Value> exclusive) {
428
428
Local<Context> context = env->context ();
429
- int32_t parent_ = parent->Int32Value (context).ToChecked ();
430
- int32_t weight_ = weight->Int32Value (context).ToChecked ();
429
+ int32_t parent_;
430
+ int32_t weight_;
431
+ if (!parent->Int32Value (context).To (&parent_) ||
432
+ !weight->Int32Value (context).To (&weight_)) {
433
+ nghttp2_priority_spec_init (this , 0 , 0 , 0 );
434
+ return ;
435
+ }
431
436
bool exclusive_ = exclusive->IsTrue ();
432
437
Debug (env, DebugCategory::HTTP2STREAM,
433
438
" Http2Priority: parent: %d, weight: %d, exclusive: %s\n " ,
@@ -2715,11 +2720,12 @@ void Http2Stream::DecrementAvailableOutboundLength(size_t amount) {
2715
2720
// back to JS land
2716
2721
void HttpErrorString (const FunctionCallbackInfo<Value>& args) {
2717
2722
Environment* env = Environment::GetCurrent (args);
2718
- uint32_t val = args[0 ]->Uint32Value (env->context ()).ToChecked ();
2719
- args.GetReturnValue ().Set (
2720
- OneByteString (
2721
- env->isolate (),
2722
- reinterpret_cast <const uint8_t *>(nghttp2_strerror (val))));
2723
+ uint32_t val;
2724
+ if (args[0 ]->Uint32Value (env->context ()).To (&val)) {
2725
+ args.GetReturnValue ().Set (
2726
+ OneByteString (env->isolate (),
2727
+ reinterpret_cast <const uint8_t *>(nghttp2_strerror (val))));
2728
+ }
2723
2729
}
2724
2730
2725
2731
@@ -2744,7 +2750,10 @@ void Http2Session::SetNextStreamID(const FunctionCallbackInfo<Value>& args) {
2744
2750
Environment* env = Environment::GetCurrent (args);
2745
2751
Http2Session* session;
2746
2752
ASSIGN_OR_RETURN_UNWRAP (&session, args.This ());
2747
- int32_t id = args[0 ]->Int32Value (env->context ()).ToChecked ();
2753
+ int32_t id;
2754
+ if (!args[0 ]->Int32Value (env->context ()).To (&id)) {
2755
+ return ;
2756
+ }
2748
2757
if (nghttp2_session_set_next_stream_id (session->session (), id) < 0 ) {
2749
2758
Debug (session, " failed to set next stream id to %d" , id);
2750
2759
return args.GetReturnValue ().Set (false );
@@ -2762,7 +2771,10 @@ void Http2Session::SetLocalWindowSize(
2762
2771
Http2Session* session;
2763
2772
ASSIGN_OR_RETURN_UNWRAP (&session, args.This ());
2764
2773
2765
- int32_t window_size = args[0 ]->Int32Value (env->context ()).ToChecked ();
2774
+ int32_t window_size;
2775
+ if (!args[0 ]->Int32Value (env->context ()).To (&window_size)) {
2776
+ return ;
2777
+ }
2766
2778
2767
2779
int result = nghttp2_session_set_local_window_size (
2768
2780
session->session (), NGHTTP2_FLAG_NONE, 0 , window_size);
@@ -2822,8 +2834,11 @@ void Http2Session::New(const FunctionCallbackInfo<Value>& args) {
2822
2834
Http2State* state = realm->GetBindingData <Http2State>();
2823
2835
2824
2836
CHECK (args.IsConstructCall ());
2825
- SessionType type = static_cast <SessionType>(
2826
- args[0 ]->Int32Value (realm->context ()).ToChecked ());
2837
+ int32_t val;
2838
+ if (!args[0 ]->Int32Value (realm->context ()).To (&val)) {
2839
+ return ;
2840
+ }
2841
+ SessionType type = static_cast <SessionType>(val);
2827
2842
Http2Session* session = new Http2Session (state, args.This (), type);
2828
2843
Debug (session, " session created" );
2829
2844
}
@@ -2845,7 +2860,10 @@ void Http2Session::Destroy(const FunctionCallbackInfo<Value>& args) {
2845
2860
Environment* env = Environment::GetCurrent (args);
2846
2861
Local<Context> context = env->context ();
2847
2862
2848
- uint32_t code = args[0 ]->Uint32Value (context).ToChecked ();
2863
+ uint32_t code;
2864
+ if (!args[0 ]->Uint32Value (context).To (&code)) {
2865
+ return ;
2866
+ }
2849
2867
session->Close (code, args[1 ]->IsTrue ());
2850
2868
}
2851
2869
@@ -2857,7 +2875,10 @@ void Http2Session::Request(const FunctionCallbackInfo<Value>& args) {
2857
2875
Environment* env = session->env ();
2858
2876
2859
2877
Local<Array> headers = args[0 ].As <Array>();
2860
- int32_t options = args[1 ]->Int32Value (env->context ()).ToChecked ();
2878
+ int32_t options;
2879
+ if (!args[1 ]->Int32Value (env->context ()).To (&options)) {
2880
+ return ;
2881
+ }
2861
2882
2862
2883
Debug (session, " request submitted" );
2863
2884
@@ -2906,8 +2927,14 @@ void Http2Session::Goaway(const FunctionCallbackInfo<Value>& args) {
2906
2927
Http2Session* session;
2907
2928
ASSIGN_OR_RETURN_UNWRAP (&session, args.This ());
2908
2929
2909
- uint32_t code = args[0 ]->Uint32Value (context).ToChecked ();
2910
- int32_t lastStreamID = args[1 ]->Int32Value (context).ToChecked ();
2930
+ uint32_t code;
2931
+ if (!args[0 ]->Uint32Value (context).To (&code)) {
2932
+ return ;
2933
+ }
2934
+ int32_t lastStreamID;
2935
+ if (!args[1 ]->Int32Value (context).To (&lastStreamID)) {
2936
+ return ;
2937
+ }
2911
2938
ArrayBufferViewContents<uint8_t > opaque_data;
2912
2939
2913
2940
if (args[2 ]->IsArrayBufferView ()) {
@@ -2945,7 +2972,10 @@ void Http2Stream::RstStream(const FunctionCallbackInfo<Value>& args) {
2945
2972
Local<Context> context = env->context ();
2946
2973
Http2Stream* stream;
2947
2974
ASSIGN_OR_RETURN_UNWRAP (&stream, args.This ());
2948
- uint32_t code = args[0 ]->Uint32Value (context).ToChecked ();
2975
+ uint32_t code;
2976
+ if (!args[0 ]->Uint32Value (context).To (&code)) {
2977
+ return ;
2978
+ }
2949
2979
Debug (stream, " sending rst_stream with code %d" , code);
2950
2980
stream->SubmitRstStream (code);
2951
2981
}
@@ -2958,7 +2988,10 @@ void Http2Stream::Respond(const FunctionCallbackInfo<Value>& args) {
2958
2988
ASSIGN_OR_RETURN_UNWRAP (&stream, args.This ());
2959
2989
2960
2990
Local<Array> headers = args[0 ].As <Array>();
2961
- int32_t options = args[1 ]->Int32Value (env->context ()).ToChecked ();
2991
+ int32_t options;
2992
+ if (!args[1 ]->Int32Value (env->context ()).To (&options)) {
2993
+ return ;
2994
+ }
2962
2995
2963
2996
args.GetReturnValue ().Set (
2964
2997
stream->SubmitResponse (
@@ -3013,7 +3046,10 @@ void Http2Stream::PushPromise(const FunctionCallbackInfo<Value>& args) {
3013
3046
ASSIGN_OR_RETURN_UNWRAP (&parent, args.This ());
3014
3047
3015
3048
Local<Array> headers = args[0 ].As <Array>();
3016
- int32_t options = args[1 ]->Int32Value (env->context ()).ToChecked ();
3049
+ int32_t options;
3050
+ if (!args[1 ]->Int32Value (env->context ()).To (&options)) {
3051
+ return ;
3052
+ }
3017
3053
3018
3054
Debug (parent, " creating push promise" );
3019
3055
@@ -3108,7 +3144,10 @@ void Http2Session::AltSvc(const FunctionCallbackInfo<Value>& args) {
3108
3144
Http2Session* session;
3109
3145
ASSIGN_OR_RETURN_UNWRAP (&session, args.This ());
3110
3146
3111
- int32_t id = args[0 ]->Int32Value (env->context ()).ToChecked ();
3147
+ int32_t id;
3148
+ if (!args[0 ]->Int32Value (env->context ()).To (&id)) {
3149
+ return ;
3150
+ }
3112
3151
3113
3152
// origin and value are both required to be ASCII, handle them as such.
3114
3153
Local<String> origin_str;
@@ -3142,9 +3181,12 @@ void Http2Session::Origin(const FunctionCallbackInfo<Value>& args) {
3142
3181
ASSIGN_OR_RETURN_UNWRAP (&session, args.This ());
3143
3182
3144
3183
Local<String> origin_string = args[0 ].As <String>();
3145
- size_t count = args[1 ]->Int32Value (context).ToChecked ();
3184
+ int32_t count;
3185
+ if (!args[1 ]->Int32Value (context).To (&count)) {
3186
+ return ;
3187
+ }
3146
3188
3147
- session->Origin (Origins (env, origin_string, count));
3189
+ session->Origin (Origins (env, origin_string, static_cast < size_t >( count) ));
3148
3190
}
3149
3191
3150
3192
// Submits a PING frame to be sent to the connected peer.
0 commit comments