Skip to content

src: use custom TryCatch subclass #24751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/async_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ using v8::WeakCallbackInfo;
using v8::WeakCallbackType;

using AsyncHooks = node::Environment::AsyncHooks;
using TryCatchScope = node::errors::TryCatchScope;

namespace node {

Expand Down Expand Up @@ -91,7 +92,7 @@ struct AsyncWrapObject : public AsyncWrap {
static void DestroyAsyncIdsCallback(Environment* env, void* data) {
Local<Function> fn = env->async_hooks_destroy_function();

FatalTryCatch try_catch(env);
TryCatchScope try_catch(env, TryCatchScope::CatchMode::kFatal);

do {
std::vector<double> destroy_async_id_list;
Expand Down Expand Up @@ -127,7 +128,7 @@ void Emit(Environment* env, double async_id, AsyncHooks::Fields type,

HandleScope handle_scope(env->isolate());
Local<Value> async_id_value = Number::New(env->isolate(), async_id);
FatalTryCatch try_catch(env);
TryCatchScope try_catch(env, TryCatchScope::CatchMode::kFatal);
USE(fn->Call(env->context(), Undefined(env->isolate()), 1, &async_id_value));
}

Expand Down Expand Up @@ -673,7 +674,7 @@ void AsyncWrap::EmitAsyncInit(Environment* env,
object,
};

FatalTryCatch try_catch(env);
TryCatchScope try_catch(env, TryCatchScope::CatchMode::kFatal);
USE(init_fn->Call(env->context(), object, arraysize(argv), argv));
}

Expand Down Expand Up @@ -776,7 +777,7 @@ Local<Object> AsyncWrap::GetOwner(Environment* env, Local<Object> obj) {
EscapableHandleScope handle_scope(env->isolate());
CHECK(!obj.IsEmpty());

TryCatch ignore_exceptions(env->isolate());
TryCatchScope ignore_exceptions(env);
while (true) {
Local<Value> owner;
if (!obj->Get(env->context(),
Expand Down
9 changes: 5 additions & 4 deletions src/env.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "async_wrap.h"
#include "node_buffer.h"
#include "node_context_data.h"
#include "node_errors.h"
#include "node_file.h"
#include "node_internals.h"
#include "node_native_module.h"
Expand All @@ -15,6 +16,7 @@

namespace node {

using errors::TryCatchScope;
using v8::Context;
using v8::EmbedderGraph;
using v8::External;
Expand All @@ -36,7 +38,6 @@ using v8::StackTrace;
using v8::String;
using v8::Symbol;
using v8::TracingController;
using v8::TryCatch;
using v8::Undefined;
using v8::Value;
using worker::Worker;
Expand Down Expand Up @@ -156,7 +157,7 @@ void Environment::TrackingTraceStateObserver::UpdateTraceCategoryState() {
Local<Function> cb = env_->trace_category_state_function();
if (cb.IsEmpty())
return;
TryCatch try_catch(isolate);
TryCatchScope try_catch(env_);
try_catch.SetVerbose(true);
cb->Call(env_->context(), Undefined(isolate),
0, nullptr).ToLocalChecked();
Expand Down Expand Up @@ -577,7 +578,7 @@ void Environment::RunAndClearNativeImmediates() {
std::vector<NativeImmediateCallback> list;
native_immediate_callbacks_.swap(list);
auto drain_list = [&]() {
TryCatch try_catch(isolate());
TryCatchScope try_catch(this);
for (auto it = list.begin(); it != list.end(); ++it) {
#ifdef DEBUG
v8::SealHandleScope seal_handle_scope(isolate());
Expand Down Expand Up @@ -642,7 +643,7 @@ void Environment::RunTimers(uv_timer_t* handle) {
// impossible for us to end up in an infinite loop due to how the JS-side
// is structured.
do {
TryCatch try_catch(env->isolate());
TryCatchScope try_catch(env);
try_catch.SetVerbose(true);
ret = cb->Call(env->context(), process, 1, &arg);
} while (ret.IsEmpty() && env->can_call_into_js());
Expand Down
14 changes: 8 additions & 6 deletions src/js_stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
#include "async_wrap.h"
#include "env-inl.h"
#include "node_buffer.h"
#include "node_errors.h"
#include "node_internals.h"
#include "stream_base-inl.h"
#include "v8.h"

namespace node {

using errors::TryCatchScope;

using v8::Array;
using v8::Context;
using v8::FunctionCallbackInfo;
Expand All @@ -18,7 +21,6 @@ using v8::Int32;
using v8::Local;
using v8::Object;
using v8::String;
using v8::TryCatch;
using v8::Value;


Expand All @@ -42,7 +44,7 @@ bool JSStream::IsAlive() {
bool JSStream::IsClosing() {
HandleScope scope(env()->isolate());
Context::Scope context_scope(env()->context());
TryCatch try_catch(env()->isolate());
TryCatchScope try_catch(env());
Local<Value> value;
if (!MakeCallback(env()->isclosing_string(), 0, nullptr).ToLocal(&value)) {
if (!try_catch.HasTerminated())
Expand All @@ -56,7 +58,7 @@ bool JSStream::IsClosing() {
int JSStream::ReadStart() {
HandleScope scope(env()->isolate());
Context::Scope context_scope(env()->context());
TryCatch try_catch(env()->isolate());
TryCatchScope try_catch(env());
Local<Value> value;
int value_int = UV_EPROTO;
if (!MakeCallback(env()->onreadstart_string(), 0, nullptr).ToLocal(&value) ||
Expand All @@ -71,7 +73,7 @@ int JSStream::ReadStart() {
int JSStream::ReadStop() {
HandleScope scope(env()->isolate());
Context::Scope context_scope(env()->context());
TryCatch try_catch(env()->isolate());
TryCatchScope try_catch(env());
Local<Value> value;
int value_int = UV_EPROTO;
if (!MakeCallback(env()->onreadstop_string(), 0, nullptr).ToLocal(&value) ||
Expand All @@ -91,7 +93,7 @@ int JSStream::DoShutdown(ShutdownWrap* req_wrap) {
req_wrap->object()
};

TryCatch try_catch(env()->isolate());
TryCatchScope try_catch(env());
Local<Value> value;
int value_int = UV_EPROTO;
if (!MakeCallback(env()->onshutdown_string(),
Expand Down Expand Up @@ -126,7 +128,7 @@ int JSStream::DoWrite(WriteWrap* w,
bufs_arr
};

TryCatch try_catch(env()->isolate());
TryCatchScope try_catch(env());
Local<Value> value;
int value_int = UV_EPROTO;
if (!MakeCallback(env()->onwrite_string(),
Expand Down
9 changes: 5 additions & 4 deletions src/module_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
namespace node {
namespace loader {

using errors::TryCatchScope;

using node::contextify::ContextifyContext;
using node::url::URL;
using node::url::URL_FLAGS_FAILED;
Expand All @@ -40,7 +42,6 @@ using v8::Promise;
using v8::ScriptCompiler;
using v8::ScriptOrigin;
using v8::String;
using v8::TryCatch;
using v8::Undefined;
using v8::Value;

Expand Down Expand Up @@ -135,7 +136,7 @@ void ModuleWrap::New(const FunctionCallbackInfo<Value>& args) {
}

Environment::ShouldNotAbortOnUncaughtScope no_abort_scope(env);
TryCatch try_catch(isolate);
TryCatchScope try_catch(env);
Local<Module> module;

Local<PrimitiveArray> host_defined_options =
Expand Down Expand Up @@ -244,7 +245,7 @@ void ModuleWrap::Instantiate(const FunctionCallbackInfo<Value>& args) {
ASSIGN_OR_RETURN_UNWRAP(&obj, args.This());
Local<Context> context = obj->context_.Get(isolate);
Local<Module> module = obj->module_.Get(isolate);
TryCatch try_catch(isolate);
TryCatchScope try_catch(env);
Maybe<bool> ok = module->InstantiateModule(context, ResolveCallback);

// clear resolve cache on instantiate
Expand Down Expand Up @@ -279,7 +280,7 @@ void ModuleWrap::Evaluate(const FunctionCallbackInfo<Value>& args) {
bool break_on_sigint = args[1]->IsTrue();

Environment::ShouldNotAbortOnUncaughtScope no_abort_scope(env);
TryCatch try_catch(isolate);
TryCatchScope try_catch(env);

bool timed_out = false;
bool received_signal = false;
Expand Down
8 changes: 4 additions & 4 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ typedef int mode_t;

namespace node {

using errors::TryCatchScope;
using native_module::NativeModuleLoader;
using options_parser::kAllowedInEnvironment;
using options_parser::kDisallowedInEnvironment;
Expand Down Expand Up @@ -154,7 +155,6 @@ using v8::SealHandleScope;
using v8::SideEffectType;
using v8::String;
using v8::TracingController;
using v8::TryCatch;
using v8::Undefined;
using v8::V8;
using v8::Value;
Expand Down Expand Up @@ -746,7 +746,7 @@ static MaybeLocal<Value> ExecuteString(Environment* env,
Local<String> source,
Local<String> filename) {
EscapableHandleScope scope(env->isolate());
TryCatch try_catch(env->isolate());
TryCatchScope try_catch(env);

// try_catch must be nonverbose to disable FatalException() handler,
// we will handle exceptions ourself.
Expand Down Expand Up @@ -1341,7 +1341,7 @@ static MaybeLocal<Function> GetBootstrapper(
Local<String> script_name) {
EscapableHandleScope scope(env->isolate());

TryCatch try_catch(env->isolate());
TryCatchScope try_catch(env);

// Disable verbose mode to stop FatalException() handler from trying
// to handle the exception. Errors this early in the start-up phase
Expand Down Expand Up @@ -1386,7 +1386,7 @@ static bool ExecuteBootstrapper(Environment* env, Local<Function> bootstrapper,
void LoadEnvironment(Environment* env) {
HandleScope handle_scope(env->isolate());

TryCatch try_catch(env->isolate());
TryCatchScope try_catch(env);
// Disable verbose mode to stop FatalException() handler from trying
// to handle the exception. Errors this early in the start-up phase
// are not safe to ignore.
Expand Down
11 changes: 6 additions & 5 deletions src/node_contextify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
namespace node {
namespace contextify {

using errors::TryCatchScope;

using v8::Array;
using v8::ArrayBuffer;
using v8::ArrayBufferView;
Expand Down Expand Up @@ -63,7 +65,6 @@ using v8::ScriptCompiler;
using v8::ScriptOrigin;
using v8::String;
using v8::Symbol;
using v8::TryCatch;
using v8::Uint32;
using v8::UnboundScript;
using v8::Value;
Expand Down Expand Up @@ -245,7 +246,7 @@ void ContextifyContext::MakeContext(const FunctionCallbackInfo<Value>& args) {
CHECK(args[4]->IsBoolean());
options.allow_code_gen_wasm = args[4].As<Boolean>();

TryCatch try_catch(env->isolate());
TryCatchScope try_catch(env);
ContextifyContext* context = new ContextifyContext(env, sandbox, options);

if (try_catch.HasCaught()) {
Expand Down Expand Up @@ -705,7 +706,7 @@ void ContextifyScript::New(const FunctionCallbackInfo<Value>& args) {
if (source.GetCachedData() != nullptr)
compile_options = ScriptCompiler::kConsumeCodeCache;

TryCatch try_catch(isolate);
TryCatchScope try_catch(env);
Environment::ShouldNotAbortOnUncaughtScope no_abort_scope(env);
Context::Scope scope(parsing_context);

Expand Down Expand Up @@ -863,7 +864,7 @@ bool ContextifyScript::EvalMachine(Environment* env,
"Script methods can only be called on script instances.");
return false;
}
TryCatch try_catch(env->isolate());
TryCatchScope try_catch(env);
ContextifyScript* wrapped_script;
ASSIGN_OR_RETURN_UNWRAP(&wrapped_script, args.Holder(), false);
Local<UnboundScript> unbound_script =
Expand Down Expand Up @@ -1012,7 +1013,7 @@ void ContextifyContext::CompileFunction(
options = ScriptCompiler::kConsumeCodeCache;
}

TryCatch try_catch(isolate);
TryCatchScope try_catch(env);
Context::Scope scope(parsing_context);

// Read context extensions from buffer
Expand Down
5 changes: 3 additions & 2 deletions src/node_contextify.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

#include "node_internals.h"
#include "node_context_data.h"
#include "base_object-inl.h"
#include "node_context_data.h"
#include "node_errors.h"
#include "node_internals.h"

namespace node {
namespace contextify {
Expand Down
Loading