Fix: require.async module exception delegation
The fs.readFile bug was hiding another bug that was causing this test to pass, even so it was broken: require.async("../fixtures/throws_error1") in test-module-loading.js This patch fixes the original test by running _compile within a try..catch block for _loadScript. _loadScriptSync also had some useless (deprecated?) code for dealing with module entry point exceptions. This code was also removed for greater clarity.
This commit is contained in:
parent
55e964ec19
commit
987cbe35c6
@ -390,12 +390,8 @@ Module.prototype._compile = function (content, filename) {
|
|||||||
|
|
||||||
Module.prototype._loadScriptSync = function (filename) {
|
Module.prototype._loadScriptSync = function (filename) {
|
||||||
var content = requireNative('fs').readFileSync(filename, 'utf8');
|
var content = requireNative('fs').readFileSync(filename, 'utf8');
|
||||||
var e = this._compile(content, filename);
|
this._compile(content, filename);
|
||||||
if (e) {
|
this.loaded = true;
|
||||||
throw e;
|
|
||||||
} else {
|
|
||||||
this.loaded = true;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -406,16 +402,18 @@ Module.prototype._loadScript = function (filename, callback) {
|
|||||||
if (err) {
|
if (err) {
|
||||||
if (callback) callback(err);
|
if (callback) callback(err);
|
||||||
} else {
|
} else {
|
||||||
var e = self._compile(content, filename);
|
try {
|
||||||
if (e) {
|
self._compile(content, filename);
|
||||||
if (callback) callback(e);
|
} catch (err) {
|
||||||
} else {
|
if (callback) callback(err);
|
||||||
self._waitChildrenLoad(function () {
|
return;
|
||||||
self.loaded = true;
|
|
||||||
if (self.onload) self.onload();
|
|
||||||
if (callback) callback(null, self.exports);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self._waitChildrenLoad(function () {
|
||||||
|
self.loaded = true;
|
||||||
|
if (self.onload) self.onload();
|
||||||
|
if (callback) callback(null, self.exports);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user