main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1014 bytes
|
Rev | Line | |
---|
[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var $TypeError = require('es-errors/type');
|
---|
| 4 |
|
---|
| 5 | var DefinePropertyOrThrow = require('./DefinePropertyOrThrow');
|
---|
| 6 | var HasOwnProperty = require('./HasOwnProperty');
|
---|
| 7 | var IsExtensible = require('./IsExtensible');
|
---|
| 8 |
|
---|
| 9 | var isInteger = require('../helpers/isInteger');
|
---|
| 10 |
|
---|
| 11 | // https://262.ecma-international.org/12.0/#sec-setfunctionlength
|
---|
| 12 |
|
---|
| 13 | module.exports = function SetFunctionLength(F, length) {
|
---|
| 14 | if (typeof F !== 'function' || !IsExtensible(F) || HasOwnProperty(F, 'length')) {
|
---|
| 15 | throw new $TypeError('Assertion failed: `F` must be an extensible function and lack an own `length` property');
|
---|
| 16 | }
|
---|
| 17 | if (typeof length !== 'number') {
|
---|
| 18 | throw new $TypeError('Assertion failed: `length` must be a Number');
|
---|
| 19 | }
|
---|
| 20 | if (length !== Infinity && (!isInteger(length) || length < 0)) {
|
---|
| 21 | throw new $TypeError('Assertion failed: `length` must be ∞, or an integer >= 0');
|
---|
| 22 | }
|
---|
| 23 | return DefinePropertyOrThrow(F, 'length', {
|
---|
| 24 | '[[Configurable]]': true,
|
---|
| 25 | '[[Enumerable]]': false,
|
---|
| 26 | '[[Value]]': length,
|
---|
| 27 | '[[Writable]]': false
|
---|
| 28 | });
|
---|
| 29 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.