0

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 
Community
  • 1
  • 1
Jeff
  • 51
  • 4

1 Answers1

0

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.

Jeffrey Sweeney
  • 5,986
  • 5
  • 24
  • 32
  • That makes sense, and is likely why the lineno property is viewed by the iOS Simulator as '0' rather than '1' (1 would likely mean the JS is compressed, and all on 1 line, like when viewing minified JS in Firebug on your desktop). It likely doesn't exist in the iOS Simulator, so jQuery just returns a value of '0'. – Jeff Feb 10 '12 at 15:43
  • Quick testing reveals that either using the jQuery event I posted above, or straight JS (window.onerror) both yield the same results; line number in Chrome/desktop, no line number in iOS Simulator. Anyone know of a way to get the line number in JS in the iOS Simulator? Xcode's debugger doesn't log anything, but it does look like the standard Safari debugger does report line numbers: https://developer.apple.com/library/IOs/#documentation/AppleApplications/Reference/SafariWebContent/DebuggingSafarioniPhoneContent/DebuggingSafarioniPhoneContent.html Any way to access this via JS? – Jeff Feb 10 '12 at 16:03
  • Unfortunately, it just sounds like a limitation of the IOS browser. The fact that that developer site shows everything on line 1 makes me even more pessimistic. Sorry :| – Jeffrey Sweeney Feb 10 '12 at 16:08