Skip to content

Commit 652a73a

Browse files
committed
修复重复定义JSEbug
1 parent 6f62464 commit 652a73a

File tree

1 file changed

+61
-59
lines changed

1 file changed

+61
-59
lines changed

public/js/common/JSEController.js

Lines changed: 61 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,65 @@
1-
Object.defineProperty(window, 'JSE', {
2-
value: {
3-
InfiniteLoopController: {
4-
_timeConfig: {
5-
maxSumExeTime: 3000, // 每个循环最大累计执行时间
6-
maxLoopCount: 1000000 // 循环最大次数
7-
},
8-
_loopMap: new Map(),
9-
_initLoop (loopID) { // 初始化loop
10-
this._setLoop(loopID, {
11-
isInit: true, // 是否被初始化
12-
sumExeTime: 0, // 该循环执行累计时间
13-
startTime: Date.now(), // 循环开始时间
14-
count: 0 // 循环执行次数
15-
})
16-
},
17-
_getLoop (loopID) {
18-
return this._loopMap.get(loopID)
19-
},
20-
_setLoop (loopID, loop) {
21-
this._loopMap.set(loopID, loop)
22-
},
23-
_delLoop (loopID) {
24-
this._loopMap.delete(loopID)
25-
},
26-
_clearLoops () {
27-
this._loopMap.clear()
28-
},
29-
_exitLoop (loopID) { // 退出循环
30-
this._delLoop(loopID)
31-
},
32-
_calcLoop (loopID) {
33-
if (this._loopMap.has(loopID)) {
34-
let { isInit, sumExeTime, startTime, count } = this._getLoop(loopID)
35-
if (isInit) {
36-
sumExeTime = Date.now() - startTime
37-
count++
38-
this._setLoop(loopID, {
39-
isInit,
40-
sumExeTime,
41-
startTime,
42-
count
43-
})
1+
if (window.hasOwnProperty('JSE')) {
2+
Object.defineProperty(window, 'JSE', {
3+
value: {
4+
InfiniteLoopController: {
5+
_timeConfig: {
6+
maxSumExeTime: 3000, // 每个循环最大累计执行时间
7+
maxLoopCount: 1000000 // 循环最大次数
8+
},
9+
_loopMap: new Map(),
10+
_initLoop (loopID) { // 初始化loop
11+
this._setLoop(loopID, {
12+
isInit: true, // 是否被初始化
13+
sumExeTime: 0, // 该循环执行累计时间
14+
startTime: Date.now(), // 循环开始时间
15+
count: 0 // 循环执行次数
16+
})
17+
},
18+
_getLoop (loopID) {
19+
return this._loopMap.get(loopID)
20+
},
21+
_setLoop (loopID, loop) {
22+
this._loopMap.set(loopID, loop)
23+
},
24+
_delLoop (loopID) {
25+
this._loopMap.delete(loopID)
26+
},
27+
_clearLoops () {
28+
this._loopMap.clear()
29+
},
30+
_exitLoop (loopID) { // 退出循环
31+
this._delLoop(loopID)
32+
},
33+
_calcLoop (loopID) {
34+
if (this._loopMap.has(loopID)) {
35+
let { isInit, sumExeTime, startTime, count } = this._getLoop(loopID)
36+
if (isInit) {
37+
sumExeTime = Date.now() - startTime
38+
count++
39+
this._setLoop(loopID, {
40+
isInit,
41+
sumExeTime,
42+
startTime,
43+
count
44+
})
45+
} else {
46+
this._initLoop(loopID)
47+
}
4448
} else {
4549
this._initLoop(loopID)
4650
}
47-
} else {
48-
this._initLoop(loopID)
49-
}
50-
},
51-
_loopMonitor (loopID) {
52-
this._calcLoop(loopID)
53-
const loop = this._getLoop(loopID)
54-
const { maxSumExeTime, maxLoopCount } = this._timeConfig
55-
// 如果循环次数超过最大次数,并且时间超过最大循环时间,就抛出异常
56-
if (loop.sumExeTime > maxSumExeTime && loop.count > maxLoopCount) {
57-
this._clearLoops()
58-
throw new Error("This loop executes so many times that JS-Encoder have to exit the loop in case the page gets stuck")
59-
}
60-
},
51+
},
52+
_loopMonitor (loopID) {
53+
this._calcLoop(loopID)
54+
const loop = this._getLoop(loopID)
55+
const { maxSumExeTime, maxLoopCount } = this._timeConfig
56+
// 如果循环次数超过最大次数,并且时间超过最大循环时间,就抛出异常
57+
if (loop.sumExeTime > maxSumExeTime && loop.count > maxLoopCount) {
58+
this._clearLoops()
59+
throw new Error("This loop executes so many times that JS-Encoder have to exit the loop in case the page gets stuck")
60+
}
61+
},
62+
}
6163
}
62-
}
63-
})
64+
})
65+
}

0 commit comments

Comments
 (0)