[njs] Fixed Object.getPrototypeOf() according to the specification.
Dmitry Volyntsev
xeioex at nginx.com
Tue Nov 19 16:31:59 UTC 2019
details: https://hg.nginx.org/njs/rev/d4fdf0fc449d
branches:
changeset: 1244:d4fdf0fc449d
user: Artem S. Povalyukhin <artem.povaluhin at gmail.com>
date: Tue Nov 19 17:22:53 2019 +0300
description:
Fixed Object.getPrototypeOf() according to the specification.
This closes #252 issue on Github.
diffstat:
src/njs_object.c | 10 ++++++++++
src/test/njs_unit_test.c | 8 +++-----
2 files changed, 13 insertions(+), 5 deletions(-)
diffs (45 lines):
diff -r e4383fdfdc82 -r d4fdf0fc449d src/njs_object.c
--- a/src/njs_object.c Tue Nov 19 19:17:09 2019 +0300
+++ b/src/njs_object.c Tue Nov 19 17:22:53 2019 +0300
@@ -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
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 -r e4383fdfdc82 -r d4fdf0fc449d src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Tue Nov 19 19:17:09 2019 +0300
+++ b/src/test/njs_unit_test.c Tue Nov 19 17:22:53 2019 +0300
@@ -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)"),
More information about the nginx-devel
mailing list