changeset 365:2b61f82350de

Merge
author chegar
date Mon, 10 Jun 2013 09:53:21 +0100
parents ded7168cb008 e3bd0ed64da8
children 12f1d8d74375
files src/jdk/nashorn/internal/objects/DateParser.java src/jdk/nashorn/internal/runtime/options/ValueOption.java src/jdk/nashorn/internal/runtime/regexp/DefaultRegExp.java src/jdk/nashorn/internal/runtime/regexp/joni/AsmCompiler.java src/jdk/nashorn/internal/runtime/regexp/joni/AsmCompilerSupport.java src/jdk/nashorn/internal/runtime/regexp/joni/CaptureTreeNode.java src/jdk/nashorn/internal/runtime/regexp/joni/NameEntry.java src/jdk/nashorn/internal/runtime/regexp/joni/NativeMachine.java src/jdk/nashorn/internal/runtime/regexp/joni/UnsetAddrList.java src/jdk/nashorn/internal/runtime/regexp/joni/ast/CTypeNode.java src/jdk/nashorn/internal/runtime/regexp/joni/ast/CallNode.java src/jdk/nashorn/internal/runtime/regexp/joni/bench/AbstractBench.java src/jdk/nashorn/internal/runtime/regexp/joni/bench/BenchGreedyBacktrack.java src/jdk/nashorn/internal/runtime/regexp/joni/bench/BenchRailsRegs.java src/jdk/nashorn/internal/runtime/regexp/joni/bench/BenchSeveralRegexps.java src/jdk/nashorn/internal/runtime/regexp/joni/constants/Reduce.java src/jdk/nashorn/internal/runtime/regexp/joni/encoding/AsciiTables.java src/jdk/nashorn/internal/runtime/regexp/joni/encoding/PosixBracket.java src/jdk/nashorn/internal/runtime/regexp/joni/encoding/Ptr.java src/netscape/javascript/JSObject.java
diffstat 248 files changed, 7205 insertions(+), 6454 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Fri May 31 10:28:34 2013 +0100
+++ b/.hgignore	Mon Jun 10 09:53:21 2013 +0100
@@ -24,3 +24,4 @@
 .idea/*
 test/lib/testng.jar
 test/script/external/*
+.project
--- a/docs/JavaScriptingProgrammersGuide.html	Fri May 31 10:28:34 2013 +0100
+++ b/docs/JavaScriptingProgrammersGuide.html	Mon Jun 10 09:53:21 2013 +0100
@@ -71,9 +71,20 @@
 Arrays</a></span></li>
 <li><span><a href="#jsimplement">Implementing Java
 Interfaces</a></span></li>
-<li><span><a href="#jsextend">Extending Java classes
+<li><span><a href="#jsextendabstract">Extending Abstract Java Classes
+</a></span></li>
+<li><span><a href="#jsextendconcrete">Extending Concrete Java Classes
+</a></span></li>
+<li><span><a href="#jsimplementmultiple">Implementing Multiple Java Interfaces
+</a></span></li>
+<li><span><a href="#classBoundImplementations">Class-Bound Implementations
 </a></span></li>
 <li><span><a href="#jsoverload">Overload Resolution</a></span></li>
+<li><span><a href="#dataTypeMapping">Mapping of Data Types Between Java
+and JavaScript</a></span></li>
+
+
+
 </ul>
 </li>
 <li><span><a href="#engineimpl">Implementing Your Own Script
@@ -466,10 +477,10 @@
 </code>
 </pre> 
 
-Note that the name of the type is always a string for a fully qualified name. You can use any of these types to create new instances, e.g.:
+Note that the name of the type is always a string for a fully qualified name. You can use any of these expressions to create new instances, e.g.:
 
 <pre><code>
- var anArrayList = new Java.type("java.util.ArrayList")
+ var anArrayList = new (Java.type("java.util.ArrayList"))
 </code></pre> 
 
 or
@@ -496,6 +507,37 @@
 <p>
 You can access both static and non-static inner classes. If you want to create an instance of a non-static inner class, remember to pass an instance of its outer class as the first argument to the constructor.
 </p>
+<p>
+In addition to creating new instances, the type objects returned from <code>Java.type</code> calls can also be used to access the
+static fields and methods of the classes:
+<pre><code>
+ var File = Java.type("java.io.File")
+ File.createTempFile("nashorn", ".tmp")
+</code></pre> 
+<p>
+Methods with names of the form <code>isXxx()</code>, <code>getXxx()</code>, and <code>setXxx()</code> can also be used as properties, for both instances and statics.
+</p>
+<p>
+A type object returned from <code>Java.type</code> is distinct from a <code>java.lang.Class</code> object. You can obtain one from the other using properties <code>class</code> and <code>static</code> on them.
+<pre><code>
+ var ArrayList = Java.type("java.util.ArrayList")
+ var a = new ArrayList
+
+ // All of the following print true:
+ print("Type acts as target of instanceof: " + (a instanceof ArrayList))
+ print("Class doesn't act as target of instanceof: " + !(a instanceof a.getClass()))
+ print("Type is not same as instance's getClass(): " + (a.getClass() !== ArrayList))
+ print("Type's `class` property is same as instance getClass(): " + (a.getClass() === ArrayList.class))
+ print("Type is same as instance getClass()'s `static` property: " + (a.getClass().static === ArrayList))
+</code></pre> 
+<p>
+You can think of the type object as similar to the class names as used in Java source code: you use them as the
+arguments to the <code>new</code> and <code>instanceof</code> operators and as the namespace for the static fields
+and methods, but they are different than the runtime <code>Class</code> objects returned by <code>getClass()</code> calls.
+Syntactically and semantically, this separation produces code that is most similar to Java code, where a distinction
+between compile-time class expressions and runtime class objects also exists. (Also, Java can't have the equivalent of <code>static</code>
+property on a <code>Class</code> object since compile-time class expressions are never reified as objects).
+</p>
 <hr>
 <a name="jsimport" id="jsimport"></a>
 <h3>Importing Java Packages, Classes</h3>
@@ -558,10 +600,7 @@
 <a name="jsarrays" id="jsarrays"></a>
 <h3>Creating, Converting and Using Java Arrays</h3>
 <p>
-Array element access or length access is
-the same as in Java. Also, a script array can be used when a Java
-method expects a Java array (auto conversion). So in most cases we
-don't have to create Java arrays explicitly.</p>
+Array element access or length access is the same as in Java.</p>
 <pre><code>
 // <a href="source/javaarray.js">javaarray.js</a>
 
@@ -577,27 +616,31 @@
 </pre>
 <p>
 It is also possible to convert between JavaScript and Java arrays.
-Given a JavaScript array and a Java type, <code>Java.toJavaArray</code> returns a Java array with the same initial contents, and with the specified component type. 
+Given a JavaScript array and a Java type, <code>Java.to</code> returns a Java array with the same initial contents, and with the specified array type. 
 </p>
 <pre><code>
  var anArray = [1, "13", false]
- var javaIntArray = Java.toJavaArray(anArray, "int")
+ var javaIntArray = Java.to(anArray, "int[]")
  print(javaIntArray[0]) // prints 1
  print(javaIntArray[1]) // prints 13, as string "13" was converted to number 13 as per ECMAScript ToNumber conversion
  print(javaIntArray[2]) // prints 0, as boolean false was converted to number 0 as per ECMAScript ToNumber conversion
 </code></pre>
 <p>
-Given a Java array or Collection, <code>Java.toJavaScriptArray</code> returns a JavaScript array with a shallow copy of its contents. Note that in most cases, you can use Java arrays and lists natively in Nashorn; in cases where for some reason you need to have an actual JavaScript native array (e.g. to work with the array comprehensions functions), you will want to use this method.i
+You can use either a string or a type object returned from <code>Java.type()</code> to specify the type of the array. 
+You can also omit the array type, in which case a <code>Object[]</code> will be created.
+</p>
+<p>
+Given a Java array or Collection, <code>Java.from</code> returns a JavaScript array with a shallow copy of its contents. Note that in most cases, you can use Java arrays and lists natively in Nashorn; in cases where for some reason you need to have an actual JavaScript native array (e.g. to work with the array comprehensions functions), you will want to use this method.
 </p>
 <pre><code>
 var File = Java.type("java.io.File");
 var listCurDir = new File(".").listFiles();
-var jsList = Java.toJavaScriptArray(listCurDir);
+var jsList = Java.from(listCurDir);
 print(jsList);
 </code></pre>
 <hr>
 <a name="jsimplement" id="jsimplement"></a>
-<h3>Implementing Java Interfaces</h3>
+<h3>Implementing Java interfaces</h3>
 <p>A Java interface can be implemented in JavaScript by using a
 Java anonymous class-like syntax:</p>
 <pre><code>
@@ -631,8 +674,8 @@
 </code>
 </pre>
 <hr>
-<a name="jsextend" id="jsextend"></a>
-<h3>Extending Java classes</h3>
+<a name="jsextendabstract" id="jsextendabstract"></a>
+<h3>Extending Abstract Java Classes</h3>
 <p>
 If a Java class is abstract, you can instantiate an anonymous subclass of it using an argument list that is applicable to any of its public or protected constructors, but inserting a JavaScript object with functions properties that provide JavaScript implementations of the abstract methods. If method names are overloaded, the JavaScript function will provide implementation for all overloads. E.g.:
 </p>
@@ -671,6 +714,9 @@
 
 Here, <code>Timer.schedule()</code> expects a <code>TimerTask</code> as its argument, so Nashorn creates an instance of a TimerTask subclass and uses the passed function to implement its only abstract method, run(). In this usage though, you can't use non-default constructors; the type must be either an interface, or must have a protected or public no-arg constructor.
 
+<hr>
+<a name="jsextendconcrete" id="jsextendconcrete"></a>
+<h3>Extending Concrete Java Classes</h3>
 <p>
 To extend a concrete Java class, you have to use <code>Java.extend</code> function.
 <code>Java.extend</code> returns a type object for a subclass of the specified Java class (or implementation of the specified interface) that acts as a script-to-Java adapter for it.  
@@ -695,26 +741,178 @@
 printSizeInvokedArrayList.size();
 printAddInvokedArrayList.add(33, 33);
 </code></pre>
+<p>
+The reason you must use <code>Java.extend()</code> with concrete classes is that with concrete classes, there can be a 
+syntactic ambiguity if you just invoke their constructor. Consider this example:
+</p>
+<pre><code>
+var t = new java.lang.Thread({ run: function() { print("Hello!") } })
+</code></pre>
+<p>
+If we allowed subclassing of concrete classes with constructor syntax, Nashorn couldn't tell if you're creating a new 
+<code>Thread</code> and passing it a <code>Runnable</code> at this point, or you are subclassing <code>Thread</code> and
+passing it a new implementation for its own <code>run()</code> method.
+</p>
+<hr>
+<a name="jsimplementmultiple" id="jsimplementmultiple"></a>
+<h3>Implementing Multiple Interfaces</h3>
+<p>
+<code>Java.extend</code> can in fact take a list of multiple types. At most one of the types can be a class, and the rest must
+be interfaces (the class doesn't have to be the first in the list). You will get back an object that extends the class and 
+implements all the interfaces. (Obviously, if you only specify interfaces and no class, the object will extend <code>java.lang.Object</code>).
+<hr>
+<a name="classBoundImplementations" id="classBoundImplementations"></a>
+<h3>Class-Bound Implementations</h3>
+<p>
+The methods shown so far for extending Java classes and implementing interfaces &ndash; passing an implementation JavaScript object 
+or function to a constructor, or using <code>Java.extend</code> with <code>new</code> &ndash; all produce classes that take an
+extra JavaScript object parameter in their constructors that specifies the implementation. The implementation is therefore always bound
+to the actual instance being created with <code>new</code>, and not to the whole class. This has some advantages, for example in the
+memory footprint of the runtime, as Nashorn can just create a single "universal adapter" for every combination of types being implemented.
+In reality, the below code shows that different instantiations of, say, <code>Runnable</code> have the same class regardless of them having
+different JavaScript implementation objects:
+</p>
+<pre><code>
+var Runnable = java.lang.Runnable;
+var r1 = new Runnable(function() { print("I'm runnable 1!") })
+var r2 = new Runnable(function() { print("I'm runnable 2!") })
+r1.run()
+r2.run()
+print("We share the same class: " + (r1.class === r2.class))
+</code></pre>
+<p>
+prints:
+</p>
+<pre><code>
+I'm runnable 1!
+I'm runnable 2!
+We share the same class: true
+</code></pre>
+<p>
+Sometimes, however, you'll want to extend a Java class or implement an interface with implementation bound to the class, not to
+its instances. Such a need arises, for example, when you need to pass the class for instantiation to an external API; prime example
+of this is the JavaFX framework where you need to pass an Application class to the FX API and let it instantiate it.
+</p>
+<p>
+Fortunately, there's a solution for that: <code>Java.extend()</code> &ndash; aside from being able to take any number of type parameters
+denoting a class to extend and interfaces to implement &ndash; can also take one last argument that has to be a JavaScript object
+that serves as the implementation for the methods. In this case, <code>Java.extend()</code> will create a class that has the same
+constructors as the original class had, as they don't need to take an an extra implementation object parameter. The example below
+shows how you can create class-bound implementations, and shows that in this case, the implementation classes for different invocations
+are indeed different:
+</p>
+<pre><code>
+var RunnableImpl1 = Java.extend(java.lang.Runnable, function() { print("I'm runnable 1!") })
+var RunnableImpl2 = Java.extend(java.lang.Runnable, function() { print("I'm runnable 2!") })
+var r1 = new RunnableImpl1()
+var r2 = new RunnableImpl2()
+r1.run()
+r2.run()
+print("We share the same class: " + (r1.class === r2.class))
+</code></pre>
+<p>
+prints:
+</p>
+<pre><code>
+I'm runnable 1!
+I'm runnable 2!
+We share the same class: false
+</code></pre>
+<p>
+As you can see, the major difference here is that we moved the implementation object into the invocation of <code>Java.extend</code>
+from the constructor invocations &ndash; indeed the constructor invocations now don't even need to take an extra parameter! Since
+the implementations are bound to a class, the two classes obviously can't be the same, and we indeed see that the two runnables no
+longer share the same class &ndash; every invocation of <code>Java.extend()</code> with a class-specific implementation object triggers
+the creation of a new Java adapter class.
+</p>
+<p>
+Finally, the adapter classes with class-bound implementations can <i>still</i> take an additional constructor parameter to further
+override the behavior on a per-instance basis. Thus, you can even combine the two approaches: you can provide part of the implementation
+in a class-based JavaScript implementation object passed to <code>Java.extend</code>, and part in another object passed to the constructor.
+Whatever functions are provided by the constructor-passed object will override the functions in the class-bound object.
+</p>
+<pre><code>
+var RunnableImpl = Java.extend(java.lang.Runnable, function() { print("I'm runnable 1!") })
+var r1 = new RunnableImpl()
+var r2 = new RunnableImpl(function() { print("I'm runnable 2!") })
+r1.run()
+r2.run()
+print("We share the same class: " + (r1.class === r2.class))
+</code></pre>
+<p>
+prints:
+</p>
+<pre><code>
+I'm runnable 1!
+I'm runnable 2!
+We share the same class: true
+</code></pre>
 <hr>
 <a name="jsoverload" id="jsoverload"></a>
 <h3>Overload Resolution</h3>
 <p>Java methods can be overloaded by argument types. In Java,
 overload resolution occurs at compile time (performed by javac).
-When calling Java methods from a script, the script
-interpreter/compiler needs to select the appropriate method. With
-the JavaScript engine, you do not need to do anything special - the
-correct Java method overload variant is selected based on the
-argument types. But, sometimes you may want (or have) to explicitly
-select a particular overload variant.</p>
+When calling Java methods from Nashorn, the appropriate method will be
+selected based on the argument types at invocation time. You do not need
+to do anything special &ndash; the correct Java method overload variant 
+is selected based automatically. You still have the option of explicitly
+specifying a particular overload variant. Reasons for this include 
+either running into a genuine ambiguity with actual argument types, or 
+rarely reasons of performance &ndash; if you specify the actual overload
+then the engine doesn't have to perform resolution during invocation.
+Individual overloads of a Java methods are exposed as special properties
+with the name of the method followed with its signature in parentheses. 
+You can invoke them like this:</p>
 <pre><code>
 // <a href="source/overload.js">overload.js</a>
 
 var out = java.lang.System.out;
 
 // select a particular print function 
-out["println(java.lang.Object)"]("hello");
+out["println(Object)"]("hello");
 </code>
 </pre>
+<p>
+Note that you normally don't even have to use qualified class names in 
+the signatures as long as the unqualified name of the type is sufficient
+for uniquely identifying the signature. In practice this means that only
+in the extremely unlikely case that two overloads only differ in 
+parameter types that have identical unqualified names but come from 
+different packages would you need to use the fully qualified name of the
+class.
+</p>
+<hr>
+<a name="dataTypeMapping" id="dataTypeMapping"></a>
+<h3>Mapping of Data Types Between Java and JavaScript</h3>
+<p>
+We have previously shown some of the data type mappings between Java and JavaScript.
+We saw that arrays need to be explicitly converted. We have also shown that JavaScript functions
+are automatically converted to SAM types when passed as parameters to Java methods. Most other
+conversions work as you would expect.
+</p>
+<p>
+Every JavaScript object is also a <code>java.util.Map</code> so APIs receiving maps will receive them directly.
+</p>
+<p>
+When numbers are passed to a Java API, they will be converted to the expected target numeric type, either boxed or
+primitive, but if the target type is less specific, say <code>Number</code> or <code>Object</code>, you can only
+count on them being a <code>Number</code>, and have to test specifically for whether it's a boxed <code>Double</code>,
+<code>Integer</code>, <code>Long</code>, etc. &ndash; it can be any of these due to internal optimizations. Also, you 
+can pass any JavaScript value to a Java API expecting either a boxed or primitive number; the JavaScript specification's
+<code>ToNumber</code> conversion algorithm will be applied to the value.
+</p>
+<p>
+In a similar vein, if a Java method expects a <code>String</code> or a <code>Boolean</code>, the values will be
+converted using all conversions allowed by the JavaScript specification's <code>ToString</code> and <code>ToBoolean</code>
+conversions.
+</p>
+<p>
+Finally, a word of caution about strings. Due to internal performance optimizations of string operations, JavaScript strings are
+not always necessarily of type <code>java.lang.String</code>, but they will always be of type <code>java.lang.CharSequence</code>.
+If you pass them to a Java method that expects a <code>java.lang.String</code> parameter, then you will naturally receive a Java
+String, but if the signature of your method is more generic, i.e. it receives a <code>java.lang.Object</code> parameter, you can 
+end up with an object of private engine implementation class that implements <code>CharSequence</code> but is not a Java String.
+</p>
 <hr>
 <a name="engineimpl" id="engineimpl"></a>
 <h2>Implementing Your Own Script Engine</h2>
--- a/docs/source/javaarray.js	Fri May 31 10:28:34 2013 +0100
+++ b/docs/source/javaarray.js	Mon Jun 10 09:53:21 2013 +0100
@@ -40,7 +40,7 @@
 
 // convert a script array to Java array
 var anArray = [1, "13", false];
-var javaIntArray = Java.toJavaArray(anArray, "int");
+var javaIntArray = Java.to(anArray, "int[]");
 print(javaIntArray[0]);// prints 1
 print(javaIntArray[1]); // prints 13, as string "13" was converted to number 13 as per ECMAScript ToNumber conversion
 print(javaIntArray[2]);// prints 0, as boolean false was converted to number 0 as per ECMAScript ToNumber conversion
@@ -48,5 +48,5 @@
 // convert a Java array to a JavaScript array
 var File = Java.type("java.io.File");
 var listCurDir = new File(".").listFiles();
-var jsList = Java.toJavaScriptArray(listCurDir);
+var jsList = Java.from(listCurDir);
 print(jsList);
--- a/make/build-benchmark.xml	Fri May 31 10:28:34 2013 +0100
+++ b/make/build-benchmark.xml	Mon Jun 10 09:53:21 2013 +0100
@@ -24,258 +24,270 @@
 <project name="nashorn-benchmarks" default="all" basedir="..">
 
   <target name="octane-init" depends="jar">
-    <fileset id="octane-set"
-	     dir="${octane-test-sys-prop.test.js.roots}"
-	     excludes="${octane-test-sys-prop.test.js.exclude.list}">
-      <include name="*.js"/>
-    </fileset>
-    <pathconvert pathsep=" " property="octane-tests" refid="octane-set"/>
+    <property name="octane-tests" value="box2d code-load crypto deltablue earley-boyer gbemu navier-stokes pdfjs raytrace regexp richards splay"/>
+  </target>
+  
+  <!-- ignore benchmarks where rhino crashes -->
+  <target name="octane-init-rhino" depends="jar">
+    <property name="octane-tests" value="box2d code-load crypto deltablue earley-boyer gbemu navier-stokes raytrace regexp richards splay"/>
   </target>
 
   <!-- box2d -->
   <target name="octane-box2d" depends="jar">
     <antcall target="run-octane">
-      <param name="octane-tests" value="${octane-test-sys-prop.test.js.roots}/box2d.js"/>
+      <param name="octane-tests" value="box2d"/>
     </antcall>
   </target>
 
   <target name="octane-box2d-v8" depends="jar">
     <antcall target="run-octane-v8">
-      <param name="octane-tests" value="${octane-test-sys-prop.test.js.roots}/box2d.js"/>
+      <param name="octane-tests" value="box2d"/>
     </antcall>
   </target>
 
   <target name="octane-box2d-rhino" depends="jar">
     <antcall target="run-octane-rhino">
-      <param name="octane-tests" value="${octane-test-sys-prop.test.js.roots}/box2d.js"/>
+      <param name="octane-tests" value="box2d"/>
     </antcall>
   </target>
 
+
   <!-- code-load -->  
   <target name="octane-code-load" depends="jar">
     <antcall target="run-octane">
-      <param name="octane-tests" value="${octane-test-sys-prop.test.js.roots}/code-load.js"/>
+      <param name="octane-tests" value="code-load"/>
     </antcall>
   </target>
 
   <target name="octane-code-load-v8" depends="jar">
     <antcall target="run-octane-v8">
-      <param name="octane-tests" value="${octane-test-sys-prop.test.js.roots}/code-load.js"/>
+      <param name="octane-tests" value="code-load"/>
     </antcall>
   </target>
 
   <target name="octane-code-load-rhino" depends="jar">
     <antcall target="run-octane-rhino">
-      <param name="octane-tests" value="${octane-test-sys-prop.test.js.roots}/code-load.js"/>
+      <param name="octane-tests" value="code-load"/>
     </antcall>
   </target>
 
+
   <!-- crypto -->
   <target name="octane-crypto" depends="jar">
     <antcall target="run-octane">
-      <param name="octane-tests" value="${octane-test-sys-prop.test.js.roots}/crypto.js"/>
+      <param name="octane-tests" value="crypto"/>
     </antcall>
   </target>
 
   <target name="octane-crypto-v8" depends="jar">
     <antcall target="run-octane-v8">
-      <param name="octane-tests" value="${octane-test-sys-prop.test.js.roots}/crypto.js"/>
+      <param name="octane-tests" value="crypto"/>
     </antcall>
   </target>
 
   <target name="octane-crypto-rhino" depends="jar">
     <antcall target="run-octane-rhino">
-      <param name="octane-tests" value="${octane-test-sys-prop.test.js.roots}/crypto.js"/>
+      <param name="octane-tests" value="crypto"/>
     </antcall>
   </target>
 
+
   <!-- deltablue -->
   <target name="octane-deltablue" depends="jar">
     <antcall target="run-octane">
-      <param name="octane-tests" value="${octane-test-sys-prop.test.js.roots}/deltablue.js"/>
+      <param name="octane-tests" value="deltablue"/>
     </antcall>
   </target>
 
   <target name="octane-deltablue-v8" depends="jar">
     <antcall target="run-octane-v8">
-      <param name="octane-tests" value="${octane-test-sys-prop.test.js.roots}/deltablue.js"/>
+      <param name="octane-tests" value="deltablue"/>
     </antcall>
   </target>
 
   <target name="octane-deltablue-rhino" depends="jar">
     <antcall target="run-octane-rhino">
-      <param name="octane-tests" value="${octane-test-sys-prop.test.js.roots}/deltablue.js"/>
+      <param name="octane-tests" value="deltablue"/>
     </antcall>
   </target>
 
+
   <!-- earley-boyer -->
   <target name="octane-earley-boyer" depends="jar">
     <antcall target="run-octane">
-      <param name="octane-tests" value="${octane-test-sys-prop.test.js.roots}/earley-boyer.js"/>
+      <param name="octane-tests" value="earley-boyer"/>
     </antcall>
   </target>
 
   <target name="octane-earley-boyer-v8" depends="jar">
     <antcall target="run-octane-v8">
-      <param name="octane-tests" value="${octane-test-sys-prop.test.js.roots}/earley-boyer.js"/>
+      <param name="octane-tests" value="earley-boyer"/>
     </antcall>
   </target>
 
   <target name="octane-earley-boyer-rhino" depends="jar">
     <antcall target="run-octane-rhino">
-      <param name="octane-tests" value="${octane-test-sys-prop.test.js.roots}/earley-boyer.js"/>
+      <param name="octane-tests" value="earley-boyer"/>
     </antcall>
   </target>
 
+
   <!-- gbemu -->  
   <target name="octane-gbemu" depends="jar">
     <antcall target="run-octane">
-      <param name="octane-tests" value="${octane-test-sys-prop.test.js.roots}/gbemu.js"/>
+      <param name="octane-tests" value="gbemu"/>
     </antcall>
   </target>
 
   <target name="octane-gbemu-v8" depends="jar">
     <antcall target="run-octane-v8">
-      <param name="octane-tests" value="${octane-test-sys-prop.test.js.roots}/gbemu.js"/>
+      <param name="octane-tests" value="gbemu"/>
     </antcall>
   </target>
 
   <target name="octane-gbemu-rhino" depends="jar">
     <antcall target="run-octane-rhino">
-      <param name="octane-tests" value="${octane-test-sys-prop.test.js.roots}/gbemu.js"/>
+      <param name="octane-tests" value="gbemu"/>
     </antcall>
   </target>
 
+
   <!-- mandreel -->  
   <target name="octane-mandreel" depends="jar">
     <antcall target="run-octane">
-      <param name="octane-tests" value="${octane-test-sys-prop.test.js.roots}/mandreel.js"/>
+      <param name="octane-tests" value="mandreel"/>
     </antcall>
   </target>
 
   <target name="octane-mandreel-v8" depends="jar">
     <antcall target="run-octane-v8">
-      <param name="octane-tests" value="${octane-test-sys-prop.test.js.roots}/mandreel.js"/>
+      <param name="octane-tests" value="mandreel"/>
     </antcall>
   </target>
 
   <target name="octane-mandreel-rhino" depends="jar">
     <antcall target="run-octane-rhino">
-      <param name="octane-tests" value="${octane-test-sys-prop.test.js.roots}/mandreel.js"/>
+      <param name="octane-tests" value="mandreel"/>
     </antcall>
   </target>
 
+
   <!-- navier-stokes -->
   <target name="octane-navier-stokes" depends="jar">
     <antcall target="run-octane">
-      <param name="octane-tests" value="${octane-test-sys-prop.test.js.roots}/navier-stokes.js"/>
+      <param name="octane-tests" value="navier-stokes"/>
     </antcall>
   </target>
 
   <target name="octane-navier-stokes-v8" depends="jar">
     <antcall target="run-octane-v8">
-      <param name="octane-tests" value="${octane-test-sys-prop.test.js.roots}/navier-stokes.js"/>
+      <param name="octane-tests" value="navier-stokes"/>
     </antcall>
   </target>
 
   <target name="octane-navier-stokes-rhino" depends="jar">
     <antcall target="run-octane-rhino">
-      <param name="octane-tests" value="${octane-test-sys-prop.test.js.roots}/navier-stokes.js"/>
+      <param name="octane-tests" value="navier-stokes"/>
     </antcall>
   </target>
 
+
   <!-- pdfjs -->  
   <target name="octane-pdfjs" depends="jar">
     <antcall target="run-octane">
-      <param name="octane-tests" value="${octane-test-sys-prop.test.js.roots}/pdfjs.js"/>
+      <param name="octane-tests" value="pdfjs"/>
     </antcall>
   </target>
 
   <target name="octane-pdfjs-v8" depends="jar">
     <antcall target="run-octane-v8">
-      <param name="octane-tests" value="${octane-test-sys-prop.test.js.roots}/pdfjs.js"/>
+      <param name="octane-tests" value="pdfjs"/>
     </antcall>
   </target>
 
   <target name="octane-pdfjs-rhino" depends="jar">
     <antcall target="run-octane-rhino">
-      <param name="octane-tests" value="${octane-test-sys-prop.test.js.roots}/pdfjs.js"/>
+      <param name="octane-tests" value="pdfjs"/>
     </antcall>
   </target>
 
+
   <!-- raytrace -->
   <target name="octane-raytrace" depends="jar">
     <antcall target="run-octane">
-      <param name="octane-tests" value="${octane-test-sys-prop.test.js.roots}/raytrace.js"/>
+      <param name="octane-tests" value="raytrace"/>
     </antcall>
   </target>
 
   <target name="octane-raytrace-v8" depends="jar">
     <antcall target="run-octane-v8">
-      <param name="octane-tests" value="${octane-test-sys-prop.test.js.roots}/raytrace.js"/>
+      <param name="octane-tests" value="raytrace"/>
     </antcall>
   </target>
 
   <target name="octane-raytrace-rhino" depends="jar">
     <antcall target="run-octane-rhino">
-      <param name="octane-tests" value="${octane-test-sys-prop.test.js.roots}/raytrace.js"/>
+      <param name="octane-tests" value="raytrace"/>
     </antcall>
   </target>
 
+
   <!-- regexp -->
   <target name="octane-regexp" depends="jar">
     <antcall target="run-octane">
-      <param name="octane-tests" value="${octane-test-sys-prop.test.js.roots}/regexp.js"/>
+      <param name="octane-tests" value="regexp"/>
     </antcall>
   </target>
 
   <target name="octane-regexp-octane-v8" depends="jar">
     <antcall target="run-octane-v8">
-      <param name="octane-tests" value="${octane-test-sys-prop.test.js.roots}/regexp.js"/>
+      <param name="octane-tests" value="regexp"/>
     </antcall>
   </target>
 
   <target name="octane-regexp-rhino" depends="jar">
     <antcall target="run-octane-rhino">
-      <param name="octane-tests" value="${octane-test-sys-prop.test.js.roots}/regexp.js"/>
+      <param name="octane-tests" value="regexp"/>
     </antcall>
   </target>
 
+
   <!-- richards -->
   <target name="octane-richards" depends="jar">
     <antcall target="run-octane">
-      <param name="octane-tests" value="${octane-test-sys-prop.test.js.roots}/richards.js"/>
+      <param name="octane-tests" value="richards"/>
     </antcall>
   </target>
 
   <target name="octane-richards-v8" depends="jar">
     <antcall target="run-octane-v8">
-      <param name="octane-tests" value="${octane-test-sys-prop.test.js.roots}/richards.js"/>
+      <param name="octane-tests" value="richards"/>
     </antcall>
   </target>
 
   <target name="octane-richards-rhino" depends="jar">
     <antcall target="run-octane-rhino">
-      <param name="octane-tests" value="${octane-test-sys-prop.test.js.roots}/richards.js"/>
+      <param name="octane-tests" value="richards"/>
     </antcall>
   </target>
 
+
   <!-- splay -->
   <target name="octane-splay" depends="jar">
     <antcall target="run-octane">
-      <param name="octane-tests" value="${octane-test-sys-prop.test.js.roots}/splay.js"/>
+      <param name="octane-tests" value="splay"/>
     </antcall>
   </target>
 
   <target name="octane-splay-v8" depends="jar">
     <antcall target="run-octane-v8">
-      <param name="octane-tests" value="${octane-test-sys-prop.test.js.roots}/splay.js"/>
+      <param name="octane-tests" value="splay"/>
     </antcall>
   </target>
 
   <target name="octane-splay-rhino" depends="jar">
     <antcall target="run-octane-rhino">
-      <param name="octane-tests" value="${octane-test-sys-prop.test.js.roots}/splay.js"/>
+      <param name="octane-tests" value="splay"/>
     </antcall>
   </target>
 
@@ -307,7 +319,7 @@
   </target>
 
   <!-- run octane benchmarks using Rhino as runtime -->
-  <target name="octane-rhino" depends="octane-init">
+  <target name="octane-rhino" depends="octane-init-rhino">
     <antcall target="run-octane-rhino"/>
   </target>
   
--- a/make/build.xml	Fri May 31 10:28:34 2013 +0100
+++ b/make/build.xml	Mon Jun 10 09:53:21 2013 +0100
@@ -212,7 +212,9 @@
            target="${javac.target}"
            debug="${javac.debug}"
            encoding="${javac.encoding}"
-           includeantruntime="false"/>
+           includeantruntime="false">
+        <compilerarg line="-extdirs &quot;&quot;"/>
+    </javac>
 
     <!-- tests that check nashorn internals and internal API -->
     <jar jarfile="${nashorn.internal.tests.jar}">
@@ -305,6 +307,8 @@
       <include name="**/codegen/*Test.class"/>
       <include name="**/parser/*Test.class"/>
       <include name="**/runtime/*Test.class"/>
+      <include name="**/runtime/regexp/*Test.class"/>
+      <include name="**/runtime/regexp/joni/*Test.class"/>
       <include name="**/framework/*Test.class"/>
     </fileset>
 
--- a/make/code_coverage.xml	Fri May 31 10:28:34 2013 +0100
+++ b/make/code_coverage.xml	Mon Jun 10 09:53:21 2013 +0100
@@ -139,6 +139,32 @@
       <arg value="${cc.merged.xml}"/>
       <arg value="-exclude"/>
       <arg value="com\.oracle\.nashorn\.runtime\.ScriptRuntime*"/>
+      <arg value="-exclude"/>
+      <arg value="jdk\.nashorn\.internal\.javaadapters*"/>
+      <arg value="-exclude"/>
+      <arg value="jdk\.nashorn\.internal\.objects\.annotations*"/>
+      <arg value="-exclude"/>
+      <arg value="jdk\.nashorn\.internal\.scripts*"/>
+      <arg value="-exclude"/>
+      <arg value="jdk\.nashorn\.internal\.lookup\.MethodHandleFactory*"/>
+      <arg value="-exclude"/>
+      <arg value="jdk\.nashorn\.internal\.test\.framework*"/>
+      <arg value="-exclude"/>
+      <arg value="jdk\.nashorn\.test\.models*"/>
+      <arg value="-exclude"/>
+      <arg value="jdk\.nashorn\.internal\.ir\.debug*"/>
+      <arg value="-exclude"/>
+      <arg value="jdk\.nashorn\.internal\.runtime\.regexp\.joni\.bench*"/>
+      <arg value="-exclude"/>
+      <arg value="jdk\.nashorn\.internal\.runtime\.DebugLogger*"/>
+      <arg value="-exclude"/>
+      <arg value="jdk\.nashorn\.internal\.runtime\.Timing*"/>
+      <arg value="-exclude"/>
+      <arg value="jdk\.nashorn\.internal\.runtime\.Logging*"/>
+      <arg value="-exclude"/>
+      <arg value="jdk\.nashorn\.internal\.runtime\.Debug*"/>
+      <arg value="-exclude"/>
+      <arg value="jdk\.nashorn\.internal\.objects\.NativeDebug*"/>
       <arg line="${cc.all.xmls}"/>
       <classpath>
         <pathelement location="${jcov.jar}"/>
--- a/make/project.properties	Fri May 31 10:28:34 2013 +0100
+++ b/make/project.properties	Mon Jun 10 09:53:21 2013 +0100
@@ -87,6 +87,7 @@
 
 testng.listeners=\
  org.testng.reporters.SuiteHTMLReporter, \
+ org.testng.reporters.TestHTMLReporter, \
  org.testng.reporters.jq.Main, \
  org.testng.reporters.FailedReporter, \
  org.testng.reporters.XMLReporter \
@@ -214,9 +215,13 @@
 run.test.xmx=3G
 run.test.xms=2G
 
+run.test.user.language=tr
+run.test.user.country=TR
+
 #  -XX:+PrintCompilation -XX:+UnlockDiagnosticVMOptions -XX:+PrintNMethods
 # add '-Dtest.js.outofprocess' to run each test in a new sub-process
-run.test.jvmargs.main=-server -Xmx${run.test.xmx} -XX:+TieredCompilation -ea -Dnashorn.debug=true -Dfile.encoding=UTF-8
+run.test.jvmargs.main=-server -Xmx${run.test.xmx} -XX:+TieredCompilation -ea -Dfile.encoding=UTF-8 -Duser.language=${run.test.user.language} -Duser.country=${run.test.user.country}
+
 #-XX:+HeapDumpOnOutOfMemoryError -XX:-UseCompressedKlassPointers -XX:+PrintHeapAtGC -XX:ClassMetaspaceSize=300M  
 run.test.jvmargs.octane.main=-Xms${run.test.xms} ${run.test.jvmargs.main}
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jdk/nashorn/api/scripting/JSObject.java	Mon Jun 10 09:53:21 2013 +0100
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.nashorn.api.scripting;
+
+/**
+ * netscape.javascript.JSObject-like interface for nashorn script objects.
+ */
+public abstract class JSObject {
+    /**
+     * Call a JavaScript method
+     *
+     * @param methodName name of method
+     * @param args arguments to method
+     * @return result of call
+     */
+    public abstract Object call(String methodName, Object args[]);
+
+    /**
+     * Evaluate a JavaScript expression
+     *
+     * @param s JavaScript expression to evaluate
+     * @return evaluation result
+     */
+    public abstract Object eval(String s);
+
+    /**
+     * Retrieves a named member of a JavaScript object.
+     *
+     * @param name of member
+     * @return member
+     */
+    public abstract Object getMember(String name);
+
+    /**
+     * Retrieves an indexed member of a JavaScript object.
+     *
+     * @param index index of member slot
+     * @return member
+     */
+    public abstract Object getSlot(int index);
+
+    /**
+     * Remove a named member from a JavaScript object
+     *
+     * @param name name of member
+     */
+    public abstract void removeMember(String name);
+
+    /**
+     * Set a named member in a JavaScript object
+     *
+     * @param name  name of member
+     * @param value value of member
+     */
+    public abstract void setMember(String name, Object value);
+
+    /**
+     * Set an indexed member in a JavaScript object
+     *
+     * @param index index of member slot
+     * @param value value of member
+     */
+    public abstract void setSlot(int index, Object value);
+}
--- a/src/jdk/nashorn/api/scripting/ScriptObjectMirror.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/api/scripting/ScriptObjectMirror.java	Mon Jun 10 09:53:21 2013 +0100
@@ -31,7 +31,7 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.HashSet;
+import java.util.LinkedHashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -42,14 +42,13 @@
 import jdk.nashorn.internal.runtime.ScriptFunction;
 import jdk.nashorn.internal.runtime.ScriptObject;
 import jdk.nashorn.internal.runtime.ScriptRuntime;
-import netscape.javascript.JSObject;
 
 /**
  * Mirror object that wraps a given ScriptObject instance. User can
  * access ScriptObject via the javax.script.Bindings interface or
  * netscape.javascript.JSObject interface.
  */
-final class ScriptObjectMirror extends JSObject implements Bindings {
+public final class ScriptObjectMirror extends JSObject implements Bindings {
     private final ScriptObject sobj;
     private final ScriptObject global;
 
@@ -218,7 +217,7 @@
         return inGlobal(new Callable<Set<Map.Entry<String, Object>>>() {
             @Override public Set<Map.Entry<String, Object>> call() {
                 final Iterator<String>               iter    = sobj.propertyIterator();
-                final Set<Map.Entry<String, Object>> entries = new HashSet<>();
+                final Set<Map.Entry<String, Object>> entries = new LinkedHashSet<>();
 
                 while (iter.hasNext()) {
                     final String key   = iter.next();
@@ -254,7 +253,7 @@
         return inGlobal(new Callable<Set<String>>() {
             @Override public Set<String> call() {
                 final Iterator<String> iter   = sobj.propertyIterator();
-                final Set<String>      keySet = new HashSet<>();
+                final Set<String>      keySet = new LinkedHashSet<>();
 
                 while (iter.hasNext()) {
                     keySet.add(iter.next());
@@ -303,6 +302,21 @@
         });
     }
 
+    /**
+     * Delete a property from this object.
+     *
+     * @param key the property to be deleted
+     *
+     * @return if the delete was successful or not
+     */
+    public boolean delete(final Object key) {
+        return inGlobal(new Callable<Boolean>() {
+            @Override public Boolean call() {
+                return sobj.delete(unwrap(key, global));
+            }
+        });
+    }
+
     @Override
     public int size() {
         return inGlobal(new Callable<Integer>() {
@@ -328,20 +342,28 @@
         });
     }
 
-    // package-privates below this.
-    ScriptObject getScriptObject() {
-        return sobj;
-    }
 
-    static Object translateUndefined(Object obj) {
-        return (obj == ScriptRuntime.UNDEFINED)? null : obj;
-    }
+    // These are public only so that Context can access these.
 
-    static Object wrap(final Object obj, final ScriptObject homeGlobal) {
+    /**
+     * Make a script object mirror on given object if needed.
+     *
+     * @param obj object to be wrapped
+     * @param homeGlobal global to which this object belongs
+     * @return wrapped object
+     */
+    public static Object wrap(final Object obj, final ScriptObject homeGlobal) {
         return (obj instanceof ScriptObject) ? new ScriptObjectMirror((ScriptObject)obj, homeGlobal) : obj;
     }
 
-    static Object unwrap(final Object obj, final ScriptObject homeGlobal) {
+    /**
+     * Unwrap a script object mirror if needed.
+     *
+     * @param obj object to be unwrapped
+     * @param homeGlobal global to which this object belongs
+     * @return unwrapped object
+     */
+    public static Object unwrap(final Object obj, final ScriptObject homeGlobal) {
         if (obj instanceof ScriptObjectMirror) {
             final ScriptObjectMirror mirror = (ScriptObjectMirror)obj;
             return (mirror.global == homeGlobal)? mirror.sobj : obj;
@@ -350,7 +372,14 @@
         return obj;
     }
 
-    static Object[] wrapArray(final Object[] args, final ScriptObject homeGlobal) {
+    /**
+     * Wrap an array of object to script object mirrors if needed.
+     *
+     * @param args array to be unwrapped
+     * @param homeGlobal global to which this object belongs
+     * @return wrapped array
+     */
+    public static Object[] wrapArray(final Object[] args, final ScriptObject homeGlobal) {
         if (args == null || args.length == 0) {
             return args;
         }
@@ -364,7 +393,14 @@
         return newArgs;
     }
 
-    static Object[] unwrapArray(final Object[] args, final ScriptObject homeGlobal) {
+    /**
+     * Unwrap an array of script object mirrors if needed.
+     *
+     * @param args array to be unwrapped
+     * @param homeGlobal global to which this object belongs
+     * @return unwrapped array
+     */
+    public static Object[] unwrapArray(final Object[] args, final ScriptObject homeGlobal) {
         if (args == null || args.length == 0) {
             return args;
         }
@@ -377,4 +413,13 @@
         }
         return newArgs;
     }
+
+    // package-privates below this.
+    ScriptObject getScriptObject() {
+        return sobj;
+    }
+
+    static Object translateUndefined(Object obj) {
+        return (obj == ScriptRuntime.UNDEFINED)? null : obj;
+    }
 }
--- a/src/jdk/nashorn/api/scripting/resources/engine.js	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/api/scripting/resources/engine.js	Mon Jun 10 09:53:21 2013 +0100
@@ -88,7 +88,7 @@
             }
         }
 
-        array = Java.toJavaArray(array);
+        array = Java.to(array);
         return Packages.jdk.nashorn.api.scripting.ScriptUtils.format(format, array);
     }
 });
--- a/src/jdk/nashorn/internal/codegen/Attr.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/codegen/Attr.java	Mon Jun 10 09:53:21 2013 +0100
@@ -90,7 +90,6 @@
 import jdk.nashorn.internal.runtime.Context;
 import jdk.nashorn.internal.runtime.Debug;
 import jdk.nashorn.internal.runtime.DebugLogger;
-import jdk.nashorn.internal.runtime.ECMAException;
 import jdk.nashorn.internal.runtime.JSType;
 import jdk.nashorn.internal.runtime.Property;
 import jdk.nashorn.internal.runtime.PropertyMap;
@@ -111,7 +110,7 @@
  * computed.
  */
 
-final class Attr extends NodeOperatorVisitor {
+final class Attr extends NodeOperatorVisitor<LexicalContext> {
 
     /**
      * Local definitions in current block (to discriminate from function
@@ -138,6 +137,7 @@
      * Constructor.
      */
     Attr(final TemporarySymbols temporarySymbols) {
+        super(new LexicalContext());
         this.temporarySymbols = temporarySymbols;
         this.localDefs   = new ArrayDeque<>();
         this.localUses   = new ArrayDeque<>();
@@ -202,7 +202,7 @@
     private void acceptDeclarations(final FunctionNode functionNode, final Block body) {
         // This visitor will assign symbol to all declared variables, except function declarations (which are taken care
         // in a separate step above) and "var" declarations in for loop initializers.
-        body.accept(new NodeOperatorVisitor() {
+        body.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
             @Override
             public boolean enterFunctionNode(final FunctionNode nestedFn) {
                 return false;
@@ -218,7 +218,7 @@
                     if (varNode.isFunctionDeclaration()) {
                         newType(symbol, FunctionNode.FUNCTION_TYPE);
                     }
-                    return varNode.setName((IdentNode)ident.setSymbol(getLexicalContext(), symbol));
+                    return varNode.setName((IdentNode)ident.setSymbol(lc, symbol));
                 }
                 return varNode;
             }
@@ -227,8 +227,8 @@
 
     private void enterFunctionBody() {
 
-        final FunctionNode functionNode = getLexicalContext().getCurrentFunction();
-        final Block body = getLexicalContext().getCurrentBlock();
+        final FunctionNode functionNode = lc.getCurrentFunction();
+        final Block body = lc.getCurrentBlock();
 
         initFunctionWideVariables(functionNode, body);
 
@@ -256,7 +256,7 @@
         //the symbols in the block should really be stateless
         block.clearSymbols();
 
-        if (getLexicalContext().isFunctionBody()) {
+        if (lc.isFunctionBody()) {
             enterFunctionBody();
         }
         pushLocalsBlock();
@@ -283,7 +283,7 @@
     @Override
     public boolean enterCatchNode(final CatchNode catchNode) {
         final IdentNode exception = catchNode.getException();
-        final Block     block     = getLexicalContext().getCurrentBlock();
+        final Block     block     = lc.getCurrentBlock();
 
         start(catchNode);
 
@@ -298,10 +298,10 @@
     @Override
     public Node leaveCatchNode(final CatchNode catchNode) {
         final IdentNode exception = catchNode.getException();
-        final Block  block        = getLexicalContext().getCurrentBlock();
+        final Block  block        = lc.getCurrentBlock();
         final Symbol symbol       = findSymbol(block, exception.getName());
         assert symbol != null;
-        return end(catchNode.setException((IdentNode)exception.setSymbol(getLexicalContext(), symbol)));
+        return end(catchNode.setException((IdentNode)exception.setSymbol(lc, symbol)));
     }
 
     /**
@@ -320,7 +320,7 @@
             flags |= IS_SCOPE;
         }
 
-        final FunctionNode function = getLexicalContext().getFunction(block);
+        final FunctionNode function = lc.getFunction(block);
         if (symbol != null) {
             // Symbol was already defined. Check if it needs to be redefined.
             if ((flags & KINDMASK) == IS_PARAM) {
@@ -353,12 +353,12 @@
             if ((flags & Symbol.KINDMASK) == IS_VAR && ((flags & IS_INTERNAL) == IS_INTERNAL || (flags & IS_LET) == IS_LET)) {
                 symbolBlock = block; //internal vars are always defined in the block closest to them
             } else {
-                symbolBlock = getLexicalContext().getFunctionBody(function);
+                symbolBlock = lc.getFunctionBody(function);
             }
 
             // Create and add to appropriate block.
             symbol = new Symbol(name, flags);
-            symbolBlock.putSymbol(getLexicalContext(), symbol);
+            symbolBlock.putSymbol(lc, symbol);
 
             if ((flags & Symbol.KINDMASK) != IS_GLOBAL) {
                 symbol.setNeedsSlot(true);
@@ -381,7 +381,7 @@
         //an outermost function in our lexical context that is not a program (runScript)
         //is possible - it is a function being compiled lazily
         if (functionNode.isDeclared()) {
-            final Iterator<Block> blocks = getLexicalContext().getBlocks();
+            final Iterator<Block> blocks = lc.getBlocks();
             if (blocks.hasNext()) {
                 defineSymbol(blocks.next(), functionNode.getIdent().getName(), IS_VAR);
             }
@@ -397,13 +397,11 @@
     public Node leaveFunctionNode(final FunctionNode functionNode) {
         FunctionNode newFunctionNode = functionNode;
 
-        final LexicalContext lc = getLexicalContext();
-
         final Block body = newFunctionNode.getBody();
 
         //look for this function in the parent block
         if (functionNode.isDeclared()) {
-            final Iterator<Block> blocks = getLexicalContext().getBlocks();
+            final Iterator<Block> blocks = lc.getBlocks();
             if (blocks.hasNext()) {
                 newFunctionNode = (FunctionNode)newFunctionNode.setSymbol(lc, findSymbol(blocks.next(), functionNode.getIdent().getName()));
             }
@@ -411,7 +409,7 @@
             final boolean anonymous = functionNode.isAnonymous();
             final String  name      = anonymous ? null : functionNode.getIdent().getName();
             if (anonymous || body.getExistingSymbol(name) != null) {
-                newFunctionNode = (FunctionNode)ensureSymbol(lc, FunctionNode.FUNCTION_TYPE, newFunctionNode);
+                newFunctionNode = (FunctionNode)ensureSymbol(FunctionNode.FUNCTION_TYPE, newFunctionNode);
             } else {
                 assert name != null;
                 final Symbol self = body.getExistingSymbol(name);
@@ -490,8 +488,6 @@
 
         start(identNode);
 
-        final LexicalContext lc = getLexicalContext();
-
         if (identNode.isPropertyName()) {
             // assign a pseudo symbol to property name
             final Symbol pseudoSymbol = pseudoSymbol(name);
@@ -549,7 +545,7 @@
      */
     private void maybeForceScope(final Symbol symbol) {
         if (!symbol.isScope() && symbolNeedsToBeScope(symbol)) {
-            Symbol.setSymbolIsScope(getLexicalContext(), symbol);
+            Symbol.setSymbolIsScope(lc, symbol);
         }
     }
 
@@ -558,7 +554,7 @@
             return false;
         }
         boolean previousWasBlock = false;
-        for(final Iterator<LexicalContextNode> it = getLexicalContext().getAllNodes(); it.hasNext();) {
+        for(final Iterator<LexicalContextNode> it = lc.getAllNodes(); it.hasNext();) {
             final LexicalContextNode node = it.next();
             if(node instanceof FunctionNode) {
                 // We reached the function boundary without seeing a definition for the symbol - it needs to be in
@@ -594,10 +590,8 @@
         }
 
         if (symbol.isScope()) {
-            final LexicalContext lc = getLexicalContext();
-
             Block scopeBlock = null;
-            for (final Iterator<LexicalContextNode> contextNodeIter = getLexicalContext().getAllNodes(); contextNodeIter.hasNext(); ) {
+            for (final Iterator<LexicalContextNode> contextNodeIter = lc.getAllNodes(); contextNodeIter.hasNext(); ) {
                 final LexicalContextNode node = contextNodeIter.next();
                 if (node instanceof Block) {
                     if (((Block)node).getExistingSymbol(name) != null) {
@@ -610,7 +604,7 @@
             }
 
             if (scopeBlock != null) {
-                assert getLexicalContext().contains(scopeBlock);
+                assert lc.contains(scopeBlock);
                 lc.setFlag(scopeBlock, Block.NEEDS_SCOPE);
             }
         }
@@ -622,8 +616,8 @@
      * @see #needsParentScope()
      */
     private void setUsesGlobalSymbol() {
-        for (final Iterator<FunctionNode> fns = getLexicalContext().getFunctions(); fns.hasNext();) {
-            getLexicalContext().setFlag(fns.next(), FunctionNode.USES_ANCESTOR_SCOPE);
+        for (final Iterator<FunctionNode> fns = lc.getFunctions(); fns.hasNext();) {
+            lc.setFlag(fns.next(), FunctionNode.USES_ANCESTOR_SCOPE);
         }
     }
 
@@ -635,7 +629,7 @@
     private Symbol findSymbol(final Block block, final String name) {
         // Search up block chain to locate symbol.
 
-        for (final Iterator<Block> blocks = getLexicalContext().getBlocks(block); blocks.hasNext();) {
+        for (final Iterator<Block> blocks = lc.getBlocks(block); blocks.hasNext();) {
             // Find name.
             final Symbol symbol = blocks.next().getExistingSymbol(name);
             // If found then we are good.
@@ -656,11 +650,11 @@
     public Node leaveLiteralNode(final LiteralNode literalNode) {
         assert !literalNode.isTokenType(TokenType.THIS) : "tokentype for " + literalNode + " is this"; //guard against old dead code case. literal nodes should never inherit tokens
         assert literalNode instanceof ArrayLiteralNode || !(literalNode.getValue() instanceof Node) : "literals with Node values not supported";
-        final Symbol symbol = new Symbol(getLexicalContext().getCurrentFunction().uniqueName(LITERAL_PREFIX.symbolName()), IS_CONSTANT, literalNode.getType());
+        final Symbol symbol = new Symbol(lc.getCurrentFunction().uniqueName(LITERAL_PREFIX.symbolName()), IS_CONSTANT, literalNode.getType());
         if (literalNode instanceof ArrayLiteralNode) {
             ((ArrayLiteralNode)literalNode).analyze();
         }
-        return end(literalNode.setSymbol(getLexicalContext(), symbol));
+        return end(literalNode.setSymbol(lc, symbol));
     }
 
     @Override
@@ -676,7 +670,7 @@
     @Override
     public Node leavePropertyNode(final PropertyNode propertyNode) {
         // assign a pseudo symbol to property name, see NASHORN-710
-        return propertyNode.setSymbol(getLexicalContext(), new Symbol(propertyNode.getKeyName(), 0, Type.OBJECT));
+        return propertyNode.setSymbol(lc, new Symbol(propertyNode.getKeyName(), 0, Type.OBJECT));
     }
 
     @Override
@@ -734,11 +728,11 @@
             type = Type.OBJECT;
         }
 
-        switchNode.setTag(newInternal(getLexicalContext().getCurrentFunction().uniqueName(SWITCH_TAG_PREFIX.symbolName()), type));
+        switchNode.setTag(newInternal(lc.getCurrentFunction().uniqueName(SWITCH_TAG_PREFIX.symbolName()), type));
 
         end(switchNode);
 
-        return switchNode.setCases(getLexicalContext(), newCases);
+        return switchNode.setCases(lc, newCases);
     }
 
     @Override
@@ -761,7 +755,7 @@
         final IdentNode ident = varNode.getName();
         final String    name  = ident.getName();
 
-        final Symbol symbol = defineSymbol(getLexicalContext().getCurrentBlock(), name, IS_VAR);
+        final Symbol symbol = defineSymbol(lc.getCurrentBlock(), name, IS_VAR);
         assert symbol != null;
 
         // NASHORN-467 - use before definition of vars - conservative
@@ -781,7 +775,6 @@
         final IdentNode ident = newVarNode.getName();
         final String    name  = ident.getName();
 
-        final LexicalContext lc = getLexicalContext();
         final Symbol  symbol = findSymbol(lc.getCurrentBlock(), ident.getName());
 
         if (init == null) {
@@ -834,7 +827,7 @@
 
     @Override
     public Node leaveDELETE(final UnaryNode unaryNode) {
-        final FunctionNode   currentFunctionNode = getLexicalContext().getCurrentFunction();
+        final FunctionNode   currentFunctionNode = lc.getCurrentFunction();
         final boolean        strictMode          = currentFunctionNode.isStrict();
         final Node           rhs                 = unaryNode.rhs();
         final Node           strictFlagNode      = LiteralNode.newInstance(unaryNode, strictMode).accept(this);
@@ -894,10 +887,10 @@
      * @return true if the symbol denoted by the specified name in the current lexical context defined in the program level.
      */
     private boolean isProgramLevelSymbol(final String name) {
-        for(final Iterator<Block> it = getLexicalContext().getBlocks(); it.hasNext();) {
+        for(final Iterator<Block> it = lc.getBlocks(); it.hasNext();) {
             final Block next = it.next();
             if(next.getExistingSymbol(name) != null) {
-                return next == getLexicalContext().getFunctionBody(getLexicalContext().getOutermostFunction());
+                return next == lc.getFunctionBody(lc.getOutermostFunction());
             }
         }
         throw new AssertionError("Couldn't find symbol " + name + " in the context");
@@ -914,14 +907,14 @@
     }
 
     private IdentNode compilerConstant(CompilerConstants cc) {
-        final FunctionNode functionNode = getLexicalContext().getCurrentFunction();
+        final FunctionNode functionNode = lc.getCurrentFunction();
         return (IdentNode)
             new IdentNode(
                 functionNode.getToken(),
                 functionNode.getFinish(),
                 cc.symbolName()).
                 setSymbol(
-                    getLexicalContext(),
+                    lc,
                     functionNode.compilerConstant(cc));
     }
 
@@ -999,7 +992,7 @@
         final Node lhs = binaryNode.lhs();
 
         if (lhs instanceof IdentNode) {
-            final Block     block = getLexicalContext().getCurrentBlock();
+            final Block     block = lc.getCurrentBlock();
             final IdentNode ident = (IdentNode)lhs;
             final String    name  = ident.getName();
 
@@ -1043,7 +1036,7 @@
     }
 
     private boolean isLocal(FunctionNode function, Symbol symbol) {
-        final FunctionNode definingFn = getLexicalContext().getDefiningFunction(symbol);
+        final FunctionNode definingFn = lc.getDefiningFunction(symbol);
         // Temp symbols are not assigned to a block, so their defining fn is null; those can be assumed local
         return definingFn == null || definingFn == function;
     }
@@ -1329,7 +1322,7 @@
     @Override
     public Node leaveForNode(final ForNode forNode) {
         if (forNode.isForIn()) {
-            forNode.setIterator(newInternal(getLexicalContext().getCurrentFunction().uniqueName(ITERATOR_PREFIX.symbolName()), Type.OBJECT)); //NASHORN-73
+            forNode.setIterator(newInternal(lc.getCurrentFunction().uniqueName(ITERATOR_PREFIX.symbolName()), Type.typeFor(ITERATOR_PREFIX.type()))); //NASHORN-73
             /*
              * Iterators return objects, so we need to widen the scope of the
              * init variable if it, for example, has been assigned double type
@@ -1407,7 +1400,7 @@
             final Symbol paramSymbol = functionNode.getBody().getExistingSymbol(param.getName());
             assert paramSymbol != null;
             assert paramSymbol.isParam();
-            newParams.add((IdentNode)param.setSymbol(getLexicalContext(), paramSymbol));
+            newParams.add((IdentNode)param.setSymbol(lc, paramSymbol));
 
             assert paramSymbol != null;
             Type type = functionNode.getHints().getParameterType(pos);
@@ -1439,10 +1432,10 @@
         FunctionNode newFunctionNode = functionNode;
 
         if (nparams == 0 || (specialize * 2) < nparams) {
-            newFunctionNode = newFunctionNode.clearSnapshot(getLexicalContext());
+            newFunctionNode = newFunctionNode.clearSnapshot(lc);
         }
 
-        return newFunctionNode.setParameters(getLexicalContext(), newParams);
+        return newFunctionNode.setParameters(lc, newParams);
     }
 
     /**
@@ -1506,7 +1499,7 @@
     }
 
     private Symbol exceptionSymbol() {
-        return newInternal(getLexicalContext().getCurrentFunction().uniqueName(EXCEPTION_PREFIX.symbolName()), Type.typeFor(ECMAException.class));
+        return newInternal(lc.getCurrentFunction().uniqueName(EXCEPTION_PREFIX.symbolName()), Type.typeFor(EXCEPTION_PREFIX.type()));
     }
 
     /**
@@ -1520,8 +1513,8 @@
      * @param assignmentDest the destination node of the assignment, e.g. lhs for binary nodes
      */
     private Node ensureAssignmentSlots(final Node assignmentDest) {
-        final LexicalContext attrLexicalContext = getLexicalContext();
-        return assignmentDest.accept(new NodeVisitor() {
+        final LexicalContext attrLexicalContext = lc;
+        return assignmentDest.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
             @Override
             public Node leaveIndexNode(final IndexNode indexNode) {
                 assert indexNode.getSymbol().isTemp();
@@ -1565,7 +1558,7 @@
         FunctionNode currentFunctionNode = functionNode;
         do {
             changed.clear();
-            final FunctionNode newFunctionNode = (FunctionNode)currentFunctionNode.accept(new NodeVisitor() {
+            final FunctionNode newFunctionNode = (FunctionNode)currentFunctionNode.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
 
                 private Node widen(final Node node, final Type to) {
                     if (node instanceof LiteralNode) {
@@ -1579,7 +1572,7 @@
                             symbol = temporarySymbols.getTypedTemporarySymbol(to);
                         }
                         newType(symbol, to);
-                        final Node newNode = node.setSymbol(getLexicalContext(), symbol);
+                        final Node newNode = node.setSymbol(lc, symbol);
                         changed.add(newNode);
                         return newNode;
                     }
@@ -1622,7 +1615,7 @@
                     return newBinaryNode;
                 }
             });
-            getLexicalContext().replace(currentFunctionNode, newFunctionNode);
+            lc.replace(currentFunctionNode, newFunctionNode);
             currentFunctionNode = newFunctionNode;
         } while (!changed.isEmpty());
         return currentFunctionNode;
@@ -1643,12 +1636,12 @@
     }
 
     private Node ensureSymbol(final Type type, final Node node) {
-        LOG.info("New TEMPORARY added to ", getLexicalContext().getCurrentFunction().getName(), " type=", type);
-        return ensureSymbol(getLexicalContext(), type, node);
+        LOG.info("New TEMPORARY added to ", lc.getCurrentFunction().getName(), " type=", type);
+        return temporarySymbols.ensureSymbol(lc, type, node);
     }
 
     private Symbol newInternal(final String name, final Type type) {
-        final Symbol iter = defineSymbol(getLexicalContext().getCurrentBlock(), name, IS_VAR | IS_INTERNAL);
+        final Symbol iter = defineSymbol(lc.getCurrentBlock(), name, IS_VAR | IS_INTERNAL);
         iter.setType(type); // NASHORN-73
         return iter;
     }
@@ -1705,10 +1698,6 @@
         localUses.peek().add(name);
     }
 
-    private Node ensureSymbol(final LexicalContext lc, final Type type, final Node node) {
-        return temporarySymbols.ensureSymbol(lc, type, node);
-    }
-
     /**
      * Pessimistically promote all symbols in current function node to Object types
      * This is done when the function contains unevaluated black boxes such as
@@ -1717,7 +1706,7 @@
      * @param body body for the function node we are leaving
      */
     private static void objectifySymbols(final Block body) {
-        body.accept(new NodeVisitor() {
+        body.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
             private void toObject(final Block block) {
                 for (final Symbol symbol : block.getSymbols()) {
                     if (!symbol.isTemp()) {
@@ -1761,7 +1750,7 @@
                 append("] ").
                 append(printNode ? node.toString() : "").
                 append(" in '").
-                append(getLexicalContext().getCurrentFunction().getName()).
+                append(lc.getCurrentFunction().getName()).
                 append("'");
             LOG.info(sb);
             LOG.indent();
@@ -1787,7 +1776,7 @@
                 append("] ").
                 append(printNode ? node.toString() : "").
                 append(" in '").
-                append(getLexicalContext().getCurrentFunction().getName());
+                append(lc.getCurrentFunction().getName());
 
             if (node.getSymbol() == null) {
                 sb.append(" <NO SYMBOL>");
--- a/src/jdk/nashorn/internal/codegen/CodeGenerator.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/codegen/CodeGenerator.java	Mon Jun 10 09:53:21 2013 +0100
@@ -52,18 +52,14 @@
 import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_STRICT;
 
 import java.io.PrintWriter;
-import java.util.ArrayDeque;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Deque;
 import java.util.EnumSet;
-import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
-import java.util.Map;
+import java.util.Locale;
 import java.util.TreeMap;
-
 import jdk.nashorn.internal.codegen.ClassEmitter.Flag;
 import jdk.nashorn.internal.codegen.CompilerConstants.Call;
 import jdk.nashorn.internal.codegen.RuntimeCallSite.SpecializedRuntimeNode;
@@ -150,7 +146,7 @@
  * The CodeGenerator visits nodes only once, tags them as resolved and emits
  * bytecode for them.
  */
-final class CodeGenerator extends NodeOperatorVisitor {
+final class CodeGenerator extends NodeOperatorVisitor<CodeGeneratorLexicalContext> {
 
     /** Name of the Global object, cannot be referred to as .class, @see CodeGenerator */
     private static final String GLOBAL_OBJECT = Compiler.OBJECTS_PACKAGE + '/' + "Global";
@@ -168,23 +164,12 @@
     /** How many regexp fields have been emitted */
     private int regexFieldCount;
 
-    /** Map of shared scope call sites */
-    private final Map<SharedScopeCall, SharedScopeCall> scopeCalls = new HashMap<>();
-
-    /** Compile unit stack - every time we start a sub method (e.g. a split) we push one */
-    private final Deque<CompileUnit> compileUnits = new ArrayDeque<>();
-
-    /** Method emitter stack - every time we start a sub method (e.g. a split) we push one */
-    private final Deque<MethodEmitter> methodEmitters = new ArrayDeque<>();
-
-    /** The discard stack - whenever we enter a discard node we keep track of its return value status -
-     *  i.e. should we keep it or throw it away */
-    private final Deque<Node> discard = new ArrayDeque<>();
-
-    // A stack tracking the next free local variable slot in the blocks. There's one entry for every block
-    // currently on the lexical context stack.
-    private int[] nextFreeSlots = new int[16];
-    private int nextFreeSlotsSize = 0;
+    /** Line number for last statement. If we encounter a new line number, line number bytecode information
+     *  needs to be generated */
+    private int lastLineNumber = -1;
+
+    /** When should we stop caching regexp expressions in fields to limit bytecode size? */
+    private static final int MAX_REGEX_FIELDS = 2 * 1024;
 
     /** Current method emitter */
     private MethodEmitter method;
@@ -192,20 +177,16 @@
     /** Current compile unit */
     private CompileUnit unit;
 
-    private int lastLineNumber = -1;
-
-    /** When should we stop caching regexp expressions in fields to limit bytecode size? */
-    private static final int MAX_REGEX_FIELDS = 2 * 1024;
-
     private static final DebugLogger LOG   = new DebugLogger("codegen", "nashorn.codegen.debug");
 
+
     /**
      * Constructor.
      *
      * @param compiler
      */
     CodeGenerator(final Compiler compiler) {
-        super(new DynamicScopeTrackingLexicalContext());
+        super(new CodeGeneratorLexicalContext());
         this.compiler      = compiler;
         this.callSiteFlags = compiler.getEnv()._callsite_flags;
     }
@@ -217,37 +198,7 @@
      * @return the correct flags for a call site in the current function
      */
     int getCallSiteFlags() {
-        return getLexicalContext().getCurrentFunction().isStrict() ? callSiteFlags | CALLSITE_STRICT : callSiteFlags;
-    }
-
-    private void pushMethodEmitter(final MethodEmitter newMethod) {
-        methodEmitters.push(newMethod);
-        this.method = newMethod;
-    }
-
-    private void popMethodEmitter(final MethodEmitter oldMethod) {
-        assert methodEmitters.peek() == oldMethod;
-        methodEmitters.pop();
-        if (!methodEmitters.isEmpty()) {
-            this.method = methodEmitters.peek();
-        } else {
-            this.method = null;
-        }
-    }
-
-    private void push(final CompileUnit newUnit) {
-        compileUnits.push(newUnit);
-        this.unit = newUnit;
-    }
-
-    private void pop(final CompileUnit oldUnit) {
-        assert compileUnits.peek() == oldUnit;
-        compileUnits.pop();
-        if (!compileUnits.isEmpty()) {
-            this.unit = compileUnits.peek();
-        } else {
-            this.unit = null;
-        }
+        return lc.getCurrentFunction().isStrict() ? callSiteFlags | CALLSITE_STRICT : callSiteFlags;
     }
 
     /**
@@ -265,7 +216,7 @@
         }
 
         final String name   = symbol.getName();
-        final Source source = getLexicalContext().getCurrentFunction().getSource();
+        final Source source = lc.getCurrentFunction().getSource();
 
         if (CompilerConstants.__FILE__.name().equals(name)) {
             return method.load(source.getName());
@@ -291,88 +242,43 @@
     }
 
     /**
-     * A lexical context that also tracks if we have any dynamic scopes in the context. Such scopes can have new
-     * variables introduced into them at run time - a with block or a function directly containing an eval call.
-     */
-    private static class DynamicScopeTrackingLexicalContext extends LexicalContext {
-        int dynamicScopeCount = 0;
-
-        @Override
-        public <T extends LexicalContextNode> T push(T node) {
-            if(isDynamicScopeBoundary(node)) {
-                ++dynamicScopeCount;
-            }
-            return super.push(node);
-        }
-
-        @Override
-        public <T extends LexicalContextNode> T pop(T node) {
-            final T popped = super.pop(node);
-            if(isDynamicScopeBoundary(popped)) {
-                --dynamicScopeCount;
-            }
-            return popped;
-        }
-
-        private boolean isDynamicScopeBoundary(LexicalContextNode node) {
-            if(node instanceof Block) {
-                // Block's immediate parent is a with node. Note we aren't testing for a WithNode, as that'd capture
-                // processing of WithNode.expression too, but it should be unaffected.
-                return !isEmpty() && peek() instanceof WithNode;
-            } else if(node instanceof FunctionNode) {
-                // Function has a direct eval in it (so a top-level "var ..." in the eval code can introduce a new
-                // variable into the function's scope), and it isn't strict (as evals in strict functions get an
-                // isolated scope).
-                return isFunctionDynamicScope((FunctionNode)node);
-            }
-            return false;
-        }
-    }
-
-    boolean inDynamicScope() {
-        return ((DynamicScopeTrackingLexicalContext)getLexicalContext()).dynamicScopeCount > 0;
-    }
-
-    static boolean isFunctionDynamicScope(FunctionNode fn) {
-        return fn.hasEval() && !fn.isStrict();
-    }
-
-    /**
      * Check if this symbol can be accessed directly with a putfield or getfield or dynamic load
      *
      * @param function function to check for fast scope
      * @return true if fast scope
      */
     private boolean isFastScope(final Symbol symbol) {
-        if(!symbol.isScope()) {
+        if (!symbol.isScope()) {
             return false;
         }
-        final LexicalContext lc = getLexicalContext();
-        if(!inDynamicScope()) {
+
+        if (!lc.inDynamicScope()) {
             // If there's no with or eval in context, and the symbol is marked as scoped, it is fast scoped. Such a
             // symbol must either be global, or its defining block must need scope.
             assert symbol.isGlobal() || lc.getDefiningBlock(symbol).needsScope() : symbol.getName();
             return true;
         }
-        if(symbol.isGlobal()) {
+
+        if (symbol.isGlobal()) {
             // Shortcut: if there's a with or eval in context, globals can't be fast scoped
             return false;
         }
+
         // Otherwise, check if there's a dynamic scope between use of the symbol and its definition
         final String name = symbol.getName();
         boolean previousWasBlock = false;
         for (final Iterator<LexicalContextNode> it = lc.getAllNodes(); it.hasNext();) {
             final LexicalContextNode node = it.next();
-            if(node instanceof Block) {
+            if (node instanceof Block) {
                 // If this block defines the symbol, then we can fast scope the symbol.
                 final Block block = (Block)node;
-                if(block.getExistingSymbol(name) == symbol) {
+                if (block.getExistingSymbol(name) == symbol) {
                     assert block.needsScope();
                     return true;
                 }
                 previousWasBlock = true;
             } else {
-                if((node instanceof WithNode && previousWasBlock) || (node instanceof FunctionNode && isFunctionDynamicScope((FunctionNode)node))) {
+                if ((node instanceof WithNode && previousWasBlock) || (node instanceof FunctionNode && CodeGeneratorLexicalContext.isFunctionDynamicScope((FunctionNode)node))) {
                     // If we hit a scope that can have symbols introduced into it at run time before finding the defining
                     // block, the symbol can't be fast scoped. A WithNode only counts if we've immediately seen a block
                     // before - its block. Otherwise, we are currently processing the WithNode's expression, and that's
@@ -387,16 +293,14 @@
     }
 
     private MethodEmitter loadSharedScopeVar(final Type valueType, final Symbol symbol, final int flags) {
-        method.load(isFastScope(symbol) ? getScopeProtoDepth(getLexicalContext().getCurrentBlock(), symbol) : -1);
-        final SharedScopeCall scopeCall = getScopeGet(valueType, symbol, flags | CALLSITE_FAST_SCOPE);
-        scopeCall.generateInvoke(method);
-        return method;
+        method.load(isFastScope(symbol) ? getScopeProtoDepth(lc.getCurrentBlock(), symbol) : -1);
+        final SharedScopeCall scopeCall = lc.getScopeGet(unit, valueType, symbol, flags | CALLSITE_FAST_SCOPE);
+        return scopeCall.generateInvoke(method);
     }
 
     private MethodEmitter loadFastScopeVar(final Type valueType, final Symbol symbol, final int flags, final boolean isMethod) {
         loadFastScopeProto(symbol, false);
-        method.dynamicGet(valueType, symbol.getName(), flags | CALLSITE_FAST_SCOPE, isMethod);
-        return method;
+        return method.dynamicGet(valueType, symbol.getName(), flags | CALLSITE_FAST_SCOPE, isMethod);
     }
 
     private MethodEmitter storeFastScopeVar(final Type valueType, final Symbol symbol, final int flags) {
@@ -408,7 +312,7 @@
     private int getScopeProtoDepth(final Block startingBlock, final Symbol symbol) {
         int depth = 0;
         final String name = symbol.getName();
-        for(final Iterator<Block> blocks = getLexicalContext().getBlocks(startingBlock); blocks.hasNext();) {
+        for(final Iterator<Block> blocks = lc.getBlocks(startingBlock); blocks.hasNext();) {
             final Block currentBlock = blocks.next();
             if (currentBlock.getExistingSymbol(name) == symbol) {
                 return depth;
@@ -421,7 +325,7 @@
     }
 
     private void loadFastScopeProto(final Symbol symbol, final boolean swap) {
-        final int depth = getScopeProtoDepth(getLexicalContext().getCurrentBlock(), symbol);
+        final int depth = getScopeProtoDepth(lc.getCurrentBlock(), symbol);
         assert depth != -1;
         if (depth > 0) {
             if (swap) {
@@ -464,7 +368,7 @@
          */
         final CodeGenerator codegen = this;
 
-        node.accept(new NodeVisitor() {
+        node.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
             @Override
             public boolean enterIdentNode(final IdentNode identNode) {
                 loadIdent(identNode);
@@ -538,7 +442,7 @@
             final boolean isInternal = symbol.isParam() || symbol.isInternal() || symbol.isThis() || !symbol.canBeUndefined();
 
             if (symbol.hasSlot() && !isInternal) {
-                assert symbol.getSymbolType().isNumber() || symbol.getSymbolType().isObject() : "no potentially undefined narrower local vars than doubles are allowed: " + symbol + " in " + getLexicalContext().getCurrentFunction();
+                assert symbol.getSymbolType().isNumber() || symbol.getSymbolType().isObject() : "no potentially undefined narrower local vars than doubles are allowed: " + symbol + " in " + lc.getCurrentFunction();
                 if (symbol.getSymbolType().isNumber()) {
                     numbers.add(symbol);
                 } else if (symbol.getSymbolType().isObject()) {
@@ -552,17 +456,18 @@
     }
 
     private void initSymbols(final LinkedList<Symbol> symbols, final Type type) {
-        if (symbols.isEmpty()) {
-            return;
-        }
-
-        method.loadUndefined(type);
-        while (!symbols.isEmpty()) {
-            final Symbol symbol = symbols.removeFirst();
-            if (!symbols.isEmpty()) {
-                method.dup();
-            }
-            method.store(symbol);
+        final Iterator<Symbol> it = symbols.iterator();
+        if(it.hasNext()) {
+            method.loadUndefined(type);
+            boolean hasNext;
+            do {
+                final Symbol symbol = it.next();
+                hasNext = it.hasNext();
+                if(hasNext) {
+                    method.dup();
+                }
+                method.store(symbol);
+            } while(hasNext);
         }
     }
 
@@ -595,7 +500,6 @@
         if (block.needsScope() && !block.isTerminal()) {
             popBlockScope(block);
         }
-        --nextFreeSlotsSize;
         return block;
     }
 
@@ -624,11 +528,11 @@
     public boolean enterBreakNode(final BreakNode breakNode) {
         lineNumber(breakNode);
 
-        final BreakableNode breakFrom = getLexicalContext().getBreakable(breakNode.getLabel());
-        for (int i = 0; i < getLexicalContext().getScopeNestingLevelTo(breakFrom); i++) {
+        final BreakableNode breakFrom = lc.getBreakable(breakNode.getLabel());
+        for (int i = 0; i < lc.getScopeNestingLevelTo(breakFrom); i++) {
             closeWith();
         }
-        method.splitAwareGoto(getLexicalContext(), breakFrom.getBreakLabel());
+        method.splitAwareGoto(lc, breakFrom.getBreakLabel());
 
         return false;
     }
@@ -672,11 +576,12 @@
 
         final List<Node>   args            = callNode.getArgs();
         final Node         function        = callNode.getFunction();
-        final Block        currentBlock    = getLexicalContext().getCurrentBlock();
-
-        function.accept(new NodeVisitor() {
-
-            private void sharedScopeCall(final IdentNode identNode, final int flags) {
+        final Block        currentBlock    = lc.getCurrentBlock();
+        final CodeGeneratorLexicalContext codegenLexicalContext = lc;
+
+        function.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
+
+            private MethodEmitter sharedScopeCall(final IdentNode identNode, final int flags) {
                 final Symbol symbol = identNode.getSymbol();
                 int    scopeCallFlags = flags;
                 method.loadCompilerConstant(SCOPE);
@@ -688,8 +593,8 @@
                 }
                 loadArgs(args);
                 final Type[] paramTypes = method.getTypesFromStack(args.size());
-                final SharedScopeCall scopeCall = getScopeCall(symbol, identNode.getType(), callNode.getType(), paramTypes, scopeCallFlags);
-                scopeCall.generateInvoke(method);
+                final SharedScopeCall scopeCall = codegenLexicalContext.getScopeCall(unit, symbol, identNode.getType(), callNode.getType(), paramTypes, scopeCallFlags);
+                return scopeCall.generateInvoke(method);
             }
 
             private void scopeCall(final IdentNode node, final int flags) {
@@ -756,7 +661,7 @@
                         evalCall(node, flags);
                     } else if (useCount <= SharedScopeCall.FAST_SCOPE_CALL_THRESHOLD
                             || (!isFastScope(symbol) && useCount <= SharedScopeCall.SLOW_SCOPE_CALL_THRESHOLD)
-                            || CodeGenerator.this.inDynamicScope()) {
+                            || CodeGenerator.this.lc.inDynamicScope()) {
                         scopeCall(node, flags);
                     } else {
                         sharedScopeCall(node, flags);
@@ -845,11 +750,11 @@
     public boolean enterContinueNode(final ContinueNode continueNode) {
         lineNumber(continueNode);
 
-        final LoopNode continueTo = getLexicalContext().getContinueTo(continueNode.getLabel());
-        for (int i = 0; i < getLexicalContext().getScopeNestingLevelTo(continueTo); i++) {
+        final LoopNode continueTo = lc.getContinueTo(continueNode.getLabel());
+        for (int i = 0; i < lc.getScopeNestingLevelTo(continueTo); i++) {
             closeWith();
         }
-        method.splitAwareGoto(getLexicalContext(), continueTo.getContinueLabel());
+        method.splitAwareGoto(lc, continueTo.getContinueLabel());
 
         return false;
     }
@@ -875,90 +780,89 @@
     public boolean enterForNode(final ForNode forNode) {
         lineNumber(forNode);
 
+        if (forNode.isForIn()) {
+            enterForIn(forNode);
+        } else {
+            enterFor(forNode);
+        }
+
+        return false;
+    }
+
+    private void enterFor(final ForNode forNode) {
+        final Node  init   = forNode.getInit();
         final Node  test   = forNode.getTest();
         final Block body   = forNode.getBody();
         final Node  modify = forNode.getModify();
 
-        final Label breakLabel    = forNode.getBreakLabel();
-        final Label continueLabel = forNode.getContinueLabel();
-        final Label loopLabel     = new Label("loop");
+        if (init != null) {
+            init.accept(this);
+        }
+
+        final Label loopLabel = new Label("loop");
+        final Label testLabel = new Label("test");
+
+        method._goto(testLabel);
+        method.label(loopLabel);
+        body.accept(this);
+        method.label(forNode.getContinueLabel());
+
+        if (!body.isTerminal() && modify != null) {
+            load(modify);
+        }
+
+        method.label(testLabel);
+        if (test != null) {
+            new BranchOptimizer(this, method).execute(test, loopLabel, true);
+        } else {
+            method._goto(loopLabel);
+        }
+
+        method.label(forNode.getBreakLabel());
+    }
+
+    private void enterForIn(final ForNode forNode) {
+        final Block body   = forNode.getBody();
+        final Node  modify = forNode.getModify();
+
+        final Symbol iter      = forNode.getIterator();
+        final Label  loopLabel = new Label("loop");
 
         Node init = forNode.getInit();
 
-        if (forNode.isForIn()) {
-            final Symbol iter = forNode.getIterator();
-
-            // We have to evaluate the optional initializer expression
-            // of the iterator variable of the for-in statement.
-            if (init instanceof VarNode) {
-                init.accept(this);
-                init = ((VarNode)init).getName();
+        // We have to evaluate the optional initializer expression
+        // of the iterator variable of the for-in statement.
+        if (init instanceof VarNode) {
+            init.accept(this);
+            init = ((VarNode)init).getName();
+        }
+
+        load(modify);
+        assert modify.getType().isObject();
+        method.invoke(forNode.isForEach() ? ScriptRuntime.TO_VALUE_ITERATOR : ScriptRuntime.TO_PROPERTY_ITERATOR);
+        method.store(iter);
+        method._goto(forNode.getContinueLabel());
+        method.label(loopLabel);
+
+        new Store<Node>(init) {
+            @Override
+            protected void storeNonDiscard() {
+                return;
             }
-
-            load(modify);
-            assert modify.getType().isObject();
-            method.invoke(forNode.isForEach() ? ScriptRuntime.TO_VALUE_ITERATOR : ScriptRuntime.TO_PROPERTY_ITERATOR);
-            method.store(iter);
-            method._goto(continueLabel);
-            method.label(loopLabel);
-
-            new Store<Node>(init) {
-                @Override
-                protected void storeNonDiscard() {
-                    return;
-                }
-                @Override
-                protected void evaluate() {
-                    method.load(iter);
-                    method.invoke(interfaceCallNoLookup(Iterator.class, "next", Object.class));
-                }
-            }.store();
-
-            body.accept(this);
-
-            method.label(continueLabel);
-            method.load(iter);
-            method.invoke(interfaceCallNoLookup(Iterator.class, "hasNext", boolean.class));
-            method.ifne(loopLabel);
-            method.label(breakLabel);
-        } else {
-            if (init != null) {
-                init.accept(this);
+            @Override
+            protected void evaluate() {
+                method.load(iter);
+                method.invoke(interfaceCallNoLookup(Iterator.class, "next", Object.class));
             }
-
-            final Label testLabel = new Label("test");
-
-            method._goto(testLabel);
-            method.label(loopLabel);
-            body.accept(this);
-            method.label(continueLabel);
-
-            if (!body.isTerminal() && modify != null) {
-                load(modify);
-            }
-
-            method.label(testLabel);
-            if (test != null) {
-                new BranchOptimizer(this, method).execute(test, loopLabel, true);
-            } else {
-                method._goto(loopLabel);
-            }
-
-            method.label(breakLabel);
-        }
-
-        return false;
-    }
-
-    private static int assignSlots(final Block block, final int firstSlot) {
-        int nextSlot = firstSlot;
-        for (final Symbol symbol : block.getSymbols()) {
-            if (symbol.hasSlot()) {
-                symbol.setSlot(nextSlot);
-                nextSlot += symbol.slotCount();
-            }
-        }
-        return nextSlot;
+        }.store();
+
+        body.accept(this);
+
+        method.label(forNode.getContinueLabel());
+        method.load(iter);
+        method.invoke(interfaceCallNoLookup(Iterator.class, "hasNext", boolean.class));
+        method.ifne(loopLabel);
+        method.label(forNode.getBreakLabel());
     }
 
     /**
@@ -967,24 +871,11 @@
      * @param block block with local vars.
      */
     private void initLocals(final Block block) {
-        final boolean isFunctionBody = getLexicalContext().isFunctionBody();
-
-        final int nextFreeSlot;
-        if (isFunctionBody) {
-            // On entry to function, start with slot 0
-            nextFreeSlot = 0;
-        } else {
-            // Otherwise, continue from previous block's first free slot
-            nextFreeSlot = nextFreeSlots[nextFreeSlotsSize - 1];
-        }
-        if(nextFreeSlotsSize == nextFreeSlots.length) {
-            final int[] newNextFreeSlots = new int[nextFreeSlotsSize * 2];
-            System.arraycopy(nextFreeSlots, 0, newNextFreeSlots, 0, nextFreeSlotsSize);
-            nextFreeSlots = newNextFreeSlots;
-        }
-        nextFreeSlots[nextFreeSlotsSize++] = assignSlots(block, nextFreeSlot);
-
-        final FunctionNode function = getLexicalContext().getCurrentFunction();
+        lc.nextFreeSlot(block);
+
+        final boolean isFunctionBody = lc.isFunctionBody();
+
+        final FunctionNode function = lc.getCurrentFunction();
         if (isFunctionBody) {
             /* Fix the predefined slots so they have numbers >= 0, like varargs. */
             if (function.needsParentScope()) {
@@ -1023,7 +914,7 @@
                 }
 
                 if (symbol.isVar()) {
-                    if(varsInScope || symbol.isScope()) {
+                    if (varsInScope || symbol.isScope()) {
                         nameList.add(symbol.getName());
                         newSymbols.add(symbol);
                         values.add(null);
@@ -1051,18 +942,13 @@
              */
             final FieldObjectCreator<Symbol> foc = new FieldObjectCreator<Symbol>(this, nameList, newSymbols, values, true, hasArguments) {
                 @Override
-                protected Type getValueType(final Symbol value) {
-                    return value.getSymbolType();
-                }
-
-                @Override
                 protected void loadValue(final Symbol value) {
                     method.load(value);
                 }
 
                 @Override
                 protected void loadScope(MethodEmitter m) {
-                    if(function.needsParentScope()) {
+                    if (function.needsParentScope()) {
                         m.loadCompilerConstant(SCOPE);
                     } else {
                         m.loadNull();
@@ -1096,7 +982,7 @@
 
     private void initArguments(final FunctionNode function) {
         method.loadCompilerConstant(VARARGS);
-        if(function.needsCallee()) {
+        if (function.needsCallee()) {
             method.loadCompilerConstant(CALLEE);
         } else {
             // If function is strict mode, "arguments.callee" is not populated, so we don't necessarily need the
@@ -1126,10 +1012,10 @@
         LOG.info("=== BEGIN ", functionNode.getName());
 
         assert functionNode.getCompileUnit() != null : "no compile unit for " + functionNode.getName() + " " + Debug.id(functionNode);
-        push(functionNode.getCompileUnit());
-        assert !compileUnits.isEmpty();
-
-        pushMethodEmitter(unit.getClassEmitter().method(functionNode));
+        unit = lc.pushCompileUnit(functionNode.getCompileUnit());
+        assert lc.hasCompileUnits();
+
+        method = lc.pushMethodEmitter(unit.getClassEmitter().method(functionNode));
         // Mark end for variable tables.
         method.begin();
 
@@ -1140,11 +1026,11 @@
     public Node leaveFunctionNode(final FunctionNode functionNode) {
         try {
             method.end(); // wrap up this method
-            pop(functionNode.getCompileUnit());
-            popMethodEmitter(method);
+            unit   = lc.popCompileUnit(functionNode.getCompileUnit());
+            method = lc.popMethodEmitter(method);
             LOG.info("=== END ", functionNode.getName());
 
-            final FunctionNode newFunctionNode = functionNode.setState(getLexicalContext(), CompilationState.EMITTED);
+            final FunctionNode newFunctionNode = functionNode.setState(lc, CompilationState.EMITTED);
 
             newFunctionObject(newFunctionNode, functionNode);
             return newFunctionNode;
@@ -1238,16 +1124,16 @@
             final MethodEmitter savedMethod = method;
 
             for (final ArrayUnit arrayUnit : units) {
-                push(arrayUnit.getCompileUnit());
+                unit = lc.pushCompileUnit(arrayUnit.getCompileUnit());
 
                 final String className = unit.getUnitClassName();
-                final String name      = getLexicalContext().getCurrentFunction().uniqueName(SPLIT_PREFIX.symbolName());
+                final String name      = lc.getCurrentFunction().uniqueName(SPLIT_PREFIX.symbolName());
                 final String signature = methodDescriptor(type, Object.class, ScriptFunction.class, ScriptObject.class, type);
 
                 final MethodEmitter me = unit.getClassEmitter().method(EnumSet.of(Flag.PUBLIC, Flag.STATIC), name, signature);
-                pushMethodEmitter(me);
-
-                method.setFunctionNode(getLexicalContext().getCurrentFunction());
+                method = lc.pushMethodEmitter(me);
+
+                method.setFunctionNode(lc.getCurrentFunction());
                 method.begin();
 
                 fixScopeSlot();
@@ -1260,7 +1146,7 @@
 
                 method._return();
                 method.end();
-                popMethodEmitter(me);
+                method = lc.popMethodEmitter(me);
 
                 assert method == savedMethod;
                 method.loadCompilerConstant(THIS);
@@ -1271,7 +1157,7 @@
                 method.swap();
                 method.invokestatic(className, name, signature);
 
-                pop(unit);
+                unit = lc.popCompileUnit(unit);
             }
 
             return method;
@@ -1407,7 +1293,7 @@
             return loadRegexToken(regexToken);
         }
         // emit field
-        final String       regexName    = getLexicalContext().getCurrentFunction().uniqueName(REGEX_PREFIX.symbolName());
+        final String       regexName    = lc.getCurrentFunction().uniqueName(REGEX_PREFIX.symbolName());
         final ClassEmitter classEmitter = unit.getClassEmitter();
 
         classEmitter.field(EnumSet.of(PRIVATE, STATIC), regexName, Object.class);
@@ -1440,8 +1326,7 @@
 
     @Override
     public boolean enterObjectNode(final ObjectNode objectNode) {
-        final List<Node> elements = objectNode.getElements();
-        final int        size     = elements.size();
+        final List<PropertyNode> elements = objectNode.getElements();
 
         final List<String> keys    = new ArrayList<>();
         final List<Symbol> symbols = new ArrayList<>();
@@ -1449,8 +1334,7 @@
 
         boolean hasGettersSetters = false;
 
-        for (int i = 0; i < size; i++) {
-            final PropertyNode propertyNode = (PropertyNode)elements.get(i);
+        for (PropertyNode propertyNode: elements) {
             final Node         value        = propertyNode.getValue();
             final String       key          = propertyNode.getKeyName();
             final Symbol       symbol       = value == null ? null : propertyNode.getSymbol();
@@ -1466,11 +1350,6 @@
 
         new FieldObjectCreator<Node>(this, keys, symbols, values) {
             @Override
-            protected Type getValueType(final Node node) {
-                return node.getType();
-            }
-
-            @Override
             protected void loadValue(final Node node) {
                 load(node);
             }
@@ -1545,7 +1424,7 @@
 
         method.registerReturn();
 
-        final Type returnType = getLexicalContext().getCurrentFunction().getReturnType();
+        final Type returnType = lc.getCurrentFunction().getReturnType();
 
         final Node expression = returnNode.getExpression();
         if (expression != null) {
@@ -1756,7 +1635,7 @@
 
         final CompileUnit splitCompileUnit = splitNode.getCompileUnit();
 
-        final FunctionNode fn   = getLexicalContext().getCurrentFunction();
+        final FunctionNode fn   = lc.getCurrentFunction();
         final String className  = splitCompileUnit.getUnitClassName();
         final String name       = splitNode.getName();
 
@@ -1767,7 +1646,7 @@
                 new Class<?>[] {ScriptFunction.class, Object.class, ScriptObject.class};
 
         final MethodEmitter caller = method;
-        push(splitCompileUnit);
+        unit = lc.pushCompileUnit(splitCompileUnit);
 
         final Call splitCall = staticCallNoLookup(
             className,
@@ -1781,8 +1660,7 @@
                         rtype,
                         ptypes);
 
-        pushMethodEmitter(splitEmitter);
-
+        method = lc.pushMethodEmitter(splitEmitter);
         method.setFunctionNode(fn);
 
         if (fn.needsCallee()) {
@@ -1809,7 +1687,7 @@
     }
 
     private void fixScopeSlot() {
-        if (getLexicalContext().getCurrentFunction().compilerConstant(SCOPE).getSlot() != SCOPE.slot()) {
+        if (lc.getCurrentFunction().compilerConstant(SCOPE).getSlot() != SCOPE.slot()) {
             // TODO hack to move the scope to the expected slot (that's needed because split methods reuse the same slots as the root method)
             method.load(Type.typeFor(ScriptObject.class), SCOPE.slot());
             method.storeCompilerConstant(SCOPE);
@@ -1826,15 +1704,15 @@
             // Wrap up this method.
 
             method.loadCompilerConstant(RETURN);
-            method._return(getLexicalContext().getCurrentFunction().getReturnType());
+            method._return(lc.getCurrentFunction().getReturnType());
             method.end();
 
-            pop(splitNode.getCompileUnit());
-            popMethodEmitter(method);
+            unit   = lc.popCompileUnit(splitNode.getCompileUnit());
+            method = lc.popMethodEmitter(method);
 
         } catch (final Throwable t) {
             Context.printStackTrace(t);
-            final VerifyError e = new VerifyError("Code generation bug in \"" + splitNode.getName() + "\": likely stack misaligned: " + t + " " + getLexicalContext().getCurrentFunction().getSource().getName());
+            final VerifyError e = new VerifyError("Code generation bug in \"" + splitNode.getName() + "\": likely stack misaligned: " + t + " " + lc.getCurrentFunction().getSource().getName());
             e.initCause(t);
             throw e;
         }
@@ -1862,7 +1740,7 @@
             //has to be zero
             caller.label(new Label("split_return"));
             method.loadCompilerConstant(RETURN);
-            caller._return(getLexicalContext().getCurrentFunction().getReturnType());
+            caller._return(lc.getCurrentFunction().getReturnType());
             caller.label(breakLabel);
         } else {
             assert !targets.isEmpty();
@@ -1879,14 +1757,14 @@
                 caller.label(labels[i - low]);
                 if (i == 0) {
                     caller.loadCompilerConstant(RETURN);
-                    caller._return(getLexicalContext().getCurrentFunction().getReturnType());
+                    caller._return(lc.getCurrentFunction().getReturnType());
                 } else {
                     // Clear split state.
                     caller.loadCompilerConstant(SCOPE);
                     caller.checkcast(Scope.class);
                     caller.load(-1);
                     caller.invoke(Scope.SET_SPLIT_STATE);
-                    caller.splitAwareGoto(getLexicalContext(), targets.get(i - 1));
+                    caller.splitAwareGoto(lc, targets.get(i - 1));
                 }
             }
             caller.label(breakLabel);
@@ -2028,9 +1906,16 @@
     public boolean enterThrowNode(final ThrowNode throwNode) {
         lineNumber(throwNode);
 
+        if (throwNode.isSyntheticRethrow()) {
+            //do not wrap whatever this is in an ecma exception, just rethrow it
+            load(throwNode.getExpression());
+            method.athrow();
+            return false;
+        }
+
         method._new(ECMAException.class).dup();
 
-        final Source source     = getLexicalContext().getCurrentFunction().getSource();
+        final Source source     = lc.getCurrentFunction().getSource();
 
         final Node   expression = throwNode.getExpression();
         final int    position   = throwNode.position();
@@ -2081,7 +1966,7 @@
             //TODO this is very ugly - try not to call enter/leave methods directly
             //better to use the implicit lexical context scoping given by the visitor's
             //accept method.
-            getLexicalContext().push(catchBlock);
+            lc.push(catchBlock);
             enterBlock(catchBlock);
 
             final CatchNode catchNode          = (CatchNode)catchBlocks.get(i).getStatements().get(0);
@@ -2094,15 +1979,19 @@
                 protected void storeNonDiscard() {
                     return;
                 }
+
                 @Override
                 protected void evaluate() {
+                    if (catchNode.isSyntheticRethrow()) {
+                        method.load(symbol);
+                        return;
+                    }
                     /*
                      * If caught object is an instance of ECMAException, then
                      * bind obj.thrown to the script catch var. Or else bind the
                      * caught object itself to the script catch var.
                      */
                     final Label notEcmaException = new Label("no_ecma_exception");
-
                     method.load(symbol).dup()._instanceof(ECMAException.class).ifeq(notEcmaException);
                     method.checkcast(ECMAException.class); //TODO is this necessary?
                     method.getField(ECMAException.THROWN);
@@ -2137,7 +2026,7 @@
             }
 
             leaveBlock(catchBlock);
-            getLexicalContext().pop(catchBlock);
+            lc.pop(catchBlock);
         }
 
         method.label(skip);
@@ -2234,7 +2123,7 @@
         final boolean hasScope = method.hasScope();
 
         final Label tryLabel;
-        if(hasScope) {
+        if (hasScope) {
             tryLabel = new Label("with_try");
             method.label(tryLabel);
             method.loadCompilerConstant(SCOPE);
@@ -2245,7 +2134,7 @@
         load(expression);
         assert expression.getType().isObject() : "with expression needs to be object: " + expression;
 
-        if(hasScope) {
+        if (hasScope) {
             // Construct a WithObject if we have a scope
             method.invoke(ScriptRuntime.OPEN_WITH);
             method.storeCompilerConstant(SCOPE);
@@ -2285,7 +2174,7 @@
     @Override
     public boolean enterADD(final UnaryNode unaryNode) {
         load(unaryNode.rhs());
-        assert unaryNode.rhs().getType().isNumber();
+        assert unaryNode.rhs().getType().isNumber() : unaryNode.rhs().getType() + " "+ unaryNode.getSymbol();
         method.store(unaryNode.getSymbol());
 
         return false;
@@ -2320,7 +2209,7 @@
                 }
                 method.convert(Type.OBJECT);
             } else if (value instanceof Boolean) {
-                method.getField(staticField(Boolean.class, value.toString().toUpperCase(), Boolean.class));
+                method.getField(staticField(Boolean.class, value.toString().toUpperCase(Locale.ENGLISH), Boolean.class));
             } else {
                 load(rhs);
                 method.convert(unaryNode.getType());
@@ -2387,13 +2276,13 @@
     public boolean enterDISCARD(final UnaryNode unaryNode) {
         final Node rhs = unaryNode.rhs();
 
-        discard.push(rhs);
+        lc.pushDiscard(rhs);
         load(rhs);
 
-        if (discard.peek() == rhs) {
+        if (lc.getCurrentDiscard() == rhs) {
             assert !rhs.isAssignment();
             method.pop();
-            discard.pop();
+            lc.popDiscard();
         }
 
         return false;
@@ -2445,7 +2334,7 @@
         assert lhs.getType().equals(rhs.getType()) && lhs.getType().equals(type) : lhs.getType() + " != " + rhs.getType() + " != " + type + " " + new ASTWriter(lhs) + " " + new ASTWriter(rhs);
         load(lhs);
         load(rhs);
-        method.add();
+        method.add(); //if the symbol is optimistic, it always needs to be written, not on the stack?
         method.store(symbol);
         return null;
     }
@@ -2989,53 +2878,12 @@
      * Generate all shared scope calls generated during codegen.
      */
     protected void generateScopeCalls() {
-        for (final SharedScopeCall scopeAccess : scopeCalls.values()) {
+        for (final SharedScopeCall scopeAccess : lc.getScopeCalls()) {
             scopeAccess.generateScopeCall();
         }
     }
 
     /**
-     * Get a shared static method representing a dynamic scope callsite.
-     *
-     * @param symbol the symbol
-     * @param valueType the value type of the symbol
-     * @param returnType the return type
-     * @param paramTypes the parameter types
-     * @param flags the callsite flags
-     * @return an object representing a shared scope call
-     */
-    private SharedScopeCall getScopeCall(final Symbol symbol, final Type valueType, final Type returnType,
-                                         final Type[] paramTypes, final int flags) {
-
-        final SharedScopeCall scopeCall = new SharedScopeCall(symbol, valueType, returnType, paramTypes, flags);
-        if (scopeCalls.containsKey(scopeCall)) {
-            return scopeCalls.get(scopeCall);
-        }
-        scopeCall.setClassAndName(unit, getLexicalContext().getCurrentFunction().uniqueName("scopeCall"));
-        scopeCalls.put(scopeCall, scopeCall);
-        return scopeCall;
-    }
-
-    /**
-     * Get a shared static method representing a dynamic scope get access.
-     *
-     * @param type the type of the variable
-     * @param symbol the symbol
-     * @param flags the callsite flags
-     * @return an object representing a shared scope call
-     */
-    private SharedScopeCall getScopeGet(final Type type, final Symbol symbol, final int flags) {
-
-        final SharedScopeCall scopeCall = new SharedScopeCall(symbol, type, type, null, flags);
-        if (scopeCalls.containsKey(scopeCall)) {
-            return scopeCalls.get(scopeCall);
-        }
-        scopeCall.setClassAndName(unit, getLexicalContext().getCurrentFunction().uniqueName("scopeCall"));
-        scopeCalls.put(scopeCall, scopeCall);
-        return scopeCall;
-    }
-
-    /**
      * Debug code used to print symbols
      *
      * @param block the block we are in
@@ -3129,14 +2977,14 @@
 
         private void prologue() {
             final Symbol targetSymbol = target.getSymbol();
-            final Symbol scopeSymbol  = getLexicalContext().getCurrentFunction().compilerConstant(SCOPE);
+            final Symbol scopeSymbol  = lc.getCurrentFunction().compilerConstant(SCOPE);
 
             /**
              * This loads the parts of the target, e.g base and index. they are kept
              * on the stack throughout the store and used at the end to execute it
              */
 
-            target.accept(new NodeVisitor() {
+            target.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
                 @Override
                 public boolean enterIdentNode(final IdentNode node) {
                     if (targetSymbol.isScope()) {
@@ -3203,22 +3051,21 @@
          * @return the quick symbol
          */
         private Symbol quickSymbol(final Type type, final String prefix) {
-            final String name = getLexicalContext().getCurrentFunction().uniqueName(prefix);
+            final String name = lc.getCurrentFunction().uniqueName(prefix);
             final Symbol symbol = new Symbol(name, IS_TEMP | IS_INTERNAL);
 
             symbol.setType(type);
-            final int quickSlot = nextFreeSlots[nextFreeSlotsSize - 1];
-            nextFreeSlots[nextFreeSlotsSize - 1] = quickSlot + symbol.slotCount();
-            symbol.setSlot(quickSlot);
+
+            symbol.setSlot(lc.quickSlot(symbol));
 
             return symbol;
         }
 
         // store the result that "lives on" after the op, e.g. "i" in i++ postfix.
         protected void storeNonDiscard() {
-            if (discard.peek() == assignNode) {
+            if (lc.getCurrentDiscard() == assignNode) {
                 assert assignNode.isAssignment();
-                discard.pop();
+                lc.popDiscard();
                 return;
             }
 
@@ -3246,7 +3093,7 @@
              */
             method.convert(target.getType());
 
-            target.accept(new NodeVisitor() {
+            target.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
                 @Override
                 protected boolean enterDefault(Node node) {
                     throw new AssertionError("Unexpected node " + node + " in store epilogue");
@@ -3308,7 +3155,6 @@
     }
 
     private void newFunctionObject(final FunctionNode functionNode, final FunctionNode originalFunctionNode) {
-        final LexicalContext lc = getLexicalContext();
         assert lc.peek() == functionNode;
         // We don't emit a ScriptFunction on stack for:
         // 1. the outermost compiled function (as there's no code being generated in its outer context that'd need it
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jdk/nashorn/internal/codegen/CodeGeneratorLexicalContext.java	Mon Jun 10 09:53:21 2013 +0100
@@ -0,0 +1,235 @@
+/*
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.nashorn.internal.codegen;
+
+import java.util.ArrayDeque;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Deque;
+import java.util.HashMap;
+import java.util.Map;
+
+import jdk.nashorn.internal.codegen.types.Type;
+import jdk.nashorn.internal.ir.Block;
+import jdk.nashorn.internal.ir.FunctionNode;
+import jdk.nashorn.internal.ir.LexicalContext;
+import jdk.nashorn.internal.ir.LexicalContextNode;
+import jdk.nashorn.internal.ir.Node;
+import jdk.nashorn.internal.ir.Symbol;
+import jdk.nashorn.internal.ir.WithNode;
+
+/**
+ * A lexical context that also tracks if we have any dynamic scopes in the context. Such scopes can have new
+ * variables introduced into them at run time - a with block or a function directly containing an eval call.
+ * Furthermore, this class keeps track of current discard state, which the current method emitter being used is,
+ * the current compile unit, and local variable indexes
+ */
+final class CodeGeneratorLexicalContext extends LexicalContext {
+    private int dynamicScopeCount;
+
+    /** Map of shared scope call sites */
+    private final Map<SharedScopeCall, SharedScopeCall> scopeCalls = new HashMap<>();
+
+    /** Compile unit stack - every time we start a sub method (e.g. a split) we push one */
+    private final Deque<CompileUnit> compileUnits = new ArrayDeque<>();
+
+    /** Method emitter stack - every time we start a sub method (e.g. a split) we push one */
+    private final Deque<MethodEmitter> methodEmitters = new ArrayDeque<>();
+
+    /** The discard stack - whenever we enter a discard node we keep track of its return value status -
+     *  i.e. should we keep it or throw it away */
+    private final Deque<Node> discard = new ArrayDeque<>();
+
+    /** A stack tracking the next free local variable slot in the blocks. There's one entry for every block
+     *  currently on the lexical context stack. */
+    private int[] nextFreeSlots = new int[16];
+
+    /** size of next free slot vector */
+    private int nextFreeSlotsSize;
+
+    @Override
+    public <T extends LexicalContextNode> T push(final T node) {
+        if (isDynamicScopeBoundary(node)) {
+            ++dynamicScopeCount;
+        }
+        return super.push(node);
+    }
+
+    @Override
+    public <T extends LexicalContextNode> T pop(final T node) {
+        final T popped = super.pop(node);
+        if (isDynamicScopeBoundary(popped)) {
+            --dynamicScopeCount;
+        }
+        if (node instanceof Block) {
+            --nextFreeSlotsSize;
+        }
+        return popped;
+    }
+
+    private boolean isDynamicScopeBoundary(final LexicalContextNode node) {
+        if (node instanceof Block) {
+            // Block's immediate parent is a with node. Note we aren't testing for a WithNode, as that'd capture
+            // processing of WithNode.expression too, but it should be unaffected.
+            return !isEmpty() && peek() instanceof WithNode;
+        } else if (node instanceof FunctionNode) {
+            // Function has a direct eval in it (so a top-level "var ..." in the eval code can introduce a new
+            // variable into the function's scope), and it isn't strict (as evals in strict functions get an
+            // isolated scope).
+            return isFunctionDynamicScope((FunctionNode)node);
+        }
+        return false;
+    }
+
+    boolean inDynamicScope() {
+        return dynamicScopeCount > 0;
+    }
+
+    static boolean isFunctionDynamicScope(FunctionNode fn) {
+        return fn.hasEval() && !fn.isStrict();
+    }
+
+    MethodEmitter pushMethodEmitter(final MethodEmitter newMethod) {
+        methodEmitters.push(newMethod);
+        return newMethod;
+    }
+
+    MethodEmitter popMethodEmitter(final MethodEmitter oldMethod) {
+        assert methodEmitters.peek() == oldMethod;
+        methodEmitters.pop();
+        return methodEmitters.isEmpty() ? null : methodEmitters.peek();
+    }
+
+    CompileUnit pushCompileUnit(final CompileUnit newUnit) {
+        compileUnits.push(newUnit);
+        return newUnit;
+    }
+
+    CompileUnit popCompileUnit(final CompileUnit oldUnit) {
+        assert compileUnits.peek() == oldUnit;
+        compileUnits.pop();
+        return compileUnits.isEmpty() ? null : compileUnits.peek();
+    }
+
+    boolean hasCompileUnits() {
+        return !compileUnits.isEmpty();
+    }
+
+    Collection<SharedScopeCall> getScopeCalls() {
+        return Collections.unmodifiableCollection(scopeCalls.values());
+    }
+
+    /**
+     * Get a shared static method representing a dynamic scope callsite.
+     *
+     * @param unit current compile unit
+     * @param symbol the symbol
+     * @param valueType the value type of the symbol
+     * @param returnType the return type
+     * @param paramTypes the parameter types
+     * @param flags the callsite flags
+     * @return an object representing a shared scope call
+     */
+    SharedScopeCall getScopeCall(final CompileUnit unit, final Symbol symbol, final Type valueType, final Type returnType, final Type[] paramTypes, final int flags) {
+        final SharedScopeCall scopeCall = new SharedScopeCall(symbol, valueType, returnType, paramTypes, flags);
+        if (scopeCalls.containsKey(scopeCall)) {
+            return scopeCalls.get(scopeCall);
+        }
+        scopeCall.setClassAndName(unit, getCurrentFunction().uniqueName("scopeCall"));
+        scopeCalls.put(scopeCall, scopeCall);
+        return scopeCall;
+    }
+
+    /**
+     * Get a shared static method representing a dynamic scope get access.
+     *
+     * @param unit current compile unit
+     * @param type the type of the variable
+     * @param symbol the symbol
+     * @param flags the callsite flags
+     * @return an object representing a shared scope call
+     */
+    SharedScopeCall getScopeGet(final CompileUnit unit, final Type type, final Symbol symbol, final int flags) {
+        final SharedScopeCall scopeCall = new SharedScopeCall(symbol, type, type, null, flags);
+        if (scopeCalls.containsKey(scopeCall)) {
+            return scopeCalls.get(scopeCall);
+        }
+        scopeCall.setClassAndName(unit, getCurrentFunction().uniqueName("scopeCall"));
+        scopeCalls.put(scopeCall, scopeCall);
+        return scopeCall;
+    }
+
+
+    void nextFreeSlot(final Block block) {
+        final boolean isFunctionBody = isFunctionBody();
+
+        final int nextFreeSlot;
+        if (isFunctionBody) {
+            // On entry to function, start with slot 0
+            nextFreeSlot = 0;
+        } else {
+            // Otherwise, continue from previous block's first free slot
+            nextFreeSlot = nextFreeSlots[nextFreeSlotsSize - 1];
+        }
+        if (nextFreeSlotsSize == nextFreeSlots.length) {
+            final int[] newNextFreeSlots = new int[nextFreeSlotsSize * 2];
+            System.arraycopy(nextFreeSlots, 0, newNextFreeSlots, 0, nextFreeSlotsSize);
+            nextFreeSlots = newNextFreeSlots;
+        }
+        nextFreeSlots[nextFreeSlotsSize++] = assignSlots(block, nextFreeSlot);
+    }
+
+    private static int assignSlots(final Block block, final int firstSlot) {
+        int nextSlot = firstSlot;
+        for (final Symbol symbol : block.getSymbols()) {
+            if (symbol.hasSlot()) {
+                symbol.setSlot(nextSlot);
+                nextSlot += symbol.slotCount();
+            }
+        }
+        return nextSlot;
+    }
+
+    void pushDiscard(final Node node) {
+        discard.push(node);
+    }
+
+    Node popDiscard() {
+        return discard.pop();
+    }
+
+    Node getCurrentDiscard() {
+        return discard.peek();
+    }
+
+    int quickSlot(final Symbol symbol) {
+        final int quickSlot = nextFreeSlots[nextFreeSlotsSize - 1];
+        nextFreeSlots[nextFreeSlotsSize - 1] = quickSlot + symbol.slotCount();
+        return quickSlot;
+    }
+
+}
+
--- a/src/jdk/nashorn/internal/codegen/CompilationPhase.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/codegen/CompilationPhase.java	Mon Jun 10 09:53:21 2013 +0100
@@ -11,20 +11,27 @@
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.Deque;
 import java.util.EnumSet;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
+
+import jdk.nashorn.internal.codegen.types.Range;
 import jdk.nashorn.internal.codegen.types.Type;
 import jdk.nashorn.internal.ir.Block;
 import jdk.nashorn.internal.ir.CallNode;
 import jdk.nashorn.internal.ir.FunctionNode;
+import jdk.nashorn.internal.ir.LexicalContext;
+import jdk.nashorn.internal.ir.ReturnNode;
+import jdk.nashorn.internal.ir.Symbol;
 import jdk.nashorn.internal.ir.FunctionNode.CompilationState;
-import jdk.nashorn.internal.ir.LexicalContext;
 import jdk.nashorn.internal.ir.Node;
 import jdk.nashorn.internal.ir.TemporarySymbols;
 import jdk.nashorn.internal.ir.debug.ASTWriter;
 import jdk.nashorn.internal.ir.debug.PrintVisitor;
-import jdk.nashorn.internal.ir.visitor.NodeOperatorVisitor;
 import jdk.nashorn.internal.ir.visitor.NodeVisitor;
 import jdk.nashorn.internal.runtime.ECMAErrors;
 import jdk.nashorn.internal.runtime.ScriptEnvironment;
@@ -66,7 +73,7 @@
 
             FunctionNode newFunctionNode = outermostFunctionNode;
 
-            newFunctionNode = (FunctionNode)newFunctionNode.accept(new NodeVisitor() {
+            newFunctionNode = (FunctionNode)newFunctionNode.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
                 // self references are done with invokestatic and thus cannot
                 // have trampolines - never lazy
                 @Override
@@ -99,10 +106,9 @@
                 lazy.remove(node);
             }
 
-            newFunctionNode = (FunctionNode)newFunctionNode.accept(new NodeOperatorVisitor() {
+            newFunctionNode = (FunctionNode)newFunctionNode.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
                 @Override
                 public Node leaveFunctionNode(final FunctionNode functionNode) {
-                    final LexicalContext lc = getLexicalContext();
                     if (lazy.contains(functionNode)) {
                         Compiler.LOG.fine(
                                 "Marking ",
@@ -174,7 +180,7 @@
         FunctionNode transform(final Compiler compiler, final FunctionNode fn) {
             final TemporarySymbols ts = compiler.getTemporarySymbols();
             final FunctionNode newFunctionNode = (FunctionNode)enterAttr(fn, ts).accept(new Attr(ts));
-            if(compiler.getEnv()._print_mem_usage) {
+            if (compiler.getEnv()._print_mem_usage) {
                 Compiler.LOG.info("Attr temporary symbol count: " + ts.getTotalSymbolCount());
             }
             return newFunctionNode;
@@ -186,12 +192,11 @@
          * @param functionNode node where to start iterating
          */
         private FunctionNode enterAttr(final FunctionNode functionNode, final TemporarySymbols ts) {
-            return (FunctionNode)functionNode.accept(new NodeVisitor() {
+            return (FunctionNode)functionNode.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
                 @Override
                 public Node leaveFunctionNode(final FunctionNode node) {
-                    final LexicalContext lc = getLexicalContext();
                     if (node.isLazy()) {
-                        FunctionNode newNode = node.setReturnType(getLexicalContext(), Type.OBJECT);
+                        FunctionNode newNode = node.setReturnType(lc, Type.OBJECT);
                         return ts.ensureSymbol(lc, Type.OBJECT, newNode);
                     }
                     //node may have a reference here that needs to be nulled if it was referred to by
@@ -208,6 +213,89 @@
     },
 
     /*
+     * Range analysis
+     *    Conservatively prove that certain variables can be narrower than
+     *    the most generic number type
+     */
+    RANGE_ANALYSIS_PHASE(EnumSet.of(INITIALIZED, PARSED, CONSTANT_FOLDED, LOWERED, ATTR)) {
+        @Override
+        FunctionNode transform(final Compiler compiler, final FunctionNode fn) {
+            if (!compiler.getEnv()._range_analysis) {
+                return fn;
+            }
+
+            FunctionNode newFunctionNode = (FunctionNode)fn.accept(new RangeAnalyzer());
+            final List<ReturnNode> returns = new ArrayList<>();
+
+            newFunctionNode = (FunctionNode)newFunctionNode.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
+                private final Deque<ArrayList<ReturnNode>> returnStack = new ArrayDeque<>();
+
+                @Override
+                public boolean enterFunctionNode(final FunctionNode functionNode) {
+                    returnStack.push(new ArrayList<ReturnNode>());
+                    return true;
+                }
+
+                @Override
+                public Node leaveFunctionNode(final FunctionNode functionNode) {
+                    Type returnType = Type.UNKNOWN;
+                    for (final ReturnNode ret : returnStack.pop()) {
+                        if (ret.getExpression() == null) {
+                            returnType = Type.OBJECT;
+                            break;
+                        }
+                        returnType = Type.widest(returnType, ret.getExpression().getType());
+                    }
+                    return functionNode.setReturnType(lc, returnType);
+                }
+
+                @Override
+                public Node leaveReturnNode(final ReturnNode returnNode) {
+                    final ReturnNode result = (ReturnNode)leaveDefault(returnNode);
+                    returns.add(result);
+                    return result;
+                }
+
+                @Override
+                public Node leaveDefault(final Node node) {
+                    final Symbol symbol = node.getSymbol();
+                    if (symbol != null) {
+                        final Range range  = symbol.getRange();
+                        final Type  symbolType = symbol.getSymbolType();
+                        if (!symbolType.isNumeric()) {
+                            return node;
+                        }
+                        final Type  rangeType  = range.getType();
+                        if (!Type.areEquivalent(symbolType, rangeType) && Type.widest(symbolType, rangeType) == symbolType) { //we can narrow range
+                            RangeAnalyzer.LOG.info("[", lc.getCurrentFunction().getName(), "] ", symbol, " can be ", range.getType(), " ", symbol.getRange());
+                            return node.setSymbol(lc, symbol.setTypeOverrideShared(range.getType(), compiler.getTemporarySymbols()));
+                        }
+                    }
+                    return node;
+                }
+            });
+
+            Type returnType = Type.UNKNOWN;
+            for (final ReturnNode node : returns) {
+                if (node.getExpression() != null) {
+                    returnType = Type.widest(returnType, node.getExpression().getType());
+                } else {
+                    returnType = Type.OBJECT;
+                    break;
+                }
+            }
+
+            return newFunctionNode.setReturnType(null, returnType);
+        }
+
+        @Override
+        public String toString() {
+            return "[Range Analysis]";
+        }
+    },
+
+
+    /*
      * Splitter Split the AST into several compile units based on a size
      * heuristic Splitter needs attributed AST for weight calculations (e.g. is
      * a + b a ScriptRuntime.ADD with call overhead or a dadd with much less).
@@ -218,7 +306,6 @@
         FunctionNode transform(final Compiler compiler, final FunctionNode fn) {
             final CompileUnit outermostCompileUnit = compiler.addCompileUnit(compiler.firstCompileUnitName());
 
-//            assert fn.isProgram() ;
             final FunctionNode newFunctionNode = new Splitter(compiler, fn, outermostCompileUnit).split(fn);
 
             assert newFunctionNode.getCompileUnit() == outermostCompileUnit : "fn.compileUnit (" + newFunctionNode.getCompileUnit() + ") != " + outermostCompileUnit;
--- a/src/jdk/nashorn/internal/codegen/Compiler.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/codegen/Compiler.java	Mon Jun 10 09:53:21 2013 +0100
@@ -99,7 +99,7 @@
 
     private boolean strict;
 
-    private CodeInstaller<ScriptEnvironment> installer;
+    private final CodeInstaller<ScriptEnvironment> installer;
 
     private final TemporarySymbols temporarySymbols = new TemporarySymbols();
 
@@ -219,6 +219,7 @@
         CompilationPhase.CONSTANT_FOLDING_PHASE,
         CompilationPhase.LOWERING_PHASE,
         CompilationPhase.ATTRIBUTION_PHASE,
+        CompilationPhase.RANGE_ANALYSIS_PHASE,
         CompilationPhase.SPLITTING_PHASE,
         CompilationPhase.TYPE_FINALIZATION_PHASE,
         CompilationPhase.BYTECODE_GENERATION_PHASE);
@@ -384,6 +385,8 @@
         if (info) {
             final StringBuilder sb = new StringBuilder();
             sb.append("Compile job for '").
+                append(newFunctionNode.getSource()).
+                append(':').
                 append(newFunctionNode.getName()).
                 append("' finished");
 
@@ -487,7 +490,7 @@
         }
 
         if (sb != null) {
-            LOG.info(sb);
+            LOG.fine(sb);
         }
 
         return rootClass;
--- a/src/jdk/nashorn/internal/codegen/CompilerConstants.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/codegen/CompilerConstants.java	Mon Jun 10 09:53:21 2013 +0100
@@ -29,6 +29,7 @@
 
 import java.lang.invoke.MethodHandle;
 import java.lang.invoke.MethodHandles;
+import java.util.Iterator;
 import jdk.nashorn.internal.codegen.types.Type;
 import jdk.nashorn.internal.runtime.ScriptFunction;
 import jdk.nashorn.internal.runtime.ScriptObject;
@@ -105,13 +106,13 @@
     ARGUMENTS("arguments", Object.class, 2),
 
     /** prefix for iterators for for (x in ...) */
-    ITERATOR_PREFIX(":i"),
+    ITERATOR_PREFIX(":i", Iterator.class),
 
     /** prefix for tag variable used for switch evaluation */
     SWITCH_TAG_PREFIX(":s"),
 
     /** prefix for all exceptions */
-    EXCEPTION_PREFIX(":e"),
+    EXCEPTION_PREFIX(":e", Throwable.class),
 
     /** prefix for quick slots generated in Store */
     QUICK_PREFIX(":q"),
@@ -262,7 +263,7 @@
      * @return the internal descriptor for this type
      */
     public static String typeDescriptor(final Class<?> clazz) {
-        return Type.getDescriptor(clazz);
+        return Type.typeFor(clazz).getDescriptor();
     }
 
     /**
--- a/src/jdk/nashorn/internal/codegen/FieldObjectCreator.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/codegen/FieldObjectCreator.java	Mon Jun 10 09:53:21 2013 +0100
@@ -145,15 +145,6 @@
     protected abstract void loadValue(T value);
 
     /**
-     * Determine the type of a value. Defined by anonymous subclasses in code gen.
-     *
-     * @param value Value to inspect.
-     *
-     * @return Value type.
-     */
-    protected abstract Type getValueType(T value);
-
-    /**
      * Store a value in a field of the generated class object.
      *
      * @param method      Script method.
@@ -165,13 +156,6 @@
         method.dup();
 
         loadValue(value);
-
-        final Type valueType = getValueType(value);
-        // for example when we have a with scope
-        if (valueType.isObject() || valueType.isBoolean()) {
-            method.convert(OBJECT);
-        }
-
         method.convert(OBJECT);
         method.putField(getClassName(), ObjectClassGenerator.getFieldName(fieldIndex, Type.OBJECT), typeDescriptor(Object.class));
     }
--- a/src/jdk/nashorn/internal/codegen/FinalizeTypes.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/codegen/FinalizeTypes.java	Mon Jun 10 09:53:21 2013 +0100
@@ -31,6 +31,7 @@
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
+
 import jdk.nashorn.internal.codegen.types.Type;
 import jdk.nashorn.internal.ir.AccessNode;
 import jdk.nashorn.internal.ir.Assignment;
@@ -84,13 +85,14 @@
  * and frame optimizations
  */
 
-final class FinalizeTypes extends NodeOperatorVisitor {
+final class FinalizeTypes extends NodeOperatorVisitor<LexicalContext> {
 
     private static final DebugLogger LOG = new DebugLogger("finalize");
 
     private final TemporarySymbols temporarySymbols;
 
     FinalizeTypes(final TemporarySymbols temporarySymbols) {
+        super(new LexicalContext());
         this.temporarySymbols = temporarySymbols;
     }
 
@@ -233,7 +235,7 @@
 
     private boolean symbolIsInteger(Node node) {
         final Symbol symbol = node.getSymbol();
-        assert symbol != null && symbol.getSymbolType().isInteger() : "int coercion expected: " + Debug.id(symbol) + " " + symbol + " " + getLexicalContext().getCurrentFunction().getSource();
+        assert symbol != null && symbol.getSymbolType().isInteger() : "int coercion expected: " + Debug.id(symbol) + " " + symbol + " " + lc.getCurrentFunction().getSource();
         return true;
     }
 
@@ -382,12 +384,10 @@
         final Node test   = forNode.getTest();
         final Node modify = forNode.getModify();
 
-        final LexicalContext lc = getLexicalContext();
-
         if (forNode.isForIn()) {
             return forNode.setModify(lc, convert(forNode.getModify(), Type.OBJECT)); // NASHORN-400
         }
-        assert test != null || forNode.hasGoto() : "forNode " + forNode + " needs goto and is missing it in " + getLexicalContext().getCurrentFunction();
+        assert test != null || forNode.hasGoto() : "forNode " + forNode + " needs goto and is missing it in " + lc.getCurrentFunction();
 
         return forNode.
             setInit(lc, init == null ? null : discard(init)).
@@ -419,7 +419,7 @@
 
     @Override
     public Node leaveFunctionNode(final FunctionNode functionNode) {
-        return functionNode.setState(getLexicalContext(), CompilationState.FINALIZED);
+        return functionNode.setState(lc, CompilationState.FINALIZED);
     }
 
     @Override
@@ -450,7 +450,7 @@
     public Node leaveReturnNode(final ReturnNode returnNode) {
         final Node expr = returnNode.getExpression();
         if (expr != null) {
-            return returnNode.setExpression(convert(expr, getLexicalContext().getCurrentFunction().getReturnType()));
+            return returnNode.setExpression(convert(expr, lc.getCurrentFunction().getReturnType()));
         }
         return returnNode;
     }
@@ -482,8 +482,8 @@
         }
 
         return switchNode.
-            setExpression(getLexicalContext(), convert(expression, Type.OBJECT)).
-            setCases(getLexicalContext(), newCases);
+            setExpression(lc, convert(expression, Type.OBJECT)).
+            setCases(lc, newCases);
     }
 
     @Override
@@ -519,14 +519,14 @@
     public Node leaveWhileNode(final WhileNode whileNode) {
         final Node test = whileNode.getTest();
         if (test != null) {
-            return whileNode.setTest(getLexicalContext(), convert(test, Type.BOOLEAN));
+            return whileNode.setTest(lc, convert(test, Type.BOOLEAN));
         }
         return whileNode;
     }
 
     @Override
     public Node leaveWithNode(final WithNode withNode) {
-        return withNode.setExpression(getLexicalContext(), convert(withNode.getExpression(), Type.OBJECT));
+        return withNode.setExpression(lc, convert(withNode.getExpression(), Type.OBJECT));
     }
 
     private static void updateSymbolsLog(final FunctionNode functionNode, final Symbol symbol, final boolean loseSlot) {
@@ -550,7 +550,6 @@
             return; // nothing to do
         }
 
-        final LexicalContext lc             = getLexicalContext();
         final FunctionNode   functionNode   = lc.getFunction(block);
         final boolean        allVarsInScope = functionNode.allVarsInScope();
         final boolean        isVarArg       = functionNode.isVarArg();
@@ -652,7 +651,7 @@
     private static void setCanBePrimitive(final Node node, final Type to) {
         final HashSet<Node> exclude = new HashSet<>();
 
-        node.accept(new NodeVisitor() {
+        node.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
             private void setCanBePrimitive(final Symbol symbol) {
                 LOG.info("*** can be primitive symbol ", symbol, " ", Debug.id(symbol));
                 symbol.setCanBePrimitive(to);
@@ -762,7 +761,7 @@
             }
         }
         LOG.info("Type override for lhs in '", node, "' => ", to);
-        return ((TypeOverride<T>)node).setType(temporarySymbols, getLexicalContext(), to);
+        return ((TypeOverride<T>)node).setType(temporarySymbols, lc, to);
     }
 
     /**
@@ -785,8 +784,8 @@
     private Node convert(final Node node, final Type to) {
         assert !to.isUnknown() : "unknown type for " + node + " class=" + node.getClass();
         assert node != null : "node is null";
-        assert node.getSymbol() != null : "node " + node + " " + node.getClass() + " has no symbol! " + getLexicalContext().getCurrentFunction();
-        assert node.tokenType() != TokenType.CONVERT : "assert convert in convert " + node + " in " + getLexicalContext().getCurrentFunction();
+        assert node.getSymbol() != null : "node " + node + " " + node.getClass() + " has no symbol! " + lc.getCurrentFunction();
+        assert node.tokenType() != TokenType.CONVERT : "assert convert in convert " + node + " in " + lc.getCurrentFunction();
 
         final Type from = node.getType();
 
@@ -800,7 +799,7 @@
 
         Node resultNode = node;
 
-        if (node instanceof LiteralNode && !to.isObject()) {
+        if (node instanceof LiteralNode && !(node instanceof ArrayLiteralNode) && !to.isObject()) {
             final LiteralNode<?> newNode = new LiteralNodeConstantEvaluator((LiteralNode<?>)node, to).eval();
             if (newNode != null) {
                 resultNode = newNode;
@@ -817,7 +816,6 @@
 
         assert !node.isTerminal();
 
-        final LexicalContext lc = getLexicalContext();
         //This is the only place in this file that can create new temporaries
         //FinalizeTypes may not introduce ANY node that is not a conversion.
         return temporarySymbols.ensureSymbol(lc, to, resultNode);
@@ -854,7 +852,7 @@
             symbol = symbol.setTypeOverrideShared(to, temporarySymbols);
             LOG.info("Type override for temporary in '", node, "' => ", to);
         }
-        return node.setSymbol(getLexicalContext(), symbol);
+        return node.setSymbol(lc, symbol);
     }
 
     /**
@@ -907,7 +905,7 @@
 
             if (literalNode != null) {
                 //inherit literal symbol for attr.
-                literalNode = (LiteralNode<?>)literalNode.setSymbol(getLexicalContext(), parent.getSymbol());
+                literalNode = (LiteralNode<?>)literalNode.setSymbol(lc, parent.getSymbol());
             }
 
             return literalNode;
--- a/src/jdk/nashorn/internal/codegen/FoldConstants.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/codegen/FoldConstants.java	Mon Jun 10 09:53:21 2013 +0100
@@ -33,7 +33,9 @@
 import jdk.nashorn.internal.ir.FunctionNode;
 import jdk.nashorn.internal.ir.FunctionNode.CompilationState;
 import jdk.nashorn.internal.ir.IfNode;
+import jdk.nashorn.internal.ir.LexicalContext;
 import jdk.nashorn.internal.ir.LiteralNode;
+import jdk.nashorn.internal.ir.LiteralNode.ArrayLiteralNode;
 import jdk.nashorn.internal.ir.Node;
 import jdk.nashorn.internal.ir.TernaryNode;
 import jdk.nashorn.internal.ir.UnaryNode;
@@ -45,11 +47,12 @@
 /**
  * Simple constant folding pass, executed before IR is starting to be lowered.
  */
-final class FoldConstants extends NodeVisitor {
+final class FoldConstants extends NodeVisitor<LexicalContext> {
 
     private static final DebugLogger LOG = new DebugLogger("fold");
 
     FoldConstants() {
+        super(new LexicalContext());
     }
 
     @Override
@@ -79,7 +82,7 @@
 
     @Override
     public Node leaveFunctionNode(final FunctionNode functionNode) {
-        return functionNode.setState(getLexicalContext(), CompilationState.CONSTANT_FOLDED);
+        return functionNode.setState(lc, CompilationState.CONSTANT_FOLDED);
     }
 
     @Override
@@ -141,6 +144,10 @@
                 return null;
             }
 
+            if (rhsNode instanceof ArrayLiteralNode) {
+                return null;
+            }
+
             final LiteralNode<?> rhs = (LiteralNode<?>)rhsNode;
             final boolean rhsInteger = rhs.getType().isInteger();
 
@@ -212,6 +219,10 @@
             final LiteralNode<?> lhs = (LiteralNode<?>)parent.lhs();
             final LiteralNode<?> rhs = (LiteralNode<?>)parent.rhs();
 
+            if (lhs instanceof ArrayLiteralNode || rhs instanceof ArrayLiteralNode) {
+                return null;
+            }
+
             final Type widest = Type.widest(lhs.getType(), rhs.getType());
 
             boolean isInteger = widest.isInteger();
@@ -279,9 +290,9 @@
             isLong    &= value != 0.0 && JSType.isRepresentableAsLong(value);
 
             if (isInteger) {
-                return LiteralNode.newInstance(token, finish, JSType.toInt32(value));
+                return LiteralNode.newInstance(token, finish, (int)value);
             } else if (isLong) {
-                return LiteralNode.newInstance(token, finish, JSType.toLong(value));
+                return LiteralNode.newInstance(token, finish, (long)value);
             }
 
             return LiteralNode.newInstance(token, finish, value);
--- a/src/jdk/nashorn/internal/codegen/Lower.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/codegen/Lower.java	Mon Jun 10 09:53:21 2013 +0100
@@ -32,7 +32,6 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
-
 import jdk.nashorn.internal.ir.BaseNode;
 import jdk.nashorn.internal.ir.BinaryNode;
 import jdk.nashorn.internal.ir.Block;
@@ -80,7 +79,7 @@
  * finalized.
  */
 
-final class Lower extends NodeOperatorVisitor {
+final class Lower extends NodeOperatorVisitor<BlockLexicalContext> {
 
     private static final DebugLogger LOG = new DebugLogger("lower");
 
@@ -105,7 +104,7 @@
                             terminated = true;
                         }
                     } else {
-                        statement.accept(new NodeVisitor() {
+                        statement.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
                             @Override
                             public boolean enterVarNode(final VarNode varNode) {
                                 newStatements.add(varNode.setInit(null));
@@ -121,7 +120,6 @@
 
     @Override
     public boolean enterBlock(final Block block) {
-        final LexicalContext lc = getLexicalContext();
         final FunctionNode   function = lc.getCurrentFunction();
         if (lc.isFunctionBody() && function.isProgram() && !function.hasDeclaredFunctions()) {
             new ExecuteNode(block.getLineNumber(), block.getToken(), block.getFinish(), LiteralNode.newInstance(block, ScriptRuntime.UNDEFINED)).accept(this);
@@ -134,12 +132,10 @@
         //now we have committed the entire statement list to the block, but we need to truncate
         //whatever is after the last terminal. block append won't append past it
 
-        final BlockLexicalContext lc = (BlockLexicalContext)getLexicalContext();
-
         Statement last = lc.getLastStatement();
 
         if (lc.isFunctionBody()) {
-            final FunctionNode currentFunction = getLexicalContext().getCurrentFunction();
+            final FunctionNode currentFunction = lc.getCurrentFunction();
             final boolean isProgram = currentFunction.isProgram();
             final ReturnNode returnNode = new ReturnNode(
                 last == null ? block.getLineNumber() : last.getLineNumber(), //TODO?
@@ -191,7 +187,7 @@
         final Node expr = executeNode.getExpression();
         ExecuteNode node = executeNode;
 
-        final FunctionNode currentFunction = getLexicalContext().getCurrentFunction();
+        final FunctionNode currentFunction = lc.getCurrentFunction();
 
         if (currentFunction.isProgram()) {
             if (!(expr instanceof Block) || expr instanceof FunctionNode) { // it's not a block, but can be a function
@@ -216,7 +212,7 @@
 
         final Node  test = forNode.getTest();
         if (!forNode.isForIn() && conservativeAlwaysTrue(test)) {
-            newForNode = forNode.setTest(getLexicalContext(), null);
+            newForNode = forNode.setTest(lc, null);
         }
 
         return addStatement(checkEscape(newForNode));
@@ -230,7 +226,7 @@
     @Override
     public Node leaveFunctionNode(final FunctionNode functionNode) {
         LOG.info("END FunctionNode: ", functionNode.getName());
-        return functionNode.setState(getLexicalContext(), CompilationState.LOWERED);
+        return functionNode.setState(lc, CompilationState.LOWERED);
     }
 
     @Override
@@ -261,19 +257,25 @@
         return throwNode;
     }
 
-    private static Node ensureUniqueLabelsIn(final Node node) {
-        return node.accept(new NodeVisitor() {
-           @Override
-           public Node leaveDefault(final Node labelledNode) {
-               return labelledNode.ensureUniqueLabels(getLexicalContext());
-           }
+    private static Node ensureUniqueNamesIn(final Node node) {
+        return node.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
+            @Override
+            public Node leaveFunctionNode(final FunctionNode functionNode) {
+                final String name = functionNode.getName();
+                return functionNode.setName(lc, lc.getCurrentFunction().uniqueName(name));
+            }
+
+            @Override
+            public Node leaveDefault(final Node labelledNode) {
+                return labelledNode.ensureUniqueLabels(lc);
+            }
         });
     }
 
     private static List<Statement> copyFinally(final Block finallyBody) {
         final List<Statement> newStatements = new ArrayList<>();
         for (final Statement statement : finallyBody.getStatements()) {
-            newStatements.add((Statement)ensureUniqueLabelsIn(statement));
+            newStatements.add((Statement)ensureUniqueNamesIn(statement));
             if (statement.hasTerminalFlags()) {
                 return newStatements;
             }
@@ -286,12 +288,12 @@
         final long token      = tryNode.getToken();
         final int  finish     = tryNode.getFinish();
 
-        final IdentNode exception = new IdentNode(token, finish, getLexicalContext().getCurrentFunction().uniqueName("catch_all"));
+        final IdentNode exception = new IdentNode(token, finish, lc.getCurrentFunction().uniqueName("catch_all"));
 
-        final Block catchBody = new Block(lineNumber, token, finish, new ThrowNode(lineNumber, token, finish, new IdentNode(exception))).
-                setIsTerminal(getLexicalContext(), true); //ends with throw, so terminal
+        final Block catchBody = new Block(lineNumber, token, finish, new ThrowNode(lineNumber, token, finish, new IdentNode(exception), ThrowNode.IS_SYNTHETIC_RETHROW)).
+                setIsTerminal(lc, true); //ends with throw, so terminal
 
-        final CatchNode catchAllNode  = new CatchNode(lineNumber, token, finish, new IdentNode(exception), null, catchBody);
+        final CatchNode catchAllNode  = new CatchNode(lineNumber, token, finish, new IdentNode(exception), null, catchBody, CatchNode.IS_SYNTHETIC_RETHROW);
         final Block     catchAllBlock = new Block(lineNumber, token, finish, catchAllNode);
 
         //catchallblock -> catchallnode (catchnode) -> exception -> throw
@@ -300,7 +302,7 @@
     }
 
     private IdentNode compilerConstant(final CompilerConstants cc) {
-        final FunctionNode functionNode = getLexicalContext().getCurrentFunction();
+        final FunctionNode functionNode = lc.getCurrentFunction();
         return new IdentNode(functionNode.getToken(), functionNode.getFinish(), cc.symbolName());
     }
 
@@ -316,11 +318,10 @@
      * @return new try node after splicing finally code (same if nop)
      */
     private Node spliceFinally(final TryNode tryNode, final List<ThrowNode> rethrows, final Block finallyBody) {
-        final int finish = tryNode.getFinish();
+        assert tryNode.getFinallyBody() == null;
+        final int            finish = tryNode.getFinish();
 
-        assert tryNode.getFinallyBody() == null;
-
-        final TryNode newTryNode = (TryNode)tryNode.accept(new NodeVisitor() {
+        final TryNode newTryNode = (TryNode)tryNode.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
             final List<Node> insideTry = new ArrayList<>();
 
             @Override
@@ -349,12 +350,12 @@
 
             @Override
             public Node leaveBreakNode(final BreakNode breakNode) {
-                return copy(breakNode, Lower.this.getLexicalContext().getBreakable(breakNode.getLabel()));
+                return copy(breakNode, Lower.this.lc.getBreakable(breakNode.getLabel()));
             }
 
             @Override
             public Node leaveContinueNode(final ContinueNode continueNode) {
-                return copy(continueNode, Lower.this.getLexicalContext().getContinueTo(continueNode.getLabel()));
+                return copy(continueNode, Lower.this.lc.getContinueTo(continueNode.getLabel()));
             }
 
             @Override
@@ -377,7 +378,7 @@
                     newStatements.add(expr == null ? returnNode : returnNode.setExpression(resultNode));
                 }
 
-                return new ExecuteNode(returnNode.getLineNumber(), returnNode.getToken(), returnNode.getFinish(), new Block(returnNode.getLineNumber(), returnNode.getToken(), getLexicalContext().getCurrentBlock().getFinish(), newStatements));
+                return new ExecuteNode(returnNode.getLineNumber(), returnNode.getToken(), returnNode.getFinish(), new Block(returnNode.getLineNumber(), returnNode.getToken(), lc.getCurrentBlock().getFinish(), newStatements));
             }
 
             private Node copy(final Statement endpoint, final Node targetNode) {
@@ -436,7 +437,7 @@
         final Block catchAll = catchAllBlock(tryNode);
 
         final List<ThrowNode> rethrows = new ArrayList<>();
-        catchAll.accept(new NodeVisitor() {
+        catchAll.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
             @Override
             public boolean enterThrowNode(final ThrowNode throwNode) {
                 rethrows.add(throwNode);
@@ -464,7 +465,7 @@
     @Override
     public Node leaveVarNode(final VarNode varNode) {
         addStatement(varNode);
-        if (varNode.getFlag(VarNode.IS_LAST_FUNCTION_DECLARATION) && getLexicalContext().getCurrentFunction().isProgram()) {
+        if (varNode.getFlag(VarNode.IS_LAST_FUNCTION_DECLARATION) && lc.getCurrentFunction().isProgram()) {
             new ExecuteNode(varNode.getLineNumber(), varNode.getToken(), varNode.getFinish(), new IdentNode(varNode.getName())).accept(this);
         }
         return varNode;
@@ -478,7 +479,7 @@
         if (conservativeAlwaysTrue(test)) {
             //turn it into a for node without a test.
             final ForNode forNode = (ForNode)new ForNode(whileNode.getLineNumber(), whileNode.getToken(), whileNode.getFinish(), null, null, body, null, ForNode.IS_FOR).accept(this);
-            getLexicalContext().replace(whileNode, forNode);
+            lc.replace(whileNode, forNode);
             return forNode;
         }
 
@@ -513,7 +514,7 @@
      * @return eval location
      */
     private String evalLocation(final IdentNode node) {
-        final Source source = getLexicalContext().getCurrentFunction().getSource();
+        final Source source = lc.getCurrentFunction().getSource();
         return new StringBuilder().
             append(source.getName()).
             append('#').
@@ -545,10 +546,10 @@
 
             // 'eval' call with at least one argument
             if (args.size() >= 1 && EVAL.symbolName().equals(callee.getName())) {
-                final FunctionNode currentFunction = getLexicalContext().getCurrentFunction();
+                final FunctionNode currentFunction = lc.getCurrentFunction();
                 return callNode.setEvalArgs(
                     new CallNode.EvalArgs(
-                        ensureUniqueLabelsIn(args.get(0)).accept(this),
+                        ensureUniqueNamesIn(args.get(0)).accept(this),
                         compilerConstant(THIS),
                         evalLocation(callee),
                         currentFunction.isStrict()));
@@ -574,7 +575,7 @@
     private static boolean controlFlowEscapes(final LexicalContext lex, final Block loopBody) {
         final List<Node> escapes = new ArrayList<>();
 
-        loopBody.accept(new NodeVisitor() {
+        loopBody.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
             @Override
             public Node leaveBreakNode(final BreakNode node) {
                 escapes.add(node);
@@ -595,7 +596,6 @@
     }
 
     private LoopNode checkEscape(final LoopNode loopNode) {
-        final LexicalContext lc = getLexicalContext();
         final boolean escapes = controlFlowEscapes(lc, loopNode.getBody());
         if (escapes) {
             return loopNode.
@@ -607,7 +607,7 @@
 
 
     private Node addStatement(final Statement statement) {
-        ((BlockLexicalContext)getLexicalContext()).appendStatement(statement);
+        lc.appendStatement(statement);
         return statement;
     }
 
--- a/src/jdk/nashorn/internal/codegen/MethodEmitter.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/codegen/MethodEmitter.java	Mon Jun 10 09:53:21 2013 +0100
@@ -2081,7 +2081,9 @@
      * @param args debug information to print
      */
     private void debug(final Object... args) {
-        debug(30, args);
+        if (DEBUG) {
+            debug(30, args);
+        }
     }
 
     /**
@@ -2091,7 +2093,9 @@
      * @param args debug information to print
      */
     private void debug_label(final Object... args) {
-        debug(26, args);
+        if (DEBUG) {
+            debug(22, args);
+        }
     }
 
     private void debug(final int padConstant, final Object... args) {
@@ -2164,7 +2168,6 @@
                     new Throwable().printStackTrace(LOG.getOutputStream());
                 }
             }
-
         }
     }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jdk/nashorn/internal/codegen/RangeAnalyzer.java	Mon Jun 10 09:53:21 2013 +0100
@@ -0,0 +1,476 @@
+/*
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.nashorn.internal.codegen;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+
+import jdk.nashorn.internal.codegen.types.Range;
+import jdk.nashorn.internal.codegen.types.Type;
+import jdk.nashorn.internal.ir.Assignment;
+import jdk.nashorn.internal.ir.BinaryNode;
+import jdk.nashorn.internal.ir.ForNode;
+import jdk.nashorn.internal.ir.IdentNode;
+import jdk.nashorn.internal.ir.LexicalContext;
+import jdk.nashorn.internal.ir.LiteralNode;
+import jdk.nashorn.internal.ir.LiteralNode.ArrayLiteralNode;
+import jdk.nashorn.internal.ir.LoopNode;
+import jdk.nashorn.internal.ir.Node;
+import jdk.nashorn.internal.ir.RuntimeNode;
+import jdk.nashorn.internal.ir.Symbol;
+import jdk.nashorn.internal.ir.UnaryNode;
+import jdk.nashorn.internal.ir.VarNode;
+import jdk.nashorn.internal.ir.visitor.NodeOperatorVisitor;
+import jdk.nashorn.internal.ir.visitor.NodeVisitor;
+import jdk.nashorn.internal.parser.TokenType;
+import jdk.nashorn.internal.runtime.DebugLogger;
+
+/**
+ * Range analysis and narrowing of type where it can be proven
+ * that there is no spillover, e.g.
+ *
+ *  function func(c) {
+ *    var v = c & 0xfff;
+ *    var w = c & 0xeee;
+ *    var x = v * w;
+ *    return x;
+ *  }
+ *
+ *  Proves that the multiplication never exceeds 24 bits and can thus be an int
+ */
+final class RangeAnalyzer extends NodeOperatorVisitor<LexicalContext> {
+    static final DebugLogger LOG = new DebugLogger("ranges");
+
+    private static final Range.Functionality RANGE = new Range.Functionality(LOG);
+
+    private final Map<LoopNode, Symbol> loopCounters = new HashMap<>();
+
+    RangeAnalyzer() {
+        super(new LexicalContext());
+    }
+
+    @Override
+    public boolean enterForNode(final ForNode forNode) {
+        //conservatively attempt to identify the loop counter. Null means that it wasn't
+        //properly identified and that no optimizations can be made with it - its range is
+        //simply unknown in that case, if it is assigned in the loop
+        final Symbol counter = findLoopCounter(forNode);
+        LOG.fine("Entering forNode " + forNode + " counter = " + counter);
+        if (counter != null && !assignedInLoop(forNode,  counter)) {
+            loopCounters.put(forNode, counter);
+        }
+        return true;
+    }
+
+    //destination visited
+    private Symbol setRange(final Node dest, final Range range) {
+        if (range.isUnknown()) {
+            return null;
+        }
+
+        final Symbol symbol = dest.getSymbol();
+        assert symbol != null : dest + " " + dest.getClass() + " has no symbol";
+        assert symbol.getRange() != null : symbol + " has no range";
+        final Range symRange = RANGE.join(symbol.getRange(), range);
+
+        //anything assigned in the loop, not being the safe loop counter(s) invalidates its entire range
+        if (lc.inLoop() && !isLoopCounter(lc.getCurrentLoop(), symbol)) {
+            symbol.setRange(Range.createGenericRange());
+            return symbol;
+        }
+
+        if (!symRange.equals(symbol.getRange())) {
+            LOG.fine("Modify range for " + dest + " " + symbol + " from " + symbol.getRange() + " to " + symRange + " (in node = " + dest + ")" );
+            symbol.setRange(symRange);
+        }
+
+        return null;
+    }
+
+    @Override
+    public Node leaveADD(final BinaryNode node) {
+        setRange(node, RANGE.add(node.lhs().getSymbol().getRange(), node.rhs().getSymbol().getRange()));
+        return node;
+    }
+
+    @Override
+    public Node leaveSUB(final BinaryNode node) {
+        setRange(node, RANGE.sub(node.lhs().getSymbol().getRange(), node.rhs().getSymbol().getRange()));
+        return node;
+    }
+
+    @Override
+    public Node leaveMUL(final BinaryNode node) {
+        setRange(node, RANGE.mul(node.lhs().getSymbol().getRange(), node.rhs().getSymbol().getRange()));
+        return node;
+    }
+
+    @Override
+    public Node leaveDIV(final BinaryNode node) {
+        setRange(node, RANGE.div(node.lhs().getSymbol().getRange(), node.rhs().getSymbol().getRange()));
+        return node;
+    }
+
+    @Override
+    public Node leaveMOD(final BinaryNode node) {
+        setRange(node, RANGE.mod(node.lhs().getSymbol().getRange(), node.rhs().getSymbol().getRange()));
+        return node;
+    }
+
+    @Override
+    public Node leaveBIT_AND(final BinaryNode node) {
+        setRange(node, RANGE.and(node.lhs().getSymbol().getRange(), node.rhs().getSymbol().getRange()));
+        return node;
+    }
+
+    @Override
+    public Node leaveBIT_OR(final BinaryNode node) {
+        setRange(node, RANGE.or(node.lhs().getSymbol().getRange(), node.rhs().getSymbol().getRange()));
+        return node;
+    }
+
+    @Override
+    public Node leaveBIT_XOR(final BinaryNode node) {
+        setRange(node, RANGE.xor(node.lhs().getSymbol().getRange(), node.rhs().getSymbol().getRange()));
+        return node;
+    }
+
+    @Override
+    public Node leaveSAR(final BinaryNode node) {
+        setRange(node, RANGE.sar(node.lhs().getSymbol().getRange(), node.rhs().getSymbol().getRange()));
+        return node;
+    }
+
+    @Override
+    public Node leaveSHL(final BinaryNode node) {
+        setRange(node, RANGE.shl(node.lhs().getSymbol().getRange(), node.rhs().getSymbol().getRange()));
+        return node;
+    }
+
+    @Override
+    public Node leaveSHR(final BinaryNode node) {
+        setRange(node, RANGE.shr(node.lhs().getSymbol().getRange(), node.rhs().getSymbol().getRange()));
+        return node;
+    }
+
+    private Node leaveCmp(final BinaryNode node) {
+        setRange(node, Range.createTypeRange(Type.BOOLEAN));
+        return node;
+    }
+
+    @Override
+    public Node leaveEQ(final BinaryNode node) {
+        return leaveCmp(node);
+    }
+
+    @Override
+    public Node leaveEQ_STRICT(final BinaryNode node) {
+        return leaveCmp(node);
+    }
+
+    @Override
+    public Node leaveNE(final BinaryNode node) {
+        return leaveCmp(node);
+    }
+
+    @Override
+    public Node leaveNE_STRICT(final BinaryNode node) {
+        return leaveCmp(node);
+    }
+
+    @Override
+    public Node leaveLT(final BinaryNode node) {
+        return leaveCmp(node);
+    }
+
+    @Override
+    public Node leaveLE(final BinaryNode node) {
+        return leaveCmp(node);
+    }
+
+    @Override
+    public Node leaveGT(final BinaryNode node) {
+        return leaveCmp(node);
+    }
+
+    @Override
+    public Node leaveGE(final BinaryNode node) {
+        return leaveCmp(node);
+    }
+
+    @Override
+    public Node leaveASSIGN(final BinaryNode node) {
+        Range range = node.rhs().getSymbol().getRange();
+        if (range.isUnknown()) {
+            range = Range.createGenericRange();
+        }
+
+        setRange(node.lhs(), range);
+        setRange(node, range);
+
+        return node;
+    }
+
+    private Node leaveSelfModifyingAssign(final BinaryNode node, final Range range) {
+        setRange(node.lhs(), range);
+        setRange(node, range);
+        return node;
+    }
+
+    private Node leaveSelfModifyingAssign(final UnaryNode node, final Range range) {
+        setRange(node.rhs(), range);
+        setRange(node, range);
+        return node;
+    }
+
+    @Override
+    public Node leaveASSIGN_ADD(final BinaryNode node) {
+        return leaveSelfModifyingAssign(node, RANGE.add(node.lhs().getSymbol().getRange(), node.rhs().getSymbol().getRange()));
+    }
+
+    @Override
+    public Node leaveASSIGN_SUB(final BinaryNode node) {
+        return leaveSelfModifyingAssign(node, RANGE.sub(node.lhs().getSymbol().getRange(), node.rhs().getSymbol().getRange()));
+    }
+
+    @Override
+    public Node leaveASSIGN_MUL(final BinaryNode node) {
+        return leaveSelfModifyingAssign(node, RANGE.mul(node.lhs().getSymbol().getRange(), node.rhs().getSymbol().getRange()));
+    }
+
+    @Override
+    public Node leaveASSIGN_DIV(final BinaryNode node) {
+        return leaveSelfModifyingAssign(node, Range.createTypeRange(Type.NUMBER));
+    }
+
+    @Override
+    public Node leaveASSIGN_MOD(final BinaryNode node) {
+        return leaveSelfModifyingAssign(node, Range.createTypeRange(Type.NUMBER));
+    }
+
+    @Override
+    public Node leaveASSIGN_BIT_AND(final BinaryNode node) {
+        return leaveSelfModifyingAssign(node, RANGE.and(node.lhs().getSymbol().getRange(), node.rhs().getSymbol().getRange()));
+    }
+
+    @Override
+    public Node leaveASSIGN_BIT_OR(final BinaryNode node) {
+        return leaveSelfModifyingAssign(node, RANGE.or(node.lhs().getSymbol().getRange(), node.rhs().getSymbol().getRange()));
+    }
+
+    @Override
+    public Node leaveASSIGN_BIT_XOR(final BinaryNode node) {
+        return leaveSelfModifyingAssign(node, RANGE.xor(node.lhs().getSymbol().getRange(), node.rhs().getSymbol().getRange()));
+    }
+
+    @Override
+    public Node leaveASSIGN_SAR(final BinaryNode node) {
+        return leaveSelfModifyingAssign(node, RANGE.sar(node.lhs().getSymbol().getRange(), node.rhs().getSymbol().getRange()));
+    }
+
+    @Override
+    public Node leaveASSIGN_SHR(final BinaryNode node) {
+        return leaveSelfModifyingAssign(node, RANGE.shr(node.lhs().getSymbol().getRange(), node.rhs().getSymbol().getRange()));
+    }
+
+    @Override
+    public Node leaveASSIGN_SHL(final BinaryNode node) {
+        return leaveSelfModifyingAssign(node, RANGE.shl(node.lhs().getSymbol().getRange(), node.rhs().getSymbol().getRange()));
+    }
+
+    @Override
+    public Node leaveDECINC(final UnaryNode node) {
+        switch (node.tokenType()) {
+        case DECPREFIX:
+        case DECPOSTFIX:
+            return leaveSelfModifyingAssign(node, RANGE.sub(node.rhs().getSymbol().getRange(), Range.createRange(1)));
+        case INCPREFIX:
+        case INCPOSTFIX:
+            return leaveSelfModifyingAssign(node, RANGE.add(node.rhs().getSymbol().getRange(), Range.createRange(1)));
+        default:
+            assert false;
+            return node;
+        }
+    }
+
+    @Override
+    public Node leaveADD(final UnaryNode node) {
+        Range range = node.rhs().getSymbol().getRange();
+        if (!range.getType().isNumeric()) {
+           range = Range.createTypeRange(Type.NUMBER);
+        }
+        setRange(node, range);
+        return node;
+    }
+
+    @Override
+    public Node leaveBIT_NOT(final UnaryNode node) {
+        setRange(node, Range.createTypeRange(Type.INT));
+        return node;
+    }
+
+    @Override
+    public Node leaveNOT(final UnaryNode node) {
+        setRange(node, Range.createTypeRange(Type.BOOLEAN));
+        return node;
+    }
+
+    @Override
+    public Node leaveSUB(final UnaryNode node) {
+        setRange(node, RANGE.neg(node.rhs().getSymbol().getRange()));
+        return node;
+    }
+
+    @Override
+    public Node leaveVarNode(final VarNode node) {
+        if (node.isAssignment()) {
+            Range range = node.getInit().getSymbol().getRange();
+            range = range.isUnknown() ? Range.createGenericRange() : range;
+
+            setRange(node.getName(), range);
+            setRange(node, range);
+        }
+
+        return node;
+    }
+
+    @SuppressWarnings("rawtypes")
+    @Override
+    public boolean enterLiteralNode(final LiteralNode node) {
+        // ignore array literals
+        return !(node instanceof ArrayLiteralNode);
+    }
+
+    @Override
+    public Node leaveLiteralNode(@SuppressWarnings("rawtypes") final LiteralNode node) {
+        if (node.getType().isInteger()) {
+            setRange(node, Range.createRange(node.getInt32()));
+        } else if (node.getType().isNumber()) {
+            setRange(node, Range.createRange(node.getNumber()));
+        } else if (node.getType().isLong()) {
+            setRange(node, Range.createRange(node.getLong()));
+        } else if (node.getType().isBoolean()) {
+            setRange(node, Range.createTypeRange(Type.BOOLEAN));
+        } else {
+            setRange(node, Range.createGenericRange());
+        }
+        return node;
+    }
+
+    @Override
+    public boolean enterRuntimeNode(final RuntimeNode node) {
+        // a runtime node that cannot be specialized is no point entering
+        return node.getRequest().canSpecialize();
+    }
+
+    /**
+     * Check whether a symbol is unsafely assigned in a loop - i.e. repeteadly assigned and
+     * not being identified as the loop counter. That means we don't really know anything
+     * about its range.
+     * @param loopNode loop node
+     * @param symbol   symbol
+     * @return true if assigned in loop
+     */
+    // TODO - this currently checks for nodes only - needs to be augmented for while nodes
+    // assignment analysis is also very conservative
+    private static boolean assignedInLoop(final LoopNode loopNode, final Symbol symbol) {
+        final HashSet<Node> skip = new HashSet<>();
+        final HashSet<Node> assignmentsInLoop = new HashSet<>();
+
+        loopNode.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
+            private boolean assigns(final Node node, final Symbol s) {
+                return node.isAssignment() && ((Assignment<?>)node).getAssignmentDest().getSymbol() == s;
+            }
+
+            @Override
+            public boolean enterForNode(final ForNode forNode) {
+                if (forNode.getInit() != null) {
+                    skip.add(forNode.getInit());
+                }
+                if (forNode.getModify() != null) {
+                    skip.add(forNode.getModify());
+                }
+                return true;
+            }
+
+            @Override
+            public Node leaveDefault(final Node node) {
+                //if this is an assignment to symbol
+                if (!skip.contains(node) && assigns(node, symbol)) {
+                    assignmentsInLoop.add(node);
+                }
+                return node;
+            }
+        });
+
+        return !assignmentsInLoop.isEmpty();
+    }
+
+    /**
+     * Check for a loop counter. This is currently quite conservative, in that it only handles
+     * x <= counter and x < counter.
+     *
+     * @param node loop node to check
+     * @return
+     */
+    private static Symbol findLoopCounter(final LoopNode node) {
+        final Node test = node.getTest();
+
+        if (test != null && test.isComparison()) {
+            final BinaryNode binaryNode = (BinaryNode)test;
+            final Node lhs = binaryNode.lhs();
+            final Node rhs = binaryNode.rhs();
+
+            //detect ident cmp int_literal
+            if (lhs instanceof IdentNode && rhs instanceof LiteralNode && ((LiteralNode<?>)rhs).getType().isInteger()) {
+                final Symbol    symbol = lhs.getSymbol();
+                final int       margin = ((LiteralNode<?>)rhs).getInt32();
+                final TokenType op     = test.tokenType();
+
+                switch (op) {
+                case LT:
+                case LE:
+                    symbol.setRange(RANGE.join(symbol.getRange(), Range.createRange(op == TokenType.LT ? margin - 1 : margin)));
+                    return symbol;
+                case GT:
+                case GE:
+                    //setRange(lhs, Range.createRange(op == TokenType.GT ? margin + 1 : margin));
+                    //return symbol;
+                default:
+                    break;
+                }
+            }
+        }
+
+        return null;
+    }
+
+    private boolean isLoopCounter(final LoopNode loopNode, final Symbol symbol) {
+        //this only works if loop nodes aren't replaced by other ones during this transform, but they are not
+        return loopCounters.get(loopNode) == symbol;
+    }
+}
--- a/src/jdk/nashorn/internal/codegen/RuntimeCallSite.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/codegen/RuntimeCallSite.java	Mon Jun 10 09:53:21 2013 +0100
@@ -41,10 +41,10 @@
 import jdk.nashorn.internal.codegen.types.Type;
 import jdk.nashorn.internal.ir.RuntimeNode;
 import jdk.nashorn.internal.ir.RuntimeNode.Request;
+import jdk.nashorn.internal.lookup.Lookup;
+import jdk.nashorn.internal.lookup.MethodHandleFactory;
 import jdk.nashorn.internal.runtime.ScriptRuntime;
 import jdk.nashorn.internal.runtime.linker.Bootstrap;
-import jdk.nashorn.internal.lookup.Lookup;
-import jdk.nashorn.internal.lookup.MethodHandleFactory;
 
 /**
  * Optimistic call site that assumes its Object arguments to be of a boxed type.
@@ -59,12 +59,10 @@
 public final class RuntimeCallSite extends MutableCallSite {
     static final Call BOOTSTRAP = staticCallNoLookup(Bootstrap.class, "runtimeBootstrap", CallSite.class, MethodHandles.Lookup.class, String.class, MethodType.class);
 
-    private static final MethodHandle NEXT = findOwnMH("next",  MethodHandle.class);
+    private static final MethodHandle NEXT = findOwnMH("next",  MethodHandle.class, String.class);
 
     private final RuntimeNode.Request request;
 
-    private String name;
-
     /**
      * A specialized runtime node, i.e. on where we know at least one more specific type than object
      */
@@ -203,7 +201,6 @@
      */
     public RuntimeCallSite(final MethodType type, final String name) {
         super(type);
-        this.name    = name;
         this.request = Request.valueOf(name.substring(0, name.indexOf(SpecializedRuntimeNode.REQUEST_SEPARATOR)));
         setTarget(makeMethod(name));
     }
@@ -292,7 +289,7 @@
                 mh = MH.explicitCastArguments(mh, type());
             }
 
-            final MethodHandle fallback = MH.foldArguments(MethodHandles.exactInvoker(type()), MH.bindTo(NEXT, this));
+            final MethodHandle fallback = MH.foldArguments(MethodHandles.exactInvoker(type()), MH.insertArguments(NEXT, 0, this, requestName));
 
             MethodHandle guard;
             if (type().parameterType(0).isPrimitive()) {
@@ -336,20 +333,15 @@
      *
      * Do not call directly
      *
+     * @param name current name (with type) of runtime call at the call site
      * @return next wider specialization method for this RuntimeCallSite
      */
-    public MethodHandle next() {
-        this.name = nextName(name);
-        final MethodHandle next = makeMethod(name);
+   public MethodHandle next(final String name) {
+        final MethodHandle next = makeMethod(nextName(name));
         setTarget(next);
         return next;
     }
 
-    @Override
-    public String toString() {
-        return super.toString() + " " + name;
-    }
-
     /** Method cache */
     private static final Map<String, MethodHandle> METHODS;
 
--- a/src/jdk/nashorn/internal/codegen/SharedScopeCall.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/codegen/SharedScopeCall.java	Mon Jun 10 09:53:21 2013 +0100
@@ -116,9 +116,10 @@
     /**
      * Generate the invoke instruction for this shared scope call.
      * @param method the method emitter
+     * @return the method emitter
      */
-    public void generateInvoke(final MethodEmitter method) {
-        method.invokestatic(compileUnit.getUnitClassName(), methodName, getStaticSignature());
+    public MethodEmitter generateInvoke(final MethodEmitter method) {
+        return method.invokestatic(compileUnit.getUnitClassName(), methodName, getStaticSignature());
     }
 
     /**
--- a/src/jdk/nashorn/internal/codegen/Splitter.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/codegen/Splitter.java	Mon Jun 10 09:53:21 2013 +0100
@@ -49,12 +49,12 @@
 /**
  * Split the IR into smaller compile units.
  */
-final class Splitter extends NodeVisitor {
+final class Splitter extends NodeVisitor<LexicalContext> {
     /** Current compiler. */
     private final Compiler compiler;
 
     /** IR to be broken down. */
-    private FunctionNode outermost;
+    private final FunctionNode outermost;
 
     /** Compile unit for the main script. */
     private final CompileUnit outermostCompileUnit;
@@ -75,6 +75,7 @@
      * @param outermostCompileUnit  compile unit for outermost function, if non-lazy this is the script's compile unit
      */
     public Splitter(final Compiler compiler, final FunctionNode functionNode, final CompileUnit outermostCompileUnit) {
+        super(new LexicalContext());
         this.compiler             = compiler;
         this.outermost            = functionNode;
         this.outermostCompileUnit = outermostCompileUnit;
@@ -93,8 +94,6 @@
 
         LOG.finest("Initiating split of '", functionNode.getName(), "'");
 
-        final LexicalContext lc = getLexicalContext();
-
         long weight = WeighNodes.weigh(functionNode);
         final boolean top = fn.isProgram(); //compiler.getFunctionNode() == outermost;
 
@@ -127,7 +126,7 @@
         final Block body = functionNode.getBody();
         final List<FunctionNode> dc = directChildren(functionNode);
 
-        final Block newBody = (Block)body.accept(new NodeVisitor() {
+        final Block newBody = (Block)body.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
             @Override
             public boolean enterFunctionNode(final FunctionNode nestedFunction) {
                 return dc.contains(nestedFunction);
@@ -136,7 +135,7 @@
             @Override
             public Node leaveFunctionNode(final FunctionNode nestedFunction) {
                 FunctionNode split = new Splitter(compiler, nestedFunction, outermostCompileUnit).split(nestedFunction);
-                getLexicalContext().replace(nestedFunction, split);
+                lc.replace(nestedFunction, split);
                 return split;
             }
         });
@@ -149,13 +148,13 @@
 
     private static List<FunctionNode> directChildren(final FunctionNode functionNode) {
         final List<FunctionNode> dc = new ArrayList<>();
-        functionNode.accept(new NodeVisitor() {
+        functionNode.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
             @Override
             public boolean enterFunctionNode(final FunctionNode child) {
                 if (child == functionNode) {
                     return true;
                 }
-                if (getLexicalContext().getParentFunction(child) == functionNode) {
+                if (lc.getParentFunction(child) == functionNode) {
                     dc.add(child);
                 }
                 return false;
@@ -181,7 +180,7 @@
      * @return new weight for the resulting block.
      */
     private Block splitBlock(final Block block, final FunctionNode function) {
-        getLexicalContext().setFlag(getLexicalContext().getCurrentFunction(), FunctionNode.IS_SPLIT);
+        lc.setFlag(lc.getCurrentFunction(), FunctionNode.IS_SPLIT);
 
         final List<Statement> splits = new ArrayList<>();
         List<Statement> statements = new ArrayList<>();
@@ -210,7 +209,7 @@
             splits.add(createBlockSplitNode(block, function, statements, statementsWeight));
         }
 
-        return block.setStatements(getLexicalContext(), splits);
+        return block.setStatements(lc, splits);
     }
 
     /**
@@ -258,7 +257,7 @@
         // been split already, so weigh again before splitting.
         long weight = WeighNodes.weigh(block, weightCache);
         if (weight >= SPLIT_THRESHOLD) {
-            newBlock = splitBlock(block, getLexicalContext().getFunction(block));
+            newBlock = splitBlock(block, lc.getFunction(block));
             weight   = WeighNodes.weigh(newBlock, weightCache);
         }
         weightCache.put(newBlock, weight);
@@ -274,9 +273,9 @@
             return literal;
         }
 
-        final FunctionNode functionNode = getLexicalContext().getCurrentFunction();
+        final FunctionNode functionNode = lc.getCurrentFunction();
 
-        getLexicalContext().setFlag(functionNode, FunctionNode.IS_SPLIT);
+        lc.setFlag(functionNode, FunctionNode.IS_SPLIT);
 
         if (literal instanceof ArrayLiteralNode) {
             final ArrayLiteralNode arrayLiteralNode = (ArrayLiteralNode) literal;
--- a/src/jdk/nashorn/internal/codegen/WeighNodes.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/codegen/WeighNodes.java	Mon Jun 10 09:53:21 2013 +0100
@@ -27,6 +27,7 @@
 
 import java.util.List;
 import java.util.Map;
+
 import jdk.nashorn.internal.codegen.types.Type;
 import jdk.nashorn.internal.ir.AccessNode;
 import jdk.nashorn.internal.ir.BinaryNode;
@@ -41,6 +42,7 @@
 import jdk.nashorn.internal.ir.IdentNode;
 import jdk.nashorn.internal.ir.IfNode;
 import jdk.nashorn.internal.ir.IndexNode;
+import jdk.nashorn.internal.ir.LexicalContext;
 import jdk.nashorn.internal.ir.LiteralNode;
 import jdk.nashorn.internal.ir.LiteralNode.ArrayLiteralNode;
 import jdk.nashorn.internal.ir.LiteralNode.ArrayLiteralNode.ArrayUnit;
@@ -63,7 +65,7 @@
  * Computes the "byte code" weight of an AST segment. This is used
  * for Splitting too large class files
  */
-final class WeighNodes extends NodeOperatorVisitor {
+final class WeighNodes extends NodeOperatorVisitor<LexicalContext> {
     /*
      * Weight constants.
      */
@@ -100,7 +102,7 @@
      * @param weightCache cache of already calculated block weights
      */
     private WeighNodes(FunctionNode topFunction, final Map<Node, Long> weightCache) {
-        super();
+        super(new LexicalContext());
         this.topFunction = topFunction;
         this.weightCache = weightCache;
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jdk/nashorn/internal/codegen/types/Range.java	Mon Jun 10 09:53:21 2013 +0100
@@ -0,0 +1,705 @@
+/*
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.nashorn.internal.codegen.types;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import jdk.nashorn.internal.runtime.DebugLogger;
+import jdk.nashorn.internal.runtime.JSType;
+
+/**
+ * Represents the value range of a symbol.
+ */
+public abstract class Range {
+
+    private static final Range GENERIC_RANGE = new Range() {
+        @Override
+        public Type getType() {
+            return Type.OBJECT;
+        }
+    };
+
+    private static final Range NUMBER_RANGE = new Range() {
+        @Override
+        public Type getType() {
+            return Type.NUMBER;
+        }
+    };
+
+    private static final Range UNKNOWN_RANGE = new Range() {
+        @Override
+        public Type getType() {
+            return Type.UNKNOWN;
+        }
+
+        @Override
+        public boolean isUnknown() {
+            return true;
+        }
+    };
+
+    private static class IntegerRange extends Range {
+        private final long min;
+        private final long max;
+        private final Type type;
+
+        private IntegerRange(final long min, final long max) {
+            assert min <= max;
+            this.min  = min;
+            this.max  = max;
+            this.type = typeFromRange(min, max);
+        }
+
+        private static Type typeFromRange(final long from, final long to) {
+            if (from >= Integer.MIN_VALUE && to <= Integer.MAX_VALUE) {
+                return Type.INT;
+            }
+            return Type.LONG;
+        }
+
+        @Override
+        public Type getType() {
+            return type;
+        }
+
+        public long getMin() {
+            return min;
+        }
+
+        public long getMax() {
+            return max;
+        }
+
+        @Override
+        public boolean isIntegerConst() {
+            return getMin() == getMax();
+        }
+
+        private long getBitMask() {
+            if (min == max) {
+                return min;
+            }
+
+            if (min < 0) {
+                return ~0L;
+            }
+
+            long mask = 1;
+            while (mask < max) {
+                mask = (mask << 1) | 1;
+            }
+            return mask;
+        }
+
+        @Override
+        public boolean equals(final Object obj) {
+            if (obj instanceof IntegerRange) {
+                final IntegerRange other = (IntegerRange)obj;
+                return this.type == other.type && this.min == other.min && this.max == other.max;
+            }
+            return false;
+        }
+
+        @Override
+        public int hashCode() {
+            return Long.hashCode(min) ^ Long.hashCode(max);
+        }
+
+        @Override
+        public String toString() {
+            return super.toString() + "[" + min +", " + max + "]";
+        }
+    }
+
+    /**
+     * Get narrowest type for this range
+     * @return type
+     */
+    public abstract Type getType();
+
+    /**
+     * Is this range unknown
+     * @return true if unknown
+     */
+    public boolean isUnknown() {
+        return false;
+    }
+
+    /**
+     * Check if an integer is enough to span this range
+     * @return true if integer is enough
+     */
+    public boolean isIntegerType() {
+        return this instanceof IntegerRange;
+    }
+
+    /**
+     * Check if an integer is enough to span this range
+     * @return true if integer is enough
+     */
+    public boolean isIntegerConst() {
+        return false;
+    }
+
+    /**
+     * Create an unknown range - this is most likely a singleton object
+     * and it represents "we have no known range information"
+     * @return the range
+     */
+    public static Range createUnknownRange() {
+        return UNKNOWN_RANGE;
+    }
+
+    /**
+     * Create a constant range: [value, value]
+     * @param value value
+     * @return the range
+     */
+    public static Range createRange(final int value) {
+        return createIntegerRange(value, value);
+    }
+
+    /**
+     * Create a constant range: [value, value]
+     * @param value value
+     * @return the range
+     */
+    public static Range createRange(final long value) {
+        return createIntegerRange(value, value);
+    }
+
+    /**
+     * Create a constant range: [value, value]
+     * @param value value
+     * @return the range
+     */
+    public static Range createRange(final double value) {
+        if (isRepresentableAsLong(value)) {
+            return createIntegerRange((long) value, (long) value);
+        }
+        return createNumberRange();
+    }
+
+    /**
+     * Create a constant range: [value, value]
+     * @param value value
+     * @return the range
+     */
+    public static Range createRange(final Object value) {
+        if (value instanceof Integer) {
+            return createRange((int)value);
+        } else if (value instanceof Long) {
+            return createRange((long)value);
+        } else if (value instanceof Double) {
+            return createRange((double)value);
+        }
+
+        return createGenericRange();
+    }
+
+    /**
+     * Create a generic range - object symbol that carries no range
+     * information
+     * @return the range
+     */
+    public static Range createGenericRange() {
+        return GENERIC_RANGE;
+    }
+
+    /**
+     * Create a number range - number symbol that carries no range
+     * information
+     * @return the range
+     */
+    public static Range createNumberRange() {
+        return NUMBER_RANGE;
+    }
+
+    /**
+     * Create an integer range [min, max]
+     * @param min minimum value, inclusive
+     * @param max maximum value, inclusive
+     * @return the range
+     */
+    public static IntegerRange createIntegerRange(final long min, final long max) {
+        return new IntegerRange(min, max);
+    }
+
+    /**
+     * Create an integer range of maximum type width for the given type
+     * @param type the type
+     * @return the range
+     */
+    public static IntegerRange createIntegerRange(final Type type) {
+        assert type.isNumeric() && !type.isNumber();
+        final long min;
+        final long max;
+        if (type.isInteger()) {
+            min = Integer.MIN_VALUE;
+            max = Integer.MAX_VALUE;
+        } else if (type.isLong()) {
+            min = Long.MIN_VALUE;
+            max = Long.MAX_VALUE;
+        } else {
+            throw new AssertionError(); //type incompatible with integer range
+        }
+        return new IntegerRange(min, max);
+    }
+
+    /**
+     * Create an range of maximum type width for the given type
+     * @param type the type
+     * @return the range
+     */
+    public static Range createTypeRange(final Type type) {
+        if (type.isNumber()) {
+            return createNumberRange();
+        } else if (type.isNumeric()) {
+            return createIntegerRange(type);
+        } else {
+            return createGenericRange();
+        }
+    }
+
+    // check that add doesn't overflow
+    private static boolean checkAdd(final long a, final long b) {
+        final long result = a + b;
+        return ((a ^ result) & (b ^ result)) >= 0;
+    }
+
+    // check that sub doesn't overflow
+    private static boolean checkSub(final long a, final long b) {
+        final long result = a - b;
+        return ((a ^ result) & (b ^ result)) >= 0;
+    }
+
+    private static boolean checkMul(final long a, final long b) {
+        // TODO correct overflow check
+        return a >= Integer.MIN_VALUE && a <= Integer.MAX_VALUE && b >= Integer.MIN_VALUE && b <= Integer.MAX_VALUE;
+    }
+
+    /**
+     * The range functionality class responsible for merging ranges and drawing
+     * range conclusions from operations executed
+     */
+    public static class Functionality {
+        /** logger */
+        protected final DebugLogger log;
+
+        /**
+         * Constructor
+         * @param log logger
+         */
+        public Functionality(final DebugLogger log) {
+            this.log = log;
+        }
+
+        /**
+         * Join two ranges
+         * @param a first range
+         * @param b second range
+         * @return the joined range
+         */
+        public Range join(final Range a, final Range b) {
+            if (a.equals(b)) {
+                return a;
+            }
+
+            Type joinedType = a.getType();
+            if (a.getType() != b.getType()) {
+                if (a.isUnknown()) {
+                    return b;
+                }
+                if (b.isUnknown()) {
+                    return a;
+                }
+
+                joinedType = Type.widest(a.getType(), b.getType());
+            }
+
+            if (joinedType.isInteger() || joinedType.isLong()) {
+                return createIntegerRange(
+                        Math.min(((IntegerRange) a).getMin(), ((IntegerRange) b).getMin()),
+                        Math.max(((IntegerRange) a).getMax(), ((IntegerRange) b).getMax()));
+            }
+
+            return createTypeRange(joinedType);
+        }
+
+        /**
+         * Add operation
+         * @param a range of first symbol to be added
+         * @param b range of second symbol to be added
+         * @return resulting range representing the value range after add
+         */
+        public Range add(final Range a, final Range b) {
+            if (a.isIntegerType() && b.isIntegerType()) {
+                final IntegerRange lhs = (IntegerRange)a;
+                final IntegerRange rhs = (IntegerRange)b;
+                if (checkAdd(lhs.getMin(), rhs.getMin()) && checkAdd(lhs.getMax(), rhs.getMax())) {
+                    return createIntegerRange(lhs.getMin() + rhs.getMin(), lhs.getMax() + rhs.getMax());
+                }
+            }
+
+            if (a.getType().isNumeric() && b.getType().isNumeric()) {
+                return createNumberRange();
+            }
+
+            return createGenericRange();
+        }
+
+        /**
+         * Sub operation
+         * @param a range of first symbol to be subtracted
+         * @param b range of second symbol to be subtracted
+         * @return resulting range representing the value range after subtraction
+         */
+        public Range sub(final Range a, final Range b) {
+            if (a.isIntegerType() && b.isIntegerType()) {
+                final IntegerRange lhs = (IntegerRange)a;
+                final IntegerRange rhs = (IntegerRange)b;
+                if (checkSub(lhs.getMin(), rhs.getMax()) && checkSub(lhs.getMax(), rhs.getMin())) {
+                    return createIntegerRange(lhs.getMin() - rhs.getMax(), lhs.getMax() - rhs.getMin());
+                }
+            }
+
+            if (a.getType().isNumeric() && b.getType().isNumeric()) {
+                return createNumberRange();
+            }
+
+            return createGenericRange();
+        }
+
+        /**
+         * Mul operation
+         * @param a range of first symbol to be multiplied
+         * @param b range of second symbol to be multiplied
+         * @return resulting range representing the value range after multiplication
+         */
+        public Range mul(final Range a, final Range b) {
+            if (a.isIntegerType() && b.isIntegerType()) {
+                final IntegerRange lhs = (IntegerRange)a;
+                final IntegerRange rhs = (IntegerRange)b;
+
+                //ensure that nothing ever overflows or underflows
+                if (checkMul(lhs.getMin(), rhs.getMin()) &&
+                    checkMul(lhs.getMax(), rhs.getMax()) &&
+                    checkMul(lhs.getMin(), rhs.getMax()) &&
+                    checkMul(lhs.getMax(), rhs.getMin())) {
+
+                    final List<Long> results =
+                        Arrays.asList(
+                            lhs.getMin() * rhs.getMin(),
+                            lhs.getMin() * rhs.getMax(),
+                            lhs.getMax() * rhs.getMin(),
+                            lhs.getMax() * rhs.getMax());
+                    return createIntegerRange(Collections.min(results), Collections.max(results));
+                }
+            }
+
+            if (a.getType().isNumeric() && b.getType().isNumeric()) {
+                return createNumberRange();
+            }
+
+            return createGenericRange();
+        }
+
+        /**
+         * Neg operation
+         * @param a range of value symbol to be negated
+         * @return resulting range representing the value range after neg
+         */
+        public Range neg(final Range a) {
+            if (a.isIntegerType()) {
+                final IntegerRange rhs = (IntegerRange)a;
+                if (rhs.getMin() != Long.MIN_VALUE && rhs.getMax() != Long.MIN_VALUE) {
+                    return createIntegerRange(-rhs.getMax(), -rhs.getMin());
+                }
+            }
+
+            if (a.getType().isNumeric()) {
+                return createNumberRange();
+            }
+
+            return createGenericRange();
+        }
+
+        /**
+         * Bitwise and operation
+         * @param a range of first symbol to be and:ed
+         * @param b range of second symbol to be and:ed
+         * @return resulting range representing the value range after and
+         */
+        public Range and(final Range a, final Range b) {
+            if (a.isIntegerType() && b.isIntegerType()) {
+                final int resultMask = (int) (((IntegerRange)a).getBitMask() & ((IntegerRange)b).getBitMask());
+                if (resultMask >= 0) {
+                    return createIntegerRange(0, resultMask);
+                }
+            } else if (a.isUnknown() && b.isIntegerType()) {
+                final long operandMask = ((IntegerRange)b).getBitMask();
+                if (operandMask >= 0) {
+                    return createIntegerRange(0, operandMask);
+                }
+            } else if (a.isIntegerType() && b.isUnknown()) {
+                final long operandMask = ((IntegerRange)a).getBitMask();
+                if (operandMask >= 0) {
+                    return createIntegerRange(0, operandMask);
+                }
+            }
+
+            return createTypeRange(Type.INT);
+        }
+
+        /**
+         * Bitwise or operation
+         * @param a range of first symbol to be or:ed
+         * @param b range of second symbol to be or:ed
+         * @return resulting range representing the value range after or
+         */
+        public Range or(final Range a, final Range b) {
+            if (a.isIntegerType() && b.isIntegerType()) {
+                final int resultMask = (int)(((IntegerRange)a).getBitMask() | ((IntegerRange)b).getBitMask());
+                if (resultMask >= 0) {
+                    return createIntegerRange(0, resultMask);
+                }
+            }
+
+            return createTypeRange(Type.INT);
+        }
+
+        /**
+         * Bitwise xor operation
+         * @param a range of first symbol to be xor:ed
+         * @param b range of second symbol to be xor:ed
+         * @return resulting range representing the value range after and
+         */
+        public Range xor(final Range a, final Range b) {
+            if (a.isIntegerConst() && b.isIntegerConst()) {
+                return createRange(((IntegerRange)a).getMin() ^ ((IntegerRange)b).getMin());
+            }
+
+            if (a.isIntegerType() && b.isIntegerType()) {
+                final int resultMask = (int)(((IntegerRange)a).getBitMask() | ((IntegerRange)b).getBitMask());
+                if (resultMask >= 0) {
+                    return createIntegerRange(0, createIntegerRange(0, resultMask).getBitMask());
+                }
+            }
+            return createTypeRange(Type.INT);
+        }
+
+        /**
+         * Bitwise shl operation
+         * @param a range of first symbol to be shl:ed
+         * @param b range of second symbol to be shl:ed
+         * @return resulting range representing the value range after shl
+         */
+        public Range shl(final Range a, final Range b) {
+            if (b.isIntegerType() && b.isIntegerConst()) {
+                final IntegerRange left  = (IntegerRange)(a.isIntegerType() ? a : createTypeRange(Type.INT));
+                final int          shift = (int)((IntegerRange) b).getMin() & 0x1f;
+                final int          min   = (int)left.getMin() << shift;
+                final int          max   = (int)left.getMax() << shift;
+                if (min >> shift == left.getMin() && max >> shift == left.getMax()) {
+                    return createIntegerRange(min, max);
+                }
+            }
+
+            return createTypeRange(Type.INT);
+        }
+
+        /**
+         * Bitwise shr operation
+         * @param a range of first symbol to be shr:ed
+         * @param b range of second symbol to be shr:ed
+         * @return resulting range representing the value range after shr
+         */
+        public Range shr(final Range a, final Range b) {
+            if (b.isIntegerType() && b.isIntegerConst()) {
+                final long         shift = ((IntegerRange) b).getMin() & 0x1f;
+                final IntegerRange left  = (IntegerRange)(a.isIntegerType() ? a : createTypeRange(Type.INT));
+                if (left.getMin() >= 0) {
+                    long min = left.getMin() >>> shift;
+                    long max = left.getMax() >>> shift;
+                    return createIntegerRange(min, max);
+                } else if (shift >= 1) {
+                    return createIntegerRange(0, JSType.MAX_UINT >>> shift);
+                }
+            }
+
+            return createTypeRange(Type.INT);
+        }
+
+        /**
+         * Bitwise sar operation
+         * @param a range of first symbol to be sar:ed
+         * @param b range of second symbol to be sar:ed
+         * @return resulting range representing the value range after sar
+         */
+        public Range sar(final Range a, final Range b) {
+            if (b.isIntegerType() && b.isIntegerConst()) {
+                final IntegerRange left  = (IntegerRange)(a.isIntegerType() ? a : createTypeRange(Type.INT));
+                final long         shift = ((IntegerRange) b).getMin() & 0x1f;
+                final long         min   = left.getMin() >> shift;
+                final long         max   = left.getMax() >> shift;
+                return createIntegerRange(min, max);
+            }
+
+            return createTypeRange(Type.INT);
+        }
+
+        /**
+         * Modulo operation
+         * @param a range of first symbol to the mod operation
+         * @param b range of second symbol to be mod operation
+         * @return resulting range representing the value range after mod
+         */
+        public Range mod(final Range a, final Range b) {
+            if (a.isIntegerType() && b.isIntegerType()) {
+                final IntegerRange rhs = (IntegerRange) b;
+                if (rhs.getMin() > 0 || rhs.getMax() < 0) { // divisor range must not include 0
+                    final long absmax = Math.max(Math.abs(rhs.getMin()), Math.abs(rhs.getMax())) - 1;
+                    return createIntegerRange(rhs.getMin() > 0 ? 0 : -absmax, rhs.getMax() < 0 ? 0 : +absmax);
+                }
+            }
+            return createTypeRange(Type.NUMBER);
+        }
+
+        /**
+         * Division operation
+         * @param a range of first symbol to the division
+         * @param b range of second symbol to be division
+         * @return resulting range representing the value range after division
+         */
+        public Range div(final Range a, final Range b) {
+            // TODO
+            return createTypeRange(Type.NUMBER);
+        }
+    }
+
+    /**
+     * Simple trace functionality that will log range creation
+     */
+    public static class TraceFunctionality extends Functionality {
+        TraceFunctionality(final DebugLogger log) {
+            super(log);
+        }
+
+        private Range trace(final Range result, final String operation, final Range... operands) {
+            log.fine("range::" + operation + Arrays.toString(operands) + " => " + result);
+            return result;
+        }
+
+        @Override
+        public Range join(final Range a, final Range b) {
+            final Range result = super.join(a, b);
+            if (!a.equals(b)) {
+                trace(result, "join", a, b);
+            }
+            return result;
+        }
+
+        @Override
+        public Range add(final Range a, final Range b) {
+            return trace(super.add(a, b), "add", a, b);
+        }
+
+        @Override
+        public Range sub(final Range a, final Range b) {
+            return trace(super.sub(a, b), "sub", a, b);
+        }
+
+        @Override
+        public Range mul(final Range a, final Range b) {
+            return trace(super.mul(a, b), "mul", a, b);
+        }
+
+        @Override
+        public Range neg(final Range a) {
+            return trace(super.neg(a), "neg", a);
+        }
+
+        @Override
+        public Range and(final Range a, final Range b) {
+            return trace(super.and(a, b), "and", a, b);
+        }
+
+        @Override
+        public Range or(final Range a, final Range b) {
+            return trace(super.or(a, b), "or", a, b);
+        }
+
+        @Override
+        public Range xor(final Range a, final Range b) {
+            return trace(super.xor(a, b), "xor", a, b);
+        }
+
+        @Override
+        public Range shl(final Range a, final Range b) {
+            return trace(super.shl(a, b), "shl", a, b);
+        }
+
+        @Override
+        public Range shr(final Range a, final Range b) {
+            return trace(super.shr(a, b), "shr", a, b);
+        }
+
+        @Override
+        public Range sar(final Range a, final Range b) {
+            return trace(super.sar(a, b), "sar", a, b);
+        }
+
+        @Override
+        public Range mod(final Range a, final Range b) {
+            return trace(super.mod(a, b), "mod", a, b);
+        }
+
+        @Override
+        public Range div(final Range a, final Range b) {
+            return trace(super.div(a, b), "div", a, b);
+        }
+    }
+
+    @Override
+    public String toString() {
+        return String.valueOf(getType());
+    }
+
+    @SuppressWarnings("unused")
+    private static boolean isRepresentableAsInt(final double number) {
+        return (int)number == number && !isNegativeZero(number);
+    }
+
+    private static boolean isRepresentableAsLong(final double number) {
+        return (long)number == number && !isNegativeZero(number);
+    }
+
+    private static boolean isNegativeZero(final double number) {
+        return Double.doubleToLongBits(number) == Double.doubleToLongBits(-0.0);
+    }
+}
--- a/src/jdk/nashorn/internal/codegen/types/Type.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/codegen/types/Type.java	Mon Jun 10 09:53:21 2013 +0100
@@ -106,23 +106,13 @@
     Type(final String name, final Class<?> clazz, final int weight, final int slots) {
         this.name       = name;
         this.clazz      = clazz;
-        this.descriptor = Type.getDescriptor(clazz);
+        this.descriptor = jdk.internal.org.objectweb.asm.Type.getDescriptor(clazz);
         this.weight     = weight;
         assert weight >= MIN_WEIGHT && weight <= MAX_WEIGHT : "illegal type weight: " + weight;
         this.slots      = slots;
     }
 
     /**
-     * Return an internal descriptor for a type
-     *
-     * @param type the type
-     * @return descriptor string
-     */
-    public static String getDescriptor(final Class<?> type) {
-        return jdk.internal.org.objectweb.asm.Type.getDescriptor(type);
-    }
-
-    /**
      * Get the weight of this type - use this e.g. for sorting method descriptors
      * @return the weight
      */
--- a/src/jdk/nashorn/internal/ir/AccessNode.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/ir/AccessNode.java	Mon Jun 10 09:53:21 2013 +0100
@@ -60,7 +60,7 @@
      * @param visitor IR navigating visitor.
      */
     @Override
-    public Node accept(final NodeVisitor visitor) {
+    public Node accept(final NodeVisitor<? extends LexicalContext> visitor) {
         if (visitor.enterAccessNode(this)) {
             return visitor.leaveAccessNode(
                 setBase(base.accept(visitor)).
@@ -110,7 +110,6 @@
         return new AccessNode(this, base, property, isFunction(), hasCallSiteType());
     }
 
-
     private AccessNode setProperty(final IdentNode property) {
         if (this.property == property) {
             return this;
--- a/src/jdk/nashorn/internal/ir/BinaryNode.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/ir/BinaryNode.java	Mon Jun 10 09:53:21 2013 +0100
@@ -59,6 +59,23 @@
         this.rhs = rhs;
     }
 
+    @Override
+    public boolean isComparison() {
+        switch (tokenType()) {
+        case EQ:
+        case EQ_STRICT:
+        case NE:
+        case NE_STRICT:
+        case LE:
+        case LT:
+        case GE:
+        case GT:
+            return true;
+        default:
+            return false;
+        }
+    }
+
     /**
      * Return the widest possible type for this operation. This is used for compile time
      * static type inference
@@ -143,7 +160,7 @@
      * @param visitor IR navigating visitor.
      */
     @Override
-    public Node accept(final NodeVisitor visitor) {
+    public Node accept(final NodeVisitor<? extends LexicalContext> visitor) {
         if (visitor.enterBinaryNode(this)) {
             return visitor.leaveBinaryNode(setLHS(lhs.accept(visitor)).setRHS(rhs.accept(visitor)));
         }
--- a/src/jdk/nashorn/internal/ir/Block.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/ir/Block.java	Mon Jun 10 09:53:21 2013 +0100
@@ -131,7 +131,7 @@
      * @return new or same node
      */
     @Override
-    public Node accept(final LexicalContext lc, final NodeVisitor visitor) {
+    public Node accept(final LexicalContext lc, final NodeVisitor<? extends LexicalContext> visitor) {
         if (visitor.enterBlock(this)) {
             return visitor.leaveBlock(setStatements(lc, Node.accept(visitor, Statement.class, statements)));
         }
--- a/src/jdk/nashorn/internal/ir/BlockLexicalContext.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/ir/BlockLexicalContext.java	Mon Jun 10 09:53:21 2013 +0100
@@ -63,7 +63,6 @@
         return sstack.pop();
     }
 
-    @SuppressWarnings("unchecked")
     @Override
     public <T extends LexicalContextNode> T pop(final T node) {
         T expected = node;
--- a/src/jdk/nashorn/internal/ir/BreakNode.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/ir/BreakNode.java	Mon Jun 10 09:53:21 2013 +0100
@@ -59,7 +59,7 @@
      * @param visitor IR navigating visitor.
      */
     @Override
-    public Node accept(final NodeVisitor visitor) {
+    public Node accept(final NodeVisitor<? extends LexicalContext> visitor) {
         if (visitor.enterBreakNode(this)) {
             return visitor.leaveBreakNode(this);
         }
--- a/src/jdk/nashorn/internal/ir/CallNode.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/ir/CallNode.java	Mon Jun 10 09:53:21 2013 +0100
@@ -27,6 +27,7 @@
 
 import java.util.Collections;
 import java.util.List;
+
 import jdk.nashorn.internal.codegen.types.Type;
 import jdk.nashorn.internal.ir.annotations.Ignore;
 import jdk.nashorn.internal.ir.annotations.Immutable;
@@ -194,7 +195,7 @@
      * @return node or replacement
      */
     @Override
-    public Node accept(final LexicalContext lc, final NodeVisitor visitor) {
+    public Node accept(final LexicalContext lc, final NodeVisitor<? extends LexicalContext> visitor) {
         if (visitor.enterCallNode(this)) {
             final CallNode newCallNode = (CallNode)visitor.leaveCallNode(
                     setFunction(function.accept(visitor)).
--- a/src/jdk/nashorn/internal/ir/CaseNode.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/ir/CaseNode.java	Mon Jun 10 09:53:21 2013 +0100
@@ -78,7 +78,7 @@
      * @param visitor IR navigating visitor.
      */
     @Override
-    public Node accept(final NodeVisitor visitor) {
+    public Node accept(final NodeVisitor<? extends LexicalContext> visitor) {
         if (visitor.enterCaseNode(this)) {
             final Node  newTest = test == null ? null : test.accept(visitor);
             final Block newBody = body == null ? null : (Block)body.accept(visitor);
--- a/src/jdk/nashorn/internal/ir/CatchNode.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/ir/CatchNode.java	Mon Jun 10 09:53:21 2013 +0100
@@ -42,6 +42,11 @@
     /** Catch body. */
     private final Block body;
 
+    private final int flags;
+
+    /** Is this block a synthethic rethrow created by finally inlining? */
+    public static final int IS_SYNTHETIC_RETHROW = 1;
+
     /**
      * Constructors
      *
@@ -51,19 +56,22 @@
      * @param exception          variable name of exception
      * @param exceptionCondition exception condition
      * @param body               catch body
+     * @param flags              flags
      */
-    public CatchNode(final int lineNumber, final long token, final int finish, final IdentNode exception, final Node exceptionCondition, final Block body) {
+    public CatchNode(final int lineNumber, final long token, final int finish, final IdentNode exception, final Node exceptionCondition, final Block body, final int flags) {
         super(lineNumber, token, finish);
         this.exception          = exception;
         this.exceptionCondition = exceptionCondition;
         this.body               = body;
+        this.flags              = flags;
     }
 
-    private CatchNode(final CatchNode catchNode, final IdentNode exception, final Node exceptionCondition, final Block body) {
+    private CatchNode(final CatchNode catchNode, final IdentNode exception, final Node exceptionCondition, final Block body, final int flags) {
         super(catchNode);
         this.exception          = exception;
         this.exceptionCondition = exceptionCondition;
         this.body               = body;
+        this.flags              = flags;
     }
 
     /**
@@ -71,7 +79,7 @@
      * @param visitor IR navigating visitor.
      */
     @Override
-    public Node accept(final NodeVisitor visitor) {
+    public Node accept(final NodeVisitor<? extends LexicalContext> visitor) {
         if (visitor.enterCatchNode(this)) {
             return visitor.leaveCatchNode(
                 setException((IdentNode)exception.accept(visitor)).
@@ -124,7 +132,7 @@
         if (this.exceptionCondition == exceptionCondition) {
             return this;
         }
-        return new CatchNode(this, exception, exceptionCondition, body);
+        return new CatchNode(this, exception, exceptionCondition, body, flags);
     }
 
     /**
@@ -144,13 +152,25 @@
         if (this.exception == exception) {
             return this;
         }
-        return new CatchNode(this, exception, exceptionCondition, body);
+        return new CatchNode(this, exception, exceptionCondition, body, flags);
     }
 
     private CatchNode setBody(final Block body) {
         if (this.body == body) {
             return this;
         }
-        return new CatchNode(this, exception, exceptionCondition, body);
+        return new CatchNode(this, exception, exceptionCondition, body, flags);
     }
+
+    /**
+     * Is this catch block a non-JavaScript constructor, for example created as
+     * part of the rethrow mechanism of a finally block in Lower? Then we just
+     * pass the exception on and need not unwrap whatever is in the ECMAException
+     * object catch symbol
+     * @return true if a finally synthetic rethrow
+     */
+    public boolean isSyntheticRethrow() {
+        return (flags & IS_SYNTHETIC_RETHROW) == IS_SYNTHETIC_RETHROW;
+    }
+
 }
--- a/src/jdk/nashorn/internal/ir/ContinueNode.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/ir/ContinueNode.java	Mon Jun 10 09:53:21 2013 +0100
@@ -55,7 +55,7 @@
     }
 
     @Override
-    public Node accept(final NodeVisitor visitor) {
+    public Node accept(final NodeVisitor<? extends LexicalContext> visitor) {
         if (visitor.enterContinueNode(this)) {
             return visitor.leaveContinueNode(this);
         }
--- a/src/jdk/nashorn/internal/ir/EmptyNode.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/ir/EmptyNode.java	Mon Jun 10 09:53:21 2013 +0100
@@ -56,7 +56,7 @@
 
 
     @Override
-    public Node accept(final NodeVisitor visitor) {
+    public Node accept(final NodeVisitor<? extends LexicalContext> visitor) {
         if (visitor.enterEmptyNode(this)) {
             return visitor.leaveEmptyNode(this);
         }
--- a/src/jdk/nashorn/internal/ir/ExecuteNode.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/ir/ExecuteNode.java	Mon Jun 10 09:53:21 2013 +0100
@@ -62,7 +62,7 @@
     }
 
     @Override
-    public Node accept(final NodeVisitor visitor) {
+    public Node accept(final NodeVisitor<? extends LexicalContext> visitor) {
         if (visitor.enterExecuteNode(this)) {
             return visitor.leaveExecuteNode(setExpression(expression.accept(visitor)));
         }
--- a/src/jdk/nashorn/internal/ir/ForNode.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/ir/ForNode.java	Mon Jun 10 09:53:21 2013 +0100
@@ -86,7 +86,7 @@
     }
 
     @Override
-    protected Node accept(final LexicalContext lc, final NodeVisitor visitor) {
+    protected Node accept(final LexicalContext lc, final NodeVisitor<? extends LexicalContext> visitor) {
         if (visitor.enterForNode(this)) {
             return visitor.leaveForNode(
                 setInit(lc, init == null ? null : init.accept(visitor)).
--- a/src/jdk/nashorn/internal/ir/FunctionNode.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/ir/FunctionNode.java	Mon Jun 10 09:53:21 2013 +0100
@@ -30,7 +30,6 @@
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
-
 import jdk.nashorn.internal.codegen.CompileUnit;
 import jdk.nashorn.internal.codegen.Compiler;
 import jdk.nashorn.internal.codegen.CompilerConstants;
@@ -250,6 +249,7 @@
         final FunctionNode functionNode,
         final long lastToken,
         final int flags,
+        final String name,
         final Type returnType,
         final CompileUnit compileUnit,
         final EnumSet<CompilationState> compilationState,
@@ -260,6 +260,7 @@
         super(functionNode);
 
         this.flags            = flags;
+        this.name             = name;
         this.returnType       = returnType;
         this.compileUnit      = compileUnit;
         this.lastToken        = lastToken;
@@ -271,7 +272,6 @@
 
         // the fields below never change - they are final and assigned in constructor
         this.source          = functionNode.source;
-        this.name            = functionNode.name;
         this.ident           = functionNode.ident;
         this.namespace       = functionNode.namespace;
         this.declaredSymbols = functionNode.declaredSymbols;
@@ -280,7 +280,7 @@
     }
 
     @Override
-    public Node accept(final LexicalContext lc, final NodeVisitor visitor) {
+    public Node accept(final LexicalContext lc, final NodeVisitor<? extends LexicalContext> visitor) {
         if (visitor.enterFunctionNode(this)) {
             return visitor.leaveFunctionNode(setBody(lc, (Block)body.accept(visitor)));
         }
@@ -315,7 +315,7 @@
         if (this.snapshot == null) {
             return this;
         }
-        return Node.replaceInLexicalContext(lc, this, new FunctionNode(this, lastToken, flags, returnType, compileUnit, compilationState, body, parameters, null, hints));
+        return Node.replaceInLexicalContext(lc, this, new FunctionNode(this, lastToken, flags, name, returnType, compileUnit, compilationState, body, parameters, null, hints));
     }
 
     /**
@@ -331,7 +331,7 @@
         if (isProgram() || parameters.isEmpty()) {
             return this; //never specialize anything that won't be recompiled
         }
-        return Node.replaceInLexicalContext(lc, this, new FunctionNode(this, lastToken, flags, returnType, compileUnit, compilationState, body, parameters, this, hints));
+        return Node.replaceInLexicalContext(lc, this, new FunctionNode(this, lastToken, flags, name, returnType, compileUnit, compilationState, body, parameters, this, hints));
     }
 
     /**
@@ -339,7 +339,7 @@
      * @return true if specialization is possible
      */
     public boolean canSpecialize() {
-        return getFlag(CAN_SPECIALIZE);
+        return snapshot != null && getFlag(CAN_SPECIALIZE);
     }
 
     /**
@@ -384,12 +384,12 @@
      * @return function node or a new one if state was changed
      */
     public FunctionNode setState(final LexicalContext lc, final CompilationState state) {
-        if (this.compilationState.equals(state)) {
+        if (this.compilationState.contains(state)) {
             return this;
         }
         final EnumSet<CompilationState> newState = EnumSet.copyOf(this.compilationState);
         newState.add(state);
-        return Node.replaceInLexicalContext(lc, this, new FunctionNode(this, lastToken, flags, returnType, compileUnit, newState, body, parameters, snapshot, hints));
+        return Node.replaceInLexicalContext(lc, this, new FunctionNode(this, lastToken, flags, name, returnType, compileUnit, newState, body, parameters, snapshot, hints));
     }
 
     /**
@@ -410,7 +410,7 @@
         if (this.hints == hints) {
             return this;
         }
-        return Node.replaceInLexicalContext(lc, this, new FunctionNode(this, lastToken, flags, returnType, compileUnit, compilationState, body, parameters, snapshot, hints));
+        return Node.replaceInLexicalContext(lc, this, new FunctionNode(this, lastToken, flags, name, returnType, compileUnit, compilationState, body, parameters, snapshot, hints));
     }
 
     /**
@@ -463,7 +463,7 @@
         if (this.flags == flags) {
             return this;
         }
-        return Node.replaceInLexicalContext(lc, this, new FunctionNode(this, lastToken, flags, returnType, compileUnit, compilationState, body, parameters, snapshot, hints));
+        return Node.replaceInLexicalContext(lc, this, new FunctionNode(this, lastToken, flags, name, returnType, compileUnit, compilationState, body, parameters, snapshot, hints));
     }
 
     @Override
@@ -529,7 +529,7 @@
     }
 
     /**
-     * Get the identifier for this function
+     * Get the identifier for this function, this is its symbol.
      * @return the identifier as an IdentityNode
      */
     public IdentNode getIdent() {
@@ -572,7 +572,7 @@
         if(this.body == body) {
             return this;
         }
-        return Node.replaceInLexicalContext(lc, this, new FunctionNode(this, lastToken, flags, returnType, compileUnit, compilationState, body, parameters, snapshot, hints));
+        return Node.replaceInLexicalContext(lc, this, new FunctionNode(this, lastToken, flags, name, returnType, compileUnit, compilationState, body, parameters, snapshot, hints));
     }
 
     /**
@@ -640,7 +640,7 @@
         if (this.lastToken == lastToken) {
             return this;
         }
-        return Node.replaceInLexicalContext(lc, this, new FunctionNode(this, lastToken, flags, returnType, compileUnit, compilationState, body, parameters, snapshot, hints));
+        return Node.replaceInLexicalContext(lc, this, new FunctionNode(this, lastToken, flags, name, returnType, compileUnit, compilationState, body, parameters, snapshot, hints));
     }
 
     /**
@@ -651,6 +651,20 @@
         return name;
     }
 
+
+    /**
+     * Set the internal name for this function
+     * @param lc    lexical context
+     * @param name new name
+     * @return new function node if changed, otherwise the same
+     */
+    public FunctionNode setName(final LexicalContext lc, final String name) {
+        if (this.name.equals(name)) {
+            return this;
+        }
+        return Node.replaceInLexicalContext(lc, this, new FunctionNode(this, lastToken, flags, name, returnType, compileUnit, compilationState, body, parameters, snapshot, hints));
+    }
+
     /**
      * Check if this function should have all its variables in its own scope. Scripts, split sub-functions, and
      * functions having with and/or eval blocks are such.
@@ -698,7 +712,7 @@
         if (this.parameters == parameters) {
             return this;
         }
-        return Node.replaceInLexicalContext(lc, this, new FunctionNode(this, lastToken, flags, returnType, compileUnit, compilationState, body, parameters, snapshot, hints));
+        return Node.replaceInLexicalContext(lc, this, new FunctionNode(this, lastToken, flags, name, returnType, compileUnit, compilationState, body, parameters, snapshot, hints));
     }
 
     /**
@@ -762,6 +776,7 @@
                 this,
                 lastToken,
                 flags,
+                name,
                 Type.widest(this.returnType, returnType.isObject() ?
                     Type.OBJECT :
                     returnType),
@@ -801,7 +816,7 @@
         if (this.compileUnit == compileUnit) {
             return this;
         }
-        return Node.replaceInLexicalContext(lc, this, new FunctionNode(this, lastToken, flags, returnType, compileUnit, compilationState, body, parameters, snapshot, hints));
+        return Node.replaceInLexicalContext(lc, this, new FunctionNode(this, lastToken, flags, name, returnType, compileUnit, compilationState, body, parameters, snapshot, hints));
     }
 
     /**
--- a/src/jdk/nashorn/internal/ir/IdentNode.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/ir/IdentNode.java	Mon Jun 10 09:53:21 2013 +0100
@@ -29,7 +29,6 @@
 import static jdk.nashorn.internal.codegen.CompilerConstants.__FILE__;
 import static jdk.nashorn.internal.codegen.CompilerConstants.__LINE__;
 import static jdk.nashorn.internal.codegen.ObjectClassGenerator.DEBUG_FIELDS;
-
 import jdk.nashorn.internal.codegen.ObjectClassGenerator;
 import jdk.nashorn.internal.codegen.types.Type;
 import jdk.nashorn.internal.ir.annotations.Immutable;
@@ -119,7 +118,7 @@
      * @param visitor IR navigating visitor.
      */
     @Override
-    public Node accept(final NodeVisitor visitor) {
+    public Node accept(final NodeVisitor<? extends LexicalContext> visitor) {
         if (visitor.enterIdentNode(this)) {
             return visitor.leaveIdentNode(this);
         }
--- a/src/jdk/nashorn/internal/ir/IfNode.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/ir/IfNode.java	Mon Jun 10 09:53:21 2013 +0100
@@ -72,7 +72,7 @@
     }
 
     @Override
-    public Node accept(final NodeVisitor visitor) {
+    public Node accept(final NodeVisitor<? extends LexicalContext> visitor) {
         if (visitor.enterIfNode(this)) {
             return visitor.leaveIfNode(
                 setTest(test.accept(visitor)).
--- a/src/jdk/nashorn/internal/ir/IndexNode.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/ir/IndexNode.java	Mon Jun 10 09:53:21 2013 +0100
@@ -56,19 +56,12 @@
     }
 
     @Override
-    public Node accept(final NodeVisitor visitor) {
+    public Node accept(final NodeVisitor<? extends LexicalContext> visitor) {
         if (visitor.enterIndexNode(this)) {
-            final Node      newBase  = base.accept(visitor);
-            final Node      newIndex = index.accept(visitor);
-            final IndexNode newNode;
-            if (newBase != base || newIndex != index) {
-                newNode = new IndexNode(this, newBase, newIndex, isFunction(), hasCallSiteType());
-            } else {
-                newNode = this;
-            }
-            return visitor.leaveIndexNode(newNode);
+            return visitor.leaveIndexNode(
+                setBase(base.accept(visitor)).
+                setIndex(index.accept(visitor)));
         }
-
         return this;
     }
 
@@ -106,6 +99,13 @@
         return index;
     }
 
+    private IndexNode setBase(final Node base) {
+        if (this.base == base) {
+            return this;
+        }
+        return new IndexNode(this, base, index, isFunction(), hasCallSiteType());
+    }
+
     /**
      * Set the index expression for this node
      * @param index new index expression
--- a/src/jdk/nashorn/internal/ir/LabelNode.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/ir/LabelNode.java	Mon Jun 10 09:53:21 2013 +0100
@@ -67,11 +67,11 @@
     }
 
     @Override
-    public Node accept(final LexicalContext lc, final NodeVisitor visitor) {
+    public Node accept(final LexicalContext lc, final NodeVisitor<? extends LexicalContext> visitor) {
         if (visitor.enterLabelNode(this)) {
             return visitor.leaveLabelNode(
-                setLabel(visitor.getLexicalContext(), (IdentNode)label.accept(visitor)).
-                setBody(visitor.getLexicalContext(), (Block)body.accept(visitor)));
+                setLabel(lc, (IdentNode)label.accept(visitor)).
+                setBody(lc, (Block)body.accept(visitor)));
         }
 
         return this;
--- a/src/jdk/nashorn/internal/ir/LexicalContext.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/ir/LexicalContext.java	Mon Jun 10 09:53:21 2013 +0100
@@ -440,6 +440,23 @@
     }
 
     /**
+     * Check whether the lexical context is currently inside a loop
+     * @return true if inside a loop
+     */
+    public boolean inLoop() {
+        return getCurrentLoop() != null;
+    }
+
+    /**
+     * Returns the loop header of the current loop, or null if not inside a loop
+     * @return loop header
+     */
+    public LoopNode getCurrentLoop() {
+        final Iterator<LoopNode> iter = new NodeIterator<>(LoopNode.class, getCurrentFunction());
+        return iter.hasNext() ? iter.next() : null;
+    }
+
+    /**
      * Find the breakable node corresponding to this label.
      * @param label label to search for, if null the closest breakable node will be returned unconditionally, e.g. a while loop with no label
      * @return closest breakable node
@@ -461,8 +478,7 @@
     }
 
     private LoopNode getContinueTo() {
-        final Iterator<LoopNode> iter = new NodeIterator<>(LoopNode.class, getCurrentFunction());
-        return iter.hasNext() ? iter.next() : null;
+        return getCurrentLoop();
     }
 
     /**
--- a/src/jdk/nashorn/internal/ir/LexicalContextNode.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/ir/LexicalContextNode.java	Mon Jun 10 09:53:21 2013 +0100
@@ -60,10 +60,10 @@
      *
      * @return new node or same node depending on state change
      */
-    protected abstract Node accept(final LexicalContext lc, final NodeVisitor visitor);
+    protected abstract Node accept(final LexicalContext lc, final NodeVisitor<? extends LexicalContext> visitor);
 
     @Override
-    public Node accept(final NodeVisitor visitor) {
+    public Node accept(final NodeVisitor<? extends LexicalContext> visitor) {
         final LexicalContext lc = visitor.getLexicalContext();
         lc.push(this);
         final LexicalContextNode newNode = (LexicalContextNode)accept(lc, visitor);
--- a/src/jdk/nashorn/internal/ir/LiteralNode.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/ir/LiteralNode.java	Mon Jun 10 09:53:21 2013 +0100
@@ -208,7 +208,7 @@
      * @param visitor IR navigating visitor.
      */
     @Override
-    public Node accept(final NodeVisitor visitor) {
+    public Node accept(final NodeVisitor<? extends LexicalContext> visitor) {
         if (visitor.enterLiteralNode(this)) {
             return visitor.leaveLiteralNode(this);
         }
@@ -241,8 +241,8 @@
      *
      * @return the new literal node
      */
-    public static LiteralNode<Node> newInstance(final long token, final int finish) {
-        return new NodeLiteralNode(token, finish);
+    public static LiteralNode<Object> newInstance(final long token, final int finish) {
+        return new NullLiteralNode(token, finish);
     }
 
     /**
@@ -252,8 +252,8 @@
      *
      * @return the new literal node
      */
-    public static LiteralNode<?> newInstance(final Node parent) {
-        return new NodeLiteralNode(parent.getToken(), parent.getFinish());
+    public static LiteralNode<Object> newInstance(final Node parent) {
+        return new NullLiteralNode(parent.getToken(), parent.getFinish());
     }
 
     @Immutable
@@ -495,33 +495,15 @@
         return new LexerTokenLiteralNode(parent.getToken(), parent.getFinish(), value);
     }
 
-    private static final class NodeLiteralNode extends LiteralNode<Node> {
+    private static final class NullLiteralNode extends LiteralNode<Object> {
 
-        private NodeLiteralNode(final long token, final int finish) {
-            this(token, finish, null);
-        }
-
-        private NodeLiteralNode(final long token, final int finish, final Node value) {
-            super(Token.recast(token, TokenType.OBJECT), finish, value);
-        }
-
-        private NodeLiteralNode(final LiteralNode<Node> literalNode) {
-            super(literalNode);
-        }
-
-        private NodeLiteralNode(final LiteralNode<Node> literalNode, final Node value) {
-            super(literalNode, value);
+        private NullLiteralNode(final long token, final int finish) {
+            super(Token.recast(token, TokenType.OBJECT), finish, null);
         }
 
         @Override
-        public Node accept(final NodeVisitor visitor) {
+        public Node accept(final NodeVisitor<? extends LexicalContext> visitor) {
             if (visitor.enterLiteralNode(this)) {
-                if (value != null) {
-                    final Node newValue = value.accept(visitor);
-                    if(value != newValue) {
-                        return visitor.leaveLiteralNode(new NodeLiteralNode(this, newValue));
-                    }
-                }
                 return visitor.leaveLiteralNode(this);
             }
 
@@ -530,38 +512,13 @@
 
         @Override
         public Type getType() {
-            return value == null ? Type.OBJECT : super.getType();
+            return Type.OBJECT;
         }
 
         @Override
         public Type getWidestOperationType() {
-            return value == null ? Type.OBJECT : value.getWidestOperationType();
+            return Type.OBJECT;
         }
-
-    }
-    /**
-     * Create a new node literal for an arbitrary node
-     *
-     * @param token   token
-     * @param finish  finish
-     * @param value   the literal value node
-     *
-     * @return the new literal node
-     */
-    public static LiteralNode<Node> newInstance(final long token, final int finish, final Node value) {
-        return new NodeLiteralNode(token, finish, value);
-    }
-
-    /**
-     * Create a new node literal based on a parent node (source, token, finish)
-     *
-     * @param parent parent node
-     * @param value  node value
-     *
-     * @return the new literal node
-     */
-    public static LiteralNode<?> newInstance(final Node parent, final Node value) {
-        return new NodeLiteralNode(parent.getToken(), parent.getFinish(), value);
     }
 
     /**
@@ -840,7 +797,7 @@
         }
 
         @Override
-        public Node accept(final NodeVisitor visitor) {
+        public Node accept(final NodeVisitor<? extends LexicalContext> visitor) {
             if (visitor.enterLiteralNode(this)) {
                 final List<Node> oldValue = Arrays.asList(value);
                 final List<Node> newValue = Node.accept(visitor, Node.class, oldValue);
--- a/src/jdk/nashorn/internal/ir/Node.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/ir/Node.java	Mon Jun 10 09:53:21 2013 +0100
@@ -27,6 +27,7 @@
 
 import java.util.ArrayList;
 import java.util.List;
+
 import jdk.nashorn.internal.codegen.types.Type;
 import jdk.nashorn.internal.ir.visitor.NodeVisitor;
 import jdk.nashorn.internal.parser.Token;
@@ -153,6 +154,14 @@
     }
 
     /**
+     * Returns true if this node represents a comparison operator
+     * @return true if comparison
+     */
+    public boolean isComparison() {
+        return false;
+    }
+
+    /**
      * For reference copies - ensure that labels in the copy node are unique
      * using an appropriate copy constructor
      * @param lc lexical context
@@ -167,7 +176,7 @@
      * @param visitor Node visitor.
      * @return node the node or its replacement after visitation, null if no further visitations are required
      */
-    public abstract Node accept(NodeVisitor visitor);
+    public abstract Node accept(NodeVisitor<? extends LexicalContext> visitor);
 
     @Override
     public String toString() {
@@ -329,7 +338,7 @@
     }
 
     //on change, we have to replace the entire list, that's we can't simple do ListIterator.set
-    static <T extends Node> List<T> accept(final NodeVisitor visitor, final Class<T> clazz, final List<T> list) {
+    static <T extends Node> List<T> accept(final NodeVisitor<? extends LexicalContext> visitor, final Class<T> clazz, final List<T> list) {
         boolean changed = false;
         final List<T> newList = new ArrayList<>();
 
--- a/src/jdk/nashorn/internal/ir/ObjectNode.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/ir/ObjectNode.java	Mon Jun 10 09:53:21 2013 +0100
@@ -27,7 +27,6 @@
 
 import java.util.Collections;
 import java.util.List;
-
 import jdk.nashorn.internal.ir.annotations.Immutable;
 import jdk.nashorn.internal.ir.visitor.NodeVisitor;
 
@@ -38,7 +37,7 @@
 public final class ObjectNode extends Node {
 
     /** Literal elements. */
-    private final List<Node> elements;
+    private final List<PropertyNode> elements;
 
     /**
      * Constructor
@@ -47,20 +46,20 @@
      * @param finish   finish
      * @param elements the elements used to initialize this ObjectNode
      */
-    public ObjectNode(final long token, final int finish, final List<Node> elements) {
+    public ObjectNode(final long token, final int finish, final List<PropertyNode> elements) {
         super(token, finish);
         this.elements = elements;
     }
 
-    private ObjectNode(final ObjectNode objectNode, final List<Node> elements) {
+    private ObjectNode(final ObjectNode objectNode, final List<PropertyNode> elements) {
         super(objectNode);
         this.elements = elements;
     }
 
     @Override
-    public Node accept(final NodeVisitor visitor) {
+    public Node accept(final NodeVisitor<? extends LexicalContext> visitor) {
         if (visitor.enterObjectNode(this)) {
-            return visitor.leaveObjectNode(setElements(Node.accept(visitor, Node.class, elements)));
+            return visitor.leaveObjectNode(setElements(Node.accept(visitor, PropertyNode.class, elements)));
         }
 
         return this;
@@ -92,11 +91,11 @@
      * Get the elements of this literal node
      * @return a list of elements
      */
-    public List<Node> getElements() {
+    public List<PropertyNode> getElements() {
         return Collections.unmodifiableList(elements);
     }
 
-    private ObjectNode setElements(final List<Node> elements) {
+    private ObjectNode setElements(final List<PropertyNode> elements) {
         if (this.elements == elements) {
             return this;
         }
--- a/src/jdk/nashorn/internal/ir/PropertyNode.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/ir/PropertyNode.java	Mon Jun 10 09:53:21 2013 +0100
@@ -81,7 +81,7 @@
     }
 
     @Override
-    public Node accept(final NodeVisitor visitor) {
+    public Node accept(final NodeVisitor<? extends LexicalContext> visitor) {
         if (visitor.enterPropertyNode(this)) {
             return visitor.leavePropertyNode(
                 setKey((PropertyKey)((Node)key).accept(visitor)).
--- a/src/jdk/nashorn/internal/ir/ReturnNode.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/ir/ReturnNode.java	Mon Jun 10 09:53:21 2013 +0100
@@ -86,7 +86,7 @@
     }
 
     @Override
-    public Node accept(final NodeVisitor visitor) {
+    public Node accept(final NodeVisitor<? extends LexicalContext> visitor) {
         if (visitor.enterReturnNode(this)) {
             if (expression != null) {
                 return visitor.leaveReturnNode(setExpression(expression.accept(visitor)));
--- a/src/jdk/nashorn/internal/ir/RuntimeNode.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/ir/RuntimeNode.java	Mon Jun 10 09:53:21 2013 +0100
@@ -29,6 +29,7 @@
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
+
 import jdk.nashorn.internal.codegen.types.Type;
 import jdk.nashorn.internal.ir.annotations.Immutable;
 import jdk.nashorn.internal.ir.visitor.NodeVisitor;
@@ -407,7 +408,7 @@
     }
 
     @Override
-    public Node accept(final NodeVisitor visitor) {
+    public Node accept(final NodeVisitor<? extends LexicalContext> visitor) {
         if (visitor.enterRuntimeNode(this)) {
             final List<Node> newArgs = new ArrayList<>();
             for (final Node arg : args) {
--- a/src/jdk/nashorn/internal/ir/SplitNode.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/ir/SplitNode.java	Mon Jun 10 09:53:21 2013 +0100
@@ -81,7 +81,7 @@
     }
 
     @Override
-    public Node accept(final LexicalContext lc, final NodeVisitor visitor) {
+    public Node accept(final LexicalContext lc, final NodeVisitor<? extends LexicalContext> visitor) {
         if (visitor.enterSplitNode(this)) {
             return visitor.leaveSplitNode(setBody(lc, body.accept(visitor)));
         }
--- a/src/jdk/nashorn/internal/ir/SwitchNode.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/ir/SwitchNode.java	Mon Jun 10 09:53:21 2013 +0100
@@ -100,11 +100,11 @@
     }
 
     @Override
-    public Node accept(final LexicalContext lc, final NodeVisitor visitor) {
+    public Node accept(final LexicalContext lc, final NodeVisitor<? extends LexicalContext> visitor) {
         if (visitor.enterSwitchNode(this)) {
             return visitor.leaveSwitchNode(
-                setExpression(visitor.getLexicalContext(), expression.accept(visitor)).
-                setCases(visitor.getLexicalContext(), Node.accept(visitor, CaseNode.class, cases), defaultCaseIndex));
+                setExpression(lc, expression.accept(visitor)).
+                setCases(lc, Node.accept(visitor, CaseNode.class, cases), defaultCaseIndex));
         }
 
         return this;
--- a/src/jdk/nashorn/internal/ir/Symbol.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/ir/Symbol.java	Mon Jun 10 09:53:21 2013 +0100
@@ -29,6 +29,8 @@
 import java.util.HashSet;
 import java.util.Set;
 import java.util.StringTokenizer;
+
+import jdk.nashorn.internal.codegen.types.Range;
 import jdk.nashorn.internal.codegen.types.Type;
 import jdk.nashorn.internal.runtime.Context;
 import jdk.nashorn.internal.runtime.Debug;
@@ -89,6 +91,9 @@
     /** Number of times this symbol is used in code */
     private int useCount;
 
+    /** Range for symbol */
+    private Range range;
+
     /** Debugging option - dump info and stack trace when symbols with given names are manipulated */
     private static final Set<String> TRACE_SYMBOLS;
     private static final Set<String> TRACE_SYMBOLS_STACKTRACE;
@@ -131,6 +136,7 @@
         this.type       = type;
         this.slot       = slot;
         this.fieldIndex = -1;
+        this.range      = Range.createUnknownRange();
         trace("CREATE SYMBOL");
     }
 
@@ -157,12 +163,13 @@
 
     private Symbol(final Symbol base, final String name, final int flags) {
         this.flags = flags;
-        this.name = name;
+        this.name  = name;
 
         this.fieldIndex = base.fieldIndex;
-        this.slot = base.slot;
-        this.type = base.type;
-        this.useCount = base.useCount;
+        this.slot       = base.slot;
+        this.type       = base.type;
+        this.useCount   = base.useCount;
+        this.range      = base.range;
     }
 
     private static String align(final String string, final int max) {
@@ -276,7 +283,7 @@
 
     @Override
     public String toString() {
-        final StringBuilder sb   = new StringBuilder();
+        final StringBuilder sb = new StringBuilder();
 
         sb.append(name).
             append(' ').
@@ -410,6 +417,22 @@
     }
 
     /**
+     * Get the range for this symbol
+     * @return range for symbol
+     */
+    public Range getRange() {
+        return range;
+    }
+
+    /**
+     * Set the range for this symbol
+     * @param range range
+     */
+    public void setRange(final Range range) {
+        this.range = range;
+    }
+
+    /**
      * Check if this symbol is a function parameter of known
      * narrowest type
      * @return true if parameter
--- a/src/jdk/nashorn/internal/ir/TernaryNode.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/ir/TernaryNode.java	Mon Jun 10 09:53:21 2013 +0100
@@ -63,7 +63,7 @@
     }
 
     @Override
-    public Node accept(final NodeVisitor visitor) {
+    public Node accept(final NodeVisitor<? extends LexicalContext> visitor) {
         if (visitor.enterTernaryNode(this)) {
             final Node newLhs = lhs().accept(visitor);
             final Node newRhs = rhs().accept(visitor);
--- a/src/jdk/nashorn/internal/ir/ThrowNode.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/ir/ThrowNode.java	Mon Jun 10 09:53:21 2013 +0100
@@ -36,6 +36,11 @@
     /** Exception expression. */
     private final Node expression;
 
+    private final int flags;
+
+    /** Is this block a synthethic rethrow created by finally inlining? */
+    public static final int IS_SYNTHETIC_RETHROW = 1;
+
     /**
      * Constructor
      *
@@ -43,15 +48,18 @@
      * @param token      token
      * @param finish     finish
      * @param expression expression to throw
+     * @param flags      flags
      */
-    public ThrowNode(final int lineNumber, final long token, final int finish, final Node expression) {
+    public ThrowNode(final int lineNumber, final long token, final int finish, final Node expression, final int flags) {
         super(lineNumber, token, finish);
         this.expression = expression;
+        this.flags = flags;
     }
 
-    private ThrowNode(final ThrowNode node, final Node expression) {
+    private ThrowNode(final ThrowNode node, final Node expression, final int flags) {
         super(node);
         this.expression = expression;
+        this.flags = flags;
     }
 
     @Override
@@ -64,7 +72,7 @@
      * @param visitor IR navigating visitor.
      */
     @Override
-    public Node accept(final NodeVisitor visitor) {
+    public Node accept(final NodeVisitor<? extends LexicalContext> visitor) {
         if (visitor.enterThrowNode(this)) {
             return visitor.leaveThrowNode(setExpression(expression.accept(visitor)));
         }
@@ -98,7 +106,17 @@
         if (this.expression == expression) {
             return this;
         }
-        return new ThrowNode(this, expression);
+        return new ThrowNode(this, expression, flags);
+    }
+
+    /**
+     * Is this a throw a synthetic rethrow in a synthetic catch-all block
+     * created when inlining finally statements? In that case we never
+     * wrap whatever is thrown into an ECMAException, just rethrow it.
+     * @return true if synthetic throw node
+     */
+    public boolean isSyntheticRethrow() {
+        return (flags & IS_SYNTHETIC_RETHROW) == IS_SYNTHETIC_RETHROW;
     }
 
 }
--- a/src/jdk/nashorn/internal/ir/TryNode.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/ir/TryNode.java	Mon Jun 10 09:53:21 2013 +0100
@@ -106,7 +106,7 @@
      * @param visitor IR navigating visitor.
      */
     @Override
-    public Node accept(final NodeVisitor visitor) {
+    public Node accept(final NodeVisitor<? extends LexicalContext> visitor) {
         if (visitor.enterTryNode(this)) {
             // Need to do finallybody first for termination analysis. TODO still necessary?
             final Block newFinallyBody = finallyBody == null ? null : (Block)finallyBody.accept(visitor);
--- a/src/jdk/nashorn/internal/ir/UnaryNode.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/ir/UnaryNode.java	Mon Jun 10 09:53:21 2013 +0100
@@ -29,7 +29,6 @@
 import static jdk.nashorn.internal.parser.TokenType.CONVERT;
 import static jdk.nashorn.internal.parser.TokenType.DECPOSTFIX;
 import static jdk.nashorn.internal.parser.TokenType.INCPOSTFIX;
-
 import jdk.nashorn.internal.codegen.types.Type;
 import jdk.nashorn.internal.ir.annotations.Immutable;
 import jdk.nashorn.internal.ir.visitor.NodeVisitor;
@@ -121,7 +120,7 @@
      * @param visitor IR navigating visitor.
      */
     @Override
-    public Node accept(final NodeVisitor visitor) {
+    public Node accept(final NodeVisitor<? extends LexicalContext> visitor) {
         if (visitor.enterUnaryNode(this)) {
             return visitor.leaveUnaryNode(setRHS(rhs.accept(visitor)));
         }
--- a/src/jdk/nashorn/internal/ir/VarNode.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/ir/VarNode.java	Mon Jun 10 09:53:21 2013 +0100
@@ -121,7 +121,7 @@
      * @param visitor IR navigating visitor.
      */
     @Override
-    public Node accept(final NodeVisitor visitor) {
+    public Node accept(final NodeVisitor<? extends LexicalContext> visitor) {
         if (visitor.enterVarNode(this)) {
             final IdentNode newName = (IdentNode)name.accept(visitor);
             final Node      newInit = init == null ? null : init.accept(visitor);
--- a/src/jdk/nashorn/internal/ir/WhileNode.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/ir/WhileNode.java	Mon Jun 10 09:53:21 2013 +0100
@@ -75,7 +75,7 @@
     }
 
     @Override
-    protected Node accept(final LexicalContext lc, final NodeVisitor visitor) {
+    protected Node accept(final LexicalContext lc, final NodeVisitor<? extends LexicalContext> visitor) {
         if (visitor.enterWhileNode(this)) {
             if (isDoWhile()) {
                 return visitor.leaveWhileNode(
--- a/src/jdk/nashorn/internal/ir/WithNode.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/ir/WithNode.java	Mon Jun 10 09:53:21 2013 +0100
@@ -64,7 +64,7 @@
      * @param visitor IR navigating visitor.
      */
     @Override
-    public Node accept(final LexicalContext lc, final NodeVisitor visitor) {
+    public Node accept(final LexicalContext lc, final NodeVisitor<? extends LexicalContext> visitor) {
         if (visitor.enterWithNode(this)) {
              return visitor.leaveWithNode(
                 setExpression(lc, expression.accept(visitor)).
--- a/src/jdk/nashorn/internal/ir/debug/JSONWriter.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/ir/debug/JSONWriter.java	Mon Jun 10 09:53:21 2013 +0100
@@ -45,6 +45,7 @@
 import jdk.nashorn.internal.ir.IfNode;
 import jdk.nashorn.internal.ir.IndexNode;
 import jdk.nashorn.internal.ir.LabelNode;
+import jdk.nashorn.internal.ir.LexicalContext;
 import jdk.nashorn.internal.ir.LiteralNode;
 import jdk.nashorn.internal.ir.Node;
 import jdk.nashorn.internal.ir.ObjectNode;
@@ -74,7 +75,8 @@
 /**
  * This IR writer produces a JSON string that represents AST as a JSON string.
  */
-public final class JSONWriter extends NodeVisitor {
+public final class JSONWriter extends NodeVisitor<LexicalContext> {
+
     /**
      * Returns AST as JSON compatible string.
      *
@@ -867,7 +869,8 @@
     // Internals below
 
     private JSONWriter(final boolean includeLocation) {
-        this.buf = new StringBuilder();
+        super(new LexicalContext());
+        this.buf             = new StringBuilder();
         this.includeLocation = includeLocation;
     }
 
@@ -963,7 +966,7 @@
             objectStart("loc");
 
             // source name
-            final Source src = getLexicalContext().getCurrentFunction().getSource();
+            final Source src = lc.getCurrentFunction().getSource();
             property("source", src.getName());
             comma();
 
--- a/src/jdk/nashorn/internal/ir/debug/PrintVisitor.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/ir/debug/PrintVisitor.java	Mon Jun 10 09:53:21 2013 +0100
@@ -36,6 +36,7 @@
 import jdk.nashorn.internal.ir.FunctionNode;
 import jdk.nashorn.internal.ir.IfNode;
 import jdk.nashorn.internal.ir.LabelNode;
+import jdk.nashorn.internal.ir.LexicalContext;
 import jdk.nashorn.internal.ir.Node;
 import jdk.nashorn.internal.ir.SplitNode;
 import jdk.nashorn.internal.ir.Statement;
@@ -53,7 +54,7 @@
  *
  * see the flags --print-parse and --print-lower-parse
  */
-public final class PrintVisitor extends NodeVisitor {
+public final class PrintVisitor extends NodeVisitor<LexicalContext> {
     /** Tab width */
     private static final int TABWIDTH = 4;
 
@@ -84,6 +85,7 @@
      * @param printLineNumbers  should line number nodes be included in the output?
      */
     public PrintVisitor(final boolean printLineNumbers) {
+        super(new LexicalContext());
         this.EOLN             = System.lineSeparator();
         this.sb               = new StringBuilder();
         this.printLineNumbers = printLineNumbers;
--- a/src/jdk/nashorn/internal/ir/visitor/NodeOperatorVisitor.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/ir/visitor/NodeOperatorVisitor.java	Mon Jun 10 09:53:21 2013 +0100
@@ -32,21 +32,15 @@
 
 /**
  * Like NodeVisitor but navigating further into operators.
+ * @param <T> Lexical context class for this NodeOperatorVisitor
  */
-public class NodeOperatorVisitor extends NodeVisitor {
-    /**
-     * Constructor
-     */
-    public NodeOperatorVisitor() {
-        super();
-    }
-
+public class NodeOperatorVisitor<T extends LexicalContext> extends NodeVisitor<T> {
     /**
      * Constructor
      *
      * @param lc a custom lexical context
      */
-    public NodeOperatorVisitor(final LexicalContext lc) {
+    public NodeOperatorVisitor(final T lc) {
         super(lc);
     }
 
--- a/src/jdk/nashorn/internal/ir/visitor/NodeVisitor.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/ir/visitor/NodeVisitor.java	Mon Jun 10 09:53:21 2013 +0100
@@ -60,23 +60,18 @@
 
 /**
  * Visitor used to navigate the IR.
+ * @param <T> lexical context class used by this visitor
  */
-public abstract class NodeVisitor {
-    private final LexicalContext lc;
-
-    /**
-     * Constructor
-     */
-    public NodeVisitor() {
-        this(new LexicalContext());
-    }
+public abstract class NodeVisitor<T extends LexicalContext> {
+    /** lexical context in use */
+    protected final T lc;
 
     /**
      * Constructor
      *
      * @param lc a custom lexical context
      */
-    public NodeVisitor(final LexicalContext lc) {
+    public NodeVisitor(final T lc) {
         this.lc = lc;
     }
 
@@ -84,7 +79,7 @@
      * Get the lexical context of this node visitor
      * @return lexical context
      */
-    public LexicalContext getLexicalContext() {
+    public T getLexicalContext() {
         return lc;
     }
 
--- a/src/jdk/nashorn/internal/objects/ArrayBufferView.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/objects/ArrayBufferView.java	Mon Jun 10 09:53:21 2013 +0100
@@ -59,11 +59,6 @@
     }
 
     @Getter(attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_WRITABLE | Attribute.NOT_CONFIGURABLE)
-    public static Object BYTES_PER_ELEMENT(final Object self) {
-        return ((ArrayBufferView)self).bytesPerElement();
-    }
-
-    @Getter(attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_WRITABLE | Attribute.NOT_CONFIGURABLE)
     public static Object buffer(final Object self) {
         return ((ArrayDataImpl)((ArrayBufferView)self).getArray()).buffer;
     }
--- a/src/jdk/nashorn/internal/objects/DateParser.java	Fri May 31 10:28:34 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,705 +0,0 @@
-/*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package jdk.nashorn.internal.objects;
-
-import static java.lang.Character.DECIMAL_DIGIT_NUMBER;
-import static java.lang.Character.LOWERCASE_LETTER;
-import static java.lang.Character.OTHER_PUNCTUATION;
-import static java.lang.Character.SPACE_SEPARATOR;
-import static java.lang.Character.UPPERCASE_LETTER;
-
-import java.util.HashMap;
-
-/**
- * JavaScript date parser. This class first tries to parse a date string
- * according to the extended ISO 8601 format specified in ES5 15.9.1.15.
- * If that fails, it falls back to legacy mode in which it accepts a range
- * of different formats.
- *
- * <p>This class is neither thread-safe nor reusable. Calling the
- * <tt>parse()</tt> method more than once will yield undefined results.</p>
- */
-public class DateParser {
-
-    /** Constant for index position of parsed year value. */
-    public final static int YEAR        = 0;
-    /** Constant for index position of parsed month value. */
-    public final static int MONTH       = 1;
-    /** Constant for index position of parsed day value. */
-    public final static int DAY         = 2;
-    /** Constant for index position of parsed hour value. */
-    public final static int HOUR        = 3;
-    /** Constant for index position of parsed minute value. */
-    public final static int MINUTE      = 4;
-    /** Constant for index position of parsed second value. */
-    public final static int SECOND      = 5;
-    /** Constant for index position of parsed millisecond value. */
-    public final static int MILLISECOND = 6;
-    /** Constant for index position of parsed time zone offset value. */
-    public final static int TIMEZONE    = 7;
-
-    private enum Token {
-        UNKNOWN, NUMBER, SEPARATOR, PARENTHESIS, NAME, SIGN, END
-    }
-
-    private final String string;
-    private final int length;
-    private final Integer[] fields;
-    private int pos = 0;
-    private Token token;
-    private int tokenLength;
-    private Name nameValue;
-    private int numValue;
-    private int currentField = YEAR;
-    private int yearSign = 0;
-    private boolean namedMonth = false;
-
-    private final static HashMap<String,Name> names = new HashMap<>();
-
-    static {
-        addName("monday", Name.DAY_OF_WEEK, 0);
-        addName("tuesday", Name.DAY_OF_WEEK, 0);
-        addName("wednesday", Name.DAY_OF_WEEK, 0);
-        addName("thursday", Name.DAY_OF_WEEK, 0);
-        addName("friday", Name.DAY_OF_WEEK, 0);
-        addName("saturday", Name.DAY_OF_WEEK, 0);
-        addName("sunday", Name.DAY_OF_WEEK, 0);
-        addName("january", Name.MONTH_NAME, 1);
-        addName("february", Name.MONTH_NAME, 2);
-        addName("march", Name.MONTH_NAME, 3);
-        addName("april", Name.MONTH_NAME, 4);
-        addName("may", Name.MONTH_NAME, 5);
-        addName("june", Name.MONTH_NAME, 6);
-        addName("july", Name.MONTH_NAME, 7);
-        addName("august", Name.MONTH_NAME, 8);
-        addName("september", Name.MONTH_NAME, 9);
-        addName("october", Name.MONTH_NAME, 10);
-        addName("november", Name.MONTH_NAME, 11);
-        addName("december", Name.MONTH_NAME, 12);
-        addName("am", Name.AM_PM, 0);
-        addName("pm", Name.AM_PM, 12);
-        addName("z", Name.TIMEZONE_ID, 0);
-        addName("gmt", Name.TIMEZONE_ID, 0);
-        addName("ut", Name.TIMEZONE_ID, 0);
-        addName("utc", Name.TIMEZONE_ID, 0);
-        addName("est", Name.TIMEZONE_ID, -5 * 60);
-        addName("edt", Name.TIMEZONE_ID, -4 * 60);
-        addName("cst", Name.TIMEZONE_ID, -6 * 60);
-        addName("cdt", Name.TIMEZONE_ID, -5 * 60);
-        addName("mst", Name.TIMEZONE_ID, -7 * 60);
-        addName("mdt", Name.TIMEZONE_ID, -6 * 60);
-        addName("pst", Name.TIMEZONE_ID, -8 * 60);
-        addName("pdt", Name.TIMEZONE_ID, -7 * 60);
-        addName("t", Name.TIME_SEPARATOR, 0);
-    }
-
-    /**
-     * Construct a new <tt>DateParser</tt> instance for parsing the given string.
-     * @param string the string to be parsed
-     */
-    public DateParser(final String string) {
-        this.string = string;
-        this.length = string.length();
-        this.fields = new Integer[TIMEZONE + 1];
-    }
-
-    /**
-     * Try parsing the given string as date according to the extended ISO 8601 format
-     * specified in ES5 15.9.1.15. Fall back to legacy mode if that fails.
-     * This method returns <tt>true</tt> if the string could be parsed.
-     * @return true if the string could be parsed as date
-     */
-    public boolean parse() {
-        return parseEcmaDate() || parseLegacyDate();
-    }
-
-    /**
-     * Try parsing the date string according to the rules laid out in ES5 15.9.1.15.
-     * The date string must conform to the following format:
-     *
-     * <pre>  [('-'|'+')yy]yyyy[-MM[-dd]][hh:mm[:ss[.sss]][Z|(+|-)hh:mm]] </pre>
-     *
-     * <p>If the string does not contain a time zone offset, the <tt>TIMEZONE</tt> field
-     * is set to <tt>0</tt> (GMT).</p>
-     * @return true if string represents a valid ES5 date string.
-     */
-    public boolean parseEcmaDate() {
-
-        if (token == null) {
-            token = next();
-        }
-
-        while (token != Token.END) {
-
-            switch (token) {
-                case NUMBER:
-                    if (currentField == YEAR && yearSign != 0) {
-                        // 15.9.1.15.1 Extended year must have six digits
-                        if (tokenLength != 6) {
-                            return false;
-                        }
-                        numValue *= yearSign;
-                    } else if (!checkEcmaField(currentField, numValue)) {
-                        return false;
-                    }
-                    if (!skipEcmaDelimiter()) {
-                        return false;
-                    }
-                    if (currentField < TIMEZONE) {
-                        set(currentField++, numValue);
-                    }
-                    break;
-
-                case NAME:
-                    if (nameValue == null) {
-                        return false;
-                    }
-                    switch (nameValue.type) {
-                        case Name.TIME_SEPARATOR:
-                            if (currentField == YEAR || currentField > HOUR) {
-                                return false;
-                            }
-                            currentField = HOUR;
-                            break;
-                        case Name.TIMEZONE_ID:
-                            if (!nameValue.key.equals("z") || !setTimezone(nameValue.value, false)) {
-                                return false;
-                            }
-                            break;
-                        default:
-                            return false;
-                    }
-                    break;
-
-                case SIGN:
-                    if (currentField == YEAR) {
-                        yearSign = numValue;
-                    } else if (currentField < SECOND || !setTimezone(readTimeZoneOffset(), true)) {
-                        // Note: Spidermonkey won't parse timezone unless time includes seconds and milliseconds
-                        return false;
-                    }
-                    break;
-
-                default:
-                    return false;
-            }
-            token = next();
-        }
-
-        return patchResult(true);
-    }
-
-    /**
-     * Try parsing the date using a fuzzy algorithm that can handle a variety of formats.
-     *
-     * <p>Numbers separated by <tt>':'</tt> are treated as time values, optionally followed by a
-     * millisecond value separated by <tt>'.'</tt>. Other number values are treated as date values.
-     * The exact sequence of day, month, and year values to apply is determined heuristically.</p>
-     *
-     * <p>English month names and selected time zone names as well as AM/PM markers are recognized
-     * and handled properly. Additionally, numeric time zone offsets such as <tt>(+|-)hh:mm</tt> or
-     * <tt>(+|-)hhmm</tt> are recognized. If the string does not contain a time zone offset
-     * the <tt>TIMEZONE</tt>field is left undefined, meaning the local time zone should be applied.</p>
-     *
-     * <p>English weekday names are recognized but ignored. All text in parentheses is ignored as well.
-     * All other text causes parsing to fail.</p>
-     *
-     * @return true if the string could be parsed
-     */
-    public boolean parseLegacyDate() {
-
-        if (yearSign != 0 || currentField > DAY) {
-            // we don't support signed years in legacy mode
-            return false;
-        }
-        if (token == null) {
-            token = next();
-        }
-
-        while (token != Token.END) {
-
-            switch (token) {
-                case NUMBER:
-                    if (skip(':')) {
-                        // A number followed by ':' is parsed as time
-                        if (!setTimeField(numValue)) {
-                            return false;
-                        }
-                        // consume remaining time tokens
-                        do {
-                            token = next();
-                            if (token != Token.NUMBER || !setTimeField(numValue)) {
-                                return false;
-                            }
-                        } while (skip(isSet(SECOND) ? '.' : ':'));
-
-                    } else {
-                        // Parse as date token
-                        if (!setDateField(numValue)) {
-                            return false;
-                        }
-                        skip('-');
-                    }
-                    break;
-
-                case NAME:
-                    if (nameValue == null) {
-                        return false;
-                    }
-                    switch (nameValue.type) {
-                        case Name.AM_PM:
-                            if (!setAmPm(nameValue.value)) {
-                                return false;
-                            }
-                            break;
-                        case Name.MONTH_NAME:
-                            if (!setMonth(nameValue.value)) {
-                                return false;
-                            }
-                            break;
-                        case Name.TIMEZONE_ID:
-                            if (!setTimezone(nameValue.value, false)) {
-                                return false;
-                            }
-                            break;
-                        case Name.TIME_SEPARATOR:
-                            return false;
-                        default:
-                            break;
-                    }
-                    if (nameValue.type != Name.TIMEZONE_ID) {
-                        skip('-');
-                    }
-                    break;
-
-                case SIGN:
-                    if (!setTimezone(readTimeZoneOffset(), true)) {
-                        return false;
-                    }
-                    break;
-
-                case PARENTHESIS:
-                    if (!skipParentheses()) {
-                        return false;
-                    }
-                    break;
-
-                case SEPARATOR:
-                    break;
-
-                default:
-                    return false;
-            }
-            token = next();
-        }
-
-        return patchResult(false);
-    }
-
-    /**
-     * Get the parsed date and time fields as an array of <tt>Integers</tt>.
-     *
-     * <p>If parsing was successful, all fields are guaranteed to be set except for the
-     * <tt>TIMEZONE</tt> field which may be <tt>null</tt>, meaning that local time zone
-     * offset should be applied.</p>
-     *
-     * @return the parsed date fields
-     */
-    public Integer[] getDateFields() {
-        return fields;
-    }
-
-    private boolean isSet(final int field) {
-        return fields[field] != null;
-    }
-
-    private Integer get(final int field) {
-        return fields[field];
-    }
-
-    private void set(final int field, final int value) {
-        fields[field] = value;
-    }
-
-    private int peek() {
-        return pos < length ? string.charAt(pos) : -1;
-    }
-
-    private boolean skip(final char c) {
-        if (pos < length && string.charAt(pos) == c) {
-            token = null;
-            pos++;
-            return true;
-        }
-        return false;
-    }
-
-    private Token next() {
-        if (pos >= length) {
-            tokenLength = 0;
-            return Token.END;
-        }
-
-        final char c = string.charAt(pos);
-
-        if (c > 0x80) {
-            tokenLength = 1;
-            pos++;
-            return Token.UNKNOWN; // We only deal with ASCII here
-        }
-
-        final int type = Character.getType(c);
-        switch (type) {
-            case DECIMAL_DIGIT_NUMBER:
-                numValue = readNumber(6);
-                return Token.NUMBER;
-            case SPACE_SEPARATOR :
-            case OTHER_PUNCTUATION:
-                tokenLength = 1;
-                pos++;
-                return Token.SEPARATOR;
-            case UPPERCASE_LETTER:
-            case LOWERCASE_LETTER:
-                nameValue = readName();
-                return Token.NAME;
-            default:
-                tokenLength = 1;
-                pos++;
-                switch (c) {
-                    case '(':
-                        return Token.PARENTHESIS;
-                    case '-':
-                    case '+':
-                        numValue = c == '-' ? -1 : 1;
-                        return Token.SIGN;
-                    default:
-                        return Token.UNKNOWN;
-                }
-        }
-    }
-
-    private static boolean checkLegacyField(final int field, final int value) {
-        switch (field) {
-            case HOUR:
-                return isHour(value);
-            case MINUTE:
-            case SECOND:
-                return isMinuteOrSecond(value);
-            case MILLISECOND:
-                return isMillisecond(value);
-            default:
-                // skip validation on other legacy fields as we don't know what's what
-                return true;
-        }
-    }
-
-    private boolean checkEcmaField(final int field, final int value) {
-        switch (field) {
-            case YEAR:
-                return tokenLength == 4;
-            case MONTH:
-                return tokenLength == 2 && isMonth(value);
-            case DAY:
-                return tokenLength == 2 && isDay(value);
-            case HOUR:
-                return tokenLength == 2 && isHour(value);
-            case MINUTE:
-            case SECOND:
-                return tokenLength == 2 && isMinuteOrSecond(value);
-            case MILLISECOND:
-                // we allow millisecond to be less than 3 digits
-                return tokenLength < 4 && isMillisecond(value);
-            default:
-                return true;
-        }
-    }
-
-    private boolean skipEcmaDelimiter() {
-        switch (currentField) {
-            case YEAR:
-            case MONTH:
-                return skip('-') || peek() == 'T' || peek() == -1;
-            case DAY:
-                return peek() == 'T' || peek() == -1;
-            case HOUR:
-            case MINUTE:
-                return skip(':') || endOfTime();
-            case SECOND:
-                return skip('.') || endOfTime();
-            default:
-                return true;
-        }
-    }
-
-    private boolean endOfTime() {
-        final int c = peek();
-        return c == -1 || c == 'Z' || c == '-' || c == '+' || c == ' ';
-    }
-
-    private static boolean isAsciiLetter(final char ch) {
-        return ('A' <= ch && ch <= 'Z') || ('a' <= ch && ch <= 'z');
-    }
-
-    private static boolean isAsciiDigit(final char ch) {
-        return '0' <= ch && ch <= '9';
-    }
-
-    private int readNumber(final int maxDigits) {
-        final int start = pos;
-        int n = 0;
-        final int max = Math.min(length, pos + maxDigits);
-        while (pos < max && isAsciiDigit(string.charAt(pos))) {
-            n = n * 10 + string.charAt(pos++) - '0';
-        }
-        tokenLength = pos - start;
-        return n;
-    }
-
-    private Name readName() {
-        final int start = pos;
-        final int limit = Math.min(pos + 3, length);
-
-        // first read up to the key length
-        while (pos < limit && isAsciiLetter(string.charAt(pos))) {
-            pos++;
-        }
-        final String key = string.substring(start, pos).toLowerCase();
-        final Name name = names.get(key);
-        // then advance to end of name
-        while (pos < length && isAsciiLetter(string.charAt(pos))) {
-            pos++;
-        }
-
-        tokenLength = pos - start;
-        // make sure we have the full name or a prefix
-        if (name != null && name.matches(string, start, tokenLength)) {
-            return name;
-        }
-        return null;
-    }
-
-    private int readTimeZoneOffset() {
-        final int sign = string.charAt(pos - 1) == '+' ? 1 : -1;
-        int offset = readNumber(2);
-        skip(':');
-        offset = offset * 60 + readNumber(2);
-        return sign * offset;
-    }
-
-    private boolean skipParentheses() {
-        int parenCount = 1;
-        while (pos < length && parenCount != 0) {
-            final char c = string.charAt(pos++);
-            if (c == '(') {
-                parenCount++;
-            } else if (c == ')') {
-                parenCount--;
-            }
-        }
-        return true;
-    }
-
-    private static int getDefaultValue(final int field) {
-        switch (field) {
-            case MONTH:
-            case DAY:
-                return 1;
-            default:
-                return 0;
-        }
-    }
-
-    private static boolean isDay(final int n) {
-        return 1 <= n && n <= 31;
-    }
-
-    private static boolean isMonth(final int n) {
-        return 1 <= n && n <= 12;
-    }
-
-    private static boolean isHour(final int n) {
-        return 0 <= n && n <= 24;
-    }
-
-    private static boolean isMinuteOrSecond(final int n) {
-        return 0 <= n && n < 60;
-    }
-
-    private static boolean isMillisecond(final int n) {
-        return 0<= n && n < 1000;
-    }
-
-    private boolean setMonth(final int m) {
-        if (!isSet(MONTH)) {
-            namedMonth = true;
-            set(MONTH, m);
-            return true;
-        }
-        return false;
-    }
-
-    private boolean setDateField(final int n) {
-        for (int field = YEAR; field != HOUR; field++) {
-            if (!isSet(field)) {
-                // no validation on legacy date fields
-                set(field, n);
-                return true;
-            }
-        }
-        return false;
-    }
-
-    private boolean setTimeField(final int n) {
-        for (int field = HOUR; field != TIMEZONE; field++) {
-            if (!isSet(field)) {
-                if (checkLegacyField(field, n)) {
-                    set(field, n);
-                    return true;
-                }
-                return false;
-            }
-        }
-        return false;
-    }
-
-    private boolean setTimezone(final int offset, final boolean asNumericOffset) {
-        if (!isSet(TIMEZONE) || (asNumericOffset && get(TIMEZONE) == 0)) {
-            set(TIMEZONE, offset);
-            return true;
-        }
-        return false;
-    }
-
-    private boolean setAmPm(final int offset) {
-        if (!isSet(HOUR)) {
-            return false;
-        }
-        final int hour = get(HOUR);
-        if (hour >= 0 && hour <= 12) {
-            set(HOUR, hour + offset);
-        }
-        return true;
-    }
-
-    private boolean patchResult(final boolean strict) {
-        // sanity checks - make sure we have something
-        if (!isSet(YEAR) && !isSet(HOUR)) {
-            return false;
-        }
-        if (isSet(HOUR) && !isSet(MINUTE)) {
-            return false;
-        }
-        // fill in default values for unset fields except timezone
-        for (int field = YEAR; field <= TIMEZONE; field++) {
-            if (get(field) == null) {
-                if (field == TIMEZONE && !strict) {
-                    // We only use UTC as default timezone for dates parsed complying with
-                    // the format specified in ES5 15.9.1.15. Otherwise the slot is left empty
-                    // and local timezone is used.
-                    continue;
-                }
-                final int value = getDefaultValue(field);
-                set(field, value);
-            }
-        }
-
-        if (!strict) {
-            // swap year, month, and day if it looks like the right thing to do
-            if (isDay(get(YEAR))) {
-                final int d = get(YEAR);
-                set(YEAR, get(DAY));
-                if (namedMonth) {
-                    // d-m-y
-                    set(DAY, d);
-                } else {
-                    // m-d-y
-                    final int d2 = get(MONTH);
-                    set(MONTH, d);
-                    set(DAY, d2);
-                }
-            }
-            // sanity checks now that we know what's what
-            if (!isMonth(get(MONTH)) || !isDay(get(DAY))) {
-                return false;
-            }
-
-            // add 1900 or 2000 to year if it's between 0 and 100
-            final int year = get(YEAR);
-            if (year >= 0 && year < 100) {
-                set(YEAR, year >= 50 ? 1900 + year : 2000 + year);
-            }
-        } else {
-            // 24 hour value is only allowed if all other time values are zero
-            if (get(HOUR) == 24 &&
-                    (get(MINUTE) != 0 || get(SECOND) != 0 || get(MILLISECOND) != 0)) {
-                return false;
-            }
-        }
-
-        // set month to 0-based
-        set(MONTH, get(MONTH) - 1);
-        return true;
-    }
-
-    private static void addName(final String str, final int type, final int value) {
-        final Name name = new Name(str, type, value);
-        names.put(name.key, name);
-    }
-
-    private static class Name {
-        final String name;
-        final String key;
-        final int value;
-        final int type;
-
-        final static int DAY_OF_WEEK    = -1;
-        final static int MONTH_NAME     = 0;
-        final static int AM_PM          = 1;
-        final static int TIMEZONE_ID    = 2;
-        final static int TIME_SEPARATOR = 3;
-
-        Name(final String name, final int type, final int value) {
-            assert name != null;
-            assert name.equals(name.toLowerCase());
-
-            this.name = name;
-            // use first three characters as lookup key
-            this.key = name.substring(0, Math.min(3, name.length()));
-            this.type = type;
-            this.value = value;
-        }
-
-        public boolean matches(final String str, final int offset, final int len) {
-            return name.regionMatches(true, 0, str, offset, len);
-        }
-
-        @Override
-        public String toString() {
-            return name;
-        }
-    }
-
-}
--- a/src/jdk/nashorn/internal/objects/GenericPropertyDescriptor.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/objects/GenericPropertyDescriptor.java	Mon Jun 10 09:53:21 2013 +0100
@@ -150,11 +150,11 @@
         if (this == obj) {
             return true;
         }
-        if (!(obj instanceof AccessorPropertyDescriptor)) {
+        if (!(obj instanceof GenericPropertyDescriptor)) {
             return false;
         }
 
-        final AccessorPropertyDescriptor other = (AccessorPropertyDescriptor)obj;
+        final GenericPropertyDescriptor other = (GenericPropertyDescriptor)obj;
         return ScriptRuntime.sameValue(configurable, other.configurable) &&
                ScriptRuntime.sameValue(enumerable, other.enumerable);
     }
--- a/src/jdk/nashorn/internal/objects/Global.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/objects/Global.java	Mon Jun 10 09:53:21 2013 +0100
@@ -119,6 +119,10 @@
     @Property(attributes = Attribute.NOT_ENUMERABLE)
     public Object load;
 
+    /** Nashorn extension: global.loadWithNewGlobal */
+    @Property(attributes = Attribute.NOT_ENUMERABLE)
+    public Object loadWithNewGlobal;
+
     /** Nashorn extension: global.exit */
     @Property(attributes = Attribute.NOT_ENUMERABLE)
     public Object exit;
@@ -364,11 +368,12 @@
     // Used to store the last RegExp result to support deprecated RegExp constructor properties
     private RegExpResult lastRegExpResult;
 
-    private static final MethodHandle EVAL    = findOwnMH("eval",    Object.class, Object.class, Object.class);
-    private static final MethodHandle PRINT   = findOwnMH("print",   Object.class, Object.class, Object[].class);
-    private static final MethodHandle PRINTLN = findOwnMH("println", Object.class, Object.class, Object[].class);
-    private static final MethodHandle LOAD    = findOwnMH("load",    Object.class, Object.class, Object.class);
-    private static final MethodHandle EXIT    = findOwnMH("exit",    Object.class, Object.class, Object.class);
+    private static final MethodHandle EVAL              = findOwnMH("eval",              Object.class, Object.class, Object.class);
+    private static final MethodHandle PRINT             = findOwnMH("print",             Object.class, Object.class, Object[].class);
+    private static final MethodHandle PRINTLN           = findOwnMH("println",           Object.class, Object.class, Object[].class);
+    private static final MethodHandle LOAD              = findOwnMH("load",              Object.class, Object.class, Object.class);
+    private static final MethodHandle LOADWITHNEWGLOBAL = findOwnMH("loadWithNewGlobal", Object.class, Object.class, Object.class);
+    private static final MethodHandle EXIT              = findOwnMH("exit",              Object.class, Object.class, Object.class);
 
     private final Context context;
 
@@ -743,6 +748,21 @@
     }
 
     /**
+     * Global loadWithNewGlobal implementation - Nashorn extension
+     *
+     * @param self    scope
+     * @param source  source to load
+     *
+     * @return result of load (undefined)
+     *
+     * @throws IOException if source could not be read
+     */
+    public static Object loadWithNewGlobal(final Object self, final Object source) throws IOException {
+        final Global global = Global.instance();
+        return global.context.loadWithNewGlobal(source);
+    }
+
+    /**
      * Global exit and quit implementation - Nashorn extension: perform a {@code System.exit} call from the script
      *
      * @param self  self reference
@@ -1387,6 +1407,7 @@
         this.unescape           = ScriptFunctionImpl.makeFunction("unescape",   GlobalFunctions.UNESCAPE);
         this.print              = ScriptFunctionImpl.makeFunction("print",      env._print_no_newline ? PRINT : PRINTLN);
         this.load               = ScriptFunctionImpl.makeFunction("load",       LOAD);
+        this.loadWithNewGlobal  = ScriptFunctionImpl.makeFunction("loadWithNewGlobal", LOADWITHNEWGLOBAL);
         this.exit               = ScriptFunctionImpl.makeFunction("exit",       EXIT);
         this.quit               = ScriptFunctionImpl.makeFunction("quit",       EXIT);
 
@@ -1628,20 +1649,21 @@
     @SuppressWarnings("resource")
     private static Object printImpl(final boolean newLine, final Object... objects) {
         final PrintWriter out = Global.getEnv().getOut();
+        final StringBuilder sb = new StringBuilder();
 
-        boolean first = true;
         for (final Object object : objects) {
-            if (first) {
-                first = false;
-            } else {
-                out.print(' ');
+            if (sb.length() != 0) {
+                sb.append(' ');
             }
 
-            out.print(JSType.toString(object));
+            sb.append(JSType.toString(object));
         }
 
+        // Print all at once to ensure thread friendly result.
         if (newLine) {
-            out.println();
+            out.println(sb.toString());
+        } else {
+            out.print(sb.toString());
         }
 
         out.flush();
--- a/src/jdk/nashorn/internal/objects/NativeArguments.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/objects/NativeArguments.java	Mon Jun 10 09:53:21 2013 +0100
@@ -603,6 +603,11 @@
         }
     }
 
+    @Override
+    public Object getLength() {
+        return length;
+    }
+
     private Object getArgumentsLength() {
         return length;
     }
--- a/src/jdk/nashorn/internal/objects/NativeArray.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/objects/NativeArray.java	Mon Jun 10 09:53:21 2013 +0100
@@ -75,7 +75,7 @@
     private static final MethodHandle FILTER_CALLBACK_INVOKER  = createIteratorCallbackInvoker(boolean.class);
 
     private static final MethodHandle REDUCE_CALLBACK_INVOKER = Bootstrap.createDynamicInvoker("dyn:call", Object.class,
-            Object.class, Undefined.class, Object.class, Object.class, int.class, Object.class);
+            Object.class, Undefined.class, Object.class, Object.class, long.class, Object.class);
     private static final MethodHandle CALL_CMP                = Bootstrap.createDynamicInvoker("dyn:call", double.class,
             ScriptFunction.class, Object.class, Object.class, Object.class);
 
@@ -754,25 +754,11 @@
         final Object       obj                 = Global.toObject(self);
         final ScriptObject sobj                = (ScriptObject)obj;
         final long         len                 = JSType.toUint32(sobj.getLength());
-        final double       startNum            = JSType.toNumber(start);
-        final long         relativeStartUint32 = JSType.toUint32(startNum);
-        final long         relativeStart       = JSType.toInteger(startNum);
+        final long         relativeStart       = JSType.toLong(start);
+        final long         relativeEnd         = (end == ScriptRuntime.UNDEFINED) ? len : JSType.toLong(end);
 
-        long k = relativeStart < 0 ?
-                Math.max(len + relativeStart, 0) :
-                Math.min(
-                    Math.max(relativeStartUint32, relativeStart),
-                    len);
-
-        final double endNum = (end == ScriptRuntime.UNDEFINED)? Double.NaN : JSType.toNumber(end);
-        final long relativeEndUint32 = (end == ScriptRuntime.UNDEFINED)? len : JSType.toUint32(endNum);
-        final long relativeEnd       = (end == ScriptRuntime.UNDEFINED)? len : JSType.toInteger(endNum);
-
-        final long finale = relativeEnd < 0 ?
-                Math.max(len + relativeEnd, 0) :
-                Math.min(
-                    Math.max(relativeEndUint32, relativeEnd),
-                    len);
+        long k = relativeStart < 0 ? Math.max(len + relativeStart, 0) : Math.min(relativeStart, len);
+        final long finale = relativeEnd < 0 ? Math.max(len + relativeEnd, 0) : Math.min(relativeEnd, len);
 
         if (k >= finale) {
             return new NativeArray(0);
@@ -909,21 +895,10 @@
         final ScriptObject sobj                = (ScriptObject)obj;
         final boolean      strict              = Global.isStrict();
         final long         len                 = JSType.toUint32(sobj.getLength());
-        final double       startNum            = JSType.toNumber(start);
-        final long         relativeStartUint32 = JSType.toUint32(startNum);
-        final long         relativeStart       = JSType.toInteger(startNum);
+        final long         relativeStart       = JSType.toLong(start);
 
-        //TODO: workaround overflow of relativeStart for start > Integer.MAX_VALUE
-        final long actualStart = relativeStart < 0 ?
-            Math.max(len + relativeStart, 0) :
-            Math.min(
-                Math.max(relativeStartUint32, relativeStart),
-                len);
-
-        final long actualDeleteCount =
-            Math.min(
-                Math.max(JSType.toInteger(deleteCount), 0),
-                len - actualStart);
+        final long actualStart = relativeStart < 0 ? Math.max(len + relativeStart, 0) : Math.min(relativeStart, len);
+        final long actualDeleteCount = Math.min(Math.max(JSType.toLong(deleteCount), 0), len - actualStart);
 
         final NativeArray array = new NativeArray(actualDeleteCount);
 
@@ -1111,7 +1086,7 @@
     private static boolean applyEvery(final Object self, final Object callbackfn, final Object thisArg) {
         return new IteratorAction<Boolean>(Global.toObject(self), callbackfn, thisArg, true) {
             @Override
-            protected boolean forEach(final Object val, final int i) throws Throwable {
+            protected boolean forEach(final Object val, final long i) throws Throwable {
                 return (result = (boolean)EVERY_CALLBACK_INVOKER.invokeExact(callbackfn, thisArg, val, i, self));
             }
         }.apply();
@@ -1129,7 +1104,7 @@
     public static Object some(final Object self, final Object callbackfn, final Object thisArg) {
         return new IteratorAction<Boolean>(Global.toObject(self), callbackfn, thisArg, false) {
             @Override
-            protected boolean forEach(final Object val, final int i) throws Throwable {
+            protected boolean forEach(final Object val, final long i) throws Throwable {
                 return !(result = (boolean)SOME_CALLBACK_INVOKER.invokeExact(callbackfn, thisArg, val, i, self));
             }
         }.apply();
@@ -1147,7 +1122,7 @@
     public static Object forEach(final Object self, final Object callbackfn, final Object thisArg) {
         return new IteratorAction<Object>(Global.toObject(self), callbackfn, thisArg, ScriptRuntime.UNDEFINED) {
             @Override
-            protected boolean forEach(final Object val, final int i) throws Throwable {
+            protected boolean forEach(final Object val, final long i) throws Throwable {
                 FOREACH_CALLBACK_INVOKER.invokeExact(callbackfn, thisArg, val, i, self);
                 return true;
             }
@@ -1166,9 +1141,9 @@
     public static Object map(final Object self, final Object callbackfn, final Object thisArg) {
         return new IteratorAction<NativeArray>(Global.toObject(self), callbackfn, thisArg, null) {
             @Override
-            protected boolean forEach(final Object val, final int i) throws Throwable {
+            protected boolean forEach(final Object val, final long i) throws Throwable {
                 final Object r = MAP_CALLBACK_INVOKER.invokeExact(callbackfn, thisArg, val, i, self);
-                result.defineOwnProperty(index, r);
+                result.defineOwnProperty((int)index, r);
                 return true;
             }
 
@@ -1192,12 +1167,12 @@
     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
     public static Object filter(final Object self, final Object callbackfn, final Object thisArg) {
         return new IteratorAction<NativeArray>(Global.toObject(self), callbackfn, thisArg, new NativeArray()) {
-            private int to = 0;
+            private long to = 0;
 
             @Override
-            protected boolean forEach(final Object val, final int i) throws Throwable {
+            protected boolean forEach(final Object val, final long i) throws Throwable {
                 if ((boolean)FILTER_CALLBACK_INVOKER.invokeExact(callbackfn, thisArg, val, i, self)) {
-                    result.defineOwnProperty(to++, val);
+                    result.defineOwnProperty((int)(to++), val);
                 }
                 return true;
             }
@@ -1225,7 +1200,7 @@
         //if initial value is ScriptRuntime.UNDEFINED - step forward once.
         return new IteratorAction<Object>(Global.toObject(self), callbackfn, ScriptRuntime.UNDEFINED, initialValue, iter) {
             @Override
-            protected boolean forEach(final Object val, final int i) throws Throwable {
+            protected boolean forEach(final Object val, final long i) throws Throwable {
                 // TODO: why can't I declare the second arg as Undefined.class?
                 result = REDUCE_CALLBACK_INVOKER.invokeExact(callbackfn, ScriptRuntime.UNDEFINED, result, val, i, self);
                 return true;
@@ -1283,7 +1258,7 @@
 
     private static MethodHandle createIteratorCallbackInvoker(final Class<?> rtype) {
         return Bootstrap.createDynamicInvoker("dyn:call", rtype, Object.class, Object.class, Object.class,
-                int.class, Object.class);
+                long.class, Object.class);
 
     }
 }
--- a/src/jdk/nashorn/internal/objects/NativeDate.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/objects/NativeDate.java	Mon Jun 10 09:53:21 2013 +0100
@@ -39,6 +39,7 @@
 import jdk.nashorn.internal.objects.annotations.ScriptClass;
 import jdk.nashorn.internal.objects.annotations.SpecializedConstructor;
 import jdk.nashorn.internal.objects.annotations.Where;
+import jdk.nashorn.internal.parser.DateParser;
 import jdk.nashorn.internal.runtime.ConsString;
 import jdk.nashorn.internal.runtime.JSType;
 import jdk.nashorn.internal.runtime.ScriptEnvironment;
@@ -770,7 +771,7 @@
             nd.setTime(NaN);
             return nd.getTime();
         }
-        int yearInt = JSType.toInteger(yearNum);
+        int yearInt = (int)yearNum;
         if (0 <= yearInt && yearInt <= 99) {
             yearInt += 1900;
         }
--- a/src/jdk/nashorn/internal/objects/NativeError.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/objects/NativeError.java	Mon Jun 10 09:53:21 2013 +0100
@@ -32,6 +32,7 @@
 import java.lang.invoke.MethodHandles;
 import java.util.ArrayList;
 import java.util.List;
+import jdk.nashorn.internal.codegen.CompilerConstants;
 import jdk.nashorn.internal.objects.annotations.Attribute;
 import jdk.nashorn.internal.objects.annotations.Constructor;
 import jdk.nashorn.internal.objects.annotations.Function;
@@ -248,7 +249,13 @@
             final List<StackTraceElement> filtered = new ArrayList<>();
             for (final StackTraceElement st : frames) {
                 if (ECMAErrors.isScriptFrame(st)) {
-                    filtered.add(st);
+                    final String className = "<" + st.getFileName() + ">";
+                    String methodName = st.getMethodName();
+                    if (methodName.equals(CompilerConstants.RUN_SCRIPT.symbolName())) {
+                        methodName = "<program>";
+                    }
+                    filtered.add(new StackTraceElement(className, methodName,
+                            st.getFileName(), st.getLineNumber()));
                 }
             }
             res = filtered.toArray();
--- a/src/jdk/nashorn/internal/objects/NativeFloat32Array.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/objects/NativeFloat32Array.java	Mon Jun 10 09:53:21 2013 +0100
@@ -28,7 +28,9 @@
 import jdk.nashorn.internal.objects.annotations.Attribute;
 import jdk.nashorn.internal.objects.annotations.Constructor;
 import jdk.nashorn.internal.objects.annotations.Function;
+import jdk.nashorn.internal.objects.annotations.Property;
 import jdk.nashorn.internal.objects.annotations.ScriptClass;
+import jdk.nashorn.internal.objects.annotations.Where;
 import jdk.nashorn.internal.runtime.JSType;
 import jdk.nashorn.internal.runtime.ScriptObject;
 import jdk.nashorn.internal.runtime.arrays.ArrayData;
@@ -38,7 +40,12 @@
  */
 @ScriptClass("Float32Array")
 public final class NativeFloat32Array extends ArrayBufferView {
-    private static final int BYTES_PER_ELEMENT = 4;
+    /**
+     * The size in bytes of each element in the array.
+     */
+    @Property(attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_WRITABLE | Attribute.NOT_CONFIGURABLE, where = Where.CONSTRUCTOR)
+    public static final int BYTES_PER_ELEMENT = 4;
+
     private static final Factory FACTORY = new Factory(BYTES_PER_ELEMENT) {
         @Override
         public ArrayBufferView construct(final NativeArrayBuffer buffer, final int byteOffset, final int length) {
--- a/src/jdk/nashorn/internal/objects/NativeFloat64Array.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/objects/NativeFloat64Array.java	Mon Jun 10 09:53:21 2013 +0100
@@ -28,7 +28,9 @@
 import jdk.nashorn.internal.objects.annotations.Attribute;
 import jdk.nashorn.internal.objects.annotations.Constructor;
 import jdk.nashorn.internal.objects.annotations.Function;
+import jdk.nashorn.internal.objects.annotations.Property;
 import jdk.nashorn.internal.objects.annotations.ScriptClass;
+import jdk.nashorn.internal.objects.annotations.Where;
 import jdk.nashorn.internal.runtime.JSType;
 import jdk.nashorn.internal.runtime.ScriptObject;
 import jdk.nashorn.internal.runtime.arrays.ArrayData;
@@ -38,7 +40,12 @@
  */
 @ScriptClass("Float64Array")
 public final class NativeFloat64Array extends ArrayBufferView {
-    private static final int BYTES_PER_ELEMENT = 8;
+    /**
+     * The size in bytes of each element in the array.
+     */
+    @Property(attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_WRITABLE | Attribute.NOT_CONFIGURABLE, where = Where.CONSTRUCTOR)
+    public static final int BYTES_PER_ELEMENT = 8;
+
     private static final Factory FACTORY = new Factory(BYTES_PER_ELEMENT) {
         @Override
         public ArrayBufferView construct(final NativeArrayBuffer buffer, final int byteOffset, final int length) {
--- a/src/jdk/nashorn/internal/objects/NativeFunction.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/objects/NativeFunction.java	Mon Jun 10 09:53:21 2013 +0100
@@ -33,10 +33,14 @@
 import jdk.nashorn.internal.objects.annotations.Constructor;
 import jdk.nashorn.internal.objects.annotations.Function;
 import jdk.nashorn.internal.objects.annotations.ScriptClass;
+import jdk.nashorn.internal.parser.Parser;
+import jdk.nashorn.internal.runtime.Context;
 import jdk.nashorn.internal.runtime.JSType;
+import jdk.nashorn.internal.runtime.ParserException;
 import jdk.nashorn.internal.runtime.ScriptFunction;
 import jdk.nashorn.internal.runtime.ScriptObject;
 import jdk.nashorn.internal.runtime.ScriptRuntime;
+import jdk.nashorn.internal.runtime.Source;
 
 /**
  * ECMA 15.3 Function Objects
@@ -187,16 +191,25 @@
 
         sb.append("(function (");
         if (args.length > 0) {
+            final StringBuilder paramListBuf = new StringBuilder();
             for (int i = 0; i < args.length - 1; i++) {
-                sb.append(JSType.toString(args[i]));
+                paramListBuf.append(JSType.toString(args[i]));
                 if (i < args.length - 2) {
-                    sb.append(",");
+                    paramListBuf.append(",");
                 }
             }
+
+            final String paramList = paramListBuf.toString();
+            if (! paramList.isEmpty()) {
+                checkFunctionParameters(paramList);
+                sb.append(paramList);
+            }
         }
         sb.append(") {\n");
         if (args.length > 0) {
-            sb.append(JSType.toString(args[args.length - 1]));
+            final String funcBody = JSType.toString(args[args.length - 1]);
+            checkFunctionBody(funcBody);
+            sb.append(funcBody);
             sb.append('\n');
         }
         sb.append("})");
@@ -205,4 +218,24 @@
 
         return Global.directEval(global, sb.toString(), global, "<function>", Global.isStrict());
     }
+
+    private static void checkFunctionParameters(final String params) {
+        final Source src = new Source("<function>", params);
+        final Parser parser = new Parser(Global.getEnv(), src, new Context.ThrowErrorManager());
+        try {
+            parser.parseFormalParameterList();
+        } catch (final ParserException pe) {
+            pe.throwAsEcmaException();
+        }
+    }
+
+    private static void checkFunctionBody(final String funcBody) {
+        final Source src = new Source("<function>", funcBody);
+        final Parser parser = new Parser(Global.getEnv(), src, new Context.ThrowErrorManager());
+        try {
+            parser.parseFunctionBody();
+        } catch (final ParserException pe) {
+            pe.throwAsEcmaException();
+        }
+    }
 }
--- a/src/jdk/nashorn/internal/objects/NativeInt16Array.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/objects/NativeInt16Array.java	Mon Jun 10 09:53:21 2013 +0100
@@ -28,7 +28,9 @@
 import jdk.nashorn.internal.objects.annotations.Attribute;
 import jdk.nashorn.internal.objects.annotations.Constructor;
 import jdk.nashorn.internal.objects.annotations.Function;
+import jdk.nashorn.internal.objects.annotations.Property;
 import jdk.nashorn.internal.objects.annotations.ScriptClass;
+import jdk.nashorn.internal.objects.annotations.Where;
 import jdk.nashorn.internal.runtime.ScriptObject;
 import jdk.nashorn.internal.runtime.arrays.ArrayData;
 
@@ -37,7 +39,12 @@
  */
 @ScriptClass("Int16Array")
 public final class NativeInt16Array extends ArrayBufferView {
-    private static final int BYTES_PER_ELEMENT = 2;
+    /**
+     * The size in bytes of each element in the array.
+     */
+    @Property(attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_WRITABLE | Attribute.NOT_CONFIGURABLE, where = Where.CONSTRUCTOR)
+    public static final int BYTES_PER_ELEMENT = 2;
+
     private static final Factory FACTORY = new Factory(BYTES_PER_ELEMENT) {
         @Override
         public ArrayBufferView construct(final NativeArrayBuffer buffer, final int byteOffset, final int length) {
--- a/src/jdk/nashorn/internal/objects/NativeInt32Array.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/objects/NativeInt32Array.java	Mon Jun 10 09:53:21 2013 +0100
@@ -28,7 +28,9 @@
 import jdk.nashorn.internal.objects.annotations.Attribute;
 import jdk.nashorn.internal.objects.annotations.Constructor;
 import jdk.nashorn.internal.objects.annotations.Function;
+import jdk.nashorn.internal.objects.annotations.Property;
 import jdk.nashorn.internal.objects.annotations.ScriptClass;
+import jdk.nashorn.internal.objects.annotations.Where;
 import jdk.nashorn.internal.runtime.ScriptObject;
 import jdk.nashorn.internal.runtime.arrays.ArrayData;
 
@@ -37,7 +39,12 @@
  */
 @ScriptClass("Int32Array")
 public final class NativeInt32Array extends ArrayBufferView {
-    private static final int BYTES_PER_ELEMENT = 4;
+    /**
+     * The size in bytes of each element in the array.
+     */
+    @Property(attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_WRITABLE | Attribute.NOT_CONFIGURABLE, where = Where.CONSTRUCTOR)
+    public static final int BYTES_PER_ELEMENT = 4;
+
     private static final Factory FACTORY = new Factory(BYTES_PER_ELEMENT) {
         @Override
         public ArrayBufferView construct(final NativeArrayBuffer buffer, final int byteOffset, final int length) {
--- a/src/jdk/nashorn/internal/objects/NativeInt8Array.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/objects/NativeInt8Array.java	Mon Jun 10 09:53:21 2013 +0100
@@ -28,7 +28,9 @@
 import jdk.nashorn.internal.objects.annotations.Attribute;
 import jdk.nashorn.internal.objects.annotations.Constructor;
 import jdk.nashorn.internal.objects.annotations.Function;
+import jdk.nashorn.internal.objects.annotations.Property;
 import jdk.nashorn.internal.objects.annotations.ScriptClass;
+import jdk.nashorn.internal.objects.annotations.Where;
 import jdk.nashorn.internal.runtime.ScriptObject;
 import jdk.nashorn.internal.runtime.arrays.ArrayData;
 
@@ -37,7 +39,12 @@
  */
 @ScriptClass("Int8Array")
 public final class NativeInt8Array extends ArrayBufferView {
-    private static final int BYTES_PER_ELEMENT = 1;
+    /**
+     * The size in bytes of each element in the array.
+     */
+    @Property(attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_WRITABLE | Attribute.NOT_CONFIGURABLE, where = Where.CONSTRUCTOR)
+    public static final int BYTES_PER_ELEMENT = 1;
+
     private static final Factory FACTORY = new Factory(BYTES_PER_ELEMENT) {
         @Override
         public ArrayBufferView construct(final NativeArrayBuffer buffer, final int byteOffset, final int length) {
--- a/src/jdk/nashorn/internal/objects/NativeJava.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/objects/NativeJava.java	Mon Jun 10 09:53:21 2013 +0100
@@ -30,6 +30,8 @@
 
 import java.lang.reflect.Array;
 import java.util.Collection;
+import java.util.Deque;
+import java.util.List;
 import jdk.internal.dynalink.beans.StaticClass;
 import jdk.internal.dynalink.support.TypeUtilities;
 import jdk.nashorn.internal.objects.annotations.Attribute;
@@ -37,6 +39,7 @@
 import jdk.nashorn.internal.objects.annotations.ScriptClass;
 import jdk.nashorn.internal.objects.annotations.Where;
 import jdk.nashorn.internal.runtime.JSType;
+import jdk.nashorn.internal.runtime.ListAdapter;
 import jdk.nashorn.internal.runtime.ScriptObject;
 import jdk.nashorn.internal.runtime.linker.JavaAdapterFactory;
 
@@ -240,39 +243,56 @@
     }
 
     /**
-     * Given a JavaScript array and a Java type, returns a Java array with the same initial contents, and with the
-     * specified component type. Example:
+     * Given a script object and a Java type, converts the script object into the desired Java type. Currently it
+     * performs shallow creation of Java arrays, as well as wrapping of objects in Lists and Dequeues. Example:
      * <pre>
      * var anArray = [1, "13", false]
-     * var javaIntArray = Java.toJavaArray(anArray, "int")
+     * var javaIntArray = Java.to(anArray, "int[]")
      * print(javaIntArray[0]) // prints 1
      * print(javaIntArray[1]) // prints 13, as string "13" was converted to number 13 as per ECMAScript ToNumber conversion
      * print(javaIntArray[2]) // prints 0, as boolean false was converted to number 0 as per ECMAScript ToNumber conversion
      * </pre>
      * @param self not used
-     * @param objArray the JavaScript array. Can be null.
-     * @param objType either a {@link #type(Object, Object) type object} or a String describing the component type of
-     * the Java array to create. Can not be null. If undefined, Object is assumed (allowing the argument to be omitted).
-     * @return a Java array with the copy of JavaScript array's contents, converted to the appropriate Java component
-     * type. Returns null if objArray is null.
+     * @param obj the script object. Can be null.
+     * @param objType either a {@link #type(Object, Object) type object} or a String describing the type of the Java
+     * object to create. Can not be null. If undefined, a "default" conversion is presumed (allowing the argument to be
+     * omitted).
+     * @return a Java object whose value corresponds to the original script object's value. Specifically, for array
+     * target types, returns a Java array of the same type with contents converted to the array's component type. Does
+     * not recursively convert for multidimensional arrays. For {@link List} or {@link Deque}, returns a live wrapper
+     * around the object, see {@link ListAdapter} for details. Returns null if obj is null.
      * @throws ClassNotFoundException if the class described by objType is not found
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
-    public static Object toJavaArray(final Object self, final Object objArray, final Object objType) throws ClassNotFoundException {
-        final StaticClass componentType =
-            objType instanceof StaticClass ?
-                (StaticClass)objType :
-                objType == UNDEFINED ?
-                    StaticClass.forClass(Object.class) :
-                    type(objType);
-
-        if (objArray == null) {
+    public static Object to(final Object self, final Object obj, final Object objType) throws ClassNotFoundException {
+        if (obj == null) {
             return null;
         }
 
-        Global.checkObject(objArray);
+        Global.checkObject(obj);
 
-        return ((ScriptObject)objArray).getArray().asArrayOfType(componentType.getRepresentedClass());
+        final Class<?> targetClass;
+        if(objType == UNDEFINED) {
+            targetClass = Object[].class;
+        } else {
+            final StaticClass targetType;
+            if(objType instanceof StaticClass) {
+                targetType = (StaticClass)objType;
+            } else {
+                targetType = type(objType);
+            }
+            targetClass = targetType.getRepresentedClass();
+        }
+
+        if(targetClass.isArray()) {
+            return ((ScriptObject)obj).getArray().asArrayOfType(targetClass.getComponentType());
+        }
+
+        if(targetClass == List.class || targetClass == Deque.class) {
+            return new ListAdapter((ScriptObject)obj);
+        }
+
+        throw typeError("unsupported.java.to.type", targetClass.getName());
     }
 
     /**
@@ -283,7 +303,7 @@
      * <pre>
      * var File = Java.type("java.io.File")
      * var listHomeDir = new File("~").listFiles()
-     * var jsListHome = Java.toJavaScriptArray(listHomeDir)
+     * var jsListHome = Java.from(listHomeDir)
      * var jpegModifiedDates = jsListHome
      *     .filter(function(val) { return val.getName().endsWith(".jpg") })
      *     .map(function(val) { return val.lastModified() })
@@ -294,7 +314,7 @@
      * null.
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
-    public static Object toJavaScriptArray(final Object self, final Object objArray) {
+    public static Object from(final Object self, final Object objArray) {
         if (objArray == null) {
             return null;
         } else if (objArray instanceof Collection) {
--- a/src/jdk/nashorn/internal/objects/NativeMath.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/objects/NativeMath.java	Mon Jun 10 09:53:21 2013 +0100
@@ -31,7 +31,6 @@
 import jdk.nashorn.internal.objects.annotations.ScriptClass;
 import jdk.nashorn.internal.objects.annotations.SpecializedFunction;
 import jdk.nashorn.internal.objects.annotations.Where;
-import jdk.nashorn.internal.runtime.GlobalFunctions;
 import jdk.nashorn.internal.runtime.JSType;
 import jdk.nashorn.internal.runtime.ScriptObject;
 
@@ -611,13 +610,11 @@
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
     public static Object round(final Object self, final Object x) {
-        if (GlobalFunctions.isNaN(self, x)) {
-            return Double.NaN;
-        } else if (!GlobalFunctions.isFinite(self, x)) {
-            return x;
+        final double d = JSType.toNumber(x);
+        if (Math.getExponent(d) >= 52) {
+            return d;
         }
-
-        return Math.round(JSType.toNumber(x));
+        return Math.copySign(Math.floor(d + 0.5), d);
     }
 
     /**
--- a/src/jdk/nashorn/internal/objects/NativeString.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/objects/NativeString.java	Mon Jun 10 09:53:21 2013 +0100
@@ -38,6 +38,7 @@
 import java.util.Arrays;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Locale;
 import jdk.internal.dynalink.CallSiteDescriptor;
 import jdk.internal.dynalink.linker.GuardedInvocation;
 import jdk.internal.dynalink.linker.LinkRequest;
@@ -630,17 +631,24 @@
 
         final String str       = checkObjectToString(self);
         final String searchStr = JSType.toString(search);
+        final int length       = str.length();
 
-        int from;
+        int end;
 
         if (pos == UNDEFINED) {
-            from = str.length();
+            end = length;
         } else {
             final double numPos = JSType.toNumber(pos);
-            from = !Double.isNaN(numPos) ? (int)numPos : (int)Double.POSITIVE_INFINITY;
+            end = Double.isNaN(numPos) ? length : (int)numPos;
+            if (end < 0) {
+                end = 0;
+            } else if (end > length) {
+                end = length;
+            }
         }
 
-        return str.lastIndexOf(searchStr, from);
+
+        return str.lastIndexOf(searchStr, end);
     }
 
     /**
@@ -997,7 +1005,7 @@
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
     public static Object toLowerCase(final Object self) {
-        return checkObjectToString(self).toLowerCase();
+        return checkObjectToString(self).toLowerCase(Locale.ROOT);
     }
 
     /**
@@ -1017,7 +1025,7 @@
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
     public static Object toUpperCase(final Object self) {
-        return checkObjectToString(self).toUpperCase();
+        return checkObjectToString(self).toUpperCase(Locale.ROOT);
     }
 
     /**
--- a/src/jdk/nashorn/internal/objects/NativeUint16Array.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/objects/NativeUint16Array.java	Mon Jun 10 09:53:21 2013 +0100
@@ -28,7 +28,9 @@
 import jdk.nashorn.internal.objects.annotations.Attribute;
 import jdk.nashorn.internal.objects.annotations.Constructor;
 import jdk.nashorn.internal.objects.annotations.Function;
+import jdk.nashorn.internal.objects.annotations.Property;
 import jdk.nashorn.internal.objects.annotations.ScriptClass;
+import jdk.nashorn.internal.objects.annotations.Where;
 import jdk.nashorn.internal.runtime.ScriptObject;
 import jdk.nashorn.internal.runtime.arrays.ArrayData;
 
@@ -37,7 +39,12 @@
  */
 @ScriptClass("Uint16Array")
 public final class NativeUint16Array extends ArrayBufferView {
-    private static final int BYTES_PER_ELEMENT = 2;
+    /**
+     * The size in bytes of each element in the array.
+     */
+    @Property(attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_WRITABLE | Attribute.NOT_CONFIGURABLE, where = Where.CONSTRUCTOR)
+    public static final int BYTES_PER_ELEMENT = 2;
+
     private static final Factory FACTORY = new Factory(BYTES_PER_ELEMENT) {
         @Override
         public ArrayBufferView construct(final NativeArrayBuffer buffer, final int byteOffset, final int length) {
--- a/src/jdk/nashorn/internal/objects/NativeUint32Array.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/objects/NativeUint32Array.java	Mon Jun 10 09:53:21 2013 +0100
@@ -28,7 +28,9 @@
 import jdk.nashorn.internal.objects.annotations.Attribute;
 import jdk.nashorn.internal.objects.annotations.Constructor;
 import jdk.nashorn.internal.objects.annotations.Function;
+import jdk.nashorn.internal.objects.annotations.Property;
 import jdk.nashorn.internal.objects.annotations.ScriptClass;
+import jdk.nashorn.internal.objects.annotations.Where;
 import jdk.nashorn.internal.runtime.JSType;
 import jdk.nashorn.internal.runtime.ScriptObject;
 import jdk.nashorn.internal.runtime.arrays.ArrayData;
@@ -38,7 +40,12 @@
  */
 @ScriptClass("Uint32Array")
 public final class NativeUint32Array extends ArrayBufferView {
-    private static final int BYTES_PER_ELEMENT = 4;
+    /**
+     * The size in bytes of each element in the array.
+     */
+    @Property(attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_WRITABLE | Attribute.NOT_CONFIGURABLE, where = Where.CONSTRUCTOR)
+    public static final int BYTES_PER_ELEMENT = 4;
+
     private static final Factory FACTORY = new Factory(BYTES_PER_ELEMENT) {
         @Override
         public ArrayBufferView construct(final NativeArrayBuffer buffer, final int byteBegin, final int length) {
--- a/src/jdk/nashorn/internal/objects/NativeUint8Array.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/objects/NativeUint8Array.java	Mon Jun 10 09:53:21 2013 +0100
@@ -28,7 +28,9 @@
 import jdk.nashorn.internal.objects.annotations.Attribute;
 import jdk.nashorn.internal.objects.annotations.Constructor;
 import jdk.nashorn.internal.objects.annotations.Function;
+import jdk.nashorn.internal.objects.annotations.Property;
 import jdk.nashorn.internal.objects.annotations.ScriptClass;
+import jdk.nashorn.internal.objects.annotations.Where;
 import jdk.nashorn.internal.runtime.ScriptObject;
 import jdk.nashorn.internal.runtime.arrays.ArrayData;
 
@@ -37,7 +39,12 @@
  */
 @ScriptClass("Uint8Array")
 public final class NativeUint8Array extends ArrayBufferView {
-    private static final int BYTES_PER_ELEMENT = 1;
+    /**
+     * The size in bytes of each element in the array.
+     */
+    @Property(attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_WRITABLE | Attribute.NOT_CONFIGURABLE, where = Where.CONSTRUCTOR)
+    public static final int BYTES_PER_ELEMENT = 1;
+
     private static final Factory FACTORY = new Factory(BYTES_PER_ELEMENT) {
         @Override
         public ArrayBufferView construct(final NativeArrayBuffer buffer, final int byteOffset, final int length) {
--- a/src/jdk/nashorn/internal/objects/NativeUint8ClampedArray.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/objects/NativeUint8ClampedArray.java	Mon Jun 10 09:53:21 2013 +0100
@@ -28,7 +28,9 @@
 import jdk.nashorn.internal.objects.annotations.Attribute;
 import jdk.nashorn.internal.objects.annotations.Constructor;
 import jdk.nashorn.internal.objects.annotations.Function;
+import jdk.nashorn.internal.objects.annotations.Property;
 import jdk.nashorn.internal.objects.annotations.ScriptClass;
+import jdk.nashorn.internal.objects.annotations.Where;
 import jdk.nashorn.internal.runtime.JSType;
 import jdk.nashorn.internal.runtime.ScriptObject;
 import jdk.nashorn.internal.runtime.arrays.ArrayData;
@@ -38,7 +40,12 @@
  */
 @ScriptClass("Uint8ClampedArray")
 public final class NativeUint8ClampedArray extends ArrayBufferView {
-    private static final int BYTES_PER_ELEMENT = 1;
+    /**
+     * The size in bytes of each element in the array.
+     */
+    @Property(attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_WRITABLE | Attribute.NOT_CONFIGURABLE, where = Where.CONSTRUCTOR)
+    public static final int BYTES_PER_ELEMENT = 1;
+
     private static final Factory FACTORY = new Factory(BYTES_PER_ELEMENT) {
         @Override
         public ArrayBufferView construct(final NativeArrayBuffer buffer, final int byteOffset, final int length) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jdk/nashorn/internal/parser/DateParser.java	Mon Jun 10 09:53:21 2013 +0100
@@ -0,0 +1,716 @@
+/*
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.nashorn.internal.parser;
+
+import static java.lang.Character.DECIMAL_DIGIT_NUMBER;
+import static java.lang.Character.LOWERCASE_LETTER;
+import static java.lang.Character.OTHER_PUNCTUATION;
+import static java.lang.Character.SPACE_SEPARATOR;
+import static java.lang.Character.UPPERCASE_LETTER;
+
+import java.util.HashMap;
+import java.util.Locale;
+
+/**
+ * JavaScript date parser. This class first tries to parse a date string
+ * according to the extended ISO 8601 format specified in ES5 15.9.1.15.
+ * If that fails, it falls back to legacy mode in which it accepts a range
+ * of different formats.
+ *
+ * <p>This class is neither thread-safe nor reusable. Calling the
+ * <tt>parse()</tt> method more than once will yield undefined results.</p>
+ */
+public class DateParser {
+
+    /** Constant for index position of parsed year value. */
+    public final static int YEAR        = 0;
+    /** Constant for index position of parsed month value. */
+    public final static int MONTH       = 1;
+    /** Constant for index position of parsed day value. */
+    public final static int DAY         = 2;
+    /** Constant for index position of parsed hour value. */
+    public final static int HOUR        = 3;
+    /** Constant for index position of parsed minute value. */
+    public final static int MINUTE      = 4;
+    /** Constant for index position of parsed second value. */
+    public final static int SECOND      = 5;
+    /** Constant for index position of parsed millisecond value. */
+    public final static int MILLISECOND = 6;
+    /** Constant for index position of parsed time zone offset value. */
+    public final static int TIMEZONE    = 7;
+
+    private enum Token {
+        UNKNOWN, NUMBER, SEPARATOR, PARENTHESIS, NAME, SIGN, END
+    }
+
+    private final String string;
+    private final int length;
+    private final Integer[] fields;
+    private int pos = 0;
+    private Token token;
+    private int tokenLength;
+    private Name nameValue;
+    private int numValue;
+    private int currentField = YEAR;
+    private int yearSign = 0;
+    private boolean namedMonth = false;
+
+    private final static HashMap<String,Name> names = new HashMap<>();
+
+    static {
+        addName("monday", Name.DAY_OF_WEEK, 0);
+        addName("tuesday", Name.DAY_OF_WEEK, 0);
+        addName("wednesday", Name.DAY_OF_WEEK, 0);
+        addName("thursday", Name.DAY_OF_WEEK, 0);
+        addName("friday", Name.DAY_OF_WEEK, 0);
+        addName("saturday", Name.DAY_OF_WEEK, 0);
+        addName("sunday", Name.DAY_OF_WEEK, 0);
+        addName("january", Name.MONTH_NAME, 1);
+        addName("february", Name.MONTH_NAME, 2);
+        addName("march", Name.MONTH_NAME, 3);
+        addName("april", Name.MONTH_NAME, 4);
+        addName("may", Name.MONTH_NAME, 5);
+        addName("june", Name.MONTH_NAME, 6);
+        addName("july", Name.MONTH_NAME, 7);
+        addName("august", Name.MONTH_NAME, 8);
+        addName("september", Name.MONTH_NAME, 9);
+        addName("october", Name.MONTH_NAME, 10);
+        addName("november", Name.MONTH_NAME, 11);
+        addName("december", Name.MONTH_NAME, 12);
+        addName("am", Name.AM_PM, 0);
+        addName("pm", Name.AM_PM, 12);
+        addName("z", Name.TIMEZONE_ID, 0);
+        addName("gmt", Name.TIMEZONE_ID, 0);
+        addName("ut", Name.TIMEZONE_ID, 0);
+        addName("utc", Name.TIMEZONE_ID, 0);
+        addName("est", Name.TIMEZONE_ID, -5 * 60);
+        addName("edt", Name.TIMEZONE_ID, -4 * 60);
+        addName("cst", Name.TIMEZONE_ID, -6 * 60);
+        addName("cdt", Name.TIMEZONE_ID, -5 * 60);
+        addName("mst", Name.TIMEZONE_ID, -7 * 60);
+        addName("mdt", Name.TIMEZONE_ID, -6 * 60);
+        addName("pst", Name.TIMEZONE_ID, -8 * 60);
+        addName("pdt", Name.TIMEZONE_ID, -7 * 60);
+        addName("t", Name.TIME_SEPARATOR, 0);
+    }
+
+    /**
+     * Construct a new <tt>DateParser</tt> instance for parsing the given string.
+     * @param string the string to be parsed
+     */
+    public DateParser(final String string) {
+        this.string = string;
+        this.length = string.length();
+        this.fields = new Integer[TIMEZONE + 1];
+    }
+
+    /**
+     * Try parsing the given string as date according to the extended ISO 8601 format
+     * specified in ES5 15.9.1.15. Fall back to legacy mode if that fails.
+     * This method returns <tt>true</tt> if the string could be parsed.
+     * @return true if the string could be parsed as date
+     */
+    public boolean parse() {
+        return parseEcmaDate() || parseLegacyDate();
+    }
+
+    /**
+     * Try parsing the date string according to the rules laid out in ES5 15.9.1.15.
+     * The date string must conform to the following format:
+     *
+     * <pre>  [('-'|'+')yy]yyyy[-MM[-dd]][hh:mm[:ss[.sss]][Z|(+|-)hh:mm]] </pre>
+     *
+     * <p>If the string does not contain a time zone offset, the <tt>TIMEZONE</tt> field
+     * is set to <tt>0</tt> (GMT).</p>
+     * @return true if string represents a valid ES5 date string.
+     */
+    public boolean parseEcmaDate() {
+
+        if (token == null) {
+            token = next();
+        }
+
+        while (token != Token.END) {
+
+            switch (token) {
+                case NUMBER:
+                    if (currentField == YEAR && yearSign != 0) {
+                        // 15.9.1.15.1 Extended year must have six digits
+                        if (tokenLength != 6) {
+                            return false;
+                        }
+                        numValue *= yearSign;
+                    } else if (!checkEcmaField(currentField, numValue)) {
+                        return false;
+                    }
+                    if (!skipEcmaDelimiter()) {
+                        return false;
+                    }
+                    if (currentField < TIMEZONE) {
+                        set(currentField++, numValue);
+                    }
+                    break;
+
+                case NAME:
+                    if (nameValue == null) {
+                        return false;
+                    }
+                    switch (nameValue.type) {
+                        case Name.TIME_SEPARATOR:
+                            if (currentField == YEAR || currentField > HOUR) {
+                                return false;
+                            }
+                            currentField = HOUR;
+                            break;
+                        case Name.TIMEZONE_ID:
+                            if (!nameValue.key.equals("z") || !setTimezone(nameValue.value, false)) {
+                                return false;
+                            }
+                            break;
+                        default:
+                            return false;
+                    }
+                    break;
+
+                case SIGN:
+                    if (peek() == -1) {
+                        // END after sign - wrong!
+                        return false;
+                    }
+
+                    if (currentField == YEAR) {
+                        yearSign = numValue;
+                    } else if (currentField < SECOND || !setTimezone(readTimeZoneOffset(), true)) {
+                        // Note: Spidermonkey won't parse timezone unless time includes seconds and milliseconds
+                        return false;
+                    }
+                    break;
+
+                default:
+                    return false;
+            }
+            token = next();
+        }
+
+        return patchResult(true);
+    }
+
+    /**
+     * Try parsing the date using a fuzzy algorithm that can handle a variety of formats.
+     *
+     * <p>Numbers separated by <tt>':'</tt> are treated as time values, optionally followed by a
+     * millisecond value separated by <tt>'.'</tt>. Other number values are treated as date values.
+     * The exact sequence of day, month, and year values to apply is determined heuristically.</p>
+     *
+     * <p>English month names and selected time zone names as well as AM/PM markers are recognized
+     * and handled properly. Additionally, numeric time zone offsets such as <tt>(+|-)hh:mm</tt> or
+     * <tt>(+|-)hhmm</tt> are recognized. If the string does not contain a time zone offset
+     * the <tt>TIMEZONE</tt>field is left undefined, meaning the local time zone should be applied.</p>
+     *
+     * <p>English weekday names are recognized but ignored. All text in parentheses is ignored as well.
+     * All other text causes parsing to fail.</p>
+     *
+     * @return true if the string could be parsed
+     */
+    public boolean parseLegacyDate() {
+
+        if (yearSign != 0 || currentField > DAY) {
+            // we don't support signed years in legacy mode
+            return false;
+        }
+        if (token == null) {
+            token = next();
+        }
+
+        while (token != Token.END) {
+
+            switch (token) {
+                case NUMBER:
+                    if (skip(':')) {
+                        // A number followed by ':' is parsed as time
+                        if (!setTimeField(numValue)) {
+                            return false;
+                        }
+                        // consume remaining time tokens
+                        do {
+                            token = next();
+                            if (token != Token.NUMBER || !setTimeField(numValue)) {
+                                return false;
+                            }
+                        } while (skip(isSet(SECOND) ? '.' : ':'));
+
+                    } else {
+                        // Parse as date token
+                        if (!setDateField(numValue)) {
+                            return false;
+                        }
+                        skip('-');
+                    }
+                    break;
+
+                case NAME:
+                    if (nameValue == null) {
+                        return false;
+                    }
+                    switch (nameValue.type) {
+                        case Name.AM_PM:
+                            if (!setAmPm(nameValue.value)) {
+                                return false;
+                            }
+                            break;
+                        case Name.MONTH_NAME:
+                            if (!setMonth(nameValue.value)) {
+                                return false;
+                            }
+                            break;
+                        case Name.TIMEZONE_ID:
+                            if (!setTimezone(nameValue.value, false)) {
+                                return false;
+                            }
+                            break;
+                        case Name.TIME_SEPARATOR:
+                            return false;
+                        default:
+                            break;
+                    }
+                    if (nameValue.type != Name.TIMEZONE_ID) {
+                        skip('-');
+                    }
+                    break;
+
+                case SIGN:
+                    if (peek() == -1) {
+                        // END after sign - wrong!
+                        return false;
+                    }
+
+                    if (!setTimezone(readTimeZoneOffset(), true)) {
+                        return false;
+                    }
+                    break;
+
+                case PARENTHESIS:
+                    if (!skipParentheses()) {
+                        return false;
+                    }
+                    break;
+
+                case SEPARATOR:
+                    break;
+
+                default:
+                    return false;
+            }
+            token = next();
+        }
+
+        return patchResult(false);
+    }
+
+    /**
+     * Get the parsed date and time fields as an array of <tt>Integers</tt>.
+     *
+     * <p>If parsing was successful, all fields are guaranteed to be set except for the
+     * <tt>TIMEZONE</tt> field which may be <tt>null</tt>, meaning that local time zone
+     * offset should be applied.</p>
+     *
+     * @return the parsed date fields
+     */
+    public Integer[] getDateFields() {
+        return fields;
+    }
+
+    private boolean isSet(final int field) {
+        return fields[field] != null;
+    }
+
+    private Integer get(final int field) {
+        return fields[field];
+    }
+
+    private void set(final int field, final int value) {
+        fields[field] = value;
+    }
+
+    private int peek() {
+        return pos < length ? string.charAt(pos) : -1;
+    }
+
+    private boolean skip(final char c) {
+        if (pos < length && string.charAt(pos) == c) {
+            token = null;
+            pos++;
+            return true;
+        }
+        return false;
+    }
+
+    private Token next() {
+        if (pos >= length) {
+            tokenLength = 0;
+            return Token.END;
+        }
+
+        final char c = string.charAt(pos);
+
+        if (c > 0x80) {
+            tokenLength = 1;
+            pos++;
+            return Token.UNKNOWN; // We only deal with ASCII here
+        }
+
+        final int type = Character.getType(c);
+        switch (type) {
+            case DECIMAL_DIGIT_NUMBER:
+                numValue = readNumber(6);
+                return Token.NUMBER;
+            case SPACE_SEPARATOR :
+            case OTHER_PUNCTUATION:
+                tokenLength = 1;
+                pos++;
+                return Token.SEPARATOR;
+            case UPPERCASE_LETTER:
+            case LOWERCASE_LETTER:
+                nameValue = readName();
+                return Token.NAME;
+            default:
+                tokenLength = 1;
+                pos++;
+                switch (c) {
+                    case '(':
+                        return Token.PARENTHESIS;
+                    case '-':
+                    case '+':
+                        numValue = c == '-' ? -1 : 1;
+                        return Token.SIGN;
+                    default:
+                        return Token.UNKNOWN;
+                }
+        }
+    }
+
+    private static boolean checkLegacyField(final int field, final int value) {
+        switch (field) {
+            case HOUR:
+                return isHour(value);
+            case MINUTE:
+            case SECOND:
+                return isMinuteOrSecond(value);
+            case MILLISECOND:
+                return isMillisecond(value);
+            default:
+                // skip validation on other legacy fields as we don't know what's what
+                return true;
+        }
+    }
+
+    private boolean checkEcmaField(final int field, final int value) {
+        switch (field) {
+            case YEAR:
+                return tokenLength == 4;
+            case MONTH:
+                return tokenLength == 2 && isMonth(value);
+            case DAY:
+                return tokenLength == 2 && isDay(value);
+            case HOUR:
+                return tokenLength == 2 && isHour(value);
+            case MINUTE:
+            case SECOND:
+                return tokenLength == 2 && isMinuteOrSecond(value);
+            case MILLISECOND:
+                // we allow millisecond to be less than 3 digits
+                return tokenLength < 4 && isMillisecond(value);
+            default:
+                return true;
+        }
+    }
+
+    private boolean skipEcmaDelimiter() {
+        switch (currentField) {
+            case YEAR:
+            case MONTH:
+                return skip('-') || peek() == 'T' || peek() == -1;
+            case DAY:
+                return peek() == 'T' || peek() == -1;
+            case HOUR:
+            case MINUTE:
+                return skip(':') || endOfTime();
+            case SECOND:
+                return skip('.') || endOfTime();
+            default:
+                return true;
+        }
+    }
+
+    private boolean endOfTime() {
+        final int c = peek();
+        return c == -1 || c == 'Z' || c == '-' || c == '+' || c == ' ';
+    }
+
+    private static boolean isAsciiLetter(final char ch) {
+        return ('A' <= ch && ch <= 'Z') || ('a' <= ch && ch <= 'z');
+    }
+
+    private static boolean isAsciiDigit(final char ch) {
+        return '0' <= ch && ch <= '9';
+    }
+
+    private int readNumber(final int maxDigits) {
+        final int start = pos;
+        int n = 0;
+        final int max = Math.min(length, pos + maxDigits);
+        while (pos < max && isAsciiDigit(string.charAt(pos))) {
+            n = n * 10 + string.charAt(pos++) - '0';
+        }
+        tokenLength = pos - start;
+        return n;
+    }
+
+    private Name readName() {
+        final int start = pos;
+        final int limit = Math.min(pos + 3, length);
+
+        // first read up to the key length
+        while (pos < limit && isAsciiLetter(string.charAt(pos))) {
+            pos++;
+        }
+        final String key = string.substring(start, pos).toLowerCase(Locale.ENGLISH);
+        final Name name = names.get(key);
+        // then advance to end of name
+        while (pos < length && isAsciiLetter(string.charAt(pos))) {
+            pos++;
+        }
+
+        tokenLength = pos - start;
+        // make sure we have the full name or a prefix
+        if (name != null && name.matches(string, start, tokenLength)) {
+            return name;
+        }
+        return null;
+    }
+
+    private int readTimeZoneOffset() {
+        final int sign = string.charAt(pos - 1) == '+' ? 1 : -1;
+        int offset = readNumber(2);
+        skip(':');
+        offset = offset * 60 + readNumber(2);
+        return sign * offset;
+    }
+
+    private boolean skipParentheses() {
+        int parenCount = 1;
+        while (pos < length && parenCount != 0) {
+            final char c = string.charAt(pos++);
+            if (c == '(') {
+                parenCount++;
+            } else if (c == ')') {
+                parenCount--;
+            }
+        }
+        return true;
+    }
+
+    private static int getDefaultValue(final int field) {
+        switch (field) {
+            case MONTH:
+            case DAY:
+                return 1;
+            default:
+                return 0;
+        }
+    }
+
+    private static boolean isDay(final int n) {
+        return 1 <= n && n <= 31;
+    }
+
+    private static boolean isMonth(final int n) {
+        return 1 <= n && n <= 12;
+    }
+
+    private static boolean isHour(final int n) {
+        return 0 <= n && n <= 24;
+    }
+
+    private static boolean isMinuteOrSecond(final int n) {
+        return 0 <= n && n < 60;
+    }
+
+    private static boolean isMillisecond(final int n) {
+        return 0<= n && n < 1000;
+    }
+
+    private boolean setMonth(final int m) {
+        if (!isSet(MONTH)) {
+            namedMonth = true;
+            set(MONTH, m);
+            return true;
+        }
+        return false;
+    }
+
+    private boolean setDateField(final int n) {
+        for (int field = YEAR; field != HOUR; field++) {
+            if (!isSet(field)) {
+                // no validation on legacy date fields
+                set(field, n);
+                return true;
+            }
+        }
+        return false;
+    }
+
+    private boolean setTimeField(final int n) {
+        for (int field = HOUR; field != TIMEZONE; field++) {
+            if (!isSet(field)) {
+                if (checkLegacyField(field, n)) {
+                    set(field, n);
+                    return true;
+                }
+                return false;
+            }
+        }
+        return false;
+    }
+
+    private boolean setTimezone(final int offset, final boolean asNumericOffset) {
+        if (!isSet(TIMEZONE) || (asNumericOffset && get(TIMEZONE) == 0)) {
+            set(TIMEZONE, offset);
+            return true;
+        }
+        return false;
+    }
+
+    private boolean setAmPm(final int offset) {
+        if (!isSet(HOUR)) {
+            return false;
+        }
+        final int hour = get(HOUR);
+        if (hour >= 0 && hour <= 12) {
+            set(HOUR, hour + offset);
+        }
+        return true;
+    }
+
+    private boolean patchResult(final boolean strict) {
+        // sanity checks - make sure we have something
+        if (!isSet(YEAR) && !isSet(HOUR)) {
+            return false;
+        }
+        if (isSet(HOUR) && !isSet(MINUTE)) {
+            return false;
+        }
+        // fill in default values for unset fields except timezone
+        for (int field = YEAR; field <= TIMEZONE; field++) {
+            if (get(field) == null) {
+                if (field == TIMEZONE && !strict) {
+                    // We only use UTC as default timezone for dates parsed complying with
+                    // the format specified in ES5 15.9.1.15. Otherwise the slot is left empty
+                    // and local timezone is used.
+                    continue;
+                }
+                final int value = getDefaultValue(field);
+                set(field, value);
+            }
+        }
+
+        if (!strict) {
+            // swap year, month, and day if it looks like the right thing to do
+            if (isDay(get(YEAR))) {
+                final int d = get(YEAR);
+                set(YEAR, get(DAY));
+                if (namedMonth) {
+                    // d-m-y
+                    set(DAY, d);
+                } else {
+                    // m-d-y
+                    final int d2 = get(MONTH);
+                    set(MONTH, d);
+                    set(DAY, d2);
+                }
+            }
+            // sanity checks now that we know what's what
+            if (!isMonth(get(MONTH)) || !isDay(get(DAY))) {
+                return false;
+            }
+
+            // add 1900 or 2000 to year if it's between 0 and 100
+            final int year = get(YEAR);
+            if (year >= 0 && year < 100) {
+                set(YEAR, year >= 50 ? 1900 + year : 2000 + year);
+            }
+        } else {
+            // 24 hour value is only allowed if all other time values are zero
+            if (get(HOUR) == 24 &&
+                    (get(MINUTE) != 0 || get(SECOND) != 0 || get(MILLISECOND) != 0)) {
+                return false;
+            }
+        }
+
+        // set month to 0-based
+        set(MONTH, get(MONTH) - 1);
+        return true;
+    }
+
+    private static void addName(final String str, final int type, final int value) {
+        final Name name = new Name(str, type, value);
+        names.put(name.key, name);
+    }
+
+    private static class Name {
+        final String name;
+        final String key;
+        final int value;
+        final int type;
+
+        final static int DAY_OF_WEEK    = -1;
+        final static int MONTH_NAME     = 0;
+        final static int AM_PM          = 1;
+        final static int TIMEZONE_ID    = 2;
+        final static int TIME_SEPARATOR = 3;
+
+        Name(final String name, final int type, final int value) {
+            assert name != null;
+            assert name.equals(name.toLowerCase(Locale.ENGLISH));
+
+            this.name = name;
+            // use first three characters as lookup key
+            this.key = name.substring(0, Math.min(3, name.length()));
+            this.type = type;
+            this.value = value;
+        }
+
+        public boolean matches(final String str, final int offset, final int len) {
+            return name.regionMatches(true, 0, str, offset, len);
+        }
+
+        @Override
+        public String toString() {
+            return name;
+        }
+    }
+
+}
--- a/src/jdk/nashorn/internal/parser/JSONParser.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/parser/JSONParser.java	Mon Jun 10 09:53:21 2013 +0100
@@ -282,7 +282,7 @@
         next();
 
         // Prepare to accumulate elements.
-        final List<Node> elements = new ArrayList<>();
+        final List<PropertyNode> elements = new ArrayList<>();
 
         // Create a block for the object literal.
 loop:
@@ -298,7 +298,7 @@
 
             default:
                 // Get and add the next property.
-                final Node property = propertyAssignment();
+                final PropertyNode property = propertyAssignment();
                 elements.add(property);
 
                 // Comma between property assigments is mandatory in JSON.
@@ -317,7 +317,7 @@
      * Parse a property assignment from the token stream
      * @return the property assignment as a Node
      */
-    private Node propertyAssignment() {
+    private PropertyNode propertyAssignment() {
         // Capture firstToken.
         final long propertyToken = token;
         LiteralNode<?> name = null;
--- a/src/jdk/nashorn/internal/parser/Parser.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/parser/Parser.java	Mon Jun 10 09:53:21 2013 +0100
@@ -59,7 +59,6 @@
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
-
 import jdk.nashorn.internal.codegen.CompilerConstants;
 import jdk.nashorn.internal.codegen.Namespace;
 import jdk.nashorn.internal.ir.AccessNode;
@@ -192,36 +191,110 @@
             // Begin parse.
             return program(scriptName);
         } catch (final Exception e) {
-            // Extract message from exception.  The message will be in error
-            // message format.
-            String message = e.getMessage();
-
-            // If empty message.
-            if (message == null) {
-                message = e.toString();
+            handleParseException(e);
+
+            return null;
+        } finally {
+            final String end = this + " end '" + scriptName + "'";
+            if (Timing.isEnabled()) {
+                Timing.accumulateTime(toString(), System.currentTimeMillis() - t0);
+                LOG.info(end, "' in ", (System.currentTimeMillis() - t0), " ms");
+            } else {
+                LOG.info(end);
             }
-
-            // Issue message.
-            if (e instanceof ParserException) {
-                errors.error((ParserException)e);
-            } else {
-                errors.error(message);
-            }
-
-            if (env._dump_on_error) {
-                e.printStackTrace(env.getErr());
-            }
-
+        }
+    }
+
+    /**
+     * Parse and return the list of function parameter list. A comma
+     * separated list of function parameter identifiers is expected to be parsed.
+     * Errors will be thrown and the error manager will contain information
+     * if parsing should fail. This method is used to check if parameter Strings
+     * passed to "Function" constructor is a valid or not.
+     *
+     * @return the list of IdentNodes representing the formal parameter list
+     */
+    public List<IdentNode> parseFormalParameterList() {
+        try {
+            stream = new TokenStream();
+            lexer  = new Lexer(source, stream, scripting && !env._no_syntax_extensions);
+
+            // Set up first token (skips opening EOL.)
+            k = -1;
+            next();
+
+            return formalParameterList(TokenType.EOF);
+        } catch (final Exception e) {
+            handleParseException(e);
             return null;
-         } finally {
-             final String end = this + " end '" + scriptName + "'";
-             if (Timing.isEnabled()) {
-                 Timing.accumulateTime(toString(), System.currentTimeMillis() - t0);
-                 LOG.info(end, "' in ", (System.currentTimeMillis() - t0), " ms");
-             } else {
-                 LOG.info(end);
-             }
-         }
+        }
+    }
+
+    /**
+     * Execute parse and return the resulting function node.
+     * Errors will be thrown and the error manager will contain information
+     * if parsing should fail. This method is used to check if code String
+     * passed to "Function" constructor is a valid function body or not.
+     *
+     * @return function node resulting from successful parse
+     */
+    public FunctionNode parseFunctionBody() {
+        try {
+            stream = new TokenStream();
+            lexer  = new Lexer(source, stream, scripting && !env._no_syntax_extensions);
+
+            // Set up first token (skips opening EOL.)
+            k = -1;
+            next();
+
+            // Make a fake token for the function.
+            final long functionToken = Token.toDesc(FUNCTION, 0, source.getLength());
+            // Set up the function to append elements.
+
+            FunctionNode function = newFunctionNode(
+                functionToken,
+                new IdentNode(functionToken, Token.descPosition(functionToken), RUN_SCRIPT.symbolName()),
+                new ArrayList<IdentNode>(),
+                FunctionNode.Kind.NORMAL);
+
+            functionDeclarations = new ArrayList<>();
+            sourceElements();
+            addFunctionDeclarations(function);
+            functionDeclarations = null;
+
+            expect(EOF);
+
+            function.setFinish(source.getLength() - 1);
+
+            function = restoreFunctionNode(function, token); //commit code
+            function = function.setBody(lc, function.getBody().setNeedsScope(lc));
+            return function;
+        } catch (final Exception e) {
+            handleParseException(e);
+            return null;
+        }
+    }
+
+    private void handleParseException(final Exception e) {
+        // Extract message from exception.  The message will be in error
+        // message format.
+        String message = e.getMessage();
+
+        // If empty message.
+        if (message == null) {
+            message = e.toString();
+        }
+
+        // Issue message.
+        if (e instanceof ParserException) {
+            errors.error((ParserException)e);
+        } else {
+            errors.error(message);
+        }
+
+        if (env._dump_on_error) {
+            e.printStackTrace(env.getErr());
+        }
     }
 
     /**
@@ -1537,7 +1610,7 @@
 
         endOfLine();
 
-        appendStatement(new ThrowNode(throwLine, throwToken, finish, expression));
+        appendStatement(new ThrowNode(throwLine, throwToken, finish, expression, 0));
     }
 
     /**
@@ -1597,7 +1670,7 @@
                 try {
                     // Get CATCH body.
                     final Block catchBody = getBlock(true);
-                    final CatchNode catchNode = new CatchNode(catchLine, catchToken, finish, exception, ifExpression, catchBody);
+                    final CatchNode catchNode = new CatchNode(catchLine, catchToken, finish, exception, ifExpression, catchBody, 0);
                     appendStatement(catchNode);
                 } finally {
                     catchBlock = restoreBlock(catchBlock);
@@ -1954,7 +2027,7 @@
             }
         }
 
-        return new ObjectNode(objectToken, finish, new ArrayList<Node>(map.values()));
+        return new ObjectNode(objectToken, finish, new ArrayList<>(map.values()));
     }
 
     /**
@@ -2424,12 +2497,29 @@
      * @return List of parameter nodes.
      */
     private List<IdentNode> formalParameterList() {
+        return formalParameterList(RPAREN);
+    }
+
+    /**
+     * Same as the other method of the same name - except that the end
+     * token type expected is passed as argument to this method.
+     *
+     * FormalParameterList :
+     *      Identifier
+     *      FormalParameterList , Identifier
+     *
+     * See 13
+     *
+     * Parse function parameter list.
+     * @return List of parameter nodes.
+     */
+    private List<IdentNode> formalParameterList(final TokenType endType) {
         // Prepare to gather parameters.
         final List<IdentNode> parameters = new ArrayList<>();
         // Track commas.
         boolean first = true;
 
-        while (type != RPAREN) {
+        while (type != endType) {
             // Comma prior to every argument except the first.
             if (!first) {
                 expect(COMMARIGHT);
--- a/src/jdk/nashorn/internal/parser/TokenType.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/parser/TokenType.java	Mon Jun 10 09:53:21 2013 +0100
@@ -25,6 +25,7 @@
 
 package jdk.nashorn.internal.parser;
 
+import java.util.Locale;
 import static jdk.nashorn.internal.parser.TokenKind.BINARY;
 import static jdk.nashorn.internal.parser.TokenKind.BRACKET;
 import static jdk.nashorn.internal.parser.TokenKind.FUTURE;
@@ -249,7 +250,7 @@
     }
 
     public String getNameOrType() {
-        return name == null ? super.name().toLowerCase() : name;
+        return name == null ? super.name().toLowerCase(Locale.ENGLISH) : name;
     }
 
     public TokenType getNext() {
--- a/src/jdk/nashorn/internal/runtime/AccessorProperty.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/runtime/AccessorProperty.java	Mon Jun 10 09:53:21 2013 +0100
@@ -75,7 +75,23 @@
 
     private static final MethodType[] ACCESSOR_GETTER_TYPES = new MethodType[NOOF_TYPES];
     private static final MethodType[] ACCESSOR_SETTER_TYPES = new MethodType[NOOF_TYPES];
-    private static final MethodHandle SPILLGETTER = MH.asType(MH.getter(MethodHandles.lookup(), ScriptObject.class, "spill", Object[].class), Lookup.GET_OBJECT_TYPE);
+    private static final MethodHandle SPILL_ELEMENT_GETTER;
+    private static final MethodHandle SPILL_ELEMENT_SETTER;
+
+    private static final int SPILL_CACHE_SIZE = 8;
+    private static final MethodHandle[] SPILL_ACCESSORS = new MethodHandle[SPILL_CACHE_SIZE * 2];
+
+    static {
+        for (int i = 0; i < NOOF_TYPES; i++) {
+            final Type type = ACCESSOR_TYPES.get(i);
+            ACCESSOR_GETTER_TYPES[i] = MH.type(type.getTypeClass(), Object.class);
+            ACCESSOR_SETTER_TYPES[i] = MH.type(void.class, Object.class, type.getTypeClass());
+        }
+
+        final MethodHandle spillGetter = MH.getter(MethodHandles.lookup(), ScriptObject.class, "spill", Object[].class);
+        SPILL_ELEMENT_GETTER = MH.filterArguments(MH.arrayElementGetter(Object[].class), 0, spillGetter);
+        SPILL_ELEMENT_SETTER = MH.filterArguments(MH.arrayElementSetter(Object[].class), 0, spillGetter);
+    }
 
     /** Seed getter for the primitive version of this field (in -Dnashorn.fields.dual=true mode) */
     private MethodHandle primitiveGetter;
@@ -96,14 +112,6 @@
      */
     private Class<?> currentType;
 
-    static {
-        for (int i = 0; i < NOOF_TYPES; i++) {
-            final Type type = ACCESSOR_TYPES.get(i);
-            ACCESSOR_GETTER_TYPES[i] = MH.type(type.getTypeClass(), Object.class);
-            ACCESSOR_SETTER_TYPES[i] = MH.type(void.class, Object.class, type.getTypeClass());
-        }
-    }
-
     /**
      * Delegate constructor. This is used when adding properties to the Global scope, which
      * is necessary for outermost levels in a script (the ScriptObject is represented by
@@ -114,19 +122,31 @@
      * @param delegate  delegate script object to rebind receiver to
      */
     public AccessorProperty(final AccessorProperty property, final ScriptObject delegate) {
-        this(property);
+        super(property);
 
-        this.getters = new MethodHandle[NOOF_TYPES];
-
-        this.primitiveGetter = bindTo(primitiveGetter, delegate);
-        this.primitiveSetter = bindTo(primitiveSetter, delegate);
-        this.objectGetter    = bindTo(objectGetter, delegate);
-        this.objectSetter    = bindTo(objectSetter, delegate);
+        this.primitiveGetter = bindTo(property.primitiveGetter, delegate);
+        this.primitiveSetter = bindTo(property.primitiveSetter, delegate);
+        this.objectGetter    = bindTo(property.objectGetter, delegate);
+        this.objectSetter    = bindTo(property.objectSetter, delegate);
 
         setCurrentType(property.getCurrentType());
     }
 
     /**
+     * Constructor for spill properties. Array getters and setters will be created on demand.
+     *
+     * @param key    the property key
+     * @param flags  the property flags
+     * @param slot   spill slot
+     */
+    public AccessorProperty(final String key, final int flags, final int slot) {
+        super(key, flags, slot);
+        assert (flags & IS_SPILL) == IS_SPILL;
+
+        setCurrentType(Object.class);
+    }
+
+    /**
      * Constructor. Similar to the constructor with both primitive getters and setters, the difference
      * here being that only one getter and setter (setter is optional for non writable fields) is given
      * to the constructor, and the rest are created from those. Used e.g. by Nasgen classes
@@ -268,7 +288,40 @@
     }
 
     @Override
+    protected void setObjectValue(final ScriptObject self, final ScriptObject owner, final Object value, final boolean strict)  {
+        if (isSpill()) {
+            self.spill[getSlot()] = value;
+        } else {
+            try {
+                getSetter(Object.class, self.getMap()).invokeExact((Object)self, value);
+            } catch (final Error|RuntimeException e) {
+                throw e;
+            } catch (final Throwable e) {
+                throw new RuntimeException(e);
+            }
+        }
+    }
+
+    @Override
+    protected Object getObjectValue(final ScriptObject self, final ScriptObject owner) {
+        if (isSpill()) {
+            return self.spill[getSlot()];
+        }
+
+        try {
+            return getGetter(Object.class).invokeExact((Object)self);
+        } catch (final Error|RuntimeException e) {
+            throw e;
+        } catch (final Throwable e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    @Override
     public MethodHandle getGetter(final Class<?> type) {
+        if (isSpill() && objectGetter == null) {
+            objectGetter = getSpillGetter();
+        }
         final int i = getAccessorTypeIndex(type);
         if (getters[i] == null) {
             getters[i] = debug(
@@ -284,7 +337,7 @@
                 "get");
         }
 
-        return isSpill() ? MH.filterArguments(getters[i], 0, SPILLGETTER) : getters[i];
+        return getters[i];
     }
 
     private Property getWiderProperty(final Class<?> type) {
@@ -313,6 +366,9 @@
     }
 
     private MethodHandle generateSetter(final Class<?> forType, final Class<?> type) {
+        if (isSpill() && objectSetter == null) {
+            objectSetter = getSpillSetter();
+        }
         MethodHandle mh = createSetter(forType, type, primitiveSetter, objectSetter);
         mh = MH.asType(mh, ACCESSOR_SETTER_TYPES[getAccessorTypeIndex(type)]); //has to be the case for invokeexact to work in ScriptObject
         mh = debug(mh, currentType, type, "set");
@@ -343,7 +399,7 @@
             mh = generateSetter(forType, type);
         }
 
-        return isSpill() ? MH.filterArguments(mh, 0, SPILLGETTER) : mh;
+        return mh;
     }
 
     @Override
@@ -363,6 +419,30 @@
         setCurrentType(newType);
     }
 
+    private MethodHandle getSpillGetter() {
+        final int slot = getSlot();
+        MethodHandle getter = slot < SPILL_CACHE_SIZE ? SPILL_ACCESSORS[slot * 2] : null;
+        if (getter == null) {
+            getter = MH.asType(MH.insertArguments(SPILL_ELEMENT_GETTER, 1, slot), Lookup.GET_OBJECT_TYPE);
+            if (slot < SPILL_CACHE_SIZE) {
+                SPILL_ACCESSORS[slot * 2] = getter;
+            }
+        }
+        return getter;
+    }
+
+    private MethodHandle getSpillSetter() {
+        final int slot = getSlot();
+        MethodHandle setter = slot < SPILL_CACHE_SIZE ? SPILL_ACCESSORS[slot * 2 + 1] : null;
+        if (setter == null) {
+            setter = MH.asType(MH.insertArguments(SPILL_ELEMENT_SETTER, 1, slot), Lookup.SET_OBJECT_TYPE);
+            if (slot < SPILL_CACHE_SIZE) {
+                SPILL_ACCESSORS[slot * 2 + 1] = setter;
+            }
+        }
+        return setter;
+    }
+
     private static void finest(final String str) {
         if (DEBUG_FIELDS) {
             LOG.finest(str);
--- a/src/jdk/nashorn/internal/runtime/CompiledFunction.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/runtime/CompiledFunction.java	Mon Jun 10 09:53:21 2013 +0100
@@ -35,21 +35,27 @@
  */
 final class CompiledFunction implements Comparable<CompiledFunction> {
 
+    /** The method type may be more specific than the invoker, if. e.g.
+     *  the invoker is guarded, and a guard with a generic object only
+     *  fallback, while the target is more specific, we still need the
+     *  more specific type for sorting */
+    private final MethodType   type;
     private final MethodHandle invoker;
     private MethodHandle constructor;
 
-    CompiledFunction(final MethodHandle invoker) {
-        this(invoker, null);
+    CompiledFunction(final MethodType type, final MethodHandle invoker) {
+        this(type, invoker, null);
     }
 
-    CompiledFunction(final MethodHandle invoker, final MethodHandle constructor) {
-        this.invoker = invoker;
-        this.constructor = constructor; //isConstructor
+    CompiledFunction(final MethodType type, final MethodHandle invoker, final MethodHandle constructor) {
+        this.type        = type;
+        this.invoker     = invoker;
+        this.constructor = constructor;
     }
 
     @Override
     public String toString() {
-        return "<invoker=" + invoker + " ctor=" + constructor + ">";
+        return "<callSiteType= " + type + " invoker=" + invoker + " ctor=" + constructor + ">";
     }
 
     MethodHandle getInvoker() {
@@ -69,7 +75,7 @@
     }
 
     MethodType type() {
-        return invoker.type();
+        return type;
     }
 
     @Override
@@ -103,8 +109,8 @@
         return weight() > o.weight();
     }
 
-    boolean moreGenericThan(final MethodType type) {
-        return weight() > weight(type);
+    boolean moreGenericThan(final MethodType mt) {
+        return weight() > weight(mt);
     }
 
     /**
@@ -112,15 +118,15 @@
      * It is compatible if the types are narrower than the invocation type so that
      * a semantically equivalent linkage can be performed.
      *
-     * @param typesc
+     * @param mt type to check against
      * @return
      */
-    boolean typeCompatible(final MethodType type) {
-        final Class<?>[] wantedParams   = type.parameterArray();
+    boolean typeCompatible(final MethodType mt) {
+        final Class<?>[] wantedParams   = mt.parameterArray();
         final Class<?>[] existingParams = type().parameterArray();
 
         //if we are not examining a varargs type, the number of parameters must be the same
-        if (wantedParams.length != existingParams.length && !isVarArgsType(type)) {
+        if (wantedParams.length != existingParams.length && !isVarArgsType(mt)) {
             return false;
         }
 
--- a/src/jdk/nashorn/internal/runtime/Context.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/runtime/Context.java	Mon Jun 10 09:53:21 2013 +0100
@@ -48,6 +48,7 @@
 import java.security.ProtectionDomain;
 import jdk.internal.org.objectweb.asm.ClassReader;
 import jdk.internal.org.objectweb.asm.util.CheckClassAdapter;
+import jdk.nashorn.api.scripting.ScriptObjectMirror;
 import jdk.nashorn.internal.codegen.Compiler;
 import jdk.nashorn.internal.codegen.ObjectClassGenerator;
 import jdk.nashorn.internal.ir.FunctionNode;
@@ -491,6 +492,40 @@
     }
 
     /**
+     * Implementation of {@code loadWithNewGlobal} Nashorn extension. Load a script file from a source
+     * expression, after creating a new global scope.
+     *
+     * @param from source expression for script
+     *
+     * @return return value for load call (undefined)
+     *
+     * @throws IOException if source cannot be found or loaded
+     */
+    public Object loadWithNewGlobal(final Object from) throws IOException {
+        final ScriptObject oldGlobal = getGlobalTrusted();
+        final ScriptObject newGlobal = AccessController.doPrivileged(new PrivilegedAction<ScriptObject>() {
+           @Override
+           public ScriptObject run() {
+               try {
+                   return createGlobal();
+               } catch (final RuntimeException e) {
+                   if (Context.DEBUG) {
+                       e.printStackTrace();
+                   }
+                   throw e;
+               }
+           }
+        });
+        setGlobalTrusted(newGlobal);
+
+        try {
+            return ScriptObjectMirror.wrap(load(newGlobal, from), newGlobal);
+        } finally {
+            setGlobalTrusted(oldGlobal);
+        }
+    }
+
+    /**
      * Load or get a structure class. Structure class names are based on the number of parameter fields
      * and {@link AccessorProperty} fields in them. Structure classes are used to represent ScriptObjects
      *
--- a/src/jdk/nashorn/internal/runtime/DebugLogger.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/runtime/DebugLogger.java	Mon Jun 10 09:53:21 2013 +0100
@@ -35,7 +35,6 @@
  */
 
 public final class DebugLogger {
-    @SuppressWarnings("NonConstantLogger")
     private final Logger  logger;
     private final boolean isEnabled;
 
--- a/src/jdk/nashorn/internal/runtime/FinalScriptFunctionData.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/runtime/FinalScriptFunctionData.java	Mon Jun 10 09:53:21 2013 +0100
@@ -78,9 +78,9 @@
             //only nasgen constructors: (boolean, self, args) are subject to binding a boolean newObj. isConstructor
             //is too conservative a check. However, isConstructor(mh) always implies isConstructor param
             assert isConstructor();
-            code.add(new CompiledFunction(MH.insertArguments(mh, 0, false), composeConstructor(MH.insertArguments(mh, 0, true), needsCallee))); //make sure callee state can be determined when we reach constructor
+            code.add(new CompiledFunction(mh.type(), MH.insertArguments(mh, 0, false), composeConstructor(MH.insertArguments(mh, 0, true), needsCallee))); //make sure callee state can be determined when we reach constructor
         } else {
-            code.add(new CompiledFunction(mh));
+            code.add(new CompiledFunction(mh.type(), mh));
         }
     }
 
--- a/src/jdk/nashorn/internal/runtime/FindProperty.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/runtime/FindProperty.java	Mon Jun 10 09:53:21 2013 +0100
@@ -153,5 +153,24 @@
         return prototype.isScope();
     }
 
+    /**
+     * Get the property value from self as object.
+     *
+     * @return the property value
+     */
+    public Object getObjectValue() {
+        return property.getObjectValue(getGetterReceiver(), getOwner());
+    }
+
+    /**
+     * Set the property value in self.
+     *
+     * @param value the new value
+     * @param strict strict flag
+     */
+    public void setObjectValue(final Object value, final boolean strict) {
+        property.setObjectValue(getSetterReceiver(), getOwner(), value, strict);
+    }
+
 }
 
--- a/src/jdk/nashorn/internal/runtime/GlobalFunctions.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/runtime/GlobalFunctions.java	Mon Jun 10 09:53:21 2013 +0100
@@ -30,6 +30,7 @@
 
 import java.lang.invoke.MethodHandle;
 import java.lang.invoke.MethodHandles;
+import java.util.Locale;
 
 /**
  * Utilities used by Global class.
@@ -373,10 +374,10 @@
             } else if (ch < 256) {
                 sb.append('%');
                 final byte b = (byte)ch;
-                sb.append(Integer.toHexString(b & 0xFF).toUpperCase());
+                sb.append(Integer.toHexString(b & 0xFF).toUpperCase(Locale.ENGLISH));
             } else {
                 sb.append("%u");
-                sb.append(Integer.toHexString(ch & 0xFFFF).toUpperCase());
+                sb.append(Integer.toHexString(ch & 0xFFFF).toUpperCase(Locale.ENGLISH));
             }
         }
 
--- a/src/jdk/nashorn/internal/runtime/JSONFunctions.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/runtime/JSONFunctions.java	Mon Jun 10 09:53:21 2013 +0100
@@ -25,9 +25,11 @@
 
 package jdk.nashorn.internal.runtime;
 
+import static jdk.nashorn.internal.runtime.arrays.ArrayIndex.getArrayIndexNoThrow;
+import static jdk.nashorn.internal.runtime.arrays.ArrayIndex.isValidArrayIndex;
+
 import java.lang.invoke.MethodHandle;
 import java.util.Iterator;
-import java.util.List;
 import jdk.nashorn.internal.ir.LiteralNode;
 import jdk.nashorn.internal.ir.Node;
 import jdk.nashorn.internal.ir.ObjectNode;
@@ -94,7 +96,7 @@
         if (reviver instanceof ScriptFunction) {
             assert global instanceof GlobalObject;
             final ScriptObject root = ((GlobalObject)global).newObject();
-            root.set("", unfiltered, root.isStrictContext());
+            root.addOwnProperty("", Property.WRITABLE_ENUMERABLE_CONFIGURABLE, unfiltered);
             return walk(root, "", (ScriptFunction)reviver);
         }
         return unfiltered;
@@ -115,7 +117,7 @@
                 if (newElement == ScriptRuntime.UNDEFINED) {
                     valueObj.delete(key, strict);
                 } else {
-                    valueObj.set(key, newElement, strict);
+                    setPropertyValue(valueObj, key, newElement, strict);
                 }
             }
         }
@@ -169,13 +171,13 @@
             final ObjectNode   objNode  = (ObjectNode) node;
             final ScriptObject object   = ((GlobalObject)global).newObject();
             final boolean      strict   = global.isStrictContext();
-            final List<Node>   elements = objNode.getElements();
 
-            for (final Node elem : elements) {
-                final PropertyNode pNode     = (PropertyNode) elem;
+            for (final PropertyNode pNode: objNode.getElements()) {
                 final Node         valueNode = pNode.getValue();
 
-                object.set(pNode.getKeyName(), convertNode(global, valueNode), strict);
+                final String name = pNode.getKeyName();
+                final Object value = convertNode(global, valueNode);
+                setPropertyValue(object, name, value, strict);
             }
 
             return object;
@@ -188,6 +190,21 @@
         }
     }
 
+    // add a new property if does not exist already, or else set old property
+    private static void setPropertyValue(final ScriptObject sobj, final String name, final Object value, final boolean strict) {
+        final int index = getArrayIndexNoThrow(name);
+        if (isValidArrayIndex(index)) {
+            // array index key
+            sobj.defineOwnProperty(index, value);
+        } else if (sobj.getMap().findProperty(name) != null) {
+            // pre-existing non-inherited property, call set
+            sobj.set(name, value, strict);
+        } else {
+            // add new property
+            sobj.addOwnProperty(name, Property.WRITABLE_ENUMERABLE_CONFIGURABLE, value);
+        }
+    }
+
     // does the given IR node represent a numeric array?
     private static boolean isNumericArray(final Node[] values) {
         for (final Node node : values) {
--- a/src/jdk/nashorn/internal/runtime/JSType.java	Fri May 31 10:28:34 2013 +0100
+++ b/src/jdk/nashorn/internal/runtime/JSType.java	Mon Jun 10 09:53:21 2013 +0100
@@ -28,6 +28,7 @@
 import static jdk.nashorn.internal.codegen.CompilerConstants.staticCall;
 import static jdk.nashorn.internal.runtime.ECMAErrors.typeError;
 
+import java.util.Locale;
 import jdk.internal.dynalink.beans.StaticClass;
 import jdk.nashorn.internal.codegen.CompilerConstants.Call;
 import jdk.nashorn.internal.parser.Lexer;
@@ -111,7 +112,7 @@
      */
     public final String typeName() {
         // For NULL, "object" has to be returned!
-        return ((this == NULL) ? OBJECT : this).name().toLowerCase();
+        return ((this == NULL) ? OBJECT : this).name().toLowerCase(Locale.ENGLISH);
     }
 
     /**
@@ -565,8 +566,11 @@
     }
 
     /**
-     * JavaScript compliant Object to integer conversion
-     * See ECMA 9.4 ToInteger
+     * JavaScript compliant Object to integer conversion. See ECMA 9.4 ToInteger
+     *
+     * <p>Note that this returns {@link java.lang.Integer#MAX_VALUE} or {@link java.lang.Integer#MIN_VALUE}
+     * for double values that exceed the int range, including positive and negative Infinity. It is the
+     * caller's responsibility to handle such values correctly.</p>
      *
      * @param obj  an object
      * @return an integer
@@ -576,8 +580,11 @@
     }
 
     /**
-     * JavaScript compliant Object to long conversion
-     * See ECMA 9.4 ToInteger
+     * JavaScript compliant Object to long conversion. See ECMA 9.4 ToInteger
+     *
+     * <p>Note that this returns {@link java.lang.Long#MAX_VALUE} or {@link java.lang.Long#MIN_VALUE}
+     * for double values that exceed the long range, including positive and negative Infinity. It is the
+     * caller's responsibility to handle such values correctly.</p>
      *
      * @param obj  an object
      * @return a long
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jdk/nashorn/internal/runtime/ListAdapter.java	Mon Jun 10 09:53:21 2013 +0100
@@ -0,0 +1,338 @@
+package jdk.nashorn.internal.runtime;
+
+import java.util.AbstractList;
+import java.util.Deque;
+import java.util.Iterator;
+import java.util.ListIterator;
+import java.util.NoSuchElementException;
+import java.util.RandomAccess;
+import jdk.nashorn.internal.runtime.linker.InvokeByName;
+
+/**
+ * An adapter that can wrap any ECMAScript Array-like object (that adheres to the array rules for the property
+ * {@code length} and having conforming {@code push}, {@code pop}, {@code shift}, {@code unshift}, and {@code splice}
+ * methods) and expose it as both a Java list and double-ended queue. While script arrays aren't necessarily efficient
+ * as dequeues, it's still slightly more efficient to be able to translate dequeue operations into pushes, pops, shifts,
+ * and unshifts, than to blindly translate all list's add/remove operations into splices. Also, it is conceivable that a
+ * custom script object that implements an Array-like API can have a background data representation that is optimized
+ * for dequeue-like access. Note that with ECMAScript arrays, {@code push} and {@code pop} operate at the end of the
+ * array, while in Java {@code Deque} they operate on the front of the queue and as such the Java dequeue
+ * {@link #push(Object)} and {@link #pop()} operations will translate to {@code unshift} and {@code shift} script
+ * operations respectively, while {@link #addLast(Object)} and {@link #removeLast()} will translate to {@code push} and
+ * {@code pop}.
+ */
+public class ListAdapter extends AbstractList<Object> implements RandomAccess, Deque<Object> {
+    // These add to the back and front of the list
+    private static final InvokeByName PUSH    = new InvokeByName("push",    ScriptObject.class, void.class, Object.class);
+    private static final InvokeByName UNSHIFT = new InvokeByName("unshift", ScriptObject.class, void.class, Object.class);
+
+    // These remove from the back and front of the list
+    private static final InvokeByName POP   = new InvokeByName("pop",   ScriptObject.class, Object.class);
+    private static final InvokeByName SHIFT = new InvokeByName("shift", ScriptObject.class, Object.class);
+
+    // These insert and remove in the middle of the list
+    private static final InvokeByName SPLICE_ADD    = new InvokeByName("splice", ScriptObject.class, void.class, int.class, int.class, Object.class);
+    private static final InvokeByName SPLICE_REMOVE = new InvokeByName("splice", ScriptObject.class, void.class, int.class, int.class);
+
+    private final ScriptObject obj;
+
+    /**
+     * Creates a new list wrapper for the specified script object.
+     * @param obj script the object to wrap
+     */
+    public ListAdapter(ScriptObject obj) {
+        this.obj = obj;
+    }
+
+    @Override
+    public int size() {
+        return JSType.toInt32(obj.getLength());
+    }
+
+    @Override
+    public Object get(int index) {
+        checkRange(index);
+        return obj.get(index);
+    }
+
+    @Override
+    public Object set(int index, Object element) {
+        checkRange(index);
+        final Object prevValue = get(index);
+        obj.set(index, element, false);
+        return prevValue;
+    }
+
+    private void checkRange(int index) {
+        if(index < 0 || index >= size()) {
+            throw invalidIndex(index);
+        }
+    }
+
+    @Override
+    public void push(Object e) {
+        addFirst(e);
+    }
+
+    @Override
+    public boolean add(Object e) {
+        addLast(e);
+        return true;
+    }
+
+    @Override
+    public void addFirst(Object e) {
+        try {
+            final Object fn = UNSHIFT.getGetter().invokeExact(obj);
+            checkFunction(fn, UNSHIFT);
+            UNSHIFT.getInvoker().invokeExact(fn, obj, e);
+        } catch(RuntimeException | Error ex) {
+            throw ex;
+        } catch(Throwable t) {
+            throw new RuntimeException(t);
+        }
+    }
+
+    @Override
+    public void addLast(Object e) {
+        try {
+            final Object fn = PUSH.getGetter().invokeExact(obj);
+            checkFunction(fn, PUSH);
+            PUSH.getInvoker().invokeExact(fn, obj, e);
+        } catch(RuntimeException | Error ex) {
+            throw ex;
+        } catch(Throwable t) {
+            throw new RuntimeException(t);
+        }
+    }
+
+    @Override
+    public void add(int index, Object e) {
+        try {
+            if(index < 0) {