1 | 'use strict';
|
---|
2 |
|
---|
3 | var $TypeError = require('es-errors/type');
|
---|
4 |
|
---|
5 | var hasOwn = require('hasown');
|
---|
6 |
|
---|
7 | var IsDataDescriptor = require('./IsDataDescriptor');
|
---|
8 | var IsGenericDescriptor = require('./IsGenericDescriptor');
|
---|
9 |
|
---|
10 | var isPropertyDescriptor = require('../helpers/records/property-descriptor');
|
---|
11 |
|
---|
12 | // https://262.ecma-international.org/6.0/#sec-completepropertydescriptor
|
---|
13 |
|
---|
14 | module.exports = function CompletePropertyDescriptor(Desc) {
|
---|
15 | if (!isPropertyDescriptor(Desc)) {
|
---|
16 | throw new $TypeError('Assertion failed: `Desc` must be a Property Descriptor');
|
---|
17 | }
|
---|
18 |
|
---|
19 | /* eslint no-param-reassign: 0 */
|
---|
20 |
|
---|
21 | if (IsGenericDescriptor(Desc) || IsDataDescriptor(Desc)) {
|
---|
22 | if (!hasOwn(Desc, '[[Value]]')) {
|
---|
23 | Desc['[[Value]]'] = void 0;
|
---|
24 | }
|
---|
25 | if (!hasOwn(Desc, '[[Writable]]')) {
|
---|
26 | Desc['[[Writable]]'] = false;
|
---|
27 | }
|
---|
28 | } else {
|
---|
29 | if (!hasOwn(Desc, '[[Get]]')) {
|
---|
30 | Desc['[[Get]]'] = void 0;
|
---|
31 | }
|
---|
32 | if (!hasOwn(Desc, '[[Set]]')) {
|
---|
33 | Desc['[[Set]]'] = void 0;
|
---|
34 | }
|
---|
35 | }
|
---|
36 | if (!hasOwn(Desc, '[[Enumerable]]')) {
|
---|
37 | Desc['[[Enumerable]]'] = false;
|
---|
38 | }
|
---|
39 | if (!hasOwn(Desc, '[[Configurable]]')) {
|
---|
40 | Desc['[[Configurable]]'] = false;
|
---|
41 | }
|
---|
42 | return Desc;
|
---|
43 | };
|
---|