bootstrap: mksnapshot should show JS error
PR-URL: https://github.com/nodejs/node/pull/38174 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
7b2bad4005
commit
8d9d8236b7
@ -15,8 +15,12 @@ using v8::Context;
|
|||||||
using v8::HandleScope;
|
using v8::HandleScope;
|
||||||
using v8::Isolate;
|
using v8::Isolate;
|
||||||
using v8::Local;
|
using v8::Local;
|
||||||
|
using v8::Object;
|
||||||
using v8::SnapshotCreator;
|
using v8::SnapshotCreator;
|
||||||
using v8::StartupData;
|
using v8::StartupData;
|
||||||
|
using v8::String;
|
||||||
|
using v8::TryCatch;
|
||||||
|
using v8::Value;
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void WriteVector(std::stringstream* ss, const T* vec, size_t size) {
|
void WriteVector(std::stringstream* ss, const T* vec, size_t size) {
|
||||||
@ -79,6 +83,10 @@ std::string SnapshotBuilder::Generate(
|
|||||||
const std::vector<std::string> args,
|
const std::vector<std::string> args,
|
||||||
const std::vector<std::string> exec_args) {
|
const std::vector<std::string> exec_args) {
|
||||||
Isolate* isolate = Isolate::Allocate();
|
Isolate* isolate = Isolate::Allocate();
|
||||||
|
isolate->SetCaptureStackTraceForUncaughtExceptions(
|
||||||
|
true,
|
||||||
|
10,
|
||||||
|
v8::StackTrace::StackTraceOptions::kDetailed);
|
||||||
per_process::v8_platform.Platform()->RegisterIsolate(isolate,
|
per_process::v8_platform.Platform()->RegisterIsolate(isolate,
|
||||||
uv_default_loop());
|
uv_default_loop());
|
||||||
std::unique_ptr<NodeMainInstance> main_instance;
|
std::unique_ptr<NodeMainInstance> main_instance;
|
||||||
@ -104,7 +112,40 @@ std::string SnapshotBuilder::Generate(
|
|||||||
creator.SetDefaultContext(Context::New(isolate));
|
creator.SetDefaultContext(Context::New(isolate));
|
||||||
isolate_data_indexes = main_instance->isolate_data()->Serialize(&creator);
|
isolate_data_indexes = main_instance->isolate_data()->Serialize(&creator);
|
||||||
|
|
||||||
|
TryCatch bootstrapCatch(isolate);
|
||||||
Local<Context> context = NewContext(isolate);
|
Local<Context> context = NewContext(isolate);
|
||||||
|
if (bootstrapCatch.HasCaught()) {
|
||||||
|
Local<Object> obj = bootstrapCatch.Exception()->ToObject(context)
|
||||||
|
.ToLocalChecked();
|
||||||
|
Local<Value> stack = obj->Get(
|
||||||
|
context,
|
||||||
|
FIXED_ONE_BYTE_STRING(isolate, "stack")).ToLocalChecked();
|
||||||
|
if (stack->IsUndefined()) {
|
||||||
|
Local<String> str = obj->Get(
|
||||||
|
context,
|
||||||
|
FIXED_ONE_BYTE_STRING(isolate, "name"))
|
||||||
|
.ToLocalChecked()->ToString(context).ToLocalChecked();
|
||||||
|
str = String::Concat(
|
||||||
|
isolate,
|
||||||
|
str,
|
||||||
|
FIXED_ONE_BYTE_STRING(isolate, ": "));
|
||||||
|
stack = String::Concat(
|
||||||
|
isolate,
|
||||||
|
str,
|
||||||
|
obj->Get(
|
||||||
|
context,
|
||||||
|
FIXED_ONE_BYTE_STRING(isolate, "message"))
|
||||||
|
.ToLocalChecked()->ToString(context).ToLocalChecked());
|
||||||
|
}
|
||||||
|
v8::String::Utf8Value utf8_value(isolate, stack);
|
||||||
|
if (*utf8_value != nullptr) {
|
||||||
|
std::string out(*utf8_value, utf8_value.length());
|
||||||
|
fprintf(stderr, "Had Exception: %s\n", out.c_str());
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "Unknown JS Exception\n");
|
||||||
|
}
|
||||||
|
abort();
|
||||||
|
}
|
||||||
Context::Scope context_scope(context);
|
Context::Scope context_scope(context);
|
||||||
|
|
||||||
env = new Environment(main_instance->isolate_data(),
|
env = new Environment(main_instance->isolate_data(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user