Commit 87ac636c authored by Gabriel Ivăncescu's avatar Gabriel Ivăncescu Committed by Alexandre Julliard

jscript: Implement Object.prototype.isPrototypeOf method.

parent 6c8500d0
......@@ -196,8 +196,24 @@ static HRESULT Object_propertyIsEnumerable(script_ctx_t *ctx, vdisp_t *jsthis, W
static HRESULT Object_isPrototypeOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
jsval_t *r)
{
FIXME("\n");
return E_NOTIMPL;
jsdisp_t *jsdisp;
BOOL ret = FALSE;
if(!r)
return S_OK;
if(argc && is_jsdisp(jsthis) && is_object_instance(argv[0]) && (jsdisp = to_jsdisp(get_object(argv[0])))) {
while(jsdisp->prototype) {
if(jsdisp->prototype == jsthis->u.jsdisp) {
ret = TRUE;
break;
}
jsdisp = jsdisp->prototype;
}
}
*r = jsval_bool(ret);
return S_OK;
}
static HRESULT Object_get_value(script_ctx_t *ctx, jsdisp_t *jsthis, jsval_t *r)
......
......@@ -1679,14 +1679,28 @@ tmp = new instanceOfTest();
ok((tmp instanceof instanceOfTest) === true, "tmp is not instance of instanceOfTest");
ok((tmp instanceof Object) === true, "tmp is not instance of Object");
ok((tmp instanceof String) === false, "tmp is instance of String");
ok(instanceOfTest.isPrototypeOf(tmp) === false, "instanceOfTest is prototype of tmp");
ok(instanceOfTest.prototype.isPrototypeOf(tmp) === true, "instanceOfTest.prototype is not prototype of tmp");
ok(Object.prototype.isPrototypeOf(tmp) === true, "Object.prototype is not prototype of tmp");
instanceOfTest.prototype = new Object();
ok((tmp instanceof instanceOfTest) === false, "tmp is instance of instanceOfTest");
ok((tmp instanceof Object) === true, "tmp is not instance of Object");
ok(instanceOfTest.prototype.isPrototypeOf(tmp) === false, "instanceOfTest.prototype is prototype of tmp");
ok((1 instanceof Object) === false, "1 is instance of Object");
ok((false instanceof Boolean) === false, "false is instance of Boolean");
ok(("" instanceof Object) === false, "'' is instance of Object");
ok(Number.prototype.isPrototypeOf(1) === false, "Number.prototype is prototype of 1");
ok(String.prototype.isPrototypeOf("") === false, "String.prototype is prototype of ''");
ok(tmp.isPrototypeOf(null) === false, "tmp is prototype of null");
ok(tmp.isPrototypeOf(undefined) === false, "tmp is prototype of undefined");
ok(Object.prototype.isPrototypeOf.call(tmp) === false, "tmp is prototype of no argument");
ok(Object.prototype.isPrototypeOf.call(test, Object) === false, "test is prototype of Object");
ok(Object.prototype.isPrototypeOf.call(testObj, Object) === false, "testObj is prototype of Object");
ok(Object.prototype.isPrototypeOf(test) === false, "Object.prototype is prototype of test");
ok(Object.prototype.isPrototypeOf(testObj) === false, "Object.prototype is prototype of testObj");
(function () {
ok((arguments instanceof Object) === true, "argument is not instance of Object");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment