iOS模拟器JS错误仅提醒lineno为0

发布于 2025-01-04 13:45:06 字数 1670 浏览 4 评论 0原文

在 iOS 模拟器中运行项目时,XCode 是否会压缩/缩小 JS?我正在尝试使用 jQuery 调试 JS 文件,在 iOS 模拟器中获取错误数据的方法之一如下:

$(window).error(function(err) {  
    alert('Msg: ' + err.originalEvent.message + ' | Lno: ' + err.originalEvent.lineno);  
}):  

问题是唯一发出警报的行号是 0。消息属性工作正常。当我使用桌面浏览器在桌面上运行相同的代码时,我可以毫无问题地获取原始事件对象的 lineno 属性,因此我猜测 XCode 在构建项目时对我的 JS 做了一些操作。

有什么办法可以关掉这个吗?


经过更多调试(并使用此线程中的 printObject 函数:打印 JavaScript 对象的内容?< /a>),看来大多数错误对象的属性在 iOS 模拟器中都可用。然而,出于某种原因,lineno 的值始终只有 0。

这全部来自 iOS 模拟器的 JS 错误对象:

message: ReferenceError: Can't find variable: URL  
lineno: 0  
returnValue: true  
timeStamp: 1328890716292  
eventPhase: 2  
target: [object DOMWindow]  
defaultPrevented: false  
srcElement: [object DOMWindow]  
type: error  
clipboardData: undefined  
cancelable: true  
currentTarget: [object DOMWindow]  
bubbles: false  
cancelBubble: false  
initErrorEvent: function initErrorEvent() {  
    [native code]  
}  
preventDefault: function preventDefault() {  
    [native code]  
}  
initEvent: function initEvent() {  
    [native code]  
}  
stopPropagation: function stopPropagation() {  
    [native code]  
}  
stopImmediatePropagation: function stopImmediatePropagation() {  
    [native code]  
}  
MOUSEOUT: 8  
FOCUS: 4096  
CHANGE: 32768  
MOUSEMOVE: 16  
AT_TARGET: 2  
SELECT: 16384  
BLUR: 8192  
KEYUP: 512  
MOUSEDOWN: 1  
MOUSEDRAG: 32  
BUBBLING_PHASE: 3  
MOUSEUP: 2  
CAPTURING_PHASE: 1  
MOUSEOVER: 4  
CLICK: 64  
DBLCLICK: 128  
KEYDOWN: 256  
KEYPRESS: 1024  
DRAGDROP: 2048 

Does XCode compress/minify JS when running a project in the iOS Simulator? I'm trying to debug a JS file using jQuery, and one of the ways I get at error data in the iOS Simulator is like this:

$(window).error(function(err) {  
    alert('Msg: ' + err.originalEvent.message + ' | Lno: ' + err.originalEvent.lineno);  
}):  

The problem is that the only line number alerted is 0. The message property works fine. When I run the same code on my desktop using a desktop browser, I can get at the lineno property of the originalEvent object without issue, so I'm guessing XCode does something to my JS when it builds the project.

Any way to turn this off?


After a bit more debugging (and using the printObject function from this thread: Print content of JavaScript object?), it appears that most of the error object's properties are available in the iOS Simulator. For some reason, lineno only ever has a value of 0, however.

This is all from the iOS Simulator's JS error object:

message: ReferenceError: Can't find variable: URL  
lineno: 0  
returnValue: true  
timeStamp: 1328890716292  
eventPhase: 2  
target: [object DOMWindow]  
defaultPrevented: false  
srcElement: [object DOMWindow]  
type: error  
clipboardData: undefined  
cancelable: true  
currentTarget: [object DOMWindow]  
bubbles: false  
cancelBubble: false  
initErrorEvent: function initErrorEvent() {  
    [native code]  
}  
preventDefault: function preventDefault() {  
    [native code]  
}  
initEvent: function initEvent() {  
    [native code]  
}  
stopPropagation: function stopPropagation() {  
    [native code]  
}  
stopImmediatePropagation: function stopImmediatePropagation() {  
    [native code]  
}  
MOUSEOUT: 8  
FOCUS: 4096  
CHANGE: 32768  
MOUSEMOVE: 16  
AT_TARGET: 2  
SELECT: 16384  
BLUR: 8192  
KEYUP: 512  
MOUSEDOWN: 1  
MOUSEDRAG: 32  
BUBBLING_PHASE: 3  
MOUSEUP: 2  
CAPTURING_PHASE: 1  
MOUSEOVER: 4  
CLICK: 64  
DBLCLICK: 128  
KEYDOWN: 256  
KEYPRESS: 1024  
DRAGDROP: 2048 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

贱人配狗天长地久 2025-01-11 13:45:06

Javascript 是一种解释性语言,它不需要像传统编译语言那样“构建”。所以不,XCode 不会(或不应该)对您的 JS 代码执行任何操作。

问题可能在于 IOS(或者至少是 IOS 模拟器)查看代码的方式。桌面浏览器和移动浏览器之间存在差异,并且为了简单起见,您不太可能像在功能更强大的设备上那样深入了解错误日志。

Javascript is an interpreted language, and it doesn't need to 'build' as do traditional compiled languages. So no, XCode is not doing (or shouldn't be doing) anything to your JS code.

The problem likely lies in the way the IOS, or at least the IOS Simulator, views your code. There are discrepancies in a desktop browser and a mobile browser, and, for the sake of simplicity, you will not likely get as in-depth of an error log as you would on a more powerful device.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文