Browse Source

module: assert that require() is called with a string

as requested in #4577
v0.9.7-release
Felix Böhm 12 years ago
committed by isaacs
parent
commit
7465cf911a
  1. 1
      lib/module.js
  2. 9
      test/simple/test-module-loading.js

1
lib/module.js

@ -359,6 +359,7 @@ Module.prototype.load = function(filename) {
Module.prototype.require = function(path) {
assert(typeof path === 'string', 'path must be a string');
assert(path, 'missing path');
return Module._load(path, this);
};

9
test/simple/test-module-loading.js

@ -295,3 +295,12 @@ process.on('exit', function() {
// #1440 Loading files with a byte order marker.
assert.equal(42, require('../fixtures/utf8-bom.js'));
assert.equal(42, require('../fixtures/utf8-bom.json'));
// require() must take string, and must be truthy
assert.throws(function() {
require({ foo: 'bar' });
}, 'path must be a string');
assert.throws(function() {
require(false);
}, 'missing path');

Loading…
Cancel
Save