1 |
3a515b92
|
cagy
|
'use strict';
|
2 |
|
|
|
3 |
|
|
var GetIntrinsic = require('../GetIntrinsic');
|
4 |
|
|
|
5 |
|
|
var $TypeError = GetIntrinsic('%TypeError%');
|
6 |
|
|
|
7 |
|
|
var DefineOwnProperty = require('../helpers/DefineOwnProperty');
|
8 |
|
|
|
9 |
|
|
var FromPropertyDescriptor = require('./FromPropertyDescriptor');
|
10 |
|
|
var OrdinaryGetOwnProperty = require('./OrdinaryGetOwnProperty');
|
11 |
|
|
var IsDataDescriptor = require('./IsDataDescriptor');
|
12 |
|
|
var IsExtensible = require('./IsExtensible');
|
13 |
|
|
var IsPropertyKey = require('./IsPropertyKey');
|
14 |
|
|
var SameValue = require('./SameValue');
|
15 |
|
|
var Type = require('./Type');
|
16 |
|
|
|
17 |
|
|
// https://www.ecma-international.org/ecma-262/6.0/#sec-createdataproperty
|
18 |
|
|
|
19 |
|
|
module.exports = function CreateDataProperty(O, P, V) {
|
20 |
|
|
if (Type(O) !== 'Object') {
|
21 |
|
|
throw new $TypeError('Assertion failed: Type(O) is not Object');
|
22 |
|
|
}
|
23 |
|
|
if (!IsPropertyKey(P)) {
|
24 |
|
|
throw new $TypeError('Assertion failed: IsPropertyKey(P) is not true');
|
25 |
|
|
}
|
26 |
|
|
var oldDesc = OrdinaryGetOwnProperty(O, P);
|
27 |
|
|
var extensible = !oldDesc || IsExtensible(O);
|
28 |
|
|
var immutable = oldDesc && (!oldDesc['[[Writable]]'] || !oldDesc['[[Configurable]]']);
|
29 |
|
|
if (immutable || !extensible) {
|
30 |
|
|
return false;
|
31 |
|
|
}
|
32 |
|
|
return DefineOwnProperty(
|
33 |
|
|
IsDataDescriptor,
|
34 |
|
|
SameValue,
|
35 |
|
|
FromPropertyDescriptor,
|
36 |
|
|
O,
|
37 |
|
|
P,
|
38 |
|
|
{
|
39 |
|
|
'[[Configurable]]': true,
|
40 |
|
|
'[[Enumerable]]': true,
|
41 |
|
|
'[[Value]]': V,
|
42 |
|
|
'[[Writable]]': true
|
43 |
|
|
}
|
44 |
|
|
);
|
45 |
|
|
};
|