@@ -9,6 +9,7 @@ namespace node {
9
9
namespace inspector {
10
10
namespace {
11
11
12
+ using v8::Boolean;
12
13
using v8::Context;
13
14
using v8::Function;
14
15
using v8::FunctionCallbackInfo;
@@ -78,7 +79,11 @@ class JSBindingsConnection : public AsyncWrap {
78
79
79
80
Agent* inspector = env->inspector_agent ();
80
81
if (inspector->delegate () != nullptr ) {
81
- env->ThrowTypeError (" Session is already attached" );
82
+ // This signals JS code that it has to throw an error.
83
+ Local<String> session_attached =
84
+ FIXED_ONE_BYTE_STRING (env->isolate (), " sessionAttached" );
85
+ wrap->Set (env->context (), session_attached,
86
+ Boolean::New (env->isolate (), true )).ToChecked ();
82
87
return ;
83
88
}
84
89
inspector->Connect (&delegate_);
@@ -95,10 +100,7 @@ class JSBindingsConnection : public AsyncWrap {
95
100
96
101
static void New (const FunctionCallbackInfo<Value>& info) {
97
102
Environment* env = Environment::GetCurrent (info);
98
- if (!info[0 ]->IsFunction ()) {
99
- env->ThrowTypeError (" Message callback is required" );
100
- return ;
101
- }
103
+ CHECK (info[0 ]->IsFunction ());
102
104
Local<Function> callback = info[0 ].As <Function>();
103
105
new JSBindingsConnection (env, info.This (), callback);
104
106
}
@@ -121,10 +123,7 @@ class JSBindingsConnection : public AsyncWrap {
121
123
Environment* env = Environment::GetCurrent (info);
122
124
JSBindingsConnection* session;
123
125
ASSIGN_OR_RETURN_UNWRAP (&session, info.Holder ());
124
- if (!info[0 ]->IsString ()) {
125
- env->ThrowTypeError (" Inspector message must be a string" );
126
- return ;
127
- }
126
+ CHECK (info[0 ]->IsString ());
128
127
129
128
session->CheckIsCurrent ();
130
129
Agent* inspector = env->inspector_agent ();
@@ -143,10 +142,9 @@ void AddCommandLineAPI(const FunctionCallbackInfo<Value>& info) {
143
142
auto env = Environment::GetCurrent (info);
144
143
Local<Context> context = env->context ();
145
144
146
- if (info.Length () != 2 || !info[0 ]->IsString ()) {
147
- return env->ThrowTypeError (" inspector.addCommandLineAPI takes "
148
- " exactly 2 arguments: a string and a value." );
149
- }
145
+ // inspector.addCommandLineAPI takes 2 arguments: a string and a value.
146
+ CHECK_EQ (info.Length (), 2 );
147
+ CHECK (info[0 ]->IsString ());
150
148
151
149
Local<Object> console_api = env->inspector_console_api_object ();
152
150
console_api->Set (context, info[0 ], info[1 ]).FromJust ();
0 commit comments