3
3
#include < sstream>
4
4
#include " debug_utils-inl.h"
5
5
#include " env-inl.h"
6
+ #include " node_errors.h"
6
7
#include " node_external_reference.h"
7
8
#include " node_internals.h"
8
9
#include " node_main_instance.h"
@@ -15,10 +16,8 @@ using v8::Context;
15
16
using v8::HandleScope;
16
17
using v8::Isolate;
17
18
using v8::Local;
18
- using v8::Object;
19
19
using v8::SnapshotCreator;
20
20
using v8::StartupData;
21
- using v8::String;
22
21
using v8::TryCatch;
23
22
using v8::Value;
24
23
@@ -112,55 +111,44 @@ std::string SnapshotBuilder::Generate(
112
111
creator.SetDefaultContext (Context::New (isolate));
113
112
isolate_data_indexes = main_instance->isolate_data ()->Serialize (&creator);
114
113
115
- TryCatch bootstrapCatch (isolate);
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 ());
114
+ // Run the per-context scripts
115
+ Local<Context> context;
116
+ {
117
+ TryCatch bootstrapCatch (isolate);
118
+ context = NewContext (isolate);
119
+ if (bootstrapCatch.HasCaught ()) {
120
+ PrintCaughtException (isolate, context, bootstrapCatch);
121
+ abort ();
139
122
}
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
123
}
149
124
Context::Scope context_scope (context);
150
125
126
+ // Create the environment
151
127
env = new Environment (main_instance->isolate_data (),
152
128
context,
153
129
args,
154
130
exec_args,
155
131
nullptr ,
156
132
node::EnvironmentFlags::kDefaultFlags ,
157
133
{});
158
- env->RunBootstrapping ().ToLocalChecked ();
134
+ // Run scripts in lib/internal/bootstrap/
135
+ {
136
+ TryCatch bootstrapCatch (isolate);
137
+ v8::MaybeLocal<Value> result = env->RunBootstrapping ();
138
+ if (bootstrapCatch.HasCaught ()) {
139
+ PrintCaughtException (isolate, context, bootstrapCatch);
140
+ }
141
+ result.ToLocalChecked ();
142
+ }
143
+
159
144
if (per_process::enabled_debug_list.enabled (DebugCategory::MKSNAPSHOT)) {
160
145
env->PrintAllBaseObjects ();
161
146
printf (" Environment = %p\n " , env);
162
147
}
148
+
149
+ // Serialize the native states
163
150
env_info = env->Serialize (&creator);
151
+ // Serialize the context
164
152
size_t index = creator.AddContext (
165
153
context, {SerializeNodeContextInternalFields, env});
166
154
CHECK_EQ (index , NodeMainInstance::kNodeContextIndex );
0 commit comments