8029612: the typeErrorThrower field in ScriptFunctionImpl cannot be static and common to all Globals

Mon, 09 Dec 2013 09:48:11 +0530

author
sundar
date
Mon, 09 Dec 2013 09:48:11 +0530
changeset 690
752554d45a07
parent 685
e0b4483668a7
child 691
739f3abdfa55
child 692
4706897b4dec

8029612: the typeErrorThrower field in ScriptFunctionImpl cannot be static and common to all Globals
Reviewed-by: attila, hannesw

src/jdk/nashorn/internal/objects/Global.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeStrictArguments.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/ScriptFunctionImpl.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/jdk/nashorn/internal/objects/Global.java	Tue Nov 26 11:58:20 2013 -0400
     1.2 +++ b/src/jdk/nashorn/internal/objects/Global.java	Mon Dec 09 09:48:11 2013 +0530
     1.3 @@ -44,6 +44,7 @@
     1.4  import java.util.concurrent.ConcurrentHashMap;
     1.5  import jdk.internal.dynalink.linker.GuardedInvocation;
     1.6  import jdk.internal.dynalink.linker.LinkRequest;
     1.7 +import jdk.nashorn.internal.lookup.Lookup;
     1.8  import jdk.nashorn.internal.objects.annotations.Attribute;
     1.9  import jdk.nashorn.internal.objects.annotations.Property;
    1.10  import jdk.nashorn.internal.objects.annotations.ScriptClass;
    1.11 @@ -364,6 +365,11 @@
    1.12      private ScriptObject   builtinFloat32Array;
    1.13      private ScriptObject   builtinFloat64Array;
    1.14  
    1.15 +    /*
    1.16 +     * ECMA section 13.2.3 The [[ThrowTypeError]] Function Object
    1.17 +     */
    1.18 +    private ScriptFunction typeErrorThrower;
    1.19 +
    1.20      private PropertyMap    accessorPropertyDescriptorMap;
    1.21      private PropertyMap    arrayBufferViewMap;
    1.22      private PropertyMap    dataPropertyDescriptorMap;
    1.23 @@ -1114,6 +1120,10 @@
    1.24          return builtinArray;
    1.25      }
    1.26  
    1.27 +    ScriptFunction getTypeErrorThrower() {
    1.28 +        return typeErrorThrower;
    1.29 +    }
    1.30 +
    1.31      /**
    1.32       * Called from compiled script code to test if builtin has been overridden
    1.33       *
    1.34 @@ -2000,6 +2010,13 @@
    1.35          anon.set("constructor", builtinFunction, false);
    1.36          anon.deleteOwnProperty(anon.getMap().findProperty("prototype"));
    1.37  
    1.38 +        // use "getter" so that [[ThrowTypeError]] function's arity is 0 - as specified in step 10 of section 13.2.3
    1.39 +        this.typeErrorThrower = new ScriptFunctionImpl("TypeErrorThrower", Lookup.TYPE_ERROR_THROWER_GETTER, null, null, false, false, false);
    1.40 +        typeErrorThrower.setPrototype(UNDEFINED);
    1.41 +        // Non-constructor built-in functions do not have "prototype" property
    1.42 +        typeErrorThrower.deleteOwnProperty(typeErrorThrower.getMap().findProperty("prototype"));
    1.43 +        typeErrorThrower.preventExtensions();
    1.44 +
    1.45          // now initialize Object
    1.46          this.builtinObject = (ScriptFunction)initConstructor("Object");
    1.47          final ScriptObject ObjectPrototype = getObjectPrototype();
     2.1 --- a/src/jdk/nashorn/internal/objects/NativeStrictArguments.java	Tue Nov 26 11:58:20 2013 -0400
     2.2 +++ b/src/jdk/nashorn/internal/objects/NativeStrictArguments.java	Mon Dec 09 09:48:11 2013 +0530
     2.3 @@ -76,7 +76,7 @@
     2.4          super(proto, map);
     2.5          setIsArguments();
     2.6  
     2.7 -        final ScriptFunction func = ScriptFunctionImpl.getTypeErrorThrower();
     2.8 +        final ScriptFunction func = Global.instance().getTypeErrorThrower();
     2.9          // We have to fill user accessor functions late as these are stored
    2.10          // in this object rather than in the PropertyMap of this object.
    2.11          setUserAccessors("caller", func, func);
     3.1 --- a/src/jdk/nashorn/internal/objects/ScriptFunctionImpl.java	Tue Nov 26 11:58:20 2013 -0400
     3.2 +++ b/src/jdk/nashorn/internal/objects/ScriptFunctionImpl.java	Mon Dec 09 09:48:11 2013 +0530
     3.3 @@ -170,26 +170,6 @@
     3.4          boundfunctionmap$.setIsShared();
     3.5      }
     3.6  
     3.7 -    // function object representing TypeErrorThrower
     3.8 -    private static ScriptFunction typeErrorThrower;
     3.9 -
    3.10 -    /*
    3.11 -     * ECMA section 13.2.3 The [[ThrowTypeError]] Function Object
    3.12 -     */
    3.13 -    static synchronized ScriptFunction getTypeErrorThrower() {
    3.14 -        if (typeErrorThrower == null) {
    3.15 -            // use "getter" so that [[ThrowTypeError]] function's arity is 0 - as specified in step 10 of section 13.2.3
    3.16 -            final ScriptFunctionImpl func = new ScriptFunctionImpl("TypeErrorThrower", Lookup.TYPE_ERROR_THROWER_GETTER, null, null, false, false, false);
    3.17 -            func.setPrototype(UNDEFINED);
    3.18 -            // Non-constructor built-in functions do not have "prototype" property
    3.19 -            func.deleteOwnProperty(func.getMap().findProperty("prototype"));
    3.20 -            func.preventExtensions();
    3.21 -            typeErrorThrower = func;
    3.22 -        }
    3.23 -
    3.24 -        return typeErrorThrower;
    3.25 -    }
    3.26 -
    3.27      private static PropertyMap createStrictModeMap(final PropertyMap map) {
    3.28          final int flags = Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE;
    3.29          PropertyMap newMap = map;
    3.30 @@ -313,12 +293,13 @@
    3.31          // We have to fill user accessor functions late as these are stored
    3.32          // in this object rather than in the PropertyMap of this object.
    3.33  
    3.34 +        final ScriptFunction errorThrower = global.getTypeErrorThrower();
    3.35          if (findProperty("arguments", true) != null) {
    3.36 -            setUserAccessors("arguments", getTypeErrorThrower(), getTypeErrorThrower());
    3.37 +            setUserAccessors("arguments", errorThrower, errorThrower);
    3.38          }
    3.39  
    3.40          if (findProperty("caller", true) != null) {
    3.41 -            setUserAccessors("caller", getTypeErrorThrower(), getTypeErrorThrower());
    3.42 +            setUserAccessors("caller", errorThrower, errorThrower);
    3.43          }
    3.44      }
    3.45  }

mercurial