You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
1008 B
28 lines
1008 B
2 years ago
|
'use strict';
|
||
|
var DESCRIPTORS = require('../internals/descriptors');
|
||
|
var isArray = require('../internals/is-array');
|
||
|
|
||
|
var $TypeError = TypeError;
|
||
|
// eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
|
||
|
var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
|
||
|
|
||
|
// Safari < 13 does not throw an error in this case
|
||
|
var SILENT_ON_NON_WRITABLE_LENGTH_SET = DESCRIPTORS && !function () {
|
||
|
// makes no sense without proper strict mode support
|
||
|
if (this !== undefined) return true;
|
||
|
try {
|
||
|
// eslint-disable-next-line es/no-object-defineproperty -- safe
|
||
|
Object.defineProperty([], 'length', { writable: false }).length = 1;
|
||
|
} catch (error) {
|
||
|
return error instanceof TypeError;
|
||
|
}
|
||
|
}();
|
||
|
|
||
|
module.exports = SILENT_ON_NON_WRITABLE_LENGTH_SET ? function (O, length) {
|
||
|
if (isArray(O) && !getOwnPropertyDescriptor(O, 'length').writable) {
|
||
|
throw $TypeError('Cannot set read only .length');
|
||
|
} return O.length = length;
|
||
|
} : function (O, length) {
|
||
|
return O.length = length;
|
||
|
};
|