ref: b8aa34d91910785c37b35e950c1c4d626ba59a1a
parent: 06e821df4a51a4b71d33f72b3c293894a6b67ff9
author: Tor Andersson <[email protected]>
date: Fri Feb 7 12:39:29 EST 2014
JSON skeleton.
--- a/jsbuiltin.c
+++ b/jsbuiltin.c
@@ -202,6 +202,7 @@
jsB_initregexp(J);
jsB_initerror(J);
jsB_initmath(J);
+ jsB_initjson(J);
jsB_initdate(J);
/* Initialize the global object */
--- a/jsbuiltin.h
+++ b/jsbuiltin.h
@@ -11,6 +11,7 @@
void jsB_initregexp(js_State *J);
void jsB_initerror(js_State *J);
void jsB_initmath(js_State *J);
+void jsB_initjson(js_State *J);
void jsB_initdate(js_State *J);
void jsB_propf(js_State *J, const char *name, js_CFunction cfun, int n);
--- a/jsobject.c
+++ b/jsobject.c
@@ -36,6 +36,7 @@
case JS_CREGEXP: js_pushliteral(J, "[object RegExp]"); break;
case JS_CDATE: js_pushliteral(J, "[object Date]"); break;
case JS_CMATH: js_pushliteral(J, "[object Math]"); break;
+ case JS_CJSON: js_pushliteral(J, "[object JSON]"); break;
case JS_CITERATOR: js_pushliteral(J, "[Iterator]"); break;
case JS_CUSERDATA:
js_pushliteral(J, "[object ");
--- /dev/null
+++ b/json.c
@@ -1,0 +1,23 @@
+#include "jsi.h"
+#include "jsvalue.h"
+#include "jsbuiltin.h"
+
+static int JSON_parse(js_State *J, int argc)
+{
+ return 0;
+}
+
+static int JSON_stringify(js_State *J, int argc)
+{
+ return 0;
+}
+
+void jsB_initjson(js_State *J)
+{
+ js_pushobject(J, jsV_newobject(J, JS_CJSON, J->Object_prototype));
+ {
+ jsB_propf(J, "parse", JSON_parse, 2);
+ jsB_propf(J, "stringify", JSON_stringify, 3);
+ }
+ js_defglobal(J, "JSON", JS_DONTENUM);
+}
--- a/jsvalue.h
+++ b/jsvalue.h
@@ -29,6 +29,7 @@
JS_CREGEXP,
JS_CDATE,
JS_CMATH,
+ JS_CJSON,
JS_CITERATOR,
JS_CUSERDATA,
};