| 148 | } |
| 149 | |
| 150 | __attribute__((export_name("call"))) uint32_t call(uint32_t fn_idx, |
| 151 | void *argptr) { |
| 152 | if (Runtime.first_call) { |
| 153 | content_debugger::maybe_init_debugger(Runtime.engine, true); |
| 154 | js::ResetMathRandomSeed(Runtime.cx); |
| 155 | Runtime.first_call = false; |
| 156 | if (Runtime.clocks) { |
| 157 | builtins::web::performance::Performance::timeOrigin.emplace( |
| 158 | std::chrono::high_resolution_clock::now()); |
| 159 | } |
| 160 | } |
| 161 | if (Runtime.cur_fn_idx != -1) { |
| 162 | Runtime.engine->abort("(call) unexpected call state, post_call was not called after last call"); |
| 163 | } |
| 164 | Runtime.cur_fn_idx = fn_idx; |
| 165 | ComponentizeRuntime::CoreFn *fn = &Runtime.fns[fn_idx]; |
| 166 | if (Runtime.debug) { |
| 167 | fprintf(stderr, "(call) Function [%d] - ", fn_idx); |
| 168 | fprintf(stderr, "("); |
| 169 | if (fn->paramptr) { |
| 170 | fprintf(stderr, "*"); |
| 171 | } |
| 172 | bool first = true; |
| 173 | for (int i = 0; i < fn->args.size(); i++) { |
| 174 | if (first) { |
| 175 | first = false; |
| 176 | } else { |
| 177 | fprintf(stderr, ", "); |
| 178 | } |
| 179 | fprintf(stderr, "%s", core_ty_str(fn->args[i])); |
| 180 | } |
| 181 | fprintf(stderr, ")"); |
| 182 | if (fn->ret.has_value()) { |
| 183 | fprintf(stderr, " -> "); |
| 184 | if (fn->retptr) { |
| 185 | fprintf(stderr, "*"); |
| 186 | } |
| 187 | fprintf(stderr, "%s", core_ty_str(fn->ret.value())); |
| 188 | } |
| 189 | fprintf(stderr, "\n"); |
| 190 | } |
| 191 | |
| 192 | JSAutoRealm ar(Runtime.cx, Runtime.engine->global()); |
| 193 | |
| 194 | JS::RootedVector<JS::Value> args(Runtime.cx); |
| 195 | if (!args.resize(fn->args.size() + (fn->retptr ? 1 : 0))) { |
| 196 | Runtime.engine->abort("(call) unable to allocate memory for array resize"); |
| 197 | } |
| 198 | |
| 199 | LOG("(call) setting args"); |
| 200 | int argcnt = 0; |
| 201 | if (fn->paramptr) { |
| 202 | args[0].setInt32((uint32_t)argptr); |
| 203 | argcnt = 1; |
| 204 | } else if (fn->args.size() > 0) { |
| 205 | uint32_t *curptr = static_cast<uint32_t *>(argptr); |
| 206 | argcnt = fn->args.size(); |
| 207 | for (int i = 0; i < argcnt; i++) { |
no test coverage detected