Skip to content

Commit

Permalink
refactor: removed IE leftovers from src\client\core\utils (part 1) (#…
Browse files Browse the repository at this point in the history
…7998)

<!--
Thank you for your contribution.

Before making a PR, please read our contributing guidelines at

https://github.com/DevExpress/testcafe/blob/master/CONTRIBUTING.md#code-contribution

We recommend creating a *draft* PR, so that you can mark it as 'ready
for review' when you are done.
-->

## Purpose
_Describe the problem you want to address or the feature you want to
implement._

## Approach
_Describe how your changes address the issue or implement the desired
functionality in as much detail as possible._

## References
_Provide a link to the existing issue(s), if any._

## Pre-Merge TODO
- [ ] Write tests for your proposed changes
- [ ] Make sure that existing tests do not fail
  • Loading branch information
Aleksey28 authored Sep 12, 2023
1 parent 056b9e8 commit 444e02d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 59 deletions.
25 changes: 2 additions & 23 deletions src/client/core/utils/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,11 @@ export function isArray (arg) {
}

export function from (arg, ...args) {
if (nativeMethods.arrayFrom)
return nativeMethods.arrayFrom(arg, ...args);

// NOTE: this logic is for IE
const arr = [];
const length = arg.length;

for (let i = 0; i < length; i++)
arr.push(arg[i]);

return arr;
return nativeMethods.arrayFrom(arg, ...args);
}

export function find (arr, callback) {
if (nativeMethods.arrayFind)
return nativeMethods.arrayFind.call(arr, callback);

// NOTE: this logic is for IE
const length = arr.length;

for (let i = 0; i < length; i++) {
if (callback(arr[i], i, arr))
return arr[i];
}

return null;
return nativeMethods.arrayFind.call(arr, callback);
}

export function remove (arr, item) {
Expand Down
18 changes: 5 additions & 13 deletions src/client/core/utils/content-editable.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,23 +285,15 @@ export function getNearestCommonAncestor (node1, node2) {

//selection utils
function getSelectedPositionInParentByOffset (node, offset) {
let currentNode = null;
let currentOffset = null;
const childNodes = nativeMethods.nodeChildNodesGetter.call(node);
const childCount = domUtils.getChildNodesLength(childNodes);
let isSearchForLastChild = offset >= childCount;

// NOTE: we get a child element by its offset index in the parent
if (domUtils.isShadowUIElement(node))
return { node, offset };

// NOTE: IE behavior
if (isSearchForLastChild)
currentNode = childNodes[childCount - 1];
else {
currentNode = childNodes[offset];
currentOffset = 0;
}
const childNodes = nativeMethods.nodeChildNodesGetter.call(node);
const childCount = domUtils.getChildNodesLength(childNodes);
let isSearchForLastChild = offset >= childCount;
let currentNode = childNodes[offset];
let currentOffset = 0;

// NOTE: skip shadowUI elements
if (domUtils.isShadowUIElement(currentNode)) {
Expand Down
16 changes: 2 additions & 14 deletions src/client/core/utils/event-emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,7 @@ export default class EventEmitter {
if (!listeners)
return;

for (let i = 0; i < listeners.length; i++) {
try {
listeners[i].apply(this, args);
}
catch (e: any) {
// Hack for IE: after document.write calling IFrameSandbox event handlers
// rises 'Can't execute code from a freed script' exception because document has been
// recreated
if (e.message && e.message.indexOf('freed script') > -1)
this.off(evt, listeners[i]);
else
throw e;
}
}
for (let i = 0; i < listeners.length; i++)
listeners[i].apply(this, args);
}
}
11 changes: 2 additions & 9 deletions src/client/core/utils/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import * as domUtils from './dom';
const Promise = hammerhead.Promise;
const nativeMethods = hammerhead.nativeMethods;
const listeners = hammerhead.eventSandbox.listeners;
const browserUtils = hammerhead.utils.browser;

// Imported form the hammerhead
export const BUTTON = hammerhead.utils.event.BUTTON;
Expand All @@ -17,17 +16,11 @@ export const WHICH_PARAMETER = hammerhead.utils.event.WHICH_PARAMETER;
export const preventDefault = hammerhead.utils.event.preventDefault;

export function bind (el, event, handler, useCapture) {
if (browserUtils.isIE11 && domUtils.isWindow(el))
nativeMethods.windowAddEventListener.call(el, event, handler, useCapture);
else
nativeMethods.addEventListener.call(el, event, handler, useCapture);
nativeMethods.addEventListener.call(el, event, handler, useCapture);
}

export function unbind (el, event, handler, useCapture) {
if (browserUtils.isIE11 && domUtils.isWindow(el))
nativeMethods.windowRemoveEventListener.call(el, event, handler, useCapture);
else
nativeMethods.removeEventListener.call(el, event, handler, useCapture);
nativeMethods.removeEventListener.call(el, event, handler, useCapture);
}


Expand Down

0 comments on commit 444e02d

Please sign in to comment.