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

benchmark: update function_args addon code #34725

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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1268,7 +1268,7 @@ LINT_CPP_EXCLUDE += $(wildcard test/js-native-api/??_*/*.cc test/js-native-api/?
LINT_CPP_EXCLUDE += src/tracing/trace_event.h src/tracing/trace_event_common.h

LINT_CPP_FILES = $(filter-out $(LINT_CPP_EXCLUDE), $(wildcard \
benchmark/napi/function_call/binding.cc \
benchmark/napi/*/*.cc \
src/*.c \
src/*.cc \
src/*.h \
Expand Down
32 changes: 16 additions & 16 deletions benchmark/napi/function_args/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
#include <node.h>
#include <assert.h>

using v8::Isolate;
using v8::Array;
using v8::ArrayBuffer;
using v8::ArrayBufferView;
using v8::BackingStore;
using v8::Context;
using v8::FunctionCallbackInfo;
using v8::Isolate;
using v8::Local;
using v8::MaybeLocal;
using v8::Value;
using v8::Number;
using v8::String;
using v8::Object;
using v8::Array;
using v8::ArrayBufferView;
using v8::ArrayBuffer;
using v8::FunctionCallbackInfo;
using v8::String;
using v8::Uint32;
using v8::Value;

void CallWithString(const FunctionCallbackInfo<Value>& args) {
assert(args.Length() == 1 && args[0]->IsString());
Expand All @@ -22,7 +24,7 @@ void CallWithString(const FunctionCallbackInfo<Value>& args) {
const int32_t length = str->Utf8Length(args.GetIsolate()) + 1;
char* buf = new char[length];
str->WriteUtf8(args.GetIsolate(), buf, length);
delete [] buf;
delete[] buf;
}
}

Expand All @@ -31,7 +33,7 @@ void CallWithArray(const FunctionCallbackInfo<Value>& args) {
if (args.Length() == 1 && args[0]->IsArray()) {
const Local<Array> array = args[0].As<Array>();
uint32_t length = array->Length();
for (uint32_t i = 0; i < length; ++ i) {
for (uint32_t i = 0; i < length; i++) {
Local<Value> v;
v = array->Get(args.GetIsolate()->GetCurrentContext(),
i).ToLocalChecked();
Expand Down Expand Up @@ -101,24 +103,22 @@ void CallWithTypedarray(const FunctionCallbackInfo<Value>& args) {
const size_t byte_length = view->ByteLength();
assert(byte_length > 0);
assert(view->HasBuffer());
Local<ArrayBuffer> buffer;
buffer = view->Buffer();
ArrayBuffer::Contents contents;
contents = buffer->GetContents();
Local<ArrayBuffer> buffer = view->Buffer();
std::shared_ptr<BackingStore> bs = buffer->GetBackingStore();
const uint32_t* data = reinterpret_cast<uint32_t*>(
static_cast<uint8_t*>(contents.Data()) + byte_offset);
static_cast<uint8_t*>(bs->Data()) + byte_offset);
assert(data);
}
}

void CallWithArguments(const FunctionCallbackInfo<Value>& args) {
assert(args.Length() > 1 && args[0]->IsNumber());
if (args.Length() > 1 && args[0]->IsNumber()) {
int32_t loop = args[0].As<v8::Uint32>()->Value();
int32_t loop = args[0].As<Uint32>()->Value();
for (int32_t i = 1; i < loop; ++i) {
assert(i < args.Length());
assert(args[i]->IsUint32());
args[i].As<v8::Uint32>()->Value();
args[i].As<Uint32>()->Value();
}
}
}
Expand Down