From: Artem S. Povalyukhin Date: Tue, 19 Nov 2019 14:22:53 +0000 (+0300) Subject: Fixed Object.getPrototypeOf() according to the specification. X-Git-Tag: 0.3.8~65 X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=e6056297fd87fd064e286fba410cfc2835da1d21;p=njs.git Fixed Object.getPrototypeOf() according to the specification. This closes #252 issue on Github. --- diff --git a/src/njs_object.c b/src/njs_object.c index 76d8698e..864298f7 100644 --- a/src/njs_object.c +++ b/src/njs_object.c @@ -1387,6 +1387,7 @@ static njs_int_t njs_object_get_prototype_of(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs, njs_index_t unused) { + uint32_t index; njs_value_t *value; value = njs_arg(args, nargs, 1); @@ -1396,6 +1397,15 @@ njs_object_get_prototype_of(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs, return NJS_OK; } + if (!njs_is_null_or_undefined(value)) { + index = njs_primitive_prototype_index(value->type); + + njs_set_type_object(&vm->retval, &vm->prototypes[index].object, + njs_object_value_type(value->type)); + + return NJS_OK; + } + njs_type_error(vm, "cannot convert %s argument to object", njs_type_string(value->type)); diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c index 953c717d..b0642690 100644 --- a/src/test/njs_unit_test.c +++ b/src/test/njs_unit_test.c @@ -11064,11 +11064,9 @@ static njs_unit_test_t njs_test[] = "Object.getPrototypeOf(o) === Object.prototype"), njs_str("true") }, - { njs_str("Object.getPrototypeOf(1)"), - njs_str("TypeError: cannot convert number argument to object") }, - - { njs_str("Object.getPrototypeOf('a')"), - njs_str("TypeError: cannot convert string argument to object") }, + { njs_str("[true, 42, '' /*, Symbol()*/]" + ".every((x) => Object.getPrototypeOf(x) == Object.getPrototypeOf(Object(x)))"), + njs_str("true") }, { njs_str("var p = {}; var o = Object.create(p);" "p.isPrototypeOf(o)"),