MCPcopy Create free account
hub / github.com/ampproject/amphtml / constructor

Method constructor

src/utils/log.js:125–164  ·  view source on GitHub ↗

* opt_suffix will be appended to error message to identify the type of the * error message. We can't rely on the error object to pass along the type * because some browsers do not have this param in its window.onerror API. * See: * https://blog.sentry.io/2016/01/04/client-javascript-repo

(win, levelFunc, opt_suffix = '')

Source from the content-addressed store, hash-verified

123 * @param {string=} opt_suffix
124 */
125 constructor(win, levelFunc, opt_suffix = '') {
126 /**
127 * In tests we use the main test window instead of the iframe where
128 * the tests runs because only the former is relayed to the console.
129 * @const {!Window}
130 */
131 this.win = getMode().test && win.__AMP_TEST_IFRAME ? win.parent : win;
132
133 /** @private @const {function(number, boolean):!LogLevel_Enum} */
134 this.levelFunc_ = levelFunc;
135
136 /** @private @const {!LogLevel_Enum} */
137 this.level_ = this.defaultLevel_();
138
139 /** @private @const {string} */
140 this.suffix_ = opt_suffix;
141
142 /** @private {?JsonObject} */
143 this.messages_ = null;
144
145 this.fetchExternalMessagesOnce_ = once(() => {
146 win
147 .fetch(externalMessagesSimpleTableUrl())
148 .then((response) => response.json(), noop)
149 .then((opt_messages) => {
150 if (opt_messages) {
151 this.messages_ = /** @type {!JsonObject} */ (opt_messages);
152 }
153 });
154 });
155
156 // This bound assertion function is capable of handling the format used when
157 // error/assertion messages are extracted. This logic hasn't yet been
158 // migrated to an AMP-independent form for use in core. This binding allows
159 // Log assertion helpers to maintain message-extraction capabilities until
160 // that logic can be moved to core.
161 this.boundAssertFn_ = /** @type {!assertions.AssertionFunctionDef} */ (
162 this.assert.bind(this)
163 );
164 }
165
166 /**
167 * @return {!LogLevel_Enum}

Callers

nothing calls this directly

Calls 7

defaultLevel_Method · 0.95
getModeFunction · 0.90
onceFunction · 0.90
thenMethod · 0.45
fetchMethod · 0.45
jsonMethod · 0.45

Tested by

no test coverage detected