shithub: libmujs

Download patch

ref: fac3f501e441f946f9d90eb566439920f5fe1bfd
parent: 15fb4095b357d0244f83089ee59e55e755a05336
author: Tor Andersson <tor@ccxvii.net>
date: Sat Jan 25 17:56:16 EST 2014

Add js_hasproperty function.

--- a/js.h
+++ b/js.h
@@ -94,6 +94,7 @@
 void js_setproperty(js_State *J, int idx, const char *name);
 void js_defproperty(js_State *J, int idx, const char *name, int atts);
 void js_delproperty(js_State *J, int idx, const char *name);
+int js_hasproperty(js_State *J, int idx, const char *name);
 
 void js_pushglobal(js_State *J);
 void js_pushundefined(js_State *J);
--- a/jsfunction.c
+++ b/jsfunction.c
@@ -27,13 +27,13 @@
 		js_Function *F = self->u.f.function;
 		n = strlen("function () { ... }");
 		n += strlen(F->name);
-		for (i = 0; i < F->numparams; i++)
+		for (i = 0; i < F->numparams; ++i)
 			n += strlen(F->params[i]) + 1;
 		s = malloc(n);
 		strcpy(s, "function ");
 		strcat(s, F->name);
 		strcat(s, "(");
-		for (i = 0; i < F->numparams; i++) {
+		for (i = 0; i < F->numparams; ++i) {
 			if (i > 0) strcat(s, ",");
 			strcat(s, F->params[i]);
 		}
--- a/jsgc.c
+++ b/jsgc.c
@@ -49,7 +49,7 @@
 {
 	int i;
 	fun->gcmark = mark;
-	for (i = 0; i < fun->funlen; i++)
+	for (i = 0; i < fun->funlen; ++i)
 		if (fun->funtab[i]->gcmark != mark)
 			jsG_markfunction(J, mark, fun->funtab[i]);
 }
--- a/jsrun.c
+++ b/jsrun.c
@@ -430,6 +430,11 @@
 	jsR_delproperty(J, js_toobject(J, idx), name);
 }
 
+int js_hasproperty(js_State *J, int idx, const char *name)
+{
+	return !!jsV_getproperty(J, js_toobject(J, idx), name);
+}
+
 /* Environment records */
 
 js_Environment *jsR_newenvironment(js_State *J, js_Object *vars, js_Environment *outer)
@@ -759,8 +764,7 @@
 
 		case OP_IN:
 			str = js_tostring(J, -2);
-			obj = js_toobject(J, -1);
-			b = jsV_getproperty(J, obj, str) != NULL;
+			b = js_hasproperty(J, -1, str);
 			js_pop(J, 2);
 			js_pushboolean(J, b);
 			break;