Bugfix: require() and include() should work in callbacks.

Removing requireAsync and includeAsync from global scope for now as a
temporary fix.  Reported by Yuffster.
This commit is contained in:
Ryan Dahl 2009-09-29 19:28:54 +02:00
Родитель 1ae69a68a4
Коммит a8c0211e73
6 изменённых файлов: 39 добавлений и 35 удалений

Просмотреть файл

@ -535,7 +535,6 @@ variable (which should be a list of paths, colon separated).</p></div>
<div class="paragraph"><p>Node comes with several libraries which are installed when <tt>"make install"</tt>
is run. These are currently undocumented, but do look them up in your
system.</p></div>
<div class="paragraph"><p>(Functions <tt>require_async()</tt> and <tt>include_async()</tt> also exist.)</p></div>
<h3 id="_timers">Timers</h3><div style="clear:left"></div>
<div class="dlist"><dl>
<dt class="hdlist1">
@ -2030,7 +2029,7 @@ init (Handle&lt;Object&gt; target)
<div id="footer">
<div id="footer-text">
Version 0.1.12<br />
Last updated 2009-09-29 09:59:52 CEST
Last updated 2009-09-29 19:22:27 CEST
</div>
</div>
</body>

Просмотреть файл

@ -332,8 +332,6 @@ Node comes with several libraries which are installed when +"make install"+
is run. These are currently undocumented, but do look them up in your
system.
(Functions +require_async()+ and +include_async()+ also exist.)

Просмотреть файл

@ -554,7 +554,6 @@ variable (which should be a list of paths, colon separated).</simpara>
<simpara>Node comes with several libraries which are installed when <literal>"make install"</literal>
is run. These are currently undocumented, but do look them up in your
system.</simpara>
<simpara>(Functions <literal>require_async()</literal> and <literal>include_async()</literal> also exist.)</simpara>
</refsect2>
<refsect2 id="_timers">
<title>Timers</title>

Просмотреть файл

@ -457,8 +457,6 @@ node\.libraryPaths can be modified at runtime by simply unshifting new paths on
.sp
Node comes with several libraries which are installed when "make install" is run\. These are currently undocumented, but do look them up in your system\.
.sp
(Functions require_async() and include_async() also exist\.)
.sp
.SS "Timers"
.PP
setTimeout(callback, delay)

Просмотреть файл

@ -62,32 +62,6 @@ if (ENV["NODE_LIBRARY_PATHS"]) {
ENV["NODE_LIBRARY_PATHS"].split(":").concat(node.libraryPaths);
}
node.loadingModules = [];
function require_async (url) {
var currentModule = node.loadingModules[0];
return currentModule.newChild(url, {});
}
function require (url) {
return require_async(url).wait();
}
function include_async (url) {
var promise = require_async(url)
promise.addCallback(function (t) {
// copy properties into global namespace.
for (var prop in t) {
if (t.hasOwnProperty(prop)) process[prop] = t[prop];
}
});
return promise;
}
function include (url) {
include_async(url).wait();
}
node.Module = function (filename, parent) {
node.assert(filename.charAt(0) == "/");
this.filename = filename;
@ -223,12 +197,37 @@ node.Module.prototype.loadScript = function (loadPromise) {
// remove shebang
content = content.replace(/^\#\!.*/, '');
node.loadingModules = [];
function requireAsync (url) {
return self.newChild(url, {});
}
function require (url) {
return requireAsync(url).wait();
}
function includeAsync (url) {
var promise = requireAsync(url)
promise.addCallback(function (t) {
// copy properties into global namespace.
for (var prop in t) {
if (t.hasOwnProperty(prop)) process[prop] = t[prop];
}
});
return promise;
}
function include (url) {
includeAsync(url).wait();
}
// create wrapper function
var wrapper = "function (__filename, exports) { " + content + "\n};";
var wrapper = "function (__filename, exports, require, include) { " + content + "\n};";
var compiled_wrapper = node.compile(wrapper, self.filename);
node.loadingModules.unshift(self);
compiled_wrapper.apply(self.target, [self.filename, self.target]);
compiled_wrapper.apply(self.target, [self.filename, self.target, require, include]);
node.loadingModules.shift();
self.waitChildrenLoad(function () {

Просмотреть файл

@ -0,0 +1,11 @@
include("common.js");
setTimeout(function () {
a = require("fixtures/a.js");
}, 50);
process.addListener("exit", function () {
assertTrue("A" in a);
assertEquals("A", a.A());
assertEquals("D", a.D());
});