From 962e651476ce2035ce6e15eff5abd0f9c54e039c Mon Sep 17 00:00:00 2001 From: Jackson Tian Date: Fri, 1 Aug 2014 19:26:09 +0800 Subject: [PATCH] process: improve process binding Reviewed-By: Fedor Indutny --- src/node.cc | 7 ++++++- test/simple/test-process-binding.js | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 test/simple/test-process-binding.js diff --git a/src/node.cc b/src/node.cc index 61a5cfd..f3409dc 100644 --- a/src/node.cc +++ b/src/node.cc @@ -2240,7 +2240,12 @@ static void Binding(const FunctionCallbackInfo& args) { DefineJavaScript(env, exports); cache->Set(module, exports); } else { - return env->ThrowError("No such module"); + char errmsg[1024]; + snprintf(errmsg, + sizeof(errmsg), + "No such module: %s", + *module_v); + return env->ThrowError(errmsg); } args.GetReturnValue().Set(exports); diff --git a/test/simple/test-process-binding.js b/test/simple/test-process-binding.js new file mode 100644 index 0000000..c803a80 --- /dev/null +++ b/test/simple/test-process-binding.js @@ -0,0 +1,16 @@ +var assert = require('assert'); + +assert.throws( + function() { + process.binding('test'); + }, + /No such module: test/ +); + +assert.doesNotThrow(function () { + process.binding('buffer'); +}, function(err) { + if ( (err instanceof Error) ) { + return true; + } +}, "unexpected error"); -- 2.7.4