main
Last change
on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 5 days ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
1012 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 | var DESCRIPTORS = require('../internals/descriptors');
|
---|
3 | var isArray = require('../internals/is-array');
|
---|
4 |
|
---|
5 | var $TypeError = TypeError;
|
---|
6 | // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
|
---|
7 | var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
|
---|
8 |
|
---|
9 | // Safari < 13 does not throw an error in this case
|
---|
10 | var SILENT_ON_NON_WRITABLE_LENGTH_SET = DESCRIPTORS && !function () {
|
---|
11 | // makes no sense without proper strict mode support
|
---|
12 | if (this !== undefined) return true;
|
---|
13 | try {
|
---|
14 | // eslint-disable-next-line es/no-object-defineproperty -- safe
|
---|
15 | Object.defineProperty([], 'length', { writable: false }).length = 1;
|
---|
16 | } catch (error) {
|
---|
17 | return error instanceof TypeError;
|
---|
18 | }
|
---|
19 | }();
|
---|
20 |
|
---|
21 | module.exports = SILENT_ON_NON_WRITABLE_LENGTH_SET ? function (O, length) {
|
---|
22 | if (isArray(O) && !getOwnPropertyDescriptor(O, 'length').writable) {
|
---|
23 | throw new $TypeError('Cannot set read only .length');
|
---|
24 | } return O.length = length;
|
---|
25 | } : function (O, length) {
|
---|
26 | return O.length = length;
|
---|
27 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.