process: improve process binding

Reviewed-By: Fedor Indutny <fedor@indutny.com>
archived-io.js-v0.10
Jackson Tian 2014-08-01 19:26:09 +08:00 committed by Fedor Indutny
parent 47a103a029
commit 962e651476
2 changed files with 22 additions and 1 deletions

View 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);

View File

@ -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");