details:   https://hg.nginx.org/njs/rev/2037b3ccd677
branches:  
changeset: 833:2037b3ccd677
user:      Dmitry Volyntsev <[email protected]>
date:      Mon Mar 18 19:20:02 2019 +0300
description:
Setting [[Construct]] internal property for Function Objects.

According to ES5.1: 13.2 [[Construct]] is set by default.

diffstat:

 njs/njs_function.c |   1 +
 njs/njs_vm.c       |  16 ++++++++--------
 2 files changed, 9 insertions(+), 8 deletions(-)

diffs (44 lines):

diff -r 8868eed51544 -r 2037b3ccd677 njs/njs_function.c
--- a/njs/njs_function.c        Mon Mar 18 16:05:27 2019 +0300
+++ b/njs/njs_function.c        Mon Mar 18 19:20:02 2019 +0300
@@ -32,6 +32,7 @@ njs_function_alloc(njs_vm_t *vm)
         function->object.shared = 1;
         function->object.extensible = 1;
         function->args_offset = 1;
+        function->ctor = 1;
 
         function->u.lambda = nxt_mp_zalloc(vm->mem_pool,
                                            sizeof(njs_function_lambda_t));
diff -r 8868eed51544 -r 2037b3ccd677 njs/njs_vm.c
--- a/njs/njs_vm.c      Mon Mar 18 16:05:27 2019 +0300
+++ b/njs/njs_vm.c      Mon Mar 18 19:20:02 2019 +0300
@@ -394,6 +394,7 @@ njs_vmcode_function(njs_vm_t *vm, njs_va
     function->object.__proto__ = 
&vm->prototypes[NJS_PROTOTYPE_FUNCTION].object;
     function->object.extensible = 1;
     function->args_offset = 1;
+    function->ctor = 1;
 
     if (nesting != 0) {
         function->closure = 1;
@@ -1867,14 +1868,13 @@ njs_function_frame_create(njs_vm_t *vm, 
         function = value->data.u.function;
 
         if (ctor) {
-            if (function->native) {
-                if (!function->ctor) {
-                    njs_type_error(vm, "%s is not a constructor",
-                                   njs_type_string(value->type));
-                    return NXT_ERROR;
-                }
-
-            } else {
+            if (!function->ctor) {
+                njs_type_error(vm, "%s is not a constructor",
+                               njs_type_string(value->type));
+                return NXT_ERROR;
+            }
+
+            if (!function->native) {
                 object = njs_function_new_object(vm, value);
                 if (nxt_slow_path(object == NULL)) {
                     return NXT_ERROR;
_______________________________________________
nginx-devel mailing list
[email protected]
http://mailman.nginx.org/mailman/listinfo/nginx-devel

Reply via email to