Skip to content
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

bootstrap: mksnapshot should show JS error summaries #38174

Closed
wants to merge 6 commits into from
Closed
Changes from 4 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
43 changes: 43 additions & 0 deletions tools/snapshot/snapshot_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ using v8::Context;
using v8::HandleScope;
using v8::Isolate;
using v8::Local;
using v8::Object;
using v8::SnapshotCreator;
using v8::StartupData;
using v8::String;
using v8::TryCatch;
using v8::Value;

template <typename T>
void WriteVector(std::stringstream* ss, const T* vec, size_t size) {
Expand Down Expand Up @@ -79,6 +83,10 @@ std::string SnapshotBuilder::Generate(
const std::vector<std::string> args,
const std::vector<std::string> exec_args) {
Isolate* isolate = Isolate::Allocate();
isolate->SetCaptureStackTraceForUncaughtExceptions(
true,
10,
v8::StackTrace::StackTraceOptions::kDetailed);
per_process::v8_platform.Platform()->RegisterIsolate(isolate,
uv_default_loop());
std::unique_ptr<NodeMainInstance> main_instance;
Expand All @@ -99,12 +107,47 @@ std::string SnapshotBuilder::Generate(
per_process::v8_platform.Platform(),
args,
exec_args);
// fprintf(stderr, "BOOTSTRAPPING1\n\n\n");
bmeck marked this conversation as resolved.
Show resolved Hide resolved

HandleScope scope(isolate);
creator.SetDefaultContext(Context::New(isolate));
isolate_data_indexes = main_instance->isolate_data()->Serialize(&creator);
// fprintf(stderr, "BOOTSTRAPPING2\n\n\n");
bmeck marked this conversation as resolved.
Show resolved Hide resolved

TryCatch bootstrapCatch(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);

env = new Environment(main_instance->isolate_data(),
Expand Down