| 1689 | } |
| 1690 | |
| 1691 | tsn_value tsn_call_constructor( |
| 1692 | tsn_vm* ctx, tsn_value_const ctor, tsn_value_const new_target, int argc, tsn_value_const* argv) { |
| 1693 | if (tsn_is_undefined(ctx, ctor)) { |
| 1694 | // no ctor provided, create from prototype |
| 1695 | return JS_CreateFromCtor_tsn(ctx, new_target, 1); |
| 1696 | } |
| 1697 | auto* closure = tsn_get_closure_from_func(ctor); |
| 1698 | if (closure != nullptr) { |
| 1699 | // Fast path for calls to TSN functions |
| 1700 | if (closure->is_class_constructor) { |
| 1701 | // class constructor returns the newly constructed object |
| 1702 | return call_closure_callable(ctx, ctor, new_target, argc, argv, closure); |
| 1703 | } else { |
| 1704 | // function as class |
| 1705 | // create an emtpry object from the prototype |
| 1706 | auto obj = JS_CreateFromCtor_tsn(ctx, new_target, 1); |
| 1707 | // then call the function and use the empty object as 'this' |
| 1708 | call_closure_callable(ctx, ctor, obj, argc, argv, closure); |
| 1709 | return obj; |
| 1710 | } |
| 1711 | } else { |
| 1712 | // Call interpreted code |
| 1713 | return JS_CallConstructorInternal_tsn(ctx, ctor, new_target, argc, argv, 0); |
| 1714 | } |
| 1715 | } |
| 1716 | |
| 1717 | tsn_value tsn_call_constructor_vargs(tsn_vm* ctx, |
| 1718 | tsn_value_const ctor, |
no test coverage detected