From c76ce39a8716a3e91e804ebe39fa845b059df5e7 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Tue, 24 Oct 2006 15:52:44 +0200 Subject: [PATCH] SpiderMonkey: added setTimeout. --- src/ecmascript/spidermonkey/window.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/ecmascript/spidermonkey/window.c b/src/ecmascript/spidermonkey/window.c index 3aefa2ea..380511f7 100644 --- a/src/ecmascript/spidermonkey/window.c +++ b/src/ecmascript/spidermonkey/window.c @@ -262,10 +262,12 @@ window_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) static JSBool window_alert(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); static JSBool window_open(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); +static JSBool window_setTimeout(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); const JSFunctionSpec window_funcs[] = { { "alert", window_alert, 1 }, { "open", window_open, 3 }, + { "setTimeout", window_setTimeout, 2 }, { NULL } }; @@ -382,3 +384,25 @@ end: return JS_TRUE; } + +static JSBool +window_setTimeout(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + struct ecmascript_interpreter *interpreter = JS_GetContextPrivate(ctx); + unsigned char *code; + int timeout; + + if (argc != 2) + return JS_TRUE; + + code = jsval_to_string(ctx, &argv[0]); + if (!*code) + return JS_TRUE; + + code = stracpy(code); + if (!code) + return JS_TRUE; + timeout = atoi(jsval_to_string(ctx, &argv[1])); + ecmascript_set_timeout(interpreter, code, timeout); + return JS_TRUE; +}