diff --git a/js.h b/js.h index 411001b..32723c8 100644 --- a/js.h +++ b/js.h @@ -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 diff --git a/jsrun.c b/jsrun.c index d7c7eee..acbe3fa 100644 --- a/jsrun.c +++ b/jsrun.c @@ -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 */ diff --git a/jsvalue.c b/jsvalue.c index fc29682..f452cfe 100644 --- a/jsvalue.c +++ b/jsvalue.c @@ -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) diff --git a/jsvalue.h b/jsvalue.h index 50312d8..78d8ec9 100644 --- a/jsvalue.h +++ b/jsvalue.h @@ -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);