1 Star 0 Fork 9

[SVIP]/博客

forked from mumu/博客 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
stopExecutionOnTimeout.js 2.31 KB
一键复制 编辑 原始数据 按行查看 历史
mumu 提交于 2024-02-27 15:01 +08:00 . update
"use strict";
"object" != typeof window.CP && (window.CP = {}), window.CP.PenTimer = {
programNoLongerBeingMonitored: !1,
timeOfFirstCallToShouldStopLoop: 0,
_loopExits: {},
_loopTimers: {},
START_MONITORING_AFTER: 2e3,
STOP_ALL_MONITORING_TIMEOUT: 5e3,
MAX_TIME_IN_LOOP_WO_EXIT: 2200,
exitedLoop: function (o) {
this._loopExits[o] = !0
},
shouldStopLoop: function (o) {
if (this.programKilledSoStopMonitoring) return !0;
if (this.programNoLongerBeingMonitored) return !1;
if (this._loopExits[o]) return !1;
var t = this._getTime();
if (0 === this.timeOfFirstCallToShouldStopLoop) return this.timeOfFirstCallToShouldStopLoop = t, !1;
var i = t - this.timeOfFirstCallToShouldStopLoop;
if (i < this.START_MONITORING_AFTER) return !1;
if (i > this.STOP_ALL_MONITORING_TIMEOUT) return this.programNoLongerBeingMonitored = !0, !1;
try {
this._checkOnInfiniteLoop(o, t)
} catch (o) {
return this._sendErrorMessageToEditor(), this.programKilledSoStopMonitoring = !0, !0
}
return !1
},
_sendErrorMessageToEditor: function () {
try {
if (this._shouldPostMessage()) {
var o = {
action: "infinite-loop",
line: this._findAroundLineNumber()
};
parent.postMessage(o, "*")
} else this._throwAnErrorToStopPen()
} catch (o) {
this._throwAnErrorToStopPen()
}
},
_shouldPostMessage: function () {
return document.location.href.match(/boomerang/)
},
_throwAnErrorToStopPen: function () {
throw "We found an infinite loop in your Pen. We've stopped the Pen from running. Please correct it or contact support@codepen.io."
},
_findAroundLineNumber: function () {
var o = new Error,
t = 0;
if (o.stack) {
var i = o.stack.match(/boomerang\S+:(\d+):\d+/);
i && (t = i[1])
}
return t
},
_checkOnInfiniteLoop: function (o, t) {
if (!this._loopTimers[o]) return this._loopTimers[o] = t, !1;
var i = t - this._loopTimers[o];
if (i > this.MAX_TIME_IN_LOOP_WO_EXIT) throw "Infinite Loop found on loop: " + o
},
_getTime: function () {
return +new Date
}
}, window.CP.shouldStopExecution = function (o) {
var t = window.CP.PenTimer.shouldStopLoop(o);
return t === !0 && console.warn("[CodePen]: An infinite loop (or a loop taking too long) was detected, so we stopped its execution. Sorry!"), t
}, window.CP.exitedLoop = function (o) {
window.CP.PenTimer.exitedLoop(o)
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/lvjinhui/blog.git
git@gitee.com:lvjinhui/blog.git
lvjinhui
blog
博客
8cdf6d98ef5b00b58f202d013174fb1ad2c86012

搜索帮助