Skip to content

Commit

Permalink
SharedSymbolTables no longer treat object properties as symbols. (#648)
Browse files Browse the repository at this point in the history
  • Loading branch information
zslayton authored Nov 24, 2020
1 parent f66d154 commit b3abd8a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/IonSharedSymbolTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class SharedSymbolTable {
// Iterate through the symbol array in reverse order so if the same string appears more than
// once the smaller symbol ID is stored.
for (let m = _symbols.length - 1; m >= 0; m--) {
this._idsByText[_symbols[m]] = m;
this._idsByText.set(_symbols[m], m);
}
}

Expand Down Expand Up @@ -61,6 +61,6 @@ export class SharedSymbolTable {
}

getSymbolId(text: string): number | undefined {
return this._idsByText[text];
return this._idsByText.get(text);
}
}
14 changes: 13 additions & 1 deletion test/IonLocalSymbolTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,16 @@ describe('Local symbol table', () => {
assert.equal(originalId, duplicateId, "Duplicate symbol was not given original id");
assert.equal(originalLength + 1, symbolTable.symbols.length, "Duplicate symbol added to symbol table");
});
});

// See https://github.com/amzn/ion-js/issues/645
it('SST Object properties are not treated as symbols (Issue #645)', () => {
const symbolTable = defaultLocalSymbolTable();
symbolTable.addSymbol("foo");
assert.equal(symbolTable.getSymbolId("foo"), 10);

// 'size' has not been added to the symbol table.
// It is, however, a property (an accessor) on the 'Map' data type.
// Asking for its symbol ID should return undefined.
assert.isUndefined(symbolTable.getSymbolId("size"));
});
});

0 comments on commit b3abd8a

Please sign in to comment.