@@ -621,6 +621,7 @@ builtinScriptlets.push({
621
621
name : 'object-prune.fn' ,
622
622
fn : objectPrune ,
623
623
dependencies : [
624
+ 'get-extra-args.fn' ,
624
625
'matches-stack-trace.fn' ,
625
626
'pattern-to-regex.fn' ,
626
627
] ,
@@ -641,18 +642,24 @@ function objectPrune(
641
642
const prunePaths = rawPrunePaths !== ''
642
643
? rawPrunePaths . split ( / + / )
643
644
: [ ] ;
645
+ const extraArgs = getExtraArgs ( Array . from ( arguments ) , 4 ) ;
644
646
let needlePaths ;
645
647
let log , reLogNeedle ;
646
648
if ( prunePaths . length !== 0 ) {
647
649
needlePaths = prunePaths . length !== 0 && rawNeedlePaths !== ''
648
650
? rawNeedlePaths . split ( / + / )
649
651
: [ ] ;
652
+ if ( extraArgs . log !== undefined ) {
653
+ log = console . log . bind ( console ) ;
654
+ reLogNeedle = patternToRegex ( extraArgs . log ) ;
655
+ }
650
656
} else {
651
657
log = console . log . bind ( console ) ;
652
658
reLogNeedle = patternToRegex ( rawNeedlePaths ) ;
653
659
}
654
660
if ( stackNeedle !== '' ) {
655
- if ( matchesStackTrace ( patternToRegex ( stackNeedle ) , log ? '1' : 0 ) === false ) {
661
+ const reStackNeedle = patternToRegex ( stackNeedle ) ;
662
+ if ( matchesStackTrace ( reStackNeedle , extraArgs . logstack ) === false ) {
656
663
return obj ;
657
664
}
658
665
}
@@ -816,6 +823,7 @@ builtinScriptlets.push({
816
823
name : 'matches-stack-trace.fn' ,
817
824
fn : matchesStackTrace ,
818
825
dependencies : [
826
+ 'get-exception-token.fn' ,
819
827
'safe-self.fn' ,
820
828
] ,
821
829
} ) ;
@@ -855,9 +863,9 @@ function matchesStackTrace(
855
863
const stack = lines . join ( '\t' ) ;
856
864
const r = safe . RegExp_test . call ( reNeedle , stack ) ;
857
865
if (
858
- logLevel === '1' ||
859
- logLevel === '2' && r ||
860
- logLevel === '3' && ! r
866
+ logLevel === 1 ||
867
+ logLevel === 2 && r ||
868
+ logLevel === 3 && ! r
861
869
) {
862
870
safe . uboLog ( stack . replace ( / \t / g, '\n' ) ) ;
863
871
}
@@ -993,31 +1001,32 @@ builtinScriptlets.push({
993
1001
fn : abortOnStackTrace ,
994
1002
dependencies : [
995
1003
'get-exception-token.fn' ,
1004
+ 'get-extra-args.fn' ,
996
1005
'matches-stack-trace.fn' ,
997
1006
'pattern-to-regex.fn' ,
998
1007
] ,
999
1008
} ) ;
1000
1009
// Status is currently experimental
1001
1010
function abortOnStackTrace (
1002
1011
chain = '' ,
1003
- needle = '' ,
1004
- logLevel = ''
1012
+ needle = ''
1005
1013
) {
1006
1014
if ( typeof chain !== 'string' ) { return ; }
1007
1015
const reNeedle = patternToRegex ( needle ) ;
1016
+ const extraArgs = getExtraArgs ( Array . from ( arguments ) , 2 ) ;
1008
1017
const makeProxy = function ( owner , chain ) {
1009
1018
const pos = chain . indexOf ( '.' ) ;
1010
1019
if ( pos === - 1 ) {
1011
1020
let v = owner [ chain ] ;
1012
1021
Object . defineProperty ( owner , chain , {
1013
1022
get : function ( ) {
1014
- if ( matchesStackTrace ( reNeedle , logLevel ) ) {
1023
+ if ( matchesStackTrace ( reNeedle , extraArgs . log ) ) {
1015
1024
throw new ReferenceError ( getExceptionToken ( ) ) ;
1016
1025
}
1017
1026
return v ;
1018
1027
} ,
1019
1028
set : function ( a ) {
1020
- if ( matchesStackTrace ( reNeedle , logLevel ) ) {
1029
+ if ( matchesStackTrace ( reNeedle , extraArgs . log ) ) {
1021
1030
throw new ReferenceError ( getExceptionToken ( ) ) ;
1022
1031
}
1023
1032
v = a ;
@@ -1136,20 +1145,28 @@ function jsonPrune(
1136
1145
rawNeedlePaths = '' ,
1137
1146
stackNeedle = ''
1138
1147
) {
1148
+ const extraArgs = Array . from ( arguments ) . slice ( 3 ) ;
1139
1149
JSON . parse = new Proxy ( JSON . parse , {
1140
1150
apply : function ( target , thisArg , args ) {
1141
1151
return objectPrune (
1142
1152
Reflect . apply ( target , thisArg , args ) ,
1143
1153
rawPrunePaths ,
1144
1154
rawNeedlePaths ,
1145
- stackNeedle
1155
+ stackNeedle ,
1156
+ ...extraArgs
1146
1157
) ;
1147
1158
} ,
1148
1159
} ) ;
1149
1160
Response . prototype . json = new Proxy ( Response . prototype . json , {
1150
1161
apply : function ( target , thisArg , args ) {
1151
1162
return Reflect . apply ( target , thisArg , args ) . then ( o =>
1152
- objectPrune ( o , rawPrunePaths , rawNeedlePaths , stackNeedle )
1163
+ objectPrune (
1164
+ o ,
1165
+ rawPrunePaths ,
1166
+ rawNeedlePaths ,
1167
+ stackNeedle ,
1168
+ ...extraArgs
1169
+ )
1153
1170
) ;
1154
1171
} ,
1155
1172
} ) ;
0 commit comments