blob: 65f5c7118ba139e136960c7834d4801e4b3e9995 [file] [log] [blame]
utatane.tea@gmail.coma977ed82015-08-13 17:25:01 +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
21var proto = {};
22var object = Object.preventExtensions(Object.create(proto));
23
24shouldBe(Object.setPrototypeOf(object, proto), object);
25shouldThrow(() => {
26 Object.setPrototypeOf(object, {});
27}, `TypeError: Attempted to assign to readonly property.`);
28shouldBe(Reflect.getPrototypeOf(object), proto);
29
30shouldBe(Reflect.setPrototypeOf(object, proto), true);
31shouldBe(Reflect.setPrototypeOf(object, {}), false);
32shouldBe(Reflect.getPrototypeOf(object), proto);
33
34object.__proto__ = proto;
35shouldThrow(() => {
36 object.__proto__ = {};
37}, `TypeError: Attempted to assign to readonly property.`);
38shouldBe(object.__proto__, proto);