Suppose there is a piece of JavaScript code that is supported by different browsers, for example IE and Firefox. Would the JavaScript parsers of the different browsers generate the same output (i.e., the same AST)?
+2
A:
Would the JavaScript parsers of the different browsers generate the same output
No, Not always, different browser have different javascript Parser, IE have JScript Engine and Mozilla have its own Javascript Engine.
For example, if you run following code
'x'.split(/(x)/).length
Firefox return 3, while IE return 0
See
- http://en.wikipedia.org/wiki/JavaScript_engine for more info
S.Mark
2010-05-13 04:32:33
Hi Mark, Codeka:Wondering the different results of your guys' examples are caused by the difference of their interpreters or their parsers?
Paul
2010-05-13 04:38:04
S.Marks' differences comes from a different implementation of the split() function, so you could say that's in the standard library. Mine would be because of a difference in the parser (i.e. assigning a different meaning to the token 'e')
Dean Harding
2010-05-13 04:43:44
+2
A:
Theoretically yes, but in practise they don't. For example the following code is treated slightly different in IE vs. Firefox:
var e = 10;
try
{
e.something();
}
catch (e)
{
}
alert(e);
IE will print "[object]" whereas other browsers will print "10" because browsers other than IE assume the catch clause is a "local" variable and a different scope to the outer scope.
Dean Harding
2010-05-13 04:33:44