New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crashing in Javascript Core when setTimeout() is used #905

Closed
bdkjones opened this Issue Mar 8, 2013 · 11 comments

Comments

Projects
None yet
3 participants
@bdkjones

bdkjones commented Mar 8, 2013

Bryan here; guy behind CodeKit. I've tracked down an issue that I believe is attributable to JSHint. However, the explanation behind it is incredibly complicated so please bear with me.

Here's a screenshot of some Javascript code:

Screen Shot 2013-03-07 at 16 37 35

SUMMARY

See the two commented-out lines? Well, when I uncomment them, JSHint throws an exception when run in Javascript Core and fails to run. As soon as I comment the lines out, JSHint runs fine.

JSLint does not show the same problem; it runs correctly regardless of whether these lines are commented out. This indicates to me that Javascript Core is not the likely cause, since I can isolate the crash to JSHint exclusively.

The interesting part is that if I copy/paste the entire code into the textbox at JSHint.com and run it there, JSHint runs correctly. If I run JSHint on the file from the command line (using node.js), it also runs fine. This implies that there's something going on specifically with JSHint running in Javascript Core --- some sort of incompatibility or issue that only appears when JSHint is running inside Javascript Core.

EXCEPTION INFO

Here's the exception that Javascript Core throws when JSHint crashes on the code above. This is literally all the information it provides:

JavascriptCore Exception thrown: ReferenceError: Can't find variable: console on line 105 of (null)

I don't believe the issue is in my app, since I use the exact same code to run JSLint and that works just fine every time.

CONTENT BETWEEN QUOTES

The plot thickens. If I modify one of these "setTimeout" lines to look like this:

Screen Shot 2013-03-07 at 16 54 57

JSHint now runs correctly. However, as soon as I add any content between those quotation marks (other than a space), the exception is thrown and JSHint fails. Literally anything inside the quotes will do it --- a single letter, a function name, etc.

I've tried all sorts of various edits to these lines and this is what I've narrowed it down to. As long as nothing but spaces appear inside the quotation marks, JSHint runs fine.

EXAMPLE FILES

The link below will take you to Dropbox, where I have posted a zip file containing two files. The first is the exact file as I received it from one of my users, with no changes. The second file is one where I have commented out each "setTimeout" line until I got JSHint to run correctly. You can use a file-difference tool to see the exact lines I commented out.

Link: http://dl.dropbox.com/u/25530182/jsHint_files/files.zip

Please let me know if I can provide any additional information. Thanks for looking into this.

@valueof

This comment has been minimized.

Member

valueof commented Mar 8, 2013

What version of JSHint? I assume something pre-1.0.0 since everything else doesn't support JSC anymore (and that's why it doesn't make sense to compare with JSHint website since the website always uses the latest version).

Do you combine everything on one file? Can you paste a gist of that file somewhere? I checked jshint.js and jsc.js from r12 and there's no usage of console whatsoever.

@bdkjones

This comment has been minimized.

bdkjones commented Mar 8, 2013

I'm using 1.0.0. Also, I'm not running JSHint through the JSC shell. From your docs:

This version removes support for the JavaScriptCore shell due to its limited API. Note that this doesn’t mean that JSHint no longer works in Safari, it simply means that we removed the ability to use jshint via the command line JSC shell.

I'm executing the javascript in jshint.js using the same approach that Safari does; by using the Javascript Core C framework directly in code. I do not go through the shell.

@bdkjones

This comment has been minimized.

bdkjones commented Mar 8, 2013

Just tested with JSHint 1.1.0 (built from a cloned Git repo using the "make.js" file) and it shows the exact same issue.

@bdkjones

This comment has been minimized.

bdkjones commented Mar 8, 2013

I show 5 occurrences of the word "console" in jsHint 1.1.0, built using the "make.js" file. I would bet this is related to the problem.

@bdkjones

This comment has been minimized.

bdkjones commented Mar 8, 2013

Bingo. As suggested by one of my followers here --> https://twitter.com/BenBornschein/status/309935445909839872

If you change the setTimeout line FROM this:

setTimeout("$('#ok_check_share').hide()", 2000);

TO this:

setTimeout(function(){"$('#ok_check_share').hide()"}, 2000);

The issue is resolved and JSHint works correctly! Now the only question left is why the former line causes the exception and brings down JSHint when its running in Javascript Core.

@valueof

This comment has been minimized.

Member

valueof commented Mar 8, 2013

Thanks. Uhm, I'll try to look into it this week. What's the easiest way to run JavaScript through JSC without their shell?

@paulyoung

This comment has been minimized.

paulyoung commented Mar 9, 2013

@bdkjones - in your last comment you have an anonymous function with a string inside it; what happens when you remove the double quotes?

@bdkjones

This comment has been minimized.

bdkjones commented Mar 11, 2013

If you work on a Mac, I can throw together a really simple demo app that will run JSHint with default options and log the output to the console.

@valueof

This comment has been minimized.

Member

valueof commented Mar 11, 2013

That's be really helpful, thanks!

On Sunday, March 10, 2013, bdkjones wrote:

If you work on a Mac, I can throw together a really simple demo app that
will run JSHint with default options and log the output to the console.


Reply to this email directly or view it on GitHubhttps://github.com//issues/905#issuecomment-14695086
.

@bdkjones

This comment has been minimized.

bdkjones commented Mar 11, 2013

Sure thing. I'll need a few days, but should have it for you later this week.

@valueof

This comment has been minimized.

Member

valueof commented Dec 28, 2013

Closing since its been 10 months now with no updates and no further complaints.

@valueof valueof closed this Dec 28, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment