[79a0317] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var test = require('tape');
|
---|
| 4 |
|
---|
| 5 | var setDunderProto = require('../set');
|
---|
| 6 |
|
---|
| 7 | test('setDunderProto', { skip: !setDunderProto }, function (t) {
|
---|
| 8 | if (!setDunderProto) {
|
---|
| 9 | throw 'should never happen; this is just for type narrowing'; // eslint-disable-line no-throw-literal
|
---|
| 10 | }
|
---|
| 11 |
|
---|
| 12 | // @ts-expect-error
|
---|
| 13 | t['throws'](function () { setDunderProto(); }, TypeError, 'throws if no arguments');
|
---|
| 14 | // @ts-expect-error
|
---|
| 15 | t['throws'](function () { setDunderProto(undefined); }, TypeError, 'throws with undefined and nothing');
|
---|
| 16 | // @ts-expect-error
|
---|
| 17 | t['throws'](function () { setDunderProto(undefined, undefined); }, TypeError, 'throws with undefined and undefined');
|
---|
| 18 | // @ts-expect-error
|
---|
| 19 | t['throws'](function () { setDunderProto(null); }, TypeError, 'throws with null and undefined');
|
---|
| 20 | // @ts-expect-error
|
---|
| 21 | t['throws'](function () { setDunderProto(null, undefined); }, TypeError, 'throws with null and undefined');
|
---|
| 22 |
|
---|
| 23 | /** @type {{ inherited?: boolean }} */
|
---|
| 24 | var obj = {};
|
---|
| 25 | t.ok('toString' in obj, 'object initially has toString');
|
---|
| 26 |
|
---|
| 27 | setDunderProto(obj, null);
|
---|
| 28 | t.notOk('toString' in obj, 'object no longer has toString');
|
---|
| 29 |
|
---|
| 30 | t.notOk('inherited' in obj, 'object lacks inherited property');
|
---|
| 31 | setDunderProto(obj, { inherited: true });
|
---|
| 32 | t.equal(obj.inherited, true, 'object has inherited property');
|
---|
| 33 |
|
---|
| 34 | t.end();
|
---|
| 35 | });
|
---|
| 36 |
|
---|
| 37 | test('no dunder proto', { skip: !!setDunderProto }, function (t) {
|
---|
| 38 | if ('__proto__' in Object.prototype) {
|
---|
| 39 | t['throws'](
|
---|
| 40 | // @ts-expect-error
|
---|
| 41 | function () { ({}).__proto__ = null; }, // eslint-disable-line no-proto
|
---|
| 42 | Error,
|
---|
| 43 | 'throws when setting Object.prototype.__proto__'
|
---|
| 44 | );
|
---|
| 45 | } else {
|
---|
| 46 | t.notOk('__proto__' in Object.prototype, 'no __proto__ in Object.prototype');
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | t.end();
|
---|
| 50 | });
|
---|