Skip to content

Commit ed122c6

Browse files
authored
Merge pull request #80 from danielroe/fix/proto
fix: do not iterate over prototype properties of reducers
2 parents 293d70b + 77fa57b commit ed122c6

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/stringify.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ export function stringify(value, reducers) {
3131

3232
/** @type {Array<{ key: string, fn: (value: any) => any }>} */
3333
const custom = [];
34-
for (const key in reducers) {
35-
custom.push({ key, fn: reducers[key] });
34+
if (reducers) {
35+
for (const key of Object.getOwnPropertyNames(reducers)) {
36+
custom.push({ key, fn: reducers[key] });
37+
}
3638
}
3739

3840
/** @type {string[]} */

test/test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ const fixtures = {
167167
json: '[["Uint8Array","AQID"]]'
168168
},
169169
{
170-
name: "ArrayBuffer",
170+
name: 'ArrayBuffer',
171171
value: new Uint8Array([1, 2, 3]).buffer,
172172
js: 'new Uint8Array([1,2,3]).buffer',
173173
json: '[["ArrayBuffer","AQID"]]'
@@ -429,9 +429,10 @@ const fixtures = {
429429
return `new Custom(${uneval(value.value)})`;
430430
}
431431
},
432-
reducers: {
432+
// test for https://github.com/Rich-Harris/devalue/pull/80
433+
reducers: Object.assign(Object.create({ polluted: true }), {
433434
Custom: (x) => x instanceof Custom && x.value
434-
},
435+
}),
435436
revivers: {
436437
Custom: (x) => new Custom(x)
437438
},

0 commit comments

Comments
 (0)