Skip to content
Merged
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
46 changes: 25 additions & 21 deletions test/addons/async-resource/binding.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include "node.h"

#include <assert.h>

#include <vector>

#include "node.h"

namespace {

using node::AsyncResource;
Expand All @@ -23,9 +24,7 @@ class CustomAsyncResource : public AsyncResource {
public:
CustomAsyncResource(Isolate* isolate, Local<Object> resource)
: AsyncResource(isolate, resource, "CustomAsyncResource") {}
~CustomAsyncResource() {
custom_async_resource_destructor_calls++;
}
~CustomAsyncResource() { custom_async_resource_destructor_calls++; }
};

void CreateAsyncResource(const FunctionCallbackInfo<Value>& args) {
Expand All @@ -39,26 +38,27 @@ void CreateAsyncResource(const FunctionCallbackInfo<Value>& args) {
r = new AsyncResource(isolate, args[0].As<Object>(), "foobär");
}

args.GetReturnValue().Set(
External::New(isolate, static_cast<void*>(r)));
args.GetReturnValue().Set(External::New(isolate, static_cast<void*>(r),
v8::kExternalPointerTypeTagDefault));
}

void DestroyAsyncResource(const FunctionCallbackInfo<Value>& args) {
assert(args[0]->IsExternal());
auto r = static_cast<AsyncResource*>(args[0].As<External>()->Value());
auto r = static_cast<AsyncResource*>(
args[0].As<External>()->Value(v8::kExternalPointerTypeTagDefault));
delete r;
}

void CallViaFunction(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
assert(args[0]->IsExternal());
auto r = static_cast<AsyncResource*>(args[0].As<External>()->Value());
auto r = static_cast<AsyncResource*>(
args[0].As<External>()->Value(v8::kExternalPointerTypeTagDefault));

Local<String> name =
String::NewFromUtf8(isolate, "methöd").ToLocalChecked();
Local<Value> fn =
r->get_resource()->Get(isolate->GetCurrentContext(), name)
.ToLocalChecked();
Local<String> name = String::NewFromUtf8(isolate, "methöd").ToLocalChecked();
Local<Value> fn = r->get_resource()
->Get(isolate->GetCurrentContext(), name)
.ToLocalChecked();
assert(fn->IsFunction());

Local<Value> arg = Integer::New(isolate, 42);
Expand All @@ -69,10 +69,10 @@ void CallViaFunction(const FunctionCallbackInfo<Value>& args) {
void CallViaString(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
assert(args[0]->IsExternal());
auto r = static_cast<AsyncResource*>(args[0].As<External>()->Value());
auto r = static_cast<AsyncResource*>(
args[0].As<External>()->Value(v8::kExternalPointerTypeTagDefault));

Local<String> name =
String::NewFromUtf8(isolate, "methöd").ToLocalChecked();
Local<String> name = String::NewFromUtf8(isolate, "methöd").ToLocalChecked();

Local<Value> arg = Integer::New(isolate, 42);
MaybeLocal<Value> ret = r->MakeCallback(name, 1, &arg);
Expand All @@ -82,7 +82,8 @@ void CallViaString(const FunctionCallbackInfo<Value>& args) {
void CallViaUtf8Name(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
assert(args[0]->IsExternal());
auto r = static_cast<AsyncResource*>(args[0].As<External>()->Value());
auto r = static_cast<AsyncResource*>(
args[0].As<External>()->Value(v8::kExternalPointerTypeTagDefault));

Local<Value> arg = Integer::New(isolate, 42);
MaybeLocal<Value> ret = r->MakeCallback("methöd", 1, &arg);
Expand All @@ -91,19 +92,22 @@ void CallViaUtf8Name(const FunctionCallbackInfo<Value>& args) {

void GetAsyncId(const FunctionCallbackInfo<Value>& args) {
assert(args[0]->IsExternal());
auto r = static_cast<AsyncResource*>(args[0].As<External>()->Value());
auto r = static_cast<AsyncResource*>(
args[0].As<External>()->Value(v8::kExternalPointerTypeTagDefault));
args.GetReturnValue().Set(r->get_async_id());
}

void GetTriggerAsyncId(const FunctionCallbackInfo<Value>& args) {
assert(args[0]->IsExternal());
auto r = static_cast<AsyncResource*>(args[0].As<External>()->Value());
auto r = static_cast<AsyncResource*>(
args[0].As<External>()->Value(v8::kExternalPointerTypeTagDefault));
args.GetReturnValue().Set(r->get_trigger_async_id());
}

void GetResource(const FunctionCallbackInfo<Value>& args) {
assert(args[0]->IsExternal());
auto r = static_cast<AsyncResource*>(args[0].As<External>()->Value());
auto r = static_cast<AsyncResource*>(
args[0].As<External>()->Value(v8::kExternalPointerTypeTagDefault));
args.GetReturnValue().Set(r->get_resource());
}

Expand Down
Loading