@@ -18,9 +18,9 @@ export type SerializedValue =
18
18
undefined | boolean | number | string |
19
19
{ v : 'null' | 'undefined' | 'NaN' | 'Infinity' | '-Infinity' | '-0' } |
20
20
{ d : string } |
21
- { r : [ string , string ] } |
21
+ { r : { p : string , f : string } } |
22
22
{ a : SerializedValue [ ] } |
23
- { o : { [ key : string ] : SerializedValue } } |
23
+ { o : { k : string , v : SerializedValue } [ ] } |
24
24
{ h : number } ;
25
25
26
26
function isRegExp ( obj : any ) : obj is RegExp {
@@ -36,9 +36,9 @@ function isError(obj: any): obj is Error {
36
36
}
37
37
38
38
export function parseEvaluationResultValue ( value : SerializedValue , handles : any [ ] = [ ] ) : any {
39
- if ( value === undefined )
39
+ if ( Object . is ( value , undefined ) )
40
40
return undefined ;
41
- if ( typeof value === 'object' ) {
41
+ if ( typeof value === 'object' && value ) {
42
42
if ( 'v' in value ) {
43
43
if ( value . v === 'undefined' )
44
44
return undefined ;
@@ -52,17 +52,18 @@ export function parseEvaluationResultValue(value: SerializedValue, handles: any[
52
52
return - Infinity ;
53
53
if ( value . v === '-0' )
54
54
return - 0 ;
55
+ return undefined ;
55
56
}
56
57
if ( 'd' in value )
57
58
return new Date ( value . d ) ;
58
59
if ( 'r' in value )
59
- return new RegExp ( value . r [ 0 ] , value . r [ 1 ] ) ;
60
+ return new RegExp ( value . r . p , value . r . f ) ;
60
61
if ( 'a' in value )
61
62
return value . a . map ( ( a : any ) => parseEvaluationResultValue ( a , handles ) ) ;
62
63
if ( 'o' in value ) {
63
64
const result : any = { } ;
64
- for ( const name of Object . keys ( value . o ) )
65
- result [ name ] = parseEvaluationResultValue ( value . o [ name ] , handles ) ;
65
+ for ( const { k , v } of value . o )
66
+ result [ k ] = parseEvaluationResultValue ( v , handles ) ;
66
67
return result ;
67
68
}
68
69
if ( 'h' in value )
@@ -72,12 +73,12 @@ export function parseEvaluationResultValue(value: SerializedValue, handles: any[
72
73
}
73
74
74
75
export type HandleOrValue = { h : number } | { fallThrough : any } ;
75
- export function serializeAsCallArgument ( value : any , jsHandleSerializer : ( value : any ) => HandleOrValue ) : SerializedValue {
76
- return serialize ( value , jsHandleSerializer , new Set ( ) ) ;
76
+ export function serializeAsCallArgument ( value : any , handleSerializer : ( value : any ) => HandleOrValue ) : SerializedValue {
77
+ return serialize ( value , handleSerializer , new Set ( ) ) ;
77
78
}
78
79
79
- function serialize ( value : any , jsHandleSerializer : ( value : any ) => HandleOrValue , visited : Set < any > ) : SerializedValue {
80
- const result = jsHandleSerializer ( value ) ;
80
+ function serialize ( value : any , handleSerializer : ( value : any ) => HandleOrValue , visited : Set < any > ) : SerializedValue {
81
+ const result = handleSerializer ( value ) ;
81
82
if ( 'fallThrough' in result )
82
83
value = result . fallThrough ;
83
84
else
@@ -111,26 +112,26 @@ function serialize(value: any, jsHandleSerializer: (value: any) => HandleOrValue
111
112
const error = value ;
112
113
if ( 'captureStackTrace' in global . Error ) {
113
114
// v8
114
- return error . stack ;
115
+ return error . stack || '' ;
115
116
}
116
117
return `${ error . name } : ${ error . message } \n${ error . stack } ` ;
117
118
}
118
119
if ( isDate ( value ) )
119
120
return { d : value . toJSON ( ) } ;
120
121
if ( isRegExp ( value ) )
121
- return { r : [ value . source , value . flags ] } ;
122
+ return { r : { p : value . source , f : value . flags } } ;
122
123
123
124
if ( Array . isArray ( value ) ) {
124
- const result = [ ] ;
125
+ const a = [ ] ;
125
126
visited . add ( value ) ;
126
127
for ( let i = 0 ; i < value . length ; ++ i )
127
- result . push ( serialize ( value [ i ] , jsHandleSerializer , visited ) ) ;
128
+ a . push ( serialize ( value [ i ] , handleSerializer , visited ) ) ;
128
129
visited . delete ( value ) ;
129
- return { a : result } ;
130
+ return { a } ;
130
131
}
131
132
132
133
if ( typeof value === 'object' ) {
133
- const result : any = { } ;
134
+ const o : { k : string , v : SerializedValue } [ ] = [ ] ;
134
135
visited . add ( value ) ;
135
136
for ( const name of Object . keys ( value ) ) {
136
137
let item ;
@@ -140,11 +141,11 @@ function serialize(value: any, jsHandleSerializer: (value: any) => HandleOrValue
140
141
continue ; // native bindings will throw sometimes
141
142
}
142
143
if ( name === 'toJSON' && typeof item === 'function' )
143
- result [ name ] = { } ;
144
+ o . push ( { k : name , v : { o : [ ] } } ) ;
144
145
else
145
- result [ name ] = serialize ( item , jsHandleSerializer , visited ) ;
146
+ o . push ( { k : name , v : serialize ( item , handleSerializer , visited ) } ) ;
146
147
}
147
148
visited . delete ( value ) ;
148
- return { o : result } ;
149
+ return { o } ;
149
150
}
150
151
}
0 commit comments