tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

self.any.js (2009B)


      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");