Get.js 597 B

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