shithub: libmujs

Download patch

ref: 805e0f0f596e4f8ce1195cd7c5aac77fcde761c2
parent: a4158ae6fff14017f38c425df648c99681b5eb3a
author: Tor Andersson <tor@ccxvii.net>
date: Fri Sep 9 15:56:35 EDT 2016

Add js_newobjectx to create an object with a specific prototype object.

--- a/jsi.h
+++ b/jsi.h
@@ -209,7 +209,6 @@
 	js_Object *gcobj;
 	js_String *gcstr;
 
-
 	/* environments on the call stack but currently not in scope */
 	int envtop;
 	js_Environment *envstack[JS_ENVLIMIT];
--- a/jsproperty.c
+++ b/jsproperty.c
@@ -154,7 +154,6 @@
 	return node;
 }
 
-
 js_Object *jsV_newobject(js_State *J, enum js_Class type, js_Object *prototype)
 {
 	js_Object *obj = js_malloc(J, sizeof *obj);
--- a/jsvalue.c
+++ b/jsvalue.c
@@ -343,6 +343,13 @@
 	}
 }
 
+void js_newobjectx(js_State *J)
+{
+	js_Object *prototype = js_toobject(J, -1);
+	js_pop(J, 1);
+	js_pushobject(J, jsV_newobject(J, JS_COBJECT, prototype));
+}
+
 void js_newobject(js_State *J)
 {
 	js_pushobject(J, jsV_newobject(J, JS_COBJECT, J->Object_prototype));
--- a/mujs.h
+++ b/mujs.h
@@ -136,6 +136,7 @@
 void js_pushlstring(js_State *J, const char *v, int n);
 void js_pushliteral(js_State *J, const char *v);
 
+void js_newobjectx(js_State *J);
 void js_newobject(js_State *J);
 void js_newarray(js_State *J);
 void js_newboolean(js_State *J, int v);