Skip to content

Commit e3a2f45

Browse files
committed
1 parent d6ea893 commit e3a2f45

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

  • html/webappapis/the-shadowrealmglobalscope-interface
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// META: title=The self attribute
2+
// META: global=shadowrealm
3+
4+
test(() => {
5+
assert_equals(self, globalThis, "self should be the same object as globalThis");
6+
}, "self attribute is the global object");
7+
8+
test(() => {
9+
assert_equals(self, self.self, "self should be the same object as self.self");
10+
}, "self attribute is the object itself");
11+
12+
test(() => {
13+
assert_own_property(globalThis, "self", "self should be an own property");
14+
assert_readonly(globalThis, "self", "self should be a read-only property");
15+
}, "self is a readonly attribute");
16+
17+
test(() => {
18+
// https://webidl.spec.whatwg.org/#define-the-attributes
19+
const descr = Object.getOwnPropertyDescriptor(self, "self");
20+
assert_equals(descr.value, undefined, "self should be an accessor property");
21+
assert_true(descr.enumerable, "self should be enumerable");
22+
assert_true(descr.configurable, "self should be configurable");
23+
}, "self property descriptor");
24+
25+
test(() => {
26+
const getter = Object.getOwnPropertyDescriptor(self, "self").get;
27+
assert_equals(getter.name, "get self", "function should be named 'get self'");
28+
}, "self getter name");
29+
30+
test(() => {
31+
const getter = Object.getOwnPropertyDescriptor(self, "self").get;
32+
assert_equals(getter.length, 0, "function should take 0 arguments");
33+
}, "self getter length");
34+
35+
test(() => {
36+
// https://webidl.spec.whatwg.org/#dfn-attribute-getter
37+
const getter = Object.getOwnPropertyDescriptor(self, "self").get;
38+
39+
assert_throws_js(TypeError, () => getter.call({}),
40+
"the self getter should fail a brand check if it's an object not implementing ShadowRealmGlobalScope");
41+
assert_throws_js(TypeError, () => getter.call(42),
42+
"the self getter should fail a brand check if a primitive");
43+
44+
assert_equals(getter.call(null), self,
45+
"the self getter's this object should fall back to the realm's global object if null");
46+
assert_equals(getter.call(undefined), self,
47+
"the self getter's this object should fall back to the realm's global object if undefined");
48+
}, "self getter steps");

0 commit comments

Comments
 (0)