Get.js 549 B

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