v8/test/mjsunit/regress/regress-crbug-1350270.js
Joyee Cheung 90a39679fd [string] handle strings sliced from externalized one-byte strings
...in Runtime_StringToArray.

When a string is sliced from an externalized two-byte string that has
only one-byte chars, String::IsFlat() and
should not call ToOneByteVector() on it and instead we should use

String: :IsOneByteRepresentation() can both be true, while
FlatContent: :IsOneByte() returns false. In this case we
String: :Get() to get the individual characters.
Bug: chromium:1350270
Change-Id: I735408602072279f09b32e1997c97b2900942bdd
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3813070
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Commit-Queue: Joyee Cheung <joyee@igalia.com>
Cr-Commit-Position: refs/heads/main@{#82268}
2022-08-08 14:28:18 +00:00

20 lines
703 B
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: --expose-externalize-string
let str1 = "external string turned into two byte";
let str2 = str1.substring(1);
try {
// Turn the string to a two-byte external string, so that the sliced
// string looks like one-byte, but its parent is actually two-byte.
externalizeString(str1, true);
} catch (e) { }
assertEquals(
["x", "t", "e", "r", "n", "a", "l", " ",
"s", "t", "r", "i", "n", "g", " ",
"t", "u", "r", "n", "e", "d", " ",
"i", "n", "t", "o", " ",
"t", "w", "o", " ",
"b", "y", "t", "e"], str2.split(""));