File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -622,6 +622,11 @@ pub fn eventTargetAddEventListener(
622622 const cbk_ptr = try alloc .create (Callback );
623623 cbk_ptr .* = cbk ;
624624
625+ // When a function is used as an event handler, its this parameter is bound
626+ // to the DOM element on which the listener is placed.
627+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this#this_in_dom_event_handlers
628+ try cbk_ptr .setThisArg (et );
629+
625630 const ctx = @as (* anyopaque , @ptrCast (cbk_ptr ));
626631 var listener : ? * EventListener = undefined ;
627632 const errLst = c .dom_event_listener_create (event_handler , ctx , & listener );
Original file line number Diff line number Diff line change @@ -837,4 +837,16 @@ pub fn testExecFn(
837837 .{ .src = "req4.responseText.length > 64" , .ex = "true" },
838838 };
839839 try checkCases (js_env , & post );
840+
841+ var cbk = [_ ]Case {
842+ .{ .src = "const req5 = new XMLHttpRequest()" , .ex = "undefined" },
843+ .{ .src = "req5.open('GET', 'http://httpbin.io/json')" , .ex = "undefined" },
844+ .{ .src = "var status = 0; req5.onload = function () { status = this.status };" , .ex = "function () { status = this.status }" },
845+ .{ .src = "req5.send()" , .ex = "undefined" },
846+
847+ // Each case executed waits for all loop callaback calls.
848+ // So the url has been retrieved.
849+ .{ .src = "status" , .ex = "200" },
850+ };
851+ try checkCases (js_env , & cbk );
840852}
You can’t perform that action at this time.
0 commit comments