Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: do not use deprecated V8 API #53084

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions src/base_object-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,18 @@ v8::EmbedderGraph::Node::Detachedness BaseObject::GetDetachedness() const {

template <int Field>
void BaseObject::InternalFieldGet(
v8::Local<v8::String> property,
const v8::PropertyCallbackInfo<v8::Value>& info) {
info.GetReturnValue().Set(
info.This()->GetInternalField(Field).As<v8::Value>());
const v8::FunctionCallbackInfo<v8::Value>& args) {
args.GetReturnValue().Set(
args.This()->GetInternalField(Field).As<v8::Value>());
}

template <int Field, bool (v8::Value::* typecheck)() const>
void BaseObject::InternalFieldSet(v8::Local<v8::String> property,
v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<void>& info) {
template <int Field, bool (v8::Value::*typecheck)() const>
void BaseObject::InternalFieldSet(
const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Local<v8::Value> value = args[0];
// This could be e.g. value->IsFunction().
CHECK(((*value)->*typecheck)());
info.This()->SetInternalField(Field, value);
args.This()->SetInternalField(Field, value);
}

bool BaseObject::has_pointer_data() const {
Expand Down
7 changes: 2 additions & 5 deletions src/base_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,9 @@ class BaseObject : public MemoryRetainer {

// Setter/Getter pair for internal fields that can be passed to SetAccessor.
template <int Field>
static void InternalFieldGet(v8::Local<v8::String> property,
const v8::PropertyCallbackInfo<v8::Value>& info);
static void InternalFieldGet(const v8::FunctionCallbackInfo<v8::Value>& args);
template <int Field, bool (v8::Value::*typecheck)() const>
static void InternalFieldSet(v8::Local<v8::String> property,
v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<void>& info);
static void InternalFieldSet(const v8::FunctionCallbackInfo<v8::Value>& args);

// This is a bit of a hack. See the override in async_wrap.cc for details.
virtual bool IsDoneInitializing() const;
Expand Down
5 changes: 0 additions & 5 deletions src/node_builtins.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ namespace node {
namespace builtins {

using v8::Context;
using v8::DEFAULT;
using v8::EscapableHandleScope;
using v8::Function;
using v8::FunctionCallbackInfo;
Expand Down Expand Up @@ -710,15 +709,13 @@ void BuiltinLoader::CreatePerIsolateProperties(IsolateData* isolate_data,
nullptr,
Local<Value>(),
None,
DEFAULT,
SideEffectType::kHasNoSideEffect);

target->SetNativeDataProperty(FIXED_ONE_BYTE_STRING(isolate, "builtinIds"),
BuiltinIdsGetter,
nullptr,
Local<Value>(),
None,
DEFAULT,
SideEffectType::kHasNoSideEffect);

target->SetNativeDataProperty(
Expand All @@ -727,15 +724,13 @@ void BuiltinLoader::CreatePerIsolateProperties(IsolateData* isolate_data,
nullptr,
Local<Value>(),
None,
DEFAULT,
SideEffectType::kHasNoSideEffect);

target->SetNativeDataProperty(FIXED_ONE_BYTE_STRING(isolate, "natives"),
GetNatives,
nullptr,
Local<Value>(),
None,
DEFAULT,
SideEffectType::kHasNoSideEffect);

SetMethod(isolate, target, "getCacheUsage", BuiltinLoader::GetCacheUsage);
Expand Down
2 changes: 0 additions & 2 deletions src/node_external_reference.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ class ExternalReferenceRegistry {
V(CFunctionWithBool) \
V(const v8::CFunctionInfo*) \
V(v8::FunctionCallback) \
V(v8::AccessorGetterCallback) \
V(v8::AccessorSetterCallback) \
V(v8::AccessorNameGetterCallback) \
V(v8::AccessorNameSetterCallback) \
V(v8::NamedPropertyGetterCallback) \
Expand Down
36 changes: 31 additions & 5 deletions src/stream_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,29 @@ Local<Object> StreamBase::GetObject() {
return GetAsyncWrap()->object();
}

void StreamBase::AddAccessor(v8::Isolate* isolate,
v8::Local<v8::Signature> signature,
enum v8::PropertyAttribute attributes,
v8::Local<v8::FunctionTemplate> t,
JSMethodFunction* getter,
JSMethodFunction* setter,
v8::Local<v8::String> string) {
Local<FunctionTemplate> getter_templ =
NewFunctionTemplate(isolate,
getter,
signature,
ConstructorBehavior::kThrow,
SideEffectType::kHasNoSideEffect);
Local<FunctionTemplate> setter_templ =
NewFunctionTemplate(isolate,
setter,
signature,
ConstructorBehavior::kThrow,
SideEffectType::kHasSideEffect);
t->PrototypeTemplate()->SetAccessorProperty(
string, getter_templ, setter_templ, attributes);
}

void StreamBase::AddMethod(Isolate* isolate,
Local<Signature> signature,
enum PropertyAttribute attributes,
Expand Down Expand Up @@ -561,11 +584,14 @@ void StreamBase::AddMethods(IsolateData* isolate_data,
JSMethod<&StreamBase::WriteString<LATIN1>>);
t->PrototypeTemplate()->Set(FIXED_ONE_BYTE_STRING(isolate, "isStreamBase"),
True(isolate));
t->PrototypeTemplate()->SetAccessor(
FIXED_ONE_BYTE_STRING(isolate, "onread"),
BaseObject::InternalFieldGet<StreamBase::kOnReadFunctionField>,
BaseObject::InternalFieldSet<StreamBase::kOnReadFunctionField,
&Value::IsFunction>);
AddAccessor(isolate,
sig,
static_cast<PropertyAttribute>(DontDelete | DontEnum),
t,
BaseObject::InternalFieldGet<StreamBase::kOnReadFunctionField>,
BaseObject::InternalFieldSet<StreamBase::kOnReadFunctionField,
&Value::IsFunction>,
FIXED_ONE_BYTE_STRING(isolate, "onread"));
}

void StreamBase::RegisterExternalReferences(
Expand Down
7 changes: 7 additions & 0 deletions src/stream_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,13 @@ class StreamBase : public StreamResource {
EmitToJSStreamListener default_listener_;

void SetWriteResult(const StreamWriteResult& res);
static void AddAccessor(v8::Isolate* isolate,
v8::Local<v8::Signature> sig,
enum v8::PropertyAttribute attributes,
v8::Local<v8::FunctionTemplate> t,
JSMethodFunction* getter,
JSMethodFunction* setter,
v8::Local<v8::String> str);
static void AddMethod(v8::Isolate* isolate,
v8::Local<v8::Signature> sig,
enum v8::PropertyAttribute attributes,
Expand Down