@@ -210,7 +210,7 @@ export class Kernel {
210
210
) ;
211
211
212
212
this . _debug ( 'value:' , value ) ;
213
- const ret = this . _fromSandbox ( value , ti ) ;
213
+ const ret = this . _fromSandbox ( value , ti , `of static property ${ symbol } ` ) ;
214
214
this . _debug ( 'ret' , ret ) ;
215
215
return { value : ret } ;
216
216
}
@@ -233,7 +233,12 @@ export class Kernel {
233
233
234
234
this . _ensureSync ( `property ${ property } ` , ( ) =>
235
235
this . _wrapSandboxCode (
236
- ( ) => ( prototype [ property ] = this . _toSandbox ( value , ti ) ) ,
236
+ ( ) =>
237
+ ( prototype [ property ] = this . _toSandbox (
238
+ value ,
239
+ ti ,
240
+ `assigned to static property ${ symbol } ` ,
241
+ ) ) ,
237
242
) ,
238
243
) ;
239
244
@@ -260,7 +265,7 @@ export class Kernel {
260
265
( ) => this . _wrapSandboxCode ( ( ) => instance [ propertyToGet ] ) ,
261
266
) ;
262
267
this . _debug ( 'value:' , value ) ;
263
- const ret = this . _fromSandbox ( value , ti ) ;
268
+ const ret = this . _fromSandbox ( value , ti , `of property ${ fqn } . ${ property } ` ) ;
264
269
this . _debug ( 'ret:' , ret ) ;
265
270
return { value : ret } ;
266
271
}
@@ -282,7 +287,12 @@ export class Kernel {
282
287
283
288
this . _ensureSync ( `property '${ objref [ TOKEN_REF ] } .${ propertyToSet } '` , ( ) =>
284
289
this . _wrapSandboxCode (
285
- ( ) => ( instance [ propertyToSet ] = this . _toSandbox ( value , propInfo ) ) ,
290
+ ( ) =>
291
+ ( instance [ propertyToSet ] = this . _toSandbox (
292
+ value ,
293
+ propInfo ,
294
+ `assigned to property ${ fqn } .${ property } ` ,
295
+ ) ) ,
286
296
) ,
287
297
) ;
288
298
@@ -310,7 +320,11 @@ export class Kernel {
310
320
} ,
311
321
) ;
312
322
313
- const result = this . _fromSandbox ( ret , ti . returns ?? 'void' ) ;
323
+ const result = this . _fromSandbox (
324
+ ret ,
325
+ ti . returns ?? 'void' ,
326
+ `returned by method ${ method } ` ,
327
+ ) ;
314
328
this . _debug ( 'invoke result' , result ) ;
315
329
316
330
return { result } ;
@@ -343,7 +357,13 @@ export class Kernel {
343
357
} ) ;
344
358
345
359
this . _debug ( 'method returned:' , ret ) ;
346
- return { result : this . _fromSandbox ( ret , ti . returns ?? 'void' ) } ;
360
+ return {
361
+ result : this . _fromSandbox (
362
+ ret ,
363
+ ti . returns ?? 'void' ,
364
+ `returned by static method ${ fqn } .${ method } ` ,
365
+ ) ,
366
+ } ;
347
367
}
348
368
349
369
public begin ( req : api . BeginRequest ) : api . BeginResponse {
@@ -402,7 +422,13 @@ export class Kernel {
402
422
throw e ;
403
423
}
404
424
405
- return { result : this . _fromSandbox ( result , method . returns ?? 'void' ) } ;
425
+ return {
426
+ result : this . _fromSandbox (
427
+ result ,
428
+ method . returns ?? 'void' ,
429
+ `returned by async method ${ method . name } ` ,
430
+ ) ,
431
+ } ;
406
432
}
407
433
408
434
public callbacks ( _req ?: api . CallbacksRequest ) : api . CallbacksResponse {
@@ -444,6 +470,7 @@ export class Kernel {
444
470
const sandoxResult = this . _toSandbox (
445
471
result ,
446
472
cb . expectedReturnType ?? 'void' ,
473
+ `returned by callback ${ cbid } ` ,
447
474
) ;
448
475
this . _debug ( 'completed with result:' , sandoxResult ) ;
449
476
cb . succeed ( sandoxResult ) ;
@@ -682,7 +709,11 @@ export class Kernel {
682
709
get : { objref, property : propertyName } ,
683
710
} ) ;
684
711
this . _debug ( 'callback returned' , result ) ;
685
- return this . _toSandbox ( result , propInfo ) ;
712
+ return this . _toSandbox (
713
+ result ,
714
+ propInfo ,
715
+ `returned by callback property ${ propertyName } ` ,
716
+ ) ;
686
717
} ,
687
718
set : ( value : any ) => {
688
719
this . _debug ( 'virtual set' , objref , propertyName , {
@@ -694,7 +725,11 @@ export class Kernel {
694
725
set : {
695
726
objref,
696
727
property : propertyName ,
697
- value : this . _fromSandbox ( value , propInfo ) ,
728
+ value : this . _fromSandbox (
729
+ value ,
730
+ propInfo ,
731
+ `assigned to callback property ${ propertyName } ` ,
732
+ ) ,
698
733
} ,
699
734
} ) ;
700
735
} ,
@@ -822,7 +857,11 @@ export class Kernel {
822
857
} ,
823
858
} ) ;
824
859
this . _debug ( 'Result' , result ) ;
825
- return this . _toSandbox ( result , methodInfo . returns ?? 'void' ) ;
860
+ return this . _toSandbox (
861
+ result ,
862
+ methodInfo . returns ?? 'void' ,
863
+ `returned by callback method ${ methodName } ` ,
864
+ ) ;
826
865
} ,
827
866
} ) ;
828
867
}
@@ -1063,73 +1102,41 @@ export class Kernel {
1063
1102
return typeInfo ;
1064
1103
}
1065
1104
1066
- private _toSandbox ( v : any , expectedType : wire . OptionalValueOrVoid ) : any {
1067
- const serTypes = wire . serializationType (
1105
+ private _toSandbox (
1106
+ v : any ,
1107
+ expectedType : wire . OptionalValueOrVoid ,
1108
+ context : string ,
1109
+ ) : any {
1110
+ return wire . process (
1111
+ {
1112
+ objects : this . objects ,
1113
+ debug : this . _debug . bind ( this ) ,
1114
+ findSymbol : this . _findSymbol . bind ( this ) ,
1115
+ lookupType : this . _typeInfoForFqn . bind ( this ) ,
1116
+ } ,
1117
+ 'deserialize' ,
1118
+ v ,
1068
1119
expectedType ,
1069
- this . _typeInfoForFqn . bind ( this ) ,
1070
- ) ;
1071
- this . _debug ( 'toSandbox' , v , JSON . stringify ( serTypes ) ) ;
1072
-
1073
- const host : wire . SerializerHost = {
1074
- objects : this . objects ,
1075
- debug : this . _debug . bind ( this ) ,
1076
- findSymbol : this . _findSymbol . bind ( this ) ,
1077
- lookupType : this . _typeInfoForFqn . bind ( this ) ,
1078
- recurse : this . _toSandbox . bind ( this ) ,
1079
- } ;
1080
-
1081
- const errors = new Array < string > ( ) ;
1082
- for ( const { serializationClass, typeRef } of serTypes ) {
1083
- try {
1084
- return wire . SERIALIZERS [ serializationClass ] . deserialize (
1085
- v ,
1086
- typeRef ,
1087
- host ,
1088
- ) ;
1089
- } catch ( e : any ) {
1090
- // If no union (99% case), rethrow immediately to preserve stack trace
1091
- if ( serTypes . length === 1 ) {
1092
- throw e ;
1093
- }
1094
- errors . push ( e . message ) ;
1095
- }
1096
- }
1097
-
1098
- throw new Error (
1099
- `Value did not match any type in union: ${ errors . join ( ', ' ) } ` ,
1120
+ context ,
1100
1121
) ;
1101
1122
}
1102
1123
1103
- private _fromSandbox ( v : any , targetType : wire . OptionalValueOrVoid ) : any {
1104
- const serTypes = wire . serializationType (
1124
+ private _fromSandbox (
1125
+ v : any ,
1126
+ targetType : wire . OptionalValueOrVoid ,
1127
+ context : string ,
1128
+ ) : any {
1129
+ return wire . process (
1130
+ {
1131
+ objects : this . objects ,
1132
+ debug : this . _debug . bind ( this ) ,
1133
+ findSymbol : this . _findSymbol . bind ( this ) ,
1134
+ lookupType : this . _typeInfoForFqn . bind ( this ) ,
1135
+ } ,
1136
+ 'serialize' ,
1137
+ v ,
1105
1138
targetType ,
1106
- this . _typeInfoForFqn . bind ( this ) ,
1107
- ) ;
1108
- this . _debug ( 'fromSandbox' , v , JSON . stringify ( serTypes ) ) ;
1109
-
1110
- const host : wire . SerializerHost = {
1111
- objects : this . objects ,
1112
- debug : this . _debug . bind ( this ) ,
1113
- findSymbol : this . _findSymbol . bind ( this ) ,
1114
- lookupType : this . _typeInfoForFqn . bind ( this ) ,
1115
- recurse : this . _fromSandbox . bind ( this ) ,
1116
- } ;
1117
-
1118
- const errors = new Array < string > ( ) ;
1119
- for ( const { serializationClass, typeRef } of serTypes ) {
1120
- try {
1121
- return wire . SERIALIZERS [ serializationClass ] . serialize ( v , typeRef , host ) ;
1122
- } catch ( e : any ) {
1123
- // If no union (99% case), rethrow immediately to preserve stack trace
1124
- if ( serTypes . length === 1 ) {
1125
- throw e ;
1126
- }
1127
- errors . push ( e . message ) ;
1128
- }
1129
- }
1130
-
1131
- throw new Error (
1132
- `Value did not match any type in union: ${ errors . join ( ', ' ) } ` ,
1139
+ context ,
1133
1140
) ;
1134
1141
}
1135
1142
@@ -1148,7 +1155,7 @@ export class Kernel {
1148
1155
private _boxUnboxParameters (
1149
1156
xs : any [ ] ,
1150
1157
parameters : spec . Parameter [ ] | undefined ,
1151
- boxUnbox : ( x : any , t : wire . OptionalValueOrVoid ) => any ,
1158
+ boxUnbox : ( x : any , t : wire . OptionalValueOrVoid , context : string ) => any ,
1152
1159
) {
1153
1160
parameters = [ ...( parameters ?? [ ] ) ] ;
1154
1161
const variadic =
@@ -1166,7 +1173,9 @@ export class Kernel {
1166
1173
} )`,
1167
1174
) ;
1168
1175
}
1169
- return xs . map ( ( x , i ) => boxUnbox ( x , parameters ! [ i ] ) ) ;
1176
+ return xs . map ( ( x , i ) =>
1177
+ boxUnbox ( x , parameters ! [ i ] , `of parameter ${ parameters ! [ i ] . name } ` ) ,
1178
+ ) ;
1170
1179
}
1171
1180
1172
1181
private _debug ( ...args : any [ ] ) {
0 commit comments