2021-05-26 12:53:40 +00:00
|
|
|
// Copyright 2021 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
// Flags: --allow-natives-syntax --experimental-wasm-gc --wasm-gc-js-interop
|
|
|
|
// Flags: --expose-gc
|
|
|
|
|
2021-06-01 12:46:36 +00:00
|
|
|
d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
|
2021-05-26 12:53:40 +00:00
|
|
|
|
2021-05-26 17:01:19 +00:00
|
|
|
const kIterationsCountForICProgression = 20;
|
|
|
|
|
2021-05-26 12:53:40 +00:00
|
|
|
// TODO(ishell): remove once leaked maps could keep NativeModule alive.
|
|
|
|
let instances = [];
|
|
|
|
|
|
|
|
function createArray_i() {
|
|
|
|
let builder = new WasmModuleBuilder();
|
|
|
|
|
|
|
|
const type_index = builder.addArray(kWasmI32);
|
|
|
|
|
|
|
|
let sig_a_i = makeSig_r_x(kWasmDataRef, kWasmI32);
|
|
|
|
let sig_i_ai = makeSig([kWasmDataRef, kWasmI32], [kWasmI32]);
|
|
|
|
let sig_v_aii = makeSig([kWasmDataRef, kWasmI32, kWasmI32], []);
|
|
|
|
|
|
|
|
builder.addFunction("new_array", sig_a_i)
|
|
|
|
.addBody([
|
|
|
|
kExprLocalGet, 0, // --
|
|
|
|
kExprI32Const, 10, // --
|
|
|
|
kGCPrefix, kExprRttCanon, type_index, // --
|
|
|
|
kGCPrefix, kExprArrayNewWithRtt, type_index]) // --
|
|
|
|
.exportAs("new_array");
|
|
|
|
|
|
|
|
builder.addFunction("array_get", sig_i_ai)
|
|
|
|
.addBody([
|
|
|
|
kExprLocalGet, 0, // --
|
|
|
|
kGCPrefix, kExprRttCanon, type_index, // --
|
|
|
|
kGCPrefix, kExprRefCast, // --
|
|
|
|
kExprLocalGet, 1, // --
|
|
|
|
kGCPrefix, kExprArrayGet, type_index]) // --
|
|
|
|
.exportAs("array_get");
|
|
|
|
|
|
|
|
builder.addFunction("array_set", sig_v_aii)
|
|
|
|
.addBody([
|
|
|
|
kExprLocalGet, 0, // --
|
|
|
|
kGCPrefix, kExprRttCanon, type_index, // --
|
|
|
|
kGCPrefix, kExprRefCast, // --
|
|
|
|
kExprLocalGet, 1, // --
|
|
|
|
kExprLocalGet, 2, // --
|
|
|
|
kGCPrefix, kExprArraySet, type_index]) // --
|
|
|
|
.exportAs("array_set");
|
|
|
|
|
|
|
|
let instance = builder.instantiate();
|
|
|
|
instances.push(instance);
|
|
|
|
let new_array = instance.exports.new_array;
|
|
|
|
let array_get = instance.exports.array_get;
|
|
|
|
let array_set = instance.exports.array_set;
|
|
|
|
|
|
|
|
let value = 42;
|
|
|
|
let o = new_array(value);
|
|
|
|
%DebugPrint(o);
|
|
|
|
assertEquals(10, o.length);
|
|
|
|
for (let i = 0; i < o.length; i++) {
|
|
|
|
let res;
|
|
|
|
res = array_get(o, i);
|
|
|
|
assertEquals(value, res);
|
|
|
|
|
|
|
|
array_set(o, i, i);
|
|
|
|
res = array_get(o, i);
|
|
|
|
assertEquals(i, res);
|
|
|
|
}
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
|
|
|
(function TestSimpleArrayInterop() {
|
|
|
|
function f(o) {
|
2021-06-11 21:03:30 +00:00
|
|
|
assertEquals(10, o.length);
|
|
|
|
for (let i = 0; i < o.length; i++) {
|
2021-05-26 12:53:40 +00:00
|
|
|
let len = o.length;
|
2021-05-26 17:01:19 +00:00
|
|
|
assertEquals(10, len);
|
2021-06-11 21:03:30 +00:00
|
|
|
let v = o[i];
|
|
|
|
assertEquals(i, v);
|
2021-05-26 12:53:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let o = createArray_i();
|
|
|
|
%DebugPrint(o);
|
|
|
|
|
|
|
|
f(o);
|
|
|
|
gc();
|
|
|
|
})();
|