]> git.kaiwu.me - njs.git/commitdiff
Setting [[Construct]] internal property for Function Objects.
authorDmitry Volyntsev <xeioex@nginx.com>
Mon, 18 Mar 2019 16:20:02 +0000 (19:20 +0300)
committerDmitry Volyntsev <xeioex@nginx.com>
Mon, 18 Mar 2019 16:20:02 +0000 (19:20 +0300)
According to ES5.1: 13.2 [[Construct]] is set by default.

njs/njs_function.c
njs/njs_vm.c

index afc8422fb0dfb50c762885f2fe5c0c7d1e802f32..f510a2a8952f99ddc8c3bf23bcadb894cff3c93f 100644 (file)
@@ -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));
index c2a1515c545d7fc5abb248a47c78bc670a00b6f5..cc3d74e49eb5e42307608150475dd41123fd4feb 100644 (file)
@@ -394,6 +394,7 @@ njs_vmcode_function(njs_vm_t *vm, njs_value_t *invld1, njs_value_t *invld2)
     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, njs_value_t *value,
         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;
-                }
+            if (!function->ctor) {
+                njs_type_error(vm, "%s is not a constructor",
+                               njs_type_string(value->type));
+                return NXT_ERROR;
+            }
 
-            } else {
+            if (!function->native) {
                 object = njs_function_new_object(vm, value);
                 if (nxt_slow_path(object == NULL)) {
                     return NXT_ERROR;