blob: 681055a2fabc3f053ac39da57834b679481615d2 [file] [log] [blame]
Leo Repp58b9f112021-11-22 11:57:47 +01001'use strict';
2
3var GetIntrinsic = require('get-intrinsic');
4
5var $TypeError = GetIntrinsic('%TypeError%');
6
7var inspect = require('object-inspect');
8
9var IsPropertyKey = require('./IsPropertyKey');
10var 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
19module.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};