Skip to content

Commit

Permalink
First pass nanification. Refs #44
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcw committed Jun 9, 2014
1 parent 4f75044 commit 10eadf5
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
3 changes: 2 additions & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
'./include',
'<(SHARED_INTERMEDIATE_DIR)/',
'<!@(pkg-config freetype2 --cflags-only-I | sed s/-I//g)',
'<!@(pkg-config protobuf --cflags-only-I | sed s/-I//g)'
'<!@(pkg-config protobuf --cflags-only-I | sed s/-I//g)',
"<!(node -e \"require('nan')\")"
],
'libraries': [
'-lboost_system',
Expand Down
1 change: 1 addition & 0 deletions include/node_fontserver/glyphs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <fontserver/glyphs.hpp>

#include <node.h>
#include <nan.h>

namespace node_fontserver
{
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"private": true,
"dependencies": {
"queue-async": "1.0.x",
"node-pre-gyp": "^0.5.15"
"node-pre-gyp": "^0.5.15",
"nan": "~1.2.0"
},
"bundledDependencies": [
"node-pre-gyp"
Expand Down
25 changes: 11 additions & 14 deletions src/glyphs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

// node
#include <node_buffer.h>
#include <nan.h>

namespace node_fontserver
{
Expand Down Expand Up @@ -32,8 +33,8 @@ Glyphs::~Glyphs() {}
void Glyphs::Init(v8::Handle<v8::Object> target) {
v8::HandleScope scope;

v8::Local<v8::FunctionTemplate> tpl = v8::FunctionTemplate::New(New);
v8::Local<v8::String> name = v8::String::NewSymbol("Glyphs");
v8::Local<v8::FunctionTemplate> tpl = NanNew<v8::FunctionTemplate>(New);
v8::Local<v8::String> name = NanNew<v8::String>("Glyphs");

constructor = v8::Persistent<v8::FunctionTemplate>::New(tpl);

Expand All @@ -52,10 +53,10 @@ void Glyphs::Init(v8::Handle<v8::Object> target) {

v8::Handle<v8::Value> Glyphs::New(const v8::Arguments& args) {
if (!args.IsConstructCall()) {
return ThrowException(v8::Exception::TypeError(v8::String::New("Constructor must be called with new keyword")));
return NanThrowTypeError("Constructor must be called with new keyword");
}
if (args.Length() > 0 && !node::Buffer::HasInstance(args[0])) {
return ThrowException(v8::Exception::TypeError(v8::String::New("First argument may only be a buffer")));
return NanThrowTypeError("First argument may only be a buffer");
}

Glyphs* glyphs;
Expand All @@ -66,7 +67,7 @@ v8::Handle<v8::Value> Glyphs::New(const v8::Arguments& args) {
v8::Local<v8::Object> buffer = args[0]->ToObject();
glyphs = new Glyphs(node::Buffer::Data(buffer), node::Buffer::Length(buffer));
}

glyphs->Wrap(args.This());

return args.This();
Expand All @@ -88,23 +89,19 @@ v8::Handle<v8::Value> Glyphs::Range(const v8::Arguments& args) {

// Validate arguments.
if (args.Length() < 1 || !args[0]->IsString()) {
return ThrowException(v8::Exception::TypeError(
v8::String::New("fontstack must be a string")));
return NanThrowTypeError("fontstack must be a string");
}

if (args.Length() < 2 || !args[1]->IsString()) {
return ThrowException(v8::Exception::TypeError(
v8::String::New("range must be a string")));
return NanThrowTypeError("range must be a string");
}

if (args.Length() < 3 || !args[2]->IsArray()) {
return ThrowException(v8::Exception::TypeError(
v8::String::New("chars must be an array")));
return NanThrowTypeError("chars must be an array");
}

if (args.Length() < 4 || !args[3]->IsFunction()) {
return ThrowException(v8::Exception::TypeError(
v8::String::New("callback must be a function")));
return NanThrowTypeError("callback must be a function");
}

v8::String::Utf8Value fontstack(args[0]->ToString());
Expand Down Expand Up @@ -133,7 +130,7 @@ v8::Handle<v8::Value> Glyphs::Range(const v8::Arguments& args) {
int status = uv_queue_work(uv_default_loop(), req, AsyncRange, (uv_after_work_cb)RangeAfter);
assert(status == 0);

return v8::Undefined();
NanReturnUndefined();
}

void Glyphs::AsyncRange(uv_work_t* req) {
Expand Down
1 change: 1 addition & 0 deletions src/node_fontserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

// node
#include <node.h>
#include <nan.h>

namespace node_fontserver
{
Expand Down

0 comments on commit 10eadf5

Please sign in to comment.