OrdinaryHasInstance.js 613 B

12345678910111213141516171819202122232425
  1. 'use strict';
  2. var GetIntrinsic = require('get-intrinsic');
  3. var $TypeError = GetIntrinsic('%TypeError%');
  4. var Get = require('./Get');
  5. var IsCallable = require('./IsCallable');
  6. var Type = require('./Type');
  7. // https://262.ecma-international.org/6.0/#sec-ordinaryhasinstance
  8. module.exports = function OrdinaryHasInstance(C, O) {
  9. if (!IsCallable(C)) {
  10. return false;
  11. }
  12. if (Type(O) !== 'Object') {
  13. return false;
  14. }
  15. var P = Get(C, 'prototype');
  16. if (Type(P) !== 'Object') {
  17. throw new $TypeError('OrdinaryHasInstance called on an object with an invalid prototype property.');
  18. }
  19. return O instanceof C;
  20. };