Fix registerExtension for NODE_MODULE_CONTEXTS
Fix of registerExtension-produced non-string module loading with own context. Plus finishing touches to the test.
This commit is contained in:
Родитель
39b432e42a
Коммит
9253333850
27
src/node.js
27
src/node.js
|
@ -394,6 +394,11 @@ var module = (function () {
|
|||
content = extensionCache[ext](content);
|
||||
}
|
||||
|
||||
if ("string" !== typeof content) {
|
||||
self.exports = content;
|
||||
return;
|
||||
}
|
||||
|
||||
function requireAsync (url, cb) {
|
||||
loadModule(url, self, cb);
|
||||
}
|
||||
|
@ -410,7 +415,7 @@ var module = (function () {
|
|||
var dirname = path.dirname(filename);
|
||||
|
||||
if (contextLoad) {
|
||||
if (!Script) Script = Script = process.binding('evals').Script;
|
||||
if (!Script) Script = process.binding('evals').Script;
|
||||
|
||||
if (self.id !== ".") {
|
||||
debug('load submodule');
|
||||
|
@ -441,20 +446,16 @@ var module = (function () {
|
|||
}
|
||||
|
||||
} else {
|
||||
if ('string' === typeof content) {
|
||||
// create wrapper function
|
||||
var wrapper = "(function (exports, require, module, __filename, __dirname) { "
|
||||
+ content
|
||||
+ "\n});";
|
||||
// create wrapper function
|
||||
var wrapper = "(function (exports, require, module, __filename, __dirname) { "
|
||||
+ content
|
||||
+ "\n});";
|
||||
|
||||
var compiledWrapper = process.compile(wrapper, filename);
|
||||
if (filename === process.argv[1] && global.v8debug) {
|
||||
global.v8debug.Debug.setBreakPoint(compiledWrapper, 0, 0);
|
||||
}
|
||||
compiledWrapper.apply(self.exports, [self.exports, require, self, filename, dirname]);
|
||||
} else {
|
||||
self.exports = content;
|
||||
var compiledWrapper = process.compile(wrapper, filename);
|
||||
if (filename === process.argv[1] && global.v8debug) {
|
||||
global.v8debug.Debug.setBreakPoint(compiledWrapper, 0, 0);
|
||||
}
|
||||
compiledWrapper.apply(self.exports, [self.exports, require, self, filename, dirname]);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -152,19 +152,19 @@ assert.equal(require(loadOrder + 'file8').file8, 'file8/index.reg', msg);
|
|||
assert.equal(require(loadOrder + 'file9').file9, 'file9/index.reg2', msg);
|
||||
|
||||
process.addListener("exit", function () {
|
||||
assert.equal(true, a.A instanceof Function);
|
||||
assert.ok(common.indirectInstanceOf(a.A, Function));
|
||||
assert.equal("A done", a.A());
|
||||
|
||||
assert.equal(true, a.C instanceof Function);
|
||||
assert.ok(common.indirectInstanceOf(a.C, Function));
|
||||
assert.equal("C done", a.C());
|
||||
|
||||
assert.equal(true, a.D instanceof Function);
|
||||
assert.ok(common.indirectInstanceOf(a.D, Function));
|
||||
assert.equal("D done", a.D());
|
||||
|
||||
assert.equal(true, d.D instanceof Function);
|
||||
assert.ok(common.indirectInstanceOf(d.D, Function));
|
||||
assert.equal("D done", d.D());
|
||||
|
||||
assert.equal(true, d2.D instanceof Function);
|
||||
assert.ok(common.indirectInstanceOf(d2.D, Function));
|
||||
assert.equal("D done", d2.D());
|
||||
|
||||
assert.equal(true, errorThrown);
|
||||
|
|
Загрузка…
Ссылка в новой задаче