]>
Commit | Line | Data |
---|---|---|
ed1e77d3 A |
1 | function shouldBe(actual, expected) { |
2 | if (actual !== expected) | |
3 | throw new Error('bad value: ' + actual); | |
4 | } | |
5 | ||
6 | function shouldThrow(func, errorMessage) { | |
7 | var errorThrown = false; | |
8 | var error = null; | |
9 | try { | |
10 | func(); | |
11 | } catch (e) { | |
12 | errorThrown = true; | |
13 | error = e; | |
14 | } | |
15 | if (!errorThrown) | |
16 | throw new Error('not thrown'); | |
17 | if (String(error) !== errorMessage) | |
18 | throw new Error(`bad error: ${String(error)}`); | |
19 | } | |
20 | ||
21 | shouldThrow(function () { | |
22 | 'use strict'; | |
23 | RegExp.prototype.global = 'Cocoa'; | |
24 | }, 'TypeError: Attempted to assign to readonly property.'); | |
25 | ||
26 | // Twice. | |
27 | shouldThrow(function () { | |
28 | 'use strict'; | |
29 | RegExp.prototype.global = 'Cocoa'; | |
30 | }, 'TypeError: Attempted to assign to readonly property.'); | |
31 | ||
32 | (function () { | |
33 | 'use strict'; | |
34 | delete RegExp.prototype.global; | |
35 | RegExp.prototype.global = 'Cocoa'; | |
36 | shouldBe(RegExp.prototype.global, 'Cocoa'); | |
37 | shouldBe(/Cappuccino/.global, 'Cocoa'); | |
38 | }()); |