1 | 'use strict';
|
---|
2 | var $ = require('../internals/export');
|
---|
3 | var globalThis = require('../internals/global-this');
|
---|
4 | var defineBuiltInAccessor = require('../internals/define-built-in-accessor');
|
---|
5 | var DESCRIPTORS = require('../internals/descriptors');
|
---|
6 |
|
---|
7 | var $TypeError = TypeError;
|
---|
8 | // eslint-disable-next-line es/no-object-defineproperty -- safe
|
---|
9 | var defineProperty = Object.defineProperty;
|
---|
10 | var INCORRECT_VALUE = globalThis.self !== globalThis;
|
---|
11 |
|
---|
12 | // `self` getter
|
---|
13 | // https://html.spec.whatwg.org/multipage/window-object.html#dom-self
|
---|
14 | try {
|
---|
15 | if (DESCRIPTORS) {
|
---|
16 | // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
|
---|
17 | var descriptor = Object.getOwnPropertyDescriptor(globalThis, 'self');
|
---|
18 | // some engines have `self`, but with incorrect descriptor
|
---|
19 | // https://github.com/denoland/deno/issues/15765
|
---|
20 | if (INCORRECT_VALUE || !descriptor || !descriptor.get || !descriptor.enumerable) {
|
---|
21 | defineBuiltInAccessor(globalThis, 'self', {
|
---|
22 | get: function self() {
|
---|
23 | return globalThis;
|
---|
24 | },
|
---|
25 | set: function self(value) {
|
---|
26 | if (this !== globalThis) throw new $TypeError('Illegal invocation');
|
---|
27 | defineProperty(globalThis, 'self', {
|
---|
28 | value: value,
|
---|
29 | writable: true,
|
---|
30 | configurable: true,
|
---|
31 | enumerable: true
|
---|
32 | });
|
---|
33 | },
|
---|
34 | configurable: true,
|
---|
35 | enumerable: true
|
---|
36 | });
|
---|
37 | }
|
---|
38 | } else $({ global: true, simple: true, forced: INCORRECT_VALUE }, {
|
---|
39 | self: globalThis
|
---|
40 | });
|
---|
41 | } catch (error) { /* empty */ }
|
---|