| [9af201e] | 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | var $gOPD = require('gopd');
|
|---|
| 4 | var $SyntaxError = require('es-errors/syntax');
|
|---|
| 5 | var $TypeError = require('es-errors/type');
|
|---|
| 6 | var isObject = require('es-object-atoms/isObject');
|
|---|
| 7 |
|
|---|
| 8 | var isPropertyDescriptor = require('../helpers/records/property-descriptor');
|
|---|
| 9 |
|
|---|
| 10 | var IsAccessorDescriptor = require('./IsAccessorDescriptor');
|
|---|
| 11 | var IsExtensible = require('./IsExtensible');
|
|---|
| 12 | var isPropertyKey = require('../helpers/isPropertyKey');
|
|---|
| 13 | var ToPropertyDescriptor = require('./ToPropertyDescriptor');
|
|---|
| 14 | var SameValue = require('./SameValue');
|
|---|
| 15 | var ValidateAndApplyPropertyDescriptor = require('./ValidateAndApplyPropertyDescriptor');
|
|---|
| 16 |
|
|---|
| 17 | // https://262.ecma-international.org/6.0/#sec-ordinarydefineownproperty
|
|---|
| 18 |
|
|---|
| 19 | module.exports = function OrdinaryDefineOwnProperty(O, P, Desc) {
|
|---|
| 20 | if (!isObject(O)) {
|
|---|
| 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 | };
|
|---|