So am I to take it that the interpreted part is a requirement in the language specification, or is it misleading to say that the language is an interpreted programming language when respecting the difference between a language and its many implementations?

Firefox had just released the first browser-based JIT compiler the year that question was answered in FF 3.5 so it probably wasn't widely known about at the time. I believe modern JITs actually do a lot of compiling (or at least prep for compile) on the first pass of a JS document to do things like identify and cache methods that are isolated to a given scope.
–
Erik ReppenJun 3 '13 at 18:45

3 Answers
3

So am I to take it that the interpreted part is a requirement in the language specification, or is it misleading to say that the language is an interpreted programming language when respecting the difference between a language and its many implementations?

EcmaScript language geeks often use the term "ES interpreter" to refer to an implementation of EcmaScript, but the spec does not use that term. The language overview in particular describes the language in interpreter-agnostic terms:

ECMAScript is object-based: basic language and host facilities are provided by objects, and an ECMAScript program is a cluster of communicating objects.

So EcmaScript assumes a "host environment" which is defined as a provider of object definitions including all those that allow I/O or any other links to the outside world, but does not require an interpreter.

The semantics of statements and expressions in the language are defined in terms of completion specification which are trivially implemented in an interpreter, but the specification does not require that.

8.9 The Completion Specification Type

The Completion type is used to explain the behaviour of statements (break, continue, return and throw) that perform nonlocal transfers of control. Values of the Completion type are triples of the form (type, value, target), where type is one of normal, break, continue, return, or throw, value is any ECMAScript language value or empty, and target is any ECMAScript identifier or empty.

The term “abrupt completion” refers to any completion with a type other than normal.

The non-local transfers of control can be converted to arrays of instructions with jumps allowing for native or byte-code compilation.

There are no static compilers for JavaScript apparently

This is not true. The V8 "interpreter" compiles to native code internally, Rhino optionally compiles to Java bytecode internally, and various Mozilla interpreters ({Trace,Spider,Jager}Monkey) use a JIT compiler.

Set the current optimization level.
The optimization level is expected to be an integer between -1 and 9. Any negative values will be interpreted as -1, and any values greater than 9 will be interpreted as 9. An optimization level of -1 indicates that interpretive mode will always be used. Levels 0 through 9 indicate that class files may be generated. Higher optimization levels trade off compile time performance for runtime performance. The optimizer level can't be set greater than -1 if the optimizer package doesn't exist at run time.

TraceMonkey adds native‐code compilation to Mozilla’s JavaScript® engine (known as “SpiderMonkey”). It is based on a technique developed at UC Irvine called “trace trees”, and building on code and ideas shared with the Tamarin Tracing project. The net result is a massive speed increase both in the browser chrome and Web‐page content.

Thanks for this answer, it actually answers the question. I suppose the final comment about no static compilation is what caused the buzz about which implementations actually compile code and which ones do not. All I was interested in was the validity of the statement "JavaScript is an interpreted language" which, given implementation citations and the lack of definition by the spec, appears to be false. Not encouraging for the second paragraph of a "Definitive Guide", but I guess I will stick with it.
–
Matt EschMar 6 '12 at 18:30

@me232, the statement was substantially true prior to 2008. Rhino pre-dates that but was not a major interpreter and so few would have faulted "the Definitive Guide" at the time for ignoring it. I haven't read the book, so I can't comment on how representative that sentence is of its overall quality.
–
Mike SamuelMar 6 '12 at 20:58

The V8 JavaScript VM used in Chrome doesn't include an interpreter. Instead it consists of two compilers and compiles the code on the fly. One of the compilers runs quickly but generates inefficient code, the other is an optimizing compiler.

I can understand why some people would consider this "cheating", since V8 takes source code as input every time the code runs and the user has to have V8 installed. But consider a compiler which emits an executable which includes a complete interpreter and bytecode. Then you would have a stand-alone program. It just wouldn't be very efficient.

"otherwise you couldn't as simply work with the variables, objects, delegates and other things." - many functional languages have these items and have been compiled for a long time.
–
JettiMar 6 '12 at 16:20

2

Closure Compiler is not for the purpose of compiling JS for execution. It's for minimizing JS code.
–
OrblingMar 6 '12 at 16:41

@Orbling Closure is actually about parsing JS to an AST and turning the AST into optimized JavaScript. It's a full compiler, not just a minifier. It's just that the backend of the closure compiler outputs minified javascript
–
RaynosMar 6 '12 at 18:27

@Raynos: Yes, that's why I carefully worded my expression to say "for execution". As it is not used for that purpose, just for minimizing/optimising.
–
OrblingMar 6 '12 at 19:52