shithub: libmujs

Download patch

ref: 060dbbb03ca18062b4d6c3b0666b5924c592350b
parent: f487a7db10164e68f2f7d02d2bdc1f0b1aa2e8ef
author: Tor Andersson <tor@ccxvii.net>
date: Fri Jan 17 16:03:22 EST 2014

Create function objects with initial properties.

Set "length" and "prototype" and "prototype.constructor" properties.

Only for functions, not script functions or C-functions.

--- a/jsrun.c
+++ b/jsrun.c
@@ -117,6 +117,17 @@
 	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_pushcfunction(js_State *J, js_CFunction v)
 {
 	js_pushobject(J, jsR_newcfunction(J, v));
@@ -447,7 +458,7 @@
 		case OP_NUMBER: js_pushnumber(J, NT[*pc++]); break;
 		case OP_STRING: js_pushliteral(J, ST[*pc++]); break;
 
-		case OP_CLOSURE: js_pushobject(J, jsR_newfunction(J, FT[*pc++], J->E)); break;
+		case OP_CLOSURE: js_newfunction(J, FT[*pc++], J->E); break;
 		case OP_NEWOBJECT: js_newobject(J); break;
 		case OP_NEWARRAY: js_newarray(J); break;