You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
"cannot coerce undefined to object" - Spread into array syntax issues #140
I have a weird problem that running in isolation works just fine.
Code
(Excerpt)
if(thing.referenceTo!==undefined){trace(thing.referenceTo+'\n');for(letentryofthing.referenceTo){trace(entry+'\n');}[...thing.referenceTo];// LOCATION OF ERROR, line #178
thing.referenceTo is a Set with a single string value "*" inside as shown by the trace output below.
Output
I wish I could copy & paste from the console in xsbug....
The same thing happens in another place (the case is resched because Object.prototype.toString.call returned string "Set", which was extracted, so obj is sure to be a Set):
case 'Set':
return actualStringify([...obj], seenObjects);
Just for the record, all of that is well-tested, the exact same code, just a mini-example of our stuff, runs on node.js browser, react-native - and even low.js (on this board).
An update: When I replace the [...setObject] by Array.from(setObj) it works. So it seems that there is an issue specifically when the object spread syntax is used. But it only happens in the large project thus far, which I keep shrinking piece by piece to get a small test case. <Sigh>
The error is connected to array spread syntax. Everything works if I replace it with Array.from. Also, there have to be two spreads, the first one works.
I ran it on Linux, but I discovered the issue originally on ESP32.
There are two different errors. To discover the first one just uncomment the code marked Error #1.
'use strict';functionisString(thing){returntypeofthing==='string';}functionensureRecipeRule(thing){if(thing.referenceToinstanceofSet){[...thing.referenceTo].every(type=>isString(type));}// ERROR #1// THE EXACT SAME THING AS ABOVE REPEATED: "callback is no function"// if (thing.referenceTo instanceof Set) {// [...thing.referenceTo].every(type => isString(type));// }// ERROR #2// "cannot coerce undefined to object"if(thing.idReferenceToinstanceofSet){[...thing.idReferenceTo].every(type=>isString(type));}}trace('Start\n');[{referenceTo: newSet(['Person']),},{idReferenceTo: newSet(['Group'])}].map(rule=>ensureRecipeRule(rule));trace('End\n');
Result (Error 2):
The "callback is no function" error can also be reproduced simply by
functionisString(s){returntypeofs==='string';}consts1=newSet('s1');[...s1].every(isString);[...s1].every(isString);// the 2nd call fails
changed the title [-]"cannot coerce undefined to object" - but the value is a Set[/-][+]"cannot coerce undefined to object" - Spread into array syntax issues[/+]on Mar 10, 2019
Activity
lll000111 commentedon Mar 8, 2019
PS: I'll keep debugging and if I can't think of anything else create a runnable example to send you.
EDIT: Blocked by #141 in this attempt.
EDIT ²: Unblocked by manifest.json entry `"strip": "[]", but the minimal examples keep working.... :(
lll000111 commentedon Mar 8, 2019
An update: When I replace the
[...setObject]byArray.from(setObj)it works. So it seems that there is an issue specifically when the object spread syntax is used. But it only happens in the large project thus far, which I keep shrinking piece by piece to get a small test case. <Sigh>lll000111 commentedon Mar 9, 2019
Reproducible example
The error is connected to array spread syntax. Everything works if I replace it with
Array.from. Also, there have to be two spreads, the first one works.I ran it on Linux, but I discovered the issue originally on ESP32.
There are two different errors. To discover the first one just uncomment the code marked
Error #1.Result (Error 2):
The "callback is no function" error can also be reproduced simply by
[-]"cannot coerce undefined to object" - but the value is a Set[/-][+]"cannot coerce undefined to object" - Spread into array syntax issues[/+]lll000111 commentedon Mar 10, 2019
Another possibly related example:
Test performed on Linux.
Code
Expected Result
[1, 2, 3]Actual Result
undefinedphoddie commentedon Oct 14, 2020
This was fixed a while back.