source: imaps-frontend/node_modules/es-abstract/2022/DefineMethodProperty.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 1.5 KB
RevLine 
[d565449]1'use strict';
2
3var $TypeError = require('es-errors/type');
4
5var DefinePropertyOrThrow = require('./DefinePropertyOrThrow');
6var IsExtensible = require('./IsExtensible');
[79a0317]7
8var isObject = require('../helpers/isObject');
9var isPropertyKey = require('../helpers/isPropertyKey');
[d565449]10
11// https://262.ecma-international.org/13.0/#sec-definemethodproperty
12
13module.exports = function DefineMethodProperty(homeObject, key, closure, enumerable) {
[79a0317]14 if (!isObject(homeObject)) {
[d565449]15 throw new $TypeError('Assertion failed: `homeObject` is not an Object');
16 }
[79a0317]17 if (!isPropertyKey(key)) {
[d565449]18 throw new $TypeError('Assertion failed: `key` is not a Property Key or a Private Name');
19 }
20 if (typeof closure !== 'function') {
21 throw new $TypeError('Assertion failed: `closure` is not a function');
22 }
23 if (typeof enumerable !== 'boolean') {
24 throw new $TypeError('Assertion failed: `enumerable` is not a Boolean');
25 }
26
27 // 1. Assert: homeObject is an ordinary, extensible object with no non-configurable properties.
28 if (!IsExtensible(homeObject)) {
29 throw new $TypeError('Assertion failed: `homeObject` is not an ordinary, extensible object, with no non-configurable properties');
30 }
31
32 // 2. If key is a Private Name, then
33 // a. Return PrivateElement { [[Key]]: key, [[Kind]]: method, [[Value]]: closure }.
34 // 3. Else,
35 var desc = { // step 3.a
36 '[[Value]]': closure,
37 '[[Writable]]': true,
38 '[[Enumerable]]': enumerable,
39 '[[Configurable]]': true
40 };
41 DefinePropertyOrThrow(homeObject, key, desc); // step 3.b
42};
Note: See TracBrowser for help on using the repository browser.