OrdinaryHasInstance.js 565 B

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