11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common.js');
31cb0ef41Sopenharmony_ciconst url = require('url');
41cb0ef41Sopenharmony_ciconst URL = url.URL;
51cb0ef41Sopenharmony_ciconst assert = require('assert');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciconst bench = common.createBenchmark(main, {
81cb0ef41Sopenharmony_ci  withBase: ['true', 'false'],
91cb0ef41Sopenharmony_ci  type: common.urlDataTypes,
101cb0ef41Sopenharmony_ci  e: [1],
111cb0ef41Sopenharmony_ci});
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_cifunction useWHATWGWithBase(data) {
141cb0ef41Sopenharmony_ci  const len = data.length;
151cb0ef41Sopenharmony_ci  let result = new URL(data[0][0], data[0][1]);  // Avoid dead code elimination
161cb0ef41Sopenharmony_ci  bench.start();
171cb0ef41Sopenharmony_ci  for (let i = 0; i < len; ++i) {
181cb0ef41Sopenharmony_ci    const item = data[i];
191cb0ef41Sopenharmony_ci    result = new URL(item[0], item[1]);
201cb0ef41Sopenharmony_ci  }
211cb0ef41Sopenharmony_ci  bench.end(len);
221cb0ef41Sopenharmony_ci  return result;
231cb0ef41Sopenharmony_ci}
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_cifunction useWHATWGWithoutBase(data) {
261cb0ef41Sopenharmony_ci  const len = data.length;
271cb0ef41Sopenharmony_ci  let result = new URL(data[0]);  // Avoid dead code elimination
281cb0ef41Sopenharmony_ci  bench.start();
291cb0ef41Sopenharmony_ci  for (let i = 0; i < len; ++i) {
301cb0ef41Sopenharmony_ci    result = new URL(data[i]);
311cb0ef41Sopenharmony_ci  }
321cb0ef41Sopenharmony_ci  bench.end(len);
331cb0ef41Sopenharmony_ci  return result;
341cb0ef41Sopenharmony_ci}
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_cifunction main({ e, type, withBase }) {
371cb0ef41Sopenharmony_ci  withBase = withBase === 'true';
381cb0ef41Sopenharmony_ci  const data = common.bakeUrlData(type, e, withBase, false);
391cb0ef41Sopenharmony_ci  const noDead = withBase ? useWHATWGWithBase(data) : useWHATWGWithoutBase(data);
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ci  assert.ok(noDead);
421cb0ef41Sopenharmony_ci}
43