trying to extend web world for this.
This commit is contained in:
parent
cf40b06d69
commit
714eb87844
|
@ -1,11 +0,0 @@
|
||||||
#lang planet dyoo/whalesong
|
|
||||||
(require (planet dyoo/whalesong/js))
|
|
||||||
|
|
||||||
(define js-plus
|
|
||||||
(js-function (js-eval "function(x, y) { return x + y; }")))
|
|
||||||
|
|
||||||
(define js-minus
|
|
||||||
(js-function (js-eval "function(x, y) { return x - y; }")))
|
|
||||||
|
|
||||||
"plus: " (js-plus 3 4)
|
|
||||||
"minus:" (js-minus 239748 23)
|
|
|
@ -173,7 +173,7 @@
|
||||||
for (i = 0; i < MACHINE.a ; i = i+1) {
|
for (i = 0; i < MACHINE.a ; i = i+1) {
|
||||||
args.push(MACHINE.e[MACHINE.e.length - 1 - i]);
|
args.push(MACHINE.e[MACHINE.e.length - 1 - i]);
|
||||||
}
|
}
|
||||||
return f.call(null, args);
|
return f.apply(null, args);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -199,7 +199,7 @@
|
||||||
MACHINE,
|
MACHINE,
|
||||||
plt.baselib.format.format(
|
plt.baselib.format.format(
|
||||||
"~a",
|
"~a",
|
||||||
[((e && e.message) ? e.message : "unknown error")]));
|
[((e && e.message) ? e.message : e || "unknown error")]));
|
||||||
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -210,7 +210,7 @@
|
||||||
}
|
}
|
||||||
args.unshift(onFail);
|
args.unshift(onFail);
|
||||||
args.unshift(onSuccess);
|
args.unshift(onSuccess);
|
||||||
return f.call(null, args);
|
return f.apply(null, args);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
39
js/world/js-impl.js
Normal file
39
js/world/js-impl.js
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var resourceStructType =
|
||||||
|
MACHINE.modules['whalesong/web-world.rkt'].getNamespace().get('');
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an event source coupled to a JavaScript function. Calling the function
|
||||||
|
* should cause the event source to fire.
|
||||||
|
*/
|
||||||
|
var makeJsEventSource = function() {
|
||||||
|
var enabled = false;
|
||||||
|
var fireEvent;
|
||||||
|
|
||||||
|
var JsEventSource = function() {};
|
||||||
|
JsEventSource.prototype = plt.baselib.heir(EventSource.prototype);
|
||||||
|
JsEventSource.prototype.onStart = function(_fireEvent) {
|
||||||
|
enabled = true;
|
||||||
|
fireEvent = _fireEvent;
|
||||||
|
};
|
||||||
|
JsEventSource.prototype.onStop = function() {
|
||||||
|
enabled = false;
|
||||||
|
fireEvent = void(0);
|
||||||
|
};
|
||||||
|
|
||||||
|
var sender = function() {
|
||||||
|
if (enabled) {
|
||||||
|
var args = Array.prototype.slice.call(arguments, 0);
|
||||||
|
args.unshift(void(0));
|
||||||
|
fireEvent.apply(null, args);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return { eventSource: new JsEventSource(),
|
||||||
|
sender: sender };
|
||||||
|
};
|
||||||
|
|
||||||
|
}());
|
6
js/world/main.rkt
Normal file
6
js/world/main.rkt
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
#lang s-exp "../lang/js/js.rkt"
|
||||||
|
(require "../../web-world.rkt")
|
||||||
|
(declare-implementation
|
||||||
|
#:racket "racket-impl.rkt"
|
||||||
|
#:javascript ("js-impl.js")
|
||||||
|
#:provided-values ())
|
1
js/world/racket-impl.rkt
Normal file
1
js/world/racket-impl.rkt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
#lang s-exp "../../lang/base.rkt"
|
7
tests/more-tests/js-binding.expected
Normal file
7
tests/more-tests/js-binding.expected
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
"plus: "
|
||||||
|
7
|
||||||
|
"wait for one second: "
|
||||||
|
#<undefined>
|
||||||
|
"minus:"
|
||||||
|
239725
|
||||||
|
helloworldtesting
|
29
tests/more-tests/js-binding.rkt
Normal file
29
tests/more-tests/js-binding.rkt
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
#lang planet dyoo/whalesong
|
||||||
|
(require (planet dyoo/whalesong/js))
|
||||||
|
|
||||||
|
(define js-plus
|
||||||
|
(js-function (js-eval "function(x, y) { return x + y; }")))
|
||||||
|
|
||||||
|
(define js-minus
|
||||||
|
(js-function (js-eval "function(x, y) { return x - y; }")))
|
||||||
|
|
||||||
|
(define sleep
|
||||||
|
(js-async-function (js-eval "function(success, fail, n) { setTimeout(success, n) }")))
|
||||||
|
|
||||||
|
|
||||||
|
"plus: " (js-plus 3 4)
|
||||||
|
"wait for one second: " (sleep 1000)
|
||||||
|
"minus:" (js-minus 239748 23)
|
||||||
|
|
||||||
|
|
||||||
|
(for-each (lambda (x)
|
||||||
|
(display x)
|
||||||
|
(sleep 1000))
|
||||||
|
'(hello world testing))
|
||||||
|
|
||||||
|
|
||||||
|
;; I need exception handling...
|
||||||
|
;;
|
||||||
|
;(define i-should-fail
|
||||||
|
; (js-async-function (js-eval "function(success, fail) { fail('I should fail'); }")))
|
||||||
|
;(i-should-fail)
|
|
@ -6,6 +6,7 @@
|
||||||
;; content vs. a text file with the same name, but with the .rkt file
|
;; content vs. a text file with the same name, but with the .rkt file
|
||||||
;; type replaced with .expected.
|
;; type replaced with .expected.
|
||||||
|
|
||||||
|
(test "more-tests/js-binding.rkt")
|
||||||
(test "more-tests/simple.rkt")
|
(test "more-tests/simple.rkt")
|
||||||
(test "more-tests/simple-loop.rkt")
|
(test "more-tests/simple-loop.rkt")
|
||||||
(test "more-tests/booleans.rkt")
|
(test "more-tests/booleans.rkt")
|
||||||
|
|
|
@ -7,4 +7,4 @@
|
||||||
(provide version)
|
(provide version)
|
||||||
(: version String)
|
(: version String)
|
||||||
|
|
||||||
(define version "1.218")
|
(define version "1.221")
|
||||||
|
|
|
@ -929,7 +929,6 @@
|
||||||
EventSource.prototype.onStop = function() {
|
EventSource.prototype.onStop = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// TickEventSource sends tick events.
|
// TickEventSource sends tick events.
|
||||||
|
@ -2200,5 +2199,10 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// For private importers of the web-world library, like the FFI's js/world library.
|
||||||
|
Exports['EventSource'] = EventSource;
|
||||||
|
Exports['EventHandler'] = EventHandler;
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
}());
|
}());
|
Loading…
Reference in New Issue
Block a user