diff spidermonkey-playground.cpp @ 70:f6e3733eac01

Refactored some code, fixed some TODOs.
author Atul Varma <varmaa@toolness.com>
date Thu, 25 Jun 2009 18:11:01 -0700
parents be61430630ab
children b87b6ebb6e86
line wrap: on
line diff
--- a/spidermonkey-playground.cpp	Thu Jun 25 17:53:28 2009 -0700
+++ b/spidermonkey-playground.cpp	Thu Jun 25 18:11:01 2009 -0700
@@ -151,12 +151,6 @@
 }
 
 static JSFunctionSpec tcb_global_functions[] = {
-  JS_FS("print",          TCB_print,          1, 0, 0),
-  JS_FS("stack",          TCB_stack,          0, 0, 0),
-  JS_FS("lookupProperty", TCB_lookupProperty, 2, 0, 0),
-  JS_FS("functionInfo",   TCB_functionInfo,   1, 0, 0),
-  JS_FS("enumerate",      TCB_enumerate,      1, 0, 0),
-  JS_FS("forceGC",        TCB_forceGC,        0, 0, 0),
   JS_FS("getWrapper",     getWrapper,         1, 0, 0),
   JS_FS("unwrap",         unwrapObject,       1, 0, 0),
   JS_FS("wrap",           wrapObject,         2, 0, 0),
@@ -193,34 +187,17 @@
 
   JS_BeginRequest(tcb_cx);
 
-#ifdef DEBUG
-  JS_SetGCZeal(tcb_cx, 2);
-#endif
+  jsval rval;
 
-  /* Create the TCB's global object. */
-  tcb_global = JS_NewObject(tcb_cx, &TCB_global_class, NULL, NULL);
-  if (tcb_global == NULL)
+  if (!TCB_init(tcb_cx, &rval))
     return 1;
+  tcb_global = JSVAL_TO_OBJECT(rval);
 
   JS_AddNamedRoot(tcb_cx, &tcb_global, "TCB Global");
 
-  /* Populate the tcb_global object with the standard globals,
-     like Object and Array. */
-  if (!JS_InitStandardClasses(tcb_cx, tcb_global))
-    return 1;
-
   if (!JS_DefineFunctions(tcb_cx, tcb_global, tcb_global_functions))
     return 1;
 
-  // TODO: Check for return values here.
-  JS_SetThrowHook(rt, TCB_throwHook, tcb_global);
-  JS_DefineProperty(tcb_cx, tcb_global, "lastExceptionTraceback", JSVAL_NULL,
-                    NULL, NULL, 0);
-  JS_DefineProperty(tcb_cx, tcb_global, "lastException", JSVAL_NULL,
-                    NULL, NULL, 0);
-
-  /* Your application code here. This may include JSAPI calls
-     to create your own custom JS objects and run scripts. */
   FILE *f = fopen(TCB_FILENAME, "r");
   if (!f)
     return 1;
@@ -233,7 +210,6 @@
   fread(source, fileSize, 1, f);
   fclose(f);
 
-  jsval rval;
   if (!JS_EvaluateScript(tcb_cx, tcb_global, source,
                          fileSize, TCB_FILENAME, 1,
                          &rval)) {