[njs] Constructor function prototypes should be real functions.
Igor Sysoev
igor at sysoev.ru
Tue Oct 11 17:15:42 UTC 2016
details: http://hg.nginx.org/njs/rev/beba11b9f2a1
branches:
changeset: 197:beba11b9f2a1
user: Igor Sysoev <igor at sysoev.ru>
date: Tue Oct 11 20:09:18 2016 +0300
description:
Constructor function prototypes should be real functions.
diffstat:
njs/njs_builtin.c | 16 +++++++++++++++-
njs/njs_vm.h | 2 +-
njs/test/njs_unit_test.c | 3 +++
3 files changed, 19 insertions(+), 2 deletions(-)
diffs (63 lines):
diff -r a3588250473b -r beba11b9f2a1 njs/njs_builtin.c
--- a/njs/njs_builtin.c Tue Oct 11 17:44:05 2016 +0300
+++ b/njs/njs_builtin.c Tue Oct 11 20:09:18 2016 +0300
@@ -34,6 +34,16 @@ typedef struct {
} njs_function_init_t;
+static njs_ret_t
+njs_prototype_function(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
+ njs_index_t unused)
+{
+ vm->retval = njs_value_void;
+
+ return NXT_OK;
+}
+
+
nxt_int_t
njs_builtin_objects_create(njs_vm_t *vm)
{
@@ -75,7 +85,11 @@ njs_builtin_objects_create(njs_vm_t *vm)
{ .object_value = { .value = njs_string(""),
.object = { .type = NJS_OBJECT_STRING } } },
- { .object = { .type = NJS_FUNCTION } },
+ { .function = { .native = 1,
+ .args_offset = 1,
+ .u.native = njs_prototype_function,
+ .object = { .type = NJS_FUNCTION } } },
+
{ .object = { .type = NJS_REGEXP } },
{ .date = { .time = NJS_NAN,
diff -r a3588250473b -r beba11b9f2a1 njs/njs_vm.h
--- a/njs/njs_vm.h Tue Oct 11 17:44:05 2016 +0300
+++ b/njs/njs_vm.h Tue Oct 11 20:09:18 2016 +0300
@@ -321,12 +321,12 @@ typedef union {
.type = NJS_FUNCTION, \
.truth = 1, \
.u.function = & (njs_function_t) { \
- .object.shared = 1, \
.native = 1, \
.continuation_size = _size, \
.args_types = { __VA_ARGS__ }, \
.args_offset = 1, \
.u.native = _function, \
+ .object = { .type = NJS_FUNCTION, .shared = 1 }, \
} \
} \
}
diff -r a3588250473b -r beba11b9f2a1 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c Tue Oct 11 17:44:05 2016 +0300
+++ b/njs/test/njs_unit_test.c Tue Oct 11 20:09:18 2016 +0300
@@ -4288,6 +4288,9 @@ static njs_unit_test_t njs_test[] =
{ nxt_string("({}).constructor === Object"),
nxt_string("true") },
+ { nxt_string("var a = Object.__proto__; a()"),
+ nxt_string("undefined") },
+
{ nxt_string("var a = Array(3); a"),
nxt_string(",,") },
More information about the nginx-devel
mailing list