node/deps/v8/test/mjsunit/wasm/stringview-valuestack.js
Michaël Zasso 9d7cd9b864
deps: update V8 to 12.8.374.13
PR-URL: https://github.com/nodejs/node/pull/54077
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
2024-08-16 16:03:01 +02:00

79 lines
2.3 KiB
JavaScript

// Copyright 2023 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-stringref
d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
let kSig_v_w = makeSig([kWasmStringRef], []);
let kSig_iw_i = makeSig([kWasmI32], [kWasmI32, kWasmStringRef]);
(function TestStringViewIterStack() {
let builder = new WasmModuleBuilder();
let wrapper = builder.addStruct([makeField(kWasmStringViewIter, true)]);
let global = builder.addGlobal(wasmRefNullType(wrapper), true, false);
builder.addFunction("iterate", kSig_v_w)
.exportFunc()
.addBody([
kExprLocalGet, 0,
...GCInstr(kExprStringAsIter),
kGCPrefix, kExprStructNew, wrapper,
kExprGlobalSet, global.index
]);
// The following functions perform a stringview operation and have the
// value 42 on the stack to ensure that the value stack is preserved on each
// of these operations.
builder.addFunction("advance", kSig_ii_i)
.exportFunc()
.addBody([
kExprI32Const, 42,
kExprGlobalGet, global.index,
kGCPrefix, kExprStructGet, wrapper, 0,
kExprLocalGet, 0,
...GCInstr(kExprStringViewIterAdvance)
]);
builder.addFunction("rewind", kSig_ii_i)
.exportFunc()
.addBody([
kExprI32Const, 42,
kExprGlobalGet, global.index,
kGCPrefix, kExprStructGet, wrapper, 0,
kExprLocalGet, 0,
...GCInstr(kExprStringViewIterRewind)
]);
builder.addFunction("slice", kSig_iw_i)
.exportFunc()
.addBody([
kExprI32Const, 42,
kExprGlobalGet, global.index,
kGCPrefix, kExprStructGet, wrapper, 0,
kExprLocalGet, 0,
...GCInstr(kExprStringViewIterSlice)
]);
let instance = builder.instantiate();
let str = 'ascii string';
instance.exports.iterate(str);
for (let i = 0; i < str.length; i++) {
assertEquals([42, 1], instance.exports.advance(1));
}
assertEquals([42, 0], instance.exports.advance(1));
for (let i = 0; i < str.length; i++) {
assertEquals([42, 1], instance.exports.rewind(1));
}
assertEquals([42, 0], instance.exports.rewind(1));
for (let i = 0; i < str.length; i++) {
assertEquals([42, str.substring(0, i)], instance.exports.slice(i));
}
})();