1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | 'use strict';
|
13 |
|
14 | var caughtError = null;
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | function invokeGuardedCallback(name, func, a) {
|
25 | try {
|
26 | func(a);
|
27 | } catch (x) {
|
28 | if (caughtError === null) {
|
29 | caughtError = x;
|
30 | }
|
31 | }
|
32 | }
|
33 |
|
34 | var ReactErrorUtils = {
|
35 | invokeGuardedCallback: invokeGuardedCallback,
|
36 |
|
37 | |
38 |
|
39 |
|
40 |
|
41 | invokeGuardedCallbackWithCatch: invokeGuardedCallback,
|
42 |
|
43 | |
44 |
|
45 |
|
46 |
|
47 | rethrowCaughtError: function () {
|
48 | if (caughtError) {
|
49 | var error = caughtError;
|
50 | caughtError = null;
|
51 | throw error;
|
52 | }
|
53 | }
|
54 | };
|
55 |
|
56 | if (process.env.NODE_ENV !== 'production') {
|
57 | |
58 |
|
59 |
|
60 |
|
61 | if (typeof window !== 'undefined' && typeof window.dispatchEvent === 'function' && typeof document !== 'undefined' && typeof document.createEvent === 'function') {
|
62 | var fakeNode = document.createElement('react');
|
63 | ReactErrorUtils.invokeGuardedCallback = function (name, func, a) {
|
64 | var boundFunc = func.bind(null, a);
|
65 | var evtType = 'react-' + name;
|
66 | fakeNode.addEventListener(evtType, boundFunc, false);
|
67 | var evt = document.createEvent('Event');
|
68 | evt.initEvent(evtType, false, false);
|
69 | fakeNode.dispatchEvent(evt);
|
70 | fakeNode.removeEventListener(evtType, boundFunc, false);
|
71 | };
|
72 | }
|
73 | }
|
74 |
|
75 | module.exports = ReactErrorUtils; |
\ | No newline at end of file |