[FIX] runtime: correctly throw an error for duplicate object keys

Currently when checking for duplicate keys, we insert the value of the
key as is in a set then check for unicity against those. When the key is
an object, we check for duplicates based on object identity, whereas the
keys are used by owl as strings, and so using objects can cause
duplicate key errors that do not throw correctly but crash in the owl
internals.

This commit fixes that by making the duplicate checking code serialize
the key to string before insertion and when comparing against existing
keys.
This commit is contained in:
Samuel Degueldre
2022-10-10 12:10:52 +02:00
committed by Bruno Boi
parent a1f22829c1
commit d546244fc3
3 changed files with 68 additions and 4 deletions
+2 -2
View File
@@ -877,9 +877,9 @@ export class CodeGenerator {
// Throw error on duplicate keys in dev mode
this.helpers.add("OwlError");
this.addLine(
`if (keys${block.id}.has(key${this.target.loopLevel})) { throw new OwlError(\`Got duplicate key in t-foreach: \${key${this.target.loopLevel}}\`)}`
`if (keys${block.id}.has(String(key${this.target.loopLevel}))) { throw new OwlError(\`Got duplicate key in t-foreach: \${key${this.target.loopLevel}}\`)}`
);
this.addLine(`keys${block.id}.add(key${this.target.loopLevel});`);
this.addLine(`keys${block.id}.add(String(key${this.target.loopLevel}));`);
}
let id: string;
if (ast.memo) {