File tree Expand file tree Collapse file tree 4 files changed +24
-2
lines changed Expand file tree Collapse file tree 4 files changed +24
-2
lines changed Original file line number Diff line number Diff line change 1
1
import {
2
2
DevalueError ,
3
+ enumerable_symbols ,
3
4
get_type ,
4
5
is_plain_object ,
5
6
is_primitive ,
@@ -143,7 +144,7 @@ export function stringify(value, reducers) {
143
144
) ;
144
145
}
145
146
146
- if ( Object . getOwnPropertySymbols ( thing ) . length > 0 ) {
147
+ if ( enumerable_symbols ( thing ) . length > 0 ) {
147
148
throw new DevalueError (
148
149
`Cannot stringify POJOs with symbolic keys` ,
149
150
keys
Original file line number Diff line number Diff line change 1
1
import {
2
2
DevalueError ,
3
+ enumerable_symbols ,
3
4
escaped ,
4
5
get_type ,
5
6
is_plain_object ,
@@ -89,7 +90,7 @@ export function uneval(value, replacer) {
89
90
) ;
90
91
}
91
92
92
- if ( Object . getOwnPropertySymbols ( thing ) . length > 0 ) {
93
+ if ( enumerable_symbols ( thing ) . length > 0 ) {
93
94
throw new DevalueError (
94
95
`Cannot stringify POJOs with symbolic keys` ,
95
96
keys
Original file line number Diff line number Diff line change @@ -97,3 +97,10 @@ export function stringify_string(str) {
97
97
98
98
return `"${ last_pos === 0 ? str : result + str . slice ( last_pos ) } "` ;
99
99
}
100
+
101
+ /** @param {Record<string | symbol, any> } object */
102
+ export function enumerable_symbols ( object ) {
103
+ return Object . getOwnPropertySymbols ( object ) . filter (
104
+ ( symbol ) => Object . getOwnPropertyDescriptor ( object , symbol ) . enumerable
105
+ ) ;
106
+ }
Original file line number Diff line number Diff line change @@ -390,6 +390,19 @@ const fixtures = {
390
390
assert . equal ( Object . getPrototypeOf ( value ) , Object . prototype ) ;
391
391
assert . equal ( Object . keys ( value ) . length , 0 ) ;
392
392
}
393
+ } ,
394
+ {
395
+ name : 'non-enumerable symbolic key' ,
396
+ value : ( ( ) => {
397
+ const obj = { x : 1 } ;
398
+ Object . defineProperty ( obj , Symbol ( 'key' ) , {
399
+ value : 'value' ,
400
+ enumerable : false
401
+ } ) ;
402
+ return obj ;
403
+ } ) ( ) ,
404
+ js : '{x:1}' ,
405
+ json : '[{"x":1},1]'
393
406
}
394
407
] ,
395
408
You can’t perform that action at this time.
0 commit comments