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) { ...@@ -212,8 +212,12 @@ Reduction WasmTyper::Reduce(Node* node) {
m.Is(wasm::ObjectAccess::ToTagged(WasmArray::kLengthOffset))) { m.Is(wasm::ObjectAccess::ToTagged(WasmArray::kLengthOffset))) {
return NoChange(); return NoChange();
} }
// Do not modify if we are retrieving anything from a string. // Do not modify if we are retrieving anything from a string or a view on
if (object_type.type.is_reference_to(wasm::HeapType::kString)) { // 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(); return NoChange();
} }
uint32_t ref_index = object_type.type.ref_index(); uint32_t ref_index = object_type.type.ref_index();
......
...@@ -6176,15 +6176,6 @@ class LiftoffCompiler { ...@@ -6176,15 +6176,6 @@ class LiftoffCompiler {
UNIMPLEMENTED(); 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, void StringViewWtf16GetCodeUnit(FullDecoder* decoder, const Value& view,
const Value& pos, Value* result) { const Value& pos, Value* result) {
UNIMPLEMENTED(); UNIMPLEMENTED();
......
...@@ -1153,8 +1153,6 @@ struct ControlBase : public PcForErrors<validate> { ...@@ -1153,8 +1153,6 @@ struct ControlBase : public PcForErrors<validate> {
const Value& bytes, Value* next_pos, Value* bytes_written) \ const Value& bytes, Value* next_pos, Value* bytes_written) \
F(StringViewWtf8Slice, const Value& view, const Value& start, \ F(StringViewWtf8Slice, const Value& view, const Value& start, \
const Value& end, Value* result) \ 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, \ F(StringViewWtf16GetCodeUnit, const Value& view, const Value& pos, \
Value* result) \ Value* result) \
F(StringViewWtf16Encode, const MemoryIndexImmediate<validate>& memory, \ F(StringViewWtf16Encode, const MemoryIndexImmediate<validate>& memory, \
...@@ -5300,7 +5298,7 @@ class WasmFullDecoder : public WasmDecoder<validate, decoding_mode> { ...@@ -5300,7 +5298,7 @@ class WasmFullDecoder : public WasmDecoder<validate, decoding_mode> {
NON_CONST_ONLY NON_CONST_ONLY
Value str = Peek(0, 0, kWasmStringRef); Value str = Peek(0, 0, kWasmStringRef);
Value result = CreateValue(kWasmStringViewWtf16); Value result = CreateValue(kWasmStringViewWtf16);
CALL_INTERFACE_IF_OK_AND_REACHABLE(StringAsWtf16, str, &result); CALL_INTERFACE_IF_OK_AND_REACHABLE(Forward, str, &result);
Drop(str); Drop(str);
Push(result); Push(result);
return opcode_length; return opcode_length;
...@@ -5309,8 +5307,7 @@ class WasmFullDecoder : public WasmDecoder<validate, decoding_mode> { ...@@ -5309,8 +5307,7 @@ class WasmFullDecoder : public WasmDecoder<validate, decoding_mode> {
NON_CONST_ONLY NON_CONST_ONLY
Value view = Peek(0, 0, kWasmStringViewWtf16); Value view = Peek(0, 0, kWasmStringViewWtf16);
Value result = CreateValue(kWasmI32); Value result = CreateValue(kWasmI32);
CALL_INTERFACE_IF_OK_AND_REACHABLE(StringViewWtf16Length, view, CALL_INTERFACE_IF_OK_AND_REACHABLE(StringMeasureWtf16, view, &result);
&result);
Drop(view); Drop(view);
Push(result); Push(result);
return opcode_length; return opcode_length;
......
...@@ -1475,15 +1475,6 @@ class WasmGraphBuildingInterface { ...@@ -1475,15 +1475,6 @@ class WasmGraphBuildingInterface {
UNIMPLEMENTED(); 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, void StringViewWtf16GetCodeUnit(FullDecoder* decoder, const Value& view,
const Value& pos, Value* result) { const Value& pos, Value* result) {
UNIMPLEMENTED(); UNIMPLEMENTED();
......
...@@ -241,3 +241,30 @@ function makeWtf16TestDataSegment() { ...@@ -241,3 +241,30 @@ function makeWtf16TestDataSegment() {
assertThrows(() => instance.exports.string_measure_wtf16_null(), assertThrows(() => instance.exports.string_measure_wtf16_null(),
WebAssembly.RuntimeError, "dereferencing a null pointer"); 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