-
Notifications
You must be signed in to change notification settings - Fork 927
/
Copy pathshims.js
122 lines (107 loc) · 3.07 KB
/
shims.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var global = global || {};
var React, ReactDOM, ReactDOMServer, setTimeout, clearTimeout;
// Basic console shim. Caches all calls to console methods.
function MockConsole() {
this._calls = [];
['log', 'error', 'warn', 'debug', 'info', 'dir', 'group', 'groupEnd', 'groupCollapsed'].forEach(function (methodName) {
this[methodName] = this._handleCall.bind(this, methodName);
}, this);
}
MockConsole.prototype = {
_handleCall: function(methodName/*, ...args*/) {
var serializedArgs = [];
for (var i = 1; i < arguments.length; i++) {
serializedArgs.push(JSON.stringify(arguments[i]));
}
this._calls.push({
method: methodName,
args: serializedArgs,
stack: '\nCall stack: ' + (new Error().stack || 'not available')
});
},
_formatCall: function(call) {
return 'console.' + call.method + '("[.NET]", ' + call.args.join(', ') + ', ' + JSON.stringify(call.stack) + ');';
},
drainCalls: function() {
var calls = this._calls.map(this._formatCall).join('\n');
this._calls = [];
return calls;
}
};
var console = new MockConsole();
if (!Object.freeze) {
Object.freeze = function() { };
}
/**
* Finds a user-supplied version of React and ensures it's exposed globally.
*
* @return {string} Comma-separated list of missing globals.
*/
function ReactNET_initReact() {
var missing = [];
if (typeof React === 'undefined') {
if (global.React) {
React = global.React;
} else {
missing.push('React');
}
}
if (typeof ReactDOM === 'undefined') {
if (global.ReactDOM) {
ReactDOM = global.ReactDOM;
} else {
missing.push('ReactDOM');
}
}
if (typeof ReactDOMServer === 'undefined') {
if (global.ReactDOMServer) {
ReactDOMServer = global.ReactDOMServer;
}
else {
missing.push('ReactDOMServer');
}
}
return missing.join(',');
}
setTimeout = setTimeout || global.setTimeout;
if (setTimeout === undefined) {
setTimeout = function() {
throw new Error('setTimeout is not supported in server-rendered Javascript.');
}
}
clearTimeout = clearTimeout || global.clearTimeout;
if (clearTimeout === undefined) {
clearTimeout = function() {
throw new Error('clearTimeout is not supported in server-rendered Javascript.');
}
}
/**
* Polyfill for engines that do not support Object.assign
*/
if (typeof Object.assign !== 'function') {
Object.assign = function (target, varArgs) { // .length of function is 2
'use strict';
if (target == null) { // TypeError if undefined or null
throw new TypeError('Cannot convert undefined or null to object');
}
var to = Object(target);
for (var index = 1; index < arguments.length; index++) {
var nextSource = arguments[index];
if (nextSource != null) { // Skip over if undefined or null
for (var nextKey in nextSource) {
// Avoid bugs when hasOwnProperty is shadowed
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
to[nextKey] = nextSource[nextKey];
}
}
}
}
return to;
};
}