From: Dmitry Volyntsev Date: Mon, 18 Mar 2019 16:20:02 +0000 (+0300) Subject: Setting [[Construct]] internal property for Function Objects. X-Git-Url: http://git.kaiwu.me/postgresql/log/contrib/postgres_fdw/static/gitweb.js?a=commitdiff_plain;h=7e5994ccdced552ed5721aee168f626de038d4e6;p=njs.git Setting [[Construct]] internal property for Function Objects. According to ES5.1: 13.2 [[Construct]] is set by default. --- diff --git a/njs/njs_function.c b/njs/njs_function.c index afc8422f..f510a2a8 100644 --- a/njs/njs_function.c +++ b/njs/njs_function.c @@ -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 --git a/njs/njs_vm.c b/njs/njs_vm.c index c2a1515c..cc3d74e4 100644 --- a/njs/njs_vm.c +++ b/njs/njs_vm.c @@ -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;