HasProperty.js 464 B

123456789101112131415161718
  1. 'use strict';
  2. var $TypeError = require('es-errors/type');
  3. var IsPropertyKey = require('./IsPropertyKey');
  4. var Type = require('./Type');
  5. // https://262.ecma-international.org/6.0/#sec-hasproperty
  6. module.exports = function HasProperty(O, P) {
  7. if (Type(O) !== 'Object') {
  8. throw new $TypeError('Assertion failed: `O` must be an Object');
  9. }
  10. if (!IsPropertyKey(P)) {
  11. throw new $TypeError('Assertion failed: `P` must be a Property Key');
  12. }
  13. return P in O;
  14. };