| 139 | |
| 140 | template <bool isConst, typename Cls> |
| 141 | struct MethodVariadicRuntime |
| 142 | { |
| 143 | typedef MethodInfo<isConst, Cls, duk_ret_t, duk_context*> MethodInfoVariadic; |
| 144 | typedef typename MethodInfoVariadic::MethodHolder MethodHolderVariadic; |
| 145 | |
| 146 | static duk_ret_t finalize_method(duk_context* ctx) |
| 147 | { |
| 148 | return MethodInfoVariadic::MethodRuntime::finalize_method(ctx); |
| 149 | } |
| 150 | |
| 151 | static duk_ret_t call_native_method(duk_context* ctx) |
| 152 | { |
| 153 | // get this.obj_ptr |
| 154 | duk_push_this(ctx); |
| 155 | duk_get_prop_string(ctx, -1, "\xFF" "obj_ptr"); |
| 156 | void* obj_void = duk_get_pointer(ctx, -1); |
| 157 | if (obj_void == nullptr) { |
| 158 | duk_error(ctx, DUK_RET_REFERENCE_ERROR, "Invalid native object for 'this'"); |
| 159 | return DUK_RET_REFERENCE_ERROR; |
| 160 | } |
| 161 | |
| 162 | duk_pop_2(ctx); // pop this.obj_ptr and this |
| 163 | |
| 164 | // get current_function.method_info |
| 165 | duk_push_current_function(ctx); |
| 166 | duk_get_prop_string(ctx, -1, "\xFF" "method_holder"); |
| 167 | void* method_holder_void = duk_require_pointer(ctx, -1); |
| 168 | if (method_holder_void == nullptr) { |
| 169 | duk_error(ctx, DUK_RET_TYPE_ERROR, "Method pointer missing?!"); |
| 170 | return DUK_RET_TYPE_ERROR; |
| 171 | } |
| 172 | |
| 173 | duk_pop_2(ctx); |
| 174 | |
| 175 | // (should always be valid unless someone is intentionally messing with this.obj_ptr...) |
| 176 | Cls* obj = static_cast<Cls*>(obj_void); |
| 177 | MethodHolderVariadic* method_holder = static_cast<MethodHolderVariadic*>(method_holder_void); |
| 178 | |
| 179 | return (*obj.*method_holder->method)(ctx); |
| 180 | } |
| 181 | }; |
| 182 | } |
| 183 | } |
nothing calls this directly
no outgoing calls
no test coverage detected