shithub: libmujs

Download patch

ref: 0feb630124c74afff1d21473060c3f37f74e6e54
parent: 1237388b8e825ef032e81694a983b1eac2c6954a
author: Tor Andersson <[email protected]>
date: Sun Jan 19 08:28:01 EST 2014

Implement Function.prototype.apply()

--- a/jsbfunction.c
+++ b/jsbfunction.c
@@ -12,6 +12,33 @@
 	return 1;
 }
 
+static int Fp_apply(js_State *J, int n)
+{
+	int i, argc;
+	char name[20];
+
+	if (!js_iscallable(J, 0))
+		jsR_error(J, "TypeError");
+	js_copy(J, 0);
+
+	if (js_isundefined(J, 1) || js_isnull(J, 1))
+		js_pushglobal(J);
+	else
+		js_copy(J, 1);
+
+	js_getproperty(J, 2, "length");
+	argc = js_tonumber(J, -1);
+	js_pop(J, 1);
+
+	for (i = 0; i < argc; ++i) {
+		sprintf(name, "%d", i);
+		js_getproperty(J, 2, name);
+	}
+
+	js_call(J, argc);
+	return 1;
+}
+
 static int Fp_call(js_State *J, int n)
 {
 	int i;