Skip to content

Commit

Permalink
src: reformat all code
Browse files Browse the repository at this point in the history
Reformat all code to pass current linter checks

PR-URL: #1160
Reviewed-By: Michael Dawson <[email protected]
Reviewed-By: Nicola Del Gobbo <[email protected]>
Reviewed-By: Chengzhong Wu <[email protected]>
  • Loading branch information
KevinEady authored and mhdawson committed May 10, 2022
1 parent 33e4029 commit 10b440f
Show file tree
Hide file tree
Showing 107 changed files with 6,116 additions and 5,763 deletions.
157 changes: 95 additions & 62 deletions benchmark/function_args.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "napi.h"

static napi_value NoArgFunction_Core(napi_env env, napi_callback_info info) {
(void) env;
(void) info;
(void)env;
(void)info;
return nullptr;
}

Expand All @@ -12,7 +12,7 @@ static napi_value OneArgFunction_Core(napi_env env, napi_callback_info info) {
if (napi_get_cb_info(env, info, &argc, &argv, nullptr, nullptr) != napi_ok) {
return nullptr;
}
(void) argv;
(void)argv;
return nullptr;
}

Expand All @@ -22,8 +22,8 @@ static napi_value TwoArgFunction_Core(napi_env env, napi_callback_info info) {
if (napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr) != napi_ok) {
return nullptr;
}
(void) argv[0];
(void) argv[1];
(void)argv[0];
(void)argv[1];
return nullptr;
}

Expand All @@ -33,9 +33,9 @@ static napi_value ThreeArgFunction_Core(napi_env env, napi_callback_info info) {
if (napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr) != napi_ok) {
return nullptr;
}
(void) argv[0];
(void) argv[1];
(void) argv[2];
(void)argv[0];
(void)argv[1];
(void)argv[2];
return nullptr;
}

Expand All @@ -45,95 +45,128 @@ static napi_value FourArgFunction_Core(napi_env env, napi_callback_info info) {
if (napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr) != napi_ok) {
return nullptr;
}
(void) argv[0];
(void) argv[1];
(void) argv[2];
(void) argv[3];
(void)argv[0];
(void)argv[1];
(void)argv[2];
(void)argv[3];
return nullptr;
}

static void NoArgFunction(const Napi::CallbackInfo& info) {
(void) info;
(void)info;
}

static void OneArgFunction(const Napi::CallbackInfo& info) {
Napi::Value argv0 = info[0]; (void) argv0;
Napi::Value argv0 = info[0];
(void)argv0;
}

static void TwoArgFunction(const Napi::CallbackInfo& info) {
Napi::Value argv0 = info[0]; (void) argv0;
Napi::Value argv1 = info[1]; (void) argv1;
Napi::Value argv0 = info[0];
(void)argv0;
Napi::Value argv1 = info[1];
(void)argv1;
}

static void ThreeArgFunction(const Napi::CallbackInfo& info) {
Napi::Value argv0 = info[0]; (void) argv0;
Napi::Value argv1 = info[1]; (void) argv1;
Napi::Value argv2 = info[2]; (void) argv2;
Napi::Value argv0 = info[0];
(void)argv0;
Napi::Value argv1 = info[1];
(void)argv1;
Napi::Value argv2 = info[2];
(void)argv2;
}

static void FourArgFunction(const Napi::CallbackInfo& info) {
Napi::Value argv0 = info[0]; (void) argv0;
Napi::Value argv1 = info[1]; (void) argv1;
Napi::Value argv2 = info[2]; (void) argv2;
Napi::Value argv3 = info[3]; (void) argv3;
Napi::Value argv0 = info[0];
(void)argv0;
Napi::Value argv1 = info[1];
(void)argv1;
Napi::Value argv2 = info[2];
(void)argv2;
Napi::Value argv3 = info[3];
(void)argv3;
}

#if NAPI_VERSION > 5
class FunctionArgsBenchmark : public Napi::Addon<FunctionArgsBenchmark> {
public:
FunctionArgsBenchmark(Napi::Env env, Napi::Object exports) {
DefineAddon(exports, {
InstanceValue("addon", DefineProperties(Napi::Object::New(env), {
InstanceMethod("noArgFunction", &FunctionArgsBenchmark::NoArgFunction),
InstanceMethod("oneArgFunction",
&FunctionArgsBenchmark::OneArgFunction),
InstanceMethod("twoArgFunction",
&FunctionArgsBenchmark::TwoArgFunction),
InstanceMethod("threeArgFunction",
&FunctionArgsBenchmark::ThreeArgFunction),
InstanceMethod("fourArgFunction",
&FunctionArgsBenchmark::FourArgFunction),
}), napi_enumerable),
InstanceValue("addon_templated",
DefineProperties(Napi::Object::New(env), {
InstanceMethod<&FunctionArgsBenchmark::NoArgFunction>(
"noArgFunction"),
InstanceMethod<&FunctionArgsBenchmark::OneArgFunction>(
"oneArgFunction"),
InstanceMethod<&FunctionArgsBenchmark::TwoArgFunction>(
"twoArgFunction"),
InstanceMethod<&FunctionArgsBenchmark::ThreeArgFunction>(
"threeArgFunction"),
InstanceMethod<&FunctionArgsBenchmark::FourArgFunction>(
"fourArgFunction"),
}), napi_enumerable),
});
DefineAddon(
exports,
{
InstanceValue(
"addon",
DefineProperties(
Napi::Object::New(env),
{
InstanceMethod("noArgFunction",
&FunctionArgsBenchmark::NoArgFunction),
InstanceMethod("oneArgFunction",
&FunctionArgsBenchmark::OneArgFunction),
InstanceMethod("twoArgFunction",
&FunctionArgsBenchmark::TwoArgFunction),
InstanceMethod(
"threeArgFunction",
&FunctionArgsBenchmark::ThreeArgFunction),
InstanceMethod("fourArgFunction",
&FunctionArgsBenchmark::FourArgFunction),
}),
napi_enumerable),
InstanceValue(
"addon_templated",
DefineProperties(
Napi::Object::New(env),
{
InstanceMethod<&FunctionArgsBenchmark::NoArgFunction>(
"noArgFunction"),
InstanceMethod<&FunctionArgsBenchmark::OneArgFunction>(
"oneArgFunction"),
InstanceMethod<&FunctionArgsBenchmark::TwoArgFunction>(
"twoArgFunction"),
InstanceMethod<
&FunctionArgsBenchmark::ThreeArgFunction>(
"threeArgFunction"),
InstanceMethod<&FunctionArgsBenchmark::FourArgFunction>(
"fourArgFunction"),
}),
napi_enumerable),
});
}

private:
void NoArgFunction(const Napi::CallbackInfo& info) {
(void) info;
}
void NoArgFunction(const Napi::CallbackInfo& info) { (void)info; }

void OneArgFunction(const Napi::CallbackInfo& info) {
Napi::Value argv0 = info[0]; (void) argv0;
Napi::Value argv0 = info[0];
(void)argv0;
}

void TwoArgFunction(const Napi::CallbackInfo& info) {
Napi::Value argv0 = info[0]; (void) argv0;
Napi::Value argv1 = info[1]; (void) argv1;
Napi::Value argv0 = info[0];
(void)argv0;
Napi::Value argv1 = info[1];
(void)argv1;
}

void ThreeArgFunction(const Napi::CallbackInfo& info) {
Napi::Value argv0 = info[0]; (void) argv0;
Napi::Value argv1 = info[1]; (void) argv1;
Napi::Value argv2 = info[2]; (void) argv2;
Napi::Value argv0 = info[0];
(void)argv0;
Napi::Value argv1 = info[1];
(void)argv1;
Napi::Value argv2 = info[2];
(void)argv2;
}

void FourArgFunction(const Napi::CallbackInfo& info) {
Napi::Value argv0 = info[0]; (void) argv0;
Napi::Value argv1 = info[1]; (void) argv1;
Napi::Value argv2 = info[2]; (void) argv2;
Napi::Value argv3 = info[3]; (void) argv3;
Napi::Value argv0 = info[0];
(void)argv0;
Napi::Value argv1 = info[1];
(void)argv1;
Napi::Value argv2 = info[2];
(void)argv2;
Napi::Value argv3 = info[3];
(void)argv3;
}
};
#endif // NAPI_VERSION > 5
Expand Down
12 changes: 6 additions & 6 deletions benchmark/function_args.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const path = require('path');
const Benchmark = require('benchmark');
const addonName = path.basename(__filename, '.js');

[ addonName, addonName + '_noexcept' ]
[addonName, addonName + '_noexcept']
.forEach((addonName) => {
const rootAddon = require('bindings')({
bindings: addonName,
Expand All @@ -20,23 +20,23 @@ const addonName = path.basename(__filename, '.js');
implems.reduce((suite, implem) => {
const fn = rootAddon[implem].noArgFunction;
return suite.add(implem.padStart(maxNameLength, ' '), () => fn());
}, new Benchmark.Suite)
}, new Benchmark.Suite())
.on('cycle', (event) => console.log(String(event.target)))
.run();

console.log('one argument:');
implems.reduce((suite, implem) => {
const fn = rootAddon[implem].oneArgFunction;
return suite.add(implem.padStart(maxNameLength, ' '), () => fn('x'));
}, new Benchmark.Suite)
}, new Benchmark.Suite())
.on('cycle', (event) => console.log(String(event.target)))
.run();

console.log('two arguments:');
implems.reduce((suite, implem) => {
const fn = rootAddon[implem].twoArgFunction;
return suite.add(implem.padStart(maxNameLength, ' '), () => fn('x', 12));
}, new Benchmark.Suite)
}, new Benchmark.Suite())
.on('cycle', (event) => console.log(String(event.target)))
.run();

Expand All @@ -45,7 +45,7 @@ const addonName = path.basename(__filename, '.js');
const fn = rootAddon[implem].threeArgFunction;
return suite.add(implem.padStart(maxNameLength, ' '),
() => fn('x', 12, true));
}, new Benchmark.Suite)
}, new Benchmark.Suite())
.on('cycle', (event) => console.log(String(event.target)))
.run();

Expand All @@ -54,7 +54,7 @@ const addonName = path.basename(__filename, '.js');
const fn = rootAddon[implem].fourArgFunction;
return suite.add(implem.padStart(maxNameLength, ' '),
() => fn('x', 12, true, anObject));
}, new Benchmark.Suite)
}, new Benchmark.Suite())
.on('cycle', (event) => console.log(String(event.target)))
.run();
});
2 changes: 1 addition & 1 deletion benchmark/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const path = require('path');

let benchmarks = [];

if (!!process.env.npm_config_benchmarks) {
if (process.env.npm_config_benchmarks) {
benchmarks = process.env.npm_config_benchmarks
.split(';')
.map((item) => (item + '.js'));
Expand Down
61 changes: 27 additions & 34 deletions benchmark/property_descriptor.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "napi.h"

static napi_value Getter_Core(napi_env env, napi_callback_info info) {
(void) info;
(void)info;
napi_value result;
napi_status status = napi_create_uint32(env, 42, &result);
NAPI_THROW_IF_FAILED(env, status, nullptr);
Expand All @@ -14,7 +14,7 @@ static napi_value Setter_Core(napi_env env, napi_callback_info info) {
napi_status status =
napi_get_cb_info(env, info, &argc, &argv, nullptr, nullptr);
NAPI_THROW_IF_FAILED(env, status, nullptr);
(void) argv;
(void)argv;
return nullptr;
}

Expand All @@ -23,22 +23,23 @@ static Napi::Value Getter(const Napi::CallbackInfo& info) {
}

static void Setter(const Napi::CallbackInfo& info) {
(void) info[0];
(void)info[0];
}

#if NAPI_VERSION > 5
class PropDescBenchmark : public Napi::Addon<PropDescBenchmark> {
public:
PropDescBenchmark(Napi::Env, Napi::Object exports) {
DefineAddon(exports, {
InstanceAccessor("addon",
&PropDescBenchmark::Getter,
&PropDescBenchmark::Setter,
napi_enumerable),
InstanceAccessor<&PropDescBenchmark::Getter,
&PropDescBenchmark::Setter>("addon_templated",
napi_enumerable),
});
DefineAddon(exports,
{
InstanceAccessor("addon",
&PropDescBenchmark::Getter,
&PropDescBenchmark::Setter,
napi_enumerable),
InstanceAccessor<&PropDescBenchmark::Getter,
&PropDescBenchmark::Setter>(
"addon_templated", napi_enumerable),
});
}

private:
Expand All @@ -47,39 +48,31 @@ class PropDescBenchmark : public Napi::Addon<PropDescBenchmark> {
}

void Setter(const Napi::CallbackInfo& info, const Napi::Value& val) {
(void) info[0];
(void) val;
(void)info[0];
(void)val;
}
};
#endif // NAPI_VERSION > 5

static Napi::Object Init(Napi::Env env, Napi::Object exports) {
napi_status status;
napi_property_descriptor core_prop = {
"core",
nullptr,
nullptr,
Getter_Core,
Setter_Core,
nullptr,
napi_enumerable,
nullptr
};
napi_property_descriptor core_prop = {"core",
nullptr,
nullptr,
Getter_Core,
Setter_Core,
nullptr,
napi_enumerable,
nullptr};

status = napi_define_properties(env, exports, 1, &core_prop);
NAPI_THROW_IF_FAILED(env, status, Napi::Object());

exports.DefineProperty(
Napi::PropertyDescriptor::Accessor(env,
exports,
"cplusplus",
Getter,
Setter,
napi_enumerable));
exports.DefineProperty(Napi::PropertyDescriptor::Accessor(
env, exports, "cplusplus", Getter, Setter, napi_enumerable));

exports.DefineProperty(
Napi::PropertyDescriptor::Accessor<Getter, Setter>("templated",
napi_enumerable));
exports.DefineProperty(Napi::PropertyDescriptor::Accessor<Getter, Setter>(
"templated", napi_enumerable));

#if NAPI_VERSION > 5
PropDescBenchmark::Init(env, exports);
Expand Down
Loading

0 comments on commit 10b440f

Please sign in to comment.