Skip to content
Permalink
Browse files

fix linter errors

  • Loading branch information...
acconrad committed May 19, 2019
1 parent 28a3567 commit 1335cdd2aa1274524c9fa991958a60f26f2c61fa
Showing with 111 additions and 86 deletions.
  1. +23 −86 js/event_target.ts
  2. +88 −0 js/util.ts
@@ -1,7 +1,25 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import * as domTypes from "./dom_types";
import { DenoError, ErrorKind } from "./errors";
import { requiredArguments, hasOwnProperty } from "./util";
import {
getRoot,
hasOwnProperty,
isNode,
isShadowRoot,
isShadowInclusiveAncestor,
isSlotable,
requiredArguments,
retarget
} from "./util";

// https://dom.spec.whatwg.org/#get-the-parent
// Note: Nodes, shadow roots, and documents override this algorithm so we set it to null.
function getEventTargetParent(
eventTarget: domTypes.EventTarget,
event: domTypes.Event
): null {
return null;
}

export class EventListenerOptions implements domTypes.EventListenerOptions {
_capture = false;
@@ -189,7 +207,10 @@ export class EventTarget implements domTypes.EventTarget {
}

// https://dom.spec.whatwg.org/#concept-event-dispatch
_dispatch(eventImpl: domTypes.Event, targetOverride?: domTypes.EventTarget) {
_dispatch(
eventImpl: domTypes.Event,
targetOverride?: domTypes.EventTarget
): boolean {
let targetImpl = this;
let clearTargets = false;
let activationTarget = null;
@@ -510,90 +531,6 @@ export class EventTarget implements domTypes.EventTarget {
}
}

function isNode(nodeImpl: domTypes.EventTarget | null) {
return Boolean(nodeImpl && "nodeType" in nodeImpl);
}

function isShadowRoot(nodeImpl: domTypes.EventTarget | null) {
return Boolean(
nodeImpl &&
nodeImpl.nodeType === domTypes.NodeType.DOCUMENT_FRAGMENT_NODE &&
"host" in nodeImpl
);
}

function isSlotable(nodeImpl: domTypes.EventTarget | null) {
return (
nodeImpl &&
(nodeImpl.nodeType === domTypes.NodeType.ELEMENT_NODE ||
nodeImpl.nodeType === domTypes.NodeType.TEXT_NODE)
);
}

// https://dom.spec.whatwg.org/#node-trees
// const domSymbolTree = Symbol("DOM Symbol Tree");

// https://dom.spec.whatwg.org/#concept-shadow-including-inclusive-ancestor
function isShadowInclusiveAncestor(
ancestor: domTypes.EventTarget | null,
node: domTypes.EventTarget | null
) {
while (isNode(node)) {
if (node === ancestor) {
return true;
}

if (isShadowRoot(node)) {
node = node && node.host;
} else {
node = null; // domSymbolTree.parent(node);
}
}

return false;
}

// https://dom.spec.whatwg.org/#retarget
function retarget(a: domTypes.EventTarget | null, b: domTypes.EventTarget) {
while (true) {
if (!isNode(a)) {
return a;
}

const aRoot = getRoot(a);

if (aRoot) {
if (
!isShadowRoot(aRoot) ||
(isNode(b) && isShadowInclusiveAncestor(aRoot, b))
) {
return a;
}

a = aRoot.host;
}
}
}

// https://dom.spec.whatwg.org/#get-the-parent
// Note: Nodes, shadow roots, and documents override this algorithm so we set it to null.
function getEventTargetParent(
eventTarget: domTypes.EventTarget,
event: domTypes.Event
) {
return null;
}

function getRoot(node: domTypes.EventTarget | null) {
let root = node;

// for (const ancestor of domSymbolTree.ancestorsIterator(node)) {
// root = ancestor;
// }

return root;
}

/** Built-in objects providing `get` methods for our
* interceptable JavaScript operations.
*/
@@ -1,4 +1,5 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import * as domTypes from "./dom_types";
import { TypedArray } from "./types";

let logDebug = false;
@@ -207,3 +208,90 @@ export function splitNumberToParts(n: number): number[] {
const higher = (n - lower) / 0x100000000;
return [lower, higher];
}

// Utility functions for DOM nodes
// @internal
export function isNode(nodeImpl: domTypes.EventTarget | null): boolean {
return Boolean(nodeImpl && "nodeType" in nodeImpl);
}

// @internal
export function isShadowRoot(nodeImpl: domTypes.EventTarget | null): boolean {
return Boolean(
nodeImpl &&
nodeImpl.nodeType === domTypes.NodeType.DOCUMENT_FRAGMENT_NODE &&
"host" in nodeImpl
);
}

// @internal
export function isSlotable(nodeImpl: domTypes.EventTarget | null): boolean {
return Boolean(
nodeImpl &&
(nodeImpl.nodeType === domTypes.NodeType.ELEMENT_NODE ||
nodeImpl.nodeType === domTypes.NodeType.TEXT_NODE)
);
}

// https://dom.spec.whatwg.org/#node-trees
// const domSymbolTree = Symbol("DOM Symbol Tree");

// https://dom.spec.whatwg.org/#concept-shadow-including-inclusive-ancestor
// @internal
export function isShadowInclusiveAncestor(
ancestor: domTypes.EventTarget | null,
node: domTypes.EventTarget | null
): boolean {
while (isNode(node)) {
if (node === ancestor) {
return true;
}

if (isShadowRoot(node)) {
node = node && node.host;
} else {
node = null; // domSymbolTree.parent(node);
}
}

return false;
}

// https://dom.spec.whatwg.org/#retarget
// @internal
export function retarget(
a: domTypes.EventTarget | null,
b: domTypes.EventTarget
): domTypes.EventTarget | null {
while (true) {
if (!isNode(a)) {
return a;
}

const aRoot = getRoot(a);

if (aRoot) {
if (
!isShadowRoot(aRoot) ||
(isNode(b) && isShadowInclusiveAncestor(aRoot, b))
) {
return a;
}

a = aRoot.host;
}
}
}

// @internal
export function getRoot(
node: domTypes.EventTarget | null
): domTypes.EventTarget | null {
let root = node;

// for (const ancestor of domSymbolTree.ancestorsIterator(node)) {
// root = ancestor;
// }

return root;
}

0 comments on commit 1335cdd

Please sign in to comment.
You can’t perform that action at this time.