Skip to content

Commit 3f6c9d6

Browse files
committed
[v8] Migrate callback data accessors to DataV2()
Use explicit Value casts for callback data that is known to contain JavaScript values, and pass Data directly where supported. Refs: https://issues.chromium.org/issues/559925519
1 parent ebad5b0 commit 3f6c9d6

9 files changed

Lines changed: 20 additions & 17 deletions

File tree

‎doc/api/addons.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ class AddonData {
214214
static void Method(const v8::FunctionCallbackInfo<v8::Value>& info) {
215215
// Retrieve the per-addon-instance data.
216216
AddonData* data =
217-
reinterpret_cast<AddonData*>(info.Data().As<External>()->Value());
217+
reinterpret_cast<AddonData*>(info.DataV2().As<External>()->Value());
218218
data->call_count++;
219219
info.GetReturnValue().Set((double)data->call_count);
220220
}
@@ -982,7 +982,7 @@ void MyObject::New(const FunctionCallbackInfo<Value>& args) {
982982
const int argc = 1;
983983
Local<Value> argv[argc] = { args[0] };
984984
Local<Function> cons =
985-
args.Data().As<Object>()->GetInternalField(0)
985+
args.DataV2().As<Value>().As<Object>()->GetInternalField(0)
986986
.As<Value>().As<Function>();
987987
Local<Object> result =
988988
cons->NewInstance(context, argc, argv).ToLocalChecked();

‎src/js_native_api_v8.cc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ class CallbackBundle {
402402
return cbdata;
403403
}
404404

405-
static CallbackBundle* FromCallbackData(v8::Local<v8::Value> data) {
405+
static CallbackBundle* FromCallbackData(v8::Local<v8::Data> data) {
406406
return reinterpret_cast<CallbackBundle*>(
407407
data.As<v8::External>()->Value(v8::kExternalPointerTypeTagDefault));
408408
}
@@ -491,7 +491,7 @@ class FunctionCallbackWrapper {
491491
explicit FunctionCallbackWrapper(
492492
const v8::FunctionCallbackInfo<v8::Value>& cbinfo)
493493
: cbinfo_(cbinfo),
494-
bundle_(CallbackBundle::FromCallbackData(cbinfo.Data())) {}
494+
bundle_(CallbackBundle::FromCallbackData(cbinfo.DataV2())) {}
495495

496496
void InvokeCallback() {
497497
napi_callback_info cbinfo_wrapper =

‎src/module_wrap.cc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,7 @@ static void ImportMetaResolveLazyGetter(
12591259

12601260
// This should be createImportMetaResolve(). The loader argument is already
12611261
// bound at initialization time.
1262-
Local<Value> args[] = {info.Data()};
1262+
Local<Value> args[] = {info.DataV2().As<Value>()};
12631263
Local<Value> ret;
12641264
if (!initializer
12651265
->Call(context, Undefined(realm->isolate()), arraysize(args), args)
@@ -1290,7 +1290,7 @@ static void PathHelpersLazyGetter(Local<v8::Name> name,
12901290
}
12911291
Environment* env = Environment::GetCurrent(context);
12921292

1293-
node::Utf8Value url(isolate, info.Data());
1293+
node::Utf8Value url(isolate, info.DataV2().As<Value>());
12941294
auto file_url = ada::parse(url.ToStringView());
12951295
CHECK(file_url);
12961296
auto file_path = url::FileURLToPath(env, *file_url);

‎src/node_ffi.cc‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,8 @@ void DynamicLibrary::Close(const FunctionCallbackInfo<Value>& args) {
509509

510510
void DynamicLibrary::InvokeFunction(const FunctionCallbackInfo<Value>& args) {
511511
Environment* env = Environment::GetCurrent(args);
512-
FFIFunctionInfo* info = Unwrap<FFIFunctionInfo>(args.Data());
512+
FFIFunctionInfo* info =
513+
Unwrap<FFIFunctionInfo>(args.DataV2().As<Value>());
513514
CHECK_NOT_NULL(info);
514515
FFIFunction* fn = info->fn.get();
515516

@@ -578,7 +579,8 @@ void DynamicLibrary::InvokeFunction(const FunctionCallbackInfo<Value>& args) {
578579

579580
void DynamicLibrary::InvokeFunctionSB(const FunctionCallbackInfo<Value>& args) {
580581
Environment* env = Environment::GetCurrent(args);
581-
FFIFunctionInfo* info = Unwrap<FFIFunctionInfo>(args.Data());
582+
FFIFunctionInfo* info =
583+
Unwrap<FFIFunctionInfo>(args.DataV2().As<Value>());
582584
CHECK_NOT_NULL(info);
583585
FFIFunction* fn = info->fn.get();
584586

‎src/node_locks.cc‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ static void OnLockCallbackFulfilled(const FunctionCallbackInfo<Value>& info) {
129129
Environment* env = Environment::GetCurrent(info);
130130

131131
BaseObjectPtr<LockHolder> lock_holder{
132-
BaseObject::FromJSObject<LockHolder>(info.Data())};
132+
BaseObject::FromJSObject<LockHolder>(info.DataV2().As<Value>())};
133133
std::shared_ptr<Lock> lock = lock_holder->lock();
134134

135135
// Release the lock and continue processing the queue.
@@ -143,7 +143,7 @@ static void OnLockCallbackRejected(const FunctionCallbackInfo<Value>& info) {
143143
Environment* env = Environment::GetCurrent(info);
144144

145145
BaseObjectPtr<LockHolder> lock_holder{
146-
BaseObject::FromJSObject<LockHolder>(info.Data())};
146+
BaseObject::FromJSObject<LockHolder>(info.DataV2().As<Value>())};
147147
std::shared_ptr<Lock> lock = lock_holder->lock();
148148

149149
LockManager::GetCurrent()->ReleaseLockAndProcessQueue(
@@ -153,13 +153,13 @@ static void OnLockCallbackRejected(const FunctionCallbackInfo<Value>& info) {
153153
// Called when the promise returned from the user's callback resolves
154154
static void OnIfAvailableFulfill(const FunctionCallbackInfo<Value>& info) {
155155
HandleScope handle_scope(info.GetIsolate());
156-
USE(info.Data().As<Promise::Resolver>()->Resolve(
156+
USE(info.DataV2().As<Value>().As<Promise::Resolver>()->Resolve(
157157
info.GetIsolate()->GetCurrentContext(), info[0]));
158158
}
159159

160160
// Called when the promise returned from the user's callback rejects
161161
static void OnIfAvailableReject(const FunctionCallbackInfo<Value>& info) {
162-
USE(info.Data().As<Promise::Resolver>()->Reject(
162+
USE(info.DataV2().As<Value>().As<Promise::Resolver>()->Reject(
163163
info.GetIsolate()->GetCurrentContext(), info[0]));
164164
}
165165

‎src/node_util.cc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ static void DefineLazyPropertiesGetter(
379379
}
380380

381381
Realm* realm = Realm::GetCurrent(context);
382-
Local<Value> arg = info.Data();
382+
Local<Value> arg = info.DataV2().As<Value>();
383383
Local<Value> require_result;
384384
if (!realm->builtin_module_require()
385385
->Call(context, Null(isolate), 1, &arg)

‎src/node_wasm_web_api.cc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ void StartStreamingCompilation(const FunctionCallbackInfo<Value>& info) {
157157

158158
// Create the wrapper object.
159159
std::shared_ptr<WasmStreaming> streaming =
160-
WasmStreaming::Unpack(info.GetIsolate(), info.Data());
160+
WasmStreaming::Unpack(info.GetIsolate(), info.DataV2());
161161
Environment* env = Environment::GetCurrent(info);
162162
Local<Object> obj;
163163
if (!WasmStreamingObject::Create(env, streaming).ToLocal(&obj)) {

‎test/addons/worker-addon-exit/binding.cc‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ void MyObject::New(const FunctionCallbackInfo<Value>& args) {
7272
// Invoked as plain function `MyObject(...)`, turn into construct call.
7373
const int argc = 1;
7474
Local<Value> argv[argc] = {args[0]};
75-
Local<Function> cons = args.Data()
75+
Local<Function> cons = args.DataV2()
76+
.As<Value>()
7677
.As<Object>()
7778
->GetInternalField(0)
7879
.As<Value>()

‎test/cctest/test_environment.cc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ TEST_F(EnvironmentTest, RunAndClearNativeImmediatesSkipsEmptyScope) {
415415
context,
416416
[](const v8::FunctionCallbackInfo<v8::Value>& info) {
417417
IntVec* callback_calls =
418-
static_cast<IntVec*>(info.Data().As<v8::External>()->Value(
418+
static_cast<IntVec*>(info.DataV2().As<v8::External>()->Value(
419419
v8::kExternalPointerTypeTagDefault));
420420
callback_calls->push_back(info[0].As<v8::Int32>()->Value());
421421
},
@@ -772,7 +772,7 @@ TEST_F(EnvironmentTest, NestedMicrotaskQueue) {
772772
context,
773773
[](const v8::FunctionCallbackInfo<v8::Value>& info) {
774774
IntVec* callback_calls =
775-
static_cast<IntVec*>(info.Data().As<v8::External>()->Value(
775+
static_cast<IntVec*>(info.DataV2().As<v8::External>()->Value(
776776
v8::kExternalPointerTypeTagDefault));
777777
callback_calls->push_back(info[0].As<v8::Int32>()->Value());
778778
},

0 commit comments

Comments
 (0)