summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichaël Zasso <targos@protonmail.com>2018-03-16 09:17:58 +0100
committerMichaël Zasso <targos@protonmail.com>2018-03-22 08:24:31 +0100
commit4e1f0907dae9916215985a9f81bf3dec1eeaeaef (patch)
tree32f5784431d3052ec769a3e24cb82d0b59809a81 /src
parent258bcb9bffb1824d65a76eb30fcd0adda0f753a0 (diff)
downloadandroid-node-v8-4e1f0907dae9916215985a9f81bf3dec1eeaeaef.tar.gz
android-node-v8-4e1f0907dae9916215985a9f81bf3dec1eeaeaef.tar.bz2
android-node-v8-4e1f0907dae9916215985a9f81bf3dec1eeaeaef.zip
inspector: migrate errors from C++ to JS
Assign a code to a user-facing error. Turn other internal-only errors to checks. PR-URL: https://github.com/nodejs/node/pull/19387 Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'src')
-rw-r--r--src/inspector_js_api.cc24
1 files changed, 11 insertions, 13 deletions
diff --git a/src/inspector_js_api.cc b/src/inspector_js_api.cc
index 1cced9420a..ac6d6ba738 100644
--- a/src/inspector_js_api.cc
+++ b/src/inspector_js_api.cc
@@ -9,6 +9,7 @@ namespace node {
namespace inspector {
namespace {
+using v8::Boolean;
using v8::Context;
using v8::Function;
using v8::FunctionCallbackInfo;
@@ -78,7 +79,11 @@ class JSBindingsConnection : public AsyncWrap {
Agent* inspector = env->inspector_agent();
if (inspector->delegate() != nullptr) {
- env->ThrowTypeError("Session is already attached");
+ // This signals JS code that it has to throw an error.
+ Local<String> session_attached =
+ FIXED_ONE_BYTE_STRING(env->isolate(), "sessionAttached");
+ wrap->Set(env->context(), session_attached,
+ Boolean::New(env->isolate(), true)).ToChecked();
return;
}
inspector->Connect(&delegate_);
@@ -95,10 +100,7 @@ class JSBindingsConnection : public AsyncWrap {
static void New(const FunctionCallbackInfo<Value>& info) {
Environment* env = Environment::GetCurrent(info);
- if (!info[0]->IsFunction()) {
- env->ThrowTypeError("Message callback is required");
- return;
- }
+ CHECK(info[0]->IsFunction());
Local<Function> callback = info[0].As<Function>();
new JSBindingsConnection(env, info.This(), callback);
}
@@ -121,10 +123,7 @@ class JSBindingsConnection : public AsyncWrap {
Environment* env = Environment::GetCurrent(info);
JSBindingsConnection* session;
ASSIGN_OR_RETURN_UNWRAP(&session, info.Holder());
- if (!info[0]->IsString()) {
- env->ThrowTypeError("Inspector message must be a string");
- return;
- }
+ CHECK(info[0]->IsString());
session->CheckIsCurrent();
Agent* inspector = env->inspector_agent();
@@ -143,10 +142,9 @@ void AddCommandLineAPI(const FunctionCallbackInfo<Value>& info) {
auto env = Environment::GetCurrent(info);
Local<Context> context = env->context();
- if (info.Length() != 2 || !info[0]->IsString()) {
- return env->ThrowTypeError("inspector.addCommandLineAPI takes "
- "exactly 2 arguments: a string and a value.");
- }
+ // inspector.addCommandLineAPI takes 2 arguments: a string and a value.
+ CHECK_EQ(info.Length(), 2);
+ CHECK(info[0]->IsString());
Local<Object> console_api = env->inspector_console_api_object();
console_api->Set(context, info[0], info[1]).FromJust();