Skip to content

Instantly share code, notes, and snippets.

@jarrodhroberson
Created February 14, 2014 03:11
Show Gist options
  • Save jarrodhroberson/8995163 to your computer and use it in GitHub Desktop.
Save jarrodhroberson/8995163 to your computer and use it in GitHub Desktop.
SpiderMonkey in Xcode 3.2.3
#define XP_UNIX
#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;
//TODO app goes here
/* Cleanup. */
JS_DestroyContext(cx);
JS_DestroyRuntime(rt);
JS_ShutDown();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment