@@ -106,49 +106,40 @@ function __spreadArray(to, from, pack) {
106
106
return to . concat ( ar || Array . prototype . slice . call ( from ) ) ;
107
107
}
108
108
109
- function getCache ( obj , fnName ) {
109
+ function isEqualArgs ( args , cacheArgs , equals ) {
110
+ if ( ! cacheArgs ) {
111
+ return false ;
112
+ }
113
+ if ( args . length === 0 && cacheArgs . length === 0 ) {
114
+ return true ;
115
+ }
116
+ return ( args . length === cacheArgs . length &&
117
+ cacheArgs . every ( function ( arg , index ) { var _a , _b ; return ( _b = ( _a = equals === null || equals === void 0 ? void 0 : equals [ index ] ) === null || _a === void 0 ? void 0 : _a . call ( equals , arg , args [ index ] ) ) !== null && _b !== void 0 ? _b : arg === args [ index ] ; } ) ) ;
118
+ }
119
+ function getCacheResult ( thisObj , fnName , args , equals ) {
110
120
var _a ;
111
- return ( _a = obj === null || obj === void 0 ? void 0 : obj . __cache ) === null || _a === void 0 ? void 0 : _a [ fnName ] ;
121
+ var cache = ( _a = thisObj === null || thisObj === void 0 ? void 0 : thisObj . __cache ) === null || _a === void 0 ? void 0 : _a [ fnName ] ;
122
+ if ( cache && isEqualArgs ( args , cache . args , equals ) ) {
123
+ return cache . result ;
124
+ }
112
125
}
113
- function createCache ( obj , fnName , args ) {
114
- if ( ! obj . __cache ) {
115
- obj . __cache = { } ;
126
+ function cache ( fn , args , thisObj , fnName , equals ) {
127
+ var result = getCacheResult ( thisObj , fnName , args , equals ) ;
128
+ if ( result ) {
129
+ return result . value ;
116
130
}
117
- obj . __cache [ fnName ] = {
131
+ var cache = {
118
132
id : Symbol ( "id" ) ,
119
133
args : args ,
120
- isInProgress : true ,
121
134
time : Date . now ( ) ,
122
135
} ;
123
- return getCache ( obj , fnName ) ;
124
- }
125
- function genCache ( fn , args , thisObj , fnName ) {
126
- var cache = createCache ( thisObj , fnName , args ) ;
127
- var value = fn . apply ( thisObj , args ) ;
128
- cache . isInProgress = false ;
129
- cache . value = value ;
130
- }
131
- function read ( thisObj , fnName ) {
132
- var cache = getCache ( thisObj , fnName ) ;
133
- return cache && cache . value ;
134
- }
135
- function hitCache ( args , thisObj , fnName , equals ) {
136
- var cache = getCache ( thisObj , fnName ) ;
137
- if ( ! cache || ! cache . args )
138
- return false ;
139
- if ( args . length === 0 && cache . args . length === 0 )
140
- return true ;
141
- return cache . args . every ( function ( arg , index ) { var _a , _b ; return ( _b = ( _a = equals === null || equals === void 0 ? void 0 : equals [ index ] ) === null || _a === void 0 ? void 0 : _a . call ( equals , arg , args [ index ] ) ) !== null && _b !== void 0 ? _b : arg === args [ index ] ; } ) ;
142
- }
143
- function isCyclic ( thisObj , fnName ) {
144
- var cache = getCache ( thisObj , fnName ) ;
145
- return cache && cache . isInProgress ;
146
- }
147
- function cache ( fn , args , thisObj , fnName , equals ) {
148
- if ( ! hitCache ( args , thisObj , fnName , equals ) && ! isCyclic ( thisObj , fnName ) ) {
149
- genCache ( fn , args , thisObj , fnName ) ;
136
+ if ( ! thisObj . __cache ) {
137
+ thisObj . __cache = { } ;
150
138
}
151
- return read ( thisObj , fnName ) ;
139
+ thisObj . __cache [ fnName ] = cache ;
140
+ var value = fn . apply ( thisObj , args ) ;
141
+ cache . result = { value : value } ;
142
+ return value ;
152
143
}
153
144
function memoized ( equals ) {
154
145
return function ( target , fnName , descriptor ) {
@@ -1049,23 +1040,24 @@ var loglevel = {exports: {}};
1049
1040
1050
1041
var log = loglevel . exports ;
1051
1042
1052
- // global variables black list, forbidden to use
1053
- var blacklist = new Set ( [
1043
+ // global variables black list, forbidden to use in for jsQuery/jsAction
1044
+ var functionBlacklist = new Set ( [
1054
1045
"top" ,
1055
1046
"parent" ,
1056
1047
"document" ,
1057
1048
"location" ,
1058
1049
"chrome" ,
1059
- "setTimeout" ,
1060
1050
"fetch" ,
1061
- "setInterval" ,
1062
- "clearInterval" ,
1063
- "setImmediate" ,
1064
1051
"XMLHttpRequest" ,
1065
1052
"importScripts" ,
1066
1053
"Navigator" ,
1067
1054
"MutationObserver" ,
1068
1055
] ) ;
1056
+ var expressionBlacklist = new Set ( __spreadArray ( __spreadArray ( [ ] , Array . from ( functionBlacklist . values ( ) ) , true ) , [
1057
+ "setTimeout" ,
1058
+ "setInterval" ,
1059
+ "setImmediate" ,
1060
+ ] , false ) ) ;
1069
1061
var globalVarNames = new Set ( [ "window" , "globalThis" , "self" , "global" ] ) ;
1070
1062
function createBlackHole ( ) {
1071
1063
return new Proxy ( function ( ) {
@@ -1087,12 +1079,14 @@ function createBlackHole() {
1087
1079
} ,
1088
1080
} ) ;
1089
1081
}
1090
- function createMockWindow ( ) {
1091
- var win = new Proxy ( { } , {
1082
+ function createMockWindow ( base , blacklist ) {
1083
+ if ( blacklist === void 0 ) { blacklist = expressionBlacklist ; }
1084
+ var win = new Proxy ( Object . assign ( { } , base ) , {
1092
1085
has : function ( ) {
1093
1086
return true ;
1094
1087
} ,
1095
1088
set : function ( target , p , newValue ) {
1089
+ console . info ( "set:" , p , newValue ) ;
1096
1090
return Reflect . set ( target , p , newValue ) ;
1097
1091
} ,
1098
1092
get : function ( target , p ) {
@@ -1102,19 +1096,11 @@ function createMockWindow() {
1102
1096
if ( globalVarNames . has ( p ) ) {
1103
1097
return win ;
1104
1098
}
1105
- if ( typeof p === "string" && blacklist . has ( p ) ) {
1099
+ if ( typeof p === "string" && ( blacklist === null || blacklist === void 0 ? void 0 : blacklist . has ( p ) ) ) {
1106
1100
log . log ( "[Sandbox] access " . concat ( String ( p ) , " on mock window, return mock object" ) ) ;
1107
1101
return createBlackHole ( ) ;
1108
1102
}
1109
- var ret = Reflect . get ( window , p ) ;
1110
- if ( typeof ret === "function" && ! ret . prototype ) {
1111
- return ret . bind ( window ) ;
1112
- }
1113
- // get DOM element by id, serializing may cause error
1114
- if ( isDomElement ( ret ) ) {
1115
- return undefined ;
1116
- }
1117
- return ret ;
1103
+ return getPropertyFromNativeWindow ( p ) ;
1118
1104
} ,
1119
1105
} ) ;
1120
1106
return win ;
@@ -1126,12 +1112,26 @@ function clearMockWindow() {
1126
1112
function isDomElement ( obj ) {
1127
1113
return obj instanceof Element || obj instanceof HTMLCollection ;
1128
1114
}
1115
+ function getPropertyFromNativeWindow ( prop ) {
1116
+ var ret = Reflect . get ( window , prop ) ;
1117
+ if ( typeof ret === "function" && ! ret . prototype ) {
1118
+ return ret . bind ( window ) ;
1119
+ }
1120
+ // get DOM element by id, serializing may cause error
1121
+ if ( isDomElement ( ret ) ) {
1122
+ return undefined ;
1123
+ }
1124
+ return ret ;
1125
+ }
1129
1126
function proxySandbox ( context , methods , options ) {
1130
- var _a = ( options || { } ) . disableLimit , disableLimit = _a === void 0 ? false : _a ;
1127
+ var _a = options || { } , _b = _a . disableLimit , disableLimit = _b === void 0 ? false : _b , _c = _a . scope , scope = _c === void 0 ? "expression" : _c ;
1131
1128
var isProtectedVar = function ( key ) {
1132
1129
return key in context || key in ( methods || { } ) || globalVarNames . has ( key ) ;
1133
1130
} ;
1134
1131
var cache = { } ;
1132
+ if ( scope === "function" ) {
1133
+ mockWindow = createMockWindow ( mockWindow , functionBlacklist ) ;
1134
+ }
1135
1135
return new Proxy ( mockWindow , {
1136
1136
has : function ( target , p ) {
1137
1137
// proxy all variables
@@ -1163,7 +1163,7 @@ function proxySandbox(context, methods, options) {
1163
1163
return value ;
1164
1164
}
1165
1165
if ( disableLimit ) {
1166
- return Reflect . get ( window , p ) ;
1166
+ return getPropertyFromNativeWindow ( p ) ;
1167
1167
}
1168
1168
return Reflect . get ( target , p , receiver ) ;
1169
1169
} ,
@@ -1427,6 +1427,7 @@ var DefaultParser = /** @class */ (function () {
1427
1427
function evalJson ( unevaledValue , context ) {
1428
1428
return new RelaxedJsonParser ( unevaledValue , context ) . parse ( ) ;
1429
1429
}
1430
+ // this will also be used in node-service
1430
1431
var RelaxedJsonParser = /** @class */ ( function ( _super ) {
1431
1432
__extends ( RelaxedJsonParser , _super ) ;
1432
1433
function RelaxedJsonParser ( unevaledValue , context ) {
@@ -1503,11 +1504,12 @@ var RelaxedJsonParser = /** @class */ (function (_super) {
1503
1504
} ( DefaultParser ) ) ;
1504
1505
function evalFunction ( unevaledValue , context , methods , isAsync ) {
1505
1506
try {
1506
- return new ValueAndMsg ( function ( args , runInHost ) {
1507
+ return new ValueAndMsg ( function ( args , runInHost , scope ) {
1507
1508
if ( runInHost === void 0 ) { runInHost = false ; }
1509
+ if ( scope === void 0 ) { scope = "function" ; }
1508
1510
return evalFunc ( unevaledValue . startsWith ( "return" )
1509
1511
? unevaledValue + "\n"
1510
- : "return " . concat ( isAsync ? "async " : "" , "function(){'use strict'; " ) . concat ( unevaledValue , "\n}()" ) , args ? __assign ( __assign ( { } , context ) , args ) : context , methods , { disableLimit : runInHost } , isAsync ) ;
1512
+ : "return " . concat ( isAsync ? "async " : "" , "function(){'use strict'; " ) . concat ( unevaledValue , "\n}()" ) , args ? __assign ( __assign ( { } , context ) , args ) : context , methods , { disableLimit : runInHost , scope : scope } , isAsync ) ;
1511
1513
} ) ;
1512
1514
}
1513
1515
catch ( err ) {
@@ -3209,8 +3211,8 @@ function updateNodesV2Action(value) {
3209
3211
value : value ,
3210
3212
} ;
3211
3213
}
3212
- function wrapActionExtraInfo ( action , extraCompInfos ) {
3213
- return __assign ( __assign ( { } , action ) , { extraInfo : { compInfos : extraCompInfos } } ) ;
3214
+ function wrapActionExtraInfo ( action , extraInfos ) {
3215
+ return __assign ( __assign ( { } , action ) , { extraInfo : __assign ( __assign ( { } , action . extraInfo ) , extraInfos ) } ) ;
3214
3216
}
3215
3217
function deferAction ( action ) {
3216
3218
return __assign ( __assign ( { } , action ) , { priority : "defer" } ) ;
@@ -7537,6 +7539,7 @@ exports.FetchCheckNode = FetchCheckNode;
7537
7539
exports . FunctionNode = FunctionNode ;
7538
7540
exports . MultiBaseComp = MultiBaseComp ;
7539
7541
exports . RecordNode = RecordNode ;
7542
+ exports . RelaxedJsonParser = RelaxedJsonParser ;
7540
7543
exports . SimpleAbstractComp = SimpleAbstractComp ;
7541
7544
exports . SimpleComp = SimpleComp ;
7542
7545
exports . SimpleNode = SimpleNode ;
@@ -7558,6 +7561,7 @@ exports.evalFunc = evalFunc;
7558
7561
exports . evalFunctionResult = evalFunctionResult ;
7559
7562
exports . evalNodeOrMinor = evalNodeOrMinor ;
7560
7563
exports . evalPerfUtil = evalPerfUtil ;
7564
+ exports . evalScript = evalScript ;
7561
7565
exports . evalStyle = evalStyle ;
7562
7566
exports . executeQueryAction = executeQueryAction ;
7563
7567
exports . fromRecord = fromRecord ;
0 commit comments