2018-11-09 02:25:16 +03:00
|
|
|
'use strict';
|
|
|
|
|
2018-11-27 23:56:50 +03:00
|
|
|
var shims = [];
|
|
|
|
|
2018-11-09 02:25:16 +03:00
|
|
|
// Shim String.prototype.normalize
|
2018-11-09 22:36:21 +03:00
|
|
|
try {
|
2018-11-27 23:56:50 +03:00
|
|
|
var missing = [];
|
|
|
|
|
|
|
|
// Some platforms are missing certain normalization forms
|
|
|
|
var forms = ["NFD", "NFC", "NFKD", "NFKC"];
|
|
|
|
for (var i = 0; i < forms.length; i++) {
|
|
|
|
try {
|
|
|
|
"test".normalize(forms[i]);
|
|
|
|
} catch(error) {
|
|
|
|
missing.push(forms[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (missing.length) {
|
|
|
|
shims.push("String.prototype.normalize (missing: " + missing.join(", ") + ")");
|
|
|
|
throw new Error('bad normalize');
|
|
|
|
}
|
|
|
|
|
2018-11-09 22:36:21 +03:00
|
|
|
// Some platforms have a native normalize, but it is broken; so we force our shim
|
|
|
|
if (String.fromCharCode(0xe9).normalize('NFD') !== String.fromCharCode(0x65, 0x0301)) {
|
2018-11-27 23:56:50 +03:00
|
|
|
shims.push("String.prototype.normalize (broken)");
|
2018-11-09 22:36:21 +03:00
|
|
|
throw new Error('bad normalize');
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
var unorm = require('./unorm.js');
|
|
|
|
String.prototype.normalize = function(form) {
|
|
|
|
var func = unorm[(form || 'NFC').toLowerCase()];
|
|
|
|
if (!func) { throw new RangeError('invalid form - ' + form); }
|
|
|
|
return func(this);
|
|
|
|
}
|
|
|
|
}
|
2018-11-09 02:25:16 +03:00
|
|
|
|
|
|
|
// Shim atob and btoa
|
|
|
|
var base64 = require('./base64.js');
|
2018-11-27 23:56:50 +03:00
|
|
|
if (!global.atob) {
|
|
|
|
shims.push("atob");
|
|
|
|
global.atob = base64.atob;
|
|
|
|
}
|
|
|
|
if (!global.btoa) {
|
|
|
|
shims.push("btoa");
|
|
|
|
global.btoa = base64.btoa;
|
|
|
|
}
|
2018-11-09 02:25:16 +03:00
|
|
|
|
|
|
|
// Shim Promise
|
2018-11-27 23:56:50 +03:00
|
|
|
// @TODO: Check first?
|
2018-11-09 02:25:16 +03:00
|
|
|
var promise = require('./es6-promise.auto.js');
|
|
|
|
|
|
|
|
// Shim ArrayBuffer.isView
|
|
|
|
if (!ArrayBuffer.isView) {
|
2018-11-27 23:56:50 +03:00
|
|
|
shims.push("ArrayBuffer.isView");
|
2018-11-09 02:25:16 +03:00
|
|
|
ArrayBuffer.isView = function(obj) {
|
|
|
|
// @TODO: This should probably check various instanceof aswell
|
|
|
|
return !!(obj.buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Shim nextTick
|
|
|
|
if (!global.nextTick) {
|
2018-11-27 23:56:50 +03:00
|
|
|
shims.push("nextTick");
|
2018-11-09 02:25:16 +03:00
|
|
|
global.nextTick = function (callback) { setTimeout(callback, 0); }
|
|
|
|
}
|
|
|
|
|
2018-11-27 23:56:50 +03:00
|
|
|
if (shims.length) {
|
|
|
|
console.log("Shims Injected:");
|
|
|
|
for (var i = 0; i < shims.length; i++) {
|
|
|
|
console.log(' - ' + shims[i]);
|
|
|
|
}
|
|
|
|
}
|