changeset 0:d14fb1d5326c

Origination
author Atul Varma <varmaa@toolness.com>
date Thu, 18 Jun 2009 20:13:37 -0700
parents
children 7444443d2646
files .hgignore pavement.py spidermonkey-playground.c
diffstat 3 files changed, 90 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore	Thu Jun 18 20:13:37 2009 -0700
@@ -0,0 +1,3 @@
+syntax: glob
+*.dylib
+spidermonkey-playground
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pavement.py	Thu Jun 18 20:13:37 2009 -0700
@@ -0,0 +1,26 @@
+import os
+import subprocess
+import shutil
+
+from paver.easy import *
+
+@task
+def auto(options):
+    objdir = os.path.join("..", "mozilla-stuff", "basic-firefox", "dist")
+    objdir = os.path.abspath(objdir)
+    incdir = os.path.join(objdir, "include")
+    libdir = os.path.join(objdir, "lib")
+
+    cmdline = ["gcc", "spidermonkey-playground.c",
+               "-o", "spidermonkey-playground",
+               "-I%s" % incdir, "-L%s" % libdir, "-lmozjs"]
+
+    for dylib in ["mozjs", "plds4", "plc4", "nspr4"]:
+        name = "lib%s.dylib" % dylib
+        print "copying %s" % name
+        shutil.copyfile(os.path.join(libdir, name),
+                        "./%s" % name)
+
+    print " ".join(cmdline)
+    if subprocess.call(cmdline):
+        raise Exception("build failed")
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/spidermonkey-playground.c	Thu Jun 18 20:13:37 2009 -0700
@@ -0,0 +1,61 @@
+#include "jsapi.h"
+
+/* The class of the global object. */
+static JSClass global_class = {
+  "global", JSCLASS_GLOBAL_FLAGS,
+  JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
+  JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
+  JSCLASS_NO_OPTIONAL_MEMBERS
+};
+
+/* The error reporter callback. */
+void reportError(JSContext *cx, const char *message, JSErrorReport *report)
+{
+  fprintf(stderr, "%s:%u:%s\n",
+          report->filename ? report->filename : "<no filename>",
+          (unsigned int) report->lineno,
+          message);
+}
+
+int main(int argc, const char *argv[])
+{
+  /* JS variables. */
+  JSRuntime *rt;
+  JSContext *cx;
+  JSObject  *global;
+
+  /* Create a JS runtime. */
+  rt = JS_NewRuntime(8L * 1024L * 1024L);
+  if (rt == NULL)
+    return 1;
+
+  /* Create a context. */
+  cx = JS_NewContext(rt, 8192);
+  if (cx == NULL)
+    return 1;
+  JS_SetOptions(cx, JSOPTION_VAROBJFIX);
+  JS_SetVersion(cx, JSVERSION_LATEST);
+  JS_SetErrorReporter(cx, reportError);
+
+  /* Create the global object. */
+  global = JS_NewObject(cx, &global_class, NULL, NULL);
+  if (global == NULL)
+    return 1;
+
+  /* Populate the global object with the standard globals,
+     like Object and Array. */
+  if (!JS_InitStandardClasses(cx, global))
+    return 1;
+
+  /* Your application code here. This may include JSAPI calls
+     to create your own custom JS objects and run scripts. */
+  printf("JS initialized.\n");
+
+  /* Cleanup. */
+  JS_DestroyContext(cx);
+  JS_DestroyRuntime(rt);
+  JS_ShutDown();
+
+  printf("Farewell.\n");
+  return 0;
+}