Make instanceof a public function.

This commit is contained in:
Tor Andersson
2014-01-23 09:13:39 +01:00
parent 82a42ef1e6
commit a65416046c
4 changed files with 12 additions and 17 deletions
+1
View File
@@ -138,5 +138,6 @@ void js_concat(js_State *J);
int js_compare(js_State *J);
int js_equal(js_State *J);
int js_strictequal(js_State *J);
int js_instanceof(js_State *J);
#endif
+3 -1
View File
@@ -751,7 +751,9 @@ static void jsR_run(js_State *J, js_Function *F)
case OP_GE: b = js_compare(J); js_pushboolean(J, b >= 0); break;
case OP_INSTANCEOF:
js_instanceof(J);
b = js_instanceof(J);
js_pop(J, 2);
js_pushboolean(J, b);
break;
/* Equality */
+8 -14
View File
@@ -296,36 +296,30 @@ void js_newcconstructor(js_State *J, js_CFunction cfun, js_CFunction ccon)
/* Non-trivial operations on values. These are implemented using the stack. */
void js_instanceof(js_State *J)
int js_instanceof(js_State *J)
{
js_Object *O, *V;
if (!js_iscallable(J, -1))
js_typeerror(J, "instanceof: invalid operand");
if (!js_isobject(J, -2)) {
js_pop(J, 2);
js_pushboolean(J, 0);
return;
}
V = js_toobject(J, -2);
if (!js_isobject(J, -2))
return 0;
js_getproperty(J, -1, "prototype");
if (!js_isobject(J, -1))
js_typeerror(J, "instanceof: 'prototype' property is not an object");
O = js_toobject(J, -1);
js_pop(J, 1);
V = js_toobject(J, -2);
while (V) {
V = V->prototype;
if (O == V) {
js_pop(J, 3);
js_pushboolean(J, 1);
return;
}
if (O == V)
return 1;
}
js_pop(J, 3);
js_pushboolean(J, 0);
return 0;
}
void js_concat(js_State *J)
-2
View File
@@ -92,8 +92,6 @@ unsigned int jsV_numbertouint32(double n);
const char *jsV_numbertostring(js_State *J, double number);
double jsV_stringtonumber(js_State *J, const char *string);
void js_instanceof(js_State *J);
/* jsproperty.c */
js_Object *jsV_newobject(js_State *J, js_Class type, js_Object *prototype);
js_Property *jsV_getownproperty(js_State *J, js_Object *obj, const char *name);