diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2021-02-08 15:34:02 +0300 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2021-02-19 14:08:04 +0300 |
commit | 3c8290c5a8afd851f2521a507b375ca5c91ce87b (patch) | |
tree | 1e45d4a641f7783269d8afda8cc941be1dc2dc49 /src/env.h | |
parent | 05286b9dd4d9d38d514c56c030bd330588eb40b0 (diff) |
src: support serialization of binding data
This patch adds the SnapshotableObject interface. Native objects
supporting serialization can inherit from it, implementing
PrepareForSerialization(), Serialize() and Deserialize()
to control how the native states should be serialized and
deserialized.
See doc: https://docs.google.com/document/d/15bu038I36oILq5t4Qju1sS2nKudVB6NSGWz00oD48Q8/edit
PR-URL: https://github.com/nodejs/node/pull/36943
Fixes: https://github.com/nodejs/node/issues/35930
Refs: https://github.com/nodejs/node/issues/35711
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/env.h')
-rw-r--r-- | src/env.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/env.h b/src/env.h index dae522f2530..ba0626463f6 100644 --- a/src/env.h +++ b/src/env.h @@ -37,6 +37,7 @@ #include "node_main_instance.h" #include "node_options.h" #include "node_perf_common.h" +#include "node_snapshotable.h" #include "req_wrap.h" #include "util.h" #include "uv.h" @@ -899,7 +900,22 @@ struct PropInfo { SnapshotIndex index; // In the snapshot }; +typedef void (*DeserializeRequestCallback)(v8::Local<v8::Context> context, + v8::Local<v8::Object> holder, + int index, + InternalFieldInfo* info); +struct DeserializeRequest { + DeserializeRequestCallback cb; + v8::Global<v8::Object> holder; + int index; + InternalFieldInfo* info = nullptr; // Owned by the request + + // Move constructor + DeserializeRequest(DeserializeRequest&& other) = default; +}; + struct EnvSerializeInfo { + std::vector<PropInfo> bindings; std::vector<std::string> native_modules; AsyncHooks::SerializeInfo async_hooks; TickInfo::SerializeInfo tick_info; @@ -934,6 +950,11 @@ class Environment : public MemoryRetainer { void PrintAllBaseObjects(); void VerifyNoStrongBaseObjects(); + void EnqueueDeserializeRequest(DeserializeRequestCallback cb, + v8::Local<v8::Object> holder, + int index, + InternalFieldInfo* info); + void RunDeserializeRequests(); // Should be called before InitializeInspector() void InitializeDiagnostics(); @@ -1371,6 +1392,9 @@ class Environment : public MemoryRetainer { void AddUnmanagedFd(int fd); void RemoveUnmanagedFd(int fd); + template <typename T> + void ForEachBindingData(T&& iterator); + private: inline void ThrowError(v8::Local<v8::Value> (*fun)(v8::Local<v8::String>), const char* errmsg); @@ -1459,6 +1483,8 @@ class Environment : public MemoryRetainer { bool is_in_inspector_console_call_ = false; #endif + std::list<DeserializeRequest> deserialize_requests_; + // handle_wrap_queue_ and req_wrap_queue_ needs to be at a fixed offset from // the start of the class because it is used by // src/node_postmortem_metadata.cc to calculate offsets and generate debug |