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

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