Safari Mobile (iPad) 上的 Javascript 堆栈检查
我的代码如下所示:
function myEventHandler() {
inMyEventHandler = true;
longRunningStuff();
inMyEventHandler = false;
}
这非常有效,但在 iPad 上,Safari Mobile 偶尔会导致我的 Javascript 超时并出现错误。所以 longRunningStuff() 会死掉,而 inMyEventHandler 永远不会被清除。这是非常糟糕的,因为如果我们在这个函数之外,那么 inMyEventHander 绝对不能被设置,或者发生坏事。
理想情况下,我可以从 longRunningStuff 的深处检查 myEventHandler 是否在调用堆栈中位于其上方,并且这会自行处理。我找不到办法做到这一点...提示?
I have code that looks like this:
function myEventHandler() {
inMyEventHandler = true;
longRunningStuff();
inMyEventHandler = false;
}
This works great, except on the iPad where Safari Mobile occasionally times out my Javascript with an error. So longRunningStuff() dies and inMyEventHandler never gets cleared. This is very bad, because inMyEventHander absolutely cannot be set if we're outside this function, or Bad Things(tm) happen.
Ideally, I could just check from deep within longRunningStuff whether myEventHandler is above it in the call stack, and this would take care of itself. I can't find a way to do that... Hints?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
(最简单)您可以在
longRunningStuff
中检查arguments.callee.caller
:另一个变体:
最长的方法 - 从 https:/ 检索调用堆栈/github.com/eriwen/javascript-stacktrace
(Simplest) You can check
arguments.callee.caller
when inlongRunningStuff
:Another variant:
The longest way - retrieve call stack from https://github.com/eriwen/javascript-stacktrace
多年来我一直使用以下方法来手动检查调用堆栈。我已经有一段时间没有更新它了,也从未在 ipad 或 mobile safari 上尝试过它,所以我不知道它是否适合你。
也许你可以用它来获得灵感:
I have used the following method for years to manually inspect the callstack. I haven't updated it in a while and never tried it on ipad or mobile safari, so whether or not it will even work for you i can't tell.
Maybe you can use it for inspiration:
从 iOS 6 开始,可以使用真正的 Web 检查器。请参阅下文或此链接。 https://stackoverflow.com/a/12762449/72428
更新!!! 在操作系统上X 您可以在 iOS 模拟器和 iOS 6 设备上使用 Safari Web 检查器。
接下来,在您的 iOS 设备(或模拟器)上启用远程调试。
设备(例如 iPhone 模拟器、iPhone)
注意:仅当 Safari 处于活动状态并正在运行时,您才会在“开发人员”菜单中看到您的设备。
享受!
As of iOS 6 a real web inspector is available. See below, or this link. https://stackoverflow.com/a/12762449/72428
Update!!! On OS X you can use the Safari web inspector on the iOS Simulator AND iOS 6 devices.
Next, enable remote debugging on your iOS device (or simulator).
device (e.g. iPhone Simulator, iPhone)
Note: You'll see your device in the Developer menu ONLY when Safari is active and running.
Enjoy!