Skip to content

Commit

Permalink
src: use args.This() instead of Holder
Browse files Browse the repository at this point in the history
The latter is deprecated in V8.

Refs: http://crbug.com/333672197
PR-URL: #53474
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
  • Loading branch information
targos committed Jun 20, 2024
1 parent 977beab commit 15df4ed
Show file tree
Hide file tree
Showing 50 changed files with 356 additions and 382 deletions.
4 changes: 2 additions & 2 deletions doc/api/addons.md
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ void MyObject::New(const FunctionCallbackInfo<Value>& args) {
void MyObject::PlusOne(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();

MyObject* obj = ObjectWrap::Unwrap<MyObject>(args.Holder());
MyObject* obj = ObjectWrap::Unwrap<MyObject>(args.This());
obj->value_ += 1;

args.GetReturnValue().Set(Number::New(isolate, obj->value_));
Expand Down Expand Up @@ -1138,7 +1138,7 @@ void MyObject::NewInstance(const FunctionCallbackInfo<Value>& args) {
void MyObject::PlusOne(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();

MyObject* obj = ObjectWrap::Unwrap<MyObject>(args.Holder());
MyObject* obj = ObjectWrap::Unwrap<MyObject>(args.This());
obj->value_ += 1;

args.GetReturnValue().Set(Number::New(isolate, obj->value_));
Expand Down
6 changes: 2 additions & 4 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,6 @@ Node.js source code.)

`args[n]` is a `Local<Value>` that represents the n-th argument passed to the
function. `args.This()` is the `this` value inside this function call.
`args.Holder()` is equivalent to `args.This()` in all use cases inside of
Node.js.

`args.GetReturnValue()` is a placeholder for the return value of the function,
and provides a `.Set()` method that can be called with a boolean, integer,
Expand Down Expand Up @@ -829,7 +827,7 @@ The JavaScript object can be accessed as a `v8::Local<v8::Object>` by using
`self->object()`, given a `BaseObject` named `self`.

Accessing a `BaseObject` from a `v8::Local<v8::Object>` (frequently that is
`args.This()` or `args.Holder()` in a [binding function][]) can be done using
`args.This()` in a [binding function][]) can be done using
the `Unwrap<T>(obj)` function, where `T` is a subclass of `BaseObject`.
A helper for this is the `ASSIGN_OR_RETURN_UNWRAP` macro that returns from the
current function if unwrapping fails (typically that means that the `BaseObject`
Expand All @@ -838,7 +836,7 @@ has been deleted earlier).
```cpp
void Http2Session::Request(const FunctionCallbackInfo<Value>& args) {
Http2Session* session;
ASSIGN_OR_RETURN_UNWRAP(&session, args.Holder());
ASSIGN_OR_RETURN_UNWRAP(&session, args.This());
Environment* env = session->env();
Local<Context> context = env->context();
Isolate* isolate = env->isolate();
Expand Down
6 changes: 3 additions & 3 deletions src/async_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ static void RegisterDestroyHook(const FunctionCallbackInfo<Value>& args) {
void AsyncWrap::GetAsyncId(const FunctionCallbackInfo<Value>& args) {
AsyncWrap* wrap;
args.GetReturnValue().Set(kInvalidAsyncId);
ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
ASSIGN_OR_RETURN_UNWRAP(&wrap, args.This());
args.GetReturnValue().Set(wrap->get_async_id());
}

Expand Down Expand Up @@ -296,7 +296,7 @@ void AsyncWrap::AsyncReset(const FunctionCallbackInfo<Value>& args) {
CHECK(args[0]->IsObject());

AsyncWrap* wrap;
ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
ASSIGN_OR_RETURN_UNWRAP(&wrap, args.This());

Local<Object> resource = args[0].As<Object>();
double execution_async_id =
Expand All @@ -308,7 +308,7 @@ void AsyncWrap::AsyncReset(const FunctionCallbackInfo<Value>& args) {
void AsyncWrap::GetProviderType(const FunctionCallbackInfo<Value>& args) {
AsyncWrap* wrap;
args.GetReturnValue().Set(AsyncWrap::PROVIDER_NONE);
ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
ASSIGN_OR_RETURN_UNWRAP(&wrap, args.This());
args.GetReturnValue().Set(wrap->provider_type());
}

Expand Down
10 changes: 5 additions & 5 deletions src/cares_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,7 @@ template <class Wrap>
static void Query(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
ChannelWrap* channel;
ASSIGN_OR_RETURN_UNWRAP(&channel, args.Holder());
ASSIGN_OR_RETURN_UNWRAP(&channel, args.This());

CHECK_EQ(false, args.IsConstructCall());
CHECK(args[0]->IsObject());
Expand Down Expand Up @@ -1664,7 +1664,7 @@ void GetNameInfo(const FunctionCallbackInfo<Value>& args) {
void GetServers(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
ChannelWrap* channel;
ASSIGN_OR_RETURN_UNWRAP(&channel, args.Holder());
ASSIGN_OR_RETURN_UNWRAP(&channel, args.This());

Local<Array> server_array = Array::New(env->isolate());

Expand Down Expand Up @@ -1702,7 +1702,7 @@ void GetServers(const FunctionCallbackInfo<Value>& args) {
void SetServers(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
ChannelWrap* channel;
ASSIGN_OR_RETURN_UNWRAP(&channel, args.Holder());
ASSIGN_OR_RETURN_UNWRAP(&channel, args.This());

if (channel->active_query_count()) {
return args.GetReturnValue().Set(DNS_ESETSRVPENDING);
Expand Down Expand Up @@ -1783,7 +1783,7 @@ void SetServers(const FunctionCallbackInfo<Value>& args) {
void SetLocalAddress(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
ChannelWrap* channel;
ASSIGN_OR_RETURN_UNWRAP(&channel, args.Holder());
ASSIGN_OR_RETURN_UNWRAP(&channel, args.This());

CHECK_EQ(args.Length(), 2);
CHECK(args[0]->IsString());
Expand Down Expand Up @@ -1846,7 +1846,7 @@ void SetLocalAddress(const FunctionCallbackInfo<Value>& args) {

void Cancel(const FunctionCallbackInfo<Value>& args) {
ChannelWrap* channel;
ASSIGN_OR_RETURN_UNWRAP(&channel, args.Holder());
ASSIGN_OR_RETURN_UNWRAP(&channel, args.This());

TRACE_EVENT_INSTANT0(TRACING_CATEGORY_NODE2(dns, native),
"cancel", TRACE_EVENT_SCOPE_THREAD);
Expand Down
14 changes: 7 additions & 7 deletions src/crypto/crypto_cipher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ void CipherBase::Init(const char* cipher_type,

void CipherBase::Init(const FunctionCallbackInfo<Value>& args) {
CipherBase* cipher;
ASSIGN_OR_RETURN_UNWRAP(&cipher, args.Holder());
ASSIGN_OR_RETURN_UNWRAP(&cipher, args.This());
Environment* env = Environment::GetCurrent(args);

CHECK_GE(args.Length(), 3);
Expand Down Expand Up @@ -510,7 +510,7 @@ void CipherBase::InitIv(const char* cipher_type,

void CipherBase::InitIv(const FunctionCallbackInfo<Value>& args) {
CipherBase* cipher;
ASSIGN_OR_RETURN_UNWRAP(&cipher, args.Holder());
ASSIGN_OR_RETURN_UNWRAP(&cipher, args.This());
Environment* env = cipher->env();

CHECK_GE(args.Length(), 4);
Expand Down Expand Up @@ -645,7 +645,7 @@ bool CipherBase::IsAuthenticatedMode() const {
void CipherBase::GetAuthTag(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
CipherBase* cipher;
ASSIGN_OR_RETURN_UNWRAP(&cipher, args.Holder());
ASSIGN_OR_RETURN_UNWRAP(&cipher, args.This());

// Only callable after Final and if encrypting.
if (cipher->ctx_ ||
Expand All @@ -661,7 +661,7 @@ void CipherBase::GetAuthTag(const FunctionCallbackInfo<Value>& args) {

void CipherBase::SetAuthTag(const FunctionCallbackInfo<Value>& args) {
CipherBase* cipher;
ASSIGN_OR_RETURN_UNWRAP(&cipher, args.Holder());
ASSIGN_OR_RETURN_UNWRAP(&cipher, args.This());
Environment* env = Environment::GetCurrent(args);

if (!cipher->ctx_ ||
Expand Down Expand Up @@ -774,7 +774,7 @@ bool CipherBase::SetAAD(

void CipherBase::SetAAD(const FunctionCallbackInfo<Value>& args) {
CipherBase* cipher;
ASSIGN_OR_RETURN_UNWRAP(&cipher, args.Holder());
ASSIGN_OR_RETURN_UNWRAP(&cipher, args.This());
Environment* env = Environment::GetCurrent(args);

CHECK_EQ(args.Length(), 2);
Expand Down Expand Up @@ -887,7 +887,7 @@ bool CipherBase::SetAutoPadding(bool auto_padding) {

void CipherBase::SetAutoPadding(const FunctionCallbackInfo<Value>& args) {
CipherBase* cipher;
ASSIGN_OR_RETURN_UNWRAP(&cipher, args.Holder());
ASSIGN_OR_RETURN_UNWRAP(&cipher, args.This());

bool b = cipher->SetAutoPadding(args.Length() < 1 || args[0]->IsTrue());
args.GetReturnValue().Set(b); // Possibly report invalid state failure
Expand Down Expand Up @@ -962,7 +962,7 @@ void CipherBase::Final(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);

CipherBase* cipher;
ASSIGN_OR_RETURN_UNWRAP(&cipher, args.Holder());
ASSIGN_OR_RETURN_UNWRAP(&cipher, args.This());
if (cipher->ctx_ == nullptr)
return THROW_ERR_CRYPTO_INVALID_STATE(env);

Expand Down
Loading

0 comments on commit 15df4ed

Please sign in to comment.