fix: new polyfill for formdata

This commit is contained in:
Martin Guillon
2021-09-30 10:46:37 +02:00
parent 05c0611107
commit 53f3219b50
3 changed files with 26 additions and 23 deletions

View File

@@ -314,7 +314,10 @@ export function initGlobal() {
// installPolyfills('text', ['TextDecoder', 'TextEncoder']);
// global.registerModule('xhr', () => require('../xhr'));
// installPolyfills('xhr', ['XMLHttpRequest', 'FormData', 'Blob', 'File', 'FileReader']);
// installPolyfills('xhr', ['XMLHttpRequest', 'Blob', 'File', 'FileReader']);
// global.registerModule('formdata', () => require('../polyfills/formdata'));
// installPolyfills('formdata', ['FormData']);
// global.registerModule('fetch', () => require('../fetch'));
// installPolyfills('fetch', ['fetch', 'Headers', 'Request', 'Response']);

View File

@@ -0,0 +1,22 @@
export class FormData {
private _data: Map<string, any>;
constructor() {
this._data = new Map<string, any>();
}
append(name: string, value: any) {
this._data.set(name, value);
}
toString(): string {
const arr = new Array<string>();
this._data.forEach(function (value, name, map) {
arr.push(`${encodeURIComponent(name)}=${encodeURIComponent(value)}`);
});
return arr.join('&');
}
}

View File

@@ -353,28 +353,6 @@ const statuses = {
505: 'HTTP Version Not Supported',
};
export class FormData {
private _data: Map<string, any>;
constructor() {
this._data = new Map<string, any>();
}
append(name: string, value: any) {
this._data.set(name, value);
}
toString(): string {
const arr = new Array<string>();
this._data.forEach(function (value, name, map) {
arr.push(`${encodeURIComponent(name)}=${encodeURIComponent(value)}`);
});
return arr.join('&');
}
}
export class Blob {
// Note: only for use by XHR
public static InternalAccessor = class {