trying to extend web world for this.

This commit is contained in:
Danny Yoo 2012-03-04 20:24:34 -05:00
parent cf40b06d69
commit 714eb87844
10 changed files with 92 additions and 16 deletions

View File

@ -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)

View File

@ -173,7 +173,7 @@
for (i = 0; i < MACHINE.a ; i = i+1) {
args.push(MACHINE.e[MACHINE.e.length - 1 - i]);
}
return f.call(null, args);
return f.apply(null, args);
});
});
@ -199,7 +199,7 @@
MACHINE,
plt.baselib.format.format(
"~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(onSuccess);
return f.call(null, args);
return f.apply(null, args);
});
});
});

39
js/world/js-impl.js Normal file
View 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
View 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
View File

@ -0,0 +1 @@
#lang s-exp "../../lang/base.rkt"

View File

@ -0,0 +1,7 @@
"plus: "
7
"wait for one second: "
#<undefined>
"minus:"
239725
helloworldtesting

View 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)

View File

@ -6,6 +6,7 @@
;; content vs. a text file with the same name, but with the .rkt file
;; type replaced with .expected.
(test "more-tests/js-binding.rkt")
(test "more-tests/simple.rkt")
(test "more-tests/simple-loop.rkt")
(test "more-tests/booleans.rkt")

View File

@ -7,4 +7,4 @@
(provide version)
(: version String)
(define version "1.218")
(define version "1.221")

View File

@ -929,7 +929,6 @@
EventSource.prototype.onStop = function() {
};
// 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;
//////////////////////////////////////////////////////////////////////
}());