@@ -8,6 +8,9 @@ const { installInterfaces } = require("../living/interfaces");
88const { define, mixin } = require ( "../utils" ) ;
99const Element = require ( "../living/generated/Element" ) ;
1010const EventTarget = require ( "../living/generated/EventTarget" ) ;
11+ const EventHandlerNonNull = require ( "../living/generated/EventHandlerNonNull" ) ;
12+ const OnBeforeUnloadEventHandlerNonNull = require ( "../living/generated/OnBeforeUnloadEventHandlerNonNull" ) ;
13+ const OnErrorEventHandlerNonNull = require ( "../living/generated/OnErrorEventHandlerNonNull" ) ;
1114const PageTransitionEvent = require ( "../living/generated/PageTransitionEvent" ) ;
1215const namedPropertiesWindow = require ( "../living/named-properties-window" ) ;
1316const postMessage = require ( "../living/post-message" ) ;
@@ -34,6 +37,59 @@ const jsGlobals = require("./js-globals.json");
3437const GlobalEventHandlersImpl = require ( "../living/nodes/GlobalEventHandlers-impl" ) . implementation ;
3538const WindowEventHandlersImpl = require ( "../living/nodes/WindowEventHandlers-impl" ) . implementation ;
3639
40+ const events = new Set ( [
41+ // GlobalEventHandlers
42+ "abort" , "autocomplete" ,
43+ "autocompleteerror" , "blur" ,
44+ "cancel" , "canplay" , "canplaythrough" ,
45+ "change" , "click" ,
46+ "close" , "contextmenu" ,
47+ "cuechange" , "dblclick" ,
48+ "drag" , "dragend" ,
49+ "dragenter" ,
50+ "dragleave" , "dragover" ,
51+ "dragstart" , "drop" ,
52+ "durationchange" , "emptied" ,
53+ "ended" , "focus" ,
54+ "input" , "invalid" ,
55+ "keydown" , "keypress" ,
56+ "keyup" , "load" , "loadeddata" ,
57+ "loadedmetadata" , "loadstart" ,
58+ "mousedown" , "mouseenter" ,
59+ "mouseleave" , "mousemove" ,
60+ "mouseout" , "mouseover" ,
61+ "mouseup" , "wheel" ,
62+ "pause" , "play" ,
63+ "playing" , "progress" ,
64+ "ratechange" , "reset" ,
65+ "resize" , "scroll" ,
66+ "securitypolicyviolation" ,
67+ "seeked" , "seeking" ,
68+ "select" , "sort" , "stalled" ,
69+ "submit" , "suspend" ,
70+ "timeupdate" , "toggle" ,
71+ "volumechange" , "waiting" ,
72+
73+ // WindowEventHandlers
74+ "afterprint" ,
75+ "beforeprint" ,
76+ "hashchange" ,
77+ "languagechange" ,
78+ "message" ,
79+ "messageerror" ,
80+ "offline" ,
81+ "online" ,
82+ "pagehide" ,
83+ "pageshow" ,
84+ "popstate" ,
85+ "rejectionhandled" ,
86+ "storage" ,
87+ "unhandledrejection" ,
88+ "unload"
89+
90+ // "error" and "beforeunload" are added separately
91+ ] ) ;
92+
3793exports . createWindow = function ( options ) {
3894 return new Window ( options ) ;
3995} ;
@@ -100,6 +156,53 @@ function setupWindow(windowInstance, { runScripts }) {
100156 mixin ( windowInstance , GlobalEventHandlersImpl . prototype ) ;
101157 windowInstance . _initGlobalEvents ( ) ;
102158
159+ // The getters are already obtained from the above mixins.
160+ // eslint-disable-next-line accessor-pairs
161+ Object . defineProperty ( windowInstance , "onbeforeunload" , {
162+ set ( V ) {
163+ if ( ! idlUtils . isObject ( V ) ) {
164+ V = null ;
165+ } else {
166+ V = OnBeforeUnloadEventHandlerNonNull . convert ( V , {
167+ context : "Failed to set the 'onbeforeunload' property on 'Window': The provided value"
168+ } ) ;
169+ }
170+ this . _setEventHandlerFor ( "beforeunload" , V ) ;
171+ }
172+ } ) ;
173+
174+ // The getters are already obtained from the above mixins.
175+ // eslint-disable-next-line accessor-pairs
176+ Object . defineProperty ( windowInstance , "onerror" , {
177+ set ( V ) {
178+ if ( ! idlUtils . isObject ( V ) ) {
179+ V = null ;
180+ } else {
181+ V = OnErrorEventHandlerNonNull . convert ( V , {
182+ context : "Failed to set the 'onerror' property on 'Window': The provided value"
183+ } ) ;
184+ }
185+ this . _setEventHandlerFor ( "error" , V ) ;
186+ }
187+ } ) ;
188+
189+ for ( const event of events ) {
190+ // The getters are already obtained from the above mixins.
191+ // eslint-disable-next-line accessor-pairs
192+ Object . defineProperty ( windowInstance , `on${ event } ` , {
193+ set ( V ) {
194+ if ( ! idlUtils . isObject ( V ) ) {
195+ V = null ;
196+ } else {
197+ V = EventHandlerNonNull . convert ( V , {
198+ context : `Failed to set the 'on${ event } ' property on 'Window': The provided value`
199+ } ) ;
200+ }
201+ this . _setEventHandlerFor ( event , V ) ;
202+ }
203+ } ) ;
204+ }
205+
103206 windowInstance . _globalObject = windowInstance ;
104207}
105208
0 commit comments