Files
node/src/node_contextify.h
T
Anna Henningsen 57e301539b src: enable more detailed memory tracking
This will enable more detailed heap snapshots based on
a newer V8 API.

This commit itself is not tied to that API and could
be backported.

PR-URL: https://github.com/nodejs/node/pull/21742
Reviewed-By: James M Snell <jasnell@gmail.com>
2018-07-13 19:53:15 +02:00

105 lines
3.4 KiB
C++

#ifndef SRC_NODE_CONTEXTIFY_H_
#define SRC_NODE_CONTEXTIFY_H_
#include "node_internals.h"
#include "node_context_data.h"
namespace node {
namespace contextify {
struct ContextOptions {
v8::Local<v8::String> name;
v8::Local<v8::String> origin;
v8::Local<v8::Boolean> allow_code_gen_strings;
v8::Local<v8::Boolean> allow_code_gen_wasm;
};
class ContextifyContext {
public:
ContextifyContext(Environment* env,
v8::Local<v8::Object> sandbox_obj,
const ContextOptions& options);
v8::Local<v8::Value> CreateDataWrapper(Environment* env);
v8::Local<v8::Context> CreateV8Context(Environment* env,
v8::Local<v8::Object> sandbox_obj, const ContextOptions& options);
static void Init(Environment* env, v8::Local<v8::Object> target);
static bool AllowWasmCodeGeneration(
v8::Local<v8::Context> context, v8::Local<v8::String>);
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(ContextEmbedderIndex::kSandboxObject));
}
template <typename T>
static ContextifyContext* Get(const v8::PropertyCallbackInfo<T>& args);
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);
Environment* const env_;
Persistent<v8::Context> context_;
};
} // namespace contextify
} // namespace node
#endif // SRC_NODE_CONTEXTIFY_H_