Commit 03dcbc88 authored by Andy Wingo's avatar Andy Wingo Committed by V8 LUCI CQ

[stringrefs] Implement string.as_wtf16, stringview_wtf16.length

Bug: v8:12868
Change-Id: I19190dc8163de42964fb3911f82e8aeabaf48524
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3695585Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Andy Wingo <wingo@igalia.com>
Cr-Commit-Position: refs/heads/main@{#81046}
parent ccc8389f
......@@ -212,8 +212,12 @@ Reduction WasmTyper::Reduce(Node* node) {
m.Is(wasm::ObjectAccess::ToTagged(WasmArray::kLengthOffset))) {
return NoChange();
}
// Do not modify if we are retrieving anything from a string.
if (object_type.type.is_reference_to(wasm::HeapType::kString)) {
// Do not modify if we are retrieving anything from a string or a view on
// a string.
if (object_type.type.is_reference_to(wasm::HeapType::kString) ||
object_type.type.is_reference_to(wasm::HeapType::kStringViewWtf8) ||
object_type.type.is_reference_to(wasm::HeapType::kStringViewWtf16) ||
object_type.type.is_reference_to(wasm::HeapType::kStringViewIter)) {
return NoChange();
}
uint32_t ref_index = object_type.type.ref_index();
......
......@@ -6176,15 +6176,6 @@ class LiftoffCompiler {
UNIMPLEMENTED();
}
void StringAsWtf16(FullDecoder* decoder, const Value& str, Value* result) {
UNIMPLEMENTED();
}
void StringViewWtf16Length(FullDecoder* decoder, const Value& view,
Value* result) {
UNIMPLEMENTED();
}
void StringViewWtf16GetCodeUnit(FullDecoder* decoder, const Value& view,
const Value& pos, Value* result) {
UNIMPLEMENTED();
......
......@@ -1153,8 +1153,6 @@ struct ControlBase : public PcForErrors<validate> {
const Value& bytes, Value* next_pos, Value* bytes_written) \
F(StringViewWtf8Slice, const Value& view, const Value& start, \
const Value& end, Value* result) \
F(StringAsWtf16, const Value& str, Value* result) \
F(StringViewWtf16Length, const Value& view, Value* result) \
F(StringViewWtf16GetCodeUnit, const Value& view, const Value& pos, \
Value* result) \
F(StringViewWtf16Encode, const MemoryIndexImmediate<validate>& memory, \
......@@ -5300,7 +5298,7 @@ class WasmFullDecoder : public WasmDecoder<validate, decoding_mode> {
NON_CONST_ONLY
Value str = Peek(0, 0, kWasmStringRef);
Value result = CreateValue(kWasmStringViewWtf16);
CALL_INTERFACE_IF_OK_AND_REACHABLE(StringAsWtf16, str, &result);
CALL_INTERFACE_IF_OK_AND_REACHABLE(Forward, str, &result);
Drop(str);
Push(result);
return opcode_length;
......@@ -5309,8 +5307,7 @@ class WasmFullDecoder : public WasmDecoder<validate, decoding_mode> {
NON_CONST_ONLY
Value view = Peek(0, 0, kWasmStringViewWtf16);
Value result = CreateValue(kWasmI32);
CALL_INTERFACE_IF_OK_AND_REACHABLE(StringViewWtf16Length, view,
&result);
CALL_INTERFACE_IF_OK_AND_REACHABLE(StringMeasureWtf16, view, &result);
Drop(view);
Push(result);
return opcode_length;
......
......@@ -1475,15 +1475,6 @@ class WasmGraphBuildingInterface {
UNIMPLEMENTED();
}
void StringAsWtf16(FullDecoder* decoder, const Value& str, Value* result) {
UNIMPLEMENTED();
}
void StringViewWtf16Length(FullDecoder* decoder, const Value& view,
Value* result) {
UNIMPLEMENTED();
}
void StringViewWtf16GetCodeUnit(FullDecoder* decoder, const Value& view,
const Value& pos, Value* result) {
UNIMPLEMENTED();
......
......@@ -241,3 +241,30 @@ function makeWtf16TestDataSegment() {
assertThrows(() => instance.exports.string_measure_wtf16_null(),
WebAssembly.RuntimeError, "dereferencing a null pointer");
})();
(function TestStringViewWtf16() {
let builder = new WasmModuleBuilder();
builder.addFunction("string_measure_wtf16", kSig_i_w)
.exportFunc()
.addBody([
kExprLocalGet, 0,
kGCPrefix, kExprStringAsWtf16,
kGCPrefix, kExprStringViewWtf16Length
]);
builder.addFunction("string_measure_wtf16_null", kSig_i_v)
.exportFunc()
.addBody([
kExprRefNull, kStringViewWtf16Code,
kGCPrefix, kExprStringViewWtf16Length
]);
let instance = builder.instantiate();
for (let str of interestingStrings) {
assertEquals(str.length, instance.exports.string_measure_wtf16(str));
}
assertThrows(() => instance.exports.string_measure_wtf16_null(),
WebAssembly.RuntimeError, "dereferencing a null pointer");
})();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment