Skip to content

Commit

Permalink
Make FileList a valid array type in all decoding paths
Browse files Browse the repository at this point in the history
  • Loading branch information
evancz committed Nov 9, 2018
1 parent 079c965 commit ac61467
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/Elm/Kernel/Json.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,14 @@ function _Json_runHelp(decoder, value)
: _Json_expecting('null', value);

case __1_LIST:
if (!Array.isArray(value))
if (!_Json_isArray(value))
{
return _Json_expecting('a LIST', value);
}
return _Json_runArrayDecoder(decoder.__decoder, value, __List_fromArray);

case __1_ARRAY:
if (!Array.isArray(value))
if (!_Json_isArray(value))
{
return _Json_expecting('an ARRAY', value);
}
Expand All @@ -236,7 +236,7 @@ function _Json_runHelp(decoder, value)

case __1_INDEX:
var index = decoder.__index;
if (!Array.isArray(value))
if (!_Json_isArray(value))
{
return _Json_expecting('an ARRAY', value);
}
Expand All @@ -248,7 +248,7 @@ function _Json_runHelp(decoder, value)
return (__Result_isOk(result)) ? result : __Result_Err(A2(__Json_Index, index, result.a));

case __1_KEY_VALUE:
if (typeof value !== 'object' || value === null || Array.isArray(value))
if (typeof value !== 'object' || value === null || !_Json_isArray(value))
{
return _Json_expecting('an OBJECT', value);
}
Expand Down Expand Up @@ -326,6 +326,11 @@ function _Json_runArrayDecoder(decoder, value, toElmValue)
return __Result_Ok(toElmValue(array));
}

function _Json_isArray(value)
{
return Array.isArray(value) || value instanceof FileList;
}

function _Json_toElmArray(array)
{
return A2(__Array_initialize, array.length, function(i) { return array[i]; });
Expand Down

0 comments on commit ac61467

Please sign in to comment.