File tree Expand file tree Collapse file tree 2 files changed +34
-2
lines changed
Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Original file line number Diff line number Diff line change 1+ const circularReplacer = ( ) => {
2+ const seen = new WeakSet ( ) ;
3+ return ( _ , value ) => {
4+ if ( typeof value === 'object' && value !== null ) {
5+ if ( seen . has ( value ) ) {
6+ return Array . isArray ( value ) ? '[...]' : '{...}' ;
7+ }
8+ seen . add ( value ) ;
9+ }
10+ return value ;
11+ } ;
12+ } ;
13+
14+ const sanitize = ( input ) => {
15+ if ( typeof input === "object" && input !== null ) {
16+ return JSON . stringify ( input , circularReplacer ( ) ) ;
17+ } else {
18+ return input ;
19+ }
20+ } ;
21+
22+ const sanitizeVariableType = ( input , type ) => {
23+ if ( type === "list" ) {
24+ return input . map ( item => sanitize ( item ) ) ;
25+ } else {
26+ return sanitize ( input ) ;
27+ }
28+ } ;
29+
30+ export default sanitizeVariableType ;
Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ import styles from './style.css';
44import { readAsText } from '../common/readers' ;
55import downloadBlob from './download' ;
66
7+ import sanitizeVariableType from '../common/safe-stringify' ;
8+
79class Monitor {
810 constructor ( parent , monitor ) {
911 this . parent = parent ;
@@ -194,7 +196,7 @@ class VariableMonitor extends Monitor {
194196 return ;
195197 }
196198
197- let value = monitor . get ( 'value' ) ;
199+ let value = sanitizeVariableType ( monitor . get ( 'value' ) , ' ') ;
198200 if ( typeof value === 'number' ) {
199201 value = Number ( value . toFixed ( 6 ) ) ;
200202 }
@@ -547,7 +549,7 @@ class ListMonitor extends Monitor {
547549 this . root . style . width = `${ this . width } px` ;
548550 this . root . style . height = `${ this . height } px` ;
549551
550- this . updateValue ( monitor . get ( 'value' ) ) ;
552+ this . updateValue ( sanitizeVariableType ( monitor . get ( 'value' ) , 'list ') ) ;
551553 }
552554
553555 createRow ( index ) {
You can’t perform that action at this time.
0 commit comments