Giter VIP home page Giter VIP logo

nan's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nan's Issues

Release 1.1

Assuming everything works consistently, it is time to release.

Correct documentation of NanUInt32OptionValue

In README.md, NanUInt32OptionValue is documented as:

uint32_t NanUInt32OptionValue(v8::Handle<v8::Value>, v8::Handle<v8::String>[, uint32_t])

Similar to NanBooleanOptionValue, use NanUInt32OptionValue to fetch an integer option from your options object. Requires all 3 arguments as a default is not optional.

As the default is not optional, shouldn't it be documented as
uint32_t NanUInt32OptionValue(v8::Handle<v8::Value>, v8::Handle<v8::String>, uint32_t)?

Document new NanFromV8String arguments

@kkoopa would you mind adding documentation for the new NanFromV8String() arguments please? I'm pretty sure you have a much better handle on what's going on there than I. Also, short docs for NanGetPointerSafe() and NanSetPointerSafe() would be nice too.

I'm tidying up 0.2.0 and will merge to master in a moment for a "release", so just do it straight in master when that's done.

feature: add NanCallback::IsEmpty()

It's not really possible right now to find out if a callback has been assigned. Suggestion: add a bool NanCallback::IsEmpty() const method

I say 'not really' because while in theory you can do nan_callback->GetFunction()->IsFunction(), that will assert in debug builds because of the cast from Undefined to Function.

Object.observe doesn't call NAN_METHOD functions

I'm not sure if this is a NAN issue or something in v8, but I have the following problem on node v0.11.9.

I am defining a method through NAN as follows (pretty standard):

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

NAN_METHOD(my_function)
{
  printf("Ran my function.\n");
}

void Init(Handle<Object> exports)
{
  exports->Set(NanSymbol("my_function"),
               FunctionTemplate::New(my_function)->GetFunction());
}

NODE_MODULE(my_module, Init)

Now, if I load this module and use it as the callback to Object.observe, I get the following somewhat weird behavior:

var my_module = require('my_module');
console.log(my_module.my_function); // Prints "[Function]", as expected
my_module.my_function(); // Prints "Ran my function."

// Create a dummy object
var foo = {}

// Let's hook up an observer to my object
Object.observe(foo, my_module.my_function);
foo.bar = true; // change object
// Nothing happens! my_function isn't called, and no exception is thrown

// Ok, let's just wrap the same function in an anonymous function
Object.observe(foo, function(changes) { my_module.my_function(changes); } );
foo.baz = true; // change object
// Prints "Ran my function."

Other than Object.observe, anything else I can think to do with my_function works normally. Any ideas what this could be?

create async loops

I want to execute the NanAsyncWorker again after HandleOKCallback, to do a async loop.
For example to read from a device ;-)

How would you recommend to do that? Sorry I'm not really good in C++... :-(

PS. thanks for nan, it's cool...

Right way to assign Local from Handle

This fails for me on Nan 1.0.0 and Node 0.10 (it does not cause problems on Node 0.11)
Could you give me any tip?

(...)
v8::Local<v8::Function> fun = funTpl->GetFunction();
(...)
fun = NanMakeCallback(fun, bind, 1, argv).As<v8::Function>();
error: no match for ‘operator=’ (operand types are ‘v8::Local<v8::Function>’ and ‘v8::Handle<v8::Function>’)
       fun = NanMakeCallback(fun, bind, 1, argv).As<v8::Function>();

V8 3.24

The upgrade to V8 3.24 just landed in joyent/node (good) and that means nan needs to upgrade as well (bad). The main changes:

  • Persistent<T>::MakeWeak() is replaced with Persistent<T>::SetWeak() (and the callback takes a single argument.)
  • Array::New(), FunctionTemplate::New(), Object::New() take an isolate as their first argument.
  • Integer::New(value, isolate) is now Integer::New(isolate, value) (arguments have been swapped)
  • String::New(s) is gone, replaced with String::NewFromUtf8Value(isolate, s).
  • Probably some other things I'm forgetting right now.

Thoughts on how to upgrade? Do we want to keep on supporting older node.js v0.11 (a.k.a. V8 3.22) versions?

libuv changes

There have been some changes to libuv as well. uv_idle_cb and others have had the status argument removed. Might be other breaking changes as well. Should we address this somehow?

Node 0.11.11 errors

0.11.11 was just released so I added it to .dntrc and ran the tests ... then this ... I don't even ...

WHAAAA??

I don't have time to even begin to understand what's going on with this or whether it's even a NAN problem.

cross-compatibility for tests

asyncworker.cpp, asyncworkererror.cpp, bufferworkerpersistent.cpp are currently not cross-compatible due to usleep() function. Nothing important I think, but maybe this can be fixed for the next release.

The change to using MakeCallback breaks Node 0.6

I know it's not officially supported, but everything seemed to work nicely previously. I've figured out that MakeCallback used to be a whole lot different in 0.6. Can we add something to rectify this deviation, at least until 0.12 is released?

void MakeCallback(Handle<Object> object,
                  const char* method,
                  int argc,
                  Handle<Value> argv[]) {
  HandleScope scope;

  Local<Value> callback_v = object->Get(String::New(method));
  if (!callback_v->IsFunction()) {
    fprintf(stderr, "method = %s", method);
  }
  assert(callback_v->IsFunction());
  Local<Function> callback = Local<Function>::Cast(callback_v);

  // TODO Hook for long stack traces to be made here.

  TryCatch try_catch;

  callback->Call(object, argc, argv);

  if (try_catch.HasCaught()) {
    FatalException(try_catch);
  }
}

nan.h error on node v0.10.22

This is error was found in module geoip, the original issue can be found in here.

Quoted from original issue

We are experiencing a new error (very infrequently) since upgrading to node v0.10.22. The following message is displayed and the process exits immediately.

node: /opt/pre-publish/star/node_modules/orion/node_modules/geoip/node_modules/nan/nan.h:809: bool _NanGetExternalParts(v8::Handle<v8::Value>, const char**, size_t*): Assertion `val->IsString()' failed.
Aborted

I suspect it may have something to do with the infamous WalMart memory leak on closed handles fix.

How about NanSetPrototypeTemplate()?

Hi,
first, this project is awesome! I'm a hobbyist programmer, writing a node addon. What do you think about a NanSetPrototypeTemplate() helper function?

  NAN_INLINE void NanSetPrototypeTemplate(
      v8::Handle<v8::Template> templ
    , const char *name
    , v8::Handle<v8::Data> value) {
    templ->PrototypeTemplate()->Set(name, value);
  }

add converters "to" and "from" V8

Kind of related to #29, as NanFromV8String is the only converter. This could be helpful to have converters from and to V8 for primitives in both worlds.

Taking example from: https://github.com/rectalogic/v8-webgl/blob/420977691cb07efd956146443d61f23f5b5dcf53/src/converters.h, it could use of templates.

For the string case, this could be for c-strings:

char* str = NanFromV8<char*>(v8Str);
// opposite
v8::Handle<v8::Value> v8Str = NanToV8(str);

and this for std::string:

std::string = NanFromV8<std::string>(v8Str);
// opposite
v8::Handle<v8::Value> v8Str = NanToV8(str);

Templates would be available for all useful primitives: char, int, uint8_t, uint64_t, ...

Would you be interested in a pull request for that?

NanEscapeScope with Handle?

I had such code that was previously working okay:

Handle<Object> obj; = NanNew<Object>();
return obj;

Now I wanted to transform it to the new NanEscapeScope as advised by @kkoopa:

NanEscapableScope();
Handle<Object> obj; = NanNew<Object>();
return NanEscapeScope(obj);

but this triggers an errors because NanEscapeScope takes only Local handles.

I had to do:

NanEscapableScope();
Local<Object> obj; = NanNew<Object>();
return NanEscapeScope(obj);

Shouldn't NanEscapeScope take Handle? It will automatically work for Local as well.

perf hit from NanFromV8String

Two things are going to kick you:

  1. Always expecting the string to be utf8 is going to kill performance. I might allow users to pass enum encoding in node.h to allow a specific encoding output.
  2. If the string is external one or two byte then all you'll need is a memcpy.

A lot of this is properly addressed in node::StringBytes::Encode. But since that doesn't exist pre v0.11, maybe just use it for a reference.

Can we remove "type" arguments?

This API really bothers me:

# define NAN_WEAK_CALLBACK(type, name) \
void name( \
v8::Isolate* isolate \
, v8::Persistent<v8::Object>* object \
, type data)
# define NAN_WEAK_CALLBACK_OBJECT (*object)
# define NAN_WEAK_CALLBACK_DATA(type) ((type) data)

...

# define NanAssignPersistent(type, handle, obj) handle.Reset(nan_isolate, obj)
# define NanInitPersistent(type, name, obj) \
v8::Persistent<type> name(nan_isolate, obj)

Supplying a "type" argument is a style-smell. As far as I'm aware there isn't a clever way to make a macro accept a generic type parameter so perhaps these things should be turned into proper functions? Of the template<class T> static NAN_INLINE(...) variety.

Thoughts? It'd mean API breakage but it feels odd whenever I have to put the type as an argument like that.

Very good (but still disgusting)

I like what you are doing here. Unfortunately there is still a huge amount of cruft one has to write manually to do simple things. Do you think there is a will to have some kind of high level wrapper over all those APIs to do common tasks like exposing native objects?
I have been going from leveldown codebase and I am amazed you are able to even maintain it because there is more v8 bindings then actual code. :) I was thinking one could do much better with wrapping around those APIs, particularly utilizing C++11. Did you have any thoughts in this area?

Symbol not found with NanCallback

Hi,

I'm trying to use nan for sophia binary addon. I use NanCallback with async workers and have been running into the following crash:

dyld: lazy symbol binding failed: Symbol not found: __ZN6sophia3SetEPvPKvmS2_mP11NanCallback
  Referenced from: /Users/maciej/dev/js/sophia/build/Debug/sophia.node
  Expected in: dynamic lookup

dyld: Symbol not found: __ZN6sophia3SetEPvPKvmS2_mP11NanCallback
  Referenced from: /Users/maciej/dev/js/sophia/build/Debug/sophia.node
  Expected in: dynamic lookup

Trace/BPT trap: 5

Piece of code which (I think) is responsible for that:

    sophia::Set(
      wrap->db,
      key,
      strlen(key),
      value,
      strlen(value),
      new NanCallback(callback)
    );
    NanReturnUndefined();

Which is weird, since I use the exact same invocation of NanCallback somewhere else in the same file and it works.

Full code is here, the piece of code in question is here.

Way to reproduce (works on node 0.10):

git clone https://github.com/mmalecki/node-sophia.git
cd node-sophia
git checkout put
npm i
node test/simple-test.js

How to convert a V8 buffer to a char?

Hi,

I am looking at passing a V8 Buffer args[1].As<v8::Object>() to a char cannot seem to find an easy way to do so.

I am fairly new to working with v8 and libuv so I assume that this would be a valid use case.

I would appreciate any insight into this,
Thanks

_NanWeakCallbackInfo<T, P>::Callback prototype mismatch

#include "nan.h"
#include "v8.h"

NAN_WEAK_CALLBACK(WeakCallback) {
}

void Test() {
  NanMakeWeakPersistent(NanNew<v8::Object>(), "", WeakCallback);
}

Compiles okay with node.js master but fails with v0.10:

$ g++-4.2 -Wall -Wextra -Wno-unused-parameter -I$PWD -I../v0.10/src -I../v0.10/deps/uv/include -I../v0.10/deps/v8/include -c tmp/t.cc
tmp/t.cc: In function ‘void Test()’:
tmp/t.cc:8: error: no matches converting function ‘WeakCallback’ to type ‘void (*)(struct v8::Persistent<v8::Value>, void*)’
tmp/t.cc:4: error: candidates are: template<class T, class P> void WeakCallback(v8::Persistent<v8::Value>, void*)

$ g++-4.8 -Wall -Wextra -Wno-unused-parameter -I$PWD -I../v0.10/src -I../v0.10/deps/uv/include -I../v0.10/deps/v8/include -c tmp/t.cc
tmp/t.cc: In function 'void Test()':
tmp/t.cc:8:63: error: no matches converting function 'WeakCallback' to type '_NanWeakCallbackInfo<v8::Object, const char>::Callback {aka void (*)(class v8::Persistent<v8::Value>, void*)}'
   NanMakeWeakPersistent(NanNew<v8::Object>(), "", WeakCallback);
                                                               ^
In file included from tmp/t.cc:1:0:
tmp/t.cc:4:19: note: candidate is: template<class T, class P> void WeakCallback(v8::Persistent<v8::Value>, void*)
 NAN_WEAK_CALLBACK(WeakCallback) {
                   ^
/Users/bnoordhuis/src/nan/nan.h:1393:17: note: in definition of macro 'NAN_WEAK_CALLBACK'
     static void name(                                                          \

Affects 1.0.0 and master. I suggest doing a 1.0.1 point release for this.

On a related note, opinions on making _Nan_Weak_Callback_ ## name static in 1.0.x, like it is in master? You currently can't use NAN_WEAK_CALLBACK() inside a class.

please tag 0.3.2

Please tag release 0.3.2 (if it is already released). I am currently preparing this project as a Debian package and for proper upstream versioning in Debian I rely on Git tags of upstream projects pulled from Github.

Thanks!
Mike (aka [email protected])

Should we `delete errmsg` in `NanAsyncWorker`?

errmsg is defined as const char* here, yet we call delete on it here. That's okay, but I think that in most cases errmsg is set like errmsg = "Not found", in which case trying to free it causes:

*** Error in `node': free(): invalid pointer: 0x00007f4b1e2dccc7 ***

If this shouldn't be deleted, mmalecki/nan@30c9c66 is a fix.

doxygen of v8

Hi,

I generate the v8 documentation locally. Would there be a place where nodejs and other projects could link to v8 documentation online for discussion sake?

NanMakeWeakPersistent elaboration

I am looking at example of NanMakeWeakPersistent but I fail to see the exact purpose... why and when would one need it? I have made a lot of progress in node-cbind but I yet to touch asynchronous stuff - maybe this is the use case?

compatible profiler api

I reviewed changes of v8 and node today, and found many changes at v8-profiler.h between with 0.10 and 0.11. Then did we need a bundle of functions to do the compatible works? If yes, I prefer to do this ASAP, if not, I'm so sad to hear that, and do this in library-land.

:)

Question: `NanPersistentToLocal()->NewInstance()` is not exists?

../src/response.cc:99:71: error: no member named 'NewInstance' in
      'v8::FunctionTemplate'; did you mean 'HasInstance'?
  ...= NanPersistentToLocal(responseTemplate)->NewInstance();
                                               ^~~~~~~~~~~
                                               HasInstance

Hi, I'm using nan to improve libetpan.node to v0.11, but I get this error at this function: https://github.com/dinhviethoa/libetpan.node/blob/master/src/response.cc#L65-L86, I don't know clearly what is the culprit of this problem :(

/cc @rvagg

NanDispose() -> NanDisposePersistent()

The inconsistency here bugs me a little, what do you guys think about deprecating NanDispose() in favour of NanDisposePersistent()? It can stay in the code for a while but marked NAN_DEPRECATED.

Release 1.2.0

I think we have enough for a new release. It ought to be 1.2.0 due to the addition of NanSetPrototypeTemplate. Nothing else added, just fixes and improvements.

getting following compile errors

../node_modules/nan/nan.h: In function `v8::Local<v8::Object> NanNewBufferHandle(char*, size_t, void (*)(char*, void*), void*)':
../node_modules/nan/nan.h:1320: error: call of overloaded `NanNew(v8::Persistent<v8::Object>&)' is ambiguous
../node_modules/nan/nan.h:923: note: candidates are: v8::Local<T> NanNew(v8::Handle<T>) [with T = v8::Object]
../node_modules/nan/nan.h:944: note:                 v8::Local<T> NanNew(const v8::Persistent<S>&) [with T = v8::Object]
../node_modules/nan/nan.h:949: note:                 v8::Local<T> NanNew(P) [with T = v8::Object, P = v8::Persistent<v8::Object>]
../node_modules/nan/nan.h: In function `v8::Local<v8::Object> NanNewBufferHandle(const char*, uint32_t)':
../node_modules/nan/nan.h:1328: error: call of overloaded `NanNew(v8::Persistent<v8::Object>&)' is ambiguous
../node_modules/nan/nan.h:923: note: candidates are: v8::Local<T> NanNew(v8::Handle<T>) [with T = v8::Object]
../node_modules/nan/nan.h:944: note:                 v8::Local<T> NanNew(const v8::Persistent<S>&) [with T = v8::Object]
../node_modules/nan/nan.h:949: note:                 v8::Local<T> NanNew(P) [with T = v8::Object, P = v8::Persistent<v8::Object>]
../node_modules/nan/nan.h: In function `v8::Local<v8::Object> NanNewBufferHandle(uint32_t)':
../node_modules/nan/nan.h:1336: error: call of overloaded `NanNew(v8::Persistent<v8::Object>&)' is ambiguous
../node_modules/nan/nan.h:923: note: candidates are: v8::Local<T> NanNew(v8::Handle<T>) [with T = v8::Object]
../node_modules/nan/nan.h:944: note:                 v8::Local<T> NanNew(const v8::Persistent<S>&) [with T = v8::Object]
../node_modules/nan/nan.h:949: note:                 v8::Local<T> NanNew(P) [with T = v8::Object, P = v8::Persistent<v8::Object>]
../node_modules/nan/nan.h: In function `v8::Local<v8::Object> NanBufferUse(char*, uint32_t)':
../node_modules/nan/nan.h:1348: error: call of overloaded `NanNew(v8::Persistent<v8::Object>&)' is ambiguous
../node_modules/nan/nan.h:923: note: candidates are: v8::Local<T> NanNew(v8::Handle<T>) [with T = v8::Object]
../node_modules/nan/nan.h:944: note:                 v8::Local<T> NanNew(const v8::Persistent<S>&) [with T = v8::Object]
../node_modules/nan/nan.h:949: note:                 v8::Local<T> NanNew(P) [with T = v8::Object, P = v8::Persistent<v8::Object>]
../node_modules/nan/nan.h: In function `v8::Local<v8::Context> NanNewContextHandle(v8::ExtensionConfiguration*, v8::Handle<v8::ObjectTemplate>, v8::Handle<v8::Value>)':
../node_modules/nan/nan.h:1364: error: call of overloaded `NanNew(v8::Persistent<v8::Context>&)' is ambiguous
../node_modules/nan/nan.h:923: note: candidates are: v8::Local<T> NanNew(v8::Handle<T>) [with T = v8::Context]
../node_modules/nan/nan.h:944: note:                 v8::Local<T> NanNew(const v8::Persistent<S>&) [with T = v8::Context]
../node_modules/nan/nan.h:949: note:                 v8::Local<T> NanNew(P) [with T = v8::Context, P = v8::Persistent<v8::Context>]
../node_modules/nan/nan.h: In function `bool _NanGetExternalParts(v8::Handle<v8::Value>, const char**, size_t*)':
../node_modules/nan/nan.h:1726: error: call of overloaded `NanNew(v8::Handle<v8::String>)' is ambiguous
../node_modules/nan/nan.h:923: note: candidates are: v8::Local<T> NanNew(v8::Handle<T>) [with T = v8::String]
../node_modules/nan/nan.h:949: note:                 v8::Local<T> NanNew(P) [with T = v8::String, P = v8::Handle<v8::String>]

Using existing buffer without automatically deleting backing data

Hi,

I'm currently writing bindings for a C++ library which has a class that I want to expose to JS land, and this class has a char* buffer that I would also like to expose.

This is a problem currently because if the user does something like this:

var object = new MyPrimitiveObject();
var buffer = object.getBuffer();
buffer = null;

Then this will delete data that is owned by an object that is still active.

Would it make sense to provide a version of NanBufferUse that does not automatically free the backing data when the weak callback is called?

How to create an External with NaN

Basically I'm trying to figure out how to avoid the below here.

#if (NODE_MODULE_VERSION > 0x000B) /* node 0.11 */
  instance->SetInternalField(0, External::New(v8::Isolate::GetCurrent(), this));
#else
  instance->SetInternalField(0, External::New(this));
#endif

As you can see External::New takes an Isolate* for node 0.11 but not before.
I couldn't find anywhere how nan allows me to wrap this.

If it's not there yet, but would be good to have I'd be happy to PR to add something like NanExternalNew() somehow.

Successive calls to NanFromV8String.

Hi,

I'm using nan and it's great :)

But today, I got stuck a couple of hours, before understanding that it came from NanFromV8String.

When calling twice in a row NanFromV8String with a second string shorter than the first one, the second string gets appended with old characters from the first one, as if it uses the same buffer, without null terminating the string correctly.

For example:

char* str = NanFromV8String(String::New("hello"));
printf("%s ", str);
delete[] str;
str = NanFromV8String(String::New("hell"));
printf("%s ", str);
delete[] str;

Gives:

hello hello

However, by passing explicit parameters, this works fine:

char* str = NanFromV8String(v8Str, Nan::UTF8, NULL, NULL, 0, v8::String::HINT_MANY_WRITES_EXPECTED);
printf("%s ", str);
delete[] str;
str = NanFromV8String(v8Str, Nan::UTF8, NULL, NULL, 0, v8::String::HINT_MANY_WRITES_EXPECTED);
printf("%s ", str);
delete[] str;

If this is not the default behavior, it should be I guess, or at least be specified in the docs to avoid missunderstanding.
If there is something I do wrong, please also tell me.

Thanks!

bufferworkerpersistent.js test naming

Is it on purpose, that bufferworkerpersistent.js test is excluded from testing? Due to tap --gc js/*-test.js in package.json the suffix -test is missing.

Node 0.11.12 Missing Symbols

I assume these missing symbols are due to upstream still releasing broken builds.

/home/kkoopa/dev/node-v0.11.12-linux-x64/bin/node: symbol lookup error: /home/kkoopa/dev/nan/test/build/Release/asyncworker.node: undefined symbol: _ZN4node12MakeCallbackEN2v86HandleINS0_6ObjectEEENS1_INS0_8FunctionEEEiPNS1_INS0_5ValueEEE

not ok js/asyncworker-test.js ........................... 0/1
    Command: "/home/kkoopa/dev/node-v0.11.12-linux-x64/bin/node --expose-gc asyncworker-test.js"
    TAP version 13
    not ok 1 js/asyncworker-test.js
      ---
        exit:    127
        stderr:  /home/kkoopa/dev/node-v0.11.12-linux-x64/bin/node: symbol lookup error: /home/kkoopa/dev/nan/test/build/Release/asyncworker.node: undefined symbol: _ZN4node12MakeCallbackEN2v86HandleINS0_6ObjectEEENS1_INS0_8FunctionEEEiPNS1_INS0_5ValueEEE
        command: "/home/kkoopa/dev/node-v0.11.12-linux-x64/bin/node --expose-gc asyncworker-test.js"
      ...

    1..1
    # tests 1
    # fail  1

compile warning on osx for _nan_base64_decoded_size

Just thought I'd fire up an osx vm and try that node-snappy problem and came across this warning:

In file included from ../src/binding.cc:21:
In file included from ../src/./binding.h:26:
../src/nan.h:706:46: warning: variable 'sz_' is uninitialized when used here
      [-Wuninitialized]
      sz_ = _nan_base64_decoded_size(*value, sz_);
                                             ^~~
../src/nan.h:673:13: note: initialize the variable 'sz_' to silence this warning
  size_t sz_;
            ^
             = 0
1 warning generated.

Semi-Automatic Porting of Existing Code to NAN

For some months, I've been thinking of writing a small tool to do semi-automatic porting of existing code to NAN, but I have not yet found the time or motivation. I have, however, constructed a set of regular expression substitutions, which I use myself when porting code, among with a good text editor. These substitutions deal with most of the common cases that can be done without much or any manual intervention.

The regular expressions need to be evaluated in the order provided and some of them (the scope.Close() thing) may produce false positives and are better done interactively. The observant reader notices that some of the expressions contain explicit parameter names, like the NAN_METHOD substitution. This is intentional, as NAN assumes standard argument names, and safe renaming of parameters may require contextual knowledge.

(v8\:\:)?Handle<(v8\:\:)?Value>\s*(\S+)\s*\(\s*const\s+(v8\:\:)?Arguments\s*&\s*args\s*\)
NAN_METHOD(\3)

(v8\:\:)?Handle<(v8\:\:)?Value>\s*(\S+)\s*\(\s*(v8\:\:)?Local<(v8\:\:)?String>\s*property\s*,\s*const\s*(v8\:\:)?AccessorInfo\s*&\s*info\s*\)
NAN_GETTER(\3)

void\s*(\S+)\s*\(\s*(v8\:\:)?Local<(v8\:\:)?String>\s*property\s*,\s*(v8\:\:)?Local<(v8\:\:)?Value>\s*value\s*,\s*const\s*(v8\:\:)?AccessorInfo\s*&\s*info\s*\)
NAN_SETTER(\1)

(v8\:\:)?HandleScope\s+scope
NanScope()

(v8\:\:)?String\:\:NewSymbol
NanNew

(v8\:\:)?Null\(\)
NanNull()

(v8\:\:)?Undefined\(\)
NanUndefined()

(v8\:\:)?True\(\)
NanTrue()

(v8\:\:)?False\(\)
NanFalse()

return\s+(v8\:\:)?ThrowException\s*\(\s*(v8\:\:)?Exception::Error\s*\(\s*(v8\:\:)?String::New\s*\((.*)\)\)\)
return NanThrowError(\4)

return\s+(v8\:\:)?ThrowException\s*\(\s*(v8\:\:)?Exception::TypeError\s*\(\s*(v8\:\:)?String::New\s*\((.*)\)\)\)
return NanThrowTypeError(\4)

return\s+(v8\:\:)?ThrowException\s*\(\s*(v8\:\:)?Exception::RangeError\s*\(\s*(v8\:\:)?String::New\s*\((.*)\)\)\)
return NanThrowRangeError(\4)

return\s+scope.Close\((v8\:\:)?ThrowException\((v8\:\:)?String::New\((.*)\)\)\)
return NanThrowError(\3)

return scope.Close
NanReturnValue

(\S+)\.Dispose\(\)
NanDisposePersistent(\1)

(\S+)\s*=\s*(v8\:\:)?Persistent<(v8\:\:)?(\S+)>::New\((.+)\)
NanAssignPersistent(\3\4, \1, \5)

(v8\:\:)?Local\s*<\s*(\S*)>\s*\:\:\s*New\s*\(
NanNew<\2>(

(v8\:\:)?(\S+)\:\:\s*New\s*\(
NanNew<\2>(

Escaping NanScope without value

This seems to work for me:

    uv_async_init(uv_default_loop(), &async_handle, [](uv_async_t* handle) {
      NanScope();
      realCallback(); // call things calling node.js
      uv_close((uv_handle_t*)&async_handle, NULL);
    });

but this function should not return anything and I see no other way to close the scope without value. Can I simply leave it up to HandleScope's destructor?

Debian renamed node for some reason

Apparently Debian decided it was a good idea to rename node to nodejs. This causes problems with the current include-voodoo.

"include_dirs" : [
    "<!(node -e \"require('nan')\")"
]

serialport/node-serialport#301

Based on crypto-utils/keygrip#7, it seems a possible fix is something like

"[ -x /usr/bin/nodejs ] && /usr/bin/nodejs ./install.js || node ./install.js"

But, I suspect that will not work with Windows. So, how to make a cross-platform solution?

travis build matrix

FYI I've updated the travis config and now have a built matrix for various versions of Node. Currently the latest 0.8, the last 5 versions of 0.5 and 0.11.4, 0.11.5 and 0.11.6. unfortunately 0.11.7 and 0.11.8 come with a consistently buggy npm that causes the builds to fail so I've removed them for now. Perhaps 0.11.9 will sort that out. We'll have to manually add new versions in as they are released.

Contributing testable example

I would like to contribute an example addon to nan, maybe more complex than adding numbers and possibly useful in other circumstances (if it was faster or v8 was slower:P)

Please review my code:
https://github.com/CodeCharmLtd/nan-example-eol
I am aware of its deficiencies (too complex code in places) but it is testable and may be useful for testing regressions in nan/v8/node. Just do node-gyp rebuild && npm test.

I initially wrote it out of curiosity, whether it would be faster than carrier and well .. after feature-parity it is the same speed! Totally not worth it but still ... uses Nan's buffers, and other stuff. Could be also extended to doing stuff in threads etc.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.