Skip to content

Commit fbb5033

Browse files
authored
fix: null check on hasInstance (#137)
1 parent 36e2491 commit fbb5033

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

esm.min.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const FormData = class FormData {
1818
constructor(...a){if(a.length)throw new TypeError(`Failed to construct 'FormData': parameter 1 is not of type 'HTMLFormElement'.`)}
1919
get [t]() {return 'FormData'}
2020
[i](){return this.entries()}
21-
static [h](o) {return typeof o==='object'&&o[t]==='FormData'&&!m.some(m=>typeof o[m]!='function')}
21+
static [h](o) {return o&&typeof o==='object'&&o[t]==='FormData'&&!m.some(m=>typeof o[m]!='function')}
2222
append(...a){x('append',arguments,2);this.#d.push(f(...a))}
2323
delete(a){x('delete',arguments,1);a+='';this.#d=this.#d.filter(([b])=>b!==a)}
2424
get(a){x('get',arguments,1);a+='';for(var b=this.#d,l=b.length,c=0;c<l;c++)if(b[c][0]===a)return b[c][1];return null}

test/test-esm.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,23 @@ for (let [filename, expected] of [['val\nue', 'val%0Aue'], ['val%0Aue', 'val%0Au
7676
console.assert(fd.has('key3') === true)
7777
}
7878

79+
class FormDataLike {
80+
append(){}
81+
set(){}
82+
get(){}
83+
getAll(){}
84+
delete(){}
85+
keys(){}
86+
values(){}
87+
entries(){}
88+
forEach(){}
89+
get [Symbol.toStringTag](){ return 'FormData' }
90+
}
91+
92+
console.assert(new FormDataLike() instanceof FormData, 'It should be a formdata like object')
93+
console.assert(!(null instanceof FormData), 'null check dont throw')
94+
console.assert(new FormData() instanceof FormData, 'instance check works')
95+
7996
{
8097
const msg = 'should return the keys/values/entres in the order they was appended'
8198
const entries = [

0 commit comments

Comments
 (0)