Debian Codegraph @

js/src/tests/test262/built-ins/String/length.js

raw
1 // Copyright (C) 2016 the V8 project authors. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3 /*---
4 esid: sec-properties-of-string-instances-length
5 description: The "length" property of String objects
6 info: |
7 [...]
8 4. Return ? StringCreate(s, ? GetPrototypeFromConstructor(NewTarget,
9 "%StringPrototype%")).
10 includes: [propertyHelper.js]
11 ---*/
12
13 var str = new String('');
14
15 verifyProperty(str, 'length', {
16 writable: false,
17 enumerable: false,
18 configurable: false,
19 });
20
21 assert.sameValue(str.length, 0, 'empty string');
22
23 str = new String(' ');
24 assert.sameValue(str.length, 1, 'whitespace');
25
26 str = new String(' \b ');
27 assert.sameValue(str.length, 3, 'character escape (U+008, "backspace")');
28
29 str = new String('\ud834\udf06');
30 assert.sameValue(str.length, 2, 'Unicode escape (surrogate pair)');
31
32 reportCompare(0, 0);