HasOwnProperty.js 553 B

12345678910111213141516171819202122
  1. 'use strict';
  2. var GetIntrinsic = require('get-intrinsic');
  3. var $TypeError = GetIntrinsic('%TypeError%');
  4. var has = require('has');
  5. var IsPropertyKey = require('./IsPropertyKey');
  6. var Type = require('./Type');
  7. // https://ecma-international.org/ecma-262/6.0/#sec-hasownproperty
  8. module.exports = function HasOwnProperty(O, P) {
  9. if (Type(O) !== 'Object') {
  10. throw new $TypeError('Assertion failed: `O` must be an Object');
  11. }
  12. if (!IsPropertyKey(P)) {
  13. throw new $TypeError('Assertion failed: `P` must be a Property Key');
  14. }
  15. return has(O, P);
  16. };