Skip to content

Commit 54772f7

Browse files
author
Nick Maher
committed
Remove reference to window in react server builds
Replacing window with global enables the removal of the window object shim in ExecJS render
1 parent ad10895 commit 54772f7

File tree

10 files changed

+268
-919
lines changed

10 files changed

+268
-919
lines changed

lib/assets/react-source/development-with-addons/react-server.js

Lines changed: 61 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,14 @@
4444
/* 0 */
4545
/***/ function(module, exports, __webpack_require__) {
4646

47-
var React = __webpack_require__(1);
48-
var ReactDOM = __webpack_require__(35);
47+
/* WEBPACK VAR INJECTION */(function(global) {var React = __webpack_require__(1);
4948
var ReactDOMServer = __webpack_require__(199);
5049

5150
React.addons = __webpack_require__(175);
5251

53-
window.React = React;
54-
window.ReactDOM = ReactDOM;
55-
window.ReactDOMServer = ReactDOMServer;
56-
52+
global.React = React;
53+
global.ReactDOMServer = ReactDOMServer;
54+
/* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
5755

5856
/***/ },
5957
/* 1 */
@@ -174,27 +172,42 @@
174172
var cachedSetTimeout;
175173
var cachedClearTimeout;
176174

175+
function defaultSetTimout() {
176+
throw new Error('setTimeout has not been defined');
177+
}
178+
function defaultClearTimeout () {
179+
throw new Error('clearTimeout has not been defined');
180+
}
177181
(function () {
178182
try {
179-
cachedSetTimeout = setTimeout;
180-
} catch (e) {
181-
cachedSetTimeout = function () {
182-
throw new Error('setTimeout is not defined');
183+
if (typeof setTimeout === 'function') {
184+
cachedSetTimeout = setTimeout;
185+
} else {
186+
cachedSetTimeout = defaultSetTimout;
183187
}
188+
} catch (e) {
189+
cachedSetTimeout = defaultSetTimout;
184190
}
185191
try {
186-
cachedClearTimeout = clearTimeout;
187-
} catch (e) {
188-
cachedClearTimeout = function () {
189-
throw new Error('clearTimeout is not defined');
192+
if (typeof clearTimeout === 'function') {
193+
cachedClearTimeout = clearTimeout;
194+
} else {
195+
cachedClearTimeout = defaultClearTimeout;
190196
}
197+
} catch (e) {
198+
cachedClearTimeout = defaultClearTimeout;
191199
}
192200
} ())
193201
function runTimeout(fun) {
194202
if (cachedSetTimeout === setTimeout) {
195203
//normal enviroments in sane situations
196204
return setTimeout(fun, 0);
197205
}
206+
// if setTimeout wasn't available but was latter defined
207+
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
208+
cachedSetTimeout = setTimeout;
209+
return setTimeout(fun, 0);
210+
}
198211
try {
199212
// when when somebody has screwed with setTimeout but no I.E. maddness
200213
return cachedSetTimeout(fun, 0);
@@ -215,6 +228,11 @@
215228
//normal enviroments in sane situations
216229
return clearTimeout(marker);
217230
}
231+
// if clearTimeout wasn't available but was latter defined
232+
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
233+
cachedClearTimeout = clearTimeout;
234+
return clearTimeout(marker);
235+
}
218236
try {
219237
// when when somebody has screwed with setTimeout but no I.E. maddness
220238
return cachedClearTimeout(marker);
@@ -1266,20 +1284,12 @@
12661284
var warning = emptyFunction;
12671285

12681286
if (process.env.NODE_ENV !== 'production') {
1269-
warning = function warning(condition, format) {
1270-
for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
1271-
args[_key - 2] = arguments[_key];
1272-
}
1273-
1274-
if (format === undefined) {
1275-
throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument');
1276-
}
1277-
1278-
if (format.indexOf('Failed Composite propType: ') === 0) {
1279-
return; // Ignore CompositeComponent proptype check.
1280-
}
1287+
(function () {
1288+
var printWarning = function printWarning(format) {
1289+
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1290+
args[_key - 1] = arguments[_key];
1291+
}
12811292

1282-
if (!condition) {
12831293
var argIndex = 0;
12841294
var message = 'Warning: ' + format.replace(/%s/g, function () {
12851295
return args[argIndex++];
@@ -1293,8 +1303,26 @@
12931303
// to find the callsite that caused this warning to fire.
12941304
throw new Error(message);
12951305
} catch (x) {}
1296-
}
1297-
};
1306+
};
1307+
1308+
warning = function warning(condition, format) {
1309+
if (format === undefined) {
1310+
throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument');
1311+
}
1312+
1313+
if (format.indexOf('Failed Composite propType: ') === 0) {
1314+
return; // Ignore CompositeComponent proptype check.
1315+
}
1316+
1317+
if (!condition) {
1318+
for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
1319+
args[_key2 - 2] = arguments[_key2];
1320+
}
1321+
1322+
printWarning.apply(undefined, [format].concat(args));
1323+
}
1324+
};
1325+
})();
12981326
}
12991327

13001328
module.exports = warning;
@@ -4135,15 +4163,7 @@
41354163
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(3)))
41364164

41374165
/***/ },
4138-
/* 35 */
4139-
/***/ function(module, exports, __webpack_require__) {
4140-
4141-
'use strict';
4142-
4143-
module.exports = __webpack_require__(36);
4144-
4145-
4146-
/***/ },
4166+
/* 35 */,
41474167
/* 36 */
41484168
/***/ function(module, exports, __webpack_require__) {
41494169

@@ -10429,7 +10449,7 @@
1042910449
* @return {boolean}
1043010450
*/
1043110451
function hasArrayNature(obj) {
10432-
return(
10452+
return (
1043310453
// not null/false
1043410454
!!obj && (
1043510455
// arrays are objects, NodeLists are functions in Safari
@@ -16274,7 +16294,8 @@
1627416294
if (x === y) {
1627516295
// Steps 1-5, 7-10
1627616296
// Steps 6.b-6.e: +0 != -0
16277-
return x !== 0 || 1 / x === 1 / y;
16297+
// Added the nonzero y check to make Flow happy, but it is redundant
16298+
return x !== 0 || y !== 0 || 1 / x === 1 / y;
1627816299
} else {
1627916300
// Step 6.a: NaN == NaN
1628016301
return x !== x && y !== y;

lib/assets/react-source/development-with-addons/react.js

Lines changed: 56 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -173,27 +173,42 @@
173173
var cachedSetTimeout;
174174
var cachedClearTimeout;
175175

176+
function defaultSetTimout() {
177+
throw new Error('setTimeout has not been defined');
178+
}
179+
function defaultClearTimeout () {
180+
throw new Error('clearTimeout has not been defined');
181+
}
176182
(function () {
177183
try {
178-
cachedSetTimeout = setTimeout;
179-
} catch (e) {
180-
cachedSetTimeout = function () {
181-
throw new Error('setTimeout is not defined');
184+
if (typeof setTimeout === 'function') {
185+
cachedSetTimeout = setTimeout;
186+
} else {
187+
cachedSetTimeout = defaultSetTimout;
182188
}
189+
} catch (e) {
190+
cachedSetTimeout = defaultSetTimout;
183191
}
184192
try {
185-
cachedClearTimeout = clearTimeout;
186-
} catch (e) {
187-
cachedClearTimeout = function () {
188-
throw new Error('clearTimeout is not defined');
193+
if (typeof clearTimeout === 'function') {
194+
cachedClearTimeout = clearTimeout;
195+
} else {
196+
cachedClearTimeout = defaultClearTimeout;
189197
}
198+
} catch (e) {
199+
cachedClearTimeout = defaultClearTimeout;
190200
}
191201
} ())
192202
function runTimeout(fun) {
193203
if (cachedSetTimeout === setTimeout) {
194204
//normal enviroments in sane situations
195205
return setTimeout(fun, 0);
196206
}
207+
// if setTimeout wasn't available but was latter defined
208+
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
209+
cachedSetTimeout = setTimeout;
210+
return setTimeout(fun, 0);
211+
}
197212
try {
198213
// when when somebody has screwed with setTimeout but no I.E. maddness
199214
return cachedSetTimeout(fun, 0);
@@ -214,6 +229,11 @@
214229
//normal enviroments in sane situations
215230
return clearTimeout(marker);
216231
}
232+
// if clearTimeout wasn't available but was latter defined
233+
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
234+
cachedClearTimeout = clearTimeout;
235+
return clearTimeout(marker);
236+
}
217237
try {
218238
// when when somebody has screwed with setTimeout but no I.E. maddness
219239
return cachedClearTimeout(marker);
@@ -1265,20 +1285,12 @@
12651285
var warning = emptyFunction;
12661286

12671287
if (process.env.NODE_ENV !== 'production') {
1268-
warning = function warning(condition, format) {
1269-
for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
1270-
args[_key - 2] = arguments[_key];
1271-
}
1272-
1273-
if (format === undefined) {
1274-
throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument');
1275-
}
1276-
1277-
if (format.indexOf('Failed Composite propType: ') === 0) {
1278-
return; // Ignore CompositeComponent proptype check.
1279-
}
1288+
(function () {
1289+
var printWarning = function printWarning(format) {
1290+
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1291+
args[_key - 1] = arguments[_key];
1292+
}
12801293

1281-
if (!condition) {
12821294
var argIndex = 0;
12831295
var message = 'Warning: ' + format.replace(/%s/g, function () {
12841296
return args[argIndex++];
@@ -1292,8 +1304,26 @@
12921304
// to find the callsite that caused this warning to fire.
12931305
throw new Error(message);
12941306
} catch (x) {}
1295-
}
1296-
};
1307+
};
1308+
1309+
warning = function warning(condition, format) {
1310+
if (format === undefined) {
1311+
throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument');
1312+
}
1313+
1314+
if (format.indexOf('Failed Composite propType: ') === 0) {
1315+
return; // Ignore CompositeComponent proptype check.
1316+
}
1317+
1318+
if (!condition) {
1319+
for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
1320+
args[_key2 - 2] = arguments[_key2];
1321+
}
1322+
1323+
printWarning.apply(undefined, [format].concat(args));
1324+
}
1325+
};
1326+
})();
12971327
}
12981328

12991329
module.exports = warning;
@@ -10428,7 +10458,7 @@
1042810458
* @return {boolean}
1042910459
*/
1043010460
function hasArrayNature(obj) {
10431-
return(
10461+
return (
1043210462
// not null/false
1043310463
!!obj && (
1043410464
// arrays are objects, NodeLists are functions in Safari
@@ -16273,7 +16303,8 @@
1627316303
if (x === y) {
1627416304
// Steps 1-5, 7-10
1627516305
// Steps 6.b-6.e: +0 != -0
16276-
return x !== 0 || 1 / x === 1 / y;
16306+
// Added the nonzero y check to make Flow happy, but it is redundant
16307+
return x !== 0 || y !== 0 || 1 / x === 1 / y;
1627716308
} else {
1627816309
// Step 6.a: NaN == NaN
1627916310
return x !== x && y !== y;

0 commit comments

Comments
 (0)