blob: aac8f4f1c635f23d0d3a5513da692fed6be21486 [file] [log] [blame]
utatane.tea@gmail.comf24ee892015-06-09 18:42:46 +00001function shouldBe(actual, expected) {
2 if (actual !== expected)
3 throw new Error('bad value: ' + actual);
4}
5
6function 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
21shouldThrow(function () {
22 'use strict';
23 RegExp.prototype.global = 'Cocoa';
24}, 'TypeError: Attempted to assign to readonly property.');
25
26// Twice.
27shouldThrow(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}());