process: improve process binding
authorJackson Tian <shyvo1987@gmail.com>
Fri, 1 Aug 2014 11:26:09 +0000 (19:26 +0800)
committerFedor Indutny <fedor@indutny.com>
Sat, 2 Aug 2014 16:14:46 +0000 (20:14 +0400)
Reviewed-By: Fedor Indutny <fedor@indutny.com>
src/node.cc
test/simple/test-process-binding.js [new file with mode: 0644]

index 61a5cfd..f3409dc 100644 (file)
@@ -2240,7 +2240,12 @@ static void Binding(const FunctionCallbackInfo<Value>& 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 (file)
index 0000000..c803a80
--- /dev/null
@@ -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");