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
5 changes: 5 additions & 0 deletions src/netsurf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,11 @@ pub fn eventTargetAddEventListener(
const cbk_ptr = try alloc.create(Callback);
cbk_ptr.* = cbk;

// When a function is used as an event handler, its this parameter is bound
// to the DOM element on which the listener is placed.
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this#this_in_dom_event_handlers
try cbk_ptr.setThisArg(et);

const ctx = @as(*anyopaque, @ptrCast(cbk_ptr));
var listener: ?*EventListener = undefined;
const errLst = c.dom_event_listener_create(event_handler, ctx, &listener);
Expand Down
12 changes: 12 additions & 0 deletions src/xhr/xhr.zig
Original file line number Diff line number Diff line change
Expand Up @@ -837,4 +837,16 @@ pub fn testExecFn(
.{ .src = "req4.responseText.length > 64", .ex = "true" },
};
try checkCases(js_env, &post);

var cbk = [_]Case{
.{ .src = "const req5 = new XMLHttpRequest()", .ex = "undefined" },
.{ .src = "req5.open('GET', 'http://httpbin.io/json')", .ex = "undefined" },
.{ .src = "var status = 0; req5.onload = function () { status = this.status };", .ex = "function () { status = this.status }" },
.{ .src = "req5.send()", .ex = "undefined" },

// Each case executed waits for all loop callaback calls.
// So the url has been retrieved.
.{ .src = "status", .ex = "200" },
};
try checkCases(js_env, &cbk);
}
2 changes: 1 addition & 1 deletion vendor/jsruntime-lib