@@ -37,6 +37,7 @@ using v8::NewStringType;
37
37
using v8::Number;
38
38
using v8::Object;
39
39
using v8::Private;
40
+ using v8::SnapshotCreator;
40
41
using v8::StackTrace;
41
42
using v8::String;
42
43
using v8::Symbol;
@@ -49,22 +50,58 @@ int const Environment::kNodeContextTag = 0x6e6f64;
49
50
void * const Environment::kNodeContextTagPtr = const_cast <void *>(
50
51
static_cast <const void *>(&Environment::kNodeContextTag ));
51
52
52
- IsolateData::IsolateData (Isolate* isolate,
53
- uv_loop_t * event_loop,
54
- MultiIsolatePlatform* platform,
55
- ArrayBufferAllocator* node_allocator)
56
- : isolate_(isolate),
57
- event_loop_ (event_loop),
58
- allocator_(isolate->GetArrayBufferAllocator ()),
59
- node_allocator_(node_allocator == nullptr ?
60
- nullptr : node_allocator->GetImpl ()),
61
- uses_node_allocator_(allocator_ == node_allocator_),
62
- platform_(platform) {
63
- CHECK_NOT_NULL (allocator_);
53
+ std::vector<size_t > IsolateData::Serialize (SnapshotCreator* creator) {
54
+ Isolate* isolate = creator->GetIsolate ();
55
+ std::vector<size_t > indexes;
56
+ HandleScope handle_scope (isolate);
57
+ // XXX(joyeecheung): technically speaking, the indexes here should be
58
+ // consecutive and we could just return a range instead of an array,
59
+ // but that's not part of the V8 API contract so we use an array
60
+ // just to be safe.
61
+
62
+ #define VP (PropertyName, StringValue ) V(v8::Private, PropertyName)
63
+ #define VY (PropertyName, StringValue ) V(v8::Symbol, PropertyName)
64
+ #define VS (PropertyName, StringValue ) V(v8::String, PropertyName)
65
+ #define V (TypeName, PropertyName ) \
66
+ indexes.push_back (creator->AddData (PropertyName##_.Get (isolate)));
67
+ PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES (VP)
68
+ PER_ISOLATE_SYMBOL_PROPERTIES (VY)
69
+ PER_ISOLATE_STRING_PROPERTIES (VS)
70
+ #undef V
71
+ #undef VY
72
+ #undef VS
73
+ #undef VP
64
74
65
- options_. reset (
66
- new PerIsolateOptions (*(per_process::cli_options-> per_isolate )));
75
+ return indexes;
76
+ }
67
77
78
+ void IsolateData::DeserializeProperties (
79
+ const NodeMainInstance::IndexArray* indexes) {
80
+ size_t i = 0 ;
81
+ HandleScope handle_scope (isolate_);
82
+
83
+ #define VP (PropertyName, StringValue ) V(v8::Private, PropertyName)
84
+ #define VY (PropertyName, StringValue ) V(v8::Symbol, PropertyName)
85
+ #define VS (PropertyName, StringValue ) V(v8::String, PropertyName)
86
+ #define V (TypeName, PropertyName ) \
87
+ do { \
88
+ MaybeLocal<TypeName> field = \
89
+ isolate_->GetDataFromSnapshotOnce <TypeName>(indexes->Get (i++)); \
90
+ if (field.IsEmpty ()) { \
91
+ fprintf (stderr, " Failed to deserialize " #PropertyName " \n " ); \
92
+ } \
93
+ PropertyName##_.Set (isolate_, field.ToLocalChecked ()); \
94
+ } while (0 );
95
+ PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES (VP)
96
+ PER_ISOLATE_SYMBOL_PROPERTIES (VY)
97
+ PER_ISOLATE_STRING_PROPERTIES (VS)
98
+ #undef V
99
+ #undef VY
100
+ #undef VS
101
+ #undef VP
102
+ }
103
+
104
+ void IsolateData::CreateProperties () {
68
105
// Create string and private symbol properties as internalized one byte
69
106
// strings after the platform is properly initialized.
70
107
//
@@ -76,44 +113,68 @@ IsolateData::IsolateData(Isolate* isolate,
76
113
// One byte because our strings are ASCII and we can safely skip V8's UTF-8
77
114
// decoding step.
78
115
79
- HandleScope handle_scope (isolate );
116
+ HandleScope handle_scope (isolate_ );
80
117
81
- #define V (PropertyName, StringValue ) \
82
- PropertyName ## _.Set ( \
83
- isolate, \
84
- Private::New ( \
85
- isolate, \
86
- String::NewFromOneByte ( \
87
- isolate, \
88
- reinterpret_cast < const uint8_t *>(StringValue), \
89
- NewStringType:: kInternalized , \
90
- sizeof (StringValue) - 1 ) .ToLocalChecked ()));
118
+ #define V (PropertyName, StringValue ) \
119
+ PropertyName## _.Set ( \
120
+ isolate_, \
121
+ Private::New (isolate_, \
122
+ String::NewFromOneByte ( \
123
+ isolate_, \
124
+ reinterpret_cast < const uint8_t *>(StringValue), \
125
+ NewStringType:: kInternalized , \
126
+ sizeof (StringValue) - 1 ) \
127
+ .ToLocalChecked ()));
91
128
PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES (V)
92
129
#undef V
93
- #define V (PropertyName, StringValue ) \
94
- PropertyName ## _.Set ( \
95
- isolate, \
96
- Symbol::New ( \
97
- isolate, \
98
- String::NewFromOneByte ( \
99
- isolate, \
100
- reinterpret_cast < const uint8_t *>(StringValue), \
101
- NewStringType:: kInternalized , \
102
- sizeof (StringValue) - 1 ) .ToLocalChecked ()));
130
+ #define V (PropertyName, StringValue ) \
131
+ PropertyName## _.Set ( \
132
+ isolate_, \
133
+ Symbol::New (isolate_, \
134
+ String::NewFromOneByte ( \
135
+ isolate_, \
136
+ reinterpret_cast < const uint8_t *>(StringValue), \
137
+ NewStringType:: kInternalized , \
138
+ sizeof (StringValue) - 1 ) \
139
+ .ToLocalChecked ()));
103
140
PER_ISOLATE_SYMBOL_PROPERTIES (V)
104
141
#undef V
105
- #define V (PropertyName, StringValue ) \
106
- PropertyName ## _.Set ( \
107
- isolate, \
108
- String::NewFromOneByte ( \
109
- isolate, \
110
- reinterpret_cast < const uint8_t *>(StringValue), \
111
- NewStringType:: kInternalized , \
112
- sizeof (StringValue) - 1 ) .ToLocalChecked ());
142
+ #define V (PropertyName, StringValue ) \
143
+ PropertyName## _.Set ( \
144
+ isolate_, \
145
+ String::NewFromOneByte (isolate_, \
146
+ reinterpret_cast < const uint8_t *>(StringValue), \
147
+ NewStringType:: kInternalized , \
148
+ sizeof (StringValue) - 1 ) \
149
+ .ToLocalChecked ());
113
150
PER_ISOLATE_STRING_PROPERTIES (V)
114
151
#undef V
115
152
}
116
153
154
+ IsolateData::IsolateData (Isolate* isolate,
155
+ uv_loop_t * event_loop,
156
+ MultiIsolatePlatform* platform,
157
+ ArrayBufferAllocator* node_allocator,
158
+ const NodeMainInstance::IndexArray* indexes)
159
+ : isolate_(isolate),
160
+ event_loop_ (event_loop),
161
+ allocator_(isolate->GetArrayBufferAllocator ()),
162
+ node_allocator_(node_allocator == nullptr ? nullptr
163
+ : node_allocator->GetImpl ()),
164
+ uses_node_allocator_(allocator_ == node_allocator_),
165
+ platform_(platform) {
166
+ CHECK_NOT_NULL (allocator_);
167
+
168
+ options_.reset (
169
+ new PerIsolateOptions (*(per_process::cli_options->per_isolate )));
170
+
171
+ if (indexes == nullptr ) {
172
+ CreateProperties ();
173
+ } else {
174
+ DeserializeProperties (indexes);
175
+ }
176
+ }
177
+
117
178
void IsolateData::MemoryInfo (MemoryTracker* tracker) const {
118
179
#define V (PropertyName, StringValue ) \
119
180
tracker->TrackField (#PropertyName, PropertyName (isolate ()));
0 commit comments