From 987cbe35c60beee8b80b428bcd97abb2c709b958 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Thu, 3 Jun 2010 12:39:12 +0200 Subject: [PATCH] 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. --- lib/module.js | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/lib/module.js b/lib/module.js index 701d14f49e5..0ae4a4b9c1b 100644 --- a/lib/module.js +++ b/lib/module.js @@ -390,12 +390,8 @@ Module.prototype._compile = function (content, filename) { Module.prototype._loadScriptSync = function (filename) { var content = requireNative('fs').readFileSync(filename, 'utf8'); - var e = this._compile(content, filename); - if (e) { - throw e; - } else { - this.loaded = true; - } + this._compile(content, filename); + this.loaded = true; }; @@ -406,16 +402,18 @@ Module.prototype._loadScript = function (filename, callback) { if (err) { if (callback) callback(err); } else { - var e = self._compile(content, filename); - if (e) { - if (callback) callback(e); - } else { - self._waitChildrenLoad(function () { - self.loaded = true; - if (self.onload) self.onload(); - if (callback) callback(null, self.exports); - }); + try { + self._compile(content, filename); + } catch (err) { + if (callback) callback(err); + return; } + + self._waitChildrenLoad(function () { + self.loaded = true; + if (self.onload) self.onload(); + if (callback) callback(null, self.exports); + }); } }); };