[wasm][interpreter] Support calls to imported JS functions in cctests
The interpreter is set up specially in cctests to allow more direct testing. This requires sometimes to write special testing code in the interpreter which is different than production code. This CL fixes one instance of testing code which deals with indirect calls. In production code, indirect calls go through the indirect function table which can change over time. In cctests, however, the indirect function table is not set up completely. In cctests the interpreter uses information from the module instead to acquire the target of an indirect call. In that testing code, calls to imported JS functions were not handled. This handling gets added with this CL. CC=fgm@chromium.org R=titzer@chromium.org Bug: v8:7431 Change-Id: I3b90d4ea8fec2633c010dd8359814440c7988509 Reviewed-on: https://chromium-review.googlesource.com/c/1495560 Reviewed-by: Ben Titzer <titzer@chromium.org> Commit-Queue: Andreas Haas <ahaas@chromium.org> Cr-Commit-Position: refs/heads/master@{#59965}
This commit is contained in:
parent
06770cef6c
commit
dd23f2f316
@ -3264,6 +3264,9 @@ class ThreadImpl {
|
||||
return {ExternalCallResult::SIGNATURE_MISMATCH};
|
||||
}
|
||||
}
|
||||
if (code->function->imported) {
|
||||
return CallImportedFunction(code->function->func_index);
|
||||
}
|
||||
return {ExternalCallResult::INTERNAL, code};
|
||||
}
|
||||
|
||||
|
@ -121,6 +121,43 @@ WASM_EXEC_TEST(Run_CallJS_Add_jswrapped) {
|
||||
r.CheckCallViaJS(-666666801, -666666900);
|
||||
}
|
||||
|
||||
WASM_EXEC_TEST(Run_IndirectCallJSFunction) {
|
||||
Isolate* isolate = CcTest::InitIsolateOnce();
|
||||
HandleScope scope(isolate);
|
||||
TestSignatures sigs;
|
||||
|
||||
const char* source = "(function(a, b, c) { if(c) return a; return b; })";
|
||||
Handle<JSFunction> js_function =
|
||||
Handle<JSFunction>::cast(v8::Utils::OpenHandle(
|
||||
*v8::Local<v8::Function>::Cast(CompileRun(source))));
|
||||
|
||||
ManuallyImportedJSFunction import = {sigs.i_iii(), js_function};
|
||||
|
||||
WasmRunner<int32_t, int32_t> r(execution_tier, &import);
|
||||
|
||||
const uint32_t js_index = 0;
|
||||
const int32_t left = -2;
|
||||
const int32_t right = 3;
|
||||
|
||||
WasmFunctionCompiler& rc_fn = r.NewFunction(sigs.i_i(), "rc");
|
||||
|
||||
r.builder().AddSignature(sigs.i_iii());
|
||||
uint16_t indirect_function_table[] = {static_cast<uint16_t>(js_index)};
|
||||
|
||||
r.builder().AddIndirectFunctionTable(indirect_function_table,
|
||||
arraysize(indirect_function_table));
|
||||
r.builder().PopulateIndirectFunctionTable();
|
||||
|
||||
BUILD(rc_fn, WASM_CALL_INDIRECT3(0, WASM_I32V(js_index), WASM_I32V(left),
|
||||
WASM_I32V(right), WASM_GET_LOCAL(0)));
|
||||
|
||||
Handle<Object> args_left[] = {isolate->factory()->NewNumber(1)};
|
||||
r.CheckCallViaJS(left, rc_fn.function_index(), args_left, 1);
|
||||
|
||||
Handle<Object> args_right[] = {isolate->factory()->NewNumber(0)};
|
||||
r.CheckCallViaJS(right, rc_fn.function_index(), args_right, 1);
|
||||
}
|
||||
|
||||
void RunJSSelectTest(ExecutionTier tier, int which) {
|
||||
const int kMaxParams = 8;
|
||||
PredictableInputValues inputs(0x100);
|
||||
|
Loading…
Reference in New Issue
Block a user