A JavaScript Bug of SpiderMonkey on Firefox

Sometimes running JS directly within the global scope may introduce more unexpected results.

Based one on the very interesting JavaScript Blog of my friend 周愛民 Chou Aiming, a well-known and solid JavaScript developer, I'd like to share his latest study about a failed optimization work with the JavaScript engine, Spider Monkey.

The simple test

Let's test the script below for modern browsers, note that this test is running in global scope.

Test result for other borwsers(IE6+ , Opera, Safari)

    print » foo
    print » bar
    print » wow
    print » false
    print » false

Looks very simple, while Firefox has different opinions...

Test result for Firefox 1.5, 2, and 3

    print » wow
    print » wow
    print » wow
    print » true
    print » true

You may test the same script for yoursels, just make sure that you're running this directly in your web pages instead of the Firebug console

One possible hacky fix for SpiderMonkey...

or another possible hacky fix for SpiderMonkey..

Whew!

Hedger Wang