jscript: Add Object.getPrototypeOf implementation.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2019-03-11 14:39:27 +01:00 committed by Alexandre Julliard
parent a3037ec2f2
commit f2a07b117a
3 changed files with 60 additions and 2 deletions

View File

@ -34,6 +34,8 @@ static const WCHAR isPrototypeOfW[] = {'i','s','P','r','o','t','o','t','y','p','
static const WCHAR getOwnPropertyDescriptorW[] =
{'g','e','t','O','w','n','P','r','o','p','e','r','t','y','D','e','s','c','r','i','p','t','o','r',0};
static const WCHAR getPrototypeOfW[] =
{'g','e','t','P','r','o','t','o','t','y','p','e','O','f',0};
static const WCHAR definePropertyW[] = {'d','e','f','i','n','e','P','r','o','p','e','r','t','y',0};
static const WCHAR definePropertiesW[] = {'d','e','f','i','n','e','P','r','o','p','e','r','t','i','e','s',0};
@ -519,10 +521,36 @@ static HRESULT Object_getOwnPropertyDescriptor(script_ctx_t *ctx, vdisp_t *jsthi
return hres;
}
static HRESULT Object_getPrototypeOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
unsigned argc, jsval_t *argv, jsval_t *r)
{
jsdisp_t *obj;
if(!argc || !is_object_instance(argv[0])) {
FIXME("invalid arguments\n");
return E_NOTIMPL;
}
TRACE("(%s)\n", debugstr_jsval(argv[1]));
obj = to_jsdisp(get_object(argv[0]));
if(!obj) {
FIXME("Non-JS object\n");
return E_NOTIMPL;
}
if(r)
*r = obj->prototype
? jsval_obj(jsdisp_addref(obj->prototype))
: jsval_null();
return S_OK;
}
static const builtin_prop_t ObjectConstr_props[] = {
{definePropertiesW, Object_defineProperties, PROPF_ES5|PROPF_METHOD|2},
{definePropertyW, Object_defineProperty, PROPF_ES5|PROPF_METHOD|2},
{getOwnPropertyDescriptorW, Object_getOwnPropertyDescriptor, PROPF_ES5|PROPF_METHOD|2}
{getOwnPropertyDescriptorW, Object_getOwnPropertyDescriptor, PROPF_ES5|PROPF_METHOD|2},
{getPrototypeOfW, Object_getPrototypeOf, PROPF_ES5|PROPF_METHOD|1}
};
static const builtin_info_t ObjectConstr_info = {

View File

@ -198,6 +198,8 @@ function test_javascript() {
test_exposed("defineProperties", Object, v >= 8);
}
test_exposed("getPrototypeOf", Object, v >= 9);
test_parses("if(false) { o.default; }", v >= 9);
test_parses("if(false) { o.with; }", v >= 9);
test_parses("if(false) { o.if; }", v >= 9);

View File

@ -592,6 +592,33 @@ function test_string_split() {
next_test();
}
function test_getPrototypeOf() {
ok(Object.getPrototypeOf(new Object()) === Object.prototype,
"Object.getPrototypeOf(new Object()) !== Object.prototype");
function Constr() {}
var obj = new Constr();
ok(Object.getPrototypeOf(Constr.prototype) === Object.prototype,
"Object.getPrototypeOf(Constr.prototype) !== Object.prototype");
ok(Object.getPrototypeOf(obj) === Constr.prototype,
"Object.getPrototypeOf(obj) !== Constr.prototype");
var proto = new Object();
Constr.prototype = proto;
ok(Object.getPrototypeOf(obj) != proto,
"Object.getPrototypeOf(obj) == proto");
obj = new Constr();
ok(Object.getPrototypeOf(obj) === proto,
"Object.getPrototypeOf(obj) !== proto");
ok(Object.getPrototypeOf(obj, 2, 3, 4) === proto,
"Object.getPrototypeOf(obj) !== proto");
ok(Object.getPrototypeOf(Object.prototype) === null,
"Object.getPrototypeOf(Object.prototype) !== null");
next_test();
}
var tests = [
test_date_now,
test_toISOString,
@ -604,5 +631,6 @@ var tests = [
test_property_definitions,
test_string_trim,
test_global_properties,
test_string_split
test_string_split,
test_getPrototypeOf
];