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