From: Igor Sysoev Date: Tue, 11 Oct 2016 17:09:18 +0000 (+0300) Subject: Constructor function prototypes should be real functions. X-Git-Tag: 0.1.4~17 X-Git-Url: http://git.kaiwu.me/postgresql/log/contrib/postgres_fdw/static/gitweb.js?a=commitdiff_plain;h=ee84984006f504c79b0ffd18b864d9e0dbffe90c;p=njs.git Constructor function prototypes should be real functions. --- diff --git a/njs/njs_builtin.c b/njs/njs_builtin.c index a5f4ae7e..5eef6fa3 100644 --- a/njs/njs_builtin.c +++ b/njs/njs_builtin.c @@ -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 --git a/njs/njs_vm.h b/njs/njs_vm.h index adb9da84..b393bb0c 100644 --- a/njs/njs_vm.h +++ b/njs/njs_vm.h @@ -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 --git a/njs/test/njs_unit_test.c b/njs/test/njs_unit_test.c index 5da2cffa..5ee74d0b 100644 --- a/njs/test/njs_unit_test.c +++ b/njs/test/njs_unit_test.c @@ -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(",,") },