@@ -337,6 +337,48 @@ try test("New Object Construction") {
337
337
try expectEqual ( dog1Bark ( ) , . string( " wan " ) )
338
338
}
339
339
340
+ try test ( " Object Decoding " ) {
341
+ /*
342
+ ```js
343
+ global.objectDecodingTest = {
344
+ obj: {},
345
+ fn: () => {},
346
+ sym: Symbol("s"),
347
+ bi: BigInt(3)
348
+ };
349
+ ```
350
+ */
351
+ let js : JSValue = JSObject . global. objectDecodingTest
352
+
353
+ // I can't use regular name like `js.object` here
354
+ // cz its conflicting with case name and DML.
355
+ // so I use abbreviated names
356
+ let object : JSValue = js. obj
357
+ let function : JSValue = js. fn
358
+ let symbol : JSValue = js. sym
359
+ let bigInt : JSValue = js. bi
360
+
361
+ try expectNotNil ( JSObject . construct ( from: object) )
362
+ try expectEqual ( JSObject . construct ( from: function) . map { $0 is JSFunction } , . some( true ) )
363
+ try expectEqual ( JSObject . construct ( from: symbol) . map { $0 is JSSymbol } , . some( true ) )
364
+ try expectEqual ( JSObject . construct ( from: bigInt) . map { $0 is JSBigInt } , . some( true ) )
365
+
366
+ try expectNil ( JSFunction . construct ( from: object) )
367
+ try expectNotNil ( JSFunction . construct ( from: function) )
368
+ try expectNil ( JSFunction . construct ( from: symbol) )
369
+ try expectNil ( JSFunction . construct ( from: bigInt) )
370
+
371
+ try expectNil ( JSSymbol . construct ( from: object) )
372
+ try expectNil ( JSSymbol . construct ( from: function) )
373
+ try expectNotNil ( JSSymbol . construct ( from: symbol) )
374
+ try expectNil ( JSSymbol . construct ( from: bigInt) )
375
+
376
+ try expectNil ( JSBigInt . construct ( from: object) )
377
+ try expectNil ( JSBigInt . construct ( from: function) )
378
+ try expectNil ( JSBigInt . construct ( from: symbol) )
379
+ try expectNotNil ( JSBigInt . construct ( from: bigInt) )
380
+ }
381
+
340
382
try test ( " Call Function With This " ) {
341
383
// ```js
342
384
// global.Animal = function(name, age, isCat) {
0 commit comments