Skip to content
Browse files

add a dummy setTimeout() to run jsx-v8bench

  • Loading branch information...
1 parent 760fe4b commit 6cacff889ec79f1b401a851080d1d82c7274418f @gfx committed Jun 15, 2013
Showing with 27 additions and 0 deletions.
  1. +4 −0 hello.js
  2. +23 −0 main.c
View
4 hello.js
@@ -1,3 +1,7 @@
#!nore
console.log("Hello, JavaScript/" + process.title + "!");
console.log("argv:", JSON.stringify(process.argv));
+
+setTimeout(function () {
+ console.log("in setTimeout()");
+}, 0);
View
23 main.c
@@ -75,6 +75,26 @@ printToStderrFunc(
}
static JSValueRef
+setTimeoutFunc(
+ JSContextRef ctx,
+ JSObjectRef jobj UNUSED,
+ JSObjectRef jobjThis,
+ size_t argLen,
+ const JSValueRef args[], /* (func, duration) */
+ JSValueRef* exception) {
+
+ if (argLen != 2) {
+ return JSValueMakeUndefined(ctx);
+ }
+
+ JSObjectCallAsFunction(ctx, JSValueToObject(ctx, args[0], exception), jobjThis, 0, NULL, exception);
+
+ return JSValueMakeUndefined(ctx);
+}
+
+// ---
+
+static JSValueRef
makeJSValueFromCString(JSContextRef ctx, const char* cstr) {
JSStringRef jstr = JSStringCreateWithUTF8CString(cstr);
JSValueRef jval = JSValueMakeString(ctx, jstr);
@@ -151,6 +171,9 @@ setupJSGlobals(JSContextRef ctx, JSObjectRef jobjGlobal, int argc, const char**
jvals[i] = makeJSValueFromCString(ctx, argv[i]);
}
setProperty(ctx, jsProcess, "argv", JSObjectMakeArray(ctx, argc, jvals, NULL));
+
+ // setTimeout()
+ setFunc(ctx, jobjGlobal, "setTimeout", setTimeoutFunc);
}
static JSStringRef readSourceFile(JSContextRef ctx UNUSED, const char* fileName) {

0 comments on commit 6cacff8

Please sign in to comment.
Something went wrong with that request. Please try again.