source: imaps-frontend/node_modules/es-abstract/2023/OrdinaryDefineOwnProperty.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: 2.1 KB
Line 
1'use strict';
2
3var $gOPD = require('gopd');
4var $SyntaxError = require('es-errors/syntax');
5var $TypeError = require('es-errors/type');
6
7var isPropertyDescriptor = require('../helpers/records/property-descriptor');
8
9var IsAccessorDescriptor = require('./IsAccessorDescriptor');
10var IsExtensible = require('./IsExtensible');
11var IsPropertyKey = require('./IsPropertyKey');
12var ToPropertyDescriptor = require('./ToPropertyDescriptor');
13var SameValue = require('./SameValue');
14var Type = require('./Type');
15var ValidateAndApplyPropertyDescriptor = require('./ValidateAndApplyPropertyDescriptor');
16
17// https://262.ecma-international.org/6.0/#sec-ordinarydefineownproperty
18
19module.exports = function OrdinaryDefineOwnProperty(O, P, Desc) {
20 if (Type(O) !== 'Object') {
21 throw new $TypeError('Assertion failed: O must be an Object');
22 }
23 if (!IsPropertyKey(P)) {
24 throw new $TypeError('Assertion failed: P must be a Property Key');
25 }
26 if (!isPropertyDescriptor(Desc)) {
27 throw new $TypeError('Assertion failed: Desc must be a Property Descriptor');
28 }
29 if (!$gOPD) {
30 // ES3/IE 8 fallback
31 if (IsAccessorDescriptor(Desc)) {
32 throw new $SyntaxError('This environment does not support accessor property descriptors.');
33 }
34 var creatingNormalDataProperty = !(P in O)
35 && Desc['[[Writable]]']
36 && Desc['[[Enumerable]]']
37 && Desc['[[Configurable]]']
38 && '[[Value]]' in Desc;
39 var settingExistingDataProperty = (P in O)
40 && (!('[[Configurable]]' in Desc) || Desc['[[Configurable]]'])
41 && (!('[[Enumerable]]' in Desc) || Desc['[[Enumerable]]'])
42 && (!('[[Writable]]' in Desc) || Desc['[[Writable]]'])
43 && '[[Value]]' in Desc;
44 if (creatingNormalDataProperty || settingExistingDataProperty) {
45 O[P] = Desc['[[Value]]']; // eslint-disable-line no-param-reassign
46 return SameValue(O[P], Desc['[[Value]]']);
47 }
48 throw new $SyntaxError('This environment does not support defining non-writable, non-enumerable, or non-configurable properties');
49 }
50 var desc = $gOPD(O, P);
51 var current = desc && ToPropertyDescriptor(desc);
52 var extensible = IsExtensible(O);
53 return ValidateAndApplyPropertyDescriptor(O, P, extensible, Desc, current);
54};
Note: See TracBrowser for help on using the repository browser.