web.self.js 1.4 KB

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