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

test: lint addon tests #2427

Merged
merged 2 commits into from
Aug 18, 2015
Merged
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
15 changes: 13 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,19 @@ CPPLINT_EXCLUDE += src/node_win32_perfctr_provider.cc
CPPLINT_EXCLUDE += src/queue.h
CPPLINT_EXCLUDE += src/tree.h
CPPLINT_EXCLUDE += src/v8abbr.h

CPPLINT_FILES = $(filter-out $(CPPLINT_EXCLUDE), $(wildcard src/*.cc src/*.h src/*.c tools/icu/*.h tools/icu/*.cc deps/debugger-agent/include/* deps/debugger-agent/src/*))
CPPLINT_EXCLUDE += $(wildcard test/addons/doc-*/*.cc test/addons/doc-*/*.h)

CPPLINT_FILES = $(filter-out $(CPPLINT_EXCLUDE), $(wildcard \
deps/debugger-agent/include/* \
deps/debugger-agent/src/* \
src/*.c \
src/*.cc \
src/*.h \
test/addons/*/*.cc \
test/addons/*/*.h \
tools/icu/*.cc \
tools/icu/*.h \
))

cpplint:
@$(PYTHON) tools/cpplint.py $(CPPLINT_FILES)
Expand Down
36 changes: 18 additions & 18 deletions test/addons/async-hello-world/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,57 @@
#include <v8.h>
#include <uv.h>

using namespace v8;
using namespace node;

struct async_req {
uv_work_t req;
int input;
int output;
Persistent<Function> callback;
v8::Isolate* isolate;
v8::Persistent<v8::Function> callback;
};

void DoAsync(uv_work_t* r) {
async_req* req = reinterpret_cast<async_req*>(r->data);
sleep(1); // simulate CPU intensive process...
sleep(1); // Simulate CPU intensive process...
req->output = req->input * 2;
}

void AfterAsync(uv_work_t* r) {
Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);
async_req* req = reinterpret_cast<async_req*>(r->data);
v8::Isolate* isolate = req->isolate;
v8::HandleScope scope(isolate);

Handle<Value> argv[2] = {
Null(isolate),
Integer::New(isolate, req->output)
v8::Handle<v8::Value> argv[2] = {
v8::Null(isolate),
v8::Integer::New(isolate, req->output)
};

TryCatch try_catch;
v8::TryCatch try_catch(isolate);

Local<Function> callback = Local<Function>::New(isolate, req->callback);
v8::Local<v8::Function> callback =
v8::Local<v8::Function>::New(isolate, req->callback);
callback->Call(isolate->GetCurrentContext()->Global(), 2, argv);

// cleanup
req->callback.Reset();
delete req;

if (try_catch.HasCaught()) {
FatalException(isolate, try_catch);
node::FatalException(isolate, try_catch);
}
}

void Method(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);
void Method(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = args.GetIsolate();
v8::HandleScope scope(isolate);

async_req* req = new async_req;
req->req.data = req;

req->input = args[0]->IntegerValue();
req->output = 0;
req->isolate = isolate;

Local<Function> callback = Local<Function>::Cast(args[1]);
v8::Local<v8::Function> callback = v8::Local<v8::Function>::Cast(args[1]);
req->callback.Reset(isolate, callback);

uv_queue_work(uv_default_loop(),
Expand All @@ -62,7 +62,7 @@ void Method(const FunctionCallbackInfo<Value>& args) {
(uv_after_work_cb)AfterAsync);
}

void init(Handle<Object> exports, Handle<Object> module) {
void init(v8::Handle<v8::Object> exports, v8::Handle<v8::Object> module) {
NODE_SET_METHOD(module, "exports", Method);
}

Expand Down
8 changes: 3 additions & 5 deletions test/addons/at-exit/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ static int at_exit_cb1_called = 0;
static int at_exit_cb2_called = 0;

static void at_exit_cb1(void* arg) {
// FIXME(bnoordhuis) Isolate::GetCurrent() is on its way out.
Isolate* isolate = Isolate::GetCurrent();
Isolate* isolate = static_cast<Isolate*>(arg);
HandleScope handle_scope(isolate);
assert(arg == 0);
Local<Object> obj = Object::New(isolate);
assert(!obj.IsEmpty()); // assert VM is still alive
assert(!obj.IsEmpty()); // Assert VM is still alive.
assert(obj->IsObject());
at_exit_cb1_called++;
}
Expand All @@ -37,7 +35,7 @@ static void sanity_check(void) {
}

void init(Handle<Object> target) {
AtExit(at_exit_cb1);
AtExit(at_exit_cb1, target->CreationContext()->GetIsolate());
AtExit(at_exit_cb2, cookie);
AtExit(at_exit_cb2, cookie);
atexit(sanity_check);
Expand Down
12 changes: 5 additions & 7 deletions test/addons/hello-world-function-export/binding.cc
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
#include <node.h>
#include <v8.h>

using namespace v8;

void Method(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);
args.GetReturnValue().Set(String::NewFromUtf8(isolate, "world"));
void Method(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = args.GetIsolate();
v8::HandleScope scope(isolate);
args.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, "world"));
}

void init(Handle<Object> exports, Handle<Object> module) {
void init(v8::Handle<v8::Object> exports, v8::Handle<v8::Object> module) {
NODE_SET_METHOD(module, "exports", Method);
}

Expand Down
12 changes: 5 additions & 7 deletions test/addons/hello-world/binding.cc
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
#include <node.h>
#include <v8.h>

using namespace v8;

void Method(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);
args.GetReturnValue().Set(String::NewFromUtf8(isolate, "world"));
void Method(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = args.GetIsolate();
v8::HandleScope scope(isolate);
args.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, "world"));
}

void init(Handle<Object> target) {
void init(v8::Handle<v8::Object> target) {
NODE_SET_METHOD(target, "hello", Method);
}

Expand Down