1 |
3a515b92
|
cagy
|
'use strict';
|
2 |
|
|
|
3 |
|
|
var GetIntrinsic = require('../GetIntrinsic');
|
4 |
|
|
|
5 |
|
|
var $gOPD = require('../helpers/getOwnPropertyDescriptor');
|
6 |
|
|
var $TypeError = GetIntrinsic('%TypeError%');
|
7 |
|
|
|
8 |
|
|
var callBound = require('../helpers/callBound');
|
9 |
|
|
|
10 |
|
|
var $isEnumerable = callBound('Object.prototype.propertyIsEnumerable');
|
11 |
|
|
|
12 |
|
|
var has = require('has');
|
13 |
|
|
|
14 |
|
|
var IsArray = require('./IsArray');
|
15 |
|
|
var IsPropertyKey = require('./IsPropertyKey');
|
16 |
|
|
var IsRegExp = require('./IsRegExp');
|
17 |
|
|
var ToPropertyDescriptor = require('./ToPropertyDescriptor');
|
18 |
|
|
var Type = require('./Type');
|
19 |
|
|
|
20 |
|
|
// https://www.ecma-international.org/ecma-262/6.0/#sec-ordinarygetownproperty
|
21 |
|
|
|
22 |
|
|
module.exports = function OrdinaryGetOwnProperty(O, P) {
|
23 |
|
|
if (Type(O) !== 'Object') {
|
24 |
|
|
throw new $TypeError('Assertion failed: O must be an Object');
|
25 |
|
|
}
|
26 |
|
|
if (!IsPropertyKey(P)) {
|
27 |
|
|
throw new $TypeError('Assertion failed: P must be a Property Key');
|
28 |
|
|
}
|
29 |
|
|
if (!has(O, P)) {
|
30 |
|
|
return void 0;
|
31 |
|
|
}
|
32 |
|
|
if (!$gOPD) {
|
33 |
|
|
// ES3 / IE 8 fallback
|
34 |
|
|
var arrayLength = IsArray(O) && P === 'length';
|
35 |
|
|
var regexLastIndex = IsRegExp(O) && P === 'lastIndex';
|
36 |
|
|
return {
|
37 |
|
|
'[[Configurable]]': !(arrayLength || regexLastIndex),
|
38 |
|
|
'[[Enumerable]]': $isEnumerable(O, P),
|
39 |
|
|
'[[Value]]': O[P],
|
40 |
|
|
'[[Writable]]': true
|
41 |
|
|
};
|
42 |
|
|
}
|
43 |
|
|
return ToPropertyDescriptor($gOPD(O, P));
|
44 |
|
|
};
|