[wasm] Fix imports with numbers as name
Object::GetProperty fails if the given name is a valid array index. This CL switches to Object::GetPropertyOrElement for lookups of imports. The new tests check that we now accept numbers as module name or function name in FFI. R=ahaas@chromium.org, titzer@chromium.org Review-Url: https://codereview.chromium.org/2503313002 Cr-Commit-Position: refs/heads/master@{#41022}
This commit is contained in:
parent
36e3af325a
commit
c2db3b3898
@ -1289,7 +1289,8 @@ class WasmInstanceBuilder {
|
||||
}
|
||||
|
||||
// Look up the module first.
|
||||
MaybeHandle<Object> result = Object::GetProperty(ffi_, module_name);
|
||||
MaybeHandle<Object> result =
|
||||
Object::GetPropertyOrElement(ffi_, module_name);
|
||||
if (result.is_null()) {
|
||||
return ReportFFIError("module not found", index, module_name,
|
||||
import_name);
|
||||
@ -1304,7 +1305,8 @@ class WasmInstanceBuilder {
|
||||
module_name, import_name);
|
||||
}
|
||||
|
||||
result = Object::GetProperty(module, import_name.ToHandleChecked());
|
||||
result =
|
||||
Object::GetPropertyOrElement(module, import_name.ToHandleChecked());
|
||||
if (result.is_null()) {
|
||||
return ReportFFIError("import not found", index, module_name,
|
||||
import_name);
|
||||
|
@ -295,7 +295,7 @@ testCallBinopVoid(kAstF64);
|
||||
|
||||
|
||||
|
||||
function testCallPrint() {
|
||||
(function testCallPrint() {
|
||||
var builder = new WasmModuleBuilder();
|
||||
|
||||
builder.addImport("print", makeSig_v_x(kAstI32));
|
||||
@ -311,7 +311,30 @@ function testCallPrint() {
|
||||
|
||||
var main = builder.instantiate({print: print}).exports.main;
|
||||
for (var i = -9; i < 900; i += 6.125) main(i);
|
||||
}
|
||||
})();
|
||||
|
||||
testCallPrint();
|
||||
testCallPrint();
|
||||
|
||||
(function testImportNumbers() {
|
||||
var builder = new WasmModuleBuilder();
|
||||
|
||||
builder.addImport('0', kSig_v_i);
|
||||
|
||||
builder.instantiate({0: print});
|
||||
})();
|
||||
|
||||
(function testImportNumbers2() {
|
||||
var builder = new WasmModuleBuilder();
|
||||
|
||||
builder.addImportWithModule('foo', '0', kSig_v_i);
|
||||
builder.addImportWithModule('0', 'foo', kSig_v_i);
|
||||
builder.addImportWithModule('0', '0', kSig_v_i);
|
||||
builder.addImportWithModule('18', '-3', kSig_v_i);
|
||||
builder.addImportWithModule('-3', '18', kSig_v_i);
|
||||
|
||||
builder.instantiate({
|
||||
foo: {0: print},
|
||||
0: {0: print, foo: print},
|
||||
18: {'-3': print},
|
||||
'-3': {18: print}
|
||||
});
|
||||
})();
|
||||
|
Loading…
Reference in New Issue
Block a user