Skip to content

Commit

Permalink
refactor: simplify XMLHttpRequest mock
Browse files Browse the repository at this point in the history
  • Loading branch information
b-ma committed Dec 28, 2023
1 parent 3e816a4 commit 5f67bc2
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions .scripts/wpt-mock/XMLHttpRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const fs = require('node:fs');
class XMLHttpRequest {
constructor() {
this._pathname;
this._onload;
this._onerror;
this.onload;
this.onerror;
this.response;
}

Expand All @@ -19,20 +19,12 @@ class XMLHttpRequest {
try {
buffer = fs.readFileSync(this._pathname).buffer;
} catch (err) {
this._onerror(err);
this.onerror(err);
return;
}

this.response = buffer;
this._onload();
}

set onload(func) {
this._onload = func;
}

set onerror(func) {
this._onerror = func;
this.onload();
}
}

Expand Down

0 comments on commit 5f67bc2

Please sign in to comment.