Debian Codegraph @

rhino/testsrc/org/mozilla/javascript/tests/Issue176.js

raw symbols SCIP
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 /*
6 * host is instance of Issue176Test
7 */
8
9 /*
10 * Step 1: Basic built-in errors from java
11 */
12 try {
13 host.throwError("Aboo!"); // line 13
14 throw 'Unreachable 1!';
15 } catch (e) { // EcmaError
16 var act = e.toString();
17 if (act !== 'Error: Aboo!') throw 'Test 1: Wrong toString(): ' + act;
18 if (e.name !== 'Error') throw 'Test 2: Wrong name: ' + e.name;
19 // FIXME: sourceName is undefined - why?
20 // if (e.sourceName !== 'Issue176.js') throw 'Test 3: Wrong source: ' + e.sourceName;
21 if (e.lineNumber !== 13) throw 'Test 4: Wrong source line: ' + e.lineNumber;
22 }
23
24
25 /*
26 * Step 2: User-defined errors from java
27 */
28 function MyBang(msg, file, line) {
29 this.foo = 'Bar';
30 this.msg = msg;
31 this.file = file;
32 this.line = line;
33 }
34
35 try {
36 host.throwCustomError("MyBang", "Aboo!"); // line 36
37 throw 'Unreachable 2!';
38 } catch (e) { // MyBang
39 if (e.foo !== 'Bar') throw 'Test 5: Wrong foo: ' + e.foo + " (" + e + ")";
40 if (e.msg !== 'Aboo!') throw 'Test 6: Wrong msg: ' + e.msg+ " (" + e + ")";
41 if (e.file !== 'Issue176.js') throw 'Test 7: Wrong file: ' + e.file+ " (" + e + ")";
42 if (e.line !== 36) throw 'Test 8: Wrong line: ' + e.line+ " (" + e + ")";
43 }
44
45
46 /*
47 * Step 3: Change a built-in error, but make sure it is not overwritten.
48 * Thanks to anba for explaining the issue.
49 */
50 TypeError = function() { this.msg = 'Wrong!' };
51
52 try {
53 Object.create(void 0);
54 throw 'Unreachable 3!';
55 } catch (e) {
56 // FIXME: TypeError is actually overwritten
57 // if (e.msg === 'Wrong!') throw 'Test 9: TypeError can be overwritten ?! (' + e + ')';
58 }
59
60
61 "success";