| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,8 +15,12 @@ using v8::Context; | |||
| 15 | 15 | using v8::HandleScope; | |
| 16 | 16 | using v8::Isolate; | |
| 17 | 17 | using v8::Local; | |
| 18 | + using v8::Object; | ||
| 18 | 19 | using v8::SnapshotCreator; | |
| 19 | 20 | using v8::StartupData; | |
| 21 | + using v8::String; | ||
| 22 | + using v8::TryCatch; | ||
| 23 | + using v8::Value; | ||
| 20 | 24 | ||
| 21 | 25 | template <typename T> | |
| 22 | 26 | void WriteVector(std::stringstream* ss, const T* vec, size_t size) { | |
@@ -79,6 +83,10 @@ std::string SnapshotBuilder::Generate( | |||
| 79 | 83 | const std::vector<std::string> args, | |
| 80 | 84 | const std::vector<std::string> exec_args) { | |
| 81 | 85 | Isolate* isolate = Isolate::Allocate(); | |
| 86 | + isolate->SetCaptureStackTraceForUncaughtExceptions( | ||
| 87 | + true, | ||
| 88 | + 10, | ||
| 89 | + v8::StackTrace::StackTraceOptions::kDetailed); | ||
| 82 | 90 | per_process::v8_platform.Platform()->RegisterIsolate(isolate, | |
| 83 | 91 | uv_default_loop()); | |
| 84 | 92 | std::unique_ptr<NodeMainInstance> main_instance; | |
@@ -104,7 +112,40 @@ std::string SnapshotBuilder::Generate( | |||
| 104 | 112 | creator.SetDefaultContext(Context::New(isolate)); | |
| 105 | 113 | isolate_data_indexes = main_instance->isolate_data()->Serialize(&creator); | |
| 106 | 114 | ||
| 115 | + TryCatch bootstrapCatch(isolate); | ||
| 107 | 116 | Local<Context> context = NewContext(isolate); | |
| 117 | + if (bootstrapCatch.HasCaught()) { | ||
| 118 | + Local<Object> obj = bootstrapCatch.Exception()->ToObject(context) | ||
| 119 | + .ToLocalChecked(); | ||
| 120 | + Local<Value> stack = obj->Get( | ||
| 121 | + context, | ||
| 122 | + FIXED_ONE_BYTE_STRING(isolate, "stack")).ToLocalChecked(); | ||
| 123 | + if (stack->IsUndefined()) { | ||
| 124 | + Local<String> str = obj->Get( | ||
| 125 | + context, | ||
| 126 | + FIXED_ONE_BYTE_STRING(isolate, "name")) | ||
| 127 | + .ToLocalChecked()->ToString(context).ToLocalChecked(); | ||
| 128 | + str = String::Concat( | ||
| 129 | + isolate, | ||
| 130 | + str, | ||
| 131 | + FIXED_ONE_BYTE_STRING(isolate, ": ")); | ||
| 132 | + stack = String::Concat( | ||
| 133 | + isolate, | ||
| 134 | + str, | ||
| 135 | + obj->Get( | ||
| 136 | + context, | ||
| 137 | + FIXED_ONE_BYTE_STRING(isolate, "message")) | ||
| 138 | + .ToLocalChecked()->ToString(context).ToLocalChecked()); | ||
| 139 | + } | ||
| 140 | + v8::String::Utf8Value utf8_value(isolate, stack); | ||
| 141 | + if (*utf8_value != nullptr) { | ||
| 142 | + std::string out(*utf8_value, utf8_value.length()); | ||
| 143 | + fprintf(stderr, "Had Exception: %s\n", out.c_str()); | ||
| 144 | + } else { | ||
| 145 | + fprintf(stderr, "Unknown JS Exception\n"); | ||
| 146 | + } | ||
| 147 | + abort(); | ||
| 148 | + } | ||
| 108 | 149 | Context::Scope context_scope(context); | |
| 109 | 150 | ||
| 110 | 151 | env = new Environment(main_instance->isolate_data(), | |
| Back | FazBrowse Home | New Git URL |
0 commit comments