Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 337b4e7

Browse filesBrowse files
joyeecheungdanielleadams
authored andcommitted
src: put (de)serialization code into node_snapshotable.h/cc
So that it's easier to find the corresponding code. PR-URL: #37114 Refs: #36943 Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
1 parent 2a5f67b commit 337b4e7
Copy full SHA for 337b4e7

File tree

Expand file treeCollapse file tree

5 files changed

+64
-30
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

5 files changed

+64
-30
lines changed
Open diff view settings
Collapse file

‎node.gyp‎

Copy file name to clipboardExpand all lines: node.gyp
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,7 @@
636636
'src/node_report_module.cc',
637637
'src/node_report_utils.cc',
638638
'src/node_serdes.cc',
639+
'src/node_snapshotable.cc',
639640
'src/node_sockaddr.cc',
640641
'src/node_stat_watcher.cc',
641642
'src/node_symbols.cc',
@@ -738,6 +739,7 @@
738739
'src/node_report.h',
739740
'src/node_revert.h',
740741
'src/node_root_certs.h',
742+
'src/node_snapshotable.h',
741743
'src/node_sockaddr.h',
742744
'src/node_sockaddr-inl.h',
743745
'src/node_stat_watcher.h',
Collapse file

‎src/node_main_instance.cc‎

Copy file name to clipboardExpand all lines: src/node_main_instance.cc
+1-13Lines changed: 1 addition & 13 deletions
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) {
Collapse file

‎src/node_snapshotable.cc‎

Copy file name to clipboard
+39Lines changed: 39 additions & 0 deletions
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
Collapse file

‎src/node_snapshotable.h‎

Copy file name to clipboard
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
#ifndef SRC_NODE_SNAPSHOTABLE_H_
3+
#define SRC_NODE_SNAPSHOTABLE_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_SNAPSHOTABLE_H_
Collapse file

‎tools/snapshot/snapshot_builder.cc‎

Copy file name to clipboardExpand all lines: tools/snapshot/snapshot_builder.cc
+1-17Lines changed: 1 addition & 17 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.