Skip to content

Commit

Permalink
Remove no longer needed arePropertyDescriptorsSupported checks
Browse files Browse the repository at this point in the history
  • Loading branch information
mhassan1 authored and JakeChampion committed Apr 1, 2022
1 parent 55c034e commit 20cdbb1
Show file tree
Hide file tree
Showing 21 changed files with 429 additions and 686 deletions.
392 changes: 186 additions & 206 deletions polyfills/Map/tests.js

Large diffs are not rendered by default.

186 changes: 84 additions & 102 deletions polyfills/Object/entries/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,6 @@ it('is not enumerable', function () {
// Copyright (C) 2015 Jordan Harband. All rights reserved.
// This code is governed by the BSD license.

var arePropertyDescriptorsSupported = function() {
var obj = {};
Object.defineProperty(obj, 'x', {
enumerable: false,
value: obj
});
for (var _ in obj) {
return false;
}
return obj.x === obj;
};

var supportsDescriptors = Object.defineProperty && arePropertyDescriptorsSupported();

var hasSymbols = typeof Symbol === 'function' && typeof Symbol() === 'symbol';

var objectKeysWorksWithPrimitives = (function() {
Expand All @@ -46,26 +32,24 @@ var objectKeysWorksWithPrimitives = (function() {
}
}());

if (supportsDescriptors) {
it('should terminate if getting a value throws an exception', function () {
proclaim.throws(function () {
var obj = {};
Object.defineProperty(obj, 'a', {
enumerable: true,
get: function () {
throw new Error('This is the thrown error');
}
});
Object.defineProperty(obj, 'b', {
enumerable: true,
get: function () {
throw new Error();
}
});
Object.entries(obj);
}, Error, 'This is the thrown error');
});
}
it('should terminate if getting a value throws an exception', function () {
proclaim.throws(function () {
var obj = {};
Object.defineProperty(obj, 'a', {
enumerable: true,
get: function () {
throw new Error('This is the thrown error');
}
});
Object.defineProperty(obj, 'b', {
enumerable: true,
get: function () {
throw new Error();
}
});
Object.entries(obj);
}, Error, 'This is the thrown error');
});

it('should throw TypeError when called with `null`', function() {
proclaim.throws(function() {
Expand All @@ -79,89 +63,87 @@ it('should throw TypeError when called with `undefined`', function() {
}, TypeError);
});

if (supportsDescriptors) {
it('does not see a new element added by a getter that is hit during iteration', function () {
var bAddsC = {
a: 'A'
};
Object.defineProperty(bAddsC, 'b', {
enumerable: true,
get: function () {
this.c = 'C';
return 'B';
}
});
it('does not see a new element added by a getter that is hit during iteration', function () {
var bAddsC = {
a: 'A'
};
Object.defineProperty(bAddsC, 'b', {
enumerable: true,
get: function () {
this.c = 'C';
return 'B';
}
});

var result = Object.entries(bAddsC);
var result = Object.entries(bAddsC);

proclaim.isArray(result, 'result is an array');
proclaim.equal(result.length, 2);
proclaim.isArray(result, 'result is an array');
proclaim.equal(result.length, 2);

proclaim.isArray(result[0], 'first entry is an array');
proclaim.isArray(result[1], 'second entry is an array');
proclaim.isArray(result[0], 'first entry is an array');
proclaim.isArray(result[1], 'second entry is an array');

proclaim.deepEqual(result, [
['a', 'A'],
['b', 'B']
]);
proclaim.deepEqual(result, [
['a', 'A'],
['b', 'B']
]);
});

it('does not see an element made non-enumerable by a getter that is hit during iteration', function () {
var bHidesC = {
a: 'A'
};
Object.defineProperty(bHidesC, 'b', {
enumerable: true,
get: function () {
Object.defineProperty(this, 'c', {
enumerable: false
});
return 'B';
}
});
bHidesC.c = 'C';

it('does not see an element made non-enumerable by a getter that is hit during iteration', function () {
var bHidesC = {
a: 'A'
};
Object.defineProperty(bHidesC, 'b', {
enumerable: true,
get: function () {
Object.defineProperty(this, 'c', {
enumerable: false
});
return 'B';
}
});
bHidesC.c = 'C';
var result = Object.entries(bHidesC);

var result = Object.entries(bHidesC);
proclaim.isArray(result, 'result is an array');
proclaim.equal(result.length, 2, 'result has 2 items');

proclaim.isArray(result, 'result is an array');
proclaim.equal(result.length, 2, 'result has 2 items');
proclaim.isArray(result[0], 'first entry is an array');
proclaim.isArray(result[1], 'second entry is an array');

proclaim.isArray(result[0], 'first entry is an array');
proclaim.isArray(result[1], 'second entry is an array');
proclaim.deepEqual(result, [
['a', 'A'],
['b', 'B']
]);
});

proclaim.deepEqual(result, [
['a', 'A'],
['b', 'B']
]);
it('does not see an element removed by a getter that is hit during iteration', function () {
var bDeletesC = {
a: 'A'
};
Object.defineProperty(bDeletesC, 'b', {
enumerable: true,
get: function () {
delete this.c;
return 'B';
}
});
bDeletesC.c = 'C';

it('does not see an element removed by a getter that is hit during iteration', function () {
var bDeletesC = {
a: 'A'
};
Object.defineProperty(bDeletesC, 'b', {
enumerable: true,
get: function () {
delete this.c;
return 'B';
}
});
bDeletesC.c = 'C';

var result = Object.entries(bDeletesC);
var result = Object.entries(bDeletesC);

proclaim.isArray(result, 'result is an array');
proclaim.equal(result.length, 2, 'result has 2 items');
proclaim.isArray(result, 'result is an array');
proclaim.equal(result.length, 2, 'result has 2 items');

proclaim.isArray(result[0], 'first entry is an array');
proclaim.isArray(result[1], 'second entry is an array');
proclaim.isArray(result[0], 'first entry is an array');
proclaim.isArray(result[1], 'second entry is an array');

proclaim.deepEqual(result, [
['a', 'A'],
['b', 'B']
]);
});
}
proclaim.deepEqual(result, [
['a', 'A'],
['b', 'B']
]);
});

it('does not see inherited properties', function() {
var F = function G() {};
Expand Down
1 change: 0 additions & 1 deletion polyfills/Object/getOwnPropertyDescriptor/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ aliases = [
]
dependencies = [
"_ESAbstract.CreateMethodProperty",
"_ESAbstract.HasOwnProperty",
"_ESAbstract.ToObject",
"_ESAbstract.ToPropertyKey",
"_ESAbstract.Type",
Expand Down
32 changes: 2 additions & 30 deletions polyfills/Object/getOwnPropertyDescriptor/polyfill.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
/* global CreateMethodProperty, ToObject, ToPropertyKey, HasOwnProperty, Type */
/* global CreateMethodProperty, ToObject, ToPropertyKey, Type */
(function () {
var nativeGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;

var supportsDOMDescriptors = (function () {
try {
return Object.defineProperty(document.createElement('div'), 'one', {
get: function () {
return 1;
}
}).one === 1;
} catch (e) {
return false;
}
});

var toString = ({}).toString;
var split = ''.split;

Expand All @@ -29,21 +16,6 @@

// 3. Let desc be ? obj.[[GetOwnProperty]](key).
// 4. Return FromPropertyDescriptor(desc).
// Polyfill.io Internet Explorer 8 natively supports property descriptors only on DOM objects.
// We will fallback to the polyfill implementation if the native implementation throws an error.
if (supportsDOMDescriptors) {
try {
return nativeGetOwnPropertyDescriptor(obj, key);
// eslint-disable-next-line no-empty
} catch (error) {}
}
if (HasOwnProperty(obj, key)) {
return {
enumerable: true,
configurable: true,
writable: true,
value: obj[key]
};
}
return nativeGetOwnPropertyDescriptor(obj, key);
});
}());

0 comments on commit 20cdbb1

Please sign in to comment.