source: imaps-frontend/node_modules/es-abstract/2022/ToPropertyDescriptor.js@ d565449

main
Last change on this file since d565449 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 hasOwn = require('hasown');
4
5var $TypeError = require('es-errors/type');
6
7var Type = require('./Type');
8var ToBoolean = require('./ToBoolean');
9var IsCallable = require('./IsCallable');
10
11// https://262.ecma-international.org/5.1/#sec-8.10.5
12
13module.exports = function ToPropertyDescriptor(Obj) {
14 if (Type(Obj) !== 'Object') {
15 throw new $TypeError('ToPropertyDescriptor requires an object');
16 }
17
18 var desc = {};
19 if (hasOwn(Obj, 'enumerable')) {
20 desc['[[Enumerable]]'] = ToBoolean(Obj.enumerable);
21 }
22 if (hasOwn(Obj, 'configurable')) {
23 desc['[[Configurable]]'] = ToBoolean(Obj.configurable);
24 }
25 if (hasOwn(Obj, 'value')) {
26 desc['[[Value]]'] = Obj.value;
27 }
28 if (hasOwn(Obj, 'writable')) {
29 desc['[[Writable]]'] = ToBoolean(Obj.writable);
30 }
31 if (hasOwn(Obj, 'get')) {
32 var getter = Obj.get;
33 if (typeof getter !== 'undefined' && !IsCallable(getter)) {
34 throw new $TypeError('getter must be a function');
35 }
36 desc['[[Get]]'] = getter;
37 }
38 if (hasOwn(Obj, 'set')) {
39 var setter = Obj.set;
40 if (typeof setter !== 'undefined' && !IsCallable(setter)) {
41 throw new $TypeError('setter must be a function');
42 }
43 desc['[[Set]]'] = setter;
44 }
45
46 if ((hasOwn(desc, '[[Get]]') || hasOwn(desc, '[[Set]]')) && (hasOwn(desc, '[[Value]]') || hasOwn(desc, '[[Writable]]'))) {
47 throw new $TypeError('Invalid property descriptor. Cannot both specify accessors and a value or writable attribute');
48 }
49 return desc;
50};
Note: See TracBrowser for help on using the repository browser.