Debian Codegraph @

js/src/tests/test262/built-ins/encodeURIComponent/S15.1.3.4_A1.3_T1.js

raw
1 // Copyright 2009 the Sputnik authors. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3
4 /*---
5 info: |
6 If string.charAt(k) in [0xD800 - 0xDBFF] and string.charAt(k+1) not in
7 [0xDC00 - 0xDFFF], throw URIError
8 esid: sec-encodeuricomponent-uricomponent
9 description: >
10 Complex tests, string.charAt(k+1) in [0x0000, 0xD7FF, 0xD800,
11 0xDBFE, 0xDBFF, 0xE000, 0xFFFF]
12 includes: [decimalToHexString.js]
13 ---*/
14
15 var chars = [0x0000, 0xD7FF, 0xD800, 0xDBFE, 0xDBFF, 0xE000, 0xFFFF];
16 var errorCount = 0;
17 var count = 0;
18 var indexP;
19 var indexO = 0;
20
21 for (var index = 0xD800; index <= 0xDBFF; index++) {
22 count++;
23 var res = true;
24 for (var indexC = 0; indexC < chars.length; indexC++) {
25 try {
26 encodeURIComponent(String.fromCharCode(index, chars[indexC]));
27 } catch (e) {
28 if ((e instanceof URIError) === true) continue;
29 }
30 res = false;
31 }
32 if (res !== true) {
33 if (indexO === 0) {
34 indexO = index;
35 } else {
36 if ((index - indexP) !== 1) {
37 if ((indexP - indexO) !== 0) {
38 var hexP = decimalToHexString(indexP);
39 var hexO = decimalToHexString(indexO);
40 throw new Test262Error('#' + hexO + '-' + hexP + ' ');
41 }
42 else {
43 var hexP = decimalToHexString(indexP);
44 throw new Test262Error('#' + hexP + ' ');
45 }
46 indexO = index;
47 }
48 }
49 indexP = index;
50 errorCount++;
51 }
52 }
53
54 if (errorCount > 0) {
55 if ((indexP - indexO) !== 0) {
56 var hexP = decimalToHexString(indexP);
57 var hexO = decimalToHexString(indexO);
58 throw new Test262Error('#' + hexO + '-' + hexP + ' ');
59 } else {
60 var hexP = decimalToHexString(indexP);
61 throw new Test262Error('#' + hexP + ' ');
62 }
63 throw new Test262Error('Total error: ' + errorCount + ' bad Unicode character in ' + count + ' ');
64 }
65
66 reportCompare(0, 0);