|
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 //----------------------------------------------------------------------------- |
|
7 |
|
8 var BUGNUMBER = 315436; |
|
9 var summary = 'In strict mode, setting a read-only property should generate a warning'; |
|
10 |
|
11 printBugNumber(BUGNUMBER); |
|
12 printStatus (summary); |
|
13 |
|
14 enterFunc (String (BUGNUMBER)); |
|
15 |
|
16 // should throw an error in strict mode |
|
17 var actual = ''; |
|
18 var expect = '"length" is read-only'; |
|
19 var status = summary + ': Throw if STRICT and WERROR is enabled'; |
|
20 |
|
21 if (!options().match(/strict/)) |
|
22 { |
|
23 options('strict'); |
|
24 } |
|
25 if (!options().match(/werror/)) |
|
26 { |
|
27 options('werror'); |
|
28 } |
|
29 |
|
30 try |
|
31 { |
|
32 var s = new String ('abc'); |
|
33 s.length = 0; |
|
34 } |
|
35 catch (e) |
|
36 { |
|
37 actual = e.message; |
|
38 } |
|
39 |
|
40 reportCompare(expect, actual, status); |
|
41 |
|
42 // should not throw an error if in strict mode and WERROR is false |
|
43 |
|
44 actual = 'did not throw'; |
|
45 expect = 'did not throw'; |
|
46 var status = summary + ': Do not throw if STRICT is enabled and WERROR is disabled'; |
|
47 |
|
48 // toggle werror off |
|
49 options('werror'); |
|
50 |
|
51 try |
|
52 { |
|
53 s.length = 0; |
|
54 } |
|
55 catch (e) |
|
56 { |
|
57 actual = e.message; |
|
58 } |
|
59 |
|
60 reportCompare(expect, actual, status); |
|
61 |
|
62 // should not throw an error if not in strict mode |
|
63 |
|
64 actual = 'did not throw'; |
|
65 expect = 'did not throw'; |
|
66 var status = summary + ': Do not throw if not in strict mode'; |
|
67 |
|
68 // toggle strict off |
|
69 options('strict'); |
|
70 |
|
71 try |
|
72 { |
|
73 s.length = 0; |
|
74 } |
|
75 catch (e) |
|
76 { |
|
77 actual = e.message; |
|
78 } |
|
79 |
|
80 reportCompare(expect, actual, status); |