1414 * limitations under the License.
1515 */
1616
17- import { ExpansionOptions , variableServiceFor } from './variables' ;
17+ import { ExpansionOptions , variableServiceForDoc } from './variables' ;
1818import { findIndex } from '../../../src/utils/array' ;
1919import { isObject } from '../../../src/types' ;
2020import { parseUrlDeprecated } from '../../../src/url' ;
@@ -233,14 +233,14 @@ function filterEntries(entries, resourceDefs) {
233233 * single string.
234234 * @param {!Array<!PerformanceResourceTiming> } entries
235235 * @param {!JsonObject } resourceTimingSpec
236- * @param {!Window } win
236+ * @param {!../../../src/service/ampdoc-impl.AmpDoc } ampdoc
237237 * @return {!Promise<string> }
238238 */
239- function serialize ( entries , resourceTimingSpec , win ) {
239+ function serialize ( entries , resourceTimingSpec , ampdoc ) {
240240 const resources = resourceTimingSpec [ 'resources' ] ;
241241 const encoding = resourceTimingSpec [ 'encoding' ] ;
242242
243- const variableService = variableServiceFor ( win ) ;
243+ const variableService = variableServiceForDoc ( ampdoc ) ;
244244 const format = ( val , relativeTo = 0 ) =>
245245 Math . round ( val - relativeTo ) . toString ( encoding [ 'base' ] || 10 ) ;
246246
@@ -255,11 +255,12 @@ function serialize(entries, resourceTimingSpec, win) {
255255
256256/**
257257 * Serializes resource timing entries according to the resource timing spec.
258- * @param {!Window } win
258+ * @param {!../../../src/service/ampdoc-impl.AmpDoc } ampdoc
259259 * @param {!JsonObject } resourceTimingSpec
260260 * @return {!Promise<string> }
261261 */
262- function serializeResourceTiming ( win , resourceTimingSpec ) {
262+ function serializeResourceTiming ( ampdoc , resourceTimingSpec ) {
263+ const { win} = ampdoc ;
263264 // Check that the performance timing API exists before and that the spec is
264265 // valid before proceeding. If not, we simply return an empty string.
265266 if ( resourceTimingSpec [ 'done' ] || ! win . performance || ! win . performance . now ||
@@ -287,19 +288,19 @@ function serializeResourceTiming(win, resourceTimingSpec) {
287288 return Promise . resolve ( '' ) ;
288289 }
289290 // Yield the thread in case iterating over all resources takes a long time.
290- return yieldThread ( ( ) => serialize ( entries , resourceTimingSpec , win ) ) ;
291+ return yieldThread ( ( ) => serialize ( entries , resourceTimingSpec , ampdoc ) ) ;
291292}
292293
293294/**
294- * @param {!Window } win resource timing spec.
295+ * @param {!../../../src/service/ampdoc-impl.AmpDoc } ampdoc
295296 * @param {!JsonObject|undefined } spec resource timing spec.
296297 * @param {number } startTime start timestamp.
297298 * @return {!Promise<string> }
298299 */
299- export function getResourceTiming ( win , spec , startTime ) {
300+ export function getResourceTiming ( ampdoc , spec , startTime ) {
300301 // Only allow collecting timing within 1s
301302 if ( spec && ( Date . now ( ) < ( startTime + 60 * 1000 ) ) ) {
302- return serializeResourceTiming ( win , spec ) ;
303+ return serializeResourceTiming ( ampdoc , spec ) ;
303304 } else {
304305 return Promise . resolve ( '' ) ;
305306 }
0 commit comments