parent
8abdbbbf63
commit
240aac5683
64
packages/shims/dist/index.js
vendored
64
packages/shims/dist/index.js
vendored
@ -103,10 +103,12 @@
|
||||
(function (global){
|
||||
'use strict';
|
||||
|
||||
var shims = [];
|
||||
(function() {
|
||||
|
||||
// Shim String.prototype.normalize
|
||||
try {
|
||||
var shims = [];
|
||||
|
||||
// Shim String.prototype.normalize
|
||||
try {
|
||||
var missing = [];
|
||||
|
||||
// Some platforms are missing certain normalization forms
|
||||
@ -131,51 +133,45 @@ try {
|
||||
shims.push("String.prototype.normalize (broken)");
|
||||
throw new Error('bad normalize');
|
||||
}
|
||||
} catch (error) {
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Shim atob and btoa
|
||||
var base64 = require('./base64.js');
|
||||
if (!global.atob) {
|
||||
// Shim atob and btoa
|
||||
var base64 = require('./base64.js');
|
||||
if (!global.atob) {
|
||||
shims.push("atob");
|
||||
global.atob = base64.atob;
|
||||
}
|
||||
if (!global.btoa) {
|
||||
}
|
||||
if (!global.btoa) {
|
||||
shims.push("btoa");
|
||||
global.btoa = base64.btoa;
|
||||
}
|
||||
}
|
||||
|
||||
// Shim Promise
|
||||
// @TODO: Check first?
|
||||
//if (window.Promise == null) {
|
||||
// var promise = require('./es6-promise.auto.js');
|
||||
//}
|
||||
|
||||
// Shim ArrayBuffer.isView
|
||||
if (!ArrayBuffer.isView) {
|
||||
// Shim ArrayBuffer.isView
|
||||
if (!ArrayBuffer.isView) {
|
||||
shims.push("ArrayBuffer.isView");
|
||||
ArrayBuffer.isView = function(obj) {
|
||||
// @TODO: This should probably check various instanceof aswell
|
||||
return !!(obj.buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Shim nextTick
|
||||
if (!global.nextTick) {
|
||||
// Shim nextTick
|
||||
if (!global.nextTick) {
|
||||
shims.push("nextTick");
|
||||
global.nextTick = function (callback) { setTimeout(callback, 0); }
|
||||
}
|
||||
}
|
||||
|
||||
// Shim crypto.getRandomValues
|
||||
// @TOOD: Investigate: https://github.com/brix/crypto-js/issues/7
|
||||
if (!global.crypto) { global.crypto = { }; }
|
||||
if (!global.crypto.getRandomValues) {
|
||||
// Shim crypto.getRandomValues
|
||||
// @TOOD: Investigate: https://github.com/brix/crypto-js/issues/7
|
||||
if (!global.crypto) { global.crypto = { }; }
|
||||
if (!global.crypto.getRandomValues) {
|
||||
shims.push("crypto.getRandomValues");
|
||||
console.log("WARNING: This environment is missing a secure random source; generated private keys may be at risk, think VERY carefully about not adding a better secure source.");
|
||||
global.crypto.getRandomValues = function(buffer) {
|
||||
@ -184,11 +180,10 @@ if (!global.crypto.getRandomValues) {
|
||||
buffer[(start + i) % buffer.length] = Math.floor(Math.random() * 256);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Shim FileReader.readAsArrayBuffer
|
||||
// https://github.com/facebook/react-native/issues/21209
|
||||
(function() {
|
||||
// Shim FileReader.readAsArrayBuffer
|
||||
// https://github.com/facebook/react-native/issues/21209
|
||||
try {
|
||||
var fr = new FileReader();
|
||||
try {
|
||||
@ -217,14 +212,15 @@ if (!global.crypto.getRandomValues) {
|
||||
} catch (error) {
|
||||
console.log("Missing FileReader; unsupported platform");
|
||||
}
|
||||
})();
|
||||
|
||||
if (shims.length) {
|
||||
if (shims.length) {
|
||||
console.log("Shims Injected:");
|
||||
for (var i = 0; i < shims.length; i++) {
|
||||
console.log(' - ' + shims[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
})();
|
||||
|
||||
|
||||
|
||||
|
2
packages/shims/dist/index.min.js
vendored
2
packages/shims/dist/index.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user