src: migrate to new V8 interceptors API
Refs: https://github.com/v8/node/pull/180 PR-URL: https://github.com/nodejs/node/pull/52745 Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
This commit is contained in:
parent
956521c767
commit
d6b12f5b77
@ -51,6 +51,7 @@ using v8::FunctionTemplate;
|
|||||||
using v8::HandleScope;
|
using v8::HandleScope;
|
||||||
using v8::IndexedPropertyHandlerConfiguration;
|
using v8::IndexedPropertyHandlerConfiguration;
|
||||||
using v8::Int32;
|
using v8::Int32;
|
||||||
|
using v8::Intercepted;
|
||||||
using v8::Isolate;
|
using v8::Isolate;
|
||||||
using v8::Just;
|
using v8::Just;
|
||||||
using v8::Local;
|
using v8::Local;
|
||||||
@ -458,14 +459,15 @@ bool ContextifyContext::IsStillInitializing(const ContextifyContext* ctx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void ContextifyContext::PropertyGetterCallback(
|
Intercepted ContextifyContext::PropertyGetterCallback(
|
||||||
Local<Name> property,
|
Local<Name> property, const PropertyCallbackInfo<Value>& args) {
|
||||||
const PropertyCallbackInfo<Value>& args) {
|
|
||||||
Environment* env = Environment::GetCurrent(args);
|
Environment* env = Environment::GetCurrent(args);
|
||||||
ContextifyContext* ctx = ContextifyContext::Get(args);
|
ContextifyContext* ctx = ContextifyContext::Get(args);
|
||||||
|
|
||||||
// Still initializing
|
// Still initializing
|
||||||
if (IsStillInitializing(ctx)) return;
|
if (IsStillInitializing(ctx)) {
|
||||||
|
return Intercepted::kNo;
|
||||||
|
}
|
||||||
|
|
||||||
Local<Context> context = ctx->context();
|
Local<Context> context = ctx->context();
|
||||||
Local<Object> sandbox = ctx->sandbox();
|
Local<Object> sandbox = ctx->sandbox();
|
||||||
@ -487,18 +489,22 @@ void ContextifyContext::PropertyGetterCallback(
|
|||||||
rv = ctx->global_proxy();
|
rv = ctx->global_proxy();
|
||||||
|
|
||||||
args.GetReturnValue().Set(rv);
|
args.GetReturnValue().Set(rv);
|
||||||
|
return Intercepted::kYes;
|
||||||
}
|
}
|
||||||
|
return Intercepted::kNo;
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void ContextifyContext::PropertySetterCallback(
|
Intercepted ContextifyContext::PropertySetterCallback(
|
||||||
Local<Name> property,
|
Local<Name> property,
|
||||||
Local<Value> value,
|
Local<Value> value,
|
||||||
const PropertyCallbackInfo<Value>& args) {
|
const PropertyCallbackInfo<void>& args) {
|
||||||
ContextifyContext* ctx = ContextifyContext::Get(args);
|
ContextifyContext* ctx = ContextifyContext::Get(args);
|
||||||
|
|
||||||
// Still initializing
|
// Still initializing
|
||||||
if (IsStillInitializing(ctx)) return;
|
if (IsStillInitializing(ctx)) {
|
||||||
|
return Intercepted::kNo;
|
||||||
|
}
|
||||||
|
|
||||||
Local<Context> context = ctx->context();
|
Local<Context> context = ctx->context();
|
||||||
PropertyAttribute attributes = PropertyAttribute::None;
|
PropertyAttribute attributes = PropertyAttribute::None;
|
||||||
@ -516,8 +522,9 @@ void ContextifyContext::PropertySetterCallback(
|
|||||||
(static_cast<int>(attributes) &
|
(static_cast<int>(attributes) &
|
||||||
static_cast<int>(PropertyAttribute::ReadOnly));
|
static_cast<int>(PropertyAttribute::ReadOnly));
|
||||||
|
|
||||||
if (read_only)
|
if (read_only) {
|
||||||
return;
|
return Intercepted::kNo;
|
||||||
|
}
|
||||||
|
|
||||||
// true for x = 5
|
// true for x = 5
|
||||||
// false for this.x = 5
|
// false for this.x = 5
|
||||||
@ -536,11 +543,16 @@ void ContextifyContext::PropertySetterCallback(
|
|||||||
|
|
||||||
bool is_declared = is_declared_on_global_proxy || is_declared_on_sandbox;
|
bool is_declared = is_declared_on_global_proxy || is_declared_on_sandbox;
|
||||||
if (!is_declared && args.ShouldThrowOnError() && is_contextual_store &&
|
if (!is_declared && args.ShouldThrowOnError() && is_contextual_store &&
|
||||||
!is_function)
|
!is_function) {
|
||||||
return;
|
return Intercepted::kNo;
|
||||||
|
}
|
||||||
|
|
||||||
if (!is_declared && property->IsSymbol()) return;
|
if (!is_declared && property->IsSymbol()) {
|
||||||
if (ctx->sandbox()->Set(context, property, value).IsNothing()) return;
|
return Intercepted::kNo;
|
||||||
|
}
|
||||||
|
if (ctx->sandbox()->Set(context, property, value).IsNothing()) {
|
||||||
|
return Intercepted::kNo;
|
||||||
|
}
|
||||||
|
|
||||||
Local<Value> desc;
|
Local<Value> desc;
|
||||||
if (is_declared_on_sandbox &&
|
if (is_declared_on_sandbox &&
|
||||||
@ -554,19 +566,23 @@ void ContextifyContext::PropertySetterCallback(
|
|||||||
// We have to specify the return value for any contextual or get/set
|
// We have to specify the return value for any contextual or get/set
|
||||||
// property
|
// property
|
||||||
if (desc_obj->HasOwnProperty(context, env->get_string()).FromMaybe(false) ||
|
if (desc_obj->HasOwnProperty(context, env->get_string()).FromMaybe(false) ||
|
||||||
desc_obj->HasOwnProperty(context, env->set_string()).FromMaybe(false))
|
desc_obj->HasOwnProperty(context, env->set_string()).FromMaybe(false)) {
|
||||||
args.GetReturnValue().Set(value);
|
args.GetReturnValue().Set(value);
|
||||||
|
return Intercepted::kYes;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return Intercepted::kNo;
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void ContextifyContext::PropertyDescriptorCallback(
|
Intercepted ContextifyContext::PropertyDescriptorCallback(
|
||||||
Local<Name> property,
|
Local<Name> property, const PropertyCallbackInfo<Value>& args) {
|
||||||
const PropertyCallbackInfo<Value>& args) {
|
|
||||||
ContextifyContext* ctx = ContextifyContext::Get(args);
|
ContextifyContext* ctx = ContextifyContext::Get(args);
|
||||||
|
|
||||||
// Still initializing
|
// Still initializing
|
||||||
if (IsStillInitializing(ctx)) return;
|
if (IsStillInitializing(ctx)) {
|
||||||
|
return Intercepted::kNo;
|
||||||
|
}
|
||||||
|
|
||||||
Local<Context> context = ctx->context();
|
Local<Context> context = ctx->context();
|
||||||
|
|
||||||
@ -576,19 +592,23 @@ void ContextifyContext::PropertyDescriptorCallback(
|
|||||||
Local<Value> desc;
|
Local<Value> desc;
|
||||||
if (sandbox->GetOwnPropertyDescriptor(context, property).ToLocal(&desc)) {
|
if (sandbox->GetOwnPropertyDescriptor(context, property).ToLocal(&desc)) {
|
||||||
args.GetReturnValue().Set(desc);
|
args.GetReturnValue().Set(desc);
|
||||||
|
return Intercepted::kYes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return Intercepted::kNo;
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void ContextifyContext::PropertyDefinerCallback(
|
Intercepted ContextifyContext::PropertyDefinerCallback(
|
||||||
Local<Name> property,
|
Local<Name> property,
|
||||||
const PropertyDescriptor& desc,
|
const PropertyDescriptor& desc,
|
||||||
const PropertyCallbackInfo<Value>& args) {
|
const PropertyCallbackInfo<void>& args) {
|
||||||
ContextifyContext* ctx = ContextifyContext::Get(args);
|
ContextifyContext* ctx = ContextifyContext::Get(args);
|
||||||
|
|
||||||
// Still initializing
|
// Still initializing
|
||||||
if (IsStillInitializing(ctx)) return;
|
if (IsStillInitializing(ctx)) {
|
||||||
|
return Intercepted::kNo;
|
||||||
|
}
|
||||||
|
|
||||||
Local<Context> context = ctx->context();
|
Local<Context> context = ctx->context();
|
||||||
Isolate* isolate = context->GetIsolate();
|
Isolate* isolate = context->GetIsolate();
|
||||||
@ -607,7 +627,7 @@ void ContextifyContext::PropertyDefinerCallback(
|
|||||||
// If the property is set on the global as neither writable nor
|
// If the property is set on the global as neither writable nor
|
||||||
// configurable, don't change it on the global or sandbox.
|
// configurable, don't change it on the global or sandbox.
|
||||||
if (is_declared && read_only && dont_delete) {
|
if (is_declared && read_only && dont_delete) {
|
||||||
return;
|
return Intercepted::kNo;
|
||||||
}
|
}
|
||||||
|
|
||||||
Local<Object> sandbox = ctx->sandbox();
|
Local<Object> sandbox = ctx->sandbox();
|
||||||
@ -630,6 +650,9 @@ void ContextifyContext::PropertyDefinerCallback(
|
|||||||
desc.has_set() ? desc.set() : Undefined(isolate).As<Value>());
|
desc.has_set() ? desc.set() : Undefined(isolate).As<Value>());
|
||||||
|
|
||||||
define_prop_on_sandbox(&desc_for_sandbox);
|
define_prop_on_sandbox(&desc_for_sandbox);
|
||||||
|
// TODO(https://github.com/nodejs/node/issues/52634): this should return
|
||||||
|
// kYes to behave according to the expected semantics.
|
||||||
|
return Intercepted::kNo;
|
||||||
} else {
|
} else {
|
||||||
Local<Value> value =
|
Local<Value> value =
|
||||||
desc.has_value() ? desc.value() : Undefined(isolate).As<Value>();
|
desc.has_value() ? desc.value() : Undefined(isolate).As<Value>();
|
||||||
@ -641,26 +664,33 @@ void ContextifyContext::PropertyDefinerCallback(
|
|||||||
PropertyDescriptor desc_for_sandbox(value);
|
PropertyDescriptor desc_for_sandbox(value);
|
||||||
define_prop_on_sandbox(&desc_for_sandbox);
|
define_prop_on_sandbox(&desc_for_sandbox);
|
||||||
}
|
}
|
||||||
|
// TODO(https://github.com/nodejs/node/issues/52634): this should return
|
||||||
|
// kYes to behave according to the expected semantics.
|
||||||
|
return Intercepted::kNo;
|
||||||
}
|
}
|
||||||
|
return Intercepted::kNo;
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void ContextifyContext::PropertyDeleterCallback(
|
Intercepted ContextifyContext::PropertyDeleterCallback(
|
||||||
Local<Name> property,
|
Local<Name> property, const PropertyCallbackInfo<Boolean>& args) {
|
||||||
const PropertyCallbackInfo<Boolean>& args) {
|
|
||||||
ContextifyContext* ctx = ContextifyContext::Get(args);
|
ContextifyContext* ctx = ContextifyContext::Get(args);
|
||||||
|
|
||||||
// Still initializing
|
// Still initializing
|
||||||
if (IsStillInitializing(ctx)) return;
|
if (IsStillInitializing(ctx)) {
|
||||||
|
return Intercepted::kNo;
|
||||||
|
}
|
||||||
|
|
||||||
Maybe<bool> success = ctx->sandbox()->Delete(ctx->context(), property);
|
Maybe<bool> success = ctx->sandbox()->Delete(ctx->context(), property);
|
||||||
|
|
||||||
if (success.FromMaybe(false))
|
if (success.FromMaybe(false)) {
|
||||||
return;
|
return Intercepted::kNo;
|
||||||
|
}
|
||||||
|
|
||||||
// Delete failed on the sandbox, intercept and do not delete on
|
// Delete failed on the sandbox, intercept and do not delete on
|
||||||
// the global object.
|
// the global object.
|
||||||
args.GetReturnValue().Set(false);
|
args.GetReturnValue().Set(false);
|
||||||
|
return Intercepted::kYes;
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
@ -680,76 +710,83 @@ void ContextifyContext::PropertyEnumeratorCallback(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void ContextifyContext::IndexedPropertyGetterCallback(
|
Intercepted ContextifyContext::IndexedPropertyGetterCallback(
|
||||||
uint32_t index,
|
uint32_t index, const PropertyCallbackInfo<Value>& args) {
|
||||||
const PropertyCallbackInfo<Value>& args) {
|
|
||||||
ContextifyContext* ctx = ContextifyContext::Get(args);
|
ContextifyContext* ctx = ContextifyContext::Get(args);
|
||||||
|
|
||||||
// Still initializing
|
// Still initializing
|
||||||
if (IsStillInitializing(ctx)) return;
|
if (IsStillInitializing(ctx)) {
|
||||||
|
return Intercepted::kNo;
|
||||||
|
}
|
||||||
|
|
||||||
ContextifyContext::PropertyGetterCallback(
|
return ContextifyContext::PropertyGetterCallback(
|
||||||
Uint32ToName(ctx->context(), index), args);
|
Uint32ToName(ctx->context(), index), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Intercepted ContextifyContext::IndexedPropertySetterCallback(
|
||||||
void ContextifyContext::IndexedPropertySetterCallback(
|
|
||||||
uint32_t index,
|
uint32_t index,
|
||||||
Local<Value> value,
|
Local<Value> value,
|
||||||
const PropertyCallbackInfo<Value>& args) {
|
const PropertyCallbackInfo<void>& args) {
|
||||||
ContextifyContext* ctx = ContextifyContext::Get(args);
|
ContextifyContext* ctx = ContextifyContext::Get(args);
|
||||||
|
|
||||||
// Still initializing
|
// Still initializing
|
||||||
if (IsStillInitializing(ctx)) return;
|
if (IsStillInitializing(ctx)) {
|
||||||
|
return Intercepted::kNo;
|
||||||
|
}
|
||||||
|
|
||||||
ContextifyContext::PropertySetterCallback(
|
return ContextifyContext::PropertySetterCallback(
|
||||||
Uint32ToName(ctx->context(), index), value, args);
|
Uint32ToName(ctx->context(), index), value, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void ContextifyContext::IndexedPropertyDescriptorCallback(
|
Intercepted ContextifyContext::IndexedPropertyDescriptorCallback(
|
||||||
uint32_t index,
|
uint32_t index, const PropertyCallbackInfo<Value>& args) {
|
||||||
const PropertyCallbackInfo<Value>& args) {
|
|
||||||
ContextifyContext* ctx = ContextifyContext::Get(args);
|
ContextifyContext* ctx = ContextifyContext::Get(args);
|
||||||
|
|
||||||
// Still initializing
|
// Still initializing
|
||||||
if (IsStillInitializing(ctx)) return;
|
if (IsStillInitializing(ctx)) {
|
||||||
|
return Intercepted::kNo;
|
||||||
|
}
|
||||||
|
|
||||||
ContextifyContext::PropertyDescriptorCallback(
|
return ContextifyContext::PropertyDescriptorCallback(
|
||||||
Uint32ToName(ctx->context(), index), args);
|
Uint32ToName(ctx->context(), index), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Intercepted ContextifyContext::IndexedPropertyDefinerCallback(
|
||||||
void ContextifyContext::IndexedPropertyDefinerCallback(
|
|
||||||
uint32_t index,
|
uint32_t index,
|
||||||
const PropertyDescriptor& desc,
|
const PropertyDescriptor& desc,
|
||||||
const PropertyCallbackInfo<Value>& args) {
|
const PropertyCallbackInfo<void>& args) {
|
||||||
ContextifyContext* ctx = ContextifyContext::Get(args);
|
ContextifyContext* ctx = ContextifyContext::Get(args);
|
||||||
|
|
||||||
// Still initializing
|
// Still initializing
|
||||||
if (IsStillInitializing(ctx)) return;
|
if (IsStillInitializing(ctx)) {
|
||||||
|
return Intercepted::kNo;
|
||||||
|
}
|
||||||
|
|
||||||
ContextifyContext::PropertyDefinerCallback(
|
return ContextifyContext::PropertyDefinerCallback(
|
||||||
Uint32ToName(ctx->context(), index), desc, args);
|
Uint32ToName(ctx->context(), index), desc, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void ContextifyContext::IndexedPropertyDeleterCallback(
|
Intercepted ContextifyContext::IndexedPropertyDeleterCallback(
|
||||||
uint32_t index,
|
uint32_t index, const PropertyCallbackInfo<Boolean>& args) {
|
||||||
const PropertyCallbackInfo<Boolean>& args) {
|
|
||||||
ContextifyContext* ctx = ContextifyContext::Get(args);
|
ContextifyContext* ctx = ContextifyContext::Get(args);
|
||||||
|
|
||||||
// Still initializing
|
// Still initializing
|
||||||
if (IsStillInitializing(ctx)) return;
|
if (IsStillInitializing(ctx)) {
|
||||||
|
return Intercepted::kNo;
|
||||||
|
}
|
||||||
|
|
||||||
Maybe<bool> success = ctx->sandbox()->Delete(ctx->context(), index);
|
Maybe<bool> success = ctx->sandbox()->Delete(ctx->context(), index);
|
||||||
|
|
||||||
if (success.FromMaybe(false))
|
if (success.FromMaybe(false)) {
|
||||||
return;
|
return Intercepted::kNo;
|
||||||
|
}
|
||||||
|
|
||||||
// Delete failed on the sandbox, intercept and do not delete on
|
// Delete failed on the sandbox, intercept and do not delete on
|
||||||
// the global object.
|
// the global object.
|
||||||
args.GetReturnValue().Set(false);
|
args.GetReturnValue().Set(false);
|
||||||
|
return Intercepted::kYes;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContextifyScript::CreatePerIsolateProperties(
|
void ContextifyScript::CreatePerIsolateProperties(
|
||||||
|
@ -96,42 +96,39 @@ class ContextifyContext : public BaseObject {
|
|||||||
const errors::TryCatchScope& try_catch);
|
const errors::TryCatchScope& try_catch);
|
||||||
static void WeakCallback(
|
static void WeakCallback(
|
||||||
const v8::WeakCallbackInfo<ContextifyContext>& data);
|
const v8::WeakCallbackInfo<ContextifyContext>& data);
|
||||||
static void PropertyGetterCallback(
|
static v8::Intercepted PropertyGetterCallback(
|
||||||
v8::Local<v8::Name> property,
|
v8::Local<v8::Name> property,
|
||||||
const v8::PropertyCallbackInfo<v8::Value>& args);
|
const v8::PropertyCallbackInfo<v8::Value>& args);
|
||||||
static void PropertySetterCallback(
|
static v8::Intercepted PropertySetterCallback(
|
||||||
v8::Local<v8::Name> property,
|
v8::Local<v8::Name> property,
|
||||||
v8::Local<v8::Value> value,
|
v8::Local<v8::Value> value,
|
||||||
const v8::PropertyCallbackInfo<v8::Value>& args);
|
const v8::PropertyCallbackInfo<void>& args);
|
||||||
static void PropertyDescriptorCallback(
|
static v8::Intercepted PropertyDescriptorCallback(
|
||||||
v8::Local<v8::Name> property,
|
v8::Local<v8::Name> property,
|
||||||
const v8::PropertyCallbackInfo<v8::Value>& args);
|
const v8::PropertyCallbackInfo<v8::Value>& args);
|
||||||
static void PropertyDefinerCallback(
|
static v8::Intercepted PropertyDefinerCallback(
|
||||||
v8::Local<v8::Name> property,
|
v8::Local<v8::Name> property,
|
||||||
const v8::PropertyDescriptor& desc,
|
const v8::PropertyDescriptor& desc,
|
||||||
const v8::PropertyCallbackInfo<v8::Value>& args);
|
const v8::PropertyCallbackInfo<void>& args);
|
||||||
static void PropertyDeleterCallback(
|
static v8::Intercepted PropertyDeleterCallback(
|
||||||
v8::Local<v8::Name> property,
|
v8::Local<v8::Name> property,
|
||||||
const v8::PropertyCallbackInfo<v8::Boolean>& args);
|
const v8::PropertyCallbackInfo<v8::Boolean>& args);
|
||||||
static void PropertyEnumeratorCallback(
|
static void PropertyEnumeratorCallback(
|
||||||
const v8::PropertyCallbackInfo<v8::Array>& args);
|
const v8::PropertyCallbackInfo<v8::Array>& args);
|
||||||
static void IndexedPropertyGetterCallback(
|
static v8::Intercepted IndexedPropertyGetterCallback(
|
||||||
uint32_t index,
|
uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& args);
|
||||||
const v8::PropertyCallbackInfo<v8::Value>& args);
|
static v8::Intercepted IndexedPropertySetterCallback(
|
||||||
static void IndexedPropertySetterCallback(
|
|
||||||
uint32_t index,
|
uint32_t index,
|
||||||
v8::Local<v8::Value> value,
|
v8::Local<v8::Value> value,
|
||||||
const v8::PropertyCallbackInfo<v8::Value>& args);
|
const v8::PropertyCallbackInfo<void>& args);
|
||||||
static void IndexedPropertyDescriptorCallback(
|
static v8::Intercepted IndexedPropertyDescriptorCallback(
|
||||||
uint32_t index,
|
uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& args);
|
||||||
const v8::PropertyCallbackInfo<v8::Value>& args);
|
static v8::Intercepted IndexedPropertyDefinerCallback(
|
||||||
static void IndexedPropertyDefinerCallback(
|
|
||||||
uint32_t index,
|
uint32_t index,
|
||||||
const v8::PropertyDescriptor& desc,
|
const v8::PropertyDescriptor& desc,
|
||||||
const v8::PropertyCallbackInfo<v8::Value>& args);
|
const v8::PropertyCallbackInfo<void>& args);
|
||||||
static void IndexedPropertyDeleterCallback(
|
static v8::Intercepted IndexedPropertyDeleterCallback(
|
||||||
uint32_t index,
|
uint32_t index, const v8::PropertyCallbackInfo<v8::Boolean>& args);
|
||||||
const v8::PropertyCallbackInfo<v8::Boolean>& args);
|
|
||||||
|
|
||||||
v8::Global<v8::Context> context_;
|
v8::Global<v8::Context> context_;
|
||||||
std::unique_ptr<v8::MicrotaskQueue> microtask_queue_;
|
std::unique_ptr<v8::MicrotaskQueue> microtask_queue_;
|
||||||
|
@ -16,6 +16,7 @@ using v8::DontEnum;
|
|||||||
using v8::FunctionTemplate;
|
using v8::FunctionTemplate;
|
||||||
using v8::HandleScope;
|
using v8::HandleScope;
|
||||||
using v8::Integer;
|
using v8::Integer;
|
||||||
|
using v8::Intercepted;
|
||||||
using v8::Isolate;
|
using v8::Isolate;
|
||||||
using v8::Just;
|
using v8::Just;
|
||||||
using v8::Local;
|
using v8::Local;
|
||||||
@ -336,24 +337,27 @@ Maybe<bool> KVStore::AssignToObject(v8::Isolate* isolate,
|
|||||||
return Just(true);
|
return Just(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void EnvGetter(Local<Name> property,
|
static Intercepted EnvGetter(Local<Name> property,
|
||||||
const PropertyCallbackInfo<Value>& info) {
|
const PropertyCallbackInfo<Value>& info) {
|
||||||
Environment* env = Environment::GetCurrent(info);
|
Environment* env = Environment::GetCurrent(info);
|
||||||
CHECK(env->has_run_bootstrapping_code());
|
CHECK(env->has_run_bootstrapping_code());
|
||||||
if (property->IsSymbol()) {
|
if (property->IsSymbol()) {
|
||||||
return info.GetReturnValue().SetUndefined();
|
info.GetReturnValue().SetUndefined();
|
||||||
|
return Intercepted::kYes;
|
||||||
}
|
}
|
||||||
CHECK(property->IsString());
|
CHECK(property->IsString());
|
||||||
MaybeLocal<String> value_string =
|
MaybeLocal<String> value_string =
|
||||||
env->env_vars()->Get(env->isolate(), property.As<String>());
|
env->env_vars()->Get(env->isolate(), property.As<String>());
|
||||||
if (!value_string.IsEmpty()) {
|
if (!value_string.IsEmpty()) {
|
||||||
info.GetReturnValue().Set(value_string.ToLocalChecked());
|
info.GetReturnValue().Set(value_string.ToLocalChecked());
|
||||||
|
return Intercepted::kYes;
|
||||||
}
|
}
|
||||||
|
return Intercepted::kNo;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void EnvSetter(Local<Name> property,
|
static Intercepted EnvSetter(Local<Name> property,
|
||||||
Local<Value> value,
|
Local<Value> value,
|
||||||
const PropertyCallbackInfo<Value>& info) {
|
const PropertyCallbackInfo<void>& info) {
|
||||||
Environment* env = Environment::GetCurrent(info);
|
Environment* env = Environment::GetCurrent(info);
|
||||||
CHECK(env->has_run_bootstrapping_code());
|
CHECK(env->has_run_bootstrapping_code());
|
||||||
// calling env->EmitProcessEnvWarning() sets a variable indicating that
|
// calling env->EmitProcessEnvWarning() sets a variable indicating that
|
||||||
@ -369,34 +373,39 @@ static void EnvSetter(Local<Name> property,
|
|||||||
"the "
|
"the "
|
||||||
"value to a string before setting process.env with it.",
|
"value to a string before setting process.env with it.",
|
||||||
"DEP0104")
|
"DEP0104")
|
||||||
.IsNothing())
|
.IsNothing()) {
|
||||||
return;
|
return Intercepted::kNo;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Local<String> key;
|
Local<String> key;
|
||||||
Local<String> value_string;
|
Local<String> value_string;
|
||||||
if (!property->ToString(env->context()).ToLocal(&key) ||
|
if (!property->ToString(env->context()).ToLocal(&key) ||
|
||||||
!value->ToString(env->context()).ToLocal(&value_string)) {
|
!value->ToString(env->context()).ToLocal(&value_string)) {
|
||||||
return;
|
return Intercepted::kNo;
|
||||||
}
|
}
|
||||||
|
|
||||||
env->env_vars()->Set(env->isolate(), key, value_string);
|
env->env_vars()->Set(env->isolate(), key, value_string);
|
||||||
|
|
||||||
// Whether it worked or not, always return value.
|
return Intercepted::kYes;
|
||||||
info.GetReturnValue().Set(value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void EnvQuery(Local<Name> property,
|
static Intercepted EnvQuery(Local<Name> property,
|
||||||
const PropertyCallbackInfo<Integer>& info) {
|
const PropertyCallbackInfo<Integer>& info) {
|
||||||
Environment* env = Environment::GetCurrent(info);
|
Environment* env = Environment::GetCurrent(info);
|
||||||
CHECK(env->has_run_bootstrapping_code());
|
CHECK(env->has_run_bootstrapping_code());
|
||||||
if (property->IsString()) {
|
if (property->IsString()) {
|
||||||
int32_t rc = env->env_vars()->Query(env->isolate(), property.As<String>());
|
int32_t rc = env->env_vars()->Query(env->isolate(), property.As<String>());
|
||||||
if (rc != -1) info.GetReturnValue().Set(rc);
|
if (rc != -1) {
|
||||||
|
// Return attributes for the property.
|
||||||
|
info.GetReturnValue().Set(v8::None);
|
||||||
|
return Intercepted::kYes;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return Intercepted::kNo;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void EnvDeleter(Local<Name> property,
|
static Intercepted EnvDeleter(Local<Name> property,
|
||||||
const PropertyCallbackInfo<Boolean>& info) {
|
const PropertyCallbackInfo<Boolean>& info) {
|
||||||
Environment* env = Environment::GetCurrent(info);
|
Environment* env = Environment::GetCurrent(info);
|
||||||
CHECK(env->has_run_bootstrapping_code());
|
CHECK(env->has_run_bootstrapping_code());
|
||||||
@ -407,6 +416,7 @@ static void EnvDeleter(Local<Name> property,
|
|||||||
// process.env never has non-configurable properties, so always
|
// process.env never has non-configurable properties, so always
|
||||||
// return true like the tc39 delete operator.
|
// return true like the tc39 delete operator.
|
||||||
info.GetReturnValue().Set(true);
|
info.GetReturnValue().Set(true);
|
||||||
|
return Intercepted::kYes;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void EnvEnumerator(const PropertyCallbackInfo<Array>& info) {
|
static void EnvEnumerator(const PropertyCallbackInfo<Array>& info) {
|
||||||
@ -417,9 +427,9 @@ static void EnvEnumerator(const PropertyCallbackInfo<Array>& info) {
|
|||||||
env->env_vars()->Enumerate(env->isolate()));
|
env->env_vars()->Enumerate(env->isolate()));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void EnvDefiner(Local<Name> property,
|
static Intercepted EnvDefiner(Local<Name> property,
|
||||||
const PropertyDescriptor& desc,
|
const PropertyDescriptor& desc,
|
||||||
const PropertyCallbackInfo<Value>& info) {
|
const PropertyCallbackInfo<void>& info) {
|
||||||
Environment* env = Environment::GetCurrent(info);
|
Environment* env = Environment::GetCurrent(info);
|
||||||
if (desc.has_value()) {
|
if (desc.has_value()) {
|
||||||
if (!desc.has_writable() ||
|
if (!desc.has_writable() ||
|
||||||
@ -430,6 +440,7 @@ static void EnvDefiner(Local<Name> property,
|
|||||||
"configurable, writable,"
|
"configurable, writable,"
|
||||||
" and enumerable "
|
" and enumerable "
|
||||||
"data descriptor");
|
"data descriptor");
|
||||||
|
return Intercepted::kYes;
|
||||||
} else if (!desc.configurable() ||
|
} else if (!desc.configurable() ||
|
||||||
!desc.enumerable() ||
|
!desc.enumerable() ||
|
||||||
!desc.writable()) {
|
!desc.writable()) {
|
||||||
@ -438,6 +449,7 @@ static void EnvDefiner(Local<Name> property,
|
|||||||
"configurable, writable,"
|
"configurable, writable,"
|
||||||
" and enumerable "
|
" and enumerable "
|
||||||
"data descriptor");
|
"data descriptor");
|
||||||
|
return Intercepted::kYes;
|
||||||
} else {
|
} else {
|
||||||
return EnvSetter(property, desc.value(), info);
|
return EnvSetter(property, desc.value(), info);
|
||||||
}
|
}
|
||||||
@ -447,12 +459,14 @@ static void EnvDefiner(Local<Name> property,
|
|||||||
"'process.env' does not accept an"
|
"'process.env' does not accept an"
|
||||||
" accessor(getter/setter)"
|
" accessor(getter/setter)"
|
||||||
" descriptor");
|
" descriptor");
|
||||||
|
return Intercepted::kYes;
|
||||||
} else {
|
} else {
|
||||||
THROW_ERR_INVALID_OBJECT_DEFINE_PROPERTY(env,
|
THROW_ERR_INVALID_OBJECT_DEFINE_PROPERTY(env,
|
||||||
"'process.env' only accepts a "
|
"'process.env' only accepts a "
|
||||||
"configurable, writable,"
|
"configurable, writable,"
|
||||||
" and enumerable "
|
" and enumerable "
|
||||||
"data descriptor");
|
"data descriptor");
|
||||||
|
return Intercepted::kYes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,16 +67,17 @@ class ExternalReferenceRegistry {
|
|||||||
V(v8::AccessorSetterCallback) \
|
V(v8::AccessorSetterCallback) \
|
||||||
V(v8::AccessorNameGetterCallback) \
|
V(v8::AccessorNameGetterCallback) \
|
||||||
V(v8::AccessorNameSetterCallback) \
|
V(v8::AccessorNameSetterCallback) \
|
||||||
V(v8::GenericNamedPropertyDefinerCallback) \
|
V(v8::NamedPropertyGetterCallback) \
|
||||||
V(v8::GenericNamedPropertyDeleterCallback) \
|
V(v8::NamedPropertyDefinerCallback) \
|
||||||
V(v8::GenericNamedPropertyEnumeratorCallback) \
|
V(v8::NamedPropertyDeleterCallback) \
|
||||||
V(v8::GenericNamedPropertyQueryCallback) \
|
V(v8::NamedPropertyEnumeratorCallback) \
|
||||||
V(v8::GenericNamedPropertySetterCallback) \
|
V(v8::NamedPropertyQueryCallback) \
|
||||||
V(v8::IndexedPropertySetterCallback) \
|
V(v8::NamedPropertySetterCallback) \
|
||||||
V(v8::IndexedPropertyDefinerCallback) \
|
V(v8::IndexedPropertyGetterCallbackV2) \
|
||||||
V(v8::IndexedPropertyDeleterCallback) \
|
V(v8::IndexedPropertySetterCallbackV2) \
|
||||||
V(v8::IndexedPropertyQueryCallback) \
|
V(v8::IndexedPropertyDefinerCallbackV2) \
|
||||||
V(v8::IndexedPropertyDescriptorCallback) \
|
V(v8::IndexedPropertyDeleterCallbackV2) \
|
||||||
|
V(v8::IndexedPropertyQueryCallbackV2) \
|
||||||
V(const v8::String::ExternalStringResourceBase*)
|
V(const v8::String::ExternalStringResourceBase*)
|
||||||
|
|
||||||
#define V(ExternalReferenceType) \
|
#define V(ExternalReferenceType) \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user