Get.js 562 B

1234567891011121314151617181920212223
  1. 'use strict';
  2. var $TypeError = require('es-errors/type');
  3. var inspect = require('object-inspect');
  4. var isObject = require('../helpers/isObject');
  5. var isPropertyKey = require('../helpers/isPropertyKey');
  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 (!isObject(O)) {
  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: P is not a Property Key, got ' + inspect(P));
  15. }
  16. // 7.3.1.3
  17. return O[P];
  18. };