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