MCPcopy Create free account
hub / github.com/Snapchat/Valdi / tsn_call_constructor

Function tsn_call_constructor

tsn/src/tsn/tsn.cpp:1691–1715  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1689}
1690
1691tsn_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
1717tsn_value tsn_call_constructor_vargs(tsn_vm* ctx,
1718 tsn_value_const ctor,

Callers 1

Calls 2

tsn_is_undefinedFunction · 0.85
call_closure_callableFunction · 0.85

Tested by

no test coverage detected