|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.2 KB
|
| Line | |
|---|
| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | var callBind = require('call-bind-apply-helpers');
|
|---|
| 4 | var gOPD = require('gopd');
|
|---|
| 5 | var $TypeError = require('es-errors/type');
|
|---|
| 6 |
|
|---|
| 7 | /** @type {{ __proto__?: object | null }} */
|
|---|
| 8 | var obj = {};
|
|---|
| 9 | try {
|
|---|
| 10 | obj.__proto__ = null; // eslint-disable-line no-proto
|
|---|
| 11 | } catch (e) {
|
|---|
| 12 | if (!e || typeof e !== 'object' || !('code' in e) || e.code !== 'ERR_PROTO_ACCESS') {
|
|---|
| 13 | throw e;
|
|---|
| 14 | }
|
|---|
| 15 | }
|
|---|
| 16 |
|
|---|
| 17 | var hasProtoMutator = !('toString' in obj);
|
|---|
| 18 |
|
|---|
| 19 | // eslint-disable-next-line no-extra-parens
|
|---|
| 20 | var desc = gOPD && gOPD(Object.prototype, /** @type {keyof typeof Object.prototype} */ ('__proto__'));
|
|---|
| 21 |
|
|---|
| 22 | /** @type {import('./set')} */
|
|---|
| 23 | module.exports = hasProtoMutator && (
|
|---|
| 24 | // eslint-disable-next-line no-extra-parens
|
|---|
| 25 | (!!desc && typeof desc.set === 'function' && /** @type {import('./set')} */ (callBind([desc.set])))
|
|---|
| 26 | || /** @type {import('./set')} */ function setDunder(object, proto) {
|
|---|
| 27 | // this is node v0.10 or older, which doesn't have Object.setPrototypeOf and has undeniable __proto__
|
|---|
| 28 | if (object == null) { // eslint-disable-line eqeqeq
|
|---|
| 29 | throw new $TypeError('set Object.prototype.__proto__ called on null or undefined');
|
|---|
| 30 | }
|
|---|
| 31 | // eslint-disable-next-line no-proto, no-param-reassign, no-extra-parens
|
|---|
| 32 | /** @type {{ __proto__?: object | null }} */ (object).__proto__ = proto;
|
|---|
| 33 | return proto;
|
|---|
| 34 | }
|
|---|
| 35 | );
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.