summaryrefslogtreecommitdiff
path: root/deps/v8/test/mjsunit/harmony/string-iswellformed-external-uncached.js
blob: 193294e394355cc06f60e8cacc0b4a607ffe8cb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// 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 --harmony-string-is-well-formed

(function TestIsWellFormed() {
  const short2ByteWellFormed = '\u1234';
  const short2ByteIllFormed = '\uD83D';

  assertTrue(short2ByteWellFormed.isWellFormed());
  assertFalse(short2ByteIllFormed.isWellFormed());

  try {
    // Turn the strings into uncached external strings to hit the slow runtime
    // path.
    externalizeString(short2ByteWellFormed, true);
    externalizeString(short2ByteIllFormed, true);
  } catch (e) {}

  assertTrue(short2ByteWellFormed.isWellFormed());
  assertFalse(short2ByteIllFormed.isWellFormed());
})();

(function TestToWellFormed() {
  const short2ByteWellFormed = '\u1234';
  const short2ByteIllFormed = '\uD83D';

  assertTrue(short2ByteWellFormed.isWellFormed());
  assertFalse(short2ByteIllFormed.isWellFormed());

  try {
    // Turn the strings into uncached external strings to hit the slow runtime
    // path.
    externalizeString(short2ByteWellFormed, true);
    externalizeString(short2ByteIllFormed, true);
  } catch (e) {}

  assertEquals('\u1234', short2ByteWellFormed.toWellFormed());
  // U+FFFD (REPLACEMENT CHARACTER)
  assertEquals('\uFFFD', short2ByteIllFormed.toWellFormed());
})();