v8/test/mjsunit/wasm/gc-experimental-string-conversions.js
Matthias Liedtke d4a3ebeb2b Reland "Reland "[wasm-gc] Ref types: Convert dataref to structref""
This is a reland of commit 3b883e787d

Fixed a test case that was merged in the meantime still using the old
kExprRefAsData which is now called kExprRefAsStruct.

Original change's description:
> Reland "[wasm-gc] Ref types: Convert dataref to structref"
>
> This is a reland of commit 20327d1599
>
> Changed in reland:
> - Added new flag wasm-gc-structref-as-dataref which defaults to true
>   and preserves the existing behavior.
> - Passing --no-wasm-gc-structref-as-dataref enables the new behavior.
> - The flag affects static subtyping information between structref and
>   arrays and the corresponding cast, test and br_on instructions.
> - Even with the old behavior the name still changed to "structref".
>
> Original change's description:
> > [wasm-gc] Ref types: Convert dataref to structref
> >
> > This change changes the type hierarchy in a non-backwards compatible
> > way: dataref is replaced with structref meaning that arrayref is
> > no longer a subtype of it.
> >
> > Bug: v8:7748
> > Change-Id: I965267d9ed11ea7c7d7df133cc39ee63e6b5abc3
> > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3929041
> > Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
> > Commit-Queue: Matthias Liedtke <mliedtke@chromium.org>
> > Cr-Commit-Position: refs/heads/main@{#83515}
>
> Bug: v8:7748
> Change-Id: I2d8dd49dbc56246c087ac93452a87f860ead2195
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3945109
> Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
> Commit-Queue: Matthias Liedtke <mliedtke@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#83697}

Bug: v8:7748
Change-Id: I54f7b141ffc5b7597420fa0c838412be825a260b
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3952936
Auto-Submit: Matthias Liedtke <mliedtke@chromium.org>
Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Matthias Liedtke <mliedtke@chromium.org>
Commit-Queue: Jakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/main@{#83706}
2022-10-14 09:32:25 +00:00

69 lines
2.2 KiB
JavaScript

// Copyright 2022 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: --experimental-wasm-gc --allow-natives-syntax
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
var builder = new WasmModuleBuilder();
let i16Array = builder.addArray(kWasmI16, true);
builder.addFunction('getHelloArray', makeSig([], [kWasmArrayRef]))
.addBody([
...wasmI32Const(72), ...wasmI32Const(69), ...wasmI32Const(76),
...wasmI32Const(76), ...wasmI32Const(79),
kGCPrefix, kExprArrayNewFixed, i16Array, 5
])
.exportFunc();
builder.addFunction('getChar', makeSig([kWasmArrayRef, kWasmI32], [kWasmI32]))
.addBody([
kExprLocalGet, 0, kGCPrefix, kExprRefAsArray, kGCPrefix,
kExprRefCast, i16Array, kExprLocalGet, 1, kGCPrefix, kExprArrayGetS,
i16Array
])
.exportFunc();
const instance = builder.instantiate();
const getHelloArray = instance.exports.getHelloArray;
const getChar = instance.exports.getChar;
assertEquals(
WebAssembly.experimentalConvertArrayToString(getHelloArray(), 0, 5),
'HELLO');
assertEquals(
WebAssembly.experimentalConvertArrayToString(getHelloArray(), 1, 4),
'ELLO');
assertEquals(
WebAssembly.experimentalConvertArrayToString(getHelloArray(), 0, 3), 'HEL');
const string = 'foobar'
const array =
WebAssembly.experimentalConvertStringToArray('foobar', getHelloArray());
for (let i = 0; i < string.length; ++i) {
assertEquals(getChar(array, i), string.charCodeAt(i));
}
// Test calling built-ins with different amount of (invalid) arguments.
function arrayToString() {
WebAssembly.experimentalConvertArrayToString(...arguments);
}
function stringToArray() {
WebAssembly.experimentalConvertStringToArray(...arguments);
}
let args = [];
for (let i = 1; i <= 5; ++i) {
assertThrows(() => arrayToString(...args));
assertThrows(() => stringToArray(...args));
%PrepareFunctionForOptimization(arrayToString);
%PrepareFunctionForOptimization(stringToArray);
%OptimizeFunctionOnNextCall(arrayToString);
%OptimizeFunctionOnNextCall(stringToArray);
assertThrows(() => arrayToString(...args));
assertThrows(() => stringToArray(...args));
args.push(i);
}