Skip to content

Commit a91db8f

Browse files
authored
Do not throw when printing value that cannot be coerced to primitive (immutable-js#1334)
Fixes immutable-js#1252
1 parent 7c3e6c0 commit a91db8f

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

__tests__/issues.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,9 @@ describe('Issue #1247', () => {
7777
expect(r.wasAltered()).toBe(false);
7878
});
7979
});
80+
81+
describe('Issue #1252', () => {
82+
const prototypelessObj = Object.create(null);
83+
const list = List([prototypelessObj]);
84+
expect(list.toString()).toBe('List [ {} ]');
85+
});

src/utils/quoteString.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,9 @@
99
* Converts a value to a string, adding quotes if a string was provided.
1010
*/
1111
export default function quoteString(value) {
12-
return typeof value === 'string' ? JSON.stringify(value) : String(value);
12+
try {
13+
return typeof value === 'string' ? JSON.stringify(value) : String(value);
14+
} catch (_ignoreError) {
15+
return JSON.stringify(value);
16+
}
1317
}

0 commit comments

Comments
 (0)