Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2021-01-28 19:04:22 +0300
committerDanielle Adams <adamzdanielle@gmail.com>2021-02-16 17:12:40 +0300
commit337b4e754042f8ea68eb236d6572361ccfb4aa47 (patch)
tree592569ecd379d50e4e0b9c230f60c6ea01e48440 /src
parent2a5f67b3812a531f2bfed3330d827da165283163 (diff)
src: put (de)serialization code into node_snapshotable.h/cc
So that it's easier to find the corresponding code. PR-URL: https://github.com/nodejs/node/pull/37114 Refs: https://github.com/nodejs/node/pull/36943 Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/node_main_instance.cc14
-rw-r--r--src/node_snapshotable.cc39
-rw-r--r--src/node_snapshotable.h21
3 files changed, 61 insertions, 13 deletions
diff --git a/src/node_main_instance.cc b/src/node_main_instance.cc
index 37d9dbb9b75..b1c9444fcad 100644
--- a/src/node_main_instance.cc
+++ b/src/node_main_instance.cc
@@ -5,6 +5,7 @@
#include "node_external_reference.h"
#include "node_internals.h"
#include "node_options-inl.h"
+#include "node_snapshotable.h"
#include "node_v8_platform-inl.h"
#include "util-inl.h"
#if defined(LEAK_SANITIZER)
@@ -22,7 +23,6 @@ using v8::HandleScope;
using v8::Isolate;
using v8::Local;
using v8::Locker;
-using v8::Object;
std::unique_ptr<ExternalReferenceRegistry> NodeMainInstance::registry_ =
nullptr;
@@ -167,18 +167,6 @@ int NodeMainInstance::Run(const EnvSerializeInfo* env_info) {
return exit_code;
}
-void DeserializeNodeInternalFields(Local<Object> holder,
- int index,
- v8::StartupData payload,
- void* env) {
- if (payload.raw_size == 0) {
- holder->SetAlignedPointerInInternalField(index, nullptr);
- return;
- }
- // No embedder object in the builtin snapshot yet.
- UNREACHABLE();
-}
-
DeleteFnPtr<Environment, FreeEnvironment>
NodeMainInstance::CreateMainEnvironment(int* exit_code,
const EnvSerializeInfo* env_info) {
diff --git a/src/node_snapshotable.cc b/src/node_snapshotable.cc
new file mode 100644
index 00000000000..21de1086856
--- /dev/null
+++ b/src/node_snapshotable.cc
@@ -0,0 +1,39 @@
+
+#include "node_snapshotable.h"
+#include "base_object-inl.h"
+
+namespace node {
+
+using v8::Local;
+using v8::Object;
+using v8::StartupData;
+
+void DeserializeNodeInternalFields(Local<Object> holder,
+ int index,
+ v8::StartupData payload,
+ void* env) {
+ if (payload.raw_size == 0) {
+ holder->SetAlignedPointerInInternalField(index, nullptr);
+ return;
+ }
+ // No embedder object in the builtin snapshot yet.
+ UNREACHABLE();
+}
+
+StartupData SerializeNodeContextInternalFields(Local<Object> holder,
+ int index,
+ void* env) {
+ void* ptr = holder->GetAlignedPointerFromInternalField(index);
+ if (ptr == nullptr || ptr == env) {
+ return StartupData{nullptr, 0};
+ }
+ if (ptr == env && index == ContextEmbedderIndex::kEnvironment) {
+ return StartupData{nullptr, 0};
+ }
+
+ // No embedder objects in the builtin snapshot yet.
+ UNREACHABLE();
+ return StartupData{nullptr, 0};
+}
+
+} // namespace node
diff --git a/src/node_snapshotable.h b/src/node_snapshotable.h
new file mode 100644
index 00000000000..c45c1381b55
--- /dev/null
+++ b/src/node_snapshotable.h
@@ -0,0 +1,21 @@
+
+#ifndef SRC_NODE_SNAPSHOTABLE_H_
+#define SRC_NODE_SNAPSHOTABLE_H_
+
+#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
+
+#include "v8.h"
+namespace node {
+
+v8::StartupData SerializeNodeContextInternalFields(v8::Local<v8::Object> holder,
+ int index,
+ void* env);
+void DeserializeNodeInternalFields(v8::Local<v8::Object> holder,
+ int index,
+ v8::StartupData payload,
+ void* env);
+} // namespace node
+
+#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
+
+#endif // SRC_NODE_SNAPSHOTABLE_H_