@@ -2961,29 +2961,39 @@ void Initialize(Local<Object> target,
29612961 session->GetFunction ()).FromJust ();
29622962
29632963 Local<Object> constants = Object::New (isolate);
2964- NODE_DEFINE_CONSTANT (constants, NGHTTP2_SESSION_SERVER);
2965- NODE_DEFINE_CONSTANT (constants, NGHTTP2_SESSION_CLIENT);
2966- NODE_DEFINE_CONSTANT (constants, NGHTTP2_STREAM_STATE_IDLE);
2967- NODE_DEFINE_CONSTANT (constants, NGHTTP2_STREAM_STATE_OPEN);
2968- NODE_DEFINE_CONSTANT (constants, NGHTTP2_STREAM_STATE_RESERVED_LOCAL);
2969- NODE_DEFINE_CONSTANT (constants, NGHTTP2_STREAM_STATE_RESERVED_REMOTE);
2970- NODE_DEFINE_CONSTANT (constants, NGHTTP2_STREAM_STATE_HALF_CLOSED_LOCAL);
2971- NODE_DEFINE_CONSTANT (constants, NGHTTP2_STREAM_STATE_HALF_CLOSED_REMOTE);
2972- NODE_DEFINE_CONSTANT (constants, NGHTTP2_STREAM_STATE_CLOSED);
2973- NODE_DEFINE_CONSTANT (constants, NGHTTP2_NO_ERROR);
2974- NODE_DEFINE_CONSTANT (constants, NGHTTP2_PROTOCOL_ERROR);
2975- NODE_DEFINE_CONSTANT (constants, NGHTTP2_INTERNAL_ERROR);
2976- NODE_DEFINE_CONSTANT (constants, NGHTTP2_FLOW_CONTROL_ERROR);
2977- NODE_DEFINE_CONSTANT (constants, NGHTTP2_SETTINGS_TIMEOUT);
2978- NODE_DEFINE_CONSTANT (constants, NGHTTP2_STREAM_CLOSED);
2979- NODE_DEFINE_CONSTANT (constants, NGHTTP2_FRAME_SIZE_ERROR);
2980- NODE_DEFINE_CONSTANT (constants, NGHTTP2_REFUSED_STREAM);
2981- NODE_DEFINE_CONSTANT (constants, NGHTTP2_CANCEL);
2982- NODE_DEFINE_CONSTANT (constants, NGHTTP2_COMPRESSION_ERROR);
2983- NODE_DEFINE_CONSTANT (constants, NGHTTP2_CONNECT_ERROR);
2984- NODE_DEFINE_CONSTANT (constants, NGHTTP2_ENHANCE_YOUR_CALM);
2985- NODE_DEFINE_CONSTANT (constants, NGHTTP2_INADEQUATE_SECURITY);
2986- NODE_DEFINE_CONSTANT (constants, NGHTTP2_HTTP_1_1_REQUIRED);
2964+ Local<Array> name_for_error_code = Array::New (isolate);
2965+
2966+ #define NODE_NGHTTP2_ERROR_CODES (V ) \
2967+ V (NGHTTP2_SESSION_SERVER); \
2968+ V (NGHTTP2_SESSION_CLIENT); \
2969+ V (NGHTTP2_STREAM_STATE_IDLE); \
2970+ V (NGHTTP2_STREAM_STATE_OPEN); \
2971+ V (NGHTTP2_STREAM_STATE_RESERVED_LOCAL); \
2972+ V (NGHTTP2_STREAM_STATE_RESERVED_REMOTE); \
2973+ V (NGHTTP2_STREAM_STATE_HALF_CLOSED_LOCAL); \
2974+ V (NGHTTP2_STREAM_STATE_HALF_CLOSED_REMOTE); \
2975+ V (NGHTTP2_STREAM_STATE_CLOSED); \
2976+ V (NGHTTP2_NO_ERROR); \
2977+ V (NGHTTP2_PROTOCOL_ERROR); \
2978+ V (NGHTTP2_INTERNAL_ERROR); \
2979+ V (NGHTTP2_FLOW_CONTROL_ERROR); \
2980+ V (NGHTTP2_SETTINGS_TIMEOUT); \
2981+ V (NGHTTP2_STREAM_CLOSED); \
2982+ V (NGHTTP2_FRAME_SIZE_ERROR); \
2983+ V (NGHTTP2_REFUSED_STREAM); \
2984+ V (NGHTTP2_CANCEL); \
2985+ V (NGHTTP2_COMPRESSION_ERROR); \
2986+ V (NGHTTP2_CONNECT_ERROR); \
2987+ V (NGHTTP2_ENHANCE_YOUR_CALM); \
2988+ V (NGHTTP2_INADEQUATE_SECURITY); \
2989+ V (NGHTTP2_HTTP_1_1_REQUIRED); \
2990+
2991+ #define V (name ) \
2992+ NODE_DEFINE_CONSTANT (constants, name); \
2993+ name_for_error_code->Set (static_cast <int >(name), \
2994+ FIXED_ONE_BYTE_STRING (isolate, #name));
2995+ NODE_NGHTTP2_ERROR_CODES (V)
2996+ #undef V
29872997
29882998 NODE_DEFINE_HIDDEN_CONSTANT (constants, NGHTTP2_HCAT_REQUEST);
29892999 NODE_DEFINE_HIDDEN_CONSTANT (constants, NGHTTP2_HCAT_RESPONSE);
@@ -3048,6 +3058,9 @@ HTTP_STATUS_CODES(V)
30483058 target->Set (context,
30493059 FIXED_ONE_BYTE_STRING (isolate, " constants" ),
30503060 constants).FromJust ();
3061+ target->Set (context,
3062+ FIXED_ONE_BYTE_STRING (isolate, " nameForErrorCode" ),
3063+ name_for_error_code).FromJust ();
30513064}
30523065} // namespace http2
30533066} // namespace node
0 commit comments