-
Notifications
You must be signed in to change notification settings - Fork 30.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
addon: Pass module object to NODE_MODULE init function
mainly to allow native addons to export single functions on rather than being restricted to operating on an existing object. Init functions now receive exports as the first argument, like before, but also the module object as the second argument, if they support it. Related to #4634 cc: @rvagg
- Loading branch information
Showing
6 changed files
with
52 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include <node.h> | ||
#include <v8.h> | ||
|
||
using namespace v8; | ||
|
||
Handle<Value> Method(const Arguments& args) { | ||
HandleScope scope; | ||
return scope.Close(String::New("world")); | ||
} | ||
|
||
void init(Handle<Object> exports, Handle<Object> module) { | ||
NODE_SET_METHOD(module, "exports", Method); | ||
} | ||
|
||
NODE_MODULE(binding, init); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
'targets': [ | ||
{ | ||
'target_name': 'binding', | ||
'sources': [ 'binding.cc' ] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
var assert = require('assert'); | ||
var binding = require('./build/Release/binding'); | ||
assert.equal('world', binding()); | ||
console.log('binding.hello() =', binding()); |