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.

OrdinaryHasInstance.js 633B

12345678910111213141516171819202122232425
  1. 'use strict';
  2. var GetIntrinsic = require('../GetIntrinsic');
  3. var $TypeError = GetIntrinsic('%TypeError%');
  4. var Get = require('./Get');
  5. var IsCallable = require('./IsCallable');
  6. var Type = require('./Type');
  7. // https://www.ecma-international.org/ecma-262/6.0/#sec-ordinaryhasinstance
  8. module.exports = function OrdinaryHasInstance(C, O) {
  9. if (IsCallable(C) === false) {
  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. };