diff options
author | Gus Caplan <me@gus.host> | 2017-12-09 10:32:34 -0600 |
---|---|---|
committer | Timothy Gu <timothygu99@gmail.com> | 2018-01-30 17:00:57 -0800 |
commit | 3bf34f27a1b231eec12ec999ca0f5d59bce9da14 (patch) | |
tree | ef2e6484b77c9e1ad99575add0377632bc5fa114 /src/node_contextify.h | |
parent | 70277d6170b5c18322542b3980564a74c3d8d1b3 (diff) | |
download | node-new-3bf34f27a1b231eec12ec999ca0f5d59bce9da14.tar.gz |
src: flatten ContextifyContext
Flattens ContextifyContext allows the context interface to be used in
other parts of the code base.
PR-URL: https://github.com/nodejs/node/pull/17560
Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Diffstat (limited to 'src/node_contextify.h')
-rw-r--r-- | src/node_contextify.h | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/src/node_contextify.h b/src/node_contextify.h new file mode 100644 index 0000000000..e8a54e1667 --- /dev/null +++ b/src/node_contextify.h @@ -0,0 +1,98 @@ +#ifndef SRC_NODE_CONTEXTIFY_H_ +#define SRC_NODE_CONTEXTIFY_H_ + +#include "node_internals.h" +#include "node_watchdog.h" +#include "base_object-inl.h" + +namespace node { +namespace contextify { + +class ContextifyContext { + protected: + // V8 reserves the first field in context objects for the debugger. We use the + // second field to hold a reference to the sandbox object. + enum { kSandboxObjectIndex = 1 }; + + Environment* const env_; + v8::Persistent<v8::Context> context_; + + public: + ContextifyContext(Environment* env, + v8::Local<v8::Object> sandbox_obj, + v8::Local<v8::Object> options_obj); + ~ContextifyContext(); + + v8::Local<v8::Value> CreateDataWrapper(Environment* env); + v8::Local<v8::Context> CreateV8Context(Environment* env, + v8::Local<v8::Object> sandbox_obj, v8::Local<v8::Object> options_obj); + static void Init(Environment* env, v8::Local<v8::Object> target); + + static ContextifyContext* ContextFromContextifiedSandbox( + Environment* env, + const v8::Local<v8::Object>& sandbox); + + inline Environment* env() const { + return env_; + } + + inline v8::Local<v8::Context> context() const { + return PersistentToLocal(env()->isolate(), context_); + } + + inline v8::Local<v8::Object> global_proxy() const { + return context()->Global(); + } + + inline v8::Local<v8::Object> sandbox() const { + return v8::Local<v8::Object>::Cast( + context()->GetEmbedderData(kSandboxObjectIndex)); + } + + private: + static void MakeContext(const v8::FunctionCallbackInfo<v8::Value>& args); + static void IsContext(const v8::FunctionCallbackInfo<v8::Value>& args); + static void WeakCallback( + const v8::WeakCallbackInfo<ContextifyContext>& data); + static void PropertyGetterCallback( + v8::Local<v8::Name> property, + const v8::PropertyCallbackInfo<v8::Value>& args); + static void PropertySetterCallback( + v8::Local<v8::Name> property, + v8::Local<v8::Value> value, + const v8::PropertyCallbackInfo<v8::Value>& args); + static void PropertyDescriptorCallback( + v8::Local<v8::Name> property, + const v8::PropertyCallbackInfo<v8::Value>& args); + static void PropertyDefinerCallback( + v8::Local<v8::Name> property, + const v8::PropertyDescriptor& desc, + const v8::PropertyCallbackInfo<v8::Value>& args); + static void PropertyDeleterCallback( + v8::Local<v8::Name> property, + const v8::PropertyCallbackInfo<v8::Boolean>& args); + static void PropertyEnumeratorCallback( + const v8::PropertyCallbackInfo<v8::Array>& args); + static void IndexedPropertyGetterCallback( + uint32_t index, + const v8::PropertyCallbackInfo<v8::Value>& args); + static void IndexedPropertySetterCallback( + uint32_t index, + v8::Local<v8::Value> value, + const v8::PropertyCallbackInfo<v8::Value>& args); + static void IndexedPropertyDescriptorCallback( + uint32_t index, + const v8::PropertyCallbackInfo<v8::Value>& args); + static void IndexedPropertyDefinerCallback( + uint32_t index, + const v8::PropertyDescriptor& desc, + const v8::PropertyCallbackInfo<v8::Value>& args); + static void IndexedPropertyDeleterCallback( + uint32_t index, + const v8::PropertyCallbackInfo<v8::Boolean>& args); +}; + +} // namespace contextify +} // namespace node + +#endif // SRC_NODE_CONTEXTIFY_H_ |