Browse Source

module: correct the order of the assertions

this puts the type-checking assertions in require
into proper order.

PR-URL: https://github.com/joyent/node/pull/8333
Reviewed-by: Chris Dickinson <christopher.s.dickinson@gmail.com>
Reviewed-by: Fedor Indutny <fedor@indutny.com>
v0.11.15-release
haoxin 10 years ago
committed by Chris Dickinson
parent
commit
00d7b13a18
  1. 2
      lib/module.js
  2. 12
      test/simple/test-module-loading-error.js

2
lib/module.js

@ -360,8 +360,8 @@ Module.prototype.load = function(filename) {
// Loads a module at the given file path. Returns that module's
// `exports` property.
Module.prototype.require = function(path) {
assert(util.isString(path), 'path must be a string');
assert(path, 'missing path');
assert(util.isString(path), 'path must be a string');
return Module._load(path, this);
};

12
test/simple/test-module-loading-error.js

@ -42,3 +42,15 @@ try {
} catch (e) {
assert.notEqual(e.toString().indexOf(dlerror_msg), -1);
}
try {
require();
} catch (e) {
assert.notEqual(e.toString().indexOf('missing path'), -1);
}
try {
require({});
} catch (e) {
assert.notEqual(e.toString().indexOf('path must be a string'), -1);
}

Loading…
Cancel
Save