for (i = NJS_CONSTRUCTOR_OBJECT; i < NJS_CONSTRUCTOR_MAX; i++) {
constructors[i].object.shared = 0;
constructors[i].native = 1;
+ constructors[i].ctor = 1;
constructors[i].args_offset = 1;
constructors[i].u.native = native_constructors[i].native;
constructors[i].args_types[0] = native_constructors[i].args_types[0];
njs_vmcode_function_frame(njs_vm_t *vm, njs_value_t *value, njs_value_t *nargs)
{
njs_ret_t ret;
+ nxt_bool_t ctor;
njs_value_t val, *this;
njs_object_t *object;
njs_function_t *function;
if (nxt_fast_path(njs_is_function(value))) {
func = (njs_vmcode_function_frame_t *) vm->current;
+ ctor = func->code.ctor;
function = value->data.u.function;
if (function->native) {
+ if (ctor && !function->ctor) {
+ goto fail;
+ }
+
ret = njs_function_native_frame(vm, function, &njs_value_void,
- NULL, (uintptr_t) nargs, 0,
- func->code.ctor);
+ NULL, (uintptr_t) nargs, 0, ctor);
if (nxt_fast_path(ret == NXT_OK)) {
return sizeof(njs_vmcode_function_frame_t);
return ret;
}
- if (func->code.ctor) {
+ if (ctor) {
object = njs_function_new_object(vm, value);
if (nxt_slow_path(object == NULL)) {
return NXT_ERROR;
}
ret = njs_function_frame(vm, function, this, NULL, (uintptr_t) nargs,
- func->code.ctor);
+ ctor);
if (nxt_fast_path(ret == NXT_OK)) {
return sizeof(njs_vmcode_function_frame_t);
return ret;
}
+fail:
+
vm->exception = &njs_exception_type_error;
return NXT_ERROR;
return ret;
}
+ if (method->code.ctor) {
+ vm->exception = &njs_exception_type_error;
+ return NXT_ERROR;
+ }
+
ret = njs_function_native_frame(vm, function, object, NULL, method->nargs,
- 0, method->code.ctor);
+ 0, 0);
if (nxt_fast_path(ret == NXT_OK)) {
njs_retain(object);
uint8_t args_types[NJS_ARGS_TYPES_MAX];
uint8_t args_offset;
-
- /*
- * TODO Shared
- * When function object is used as value: in assignments,
- * as function argument, as property and as object to get properties.
- */
-
-#if (NXT_64BIT)
- uint8_t native;
- uint8_t continuation_size;
-#else
- uint8_t native;
uint8_t continuation_size;
-#endif
+
+ uint8_t native:1;
+ uint8_t ctor:1;
union {
njs_function_lambda_t *lambda;
{ nxt_string("var F = function (){}; typeof F.prototype"),
nxt_string("object") },
+ { nxt_string("new decodeURI('%00')"),
+ nxt_string("TypeError")},
+
+ { nxt_string("new ''.toString"),
+ nxt_string("TypeError")},
+
{ nxt_string("function F() { return Number }"
"var o = new (F())(5);"
"typeof o +' '+ o"),