shithub: libmujs

Download patch

ref: f8ff8652488fe34b917949c474ff4a7c39b94589
parent: 702fb1eb4a1a2d26e8bed54c9498d771e9e53fa7
author: Tor Andersson <[email protected]>
date: Fri Jan 17 20:22:11 EST 2014

Move object creation functions into jsobject.c

--- a/jsobject.c
+++ b/jsobject.c
@@ -1,8 +1,10 @@
 #include "js.h"
+#include "jscompile.h"
+#include "jsrun.h"
 #include "jsobject.h"
 #include "jsstate.h"
 
-js_Object *jsR_newfunction(js_State *J, js_Function *function, js_Environment *scope)
+static js_Object *jsR_newfunction(js_State *J, js_Function *function, js_Environment *scope)
 {
 	js_Object *obj = jsR_newobject(J, JS_CFUNCTION, J->Function_prototype);
 	obj->function = function;
@@ -10,7 +12,7 @@
 	return obj;
 }
 
-js_Object *jsR_newscript(js_State *J, js_Function *function)
+static js_Object *jsR_newscript(js_State *J, js_Function *function)
 {
 	js_Object *obj = jsR_newobject(J, JS_CSCRIPT, NULL);
 	obj->function = function;
@@ -17,7 +19,7 @@
 	return obj;
 }
 
-js_Object *jsR_newcfunction(js_State *J, js_CFunction cfunction)
+static js_Object *jsR_newcfunction(js_State *J, js_CFunction cfunction)
 {
 	js_Object *obj = jsR_newobject(J, JS_CCFUNCTION, NULL);
 	obj->cfunction = cfunction;
@@ -25,7 +27,7 @@
 	return obj;
 }
 
-js_Object *jsR_newcconstructor(js_State *J, js_CFunction cfunction, js_CFunction cconstructor)
+static js_Object *jsR_newcconstructor(js_State *J, js_CFunction cfunction, js_CFunction cconstructor)
 {
 	js_Object *obj = jsR_newobject(J, JS_CCFUNCTION, NULL);
 	obj->cfunction = cfunction;
@@ -52,4 +54,50 @@
 	js_Object *obj = jsR_newobject(J, JS_CSTRING, J->String_prototype);
 	obj->primitive.string = v;
 	return obj;
+}
+
+void js_newobject(js_State *J)
+{
+	js_pushobject(J, jsR_newobject(J, JS_COBJECT, J->Object_prototype));
+}
+
+void js_newarray(js_State *J)
+{
+	js_pushobject(J, jsR_newobject(J, JS_CARRAY, J->Array_prototype));
+}
+
+void js_newfunction(js_State *J, js_Function *F, js_Environment *scope)
+{
+	js_pushobject(J, jsR_newfunction(J, F, scope));
+	js_pushnumber(J, F->numparams);
+	js_setproperty(J, -2, "length");
+	js_newobject(J);
+	js_copy(J, -2);
+	js_setproperty(J, -2, "constructor");
+	js_setproperty(J, -2, "prototype");
+}
+
+void js_newscript(js_State *J, js_Function *F)
+{
+	js_pushobject(J, jsR_newscript(J, F));
+}
+
+void js_newcfunction(js_State *J, js_CFunction fun)
+{
+	js_pushobject(J, jsR_newcfunction(J, fun));
+	// TODO: length property?
+	js_newobject(J);
+	js_copy(J, -2);
+	js_setproperty(J, -2, "constructor");
+	js_setproperty(J, -2, "prototype");
+}
+
+void js_newcconstructor(js_State *J, js_CFunction fun, js_CFunction con)
+{
+	js_pushobject(J, jsR_newcconstructor(J, fun, con));
+	// TODO: length property?
+	js_newobject(J);
+	js_copy(J, -2);
+	js_setproperty(J, -2, "constructor");
+	js_setproperty(J, -2, "prototype");
 }
--- a/jsobject.h
+++ b/jsobject.h
@@ -97,10 +97,6 @@
 js_Property *jsR_nextproperty(js_State *J, js_Object *obj, const char *name);
 
 /* jsobject.c */
-js_Object *jsR_newfunction(js_State *J, js_Function *function, js_Environment *scope);
-js_Object *jsR_newscript(js_State *J, js_Function *function);
-js_Object *jsR_newcfunction(js_State *J, js_CFunction cfunction);
-js_Object *jsR_newcconstructor(js_State *J, js_CFunction cfunction, js_CFunction cconstructor);
 js_Object *jsR_newboolean(js_State *J, int v);
 js_Object *jsR_newnumber(js_State *J, double v);
 js_Object *jsR_newstring(js_State *J, const char *v);
--- a/jsrun.c
+++ b/jsrun.c
@@ -100,47 +100,6 @@
 	js_pushobject(J, J->G);
 }
 
-void js_newobject(js_State *J)
-{
-	js_pushobject(J, jsR_newobject(J, JS_COBJECT, J->Object_prototype));
-}
-
-void js_newarray(js_State *J)
-{
-	js_pushobject(J, jsR_newobject(J, JS_CARRAY, J->Array_prototype));
-}
-
-void js_newfunction(js_State *J, js_Function *F, js_Environment *scope)
-{
-	js_pushobject(J, jsR_newfunction(J, F, scope));
-	js_pushnumber(J, F->numparams);
-	js_setproperty(J, -2, "length");
-	js_newobject(J);
-	js_copy(J, -2);
-	js_setproperty(J, -2, "constructor");
-	js_setproperty(J, -2, "prototype");
-}
-
-void js_newcfunction(js_State *J, js_CFunction fun)
-{
-	js_pushobject(J, jsR_newcfunction(J, fun));
-	// TODO: length property?
-	js_newobject(J);
-	js_copy(J, -2);
-	js_setproperty(J, -2, "constructor");
-	js_setproperty(J, -2, "prototype");
-}
-
-void js_newcconstructor(js_State *J, js_CFunction fun, js_CFunction con)
-{
-	js_pushobject(J, jsR_newcconstructor(J, fun, con));
-	// TODO: length property?
-	js_newobject(J);
-	js_copy(J, -2);
-	js_setproperty(J, -2, "constructor");
-	js_setproperty(J, -2, "prototype");
-}
-
 /* Read values from stack */
 
 static const js_Value *stackidx(js_State *J, int idx)
@@ -839,7 +798,7 @@
 	jsP_freeparse(J);
 	if (!F) return 1;
 
-	js_pushobject(J, jsR_newscript(J, F));
+	js_newscript(J, F);
 	return 0;
 }
 
--- a/jsrun.h
+++ b/jsrun.h
@@ -38,6 +38,8 @@
 
 void js_newobject(js_State *J);
 void js_newarray(js_State *J);
+void js_newfunction(js_State *J, js_Function *function, js_Environment *scope);
+void js_newscript(js_State *J, js_Function *function);
 void js_newcfunction(js_State *J, js_CFunction fun);
 void js_newcconstructor(js_State *J, js_CFunction fun, js_CFunction con);