chore: add native_mate to lint:cpp (#18100)

This commit is contained in:
Milan Burda 2019-05-02 04:45:23 +02:00 committed by Cheng Zhao
parent d507ba68a7
commit 8785e9007c
14 changed files with 147 additions and 136 deletions

View file

@ -2,8 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE.chromium file.
#ifndef NATIVE_MATE_ARGUMENTS_H_
#define NATIVE_MATE_ARGUMENTS_H_
#ifndef NATIVE_MATE_NATIVE_MATE_ARGUMENTS_H_
#define NATIVE_MATE_NATIVE_MATE_ARGUMENTS_H_
#include <string>
#include <vector>
#include "base/macros.h"
#include "native_mate/converter.h"
@ -88,4 +91,4 @@ class Arguments {
} // namespace mate
#endif // NATIVE_MATE_ARGUMENTS_H_
#endif // NATIVE_MATE_NATIVE_MATE_ARGUMENTS_H_

View file

@ -6,8 +6,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE.chromium file.
#ifndef NATIVE_MATE_WRAPPABLE_CLASS_H_
#define NATIVE_MATE_WRAPPABLE_CLASS_H_
#ifndef NATIVE_MATE_NATIVE_MATE_CONSTRUCTOR_H_
#define NATIVE_MATE_NATIVE_MATE_CONSTRUCTOR_H_
#include "base/bind.h"
#include "native_mate/function_template.h"
@ -150,4 +150,4 @@ void InvokeNew(const base::Callback<Sig>& factory,
} // namespace mate
#endif // NATIVE_MATE_WRAPPABLE_CLASS_H_
#endif // NATIVE_MATE_NATIVE_MATE_CONSTRUCTOR_H_

View file

@ -6,29 +6,12 @@
#include "v8/include/v8.h"
using v8::Array;
using v8::Boolean;
using v8::External;
using v8::Function;
using v8::Int32;
using v8::Integer;
using v8::Isolate;
using v8::Local;
using v8::Maybe;
using v8::MaybeLocal;
using v8::Number;
using v8::Object;
using v8::Promise;
using v8::String;
using v8::Uint32;
using v8::Value;
namespace mate {
namespace {
template <typename T, typename U>
bool FromMaybe(Maybe<T> maybe, U* out) {
bool FromMaybe(v8::Maybe<T> maybe, U* out) {
if (maybe.IsNothing())
return false;
*out = static_cast<U>(maybe.FromJust());
@ -37,64 +20,71 @@ bool FromMaybe(Maybe<T> maybe, U* out) {
} // namespace
Local<Value> Converter<bool>::ToV8(Isolate* isolate, bool val) {
v8::Local<v8::Value> Converter<bool>::ToV8(v8::Isolate* isolate, bool val) {
return v8::Boolean::New(isolate, val);
}
bool Converter<bool>::FromV8(Isolate* isolate, Local<Value> val, bool* out) {
bool Converter<bool>::FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
bool* out) {
if (!val->IsBoolean())
return false;
*out = val.As<Boolean>()->Value();
*out = val.As<v8::Boolean>()->Value();
return true;
}
#if !defined(OS_LINUX) && !defined(OS_FREEBSD)
Local<Value> Converter<unsigned long>::ToV8(Isolate* isolate,
unsigned long val) {
v8::Local<v8::Value> Converter<unsigned long>::ToV8( // NOLINT(runtime/int)
v8::Isolate* isolate,
unsigned long val) { // NOLINT(runtime/int)
return v8::Integer::New(isolate, val);
}
bool Converter<unsigned long>::FromV8(Isolate* isolate,
Local<Value> val,
unsigned long* out) {
bool Converter<unsigned long>::FromV8( // NOLINT(runtime/int)
v8::Isolate* isolate,
v8::Local<v8::Value> val,
unsigned long* out) { // NOLINT(runtime/int)
if (!val->IsNumber())
return false;
return FromMaybe(val->IntegerValue(isolate->GetCurrentContext()), out);
}
#endif
Local<Value> Converter<int32_t>::ToV8(Isolate* isolate, int32_t val) {
v8::Local<v8::Value> Converter<int32_t>::ToV8(v8::Isolate* isolate,
int32_t val) {
return v8::Integer::New(isolate, val);
}
bool Converter<int32_t>::FromV8(Isolate* isolate,
Local<Value> val,
bool Converter<int32_t>::FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
int32_t* out) {
if (!val->IsInt32())
return false;
*out = val.As<Int32>()->Value();
*out = val.As<v8::Int32>()->Value();
return true;
}
Local<Value> Converter<uint32_t>::ToV8(Isolate* isolate, uint32_t val) {
v8::Local<v8::Value> Converter<uint32_t>::ToV8(v8::Isolate* isolate,
uint32_t val) {
return v8::Integer::NewFromUnsigned(isolate, val);
}
bool Converter<uint32_t>::FromV8(Isolate* isolate,
Local<Value> val,
bool Converter<uint32_t>::FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
uint32_t* out) {
if (!val->IsUint32())
return false;
*out = val.As<Uint32>()->Value();
*out = val.As<v8::Uint32>()->Value();
return true;
}
Local<Value> Converter<int64_t>::ToV8(Isolate* isolate, int64_t val) {
v8::Local<v8::Value> Converter<int64_t>::ToV8(v8::Isolate* isolate,
int64_t val) {
return v8::Number::New(isolate, static_cast<double>(val));
}
bool Converter<int64_t>::FromV8(Isolate* isolate,
Local<Value> val,
bool Converter<int64_t>::FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
int64_t* out) {
if (!val->IsNumber())
return false;
@ -103,154 +93,168 @@ bool Converter<int64_t>::FromV8(Isolate* isolate,
return FromMaybe(val->IntegerValue(isolate->GetCurrentContext()), out);
}
Local<Value> Converter<uint64_t>::ToV8(Isolate* isolate, uint64_t val) {
v8::Local<v8::Value> Converter<uint64_t>::ToV8(v8::Isolate* isolate,
uint64_t val) {
return v8::Number::New(isolate, static_cast<double>(val));
}
bool Converter<uint64_t>::FromV8(Isolate* isolate,
Local<Value> val,
bool Converter<uint64_t>::FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
uint64_t* out) {
if (!val->IsNumber())
return false;
return FromMaybe(val->IntegerValue(isolate->GetCurrentContext()), out);
}
Local<Value> Converter<float>::ToV8(Isolate* isolate, float val) {
v8::Local<v8::Value> Converter<float>::ToV8(v8::Isolate* isolate, float val) {
return v8::Number::New(isolate, val);
}
bool Converter<float>::FromV8(Isolate* isolate, Local<Value> val, float* out) {
bool Converter<float>::FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
float* out) {
if (!val->IsNumber())
return false;
*out = static_cast<float>(val.As<Number>()->Value());
*out = static_cast<float>(val.As<v8::Number>()->Value());
return true;
}
Local<Value> Converter<double>::ToV8(Isolate* isolate, double val) {
v8::Local<v8::Value> Converter<double>::ToV8(v8::Isolate* isolate, double val) {
return v8::Number::New(isolate, val);
}
bool Converter<double>::FromV8(Isolate* isolate,
Local<Value> val,
bool Converter<double>::FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
double* out) {
if (!val->IsNumber())
return false;
*out = val.As<Number>()->Value();
*out = val.As<v8::Number>()->Value();
return true;
}
Local<Value> Converter<const char*>::ToV8(Isolate* isolate, const char* val) {
v8::Local<v8::Value> Converter<const char*>::ToV8(v8::Isolate* isolate,
const char* val) {
return v8::String::NewFromUtf8(isolate, val, v8::NewStringType::kNormal)
.ToLocalChecked();
}
Local<Value> Converter<base::StringPiece>::ToV8(Isolate* isolate,
const base::StringPiece& val) {
v8::Local<v8::Value> Converter<base::StringPiece>::ToV8(
v8::Isolate* isolate,
const base::StringPiece& val) {
return v8::String::NewFromUtf8(isolate, val.data(),
v8::NewStringType::kNormal,
static_cast<uint32_t>(val.length()))
.ToLocalChecked();
}
Local<Value> Converter<std::string>::ToV8(Isolate* isolate,
const std::string& val) {
v8::Local<v8::Value> Converter<std::string>::ToV8(v8::Isolate* isolate,
const std::string& val) {
return Converter<base::StringPiece>::ToV8(isolate, val);
}
bool Converter<std::string>::FromV8(Isolate* isolate,
Local<Value> val,
bool Converter<std::string>::FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
std::string* out) {
if (!val->IsString())
return false;
Local<String> str = Local<String>::Cast(val);
v8::Local<v8::String> str = v8::Local<v8::String>::Cast(val);
int length = str->Utf8Length(isolate);
out->resize(length);
str->WriteUtf8(isolate, &(*out)[0], length, NULL,
String::NO_NULL_TERMINATION);
v8::String::NO_NULL_TERMINATION);
return true;
}
Local<Value> Converter<Local<Function>>::ToV8(Isolate* isolate,
Local<Function> val) {
v8::Local<v8::Value> Converter<v8::Local<v8::Function>>::ToV8(
v8::Isolate* isolate,
v8::Local<v8::Function> val) {
return val;
}
bool Converter<Local<Function>>::FromV8(Isolate* isolate,
Local<Value> val,
Local<Function>* out) {
bool Converter<v8::Local<v8::Function>>::FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
v8::Local<v8::Function>* out) {
if (!val->IsFunction())
return false;
*out = Local<Function>::Cast(val);
*out = v8::Local<v8::Function>::Cast(val);
return true;
}
Local<Value> Converter<Local<Object>>::ToV8(Isolate* isolate,
Local<Object> val) {
v8::Local<v8::Value> Converter<v8::Local<v8::Object>>::ToV8(
v8::Isolate* isolate,
v8::Local<v8::Object> val) {
return val;
}
bool Converter<Local<Object>>::FromV8(Isolate* isolate,
Local<Value> val,
Local<Object>* out) {
bool Converter<v8::Local<v8::Object>>::FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
v8::Local<v8::Object>* out) {
if (!val->IsObject())
return false;
*out = Local<Object>::Cast(val);
*out = v8::Local<v8::Object>::Cast(val);
return true;
}
Local<Value> Converter<Local<String>>::ToV8(Isolate* isolate,
Local<String> val) {
v8::Local<v8::Value> Converter<v8::Local<v8::String>>::ToV8(
v8::Isolate* isolate,
v8::Local<v8::String> val) {
return val;
}
bool Converter<Local<String>>::FromV8(Isolate* isolate,
Local<Value> val,
Local<String>* out) {
bool Converter<v8::Local<v8::String>>::FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
v8::Local<v8::String>* out) {
if (!val->IsString())
return false;
*out = Local<String>::Cast(val);
*out = v8::Local<v8::String>::Cast(val);
return true;
}
Local<Value> Converter<Local<External>>::ToV8(Isolate* isolate,
Local<External> val) {
v8::Local<v8::Value> Converter<v8::Local<v8::External>>::ToV8(
v8::Isolate* isolate,
v8::Local<v8::External> val) {
return val;
}
bool Converter<Local<External>>::FromV8(Isolate* isolate,
v8::Local<Value> val,
Local<External>* out) {
bool Converter<v8::Local<v8::External>>::FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
v8::Local<v8::External>* out) {
if (!val->IsExternal())
return false;
*out = Local<External>::Cast(val);
*out = v8::Local<v8::External>::Cast(val);
return true;
}
Local<Value> Converter<Local<Array>>::ToV8(Isolate* isolate, Local<Array> val) {
v8::Local<v8::Value> Converter<v8::Local<v8::Array>>::ToV8(
v8::Isolate* isolate,
v8::Local<v8::Array> val) {
return val;
}
bool Converter<Local<Array>>::FromV8(Isolate* isolate,
v8::Local<Value> val,
Local<Array>* out) {
bool Converter<v8::Local<v8::Array>>::FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
v8::Local<v8::Array>* out) {
if (!val->IsArray())
return false;
*out = Local<Array>::Cast(val);
*out = v8::Local<v8::Array>::Cast(val);
return true;
}
Local<Value> Converter<Local<Value>>::ToV8(Isolate* isolate, Local<Value> val) {
v8::Local<v8::Value> Converter<v8::Local<v8::Value>>::ToV8(
v8::Isolate* isolate,
v8::Local<v8::Value> val) {
return val;
}
Local<Promise> Converter<Local<Promise>>::ToV8(Isolate* isolate,
Local<Promise> val) {
v8::Local<v8::Promise> Converter<v8::Local<v8::Promise>>::ToV8(
v8::Isolate* isolate,
v8::Local<v8::Promise> val) {
return val;
}
bool Converter<Local<Value>>::FromV8(Isolate* isolate,
Local<Value> val,
Local<Value>* out) {
bool Converter<v8::Local<v8::Value>>::FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
v8::Local<v8::Value>* out) {
*out = val;
return true;
}

View file

@ -2,13 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE.chromium file.
#ifndef NATIVE_MATE_CONVERTER_H_
#define NATIVE_MATE_CONVERTER_H_
#ifndef NATIVE_MATE_NATIVE_MATE_CONVERTER_H_
#define NATIVE_MATE_NATIVE_MATE_CONVERTER_H_
#include <map>
#include <set>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
#include "base/strings/string_piece.h"
@ -56,11 +57,12 @@ struct Converter<bool> {
#if !defined(OS_LINUX) && !defined(OS_FREEBSD)
template <>
struct Converter<unsigned long> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, unsigned long val);
struct Converter<unsigned long> { // NOLINT(runtime/int)
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
unsigned long val); // NOLINT(runtime/int)
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
unsigned long* out);
unsigned long* out); // NOLINT(runtime/int)
};
#endif
@ -347,4 +349,4 @@ inline v8::Local<v8::String> StringToV8(v8::Isolate* isolate,
} // namespace mate
#endif // NATIVE_MATE_CONVERTER_H_
#endif // NATIVE_MATE_NATIVE_MATE_CONVERTER_H_

View file

@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE.chromium file.
#ifndef NATIVE_MATE_DICTIONARY_H_
#define NATIVE_MATE_DICTIONARY_H_
#ifndef NATIVE_MATE_NATIVE_MATE_DICTIONARY_H_
#define NATIVE_MATE_NATIVE_MATE_DICTIONARY_H_
#include "native_mate/converter.h"
#include "native_mate/object_template_builder.h"
@ -141,4 +141,4 @@ struct Converter<Dictionary> {
} // namespace mate
#endif // NATIVE_MATE_DICTIONARY_H_
#endif // NATIVE_MATE_NATIVE_MATE_DICTIONARY_H_

View file

@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE.chromium file.
#ifndef NATIVE_MATE_FUNCTION_TEMPLATE_H_
#define NATIVE_MATE_FUNCTION_TEMPLATE_H_
#ifndef NATIVE_MATE_NATIVE_MATE_FUNCTION_TEMPLATE_H_
#define NATIVE_MATE_NATIVE_MATE_FUNCTION_TEMPLATE_H_
#include "base/callback.h"
#include "base/logging.h"
@ -285,4 +285,4 @@ void CreateFunctionHandler(v8::Isolate* isolate,
} // namespace mate
#endif // NATIVE_MATE_FUNCTION_TEMPLATE_H_
#endif // NATIVE_MATE_NATIVE_MATE_FUNCTION_TEMPLATE_H_

View file

@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE.chromium file.
#ifndef NATIVE_MATE_HANDLE_H_
#define NATIVE_MATE_HANDLE_H_
#ifndef NATIVE_MATE_NATIVE_MATE_HANDLE_H_
#define NATIVE_MATE_NATIVE_MATE_HANDLE_H_
#include "native_mate/converter.h"
@ -69,4 +69,4 @@ mate::Handle<T> CreateHandle(v8::Isolate* isolate, T* object) {
} // namespace mate
#endif // NATIVE_MATE_HANDLE_H_
#endif // NATIVE_MATE_NATIVE_MATE_HANDLE_H_

View file

@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE.chromium file.
#ifndef NATIVE_MATE_OBJECT_TEMPLATE_BUILDER_H_
#define NATIVE_MATE_OBJECT_TEMPLATE_BUILDER_H_
#ifndef NATIVE_MATE_NATIVE_MATE_OBJECT_TEMPLATE_BUILDER_H_
#define NATIVE_MATE_NATIVE_MATE_OBJECT_TEMPLATE_BUILDER_H_
#include "base/bind.h"
#include "base/callback.h"
@ -14,8 +14,6 @@
namespace mate {
namespace {
// Base template - used only for non-member function pointers. Other types
// either go to one of the below specializations, or go here and fail to compile
// because of base::Bind().
@ -62,8 +60,6 @@ struct CallbackTraits<v8::Local<v8::FunctionTemplate>> {
}
};
} // namespace
// ObjectTemplateBuilder provides a handy interface to creating
// v8::ObjectTemplate instances with various sorts of properties.
class ObjectTemplateBuilder {
@ -124,4 +120,4 @@ class ObjectTemplateBuilder {
} // namespace mate
#endif // NATIVE_MATE_OBJECT_TEMPLATE_BUILDER_H_
#endif // NATIVE_MATE_NATIVE_MATE_OBJECT_TEMPLATE_BUILDER_H_

View file

@ -2,8 +2,8 @@
// Use of this source code is governed by MIT license that can be found in the
// LICENSE file.
#ifndef NATIVE_MATE_PERSISTENT_DICTIONARY_H_
#define NATIVE_MATE_PERSISTENT_DICTIONARY_H_
#ifndef NATIVE_MATE_NATIVE_MATE_PERSISTENT_DICTIONARY_H_
#define NATIVE_MATE_NATIVE_MATE_PERSISTENT_DICTIONARY_H_
#include "native_mate/dictionary.h"
#include "native_mate/scoped_persistent.h"
@ -34,4 +34,4 @@ struct Converter<PersistentDictionary> {
} // namespace mate
#endif // NATIVE_MATE_PERSISTENT_DICTIONARY_H_
#endif // NATIVE_MATE_NATIVE_MATE_PERSISTENT_DICTIONARY_H_

View file

@ -2,8 +2,10 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef NATIVE_MATE_PROMISE_H_
#define NATIVE_MATE_PROMISE_H_
#ifndef NATIVE_MATE_NATIVE_MATE_PROMISE_H_
#define NATIVE_MATE_NATIVE_MATE_PROMISE_H_
#include <string>
#include "native_mate/converter.h"
@ -12,7 +14,7 @@ namespace mate {
class Promise {
public:
Promise();
Promise(v8::Isolate* isolate);
explicit Promise(v8::Isolate* isolate);
virtual ~Promise();
static Promise Create(v8::Isolate* isolate);
@ -53,4 +55,4 @@ struct Converter<Promise> {
} // namespace mate
#endif // NATIVE_MATE_PROMISE_H_
#endif // NATIVE_MATE_NATIVE_MATE_PROMISE_H_

View file

@ -2,8 +2,8 @@
// Use of this source code is governed by MIT license that can be found in the
// LICENSE file.
#ifndef NATIVE_MATE_SCOPED_PERSISTENT_H_
#define NATIVE_MATE_SCOPED_PERSISTENT_H_
#ifndef NATIVE_MATE_NATIVE_MATE_SCOPED_PERSISTENT_H_
#define NATIVE_MATE_NATIVE_MATE_SCOPED_PERSISTENT_H_
#include "base/memory/ref_counted.h"
#include "native_mate/converter.h"
@ -99,4 +99,4 @@ struct Converter<ScopedPersistent<T>> {
} // namespace mate
#endif // NATIVE_MATE_SCOPED_PERSISTENT_H_
#endif // NATIVE_MATE_NATIVE_MATE_SCOPED_PERSISTENT_H_

View file

@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE.chromium file.
#ifndef NATIVE_MATE_WRAPPABLE_H_
#define NATIVE_MATE_WRAPPABLE_H_
#ifndef NATIVE_MATE_NATIVE_MATE_WRAPPABLE_H_
#define NATIVE_MATE_NATIVE_MATE_WRAPPABLE_H_
#include "base/bind.h"
#include "gin/per_isolate_data.h"
@ -97,4 +97,4 @@ struct Converter<T*,
} // namespace mate
#endif // NATIVE_MATE_WRAPPABLE_H_
#endif // NATIVE_MATE_NATIVE_MATE_WRAPPABLE_H_

View file

@ -1,5 +1,9 @@
#ifndef NATIVE_MATE_WRAPPABLE_BASE_H_
#define NATIVE_MATE_WRAPPABLE_BASE_H_
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE.chromium file.
#ifndef NATIVE_MATE_NATIVE_MATE_WRAPPABLE_BASE_H_
#define NATIVE_MATE_NATIVE_MATE_WRAPPABLE_BASE_H_
namespace mate {
@ -59,4 +63,4 @@ class WrappableBase {
} // namespace mate
#endif // NATIVE_MATE_WRAPPABLE_BASE_H_
#endif // NATIVE_MATE_NATIVE_MATE_WRAPPABLE_BASE_H_

View file

@ -43,7 +43,7 @@ function spawnAndCheckExitCode (cmd, args, opts) {
const LINTERS = [ {
key: 'c++',
roots: ['atom'],
roots: ['atom', 'native_mate'],
test: filename => filename.endsWith('.cc') || filename.endsWith('.h'),
run: (opts, filenames) => {
if (opts.fix) {