@@ -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 " ,
@@ -2719,11 +2724,12 @@ void Http2Stream::DecrementAvailableOutboundLength(size_t amount) {
2719
2724
// back to JS land
2720
2725
void HttpErrorString (const FunctionCallbackInfo<Value>& args) {
2721
2726
Environment* env = Environment::GetCurrent (args);
2722
- uint32_t val = args[0 ]->Uint32Value (env->context ()).ToChecked ();
2723
- args.GetReturnValue ().Set (
2724
- OneByteString (
2725
- env->isolate (),
2726
- reinterpret_cast <const uint8_t *>(nghttp2_strerror (val))));
2727
+ uint32_t val;
2728
+ if (args[0 ]->Uint32Value (env->context ()).To (&val)) {
2729
+ args.GetReturnValue ().Set (
2730
+ OneByteString (env->isolate (),
2731
+ reinterpret_cast <const uint8_t *>(nghttp2_strerror (val))));
2732
+ }
2727
2733
}
2728
2734
2729
2735
@@ -2748,7 +2754,10 @@ void Http2Session::SetNextStreamID(const FunctionCallbackInfo<Value>& args) {
2748
2754
Environment* env = Environment::GetCurrent (args);
2749
2755
Http2Session* session;
2750
2756
ASSIGN_OR_RETURN_UNWRAP (&session, args.This ());
2751
- int32_t id = args[0 ]->Int32Value (env->context ()).ToChecked ();
2757
+ int32_t id;
2758
+ if (!args[0 ]->Int32Value (env->context ()).To (&id)) {
2759
+ return ;
2760
+ }
2752
2761
if (nghttp2_session_set_next_stream_id (session->session (), id) < 0 ) {
2753
2762
Debug (session, " failed to set next stream id to %d" , id);
2754
2763
return args.GetReturnValue ().Set (false );
@@ -2766,7 +2775,10 @@ void Http2Session::SetLocalWindowSize(
2766
2775
Http2Session* session;
2767
2776
ASSIGN_OR_RETURN_UNWRAP (&session, args.This ());
2768
2777
2769
- int32_t window_size = args[0 ]->Int32Value (env->context ()).ToChecked ();
2778
+ int32_t window_size;
2779
+ if (!args[0 ]->Int32Value (env->context ()).To (&window_size)) {
2780
+ return ;
2781
+ }
2770
2782
2771
2783
int result = nghttp2_session_set_local_window_size (
2772
2784
session->session (), NGHTTP2_FLAG_NONE, 0 , window_size);
@@ -2826,8 +2838,11 @@ void Http2Session::New(const FunctionCallbackInfo<Value>& args) {
2826
2838
Http2State* state = realm->GetBindingData <Http2State>();
2827
2839
2828
2840
CHECK (args.IsConstructCall ());
2829
- SessionType type = static_cast <SessionType>(
2830
- args[0 ]->Int32Value (realm->context ()).ToChecked ());
2841
+ int32_t val;
2842
+ if (!args[0 ]->Int32Value (realm->context ()).To (&val)) {
2843
+ return ;
2844
+ }
2845
+ SessionType type = static_cast <SessionType>(val);
2831
2846
Http2Session* session = new Http2Session (state, args.This (), type);
2832
2847
Debug (session, " session created" );
2833
2848
}
@@ -2849,7 +2864,10 @@ void Http2Session::Destroy(const FunctionCallbackInfo<Value>& args) {
2849
2864
Environment* env = Environment::GetCurrent (args);
2850
2865
Local<Context> context = env->context ();
2851
2866
2852
- uint32_t code = args[0 ]->Uint32Value (context).ToChecked ();
2867
+ uint32_t code;
2868
+ if (!args[0 ]->Uint32Value (context).To (&code)) {
2869
+ return ;
2870
+ }
2853
2871
session->Close (code, args[1 ]->IsTrue ());
2854
2872
}
2855
2873
@@ -2861,7 +2879,10 @@ void Http2Session::Request(const FunctionCallbackInfo<Value>& args) {
2861
2879
Environment* env = session->env ();
2862
2880
2863
2881
Local<Array> headers = args[0 ].As <Array>();
2864
- int32_t options = args[1 ]->Int32Value (env->context ()).ToChecked ();
2882
+ int32_t options;
2883
+ if (!args[1 ]->Int32Value (env->context ()).To (&options)) {
2884
+ return ;
2885
+ }
2865
2886
2866
2887
Debug (session, " request submitted" );
2867
2888
@@ -2910,8 +2931,14 @@ void Http2Session::Goaway(const FunctionCallbackInfo<Value>& args) {
2910
2931
Http2Session* session;
2911
2932
ASSIGN_OR_RETURN_UNWRAP (&session, args.This ());
2912
2933
2913
- uint32_t code = args[0 ]->Uint32Value (context).ToChecked ();
2914
- int32_t lastStreamID = args[1 ]->Int32Value (context).ToChecked ();
2934
+ uint32_t code;
2935
+ if (!args[0 ]->Uint32Value (context).To (&code)) {
2936
+ return ;
2937
+ }
2938
+ int32_t lastStreamID;
2939
+ if (!args[1 ]->Int32Value (context).To (&lastStreamID)) {
2940
+ return ;
2941
+ }
2915
2942
ArrayBufferViewContents<uint8_t > opaque_data;
2916
2943
2917
2944
if (args[2 ]->IsArrayBufferView ()) {
@@ -2947,7 +2974,10 @@ void Http2Stream::RstStream(const FunctionCallbackInfo<Value>& args) {
2947
2974
Local<Context> context = env->context ();
2948
2975
Http2Stream* stream;
2949
2976
ASSIGN_OR_RETURN_UNWRAP (&stream, args.This ());
2950
- uint32_t code = args[0 ]->Uint32Value (context).ToChecked ();
2977
+ uint32_t code;
2978
+ if (!args[0 ]->Uint32Value (context).To (&code)) {
2979
+ return ;
2980
+ }
2951
2981
Debug (stream, " sending rst_stream with code %d" , code);
2952
2982
stream->SubmitRstStream (code);
2953
2983
}
@@ -2960,7 +2990,10 @@ void Http2Stream::Respond(const FunctionCallbackInfo<Value>& args) {
2960
2990
ASSIGN_OR_RETURN_UNWRAP (&stream, args.This ());
2961
2991
2962
2992
Local<Array> headers = args[0 ].As <Array>();
2963
- int32_t options = args[1 ]->Int32Value (env->context ()).ToChecked ();
2993
+ int32_t options;
2994
+ if (!args[1 ]->Int32Value (env->context ()).To (&options)) {
2995
+ return ;
2996
+ }
2964
2997
2965
2998
args.GetReturnValue ().Set (
2966
2999
stream->SubmitResponse (
@@ -3015,7 +3048,10 @@ void Http2Stream::PushPromise(const FunctionCallbackInfo<Value>& args) {
3015
3048
ASSIGN_OR_RETURN_UNWRAP (&parent, args.This ());
3016
3049
3017
3050
Local<Array> headers = args[0 ].As <Array>();
3018
- int32_t options = args[1 ]->Int32Value (env->context ()).ToChecked ();
3051
+ int32_t options;
3052
+ if (!args[1 ]->Int32Value (env->context ()).To (&options)) {
3053
+ return ;
3054
+ }
3019
3055
3020
3056
Debug (parent, " creating push promise" );
3021
3057
@@ -3110,7 +3146,10 @@ void Http2Session::AltSvc(const FunctionCallbackInfo<Value>& args) {
3110
3146
Http2Session* session;
3111
3147
ASSIGN_OR_RETURN_UNWRAP (&session, args.This ());
3112
3148
3113
- int32_t id = args[0 ]->Int32Value (env->context ()).ToChecked ();
3149
+ int32_t id;
3150
+ if (!args[0 ]->Int32Value (env->context ()).To (&id)) {
3151
+ return ;
3152
+ }
3114
3153
3115
3154
// origin and value are both required to be ASCII, handle them as such.
3116
3155
Local<String> origin_str = args[1 ]->ToString (env->context ()).ToLocalChecked ();
@@ -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