@@ -916,7 +916,10 @@ const tests = {
916
916
'Field decorators: Shim (instance field)' : ( ) => {
917
917
let log = [ ] ;
918
918
const dec = ( value , ctx ) => {
919
- return ( x ) => log . push ( x ) ;
919
+ return function ( x ) {
920
+ assertEq ( ( ) => this instanceof Foo , true ) ;
921
+ return log . push ( 'foo' in this , 'bar' in this , x ) ;
922
+ } ;
920
923
} ;
921
924
class Foo {
922
925
@dec
@@ -926,40 +929,43 @@ const tests = {
926
929
}
927
930
assertEq ( ( ) => log + '' , '' ) ;
928
931
var obj = new Foo ;
929
- assertEq ( ( ) => obj . foo , 1 ) ;
930
- assertEq ( ( ) => obj . bar , 2 ) ;
931
- assertEq ( ( ) => log + '' , '123,' ) ;
932
- var obj = new Foo ;
933
932
assertEq ( ( ) => obj . foo , 3 ) ;
934
- assertEq ( ( ) => obj . bar , 4 ) ;
935
- assertEq ( ( ) => log + '' , '123, ,123,' ) ;
933
+ assertEq ( ( ) => obj . bar , 6 ) ;
934
+ assertEq ( ( ) => log + '' , 'false,false ,123,true,false ,' ) ;
936
935
} ,
937
936
'Field decorators: Shim (static field)' : ( ) => {
937
+ let foo ;
938
938
let log = [ ] ;
939
939
const dec = ( value , ctx ) => {
940
- return ( x ) => log . push ( x ) ;
941
- } ;
942
- const fn = ( foo , bar ) => {
943
- class Foo {
944
- @dec
945
- static foo = 123 ;
946
- @dec
947
- static bar ;
948
- }
949
- assertEq ( ( ) => Foo . foo , foo ) ;
950
- assertEq ( ( ) => Foo . bar , bar ) ;
940
+ return function ( x ) {
941
+ assertEq ( ( ) => this , foo ) ;
942
+ return log . push ( 'foo' in this , 'bar' in this , x ) ;
943
+ } ;
951
944
} ;
952
945
assertEq ( ( ) => log + '' , '' ) ;
953
- fn ( 1 , 2 ) ;
954
- assertEq ( ( ) => log + '' , '123,' ) ;
955
- fn ( 3 , 4 ) ;
956
- assertEq ( ( ) => log + '' , '123,,123,' ) ;
946
+ class Foo {
947
+ static {
948
+ foo = Foo ;
949
+ }
950
+ @dec
951
+ static foo = 123 ;
952
+ @dec
953
+ static bar ;
954
+ }
955
+ assertEq ( ( ) => Foo . foo , 3 ) ;
956
+ assertEq ( ( ) => Foo . bar , 6 ) ;
957
+ assertEq ( ( ) => log + '' , 'false,false,123,true,false,' ) ;
957
958
} ,
958
959
'Field decorators: Shim (private instance field)' : ( ) => {
959
960
let log = [ ] ;
960
961
const dec = ( value , ctx ) => {
961
- return ( x ) => log . push ( x ) ;
962
+ return function ( x ) {
963
+ assertEq ( ( ) => this instanceof Foo , true ) ;
964
+ return log . push ( has$foo ( this ) , has$bar ( this ) , x ) ;
965
+ } ;
962
966
} ;
967
+ let has$foo ;
968
+ let has$bar ;
963
969
let get$foo ;
964
970
let get$bar ;
965
971
class Foo {
@@ -968,46 +974,48 @@ const tests = {
968
974
@dec
969
975
#bar;
970
976
static {
977
+ has$foo = x => #foo in x ;
978
+ has$bar = x => #bar in x ;
971
979
get$foo = x => x . #foo;
972
980
get$bar = x => x . #bar;
973
981
}
974
982
}
975
983
assertEq ( ( ) => log + '' , '' ) ;
976
984
var obj = new Foo ;
977
- assertEq ( ( ) => get$foo ( obj ) , 1 ) ;
978
- assertEq ( ( ) => get$bar ( obj ) , 2 ) ;
979
- assertEq ( ( ) => log + '' , '123,' ) ;
980
- var obj = new Foo ;
981
985
assertEq ( ( ) => get$foo ( obj ) , 3 ) ;
982
- assertEq ( ( ) => get$bar ( obj ) , 4 ) ;
983
- assertEq ( ( ) => log + '' , '123, ,123,' ) ;
986
+ assertEq ( ( ) => get$bar ( obj ) , 6 ) ;
987
+ assertEq ( ( ) => log + '' , 'false,false ,123,true,false ,' ) ;
984
988
} ,
985
989
'Field decorators: Shim (private static field)' : ( ) => {
990
+ let foo ;
986
991
let log = [ ] ;
987
992
const dec = ( value , ctx ) => {
988
- return ( x ) => log . push ( x ) ;
989
- } ;
990
- const fn = ( foo , bar ) => {
991
- let get$foo ;
992
- let get$bar ;
993
- class Foo {
994
- @dec
995
- static #foo = 123 ;
996
- @dec
997
- static #bar;
998
- static {
999
- get$foo = x => x . #foo;
1000
- get$bar = x => x . #bar;
1001
- }
1002
- }
1003
- assertEq ( ( ) => get$foo ( Foo ) , foo ) ;
1004
- assertEq ( ( ) => get$bar ( Foo ) , bar ) ;
993
+ return function ( x ) {
994
+ assertEq ( ( ) => this , foo ) ;
995
+ return log . push ( has$foo ( this ) , has$bar ( this ) , x ) ;
996
+ } ;
1005
997
} ;
1006
998
assertEq ( ( ) => log + '' , '' ) ;
1007
- fn ( 1 , 2 ) ;
1008
- assertEq ( ( ) => log + '' , '123,' ) ;
1009
- fn ( 3 , 4 ) ;
1010
- assertEq ( ( ) => log + '' , '123,,123,' ) ;
999
+ let has$foo ;
1000
+ let has$bar ;
1001
+ let get$foo ;
1002
+ let get$bar ;
1003
+ class Foo {
1004
+ static {
1005
+ foo = Foo ;
1006
+ has$foo = x => #foo in x ;
1007
+ has$bar = x => #bar in x ;
1008
+ get$foo = x => x . #foo;
1009
+ get$bar = x => x . #bar;
1010
+ }
1011
+ @dec
1012
+ static #foo = 123 ;
1013
+ @dec
1014
+ static #bar;
1015
+ }
1016
+ assertEq ( ( ) => get$foo ( Foo ) , 3 ) ;
1017
+ assertEq ( ( ) => get$bar ( Foo ) , 6 ) ;
1018
+ assertEq ( ( ) => log + '' , 'false,false,123,true,false,' ) ;
1011
1019
} ,
1012
1020
'Field decorators: Order (instance field)' : ( ) => {
1013
1021
const log = [ ] ;
@@ -2386,7 +2394,10 @@ const tests = {
2386
2394
let get ;
2387
2395
let set ;
2388
2396
const dec = ( target , ctx ) => {
2389
- const init = ( x ) => x + 1 ;
2397
+ function init ( x ) {
2398
+ assertEq ( ( ) => this instanceof Foo , true ) ;
2399
+ return x + 1 ;
2400
+ }
2390
2401
get = function ( ) { return target . get . call ( this ) * 10 ; } ;
2391
2402
set = function ( x ) { target . set . call ( this , x * 2 ) ; } ;
2392
2403
return { get, set, init } ;
@@ -2403,15 +2414,22 @@ const tests = {
2403
2414
assertEq ( ( ) => obj . foo , ( 321 * 2 ) * 10 ) ;
2404
2415
} ,
2405
2416
'Auto-accessor decorators: Shim (static auto-accessor)' : ( ) => {
2417
+ let foo ;
2406
2418
let get ;
2407
2419
let set ;
2408
2420
const dec = ( target , ctx ) => {
2409
- const init = ( x ) => x + 1 ;
2421
+ function init ( x ) {
2422
+ assertEq ( ( ) => this , foo ) ;
2423
+ return x + 1 ;
2424
+ }
2410
2425
get = function ( ) { return target . get . call ( this ) * 10 ; } ;
2411
2426
set = function ( x ) { target . set . call ( this , x * 2 ) ; } ;
2412
2427
return { get, set, init } ;
2413
2428
} ;
2414
2429
class Foo {
2430
+ static {
2431
+ foo = Foo ;
2432
+ }
2415
2433
@dec
2416
2434
static accessor foo = 123 ;
2417
2435
}
@@ -2425,7 +2443,10 @@ const tests = {
2425
2443
let get ;
2426
2444
let set ;
2427
2445
const dec = ( target , ctx ) => {
2428
- const init = ( x ) => x + 1 ;
2446
+ function init ( x ) {
2447
+ assertEq ( ( ) => this instanceof Foo , true ) ;
2448
+ return x + 1 ;
2449
+ }
2429
2450
get = function ( ) { return target . get . call ( this ) * 10 ; } ;
2430
2451
set = function ( x ) { target . set . call ( this , x * 2 ) ; } ;
2431
2452
return { get, set, init } ;
@@ -2446,23 +2467,28 @@ const tests = {
2446
2467
assertEq ( ( ) => get$foo ( obj ) , ( 321 * 2 ) * 10 ) ;
2447
2468
} ,
2448
2469
'Auto-accessor decorators: Shim (private static auto-accessor)' : ( ) => {
2470
+ let foo ;
2449
2471
let get ;
2450
2472
let set ;
2451
2473
const dec = ( target , ctx ) => {
2452
- const init = ( x ) => x + 1 ;
2474
+ function init ( x ) {
2475
+ assertEq ( ( ) => this , foo ) ;
2476
+ return x + 1 ;
2477
+ }
2453
2478
get = function ( ) { return target . get . call ( this ) * 10 ; } ;
2454
2479
set = function ( x ) { target . set . call ( this , x * 2 ) ; } ;
2455
2480
return { get, set, init } ;
2456
2481
} ;
2457
2482
let get$foo ;
2458
2483
let set$foo ;
2459
2484
class Foo {
2460
- @dec
2461
- static accessor #foo = 123 ;
2462
2485
static {
2486
+ foo = Foo ;
2463
2487
get$foo = x => x . #foo;
2464
2488
set$foo = ( x , y ) => { x . #foo = y ; } ;
2465
2489
}
2490
+ @dec
2491
+ static accessor #foo = 123 ;
2466
2492
}
2467
2493
assertEq ( ( ) => get$foo ( Foo ) , ( 123 + 1 ) * 10 ) ;
2468
2494
assertEq ( ( ) => set$foo ( Foo , 321 ) , undefined ) ;
0 commit comments