forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule-namespace-object-define-own-property.js
50 lines (41 loc) · 1.55 KB
/
module-namespace-object-define-own-property.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { shouldBe, shouldThrow, shouldNotThrow } from "./resources/assert.js"
import * as ns from "./module-namespace-object-define-own-property/module.js"
shouldThrow(() => {
Object.defineProperty(ns, Symbol.unscopables, {
value: 42
});
}, `TypeError: Attempting to define property on object that is not extensible.`);
shouldThrow(() => {
Object.defineProperty(ns, Symbol.toStringTag, {
value: 42
});
}, `TypeError: Attempting to change value of a readonly property.`);
shouldThrow(() => {
Object.defineProperty(ns, "variable", {
get: function () { }
});
}, `TypeError: Cannot change module namespace object's binding to accessor`);
shouldThrow(() => {
Object.defineProperty(ns, "variable", {
writable: false
});
}, `TypeError: Cannot change module namespace object's binding to non-writable attribute`);
shouldThrow(() => {
Object.defineProperty(ns, "variable", {
enumerable: false
});
}, `TypeError: Cannot replace module namespace object's binding with non-enumerable attribute`);
shouldThrow(() => {
Object.defineProperty(ns, "variable", {
configurable: true
});
}, `TypeError: Cannot replace module namespace object's binding with configurable attribute`);
shouldThrow(() => {
Object.defineProperty(ns, "variable", {
value: 43
});
}, `TypeError: Cannot replace module namespace object's binding's value`);
shouldNotThrow(() => {
Reflect.defineProperty(ns, "variable", { value: 42 });
});
shouldBe(Reflect.defineProperty(ns, "variable", { value: 42 }), true);