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
28 changes: 28 additions & 0 deletions examples/event/constructor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Create a new event instance
const myEvent = new Event("customEvent", {
bubbles: true,
cancelable: true,
composed: false,
});

console.log("Event Type:", myEvent.type);
console.log("Bubbles:", myEvent.bubbles);
console.log("Cancelable:", myEvent.cancelable);
console.log("Composed:", myEvent.composed);
console.log("Event Phase:", myEvent.eventPhase);
console.log("Before stopPropagation:", myEvent.cancelBubble);
myEvent.stopPropagation();
console.log("After stopPropagation:", myEvent.cancelBubble);
console.log("Before preventDefault:", myEvent.defaultPrevented);
myEvent.preventDefault();
console.log("After preventDefault:", myEvent.defaultPrevented);
console.log("Target:", myEvent.target);
console.log("Current Target:", myEvent.currentTarget);
console.log("NONE:", myEvent.NONE);
console.log("CAPTURING_PHASE:", myEvent.CAPTURING_PHASE);
console.log("AT_TARGET:", myEvent.AT_TARGET);
console.log("BUBBLING_PHASE:", myEvent.BUBBLING_PHASE);
console.log("Return Value (before change):", myEvent.returnValue);
myEvent.returnValue = false;
console.log("Return Value (after change):", myEvent.returnValue);
console.log("Time Stamp:", myEvent.timeStamp);
170 changes: 170 additions & 0 deletions runtime/src/ext/web/event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
// deno-lint-ignore-file no-unused-vars
class Event {
constructor(type, eventInitDict = { __proto__: null }) {
// @ts-ignore - this is a hack to make the URL object work
this.SymbolToStringTag = "Event";
// @ts-ignore - this is a hack to make the URL object work
this.canceledFlag = false;
// @ts-ignore - this is a hack to make the URL object work
this.stopPropagationFlag = false;
// @ts-ignore - this is a hack to make the URL object work
this._stopImmediatePropagationFlag = false;
// @ts-ignore - this is a hack to make the URL object work
this._inPassiveListener = false;
// @ts-ignore - this is a hack to make the URL object work
this.dispatched = false;
// @ts-ignore - this is a hack to make the URL object work
this.isTrusted = false;
// @ts-ignore - this is a hack to make the URL object work
this.path = [];

// @ts-ignore - this is a hack to make the URL object work
this.attributes = {
type,
// @ts-ignore - this is a hack to make the URL object work
bubbles: !!eventInitDict.bubbles,
// @ts-ignore - this is a hack to make the URL object work
cancelable: !!eventInitDict.cancelable,
// @ts-ignore - this is a hack to make the URL object work
composed: !!eventInitDict.composed,
currentTarget: null,
eventPhase: Event.NONE,
target: null,
timeStamp: 0,
};
}

get type() {
// @ts-ignore - this is a hack to make the URL object work
return this.attributes.type;
}

// TODO: Null is not returned
get target() {
// @ts-ignore - this is a hack to make the URL object work
return this.attributes.target;
}

get srcElement() {
return null;
}

set srcElement(_) {
// this member is deprecated
}

// TODO: Null is not returned
get currentTarget() {
// @ts-ignore - this is a hack to make the URL object work
return this.attributes.currentTarget;
}

get NONE() {
return Event.NONE;
}

get CAPTURING_PHASE() {
return Event.CAPTURING_PHASE;
}

get AT_TARGET() {
return Event.AT_TARGET;
}

get BUBBLING_PHASE() {
return Event.BUBBLING_PHASE;
}

static get NONE() {
return 0;
}

static get CAPTURING_PHASE() {
return 1;
}

static get AT_TARGET() {
return 2;
}

static get BUBBLING_PHASE() {
return 3;
}

get eventPhase() {
// @ts-ignore - this is a hack to make the URL object work
return this.attributes.eventPhase;
}

stopPropagation() {
// @ts-ignore - this is a hack to make the URL object work
this.stopPropagationFlag = true;
}

/** @deprecated */
get cancelBubble() {
// @ts-ignore - this is a hack to make the URL object work
return this.stopPropagationFlag;
}

set cancelBubble(value) {
// TODO
// this.stopPropagationFlag = webidl.converters.boolean(value);
}

stopImmediatePropagation() {
// @ts-ignore - this is a hack to make the URL object work

this.stopPropagationFlag = true;
// @ts-ignore - this is a hack to make the URL object work
this.stopImmediatePropagationFlag = true;
}

get bubbles() {
// @ts-ignore - this is a hack to make the URL object work
return this.attributes.bubbles;
}

get cancelable() {
// @ts-ignore - this is a hack to make the URL object work
return this.attributes.cancelable;
}

get returnValue() {
// @ts-ignore - this is a hack to make the URL object work
return !this.canceledFlag;
}

set returnValue(value) {
// if (!webidl.converters.boolean(value)) {
// @ts-ignore - this is a hack to make the URL object work
this.canceledFlag = true;
// }
}

preventDefault() {
// if (this.attributes.cancelable && !this.inPassiveListener) {
// @ts-ignore - this is a hack to make the URL object work
this.canceledFlag = true;
// }
}

get defaultPrevented() {
// @ts-ignore - this is a hack to make the URL object work
return this.canceledFlag;
}

get composed() {
// @ts-ignore - this is a hack to make the URL object work
return this.attributes.composed;
}

get initialized() {
return true;
}

get timeStamp() {
// @ts-ignore - this is a hack to make the URL object work
return this.attributes.timeStamp;
}
}
2 changes: 1 addition & 1 deletion runtime/src/ext/web/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl WebExt {
ExtensionOp::new("internal_atob", Self::internal_atob, 1),
],
storage: None,
files: vec![],
files: vec![include_str!("./event.ts")],
}
}

Expand Down
Loading