diff --git a/src/node.js b/src/node.js index d65b8be1c7e..2ac9db46e6c 100644 --- a/src/node.js +++ b/src/node.js @@ -48,12 +48,12 @@ function Module (id, parent) { this.exports = {}; this.parent = parent; - this.moduleCache = {}; - if (parent) { - process.mixin(this.moduleCache, parent.moduleCache); - this.moduleCache[parent.id] = parent; + this.moduleCache = parent.moduleCache; + } else { + this.moduleCache = {}; } + this.moduleCache[this.id] = this; this.filename = null; this.loaded = false; diff --git a/test/mjsunit/fixtures/a.js b/test/mjsunit/fixtures/a.js index f30ea0c4317..4b9927ee416 100644 --- a/test/mjsunit/fixtures/a.js +++ b/test/mjsunit/fixtures/a.js @@ -4,6 +4,7 @@ debug("load fixtures/a.js"); var string = "A"; +exports.SomeClass = c.SomeClass; exports.A = function () { return string; diff --git a/test/mjsunit/fixtures/b/c.js b/test/mjsunit/fixtures/b/c.js index b9a82e4569b..6aaf186726d 100644 --- a/test/mjsunit/fixtures/b/c.js +++ b/test/mjsunit/fixtures/b/c.js @@ -10,6 +10,10 @@ debug("load fixtures/b/c.js"); var string = "C"; +exports.SomeClass = function() { + +}; + exports.C = function () { return string; }; diff --git a/test/mjsunit/test-module-loading.js b/test/mjsunit/test-module-loading.js index 416c48b140c..f91958f8ba8 100644 --- a/test/mjsunit/test-module-loading.js +++ b/test/mjsunit/test-module-loading.js @@ -3,6 +3,7 @@ process.mixin(require("./common")); debug("load test-module-loading.js"); var a = require("./fixtures/a"); +var c = require("./fixtures/b/c"); var d = require("./fixtures/b/d"); var d2 = require("./fixtures/b/d"); // Absolute @@ -33,6 +34,8 @@ assert.equal("D", d3.D()); assert.equal(true, d4.D instanceof Function); assert.equal("D", d4.D()); +assert.ok((new a.SomeClass) instanceof c.SomeClass); + debug("test index.js modules ids and relative loading") var one = require("./fixtures/nested-index/one"), two = require("./fixtures/nested-index/two"); @@ -41,6 +44,7 @@ assert.notEqual(one.hello, two.hello); debug("test cycles containing a .. path"); var root = require("./fixtures/cycles/root"), foo = require("./fixtures/cycles/folder/foo"); +assert.equal(root.foo, foo); assert.equal(root.sayHello(), root.hello); var errorThrown = false;