3

I used this:

 Local<Value> argv[argc] = { String::New("hello world") };

But now I see the example on node.js website:

 Local<Value> argv[argc] = { Local<Value>::New(String::New("hello world")) };

What does it mean? What's difference, when an dwhy I should use Local<Value> in addition to String::New()

exebook
  • 32,014
  • 33
  • 141
  • 226
  • Is your usage in the context of calling a callback? – Joe Mar 01 '14 at 13:41
  • @Joe, I have simpler functions and those that call callbacks – exebook Mar 01 '14 at 13:49
  • The only code I've seen in the node addon docs use that construct in the context of a native addon calling a JS callback. But I wish I knew if it "mattered". – Joe Mar 01 '14 at 13:56
  • 1
    What's particularly interesting is that the "unstable" ver (0.11.x) docs have changed to not do this... e.g. http://nodejs.org/dist/v0.11.11/docs/api/addons.html#addons_callbacks – Joe Mar 01 '14 at 14:15

1 Answers1

3

Apparently, the node.js example in this case was wrong/inefficient.

https://github.com/joyent/node/commit/98aad77f466d9c36947f2cbb6d07b75009795ed2#commitcomment-5532648

jnardone added a note 2 hours ago

Was this just one of those things that was always wrong, or was there an underlying v8 change that meant that this should change? The additional Local::New always looked odd but I can't tell if something buried inside v8 required this additional wrapper or not.

bnoordhuis added a note 7 minutes ago

It's cleanup. Creating a Local out of a Local is not actively harmful but it's superfluous and slightly inefficient.

So, your first format is fine.

Joe
  • 41,484
  • 20
  • 104
  • 125