GeezerVison is showing github.com — src: put (de)serialization code into node_snapshotable.h/cc · nodejs/node@337b4e7
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: node.gyp +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 636 | 636 | 'src/node_report_module.cc', | 637 | 637 | 'src/node_report_utils.cc', | 638 | 638 | 'src/node_serdes.cc', | | 639 | + 'src/node_snapshotable.cc', | 639 | 640 | 'src/node_sockaddr.cc', | 640 | 641 | 'src/node_stat_watcher.cc', | 641 | 642 | 'src/node_symbols.cc', | | 738 | 739 | 'src/node_report.h', | 739 | 740 | 'src/node_revert.h', | 740 | 741 | 'src/node_root_certs.h', | | 742 | + 'src/node_snapshotable.h', | 741 | 743 | 'src/node_sockaddr.h', | 742 | 744 | 'src/node_sockaddr-inl.h', | 743 | 745 | 'src/node_stat_watcher.h', | |
Collapse file Copy file name to clipboardExpand all lines: src/node_main_instance.cc +1-13Lines changed: 1 addition & 13 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 5 | 5 | #include "node_external_reference.h" | 6 | 6 | #include "node_internals.h" | 7 | 7 | #include "node_options-inl.h" | | 8 | +#include "node_snapshotable.h" | 8 | 9 | #include "node_v8_platform-inl.h" | 9 | 10 | #include "util-inl.h" | 10 | 11 | #if defined(LEAK_SANITIZER) | @@ -22,7 +23,6 @@ using v8::HandleScope; | 22 | 23 | using v8::Isolate; | 23 | 24 | using v8::Local; | 24 | 25 | using v8::Locker; | 25 | | -using v8::Object; | 26 | 26 |
| 27 | 27 | std::unique_ptr<ExternalReferenceRegistry> NodeMainInstance::registry_ = | 28 | 28 | nullptr; | @@ -167,18 +167,6 @@ int NodeMainInstance::Run(const EnvSerializeInfo* env_info) { | 167 | 167 | return exit_code; | 168 | 168 | } | 169 | 169 |
| 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 | | - | 182 | 170 | DeleteFnPtr<Environment, FreeEnvironment> | 183 | 171 | NodeMainInstance::CreateMainEnvironment(int* exit_code, | 184 | 172 | const EnvSerializeInfo* env_info) { | |
Collapse file Copy file name to clipboard +39Lines changed: 39 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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 Copy file name to clipboard +21Lines changed: 21 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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 Copy file name to clipboardExpand all lines: tools/snapshot/snapshot_builder.cc +1-17Lines changed: 1 addition & 17 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 6 | 6 | #include "node_external_reference.h" | 7 | 7 | #include "node_internals.h" | 8 | 8 | #include "node_main_instance.h" | | 9 | +#include "node_snapshotable.h" | 9 | 10 | #include "node_v8_platform-inl.h" | 10 | 11 |
| 11 | 12 | namespace node { | @@ -14,7 +15,6 @@ using v8::Context; | 14 | 15 | using v8::HandleScope; | 15 | 16 | using v8::Isolate; | 16 | 17 | using v8::Local; | 17 | | -using v8::Object; | 18 | 18 | using v8::SnapshotCreator; | 19 | 19 | using v8::StartupData; | 20 | 20 |
| @@ -75,22 +75,6 @@ const EnvSerializeInfo* NodeMainInstance::GetEnvSerializeInfo() { | 75 | 75 | return ss.str(); | 76 | 76 | } | 77 | 77 |
| 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 | | - | 94 | 78 | std::string SnapshotBuilder::Generate( | 95 | 79 | const std::vector<std::string> args, | 96 | 80 | const std::vector<std::string> exec_args) { | |
|