Skip to content

Commit

Permalink
Appease the pedantic gcc and eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
p120ph37 committed Jan 11, 2022
1 parent 9af027a commit b337aea
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
12 changes: 7 additions & 5 deletions napi-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -4453,8 +4453,11 @@ inline ClassPropertyDescriptor<T> ObjectWrap<T>::StaticValue(Symbol name,

template <typename T>
inline Value ObjectWrap<T>::NonConstructor(const Napi::CallbackInfo& info) {
NAPI_THROW(TypeError::New(info.Env(), "Class constructors cannot be invoked without 'new'"), Napi::Value());
};
NAPI_THROW(
TypeError::New(info.Env(),
"Class constructors cannot be invoked without 'new'"),
Napi::Value());
}

template <typename T>
inline void ObjectWrap<T>::Finalize(Napi::Env /*env*/) {}
Expand All @@ -4469,9 +4472,8 @@ inline napi_value ObjectWrap<T>::ConstructorCallbackWrapper(

bool isConstructCall = (new_target != nullptr);
if (!isConstructCall) {
return details::WrapCallback([&] {
return T::NonConstructor(CallbackInfo(env, info));
});
return details::WrapCallback(
[&] { return T::NonConstructor(CallbackInfo(env, info)); });
}

napi_value wrapper = details::WrapCallback([&] {
Expand Down
18 changes: 9 additions & 9 deletions test/objectwrap_nonconstructor.cc
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
#include <napi.h>
#include "test_helper.h"
#include <unordered_map>
#include "test_helper.h"

class NonConstructorTest :
public Napi::ObjectWrap<NonConstructorTest> {
public:
NonConstructorTest(const Napi::CallbackInfo& info) :
Napi::ObjectWrap<NonConstructorTest>(info) {}
class NonConstructorTest : public Napi::ObjectWrap<NonConstructorTest> {
public:
NonConstructorTest(const Napi::CallbackInfo& info)
: Napi::ObjectWrap<NonConstructorTest>(info) {}

static Napi::Value NonConstructor(const Napi::CallbackInfo& info) {
// If called with a "true" argument, throw an exeption to test the handling.
if(!info[0].IsUndefined() && MaybeUnwrap(info[0].ToBoolean())) {
if (!info[0].IsUndefined() && MaybeUnwrap(info[0].ToBoolean())) {
NAPI_THROW(Napi::Error::New(info.Env(), "an exception"), Napi::Value());
}
// Otherwise, act as a factory.
std::vector<napi_value> args;
for(size_t i = 0; i < info.Length(); i++) args.push_back(info[i]);
for (size_t i = 0; i < info.Length(); i++) args.push_back(info[i]);
return MaybeUnwrap(GetConstructor(info.Env()).New(args));
}

Expand All @@ -37,7 +36,8 @@ class NonConstructorTest :
}
};

std::unordered_map<napi_env, Napi::FunctionReference*> NonConstructorTest::constructors = {};
std::unordered_map<napi_env, Napi::FunctionReference*>
NonConstructorTest::constructors = {};

Napi::Object InitObjectWrapNonConstructor(Napi::Env env) {
Napi::Object exports = Napi::Object::New(env);
Expand Down
2 changes: 1 addition & 1 deletion test/objectwrap_nonconstructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const assert = require('assert');
const testUtil = require('./testUtil');

function test(binding) {
function test (binding) {
return testUtil.runGCTests([
'objectwrap nonconstructor',
() => {
Expand Down

0 comments on commit b337aea

Please sign in to comment.