1
|
'use strict';
|
2
|
|
3
|
var GetIntrinsic = require('../GetIntrinsic');
|
4
|
|
5
|
var $TypeError = GetIntrinsic('%TypeError%');
|
6
|
|
7
|
var inspect = require('object-inspect');
|
8
|
|
9
|
var IsPropertyKey = require('./IsPropertyKey');
|
10
|
var Type = require('./Type');
|
11
|
|
12
|
/**
|
13
|
* 7.3.1 Get (O, P) - https://ecma-international.org/ecma-262/6.0/#sec-get-o-p
|
14
|
* 1. Assert: Type(O) is Object.
|
15
|
* 2. Assert: IsPropertyKey(P) is true.
|
16
|
* 3. Return O.[[Get]](P, O).
|
17
|
*/
|
18
|
|
19
|
module.exports = function Get(O, P) {
|
20
|
// 7.3.1.1
|
21
|
if (Type(O) !== 'Object') {
|
22
|
throw new $TypeError('Assertion failed: Type(O) is not Object');
|
23
|
}
|
24
|
// 7.3.1.2
|
25
|
if (!IsPropertyKey(P)) {
|
26
|
throw new $TypeError('Assertion failed: IsPropertyKey(P) is not true, got ' + inspect(P));
|
27
|
}
|
28
|
// 7.3.1.3
|
29
|
return O[P];
|
30
|
};
|