Debian Codegraph @

rhino/testsrc/tests/js1_5/Exceptions/regress-232182.js

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 var gTestfile = 'regress-232182.js';
7 //-----------------------------------------------------------------------------
8
9 var BUGNUMBER = 232182;
10 var summary = 'Display non-ascii characters in JS exceptions';
11 var actual = '';
12 var expect = 'no error';
13
14 printBugNumber(BUGNUMBER);
15 printStatus (summary);
16
17 /*
18 * This test accesses an undefined Unicode symbol. If the code has not been
19 * compiled with JS_C_STRINGS_ARE_UTF8, the thrown error truncates Unicode
20 * characters to bytes. Accessing \u0440\u0441, therefore, results in a
21 * message talking about an undefined variable 'AB' (\x41\x42).
22 */
23 var utf8Enabled = false;
24 try
25 {
26 \u0441\u0442;
27 }
28 catch (e)
29 {
30 utf8Enabled = (e.message.charAt (0) == '\u0441');
31 }
32
33 // Run the tests only if UTF-8 is enabled
34
35 printStatus('UTF-8 is ' + (utf8Enabled?'':'not ') + 'enabled');
36
37 if (!utf8Enabled)
38 {
39 reportCompare('Not run', 'Not run', 'utf8 is not enabled');
40 }
41 else
42 {
43 status = summary + ': Throw Error with Unicode message';
44 expect = 'test \u0440\u0441';
45 try
46 {
47 throw Error (expect);
48 }
49 catch (e)
50 {
51 actual = e.message;
52 }
53 reportCompare(expect, actual, status);
54
55 var inShell = (typeof stringsAreUTF8 == "function");
56 if (!inShell)
57 {
58 inShell = (typeof stringsAreUtf8 == "function");
59 if (inShell)
60 {
61 this.stringsAreUTF8 = stringsAreUtf8;
62 this.testUTF8 = testUtf8;
63 }
64 }
65
66 if (inShell && stringsAreUTF8())
67 {
68 status = summary + ': UTF-8 test: bad UTF-08 sequence';
69 expect = 'Error';
70 actual = 'No error!';
71 try
72 {
73 testUTF8(1);
74 }
75 catch (e)
76 {
77 actual = 'Error';
78 }
79 reportCompare(expect, actual, status);
80
81 status = summary + ': UTF-8 character too big to fit into Unicode surrogate pairs';
82 expect = 'Error';
83 actual = 'No error!';
84 try
85 {
86 testUTF8(2);
87 }
88 catch (e)
89 {
90 actual = 'Error';
91 }
92 reportCompare(expect, actual, status);
93
94 status = summary + ': bad Unicode surrogate character';
95 expect = 'Error';
96 actual = 'No error!';
97 try
98 {
99 testUTF8(3);
100 }
101 catch (e)
102 {
103 actual = 'Error';
104 }
105 reportCompare(expect, actual, status);
106 }
107
108 if (inShell)
109 {
110 status = summary + ': conversion target buffer overrun';
111 expect = 'Error';
112 actual = 'No error!';
113 try
114 {
115 testUTF8(4);
116 }
117 catch (e)
118 {
119 actual = 'Error';
120 }
121 reportCompare(expect, actual, status);
122 }
123 }