ut2
Version:
一个现代 JavaScript 实用工具库。[点击查看在线文档]。
47 lines (43 loc) • 1.91 kB
JavaScript
;
var native = require('./native.js');
var helpers = require('./helpers.js');
var getTag = require('./getTag.js');
var dataViewExisted = typeof DataView !== native.stringUndefined;
var mapExisted = typeof Map !== native.stringUndefined;
var promiseExisted = typeof Promise !== native.stringUndefined;
var setExisted = typeof Set !== native.stringUndefined;
var weakMapExisted = typeof WeakMap !== native.stringUndefined;
var dataViewCtorString = helpers.toSource(DataView);
var mapCtorString = helpers.toSource(Map);
var promiseCtorString = helpers.toSource(Promise);
var setCtorString = helpers.toSource(Set);
var weakMapCtorString = helpers.toSource(WeakMap);
var getTagWithBugfix$1 = getTag;
if ((dataViewExisted && getTag(new DataView(new ArrayBuffer(1))) !== native.dataViewTag) ||
(mapExisted && getTag(new Map()) !== native.mapTag) ||
(promiseExisted && getTag(Promise.resolve()) !== native.promiseTag) ||
(setExisted && getTag(new Set()) !== native.setTag) ||
(weakMapExisted && getTag(new WeakMap()) !== native.weakMapTag)) {
getTagWithBugfix$1 = function (value) {
var result = getTag(value);
var Ctor = result === native.objectTag ? value.constructor : native.nativeUndefined;
var ctorString = Ctor ? helpers.toSource(Ctor) : '';
if (ctorString) {
switch (ctorString) {
case dataViewCtorString:
return native.dataViewTag;
case mapCtorString:
return native.mapTag;
case promiseCtorString:
return native.promiseTag;
case setCtorString:
return native.setTag;
case weakMapCtorString:
return native.weakMapTag;
}
}
return result;
};
}
var getTagWithBugfix = getTagWithBugfix$1;
module.exports = getTagWithBugfix;