chasing initialization bug
This commit is contained in:
parent
bf2213d2b4
commit
b9e7ae57e6
|
@ -225,6 +225,7 @@ MACHINE.modules[~s] =
|
|||
|
||||
|
||||
(define (on-last-src)
|
||||
(fprintf op "console.log('module loaded'); plt.runtime.setReadyTrue();")
|
||||
(fprintf op "SUCCESS();"))
|
||||
|
||||
|
||||
|
@ -246,6 +247,7 @@ MACHINE.modules[~s] =
|
|||
|
||||
(fprintf op "var invoke = (function(MACHINE, SUCCESS, FAIL, PARAMS) {")
|
||||
(fprintf op " plt.runtime.ready(function() {")
|
||||
(fprintf op "console.log('loading module'); plt.runtime.setReadyFalse();")
|
||||
(make (list (make-MainModuleSource source-code))
|
||||
packaging-configuration)
|
||||
(fprintf op " });");
|
||||
|
|
|
@ -10,6 +10,9 @@
|
|||
// its argument stack space.
|
||||
//
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// coerseToJavaScript: racket function -> JavaScript function
|
||||
// Given a closure or primitive, produces an
|
||||
|
@ -196,4 +199,6 @@
|
|||
|
||||
exports.isFunction = isFunction;
|
||||
|
||||
exports.coerseToJavaScript = coerseToJavaScript;
|
||||
|
||||
})(this['plt'].baselib);
|
|
@ -1785,25 +1785,33 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
|
|||
|
||||
(function(scope) {
|
||||
scope.ready = function(f) {
|
||||
console.log('request');
|
||||
if (runtimeIsReady) {
|
||||
notifyWaiter(f);
|
||||
} else {
|
||||
readyWaiters.push(f);
|
||||
}
|
||||
};
|
||||
|
||||
scope.setReadyTrue = function() {
|
||||
var i;
|
||||
console.log("runtime is ready");
|
||||
runtimeIsReady = true;
|
||||
for (i = 0; i < readyWaiters.length; i++) {
|
||||
notifyWaiter(readyWaiters[i]);
|
||||
while(runtimeIsReady && readyWaiters.length > 0) {
|
||||
notifyWaiter(readyWaiters.shift());
|
||||
}
|
||||
readyWaiters = [];
|
||||
};
|
||||
|
||||
scope.setReadyFalse = function() {
|
||||
console.log("disabled runtime");
|
||||
runtimeIsReady = false;
|
||||
};
|
||||
|
||||
|
||||
var runtimeIsReady = false;
|
||||
var readyWaiters = [];
|
||||
var notifyWaiter = function(w) {
|
||||
setTimeout(w, 0);
|
||||
console.log('notifying waiter');
|
||||
w();
|
||||
};
|
||||
})(this);
|
||||
|
||||
|
@ -1831,6 +1839,17 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
|
|||
});
|
||||
};
|
||||
|
||||
// Looks up a name in any of the machine's main modules.
|
||||
var lookupInMains = function(name, machine) {
|
||||
machine = machine || runtime.currentMachine;
|
||||
for (var i = 0; i < machine.mainModules.length; i++) {
|
||||
var ns = machine.mainModules[i].getNamespace();
|
||||
if(ns.hasOwnProperty(name)) {
|
||||
return ns[name];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
@ -1842,6 +1861,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
|
|||
var exports = runtime;
|
||||
exports['currentMachine'] = new Machine();
|
||||
exports['invokeMains'] = invokeMains;
|
||||
exports['lookupInMains'] = lookupInMains;
|
||||
|
||||
|
||||
// installing new primitives
|
||||
|
@ -1854,7 +1874,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
|
|||
// Private: the runtime library will set this flag to true when
|
||||
// the library has finished loading.
|
||||
exports['setReadyTrue'] = setReadyTrue;
|
||||
|
||||
exports['setReadyFalse'] = setReadyFalse;
|
||||
|
||||
exports['Machine'] = Machine;
|
||||
exports['Frame'] = Frame;
|
||||
|
|
5
tests/coersing/Makefile
Normal file
5
tests/coersing/Makefile
Normal file
|
@ -0,0 +1,5 @@
|
|||
#!/bin/sh
|
||||
|
||||
all:
|
||||
../../whalesong get-javascript fact.rkt > fact.js
|
||||
../../whalesong get-runtime > runtime.js
|
11
tests/coersing/fact.rkt
Normal file
11
tests/coersing/fact.rkt
Normal file
|
@ -0,0 +1,11 @@
|
|||
#lang planet dyoo/whalesong
|
||||
(provide fact)
|
||||
(define (fact x)
|
||||
(cond
|
||||
[(= x 0)
|
||||
1]
|
||||
[else
|
||||
(* x (fact (sub1 x)))]))
|
||||
|
||||
|
||||
(printf "fact invoked\n")
|
28
tests/coersing/index.html
Normal file
28
tests/coersing/index.html
Normal file
|
@ -0,0 +1,28 @@
|
|||
<html>
|
||||
<head>
|
||||
|
||||
<script src="runtime.js"></script>
|
||||
<script src="fact.js"></script>
|
||||
|
||||
<script>
|
||||
</script>
|
||||
<script>
|
||||
|
||||
plt.runtime.invokeMains();
|
||||
|
||||
plt.runtime.ready(function() {
|
||||
var myFact = plt.runtime.lookupInMains('fact');
|
||||
myFact(function(v) {
|
||||
alert(v.toString());
|
||||
},
|
||||
function(err) {
|
||||
alert(err);
|
||||
},
|
||||
1000);
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user