Skip to content

Commit 7c06067

Browse files
Merge pull request #214 from lightpanda-io/event-callback
Event callback
2 parents 88106f8 + 8b47d72 commit 7c06067

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/netsurf.zig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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);

src/xhr/xhr.zig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

vendor/jsruntime-lib

0 commit comments

Comments
 (0)