This repository was archived by the owner on Mar 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpolymer-onerror.html
More file actions
126 lines (110 loc) · 3.4 KB
/
polymer-onerror.html
File metadata and controls
126 lines (110 loc) · 3.4 KB
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
123
124
125
126
<!--
@license
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<!--
Optional file to load after polymer.html that adds a `Polymer.onerror` handler
(similar to window.onerror) that will be called when any error is thrown from
Polymer code entry points. Usage:
<link rel="import" href="components/polymer/polymer.html">
<link rel="import" href="components/polymer-experiments/polymer-onerror.html">
<script>
Polymer.onerror = function(e) {
MyErrorReporter.reportError(e);
throw e;
}
</script>
NOTE: If `Polymer.onerror` is defined, it is the implementor's responsibility to
re-throw the error if uncaught errors on the console are desired.
-->
<script>
(function() {
function onError(e) {
if (window.Polymer.onerror) {
window.Polymer.onerror(e);
} else {
throw e;
}
}
var createdCallback = Polymer.Base.createdCallback;
Polymer.Base.createdCallback = function() {
try {
createdCallback.apply(this, arguments);
} catch(e) {
onError(e);
}
};
var attachedCallback = Polymer.Base.attachedCallback;
Polymer.Base.attachedCallback = function() {
try {
attachedCallback.apply(this, arguments);
} catch(e) {
onError(e);
}
};
var detachedCallback = Polymer.Base.detachedCallback;
Polymer.Base.detachedCallback = function() {
try {
detachedCallback.apply(this, arguments);
} catch(e) {
onError(e);
}
};
var attributeChangedCallback = Polymer.Base.attributeChangedCallback;
Polymer.Base.attributeChangedCallback = function() {
try {
attributeChangedCallback.apply(this, arguments);
} catch(e) {
onError(e);
}
};
var listen = Polymer.Base._listen;
var listenMap = new WeakMap();
Polymer.Base._listen = function(node, eventName, handler) {
var safeHandler = function() {
try {
handler.apply(this, arguments);
} catch(e) {
onError(e);
}
};
listenMap.set(handler, safeHandler);
listen.call(this, node, eventName, safeHandler);
};
var unlisten = Polymer.Base._unlisten;
Polymer.Base._unlisten = function(node, eventName, handler) {
unlisten.call(this, node, eventName, listenMap.get(handler));
};
var atEndOfMicrotask = Polymer.Async._atEndOfMicrotask;
Polymer.Async._atEndOfMicrotask = function() {
try {
atEndOfMicrotask.apply(Polymer.Async, arguments);
} catch(e) {
onError(e);
}
};
var renderStatusMakeReady = Polymer.RenderStatus._makeReady;
Polymer.RenderStatus._makeReady = function() {
try {
renderStatusMakeReady.apply(Polymer.RenderStatus, arguments);
} catch(e) {
onError(e);
}
};
var polymerWarn = Polymer.Base._warn;
Polymer.Base._warn = function(msg) {
polymerWarn.apply(Polymer.Base, arguments);
onError(new Error(msg));
};
var polymerError = Polymer.Base._error;
Polymer.Base._error = function(msg) {
polymerError.apply(Polymer.Base, arguments);
onError(new Error(msg));
};
})();
</script>