diff options
author | isaacs <i@izs.me> | 2013-01-24 15:40:58 -0800 |
---|---|---|
committer | isaacs <i@izs.me> | 2013-01-25 14:25:35 -0800 |
commit | 15508589a163b0c9f09ac608281f9ebb015d4deb (patch) | |
tree | c636ff300e34a2b4bdbaa8586f8a7eab74a99396 /test/addons | |
parent | 00b4b7bb97c84d19c644a4491fe98170ab9675a6 (diff) | |
download | android-node-v8-15508589a163b0c9f09ac608281f9ebb015d4deb.tar.gz android-node-v8-15508589a163b0c9f09ac608281f9ebb015d4deb.tar.bz2 android-node-v8-15508589a163b0c9f09ac608281f9ebb015d4deb.zip |
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
Diffstat (limited to 'test/addons')
-rw-r--r-- | test/addons/hello-world-function-export/binding.cc | 15 | ||||
-rw-r--r-- | test/addons/hello-world-function-export/binding.gyp | 8 | ||||
-rw-r--r-- | test/addons/hello-world-function-export/test.js | 4 |
3 files changed, 27 insertions, 0 deletions
diff --git a/test/addons/hello-world-function-export/binding.cc b/test/addons/hello-world-function-export/binding.cc new file mode 100644 index 0000000000..dcdb6b8ce8 --- /dev/null +++ b/test/addons/hello-world-function-export/binding.cc @@ -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); diff --git a/test/addons/hello-world-function-export/binding.gyp b/test/addons/hello-world-function-export/binding.gyp new file mode 100644 index 0000000000..3bfb84493f --- /dev/null +++ b/test/addons/hello-world-function-export/binding.gyp @@ -0,0 +1,8 @@ +{ + 'targets': [ + { + 'target_name': 'binding', + 'sources': [ 'binding.cc' ] + } + ] +} diff --git a/test/addons/hello-world-function-export/test.js b/test/addons/hello-world-function-export/test.js new file mode 100644 index 0000000000..238e105381 --- /dev/null +++ b/test/addons/hello-world-function-export/test.js @@ -0,0 +1,4 @@ +var assert = require('assert'); +var binding = require('./build/Release/binding'); +assert.equal('world', binding()); +console.log('binding.hello() =', binding()); |