Skip to content

Commit

Permalink
Support window.onload (denoland#2643)
Browse files Browse the repository at this point in the history
  • Loading branch information
kt3k authored and ry committed Jul 16, 2019
1 parent bd6ebb3 commit 9c45499
Show file tree
Hide file tree
Showing 14 changed files with 162 additions and 88 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@typescript-eslint/array-type": ["error", "array-simple"],
"@typescript-eslint/explicit-member-accessibility": ["off"],
"@typescript-eslint/no-non-null-assertion": ["off"],
"@typescript-eslint/no-use-before-define": ["off"],
"@typescript-eslint/no-parameter-properties": ["off"],
"@typescript-eslint/no-unused-vars": [
"error",
Expand Down
1 change: 1 addition & 0 deletions cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ fn run_script(flags: DenoFlags, argv: Vec<String>) {
worker
.execute_mod_async(&main_module, false)
.and_then(move |()| {
js_check(worker.execute("window.dispatchEvent(new Event('load'))"));
worker.then(|result| {
js_check(result);
Ok(())
Expand Down
13 changes: 9 additions & 4 deletions js/dom_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,16 @@ export enum NodeType {
DOCUMENT_FRAGMENT_NODE = 11
}

export const eventTargetHost: unique symbol = Symbol();
export const eventTargetListeners: unique symbol = Symbol();
export const eventTargetMode: unique symbol = Symbol();
export const eventTargetNodeType: unique symbol = Symbol();

export interface EventTarget {
host: EventTarget | null;
listeners: { [type in string]: EventListener[] };
mode: string;
nodeType: NodeType;
[eventTargetHost]: EventTarget | null;
[eventTargetListeners]: { [type in string]: EventListener[] };
[eventTargetMode]: string;
[eventTargetNodeType]: NodeType;
addEventListener(
type: string,
callback: (event: Event) => void | null,
Expand Down
14 changes: 8 additions & 6 deletions js/dom_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ export function isNode(nodeImpl: domTypes.EventTarget | null): boolean {
export function isShadowRoot(nodeImpl: domTypes.EventTarget | null): boolean {
return Boolean(
nodeImpl &&
nodeImpl.nodeType === domTypes.NodeType.DOCUMENT_FRAGMENT_NODE &&
"host" in nodeImpl
nodeImpl[domTypes.eventTargetNodeType] ===
domTypes.NodeType.DOCUMENT_FRAGMENT_NODE &&
nodeImpl[domTypes.eventTargetHost] != null
);
}

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

Expand All @@ -36,7 +38,7 @@ export function isShadowInclusiveAncestor(
}

if (isShadowRoot(node)) {
node = node && node.host;
node = node && node[domTypes.eventTargetHost];
} else {
node = null; // domSymbolTree.parent(node);
}
Expand Down Expand Up @@ -77,7 +79,7 @@ export function retarget(
return a;
}

a = aRoot.host;
a = aRoot[domTypes.eventTargetHost];
}
}
}
Loading

0 comments on commit 9c45499

Please sign in to comment.