changeset 197:beba11b9f2a1

Constructor function prototypes should be real functions.
author Igor Sysoev <igor@sysoev.ru>
date Tue, 11 Oct 2016 20:09:18 +0300
parents a3588250473b
children 8046b999aaaf
files njs/njs_builtin.c njs/njs_vm.h njs/test/njs_unit_test.c
diffstat 3 files changed, 19 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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 @@
 } 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 @@
         { .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,
--- 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 @@
         .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 },                  \
         }                                                                     \
     }                                                                         \
 }
--- 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 @@
     { 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(",,") },