You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Get.js 734B

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