8029612: the typeErrorThrower field in ScriptFunctionImpl cannot be static and common to all Globals
authorsundar
Mon, 09 Dec 2013 09:48:11 +0530
changeset 22382 2abc7240ef59
parent 21992 86342c6f8cfc
child 22383 0ed8e0a76adf
child 22397 1bafe007322d
8029612: the typeErrorThrower field in ScriptFunctionImpl cannot be static and common to all Globals Reviewed-by: attila, hannesw
nashorn/src/jdk/nashorn/internal/objects/Global.java
nashorn/src/jdk/nashorn/internal/objects/NativeStrictArguments.java
nashorn/src/jdk/nashorn/internal/objects/ScriptFunctionImpl.java
--- a/nashorn/src/jdk/nashorn/internal/objects/Global.java	Tue Nov 26 11:58:20 2013 -0400
+++ b/nashorn/src/jdk/nashorn/internal/objects/Global.java	Mon Dec 09 09:48:11 2013 +0530
@@ -44,6 +44,7 @@
 import java.util.concurrent.ConcurrentHashMap;
 import jdk.internal.dynalink.linker.GuardedInvocation;
 import jdk.internal.dynalink.linker.LinkRequest;
+import jdk.nashorn.internal.lookup.Lookup;
 import jdk.nashorn.internal.objects.annotations.Attribute;
 import jdk.nashorn.internal.objects.annotations.Property;
 import jdk.nashorn.internal.objects.annotations.ScriptClass;
@@ -364,6 +365,11 @@
     private ScriptObject   builtinFloat32Array;
     private ScriptObject   builtinFloat64Array;
 
+    /*
+     * ECMA section 13.2.3 The [[ThrowTypeError]] Function Object
+     */
+    private ScriptFunction typeErrorThrower;
+
     private PropertyMap    accessorPropertyDescriptorMap;
     private PropertyMap    arrayBufferViewMap;
     private PropertyMap    dataPropertyDescriptorMap;
@@ -1114,6 +1120,10 @@
         return builtinArray;
     }
 
+    ScriptFunction getTypeErrorThrower() {
+        return typeErrorThrower;
+    }
+
     /**
      * Called from compiled script code to test if builtin has been overridden
      *
@@ -2000,6 +2010,13 @@
         anon.set("constructor", builtinFunction, false);
         anon.deleteOwnProperty(anon.getMap().findProperty("prototype"));
 
+        // use "getter" so that [[ThrowTypeError]] function's arity is 0 - as specified in step 10 of section 13.2.3
+        this.typeErrorThrower = new ScriptFunctionImpl("TypeErrorThrower", Lookup.TYPE_ERROR_THROWER_GETTER, null, null, false, false, false);
+        typeErrorThrower.setPrototype(UNDEFINED);
+        // Non-constructor built-in functions do not have "prototype" property
+        typeErrorThrower.deleteOwnProperty(typeErrorThrower.getMap().findProperty("prototype"));
+        typeErrorThrower.preventExtensions();
+
         // now initialize Object
         this.builtinObject = (ScriptFunction)initConstructor("Object");
         final ScriptObject ObjectPrototype = getObjectPrototype();
--- a/nashorn/src/jdk/nashorn/internal/objects/NativeStrictArguments.java	Tue Nov 26 11:58:20 2013 -0400
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeStrictArguments.java	Mon Dec 09 09:48:11 2013 +0530
@@ -76,7 +76,7 @@
         super(proto, map);
         setIsArguments();
 
-        final ScriptFunction func = ScriptFunctionImpl.getTypeErrorThrower();
+        final ScriptFunction func = Global.instance().getTypeErrorThrower();
         // We have to fill user accessor functions late as these are stored
         // in this object rather than in the PropertyMap of this object.
         setUserAccessors("caller", func, func);
--- a/nashorn/src/jdk/nashorn/internal/objects/ScriptFunctionImpl.java	Tue Nov 26 11:58:20 2013 -0400
+++ b/nashorn/src/jdk/nashorn/internal/objects/ScriptFunctionImpl.java	Mon Dec 09 09:48:11 2013 +0530
@@ -170,26 +170,6 @@
         boundfunctionmap$.setIsShared();
     }
 
-    // function object representing TypeErrorThrower
-    private static ScriptFunction typeErrorThrower;
-
-    /*
-     * ECMA section 13.2.3 The [[ThrowTypeError]] Function Object
-     */
-    static synchronized ScriptFunction getTypeErrorThrower() {
-        if (typeErrorThrower == null) {
-            // use "getter" so that [[ThrowTypeError]] function's arity is 0 - as specified in step 10 of section 13.2.3
-            final ScriptFunctionImpl func = new ScriptFunctionImpl("TypeErrorThrower", Lookup.TYPE_ERROR_THROWER_GETTER, null, null, false, false, false);
-            func.setPrototype(UNDEFINED);
-            // Non-constructor built-in functions do not have "prototype" property
-            func.deleteOwnProperty(func.getMap().findProperty("prototype"));
-            func.preventExtensions();
-            typeErrorThrower = func;
-        }
-
-        return typeErrorThrower;
-    }
-
     private static PropertyMap createStrictModeMap(final PropertyMap map) {
         final int flags = Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE;
         PropertyMap newMap = map;
@@ -313,12 +293,13 @@
         // We have to fill user accessor functions late as these are stored
         // in this object rather than in the PropertyMap of this object.
 
+        final ScriptFunction errorThrower = global.getTypeErrorThrower();
         if (findProperty("arguments", true) != null) {
-            setUserAccessors("arguments", getTypeErrorThrower(), getTypeErrorThrower());
+            setUserAccessors("arguments", errorThrower, errorThrower);
         }
 
         if (findProperty("caller", true) != null) {
-            setUserAccessors("caller", getTypeErrorThrower(), getTypeErrorThrower());
+            setUserAccessors("caller", errorThrower, errorThrower);
         }
     }
 }