Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -222,19 +222,19 @@ const noWebGlobalsRuleList = [
{ name: "window", message: "Use InjectedScript.window instead" },
{ name: "document", message: "Use InjectedScript.document instead" },
{ name: "globalThis", message: "Use InjectedScript.window instead" },
{ name: "setTimeout", message: "Use InjectedScript.builtins.setTimeout instead" },
{ name: "clearTimeout", message: "Use InjectedScript.builtins.clearTimeout instead" },
{ name: "setInterval", message: "Use InjectedScript.builtins.setInterval instead" },
{ name: "clearInterval", message: "Use InjectedScript.builtins.clearInterval instead" },
{ name: "requestAnimationFrame", message: "Use InjectedScript.builtins.requestAnimationFrame instead" },
{ name: "cancelAnimationFrame", message: "Use InjectedScript.builtins.cancelAnimationFrame instead" },
{ name: "requestIdleCallback", message: "Use InjectedScript.builtins.requestIdleCallback instead" },
{ name: "cancelIdleCallback", message: "Use InjectedScript.builtins.cancelIdleCallback instead" },
{ name: "performance", message: "Use InjectedScript.builtins.performance instead" },
{ name: "eval", message: "Use InjectedScript.builtins.eval instead" },
{ name: "Date", message: "Use InjectedScript.builtins.Date instead" },
{ name: "Map", message: "Use InjectedScript.builtins.Map instead" },
{ name: "Set", message: "Use InjectedScript.builtins.Set instead" },
{ name: "setTimeout", message: "import { setTimeout } from './builtins' instead" },
{ name: "clearTimeout", message: "import { clearTimeout } from './builtins' instead" },
{ name: "setInterval", message: "import { setInterval } from './builtins' instead" },
{ name: "clearInterval", message: "import { clearInterval } from './builtins' instead" },
{ name: "requestAnimationFrame", message: "import { requestAnimationFrame } from './builtins' instead" },
{ name: "cancelAnimationFrame", message: "import { cancelAnimationFrame } from './builtins' instead" },
{ name: "requestIdleCallback", message: "import { requestIdleCallback } from './builtins' instead" },
{ name: "cancelIdleCallback", message: "import { cancelIdleCallback } from './builtins' instead" },
{ name: "performance", message: "import { performance } from './builtins' instead" },
{ name: "eval", message: "Use builtins().eval instead" },
{ name: "Date", message: "import { Date } from './builtins' instead" },
{ name: "Map", message: "import { Map } from './builtins' instead" },
{ name: "Set", message: "import { Set } from './builtins' instead" },
];

const noNodeGlobalsRuleList = [{ name: "process" }];
Expand Down Expand Up @@ -371,8 +371,7 @@ export default [
"no-restricted-globals": [
"error",
...noNodeGlobalsRuleList,
// TODO: reenable once the violations are fixed is utils/isomorphic/*.
// ...noWebGlobalsRules,
...noWebGlobalsRuleList,
],
...noFloatingPromisesRules,
...noBooleanCompareRules,
Expand Down
30 changes: 15 additions & 15 deletions packages/injected/src/ariaSnapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
* limitations under the License.
*/

import { Map, Set } from '@isomorphic/builtins';
import { escapeRegExp, longestCommonSubstring, normalizeWhiteSpace } from '@isomorphic/stringUtils';

import { getElementComputedStyle, getGlobalOptions } from './domUtils';
import * as roleUtils from './roleUtils';
import { yamlEscapeKeyIfNeeded, yamlEscapeValueIfNeeded } from './yaml';

import type { AriaProps, AriaRegex, AriaRole, AriaTemplateNode, AriaTemplateRoleNode, AriaTemplateTextNode } from '@isomorphic/ariaSnapshot';
import type { Builtins } from '@isomorphic/builtins';

export type AriaNode = AriaProps & {
role: AriaRole | 'fragment' | 'iframe';
Expand All @@ -33,19 +33,19 @@ export type AriaNode = AriaProps & {

export type AriaSnapshot = {
root: AriaNode;
elements: Builtins.Map<number, Element>;
elements: Map<number, Element>;
generation: number;
ids: Builtins.Map<Element, number>;
ids: Map<Element, number>;
};

export function generateAriaTree(builtins: Builtins, rootElement: Element, generation: number): AriaSnapshot {
const visited = new builtins.Set<Node>();
export function generateAriaTree(rootElement: Element, generation: number): AriaSnapshot {
const visited = new Set<Node>();

const snapshot: AriaSnapshot = {
root: { role: 'fragment', name: '', children: [], element: rootElement, props: {} },
elements: new builtins.Map<number, Element>(),
elements: new Map<number, Element>(),
generation,
ids: new builtins.Map<Element, number>(),
ids: new Map<Element, number>(),
};

const addElement = (element: Element) => {
Expand Down Expand Up @@ -87,7 +87,7 @@ export function generateAriaTree(builtins: Builtins, rootElement: Element, gener
}

addElement(element);
const childAriaNode = toAriaNode(builtins, element);
const childAriaNode = toAriaNode(element);
if (childAriaNode)
ariaNode.children.push(childAriaNode);
processElement(childAriaNode || ariaNode, element, ariaChildren);
Expand Down Expand Up @@ -133,7 +133,7 @@ export function generateAriaTree(builtins: Builtins, rootElement: Element, gener
}
}

roleUtils.beginAriaCaches(builtins);
roleUtils.beginAriaCaches();
try {
visit(snapshot.root, rootElement);
} finally {
Expand All @@ -144,15 +144,15 @@ export function generateAriaTree(builtins: Builtins, rootElement: Element, gener
return snapshot;
}

function toAriaNode(builtins: Builtins, element: Element): AriaNode | null {
function toAriaNode(element: Element): AriaNode | null {
if (element.nodeName === 'IFRAME')
return { role: 'iframe', name: '', children: [], props: {}, element };

const role = roleUtils.getAriaRole(element);
if (!role || role === 'presentation' || role === 'none')
return null;

const name = normalizeWhiteSpace(roleUtils.getElementAccessibleName(builtins, element, false) || '');
const name = normalizeWhiteSpace(roleUtils.getElementAccessibleName(element, false) || '');
const result: AriaNode = { role, name, children: [], props: {}, element };

if (roleUtils.kAriaCheckedRoles.includes(role))
Expand Down Expand Up @@ -234,8 +234,8 @@ export type MatcherReceived = {
regex: string;
};

export function matchesAriaTree(builtins: Builtins, rootElement: Element, template: AriaTemplateNode): { matches: AriaNode[], received: MatcherReceived } {
const snapshot = generateAriaTree(builtins, rootElement, 0);
export function matchesAriaTree(rootElement: Element, template: AriaTemplateNode): { matches: AriaNode[], received: MatcherReceived } {
const snapshot = generateAriaTree(rootElement, 0);
const matches = matchesNodeDeep(snapshot.root, template, false, false);
return {
matches,
Expand All @@ -246,8 +246,8 @@ export function matchesAriaTree(builtins: Builtins, rootElement: Element, templa
};
}

export function getAllByAria(builtins: Builtins, rootElement: Element, template: AriaTemplateNode): Element[] {
const root = generateAriaTree(builtins, rootElement, 0).root;
export function getAllByAria(rootElement: Element, template: AriaTemplateNode): Element[] {
const root = generateAriaTree(rootElement, 0).root;
const matches = matchesNodeDeep(root, template, true, false);
return matches.map(n => n.element);
}
Expand Down
22 changes: 10 additions & 12 deletions packages/injected/src/clock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

import { ensureBuiltins } from '@isomorphic/builtins';

import type { Builtins } from '@isomorphic/builtins';
import { Map, Date } from '@isomorphic/builtins';

export type ClockMethods = {
Date: DateConstructor;
Expand All @@ -29,7 +27,7 @@ export type ClockMethods = {
};

export type ClockConfig = {
now?: number | Builtins.Date;
now?: number | Date;
};

export type InstallConfig = ClockConfig & {
Expand Down Expand Up @@ -78,16 +76,16 @@ type LogEntryType = 'fastForward' |'install' | 'pauseAt' | 'resume' | 'runFor' |
export class ClockController {
readonly _now: Time;
private _duringTick = false;
private _timers: Builtins.Map<number, Timer>;
private _timers: Map<number, Timer>;
private _uniqueTimerId = idCounterStart;
private _embedder: Embedder;
readonly disposables: (() => void)[] = [];
private _log: { type: LogEntryType, time: number, param?: number }[] = [];
private _realTime: { startTicks: EmbedderTicks, lastSyncTicks: EmbedderTicks } | undefined;
private _currentRealTimeTimer: { callAt: Ticks, dispose: () => void } | undefined;

constructor(builtins: Builtins, embedder: Embedder) {
this._timers = new builtins.Map();
constructor(embedder: Embedder) {
this._timers = new Map();
this._now = { time: asWallTime(0), isFixedTime: false, ticks: 0 as Ticks, origin: asWallTime(-1) };
this._embedder = embedder;
}
Expand Down Expand Up @@ -431,7 +429,7 @@ export class ClockController {
}
}

function mirrorDateProperties(target: any, source: DateConstructor): DateConstructor & Builtins.Date {
function mirrorDateProperties(target: any, source: DateConstructor): DateConstructor & Date {
for (const prop in source) {
if (source.hasOwnProperty(prop))
target[prop] = (source as any)[prop];
Expand All @@ -445,8 +443,8 @@ function mirrorDateProperties(target: any, source: DateConstructor): DateConstru
return target;
}

function createDate(clock: ClockController, NativeDate: DateConstructor): DateConstructor & Builtins.Date {
function ClockDate(this: typeof ClockDate, year: number, month: number, date: number, hour: number, minute: number, second: number, ms: number): Builtins.Date | string {
function createDate(clock: ClockController, NativeDate: DateConstructor): DateConstructor & Date {
function ClockDate(this: typeof ClockDate, year: number, month: number, date: number, hour: number, minute: number, second: number, ms: number): Date | string {
// the Date constructor called as a function, ref Ecma-262 Edition 5.1, section 15.9.2.
// This remains so in the 10th edition of 2019 as well.
if (!(this instanceof ClockDate))
Expand Down Expand Up @@ -695,8 +693,8 @@ export function createClock(globalObject: WindowOrWorkerGlobalScope): { clock: C
},
};

// TODO: unify ensureBuiltins and platformOriginals
const clock = new ClockController(ensureBuiltins(globalObject as any), embedder);
// TODO: unify Builtins and platformOriginals
const clock = new ClockController(embedder);
const api = createApi(clock, originals.bound);
return { clock, api, originals: originals.raw };
}
Expand Down
7 changes: 4 additions & 3 deletions packages/injected/src/highlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import { requestAnimationFrame, cancelAnimationFrame } from '@isomorphic/builtins';
import { asLocator } from '@isomorphic/locatorGenerators';
import { stringifySelector } from '@isomorphic/selectorParser';

Expand Down Expand Up @@ -100,20 +101,20 @@ export class Highlight {

runHighlightOnRaf(selector: ParsedSelector) {
if (this._rafRequest)
this._injectedScript.builtins.cancelAnimationFrame(this._rafRequest);
cancelAnimationFrame(this._rafRequest);
const elements = this._injectedScript.querySelectorAll(selector, this._injectedScript.document.documentElement);
const locator = asLocator(this._language, stringifySelector(selector));
const color = elements.length > 1 ? '#f6b26b7f' : '#6fa8dc7f';
this.updateHighlight(elements.map((element, index) => {
const suffix = elements.length > 1 ? ` [${index + 1} of ${elements.length}]` : '';
return { element, color, tooltipText: locator + suffix };
}));
this._rafRequest = this._injectedScript.builtins.requestAnimationFrame(() => this.runHighlightOnRaf(selector));
this._rafRequest = requestAnimationFrame(() => this.runHighlightOnRaf(selector));
}

uninstall() {
if (this._rafRequest)
this._injectedScript.builtins.cancelAnimationFrame(this._rafRequest);
cancelAnimationFrame(this._rafRequest);
this._glassPaneElement.remove();
}

Expand Down
Loading
Loading