Skip to content

Commit fb0ac9c

Browse files
committed
Initial update for NAN suport
1 parent 4383a01 commit fb0ac9c

File tree

7 files changed

+595
-591
lines changed

7 files changed

+595
-591
lines changed

binding.gyp

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111
{
1212
'target_name': 'webgl',
1313
'defines': [
14-
'VERSION=0.1.4'
14+
'VERSION=0.3.0'
1515
],
1616
'sources': [
1717
'src/bindings.cc',
1818
'src/image.cc',
1919
'src/webgl.cc',
2020
],
2121
'include_dirs': [
22+
"<!(node -e \"require('nan')\")",
2223
'<(module_root_dir)/deps/include',
2324
],
2425
'library_dirs': [

package.json

+30-27
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,37 @@
22
"author": "Mikael Bourges-Sevenier <[email protected]>",
33
"name": "node-webgl",
44
"description": "WebGL bindings for node",
5-
"version": "0.2.1",
5+
"version": "0.3.0",
66
"main": "index.js",
7-
"keywords": [ "webgl", "opengl" ],
7+
"keywords": [
8+
"webgl",
9+
"opengl"
10+
],
811
"engines": {
9-
"node": "0.7.0-0.11.3"
12+
"node": ">=0.7.0"
1013
},
11-
"directories": {
12-
"src": "src",
13-
"lib": "lib",
14-
"doc": "doc",
15-
"examples": "examples",
16-
"test": "test"
17-
},
18-
"repository": {
19-
"type": "git",
20-
"url": "https://[email protected]/mikeseven/node-webgl.git"
21-
},
22-
"scripts": {
23-
"install": "node-gyp rebuild"
24-
},
25-
"licenses": [{
26-
"type": "BSD",
27-
"url": "http://github.com/mikeseven/node-webgl/raw/master/LICENSES"
28-
}],
29-
"dependencies": {
30-
"node-glfw" : ">=0.2.0"
31-
},
32-
"devDependencies": {
33-
"node-glfw" : ">=0.2.0"
34-
}
14+
"directories": {
15+
"src": "src",
16+
"lib": "lib",
17+
"doc": "doc",
18+
"examples": "examples",
19+
"test": "test"
20+
},
21+
"repository": {
22+
"type": "git",
23+
"url": "https://[email protected]/mikeseven/node-webgl.git"
24+
},
25+
"scripts": {
26+
"install": "node-gyp rebuild"
27+
},
28+
"licenses": [
29+
{
30+
"type": "BSD",
31+
"url": "http://github.com/mikeseven/node-webgl/raw/master/LICENSES"
32+
}
33+
],
34+
"dependencies": {
35+
"node-glfw": ">=0.2.0",
36+
"nan": "^0.8.0"
37+
}
3538
}

src/common.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#define COMMON_H_
1010

1111
#include <node.h>
12+
#include "nan.h"
1213
#include <v8.h>
1314
#include "arch_wrapper.h"
1415

@@ -17,7 +18,6 @@ namespace {
1718
#define JS_INT(val) v8::Integer::New(val)
1819
#define JS_FLOAT(val) v8::Number::New(val)
1920
#define JS_BOOL(val) v8::Boolean::New(val)
20-
#define JS_METHOD(name) v8::Handle<v8::Value> name(const v8::Arguments& args)
2121

2222
}
2323
#endif /* COMMON_H_ */

src/image.cc

+16-16
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static void unregisterImage(Image* obj) {
2929
Persistent<FunctionTemplate> Image::constructor_template;
3030

3131
void Image::Initialize (Handle<Object> target) {
32-
HandleScope scope;
32+
NanScope();
3333

3434
Local<FunctionTemplate> t = FunctionTemplate::New(New);
3535
constructor_template = Persistent<FunctionTemplate>::New(t);
@@ -44,7 +44,7 @@ void Image::Initialize (Handle<Object> target) {
4444
constructor_template->PrototypeTemplate()->SetAccessor(JS_STR("src"), SrcGetter, SrcSetter);
4545
//constructor_template->PrototypeTemplate()->SetAccessor(JS_STR("onload"), NULL, OnloadSetter);
4646

47-
target->Set(String::NewSymbol("Image"), constructor_template->GetFunction());
47+
target->Set(NanSymbol("Image"), constructor_template->GetFunction());
4848

4949
FreeImage_Initialise(true);
5050
}
@@ -88,7 +88,7 @@ void Image::Load (const char *filename) {
8888
}
8989

9090
Handle<Value> Image::New (const Arguments& args) {
91-
HandleScope scope;
91+
NanScope();
9292

9393
Image *image = new Image();
9494
image->Wrap(args.This());
@@ -98,39 +98,39 @@ Handle<Value> Image::New (const Arguments& args) {
9898
}
9999

100100
Handle<Value> Image::WidthGetter (Local<String> property, const AccessorInfo& info) {
101-
HandleScope scope;
101+
NanScope();
102102

103103
Image *image = ObjectWrap::Unwrap<Image>(info.This());
104104

105-
return scope.Close(JS_INT(image->GetWidth()));
105+
NanReturnValue(JS_INT(image->GetWidth()));
106106
}
107107

108108
Handle<Value> Image::HeightGetter (Local<String> property, const AccessorInfo& info) {
109-
HandleScope scope;
109+
NanScope();
110110

111111
Image *image = ObjectWrap::Unwrap<Image>(info.This());
112112

113-
return scope.Close(JS_INT(image->GetHeight()));
113+
NanReturnValue(JS_INT(image->GetHeight()));
114114
}
115115

116116
Handle<Value> Image::PitchGetter (Local<String> property, const AccessorInfo& info) {
117-
HandleScope scope;
117+
NanScope();
118118

119119
Image *image = ObjectWrap::Unwrap<Image>(info.This());
120120

121-
return scope.Close(JS_INT(image->GetPitch()));
121+
NanReturnValue(JS_INT(image->GetPitch()));
122122
}
123123

124124
Handle<Value> Image::SrcGetter (Local<String> property, const AccessorInfo& info) {
125-
HandleScope scope;
125+
NanScope();
126126

127127
Image *image = ObjectWrap::Unwrap<Image>(info.This());
128128

129-
return scope.Close(JS_STR(image->filename));
129+
NanReturnValue(JS_STR(image->filename));
130130
}
131131

132132
void Image::SrcSetter (Local<String> property, Local<Value> value, const AccessorInfo& info) {
133-
HandleScope scope;
133+
NanScope();
134134

135135
Image *image = ObjectWrap::Unwrap<Image>(info.This());
136136
String::Utf8Value filename_s(value->ToString());
@@ -155,7 +155,7 @@ void Image::SrcSetter (Local<String> property, Local<Value> value, const Accesso
155155
(int) num_bytes);
156156

157157
// emit event
158-
Local<Value> emit_v = info.This()->Get(String::NewSymbol("emit"));
158+
Local<Value> emit_v = info.This()->Get(NanSymbol("emit"));
159159
assert(emit_v->IsFunction());
160160
Local<Function> emit_f = emit_v.As<Function>();
161161

@@ -172,8 +172,8 @@ void Image::SrcSetter (Local<String> property, Local<Value> value, const Accesso
172172
FatalException(tc);
173173
}
174174

175-
JS_METHOD(Image::save) {
176-
HandleScope scope;
175+
NAN_METHOD(Image::save) {
176+
NanScope();
177177
String::Utf8Value filename(args[0]->ToString());
178178

179179
FREE_IMAGE_FORMAT format = FreeImage_GetFIFFromFilename(*filename);
@@ -205,7 +205,7 @@ JS_METHOD(Image::save) {
205205
}
206206
bool ret=FreeImage_Save(format, image, *filename)==1;
207207
FreeImage_Unload(image);
208-
return scope.Close(Boolean::New(ret));
208+
NanReturnValue(Boolean::New(ret));
209209
}
210210

211211
Image::~Image () {

src/image.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Image : public ObjectWrap {
2626
static void SrcSetter (Local<String> property, Local<Value> value, const AccessorInfo& info);
2727
static void OnloadSetter (Local<String> property, Local<Value> value, const AccessorInfo& info);
2828
static Handle<Value> PitchGetter (Local<String> property, const AccessorInfo& info);
29-
static JS_METHOD(save);
29+
static NAN_METHOD(save);
3030

3131
virtual ~Image ();
3232

0 commit comments

Comments
 (0)