Skip to content

Commit

Permalink
fix: null check on hasInstance (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmywarting authored Sep 30, 2021
1 parent 36e2491 commit fbb5033
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion esm.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const FormData = class FormData {
constructor(...a){if(a.length)throw new TypeError(`Failed to construct 'FormData': parameter 1 is not of type 'HTMLFormElement'.`)}
get [t]() {return 'FormData'}
[i](){return this.entries()}
static [h](o) {return typeof o==='object'&&o[t]==='FormData'&&!m.some(m=>typeof o[m]!='function')}
static [h](o) {return o&&typeof o==='object'&&o[t]==='FormData'&&!m.some(m=>typeof o[m]!='function')}
append(...a){x('append',arguments,2);this.#d.push(f(...a))}
delete(a){x('delete',arguments,1);a+='';this.#d=this.#d.filter(([b])=>b!==a)}
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}
Expand Down
17 changes: 17 additions & 0 deletions test/test-esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,23 @@ for (let [filename, expected] of [['val\nue', 'val%0Aue'], ['val%0Aue', 'val%0Au
console.assert(fd.has('key3') === true)
}

class FormDataLike {
append(){}
set(){}
get(){}
getAll(){}
delete(){}
keys(){}
values(){}
entries(){}
forEach(){}
get [Symbol.toStringTag](){ return 'FormData' }
}

console.assert(new FormDataLike() instanceof FormData, 'It should be a formdata like object')
console.assert(!(null instanceof FormData), 'null check dont throw')
console.assert(new FormData() instanceof FormData, 'instance check works')

{
const msg = 'should return the keys/values/entres in the order they was appended'
const entries = [
Expand Down

0 comments on commit fbb5033

Please sign in to comment.