| 1 |
// Temporary fix for https://github.com/Gozala/test-commonjs/pull/8 |
| 2 |
|
| 3 |
"use strict"; |
| 4 |
|
| 5 |
var utils = require("test/utils"); |
| 6 |
|
| 7 |
var instanceOf; |
| 8 |
|
| 9 |
try { |
| 10 |
if (utils.instanceOf) utils.instanceOf(Object.create(null), Date); |
| 11 |
} catch (e) { |
| 12 |
instanceOf = utils.instanceOf = function (value, Type) { |
| 13 |
var valueConstructor |
| 14 |
, isConstructorNameSame |
| 15 |
, isConstructorSourceSame |
| 16 |
, isInstanceOf = value instanceof Type; |
| 17 |
|
| 18 |
if (!isInstanceOf && value) { |
| 19 |
valueConstructor = value.constructor; |
| 20 |
isConstructorNameSame = valueConstructor && valueConstructor.name === Type.name; |
| 21 |
isConstructorSourceSame = String(valueConstructor) === String(Type); |
| 22 |
isInstanceOf = |
| 23 |
(isConstructorNameSame && isConstructorSourceSame) || |
| 24 |
instanceOf(Object.getPrototypeOf(value), Type); |
| 25 |
} |
| 26 |
return isInstanceOf; |
| 27 |
}; |
| 28 |
|
| 29 |
utils.isDate = function (value) { return utils.isObject(value) && instanceOf(value, Date); }; |
| 30 |
|
| 31 |
utils.isRegExp = function (value) { return instanceOf(value, RegExp); }; |
| 32 |
} |