Skip to content

Commit fa4b68a

Browse files
committed
src: put (de)serialization code into node_snapshottable.h/cc
So that it's easier to find the corresponding code.
1 parent 029d1fd commit fa4b68a

File tree

5 files changed

+64
-30
lines changed

5 files changed

+64
-30
lines changed

node.gyp

+2
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,7 @@
641641
'src/node_report_module.cc',
642642
'src/node_report_utils.cc',
643643
'src/node_serdes.cc',
644+
'src/node_snapshotable.cc',
644645
'src/node_sockaddr.cc',
645646
'src/node_stat_watcher.cc',
646647
'src/node_symbols.cc',
@@ -743,6 +744,7 @@
743744
'src/node_report.h',
744745
'src/node_revert.h',
745746
'src/node_root_certs.h',
747+
'src/node_snapshotable.h',
746748
'src/node_sockaddr.h',
747749
'src/node_sockaddr-inl.h',
748750
'src/node_stat_watcher.h',

src/node_main_instance.cc

+1-13
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "node_external_reference.h"
66
#include "node_internals.h"
77
#include "node_options-inl.h"
8+
#include "node_snapshotable.h"
89
#include "node_v8_platform-inl.h"
910
#include "util-inl.h"
1011
#if defined(LEAK_SANITIZER)
@@ -22,7 +23,6 @@ using v8::HandleScope;
2223
using v8::Isolate;
2324
using v8::Local;
2425
using v8::Locker;
25-
using v8::Object;
2626

2727
std::unique_ptr<ExternalReferenceRegistry> NodeMainInstance::registry_ =
2828
nullptr;
@@ -167,18 +167,6 @@ int NodeMainInstance::Run(const EnvSerializeInfo* env_info) {
167167
return exit_code;
168168
}
169169

170-
void DeserializeNodeInternalFields(Local<Object> holder,
171-
int index,
172-
v8::StartupData payload,
173-
void* env) {
174-
if (payload.raw_size == 0) {
175-
holder->SetAlignedPointerInInternalField(index, nullptr);
176-
return;
177-
}
178-
// No embedder object in the builtin snapshot yet.
179-
UNREACHABLE();
180-
}
181-
182170
DeleteFnPtr<Environment, FreeEnvironment>
183171
NodeMainInstance::CreateMainEnvironment(int* exit_code,
184172
const EnvSerializeInfo* env_info) {

src/node_snapshotable.cc

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
#include "node_snapshotable.h"
3+
#include "base_object-inl.h"
4+
5+
namespace node {
6+
7+
using v8::Local;
8+
using v8::Object;
9+
using v8::StartupData;
10+
11+
void DeserializeNodeInternalFields(Local<Object> holder,
12+
int index,
13+
v8::StartupData payload,
14+
void* env) {
15+
if (payload.raw_size == 0) {
16+
holder->SetAlignedPointerInInternalField(index, nullptr);
17+
return;
18+
}
19+
// No embedder object in the builtin snapshot yet.
20+
UNREACHABLE();
21+
}
22+
23+
StartupData SerializeNodeContextInternalFields(Local<Object> holder,
24+
int index,
25+
void* env) {
26+
void* ptr = holder->GetAlignedPointerFromInternalField(index);
27+
if (ptr == nullptr || ptr == env) {
28+
return StartupData{nullptr, 0};
29+
}
30+
if (ptr == env && index == ContextEmbedderIndex::kEnvironment) {
31+
return StartupData{nullptr, 0};
32+
}
33+
34+
// No embedder objects in the builtin snapshot yet.
35+
UNREACHABLE();
36+
return StartupData{nullptr, 0};
37+
}
38+
39+
} // namespace node

src/node_snapshotable.h

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
#ifndef SRC_NODE_SERIALIZABLE_H_
3+
#define SRC_NODE_SERIALIZABLE_H_
4+
5+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
6+
7+
#include "v8.h"
8+
namespace node {
9+
10+
v8::StartupData SerializeNodeContextInternalFields(v8::Local<v8::Object> holder,
11+
int index,
12+
void* env);
13+
void DeserializeNodeInternalFields(v8::Local<v8::Object> holder,
14+
int index,
15+
v8::StartupData payload,
16+
void* env);
17+
} // namespace node
18+
19+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
20+
21+
#endif // SRC_NODE_SERIALIZABLE_H_

tools/snapshot/snapshot_builder.cc

+1-17
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "node_external_reference.h"
77
#include "node_internals.h"
88
#include "node_main_instance.h"
9+
#include "node_snapshotable.h"
910
#include "node_v8_platform-inl.h"
1011

1112
namespace node {
@@ -14,7 +15,6 @@ using v8::Context;
1415
using v8::HandleScope;
1516
using v8::Isolate;
1617
using v8::Local;
17-
using v8::Object;
1818
using v8::SnapshotCreator;
1919
using v8::StartupData;
2020

@@ -75,22 +75,6 @@ const EnvSerializeInfo* NodeMainInstance::GetEnvSerializeInfo() {
7575
return ss.str();
7676
}
7777

78-
static StartupData SerializeNodeContextInternalFields(Local<Object> holder,
79-
int index,
80-
void* env) {
81-
void* ptr = holder->GetAlignedPointerFromInternalField(index);
82-
if (ptr == nullptr || ptr == env) {
83-
return StartupData{nullptr, 0};
84-
}
85-
if (ptr == env && index == ContextEmbedderIndex::kEnvironment) {
86-
return StartupData{nullptr, 0};
87-
}
88-
89-
// No embedder objects in the builtin snapshot yet.
90-
UNREACHABLE();
91-
return StartupData{nullptr, 0};
92-
}
93-
9478
std::string SnapshotBuilder::Generate(
9579
const std::vector<std::string> args,
9680
const std::vector<std::string> exec_args) {

0 commit comments

Comments
 (0)