@@ -535,6 +535,8 @@ function validateConstantFn(trusted, raw, extraArgs = {}) {
535
535
value = function ( ) { return true ; } ;
536
536
} else if ( raw === 'falseFunc' ) {
537
537
value = function ( ) { return false ; } ;
538
+ } else if ( raw === 'throwFunc' ) {
539
+ value = function ( ) { throw '' ; } ;
538
540
} else if ( / ^ - ? \d + $ / . test ( raw ) ) {
539
541
value = parseInt ( raw ) ;
540
542
if ( isNaN ( raw ) ) { return ; }
@@ -1498,31 +1500,57 @@ function proxyApplyFn(
1498
1500
const fn = context [ prop ] ;
1499
1501
if ( typeof fn !== 'function' ) { return ; }
1500
1502
if ( proxyApplyFn . CtorContext === undefined ) {
1503
+ proxyApplyFn . ctorContexts = [ ] ;
1501
1504
proxyApplyFn . CtorContext = class {
1502
- constructor ( callFn , callArgs ) {
1505
+ constructor ( ...args ) {
1506
+ this . init ( ...args ) ;
1507
+ }
1508
+ init ( callFn , callArgs ) {
1503
1509
this . callFn = callFn ;
1504
1510
this . callArgs = callArgs ;
1511
+ return this ;
1505
1512
}
1506
1513
reflect ( ) {
1507
- return Reflect . construct ( this . callFn , this . callArgs ) ;
1514
+ const r = Reflect . construct ( this . callFn , this . callArgs ) ;
1515
+ this . callFn = this . callArgs = undefined ;
1516
+ proxyApplyFn . ctorContexts . push ( this ) ;
1517
+ return r ;
1518
+ }
1519
+ static factory ( ...args ) {
1520
+ return proxyApplyFn . ctorContexts . length !== 0
1521
+ ? proxyApplyFn . ctorContexts . pop ( ) . init ( ...args )
1522
+ : new proxyApplyFn . CtorContext ( ...args ) ;
1508
1523
}
1509
1524
} ;
1525
+ proxyApplyFn . applyContexts = [ ] ;
1510
1526
proxyApplyFn . ApplyContext = class {
1511
- constructor ( callFn , thisArg , callArgs ) {
1527
+ constructor ( ...args ) {
1528
+ this . init ( ...args ) ;
1529
+ }
1530
+ init ( callFn , thisArg , callArgs ) {
1512
1531
this . callFn = callFn ;
1513
1532
this . thisArg = thisArg ;
1514
1533
this . callArgs = callArgs ;
1534
+ return this ;
1515
1535
}
1516
1536
reflect ( ) {
1517
- return Reflect . apply ( this . callFn , this . thisArg , this . callArgs ) ;
1537
+ const r = Reflect . apply ( this . callFn , this . thisArg , this . callArgs ) ;
1538
+ this . callFn = this . thisArg = this . callArgs = undefined ;
1539
+ proxyApplyFn . applyContexts . push ( this ) ;
1540
+ return r ;
1541
+ }
1542
+ static factory ( ...args ) {
1543
+ return proxyApplyFn . applyContexts . length !== 0
1544
+ ? proxyApplyFn . applyContexts . pop ( ) . init ( ...args )
1545
+ : new proxyApplyFn . ApplyContext ( ...args ) ;
1518
1546
}
1519
1547
} ;
1520
1548
}
1521
1549
const fnStr = fn . toString ( ) ;
1522
1550
const toString = ( function toString ( ) { return fnStr ; } ) . bind ( null ) ;
1523
1551
const proxyDetails = {
1524
1552
apply ( target , thisArg , args ) {
1525
- return handler ( new proxyApplyFn . ApplyContext ( target , thisArg , args ) ) ;
1553
+ return handler ( proxyApplyFn . ApplyContext . factory ( target , thisArg , args ) ) ;
1526
1554
} ,
1527
1555
get ( target , prop ) {
1528
1556
if ( prop === 'toString' ) { return toString ; }
@@ -1531,7 +1559,7 @@ function proxyApplyFn(
1531
1559
} ;
1532
1560
if ( fn . prototype ?. constructor === fn ) {
1533
1561
proxyDetails . construct = function ( target , args ) {
1534
- return handler ( new proxyApplyFn . CtorContext ( target , args ) ) ;
1562
+ return handler ( proxyApplyFn . CtorContext . factory ( target , args ) ) ;
1535
1563
} ;
1536
1564
}
1537
1565
context [ prop ] = new Proxy ( fn , proxyDetails ) ;
0 commit comments