Tue, 01 Apr 2014 11:44:05 -0700
Merge
src/jdk/nashorn/internal/runtime/GlobalObject.java | file | annotate | diff | comparison | revisions | |
src/jdk/nashorn/internal/runtime/PropertyListener.java | file | annotate | diff | comparison | revisions | |
src/jdk/nashorn/internal/runtime/PropertyListenerManager.java | file | annotate | diff | comparison | revisions |
1.1 --- a/README Wed Mar 26 12:01:34 2014 -0700 1.2 +++ b/README Tue Apr 01 11:44:05 2014 -0700 1.3 @@ -81,13 +81,13 @@ 1.4 1.5 After that, you can run the tests using: 1.6 cd make 1.7 - ant test 1.8 + ant clean test 1.9 1.10 You can also run the ECMA-262 test suite with Nashorn. In order to do 1.11 that, you will need to get a copy of it and put it in 1.12 test/script/external/test262 directory. A convenient way to do it is: 1.13 1.14 - hg clone http://hg.ecmascript.org/tests/test262/ test/script/external/test262 1.15 + git clone https://github.com/tc39/test262 test/script/external/test262 1.16 1.17 Alternatively, you can check it out elsewhere and make 1.18 test/script/external/test262 a symbolic link to that directory. After 1.19 @@ -95,6 +95,11 @@ 1.20 1.21 cd nashorn~jdk8/nashorn/make 1.22 ant test262 1.23 + 1.24 +Ant target to get/update external test suites: 1.25 + 1.26 + ant externals 1.27 + ant update-externals 1.28 1.29 These tests take time, so we have a parallelized runner for them that 1.30 takes advantage of all processor cores on the computer:
2.1 --- a/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/ClassGenerator.java Wed Mar 26 12:01:34 2014 -0700 2.2 +++ b/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/ClassGenerator.java Tue Apr 01 11:44:05 2014 -0700 2.3 @@ -50,8 +50,6 @@ 2.4 import static jdk.nashorn.internal.tools.nasgen.StringConstants.COLLECTIONS_EMPTY_LIST; 2.5 import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_DESC; 2.6 import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_FIELD_NAME; 2.7 -import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_SETISSHARED; 2.8 -import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_SETISSHARED_DESC; 2.9 import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_NEWMAP; 2.10 import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_NEWMAP_DESC; 2.11 import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_TYPE; 2.12 @@ -191,8 +189,6 @@ 2.13 // stack: Collection 2.14 // pmap = PropertyMap.newMap(Collection<Property>); 2.15 mi.invokeStatic(PROPERTYMAP_TYPE, PROPERTYMAP_NEWMAP, PROPERTYMAP_NEWMAP_DESC); 2.16 - // pmap.setIsShared(); 2.17 - mi.invokeVirtual(PROPERTYMAP_TYPE, PROPERTYMAP_SETISSHARED, PROPERTYMAP_SETISSHARED_DESC); 2.18 // $nasgenmap$ = pmap; 2.19 mi.putStatic(className, PROPERTYMAP_FIELD_NAME, PROPERTYMAP_DESC); 2.20 mi.returnVoid();
3.1 --- a/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/ConstructorGenerator.java Wed Mar 26 12:01:34 2014 -0700 3.2 +++ b/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/ConstructorGenerator.java Tue Apr 01 11:44:05 2014 -0700 3.3 @@ -33,10 +33,7 @@ 3.4 import static jdk.nashorn.internal.tools.nasgen.StringConstants.DEFAULT_INIT_DESC; 3.5 import static jdk.nashorn.internal.tools.nasgen.StringConstants.INIT; 3.6 import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_DESC; 3.7 -import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_DUPLICATE; 3.8 -import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_DUPLICATE_DESC; 3.9 import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_FIELD_NAME; 3.10 -import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_TYPE; 3.11 import static jdk.nashorn.internal.tools.nasgen.StringConstants.OBJECT_DESC; 3.12 import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROTOTYPEOBJECT_SETCONSTRUCTOR; 3.13 import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROTOTYPEOBJECT_SETCONSTRUCTOR_DESC; 3.14 @@ -171,9 +168,6 @@ 3.15 private void loadMap(final MethodGenerator mi) { 3.16 if (memberCount > 0) { 3.17 mi.getStatic(className, PROPERTYMAP_FIELD_NAME, PROPERTYMAP_DESC); 3.18 - // make sure we use duplicated PropertyMap so that original map 3.19 - // stays intact and so can be used for many globals. 3.20 - mi.invokeVirtual(PROPERTYMAP_TYPE, PROPERTYMAP_DUPLICATE, PROPERTYMAP_DUPLICATE_DESC); 3.21 } 3.22 } 3.23
4.1 --- a/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/MemberInfo.java Wed Mar 26 12:01:34 2014 -0700 4.2 +++ b/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/MemberInfo.java Tue Apr 01 11:44:05 2014 -0700 4.3 @@ -22,40 +22,62 @@ 4.4 * or visit www.oracle.com if you need additional information or have any 4.5 * questions. 4.6 */ 4.7 - 4.8 package jdk.nashorn.internal.tools.nasgen; 4.9 4.10 import static jdk.nashorn.internal.tools.nasgen.StringConstants.OBJECT_ARRAY_DESC; 4.11 import static jdk.nashorn.internal.tools.nasgen.StringConstants.OBJECT_DESC; 4.12 +import static jdk.nashorn.internal.tools.nasgen.StringConstants.SCRIPTOBJECT_DESC; 4.13 +import static jdk.nashorn.internal.tools.nasgen.StringConstants.STRING_DESC; 4.14 4.15 import jdk.internal.org.objectweb.asm.Opcodes; 4.16 import jdk.internal.org.objectweb.asm.Type; 4.17 import jdk.nashorn.internal.objects.annotations.Where; 4.18 +import jdk.nashorn.internal.runtime.ScriptObject; 4.19 4.20 /** 4.21 * Details about a Java method or field annotated with any of the field/method 4.22 * annotations from the jdk.nashorn.internal.objects.annotations package. 4.23 */ 4.24 public final class MemberInfo implements Cloneable { 4.25 + // class loader of this class 4.26 + private static ClassLoader myLoader = MemberInfo.class.getClassLoader(); 4.27 + 4.28 /** 4.29 * The different kinds of available class annotations 4.30 */ 4.31 public static enum Kind { 4.32 - /** This is a script class */ 4.33 + 4.34 + /** 4.35 + * This is a script class 4.36 + */ 4.37 SCRIPT_CLASS, 4.38 - /** This is a constructor */ 4.39 + /** 4.40 + * This is a constructor 4.41 + */ 4.42 CONSTRUCTOR, 4.43 - /** This is a function */ 4.44 + /** 4.45 + * This is a function 4.46 + */ 4.47 FUNCTION, 4.48 - /** This is a getter */ 4.49 + /** 4.50 + * This is a getter 4.51 + */ 4.52 GETTER, 4.53 - /** This is a setter */ 4.54 + /** 4.55 + * This is a setter 4.56 + */ 4.57 SETTER, 4.58 - /** This is a property */ 4.59 + /** 4.60 + * This is a property 4.61 + */ 4.62 PROPERTY, 4.63 - /** This is a specialized version of a function */ 4.64 + /** 4.65 + * This is a specialized version of a function 4.66 + */ 4.67 SPECIALIZED_FUNCTION, 4.68 - /** This is a specialized version of a constructor */ 4.69 + /** 4.70 + * This is a specialized version of a constructor 4.71 + */ 4.72 SPECIALIZED_CONSTRUCTOR 4.73 } 4.74 4.75 @@ -194,6 +216,7 @@ 4.76 4.77 /** 4.78 * Check whether this MemberInfo is a getter that resides in the instance 4.79 + * 4.80 * @return true if instance setter 4.81 */ 4.82 boolean isInstanceSetter() { 4.83 @@ -245,96 +268,201 @@ 4.84 } 4.85 4.86 void verify() { 4.87 - if (kind == Kind.CONSTRUCTOR) { 4.88 - final Type returnType = Type.getReturnType(javaDesc); 4.89 - if (! returnType.toString().equals(OBJECT_DESC)) { 4.90 - error("return value should be of Object type, found" + returnType); 4.91 - } 4.92 - final Type[] argTypes = Type.getArgumentTypes(javaDesc); 4.93 - if (argTypes.length < 2) { 4.94 - error("constructor methods should have at least 2 args"); 4.95 - } 4.96 - if (! argTypes[0].equals(Type.BOOLEAN_TYPE)) { 4.97 - error("first argument should be of boolean type, found" + argTypes[0]); 4.98 - } 4.99 - if (! argTypes[1].toString().equals(OBJECT_DESC)) { 4.100 - error("second argument should be of Object type, found" + argTypes[0]); 4.101 - } 4.102 + switch (kind) { 4.103 + case CONSTRUCTOR: { 4.104 + final Type returnType = Type.getReturnType(javaDesc); 4.105 + if (!isJSObjectType(returnType)) { 4.106 + error("return value of a @Constructor method should be of Object type, found " + returnType); 4.107 + } 4.108 + final Type[] argTypes = Type.getArgumentTypes(javaDesc); 4.109 + if (argTypes.length < 2) { 4.110 + error("@Constructor methods should have at least 2 args"); 4.111 + } 4.112 + if (!argTypes[0].equals(Type.BOOLEAN_TYPE)) { 4.113 + error("first argument of a @Constructor method should be of boolean type, found " + argTypes[0]); 4.114 + } 4.115 + if (!isJavaLangObject(argTypes[1])) { 4.116 + error("second argument of a @Constructor method should be of Object type, found " + argTypes[0]); 4.117 + } 4.118 4.119 - if (argTypes.length > 2) { 4.120 - for (int i = 2; i < argTypes.length - 1; i++) { 4.121 - if (! argTypes[i].toString().equals(OBJECT_DESC)) { 4.122 - error(i + "'th argument should be of Object type, found " + argTypes[i]); 4.123 + if (argTypes.length > 2) { 4.124 + for (int i = 2; i < argTypes.length - 1; i++) { 4.125 + if (!isJavaLangObject(argTypes[i])) { 4.126 + error(i + "'th argument of a @Constructor method should be of Object type, found " + argTypes[i]); 4.127 + } 4.128 + } 4.129 + 4.130 + final String lastArgTypeDesc = argTypes[argTypes.length - 1].getDescriptor(); 4.131 + final boolean isVarArg = lastArgTypeDesc.equals(OBJECT_ARRAY_DESC); 4.132 + if (!lastArgTypeDesc.equals(OBJECT_DESC) && !isVarArg) { 4.133 + error("last argument of a @Constructor method is neither Object nor Object[] type: " + lastArgTypeDesc); 4.134 + } 4.135 + 4.136 + if (isVarArg && argTypes.length > 3) { 4.137 + error("vararg of a @Constructor method has more than 3 arguments"); 4.138 } 4.139 } 4.140 - 4.141 - final String lastArgType = argTypes[argTypes.length - 1].toString(); 4.142 - final boolean isVarArg = lastArgType.equals(OBJECT_ARRAY_DESC); 4.143 - if (!lastArgType.equals(OBJECT_DESC) && !isVarArg) { 4.144 - error("last argument is neither Object nor Object[] type: " + lastArgType); 4.145 + } 4.146 + break; 4.147 + case SPECIALIZED_CONSTRUCTOR: { 4.148 + final Type returnType = Type.getReturnType(javaDesc); 4.149 + if (!isJSObjectType(returnType)) { 4.150 + error("return value of a @SpecializedConstructor method should be a valid JS type, found " + returnType); 4.151 + } 4.152 + final Type[] argTypes = Type.getArgumentTypes(javaDesc); 4.153 + for (int i = 0; i < argTypes.length; i++) { 4.154 + if (!isValidJSType(argTypes[i])) { 4.155 + error(i + "'th argument of a @SpecializedConstructor method is not valid JS type, found " + argTypes[i]); 4.156 + } 4.157 + } 4.158 + } 4.159 + break; 4.160 + case FUNCTION: { 4.161 + final Type returnType = Type.getReturnType(javaDesc); 4.162 + if (!isValidJSType(returnType)) { 4.163 + error("return value of a @Function method should be a valid JS type, found " + returnType); 4.164 + } 4.165 + final Type[] argTypes = Type.getArgumentTypes(javaDesc); 4.166 + if (argTypes.length < 1) { 4.167 + error("@Function methods should have at least 1 arg"); 4.168 + } 4.169 + if (!isJavaLangObject(argTypes[0])) { 4.170 + error("first argument of a @Function method should be of Object type, found " + argTypes[0]); 4.171 } 4.172 4.173 - if (isVarArg && argTypes.length > 3) { 4.174 - error("vararg constructor has more than 3 arguments"); 4.175 + if (argTypes.length > 1) { 4.176 + for (int i = 1; i < argTypes.length - 1; i++) { 4.177 + if (!isJavaLangObject(argTypes[i])) { 4.178 + error(i + "'th argument of a @Function method should be of Object type, found " + argTypes[i]); 4.179 + } 4.180 + } 4.181 + 4.182 + final String lastArgTypeDesc = argTypes[argTypes.length - 1].getDescriptor(); 4.183 + final boolean isVarArg = lastArgTypeDesc.equals(OBJECT_ARRAY_DESC); 4.184 + if (!lastArgTypeDesc.equals(OBJECT_DESC) && !isVarArg) { 4.185 + error("last argument of a @Function method is neither Object nor Object[] type: " + lastArgTypeDesc); 4.186 + } 4.187 + 4.188 + if (isVarArg && argTypes.length > 2) { 4.189 + error("vararg @Function method has more than 2 arguments"); 4.190 + } 4.191 } 4.192 } 4.193 - } else if (kind == Kind.FUNCTION) { 4.194 - final Type returnType = Type.getReturnType(javaDesc); 4.195 - if (! returnType.toString().equals(OBJECT_DESC)) { 4.196 - error("return value should be of Object type, found" + returnType); 4.197 - } 4.198 - final Type[] argTypes = Type.getArgumentTypes(javaDesc); 4.199 - if (argTypes.length < 1) { 4.200 - error("function methods should have at least 1 arg"); 4.201 - } 4.202 - if (! argTypes[0].toString().equals(OBJECT_DESC)) { 4.203 - error("first argument should be of Object type, found" + argTypes[0]); 4.204 - } 4.205 - 4.206 - if (argTypes.length > 1) { 4.207 - for (int i = 1; i < argTypes.length - 1; i++) { 4.208 - if (! argTypes[i].toString().equals(OBJECT_DESC)) { 4.209 - error(i + "'th argument should be of Object type, found " + argTypes[i]); 4.210 + break; 4.211 + case SPECIALIZED_FUNCTION: { 4.212 + final Type returnType = Type.getReturnType(javaDesc); 4.213 + if (!isValidJSType(returnType)) { 4.214 + error("return value of a @SpecializedFunction method should be a valid JS type, found " + returnType); 4.215 + } 4.216 + final Type[] argTypes = Type.getArgumentTypes(javaDesc); 4.217 + for (int i = 0; i < argTypes.length; i++) { 4.218 + if (!isValidJSType(argTypes[i])) { 4.219 + error(i + "'th argument of a @SpecializedFunction method is not valid JS type, found " + argTypes[i]); 4.220 } 4.221 } 4.222 - 4.223 - final String lastArgType = argTypes[argTypes.length - 1].toString(); 4.224 - final boolean isVarArg = lastArgType.equals(OBJECT_ARRAY_DESC); 4.225 - if (!lastArgType.equals(OBJECT_DESC) && !isVarArg) { 4.226 - error("last argument is neither Object nor Object[] type: " + lastArgType); 4.227 + } 4.228 + break; 4.229 + case GETTER: { 4.230 + final Type[] argTypes = Type.getArgumentTypes(javaDesc); 4.231 + if (argTypes.length != 1) { 4.232 + error("@Getter methods should have one argument"); 4.233 + } 4.234 + if (!isJavaLangObject(argTypes[0])) { 4.235 + error("first argument of a @Getter method should be of Object type, found: " + argTypes[0]); 4.236 } 4.237 4.238 - if (isVarArg && argTypes.length > 2) { 4.239 - error("vararg function has more than 2 arguments"); 4.240 + final Type returnType = Type.getReturnType(javaDesc); 4.241 + if (!isJavaLangObject(returnType)) { 4.242 + error("return type of a @Getter method should be Object, found: " + javaDesc); 4.243 } 4.244 } 4.245 - } else if (kind == Kind.GETTER) { 4.246 - final Type[] argTypes = Type.getArgumentTypes(javaDesc); 4.247 - if (argTypes.length != 1) { 4.248 - error("getter methods should have one argument"); 4.249 + break; 4.250 + case SETTER: { 4.251 + final Type[] argTypes = Type.getArgumentTypes(javaDesc); 4.252 + if (argTypes.length != 2) { 4.253 + error("@Setter methods should have two arguments"); 4.254 + } 4.255 + if (!isJavaLangObject(argTypes[0])) { 4.256 + error("first argument of a @Setter method should be of Object type, found: " + argTypes[0]); 4.257 + } 4.258 + if (!Type.getReturnType(javaDesc).toString().equals("V")) { 4.259 + error("return type of of a @Setter method should be void, found: " + Type.getReturnType(javaDesc)); 4.260 + } 4.261 } 4.262 - if (! argTypes[0].toString().equals(OBJECT_DESC)) { 4.263 - error("first argument of getter should be of Object type, found: " + argTypes[0]); 4.264 - } 4.265 - if (Type.getReturnType(javaDesc).equals(Type.VOID_TYPE)) { 4.266 - error("return type of getter should not be void"); 4.267 - } 4.268 - } else if (kind == Kind.SETTER) { 4.269 - final Type[] argTypes = Type.getArgumentTypes(javaDesc); 4.270 - if (argTypes.length != 2) { 4.271 - error("setter methods should have two arguments"); 4.272 - } 4.273 - if (! argTypes[0].toString().equals(OBJECT_DESC)) { 4.274 - error("first argument of setter should be of Object type, found: " + argTypes[0]); 4.275 - } 4.276 - if (!Type.getReturnType(javaDesc).toString().equals("V")) { 4.277 - error("return type of setter should be void, found: " + Type.getReturnType(javaDesc)); 4.278 + break; 4.279 + case PROPERTY: { 4.280 + if (where == Where.CONSTRUCTOR) { 4.281 + if (isStatic()) { 4.282 + if (!isFinal()) { 4.283 + error("static Where.CONSTRUCTOR @Property should be final"); 4.284 + } 4.285 + 4.286 + if (!isJSPrimitiveType(Type.getType(javaDesc))) { 4.287 + error("static Where.CONSTRUCTOR @Property should be a JS primitive"); 4.288 + } 4.289 + } 4.290 + } else if (where == Where.PROTOTYPE) { 4.291 + if (isStatic()) { 4.292 + if (!isFinal()) { 4.293 + error("static Where.PROTOTYPE @Property should be final"); 4.294 + } 4.295 + 4.296 + if (!isJSPrimitiveType(Type.getType(javaDesc))) { 4.297 + error("static Where.PROTOTYPE @Property should be a JS primitive"); 4.298 + } 4.299 + } 4.300 + } 4.301 } 4.302 } 4.303 } 4.304 4.305 + private static boolean isValidJSType(final Type type) { 4.306 + return isJSPrimitiveType(type) || isJSObjectType(type); 4.307 + } 4.308 + 4.309 + private static boolean isJSPrimitiveType(final Type type) { 4.310 + switch (type.getSort()) { 4.311 + case Type.BOOLEAN: 4.312 + case Type.INT: 4.313 + case Type.LONG: 4.314 + case Type.DOUBLE: 4.315 + return true; 4.316 + default: 4.317 + return false; 4.318 + } 4.319 + } 4.320 + 4.321 + private static boolean isJSObjectType(final Type type) { 4.322 + return isJavaLangObject(type) || isJavaLangString(type) || isScriptObject(type); 4.323 + } 4.324 + 4.325 + private static boolean isJavaLangObject(final Type type) { 4.326 + return type.getDescriptor().equals(OBJECT_DESC); 4.327 + } 4.328 + 4.329 + private static boolean isJavaLangString(final Type type) { 4.330 + return type.getDescriptor().equals(STRING_DESC); 4.331 + } 4.332 + 4.333 + private static boolean isScriptObject(final Type type) { 4.334 + if (type.getDescriptor().equals(SCRIPTOBJECT_DESC)) { 4.335 + return true; 4.336 + } 4.337 + 4.338 + if (type.getSort() == Type.OBJECT) { 4.339 + try { 4.340 + final Class clazz = Class.forName(type.getClassName(), false, myLoader); 4.341 + return ScriptObject.class.isAssignableFrom(clazz); 4.342 + } catch (final ClassNotFoundException cnfe) { 4.343 + return false; 4.344 + } 4.345 + } 4.346 + 4.347 + return false; 4.348 + } 4.349 + 4.350 private void error(final String msg) { 4.351 - throw new RuntimeException(javaName + javaDesc + " : " + msg); 4.352 + throw new RuntimeException(javaName + " of type " + javaDesc + " : " + msg); 4.353 } 4.354 4.355 /**
5.1 --- a/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/MethodGenerator.java Wed Mar 26 12:01:34 2014 -0700 5.2 +++ b/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/MethodGenerator.java Tue Apr 01 11:44:05 2014 -0700 5.3 @@ -349,19 +349,19 @@ 5.4 5.5 // invokes, field get/sets 5.6 void invokeInterface(final String owner, final String method, final String desc) { 5.7 - super.visitMethodInsn(INVOKEINTERFACE, owner, method, desc); 5.8 + super.visitMethodInsn(INVOKEINTERFACE, owner, method, desc, true); 5.9 } 5.10 5.11 void invokeVirtual(final String owner, final String method, final String desc) { 5.12 - super.visitMethodInsn(INVOKEVIRTUAL, owner, method, desc); 5.13 + super.visitMethodInsn(INVOKEVIRTUAL, owner, method, desc, false); 5.14 } 5.15 5.16 void invokeSpecial(final String owner, final String method, final String desc) { 5.17 - super.visitMethodInsn(INVOKESPECIAL, owner, method, desc); 5.18 + super.visitMethodInsn(INVOKESPECIAL, owner, method, desc, false); 5.19 } 5.20 5.21 void invokeStatic(final String owner, final String method, final String desc) { 5.22 - super.visitMethodInsn(INVOKESTATIC, owner, method, desc); 5.23 + super.visitMethodInsn(INVOKESTATIC, owner, method, desc, false); 5.24 } 5.25 5.26 void putStatic(final String owner, final String field, final String desc) { 5.27 @@ -413,7 +413,7 @@ 5.28 super.visitMethodInsn(INVOKEVIRTUAL, 5.29 "java/io/PrintStream", 5.30 "println", 5.31 - "(Ljava/lang/String;)V"); 5.32 + "(Ljava/lang/String;)V", false); 5.33 } 5.34 5.35 // print the object on the top of the stack 5.36 @@ -426,6 +426,6 @@ 5.37 super.visitMethodInsn(INVOKEVIRTUAL, 5.38 "java/io/PrintStream", 5.39 "println", 5.40 - "(Ljava/lang/Object;)V"); 5.41 + "(Ljava/lang/Object;)V", false); 5.42 } 5.43 }
6.1 --- a/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/PrototypeGenerator.java Wed Mar 26 12:01:34 2014 -0700 6.2 +++ b/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/PrototypeGenerator.java Tue Apr 01 11:44:05 2014 -0700 6.3 @@ -32,10 +32,7 @@ 6.4 import static jdk.nashorn.internal.tools.nasgen.StringConstants.DEFAULT_INIT_DESC; 6.5 import static jdk.nashorn.internal.tools.nasgen.StringConstants.INIT; 6.6 import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_DESC; 6.7 -import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_DUPLICATE; 6.8 -import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_DUPLICATE_DESC; 6.9 import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_FIELD_NAME; 6.10 -import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_TYPE; 6.11 import static jdk.nashorn.internal.tools.nasgen.StringConstants.OBJECT_DESC; 6.12 import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROTOTYPEOBJECT_TYPE; 6.13 import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROTOTYPE_SUFFIX; 6.14 @@ -129,7 +126,6 @@ 6.15 mi.getStatic(className, PROPERTYMAP_FIELD_NAME, PROPERTYMAP_DESC); 6.16 // make sure we use duplicated PropertyMap so that original map 6.17 // stays intact and so can be used for many global. 6.18 - mi.invokeVirtual(PROPERTYMAP_TYPE, PROPERTYMAP_DUPLICATE, PROPERTYMAP_DUPLICATE_DESC); 6.19 mi.invokeSpecial(PROTOTYPEOBJECT_TYPE, INIT, SCRIPTOBJECT_INIT_DESC); 6.20 // initialize Function type fields 6.21 initFunctionFields(mi);
7.1 --- a/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/ScriptClassInstrumentor.java Wed Mar 26 12:01:34 2014 -0700 7.2 +++ b/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/ScriptClassInstrumentor.java Tue Apr 01 11:44:05 2014 -0700 7.3 @@ -146,16 +146,16 @@ 7.4 // call $clinit$ just before return from <clinit> 7.5 if (isStaticInit && opcode == RETURN) { 7.6 super.visitMethodInsn(INVOKESTATIC, scriptClassInfo.getJavaName(), 7.7 - $CLINIT$, DEFAULT_INIT_DESC); 7.8 + $CLINIT$, DEFAULT_INIT_DESC, false); 7.9 } 7.10 super.visitInsn(opcode); 7.11 } 7.12 7.13 @Override 7.14 - public void visitMethodInsn(final int opcode, final String owner, final String name, final String desc) { 7.15 + public void visitMethodInsn(final int opcode, final String owner, final String name, final String desc, final boolean itf) { 7.16 if (isConstructor && opcode == INVOKESPECIAL && 7.17 INIT.equals(name) && SCRIPTOBJECT_TYPE.equals(owner)) { 7.18 - super.visitMethodInsn(opcode, owner, name, desc); 7.19 + super.visitMethodInsn(opcode, owner, name, desc, false); 7.20 7.21 if (memberCount > 0) { 7.22 // initialize @Property fields if needed 7.23 @@ -166,7 +166,7 @@ 7.24 super.visitTypeInsn(NEW, clazz); 7.25 super.visitInsn(DUP); 7.26 super.visitMethodInsn(INVOKESPECIAL, clazz, 7.27 - INIT, DEFAULT_INIT_DESC); 7.28 + INIT, DEFAULT_INIT_DESC, false); 7.29 super.visitFieldInsn(PUTFIELD, scriptClassInfo.getJavaName(), 7.30 memInfo.getJavaName(), memInfo.getJavaDesc()); 7.31 } 7.32 @@ -180,7 +180,7 @@ 7.33 } 7.34 } 7.35 } else { 7.36 - super.visitMethodInsn(opcode, owner, name, desc); 7.37 + super.visitMethodInsn(opcode, owner, name, desc, itf); 7.38 } 7.39 } 7.40
8.1 --- a/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/StringConstants.java Wed Mar 26 12:01:34 2014 -0700 8.2 +++ b/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/StringConstants.java Tue Apr 01 11:44:05 2014 -0700 8.3 @@ -45,11 +45,9 @@ 8.4 @SuppressWarnings("javadoc") 8.5 public interface StringConstants { 8.6 // standard jdk types, methods 8.7 - static final Type TYPE_METHOD = Type.getType(Method.class); 8.8 static final Type TYPE_METHODHANDLE = Type.getType(MethodHandle.class); 8.9 static final Type TYPE_METHODHANDLE_ARRAY = Type.getType(MethodHandle[].class); 8.10 static final Type TYPE_OBJECT = Type.getType(Object.class); 8.11 - static final Type TYPE_CLASS = Type.getType(Class.class); 8.12 static final Type TYPE_STRING = Type.getType(String.class); 8.13 static final Type TYPE_COLLECTION = Type.getType(Collection.class); 8.14 static final Type TYPE_COLLECTIONS = Type.getType(Collections.class); 8.15 @@ -63,6 +61,8 @@ 8.16 static final String METHODHANDLE_TYPE = TYPE_METHODHANDLE.getInternalName(); 8.17 static final String OBJECT_TYPE = TYPE_OBJECT.getInternalName(); 8.18 static final String OBJECT_DESC = TYPE_OBJECT.getDescriptor(); 8.19 + static final String STRING_TYPE = TYPE_STRING.getInternalName(); 8.20 + static final String STRING_DESC = TYPE_STRING.getDescriptor(); 8.21 static final String OBJECT_ARRAY_DESC = Type.getDescriptor(Object[].class); 8.22 static final String ARRAYLIST_TYPE = TYPE_ARRAYLIST.getInternalName(); 8.23 static final String COLLECTION_TYPE = TYPE_COLLECTION.getInternalName(); 8.24 @@ -104,10 +104,6 @@ 8.25 static final String PROPERTYMAP_DESC = TYPE_PROPERTYMAP.getDescriptor(); 8.26 static final String PROPERTYMAP_NEWMAP = "newMap"; 8.27 static final String PROPERTYMAP_NEWMAP_DESC = Type.getMethodDescriptor(TYPE_PROPERTYMAP, TYPE_COLLECTION); 8.28 - static final String PROPERTYMAP_DUPLICATE = "duplicate"; 8.29 - static final String PROPERTYMAP_DUPLICATE_DESC = Type.getMethodDescriptor(TYPE_PROPERTYMAP); 8.30 - static final String PROPERTYMAP_SETISSHARED = "setIsShared"; 8.31 - static final String PROPERTYMAP_SETISSHARED_DESC = Type.getMethodDescriptor(TYPE_PROPERTYMAP); 8.32 8.33 // PrototypeObject 8.34 static final String PROTOTYPEOBJECT_TYPE = TYPE_PROTOTYPEOBJECT.getInternalName(); 8.35 @@ -135,6 +131,7 @@ 8.36 8.37 // ScriptObject 8.38 static final String SCRIPTOBJECT_TYPE = TYPE_SCRIPTOBJECT.getInternalName(); 8.39 + static final String SCRIPTOBJECT_DESC = TYPE_SCRIPTOBJECT.getDescriptor(); 8.40 static final String SCRIPTOBJECT_INIT_DESC = Type.getMethodDescriptor(Type.VOID_TYPE, TYPE_PROPERTYMAP); 8.41 8.42 static final String GETTER_PREFIX = "G$";
9.1 --- a/make/BuildNashorn.gmk Wed Mar 26 12:01:34 2014 -0700 9.2 +++ b/make/BuildNashorn.gmk Tue Apr 01 11:44:05 2014 -0700 9.3 @@ -77,7 +77,7 @@ 9.4 $(RM) -rf $(@D)/jdk $(@D)/netscape 9.5 $(CP) -R -p $(NASHORN_OUTPUTDIR)/nashorn_classes/* $(@D)/ 9.6 $(FIXPATH) $(JAVA) \ 9.7 - -cp "$(NASHORN_OUTPUTDIR)/nasgen_classes$(PATH_SEP)$(NASHORN_OUTPUTDIR)/nashorn_classes" \ 9.8 + -Xbootclasspath/p:"$(NASHORN_OUTPUTDIR)/nasgen_classes$(PATH_SEP)$(NASHORN_OUTPUTDIR)/nashorn_classes" \ 9.9 jdk.nashorn.internal.tools.nasgen.Main $(@D) jdk.nashorn.internal.objects $(@D) 9.10 $(TOUCH) $@ 9.11
10.1 --- a/make/build.xml Wed Mar 26 12:01:34 2014 -0700 10.2 +++ b/make/build.xml Tue Apr 01 11:44:05 2014 -0700 10.3 @@ -42,6 +42,9 @@ 10.4 <condition property="hg.executable" value="/usr/local/bin/hg" else="hg"> 10.5 <available file="/usr/local/bin/hg"/> 10.6 </condition> 10.7 + <condition property="git.executable" value="/usr/local/bin/git" else="git"> 10.8 + <available file="/usr/local/bin/git"/> 10.9 + </condition> 10.10 <!-- check if JDK already has ASM classes --> 10.11 <available property="asm.available" classname="jdk.internal.org.objectweb.asm.Type"/> 10.12 <!-- check if testng.jar is avaiable --> 10.13 @@ -122,6 +125,7 @@ 10.14 <compilerarg value="-Xlint:unchecked"/> 10.15 <compilerarg value="-Xlint:deprecation"/> 10.16 <compilerarg value="-XDignore.symbol.file"/> 10.17 + <compilerarg value="-Xdiags:verbose"/> 10.18 </javac> 10.19 <copy todir="${build.classes.dir}/META-INF/services"> 10.20 <fileset dir="${meta.inf.dir}/services/"/> 10.21 @@ -240,6 +244,7 @@ 10.22 <compilerarg value="-J-Djava.ext.dirs="/> 10.23 <compilerarg value="-Xlint:unchecked"/> 10.24 <compilerarg value="-Xlint:deprecation"/> 10.25 + <compilerarg value="-Xdiags:verbose"/> 10.26 </javac> 10.27 10.28 <copy todir="${build.test.classes.dir}/META-INF/services"> 10.29 @@ -250,6 +255,10 @@ 10.30 <fileset dir="${test.src.dir}/jdk/nashorn/internal/runtime/resources"/> 10.31 </copy> 10.32 10.33 + <copy todir="${build.test.classes.dir}/jdk/nashorn/api/scripting/resources"> 10.34 + <fileset dir="${test.src.dir}/jdk/nashorn/api/scripting/resources"/> 10.35 + </copy> 10.36 + 10.37 <!-- tests that check nashorn internals and internal API --> 10.38 <jar jarfile="${nashorn.internal.tests.jar}"> 10.39 <fileset dir="${build.test.classes.dir}" excludes="**/api/**"/> 10.40 @@ -279,6 +288,11 @@ 10.41 permission java.security.AllPermission; 10.42 }; 10.43 10.44 +grant codeBase "file:/${basedir}/test/script/maptests/*" { 10.45 + permission java.io.FilePermission "${basedir}/test/script/maptests/*","read"; 10.46 + permission java.lang.RuntimePermission "nashorn.debugMode"; 10.47 +}; 10.48 + 10.49 grant codeBase "file:/${basedir}/test/script/basic/*" { 10.50 permission java.io.FilePermission "${basedir}/test/script/-", "read"; 10.51 permission java.io.FilePermission "$${user.dir}", "read"; 10.52 @@ -459,18 +473,17 @@ 10.53 10.54 <!-- test262 test suite --> 10.55 <target name="get-test262" depends="init" unless="${test-sys-prop.external.test262}"> 10.56 - <!-- clone test262 mercurial repo --> 10.57 - <exec executable="${hg.executable}"> 10.58 + <!-- clone test262 git repo --> 10.59 + <exec executable="${git.executable}"> 10.60 <arg value="clone"/> 10.61 - <arg value="http://hg.ecmascript.org/tests/test262"/> 10.62 + <arg value="https://github.com/tc39/test262"/> 10.63 <arg value="${test.external.dir}/test262"/> 10.64 </exec> 10.65 </target> 10.66 <target name="update-test262" depends="init" if="${test-sys-prop.external.test262}"> 10.67 - <!-- update test262 mercurial repo --> 10.68 - <exec executable="${hg.executable}" dir="${test.external.dir}/test262"> 10.69 + <!-- update test262 git repo --> 10.70 + <exec executable="${git.executable}" dir="${test.external.dir}/test262"> 10.71 <arg value="pull"/> 10.72 - <arg value="-u"/> 10.73 </exec> 10.74 </target> 10.75
11.1 --- a/make/project.properties Wed Mar 26 12:01:34 2014 -0700 11.2 +++ b/make/project.properties Tue Apr 01 11:44:05 2014 -0700 11.3 @@ -112,6 +112,7 @@ 11.4 test.dir=test 11.5 test.script.dir=test/script 11.6 test.basic.dir=test/script/basic 11.7 +test.maptests.dir=test/script/maptests 11.8 test.error.dir=test/script/error 11.9 test.sandbox.dir=test/script/sandbox 11.10 test.trusted.dir=test/script/trusted 11.11 @@ -121,7 +122,7 @@ 11.12 testjfx.dir=${test.script.dir}/jfx 11.13 11.14 test-sys-prop.test.dir=${test.dir} 11.15 -test-sys-prop.test.js.roots=${test.basic.dir} ${test.error.dir} ${test.sandbox.dir} ${test.trusted.dir} 11.16 +test-sys-prop.test.js.roots=${test.basic.dir} ${test.maptests.dir} ${test.error.dir} ${test.sandbox.dir} ${test.trusted.dir} 11.17 test-sys-prop.test262.suite.dir=${test262.suite.dir} 11.18 test-sys-prop.es5conform.testcases.dir=${test.external.dir}/ES5Conform/TestCases 11.19 test-sys-prop.test.basic.dir=${test.basic.dir} 11.20 @@ -201,7 +202,7 @@ 11.21 11.22 # test262 test frameworks 11.23 test262-test-sys-prop.test.js.framework=\ 11.24 - --class-cache-size=0 \ 11.25 + --class-cache-size=10 \ 11.26 --no-java \ 11.27 --no-typed-arrays \ 11.28 -timezone=PST \ 11.29 @@ -264,7 +265,7 @@ 11.30 run.test.jvmsecurityargs=-Xverify:all -Djava.security.manager -Djava.security.policy=${basedir}/build/nashorn.policy 11.31 11.32 # VM options for script tests with @fork option 11.33 -test-sys-prop.test.fork.jvm.options=${run.test.jvmargs.main} -Xmx${run.test.xmx} ${run.test.jvmsecurityargs} 11.34 +test-sys-prop.test.fork.jvm.options=${run.test.jvmargs.main} -Xmx${run.test.xmx} ${run.test.jvmsecurityargs} -cp ${run.test.classpath} 11.35 11.36 # path of rhino.jar for benchmarks 11.37 rhino.jar=
12.1 --- a/src/jdk/nashorn/api/scripting/NashornException.java Wed Mar 26 12:01:34 2014 -0700 12.2 +++ b/src/jdk/nashorn/api/scripting/NashornException.java Tue Apr 01 11:44:05 2014 -0700 12.3 @@ -29,6 +29,7 @@ 12.4 import java.util.List; 12.5 import jdk.nashorn.internal.codegen.CompilerConstants; 12.6 import jdk.nashorn.internal.runtime.ECMAErrors; 12.7 +import jdk.nashorn.internal.runtime.ScriptObject; 12.8 12.9 /** 12.10 * This is base exception for all Nashorn exceptions. These originate from 12.11 @@ -44,11 +45,13 @@ 12.12 @SuppressWarnings("serial") 12.13 public abstract class NashornException extends RuntimeException { 12.14 // script file name 12.15 - private final String fileName; 12.16 + private String fileName; 12.17 // script line number 12.18 - private final int line; 12.19 + private int line; 12.20 // script column number 12.21 - private final int column; 12.22 + private int column; 12.23 + // underlying ECMA error object - lazily initialized 12.24 + private Object ecmaError; 12.25 12.26 /** script source name used for "engine.js" */ 12.27 public static final String ENGINE_SCRIPT_SOURCE_NAME = "nashorn:engine/resources/engine.js"; 12.28 @@ -122,6 +125,15 @@ 12.29 } 12.30 12.31 /** 12.32 + * Set the source file name for this {@code NashornException} 12.33 + * 12.34 + * @param fileName the file name 12.35 + */ 12.36 + public final void setFileName(final String fileName) { 12.37 + this.fileName = fileName; 12.38 + } 12.39 + 12.40 + /** 12.41 * Get the line number for this {@code NashornException} 12.42 * 12.43 * @return the line number 12.44 @@ -131,15 +143,33 @@ 12.45 } 12.46 12.47 /** 12.48 + * Set the line number for this {@code NashornException} 12.49 + * 12.50 + * @param line the line number 12.51 + */ 12.52 + public final void setLineNumber(final int line) { 12.53 + this.line = line; 12.54 + } 12.55 + 12.56 + /** 12.57 * Get the column for this {@code NashornException} 12.58 * 12.59 - * @return the column 12.60 + * @return the column number 12.61 */ 12.62 public final int getColumnNumber() { 12.63 return column; 12.64 } 12.65 12.66 /** 12.67 + * Set the column for this {@code NashornException} 12.68 + * 12.69 + * @param column the column number 12.70 + */ 12.71 + public final void setColumnNumber(final int column) { 12.72 + this.column = column; 12.73 + } 12.74 + 12.75 + /** 12.76 * Returns array javascript stack frames from the given exception object. 12.77 * 12.78 * @param exception exception from which stack frames are retrieved and filtered 12.79 @@ -155,6 +185,11 @@ 12.80 if (methodName.equals(CompilerConstants.RUN_SCRIPT.symbolName())) { 12.81 methodName = "<program>"; 12.82 } 12.83 + 12.84 + if (methodName.contains(CompilerConstants.ANON_FUNCTION_PREFIX.symbolName())) { 12.85 + methodName = "<anonymous>"; 12.86 + } 12.87 + 12.88 filtered.add(new StackTraceElement(className, methodName, 12.89 st.getFileName(), st.getLineNumber())); 12.90 } 12.91 @@ -188,4 +223,43 @@ 12.92 } 12.93 return buf.toString(); 12.94 } 12.95 + 12.96 + protected Object getThrown() { 12.97 + return null; 12.98 + } 12.99 + 12.100 + protected NashornException initEcmaError(final ScriptObject global) { 12.101 + if (ecmaError != null) { 12.102 + return this; // initialized already! 12.103 + } 12.104 + 12.105 + final Object thrown = getThrown(); 12.106 + if (thrown instanceof ScriptObject) { 12.107 + setEcmaError(ScriptObjectMirror.wrap(thrown, global)); 12.108 + } else { 12.109 + setEcmaError(thrown); 12.110 + } 12.111 + 12.112 + return this; 12.113 + } 12.114 + 12.115 + /** 12.116 + * Return the underlying ECMA error object, if available. 12.117 + * 12.118 + * @return underlying ECMA Error object's mirror or whatever was thrown 12.119 + * from script such as a String, Number or a Boolean. 12.120 + */ 12.121 + public Object getEcmaError() { 12.122 + return ecmaError; 12.123 + } 12.124 + 12.125 + /** 12.126 + * Return the underlying ECMA error object, if available. 12.127 + * 12.128 + * @param ecmaError underlying ECMA Error object's mirror or whatever was thrown 12.129 + * from script such as a String, Number or a Boolean. 12.130 + */ 12.131 + public void setEcmaError(final Object ecmaError) { 12.132 + this.ecmaError = ecmaError; 12.133 + } 12.134 }
13.1 --- a/src/jdk/nashorn/api/scripting/NashornScriptEngine.java Wed Mar 26 12:01:34 2014 -0700 13.2 +++ b/src/jdk/nashorn/api/scripting/NashornScriptEngine.java Tue Apr 01 11:44:05 2014 -0700 13.3 @@ -57,9 +57,9 @@ 13.4 import javax.script.ScriptEngineFactory; 13.5 import javax.script.ScriptException; 13.6 import javax.script.SimpleBindings; 13.7 +import jdk.nashorn.internal.objects.Global; 13.8 import jdk.nashorn.internal.runtime.Context; 13.9 import jdk.nashorn.internal.runtime.ErrorManager; 13.10 -import jdk.nashorn.internal.runtime.GlobalObject; 13.11 import jdk.nashorn.internal.runtime.Property; 13.12 import jdk.nashorn.internal.runtime.ScriptFunction; 13.13 import jdk.nashorn.internal.runtime.ScriptObject; 13.14 @@ -99,7 +99,7 @@ 13.15 private final boolean _global_per_engine; 13.16 // This is the initial default Nashorn global object. 13.17 // This is used as "shared" global if above option is true. 13.18 - private final ScriptObject global; 13.19 + private final Global global; 13.20 // initialized bit late to be made 'final'. 13.21 // Property object for "context" property of global object. 13.22 private volatile Property contextProperty; 13.23 @@ -264,7 +264,7 @@ 13.24 public Object __noSuchProperty__(final Object self, final ScriptContext ctxt, final String name) { 13.25 if (ctxt != null) { 13.26 final int scope = ctxt.getAttributesScope(name); 13.27 - final ScriptObject ctxtGlobal = getNashornGlobalFrom(ctxt); 13.28 + final Global ctxtGlobal = getNashornGlobalFrom(ctxt); 13.29 if (scope != -1) { 13.30 return ScriptObjectMirror.unwrap(ctxt.getAttribute(name, scope), ctxtGlobal); 13.31 } 13.32 @@ -317,7 +317,7 @@ 13.33 } 13.34 13.35 ScriptObject realSelf = null; 13.36 - ScriptObject realGlobal = null; 13.37 + Global realGlobal = null; 13.38 if(thiz == null) { 13.39 // making interface out of global functions 13.40 realSelf = realGlobal = getNashornGlobalFrom(context); 13.41 @@ -346,7 +346,7 @@ 13.42 } 13.43 13.44 try { 13.45 - final ScriptObject oldGlobal = Context.getGlobal(); 13.46 + final Global oldGlobal = Context.getGlobal(); 13.47 final boolean globalChanged = (oldGlobal != realGlobal); 13.48 try { 13.49 if (globalChanged) { 13.50 @@ -371,7 +371,7 @@ 13.51 } 13.52 13.53 // Retrieve nashorn Global object for a given ScriptContext object 13.54 - private ScriptObject getNashornGlobalFrom(final ScriptContext ctxt) { 13.55 + private Global getNashornGlobalFrom(final ScriptContext ctxt) { 13.56 if (_global_per_engine) { 13.57 // shared single global object for all ENGINE_SCOPE Bindings 13.58 return global; 13.59 @@ -380,18 +380,18 @@ 13.60 final Bindings bindings = ctxt.getBindings(ScriptContext.ENGINE_SCOPE); 13.61 // is this Nashorn's own Bindings implementation? 13.62 if (bindings instanceof ScriptObjectMirror) { 13.63 - final ScriptObject sobj = globalFromMirror((ScriptObjectMirror)bindings); 13.64 - if (sobj != null) { 13.65 - return sobj; 13.66 + final Global glob = globalFromMirror((ScriptObjectMirror)bindings); 13.67 + if (glob != null) { 13.68 + return glob; 13.69 } 13.70 } 13.71 13.72 // Arbitrary user Bindings implementation. Look for NASHORN_GLOBAL in it! 13.73 Object scope = bindings.get(NASHORN_GLOBAL); 13.74 if (scope instanceof ScriptObjectMirror) { 13.75 - final ScriptObject sobj = globalFromMirror((ScriptObjectMirror)scope); 13.76 - if (sobj != null) { 13.77 - return sobj; 13.78 + final Global glob = globalFromMirror((ScriptObjectMirror)scope); 13.79 + if (glob != null) { 13.80 + return glob; 13.81 } 13.82 } 13.83 13.84 @@ -399,14 +399,14 @@ 13.85 // Create new global instance mirror and associate with the Bindings. 13.86 final ScriptObjectMirror mirror = createGlobalMirror(ctxt); 13.87 bindings.put(NASHORN_GLOBAL, mirror); 13.88 - return mirror.getScriptObject(); 13.89 + return mirror.getHomeGlobal(); 13.90 } 13.91 13.92 // Retrieve nashorn Global object from a given ScriptObjectMirror 13.93 - private ScriptObject globalFromMirror(final ScriptObjectMirror mirror) { 13.94 + private Global globalFromMirror(final ScriptObjectMirror mirror) { 13.95 ScriptObject sobj = mirror.getScriptObject(); 13.96 - if (sobj instanceof GlobalObject && isOfContext(sobj, nashornContext)) { 13.97 - return sobj; 13.98 + if (sobj instanceof Global && isOfContext((Global)sobj, nashornContext)) { 13.99 + return (Global)sobj; 13.100 } 13.101 13.102 return null; 13.103 @@ -414,15 +414,15 @@ 13.104 13.105 // Create a new ScriptObjectMirror wrapping a newly created Nashorn Global object 13.106 private ScriptObjectMirror createGlobalMirror(final ScriptContext ctxt) { 13.107 - final ScriptObject newGlobal = createNashornGlobal(ctxt); 13.108 + final Global newGlobal = createNashornGlobal(ctxt); 13.109 return new ScriptObjectMirror(newGlobal, newGlobal); 13.110 } 13.111 13.112 // Create a new Nashorn Global object 13.113 - private ScriptObject createNashornGlobal(final ScriptContext ctxt) { 13.114 - final ScriptObject newGlobal = AccessController.doPrivileged(new PrivilegedAction<ScriptObject>() { 13.115 + private Global createNashornGlobal(final ScriptContext ctxt) { 13.116 + final Global newGlobal = AccessController.doPrivileged(new PrivilegedAction<Global>() { 13.117 @Override 13.118 - public ScriptObject run() { 13.119 + public Global run() { 13.120 try { 13.121 return nashornContext.newGlobal(); 13.122 } catch (final RuntimeException e) { 13.123 @@ -460,7 +460,7 @@ 13.124 } 13.125 13.126 // scripts should see "context" and "engine" as variables in the given global object 13.127 - private void setContextVariables(final ScriptObject ctxtGlobal, final ScriptContext ctxt) { 13.128 + private void setContextVariables(final Global ctxtGlobal, final ScriptContext ctxt) { 13.129 // set "context" global variable via contextProperty - because this 13.130 // property is non-writable 13.131 contextProperty.setObjectValue(ctxtGlobal, ctxtGlobal, ctxt, false); 13.132 @@ -470,7 +470,7 @@ 13.133 } 13.134 // if no arguments passed, expose it 13.135 if (! (args instanceof ScriptObject)) { 13.136 - args = ((GlobalObject)ctxtGlobal).wrapAsObject(args); 13.137 + args = ctxtGlobal.wrapAsObject(args); 13.138 ctxtGlobal.set("arguments", args, false); 13.139 } 13.140 } 13.141 @@ -478,16 +478,19 @@ 13.142 private Object invokeImpl(final Object selfObject, final String name, final Object... args) throws ScriptException, NoSuchMethodException { 13.143 name.getClass(); // null check 13.144 13.145 + Global invokeGlobal = null; 13.146 ScriptObjectMirror selfMirror = null; 13.147 if (selfObject instanceof ScriptObjectMirror) { 13.148 selfMirror = (ScriptObjectMirror)selfObject; 13.149 if (! isOfContext(selfMirror.getHomeGlobal(), nashornContext)) { 13.150 throw new IllegalArgumentException(getMessage("script.object.from.another.engine")); 13.151 } 13.152 + invokeGlobal = selfMirror.getHomeGlobal(); 13.153 } else if (selfObject instanceof ScriptObject) { 13.154 // invokeMethod called from script code - in which case we may get 'naked' ScriptObject 13.155 // Wrap it with oldGlobal to make a ScriptObjectMirror for the same. 13.156 - final ScriptObject oldGlobal = Context.getGlobal(); 13.157 + final Global oldGlobal = Context.getGlobal(); 13.158 + invokeGlobal = oldGlobal; 13.159 if (oldGlobal == null) { 13.160 throw new IllegalArgumentException(getMessage("no.current.nashorn.global")); 13.161 } 13.162 @@ -499,7 +502,8 @@ 13.163 selfMirror = (ScriptObjectMirror)ScriptObjectMirror.wrap(selfObject, oldGlobal); 13.164 } else if (selfObject == null) { 13.165 // selfObject is null => global function call 13.166 - final ScriptObject ctxtGlobal = getNashornGlobalFrom(context); 13.167 + final Global ctxtGlobal = getNashornGlobalFrom(context); 13.168 + invokeGlobal = ctxtGlobal; 13.169 selfMirror = (ScriptObjectMirror)ScriptObjectMirror.wrap(ctxtGlobal, ctxtGlobal); 13.170 } 13.171 13.172 @@ -511,7 +515,7 @@ 13.173 if (cause instanceof NoSuchMethodException) { 13.174 throw (NoSuchMethodException)cause; 13.175 } 13.176 - throwAsScriptException(e); 13.177 + throwAsScriptException(e, invokeGlobal); 13.178 throw new AssertionError("should not reach here"); 13.179 } 13.180 } 13.181 @@ -528,11 +532,11 @@ 13.182 return evalImpl(script, ctxt, getNashornGlobalFrom(ctxt)); 13.183 } 13.184 13.185 - private Object evalImpl(final ScriptFunction script, final ScriptContext ctxt, final ScriptObject ctxtGlobal) throws ScriptException { 13.186 + private Object evalImpl(final ScriptFunction script, final ScriptContext ctxt, final Global ctxtGlobal) throws ScriptException { 13.187 if (script == null) { 13.188 return null; 13.189 } 13.190 - final ScriptObject oldGlobal = Context.getGlobal(); 13.191 + final Global oldGlobal = Context.getGlobal(); 13.192 final boolean globalChanged = (oldGlobal != ctxtGlobal); 13.193 try { 13.194 if (globalChanged) { 13.195 @@ -545,7 +549,7 @@ 13.196 } 13.197 return ScriptObjectMirror.translateUndefined(ScriptObjectMirror.wrap(ScriptRuntime.apply(script, ctxtGlobal), ctxtGlobal)); 13.198 } catch (final Exception e) { 13.199 - throwAsScriptException(e); 13.200 + throwAsScriptException(e, ctxtGlobal); 13.201 throw new AssertionError("should not reach here"); 13.202 } finally { 13.203 if (globalChanged) { 13.204 @@ -554,7 +558,7 @@ 13.205 } 13.206 } 13.207 13.208 - private static void throwAsScriptException(final Exception e) throws ScriptException { 13.209 + private static void throwAsScriptException(final Exception e, final Global global) throws ScriptException { 13.210 if (e instanceof ScriptException) { 13.211 throw (ScriptException)e; 13.212 } else if (e instanceof NashornException) { 13.213 @@ -562,6 +566,7 @@ 13.214 final ScriptException se = new ScriptException( 13.215 ne.getMessage(), ne.getFileName(), 13.216 ne.getLineNumber(), ne.getColumnNumber()); 13.217 + ne.initEcmaError(global); 13.218 se.initCause(e); 13.219 throw se; 13.220 } else if (e instanceof RuntimeException) { 13.221 @@ -577,7 +582,7 @@ 13.222 return new CompiledScript() { 13.223 @Override 13.224 public Object eval(final ScriptContext ctxt) throws ScriptException { 13.225 - final ScriptObject globalObject = getNashornGlobalFrom(ctxt); 13.226 + final Global globalObject = getNashornGlobalFrom(ctxt); 13.227 // Are we running the script in the correct global? 13.228 if (func.getScope() == globalObject) { 13.229 return evalImpl(func, ctxt, globalObject); 13.230 @@ -597,8 +602,8 @@ 13.231 return compileImpl(source, getNashornGlobalFrom(ctxt)); 13.232 } 13.233 13.234 - private ScriptFunction compileImpl(final Source source, final ScriptObject newGlobal) throws ScriptException { 13.235 - final ScriptObject oldGlobal = Context.getGlobal(); 13.236 + private ScriptFunction compileImpl(final Source source, final Global newGlobal) throws ScriptException { 13.237 + final Global oldGlobal = Context.getGlobal(); 13.238 final boolean globalChanged = (oldGlobal != newGlobal); 13.239 try { 13.240 if (globalChanged) { 13.241 @@ -607,7 +612,7 @@ 13.242 13.243 return nashornContext.compileScript(source, newGlobal); 13.244 } catch (final Exception e) { 13.245 - throwAsScriptException(e); 13.246 + throwAsScriptException(e, newGlobal); 13.247 throw new AssertionError("should not reach here"); 13.248 } finally { 13.249 if (globalChanged) { 13.250 @@ -623,6 +628,11 @@ 13.251 continue; 13.252 } 13.253 13.254 + // skip check for default methods - non-abstract, interface methods 13.255 + if (! Modifier.isAbstract(method.getModifiers())) { 13.256 + continue; 13.257 + } 13.258 + 13.259 Object obj = sobj.get(method.getName()); 13.260 if (! (obj instanceof ScriptFunction)) { 13.261 return false; 13.262 @@ -631,8 +641,7 @@ 13.263 return true; 13.264 } 13.265 13.266 - private static boolean isOfContext(final ScriptObject global, final Context context) { 13.267 - assert global instanceof GlobalObject: "Not a Global object"; 13.268 - return ((GlobalObject)global).isOfContext(context); 13.269 + private static boolean isOfContext(final Global global, final Context context) { 13.270 + return global.isOfContext(context); 13.271 } 13.272 }
14.1 --- a/src/jdk/nashorn/api/scripting/ScriptObjectMirror.java Wed Mar 26 12:01:34 2014 -0700 14.2 +++ b/src/jdk/nashorn/api/scripting/ScriptObjectMirror.java Tue Apr 01 11:44:05 2014 -0700 14.3 @@ -25,6 +25,7 @@ 14.4 14.5 package jdk.nashorn.api.scripting; 14.6 14.7 +import java.nio.ByteBuffer; 14.8 import java.security.AccessControlContext; 14.9 import java.security.AccessController; 14.10 import java.security.Permissions; 14.11 @@ -41,9 +42,10 @@ 14.12 import java.util.Set; 14.13 import java.util.concurrent.Callable; 14.14 import javax.script.Bindings; 14.15 +import jdk.nashorn.internal.objects.Global; 14.16 +import jdk.nashorn.internal.runtime.arrays.ArrayData; 14.17 import jdk.nashorn.internal.runtime.ConsString; 14.18 import jdk.nashorn.internal.runtime.Context; 14.19 -import jdk.nashorn.internal.runtime.GlobalObject; 14.20 import jdk.nashorn.internal.runtime.JSType; 14.21 import jdk.nashorn.internal.runtime.ScriptFunction; 14.22 import jdk.nashorn.internal.runtime.ScriptObject; 14.23 @@ -62,7 +64,7 @@ 14.24 private static final AccessControlContext GET_CONTEXT_ACC_CTXT = getContextAccCtxt(); 14.25 14.26 private final ScriptObject sobj; 14.27 - private final ScriptObject global; 14.28 + private final Global global; 14.29 private final boolean strict; 14.30 14.31 @Override 14.32 @@ -93,7 +95,7 @@ 14.33 14.34 @Override 14.35 public Object call(final Object thiz, final Object... args) { 14.36 - final ScriptObject oldGlobal = Context.getGlobal(); 14.37 + final Global oldGlobal = Context.getGlobal(); 14.38 final boolean globalChanged = (oldGlobal != global); 14.39 14.40 try { 14.41 @@ -108,6 +110,8 @@ 14.42 } 14.43 14.44 throw new RuntimeException("not a function: " + toString()); 14.45 + } catch (final NashornException ne) { 14.46 + throw ne.initEcmaError(global); 14.47 } catch (final RuntimeException | Error e) { 14.48 throw e; 14.49 } catch (final Throwable t) { 14.50 @@ -121,7 +125,7 @@ 14.51 14.52 @Override 14.53 public Object newObject(final Object... args) { 14.54 - final ScriptObject oldGlobal = Context.getGlobal(); 14.55 + final Global oldGlobal = Context.getGlobal(); 14.56 final boolean globalChanged = (oldGlobal != global); 14.57 14.58 try { 14.59 @@ -135,6 +139,8 @@ 14.60 } 14.61 14.62 throw new RuntimeException("not a constructor: " + toString()); 14.63 + } catch (final NashornException ne) { 14.64 + throw ne.initEcmaError(global); 14.65 } catch (final RuntimeException | Error e) { 14.66 throw e; 14.67 } catch (final Throwable t) { 14.68 @@ -165,7 +171,7 @@ 14.69 14.70 public Object callMember(final String functionName, final Object... args) { 14.71 functionName.getClass(); // null check 14.72 - final ScriptObject oldGlobal = Context.getGlobal(); 14.73 + final Global oldGlobal = Context.getGlobal(); 14.74 final boolean globalChanged = (oldGlobal != global); 14.75 14.76 try { 14.77 @@ -182,6 +188,8 @@ 14.78 } 14.79 14.80 throw new NoSuchMethodException("No such function " + functionName); 14.81 + } catch (final NashornException ne) { 14.82 + throw ne.initEcmaError(global); 14.83 } catch (final RuntimeException | Error e) { 14.84 throw e; 14.85 } catch (final Throwable t) { 14.86 @@ -253,6 +261,22 @@ 14.87 }); 14.88 } 14.89 14.90 + /** 14.91 + * Nashorn extension: setIndexedPropertiesToExternalArrayData. 14.92 + * set indexed properties be exposed from a given nio ByteBuffer. 14.93 + * 14.94 + * @param buf external buffer - should be a nio ByteBuffer 14.95 + */ 14.96 + public void setIndexedPropertiesToExternalArrayData(final ByteBuffer buf) { 14.97 + inGlobal(new Callable<Void>() { 14.98 + @Override public Void call() { 14.99 + sobj.setArray(ArrayData.allocate(buf)); 14.100 + return null; 14.101 + } 14.102 + }); 14.103 + } 14.104 + 14.105 + 14.106 @Override 14.107 public boolean isInstance(final Object obj) { 14.108 if (! (obj instanceof ScriptObjectMirror)) { 14.109 @@ -618,7 +642,7 @@ 14.110 */ 14.111 public static Object wrap(final Object obj, final Object homeGlobal) { 14.112 if(obj instanceof ScriptObject) { 14.113 - return homeGlobal instanceof ScriptObject ? new ScriptObjectMirror((ScriptObject)obj, (ScriptObject)homeGlobal) : obj; 14.114 + return homeGlobal instanceof Global ? new ScriptObjectMirror((ScriptObject)obj, (Global)homeGlobal) : obj; 14.115 } 14.116 if(obj instanceof ConsString) { 14.117 return obj.toString(); 14.118 @@ -686,13 +710,13 @@ 14.119 14.120 // package-privates below this. 14.121 14.122 - ScriptObjectMirror(final ScriptObject sobj, final ScriptObject global) { 14.123 + ScriptObjectMirror(final ScriptObject sobj, final Global global) { 14.124 assert sobj != null : "ScriptObjectMirror on null!"; 14.125 - assert global instanceof GlobalObject : "global is not a GlobalObject"; 14.126 + assert global != null : "home Global is null"; 14.127 14.128 this.sobj = sobj; 14.129 this.global = global; 14.130 - this.strict = ((GlobalObject)global).isStrictContext(); 14.131 + this.strict = global.isStrictContext(); 14.132 } 14.133 14.134 // accessors for script engine 14.135 @@ -700,7 +724,7 @@ 14.136 return sobj; 14.137 } 14.138 14.139 - ScriptObject getHomeGlobal() { 14.140 + Global getHomeGlobal() { 14.141 return global; 14.142 } 14.143 14.144 @@ -710,13 +734,15 @@ 14.145 14.146 // internals only below this. 14.147 private <V> V inGlobal(final Callable<V> callable) { 14.148 - final ScriptObject oldGlobal = Context.getGlobal(); 14.149 + final Global oldGlobal = Context.getGlobal(); 14.150 final boolean globalChanged = (oldGlobal != global); 14.151 if (globalChanged) { 14.152 Context.setGlobal(global); 14.153 } 14.154 try { 14.155 return callable.call(); 14.156 + } catch (final NashornException ne) { 14.157 + throw ne.initEcmaError(global); 14.158 } catch (final RuntimeException e) { 14.159 throw e; 14.160 } catch (final Exception e) {
15.1 --- a/src/jdk/nashorn/internal/codegen/Attr.java Wed Mar 26 12:01:34 2014 -0700 15.2 +++ b/src/jdk/nashorn/internal/codegen/Attr.java Tue Apr 01 11:44:05 2014 -0700 15.3 @@ -375,10 +375,11 @@ 15.4 * @return Symbol for given name or null for redefinition. 15.5 */ 15.6 private Symbol defineSymbol(final Block block, final String name, final int symbolFlags) { 15.7 - int flags = symbolFlags; 15.8 - Symbol symbol = findSymbol(block, name); // Locate symbol. 15.9 + int flags = symbolFlags; 15.10 + Symbol symbol = findSymbol(block, name); // Locate symbol. 15.11 + boolean isGlobal = (flags & KINDMASK) == IS_GLOBAL; 15.12 15.13 - if ((flags & KINDMASK) == IS_GLOBAL) { 15.14 + if (isGlobal) { 15.15 flags |= IS_SCOPE; 15.16 } 15.17 15.18 @@ -414,6 +415,8 @@ 15.19 // Determine where to create it. 15.20 if ((flags & Symbol.KINDMASK) == IS_VAR && ((flags & IS_INTERNAL) == IS_INTERNAL || (flags & IS_LET) == IS_LET)) { 15.21 symbolBlock = block; //internal vars are always defined in the block closest to them 15.22 + } else if (isGlobal) { 15.23 + symbolBlock = lc.getOutermostFunction().getBody(); 15.24 } else { 15.25 symbolBlock = lc.getFunctionBody(function); 15.26 }
16.1 --- a/src/jdk/nashorn/internal/codegen/CodeGenerator.java Wed Mar 26 12:01:34 2014 -0700 16.2 +++ b/src/jdk/nashorn/internal/codegen/CodeGenerator.java Tue Apr 01 11:44:05 2014 -0700 16.3 @@ -685,7 +685,7 @@ 16.4 private void scopeCall(final IdentNode node, final int flags) { 16.5 load(node, Type.OBJECT); // Type.OBJECT as foo() makes no sense if foo == 3 16.6 // ScriptFunction will see CALLSITE_SCOPE and will bind scope accordingly. 16.7 - method.loadNull(); //the 'this' 16.8 + method.loadUndefined(Type.OBJECT); //the 'this' object 16.9 method.dynamicCall(callNodeType, 2 + loadArgs(args), flags); 16.10 } 16.11 16.12 @@ -818,7 +818,7 @@ 16.13 protected boolean enterDefault(final Node node) { 16.14 // Load up function. 16.15 load(function, Type.OBJECT); //TODO, e.g. booleans can be used as functions 16.16 - method.loadNull(); // ScriptFunction will figure out the correct this when it sees CALLSITE_SCOPE 16.17 + method.loadUndefined(Type.OBJECT); // ScriptFunction will figure out the correct this when it sees CALLSITE_SCOPE 16.18 method.dynamicCall(callNodeType, 2 + loadArgs(args), getCallSiteFlags() | CALLSITE_SCOPE); 16.19 16.20 return false; 16.21 @@ -2023,8 +2023,6 @@ 16.22 return false; 16.23 } 16.24 16.25 - method._new(ECMAException.class).dup(); 16.26 - 16.27 final Source source = lc.getCurrentFunction().getSource(); 16.28 16.29 final Expression expression = throwNode.getExpression(); 16.30 @@ -2037,7 +2035,7 @@ 16.31 method.load(source.getName()); 16.32 method.load(line); 16.33 method.load(column); 16.34 - method.invoke(ECMAException.THROW_INIT); 16.35 + method.invoke(ECMAException.CREATE); 16.36 16.37 method.athrow(); 16.38
17.1 --- a/src/jdk/nashorn/internal/codegen/CodeGeneratorLexicalContext.java Wed Mar 26 12:01:34 2014 -0700 17.2 +++ b/src/jdk/nashorn/internal/codegen/CodeGeneratorLexicalContext.java Tue Apr 01 11:44:05 2014 -0700 17.3 @@ -158,7 +158,7 @@ 17.4 if (scopeCalls.containsKey(scopeCall)) { 17.5 return scopeCalls.get(scopeCall); 17.6 } 17.7 - scopeCall.setClassAndName(unit, getCurrentFunction().uniqueName("scopeCall")); 17.8 + scopeCall.setClassAndName(unit, getCurrentFunction().uniqueName(":scopeCall")); 17.9 scopeCalls.put(scopeCall, scopeCall); 17.10 return scopeCall; 17.11 } 17.12 @@ -177,7 +177,7 @@ 17.13 if (scopeCalls.containsKey(scopeCall)) { 17.14 return scopeCalls.get(scopeCall); 17.15 } 17.16 - scopeCall.setClassAndName(unit, getCurrentFunction().uniqueName("scopeCall")); 17.17 + scopeCall.setClassAndName(unit, getCurrentFunction().uniqueName(":scopeCall")); 17.18 scopeCalls.put(scopeCall, scopeCall); 17.19 return scopeCall; 17.20 }
18.1 --- a/src/jdk/nashorn/internal/codegen/Compiler.java Wed Mar 26 12:01:34 2014 -0700 18.2 +++ b/src/jdk/nashorn/internal/codegen/Compiler.java Tue Apr 01 11:44:05 2014 -0700 18.3 @@ -85,6 +85,8 @@ 18.4 18.5 private Source source; 18.6 18.7 + private String sourceName; 18.8 + 18.9 private final Map<String, byte[]> bytecode; 18.10 18.11 private final Set<CompileUnit> compileUnits; 18.12 @@ -267,6 +269,7 @@ 18.13 append('$'). 18.14 append(safeSourceName(functionNode.getSource())); 18.15 this.source = functionNode.getSource(); 18.16 + this.sourceName = functionNode.getSourceName(); 18.17 this.scriptName = sb.toString(); 18.18 } 18.19 18.20 @@ -573,7 +576,7 @@ 18.21 } 18.22 18.23 private CompileUnit initCompileUnit(final String unitClassName, final long initialWeight) { 18.24 - final ClassEmitter classEmitter = new ClassEmitter(env, source.getName(), unitClassName, strict); 18.25 + final ClassEmitter classEmitter = new ClassEmitter(env, sourceName, unitClassName, strict); 18.26 final CompileUnit compileUnit = new CompileUnit(unitClassName, classEmitter, initialWeight); 18.27 18.28 classEmitter.begin();
19.1 --- a/src/jdk/nashorn/internal/codegen/CompilerConstants.java Wed Mar 26 12:01:34 2014 -0700 19.2 +++ b/src/jdk/nashorn/internal/codegen/CompilerConstants.java Tue Apr 01 11:44:05 2014 -0700 19.3 @@ -41,6 +41,7 @@ 19.4 */ 19.5 19.6 public enum CompilerConstants { 19.7 + 19.8 /** the __FILE__ variable */ 19.9 __FILE__, 19.10 19.11 @@ -75,7 +76,7 @@ 19.12 DEFAULT_SCRIPT_NAME("Script"), 19.13 19.14 /** function prefix for anonymous functions */ 19.15 - FUNCTION_PREFIX("function$"), 19.16 + ANON_FUNCTION_PREFIX("L:"), 19.17 19.18 /** method name for Java method that is script entry point */ 19.19 RUN_SCRIPT("runScript"), 19.20 @@ -149,26 +150,31 @@ 19.21 ALLOCATE("allocate"), 19.22 19.23 /** prefix for split methods, @see Splitter */ 19.24 - SPLIT_PREFIX("$split"), 19.25 + SPLIT_PREFIX(":split"), 19.26 19.27 /** prefix for split array method and slot */ 19.28 - SPLIT_ARRAY_ARG("split_array", 3), 19.29 + SPLIT_ARRAY_ARG(":split_array", 3), 19.30 19.31 /** get string from constant pool */ 19.32 - GET_STRING("$getString"), 19.33 + GET_STRING(":getString"), 19.34 19.35 /** get map */ 19.36 - GET_MAP("$getMap"), 19.37 + GET_MAP(":getMap"), 19.38 19.39 /** get map */ 19.40 - SET_MAP("$setMap"), 19.41 + SET_MAP(":setMap"), 19.42 19.43 /** get array prefix */ 19.44 - GET_ARRAY_PREFIX("$get"), 19.45 + GET_ARRAY_PREFIX(":get"), 19.46 19.47 /** get array suffix */ 19.48 GET_ARRAY_SUFFIX("$array"); 19.49 19.50 + /** 19.51 + * Prefix used for internal methods generated in script clases. 19.52 + */ 19.53 + public static final String INTERNAL_METHOD_PREFIX = ":"; 19.54 + 19.55 private final String symbolName; 19.56 private final Class<?> type; 19.57 private final int slot;
20.1 --- a/src/jdk/nashorn/internal/codegen/ConstantData.java Wed Mar 26 12:01:34 2014 -0700 20.2 +++ b/src/jdk/nashorn/internal/codegen/ConstantData.java Tue Apr 01 11:44:05 2014 -0700 20.3 @@ -25,6 +25,9 @@ 20.4 20.5 package jdk.nashorn.internal.codegen; 20.6 20.7 +import jdk.nashorn.internal.runtime.Property; 20.8 +import jdk.nashorn.internal.runtime.PropertyMap; 20.9 + 20.10 import java.util.ArrayList; 20.11 import java.util.Arrays; 20.12 import java.util.HashMap; 20.13 @@ -110,6 +113,43 @@ 20.14 } 20.15 20.16 /** 20.17 + * {@link PropertyMap} wrapper class that provides implementations for the {@code hashCode} and {@code equals} 20.18 + * methods that are based on the map layout. {@code PropertyMap} itself inherits the identity based implementations 20.19 + * from {@code java.lang.Object}. 20.20 + */ 20.21 + private static class PropertyMapWrapper { 20.22 + private final PropertyMap propertyMap; 20.23 + private final int hashCode; 20.24 + 20.25 + public PropertyMapWrapper(final PropertyMap map) { 20.26 + int hash = 0; 20.27 + for (final Property property : map.getProperties()) { 20.28 + hash = hash << 7 ^ hash >> 7; 20.29 + hash ^= property.hashCode(); 20.30 + } 20.31 + this.hashCode = hash; 20.32 + this.propertyMap = map; 20.33 + } 20.34 + 20.35 + @Override 20.36 + public int hashCode() { 20.37 + return hashCode; 20.38 + } 20.39 + 20.40 + @Override 20.41 + public boolean equals(final Object other) { 20.42 + if (!(other instanceof PropertyMapWrapper)) { 20.43 + return false; 20.44 + } 20.45 + 20.46 + final Property[] ownProperties = propertyMap.getProperties(); 20.47 + final Property[] otherProperties = ((PropertyMapWrapper) other).propertyMap.getProperties(); 20.48 + 20.49 + return Arrays.equals(ownProperties, otherProperties); 20.50 + } 20.51 + } 20.52 + 20.53 + /** 20.54 * Constructor 20.55 */ 20.56 ConstantData() { 20.57 @@ -145,7 +185,14 @@ 20.58 * @return the index in the constant pool that the object was given 20.59 */ 20.60 public int add(final Object object) { 20.61 - final Object entry = object.getClass().isArray() ? new ArrayWrapper(object) : object; 20.62 + final Object entry; 20.63 + if (object.getClass().isArray()) { 20.64 + entry = new ArrayWrapper(object); 20.65 + } else if (object instanceof PropertyMap) { 20.66 + entry = new PropertyMapWrapper((PropertyMap) object); 20.67 + } else { 20.68 + entry = object; 20.69 + } 20.70 final Integer value = objectMap.get(entry); 20.71 20.72 if (value != null) {
21.1 --- a/src/jdk/nashorn/internal/codegen/MethodEmitter.java Wed Mar 26 12:01:34 2014 -0700 21.2 +++ b/src/jdk/nashorn/internal/codegen/MethodEmitter.java Tue Apr 01 11:44:05 2014 -0700 21.3 @@ -1130,7 +1130,11 @@ 21.4 popType(Type.OBJECT); 21.5 } 21.6 21.7 - method.visitMethodInsn(opcode, className, methodName, methodDescriptor); 21.8 + if (opcode == INVOKEINTERFACE) { 21.9 + method.visitMethodInsn(opcode, className, methodName, methodDescriptor, true); 21.10 + } else { 21.11 + method.visitMethodInsn(opcode, className, methodName, methodDescriptor, false); 21.12 + } 21.13 21.14 if (returnType != null) { 21.15 pushType(returnType);
22.1 --- a/src/jdk/nashorn/internal/codegen/SharedScopeCall.java Wed Mar 26 12:01:34 2014 -0700 22.2 +++ b/src/jdk/nashorn/internal/codegen/SharedScopeCall.java Tue Apr 01 11:44:05 2014 -0700 22.3 @@ -156,7 +156,7 @@ 22.4 if (isCall) { 22.5 method.convert(Type.OBJECT); 22.6 // ScriptFunction will see CALLSITE_SCOPE and will bind scope accordingly. 22.7 - method.loadNull(); 22.8 + method.loadUndefined(Type.OBJECT); 22.9 int slot = 2; 22.10 for (final Type type : paramTypes) { 22.11 method.load(type, slot++);
23.1 --- a/src/jdk/nashorn/internal/codegen/types/Type.java Wed Mar 26 12:01:34 2014 -0700 23.2 +++ b/src/jdk/nashorn/internal/codegen/types/Type.java Tue Apr 01 11:44:05 2014 -0700 23.3 @@ -261,7 +261,7 @@ 23.4 } 23.5 23.6 static void invokeStatic(final MethodVisitor method, final Call call) { 23.7 - method.visitMethodInsn(INVOKESTATIC, call.className(), call.name(), call.descriptor()); 23.8 + method.visitMethodInsn(INVOKESTATIC, call.className(), call.name(), call.descriptor(), false); 23.9 } 23.10 23.11 /**
24.1 --- a/src/jdk/nashorn/internal/ir/FunctionNode.java Wed Mar 26 12:01:34 2014 -0700 24.2 +++ b/src/jdk/nashorn/internal/ir/FunctionNode.java Tue Apr 01 11:44:05 2014 -0700 24.3 @@ -29,6 +29,7 @@ 24.4 import java.util.EnumSet; 24.5 import java.util.HashSet; 24.6 import java.util.List; 24.7 +import java.util.Objects; 24.8 import java.util.Set; 24.9 import jdk.nashorn.internal.codegen.CompileUnit; 24.10 import jdk.nashorn.internal.codegen.Compiler; 24.11 @@ -138,6 +139,9 @@ 24.12 /** Function flags. */ 24.13 private final int flags; 24.14 24.15 + /** //@ sourceURL or //# sourceURL for program function nodes */ 24.16 + private final String sourceURL; 24.17 + 24.18 private final int lineNumber; 24.19 24.20 /** Is anonymous function flag. */ 24.21 @@ -160,11 +164,11 @@ 24.22 public static final int HAS_EVAL = 1 << 5; 24.23 24.24 /** Does a nested function contain eval? If it does, then all variables in this function might be get/set by it. */ 24.25 - public static final int HAS_NESTED_EVAL = 1 << 6; 24.26 + public static final int HAS_NESTED_EVAL = 1 << 6; 24.27 24.28 /** Does this function have any blocks that create a scope? This is used to determine if the function needs to 24.29 * have a local variable slot for the scope symbol. */ 24.30 - public static final int HAS_SCOPE_BLOCK = 1 << 7; 24.31 + public static final int HAS_SCOPE_BLOCK = 1 << 7; 24.32 24.33 /** 24.34 * Flag this function as one that defines the identifier "arguments" as a function parameter or nested function 24.35 @@ -193,6 +197,9 @@ 24.36 /** Can this function be specialized? */ 24.37 public static final int CAN_SPECIALIZE = 1 << 14; 24.38 24.39 + /** Does this function use the "this" keyword? */ 24.40 + public static final int USES_THIS = 1 << 15; 24.41 + 24.42 /** Does this function or any nested functions contain an eval? */ 24.43 private static final int HAS_DEEP_EVAL = HAS_EVAL | HAS_NESTED_EVAL; 24.44 24.45 @@ -223,6 +230,7 @@ 24.46 * @param parameters parameter list 24.47 * @param kind kind of function as in {@link FunctionNode.Kind} 24.48 * @param flags initial flags 24.49 + * @param sourceURL sourceURL specified in script (optional) 24.50 */ 24.51 public FunctionNode( 24.52 final Source source, 24.53 @@ -235,7 +243,8 @@ 24.54 final String name, 24.55 final List<IdentNode> parameters, 24.56 final FunctionNode.Kind kind, 24.57 - final int flags) { 24.58 + final int flags, 24.59 + final String sourceURL) { 24.60 super(token, finish); 24.61 24.62 this.source = source; 24.63 @@ -250,6 +259,7 @@ 24.64 this.compilationState = EnumSet.of(CompilationState.INITIALIZED); 24.65 this.declaredSymbols = new HashSet<>(); 24.66 this.flags = flags; 24.67 + this.sourceURL = sourceURL; 24.68 this.compileUnit = null; 24.69 this.body = null; 24.70 this.snapshot = null; 24.71 @@ -260,6 +270,7 @@ 24.72 final FunctionNode functionNode, 24.73 final long lastToken, 24.74 final int flags, 24.75 + final String sourceURL, 24.76 final String name, 24.77 final Type returnType, 24.78 final CompileUnit compileUnit, 24.79 @@ -271,6 +282,7 @@ 24.80 super(functionNode); 24.81 this.lineNumber = functionNode.lineNumber; 24.82 this.flags = flags; 24.83 + this.sourceURL = sourceURL; 24.84 this.name = name; 24.85 this.returnType = returnType; 24.86 this.compileUnit = compileUnit; 24.87 @@ -308,6 +320,38 @@ 24.88 } 24.89 24.90 /** 24.91 + * get source name - sourceURL or name derived from Source. 24.92 + * 24.93 + * @return name for the script source 24.94 + */ 24.95 + public String getSourceName() { 24.96 + return (sourceURL != null)? sourceURL : source.getName(); 24.97 + } 24.98 + 24.99 + /** 24.100 + * get the sourceURL 24.101 + * @return the sourceURL 24.102 + */ 24.103 + public String getSourceURL() { 24.104 + return sourceURL; 24.105 + } 24.106 + 24.107 + /** 24.108 + * Set the sourceURL 24.109 + * 24.110 + * @param lc lexical context 24.111 + * @param newSourceURL source url string to set 24.112 + * @return function node or a new one if state was changed 24.113 + */ 24.114 + public FunctionNode setSourceURL(final LexicalContext lc, final String newSourceURL) { 24.115 + if (Objects.equals(sourceURL, newSourceURL)) { 24.116 + return this; 24.117 + } 24.118 + 24.119 + return Node.replaceInLexicalContext(lc, this, new FunctionNode(this, lastToken, flags, newSourceURL, name, returnType, compileUnit, compilationState, body, parameters, null, hints)); 24.120 + } 24.121 + 24.122 + /** 24.123 * Returns the line number. 24.124 * @return the line number. 24.125 */ 24.126 @@ -335,7 +379,7 @@ 24.127 if (this.snapshot == null) { 24.128 return this; 24.129 } 24.130 - return Node.replaceInLexicalContext(lc, this, new FunctionNode(this, lastToken, flags, name, returnType, compileUnit, compilationState, body, parameters, null, hints)); 24.131 + return Node.replaceInLexicalContext(lc, this, new FunctionNode(this, lastToken, flags, sourceURL, name, returnType, compileUnit, compilationState, body, parameters, null, hints)); 24.132 } 24.133 24.134 /** 24.135 @@ -351,7 +395,7 @@ 24.136 if (isProgram() || parameters.isEmpty()) { 24.137 return this; //never specialize anything that won't be recompiled 24.138 } 24.139 - return Node.replaceInLexicalContext(lc, this, new FunctionNode(this, lastToken, flags, name, returnType, compileUnit, compilationState, body, parameters, this, hints)); 24.140 + return Node.replaceInLexicalContext(lc, this, new FunctionNode(this, lastToken, flags, sourceURL, name, returnType, compileUnit, compilationState, body, parameters, this, hints)); 24.141 } 24.142 24.143 /** 24.144 @@ -409,7 +453,7 @@ 24.145 } 24.146 final EnumSet<CompilationState> newState = EnumSet.copyOf(this.compilationState); 24.147 newState.add(state); 24.148 - return Node.replaceInLexicalContext(lc, this, new FunctionNode(this, lastToken, flags, name, returnType, compileUnit, newState, body, parameters, snapshot, hints)); 24.149 + return Node.replaceInLexicalContext(lc, this, new FunctionNode(this, lastToken, flags, sourceURL, name, returnType, compileUnit, newState, body, parameters, snapshot, hints)); 24.150 } 24.151 24.152 /** 24.153 @@ -430,7 +474,7 @@ 24.154 if (this.hints == hints) { 24.155 return this; 24.156 } 24.157 - return Node.replaceInLexicalContext(lc, this, new FunctionNode(this, lastToken, flags, name, returnType, compileUnit, compilationState, body, parameters, snapshot, hints)); 24.158 + return Node.replaceInLexicalContext(lc, this, new FunctionNode(this, lastToken, flags, sourceURL, name, returnType, compileUnit, compilationState, body, parameters, snapshot, hints)); 24.159 } 24.160 24.161 /** 24.162 @@ -483,7 +527,7 @@ 24.163 if (this.flags == flags) { 24.164 return this; 24.165 } 24.166 - return Node.replaceInLexicalContext(lc, this, new FunctionNode(this, lastToken, flags, name, returnType, compileUnit, compilationState, body, parameters, snapshot, hints)); 24.167 + return Node.replaceInLexicalContext(lc, this, new FunctionNode(this, lastToken, flags, sourceURL, name, returnType, compileUnit, compilationState, body, parameters, snapshot, hints)); 24.168 } 24.169 24.170 @Override 24.171 @@ -550,6 +594,15 @@ 24.172 } 24.173 24.174 /** 24.175 + * Return {@code true} if this function makes use of the {@code this} object. 24.176 + * 24.177 + * @return true if function uses {@code this} object 24.178 + */ 24.179 + public boolean usesThis() { 24.180 + return getFlag(USES_THIS); 24.181 + } 24.182 + 24.183 + /** 24.184 * Get the identifier for this function, this is its symbol. 24.185 * @return the identifier as an IdentityNode 24.186 */ 24.187 @@ -593,7 +646,7 @@ 24.188 if(this.body == body) { 24.189 return this; 24.190 } 24.191 - return Node.replaceInLexicalContext(lc, this, new FunctionNode(this, lastToken, flags | (body.needsScope() ? FunctionNode.HAS_SCOPE_BLOCK : 0), name, returnType, compileUnit, compilationState, body, parameters, snapshot, hints)); 24.192 + return Node.replaceInLexicalContext(lc, this, new FunctionNode(this, lastToken, flags | (body.needsScope() ? FunctionNode.HAS_SCOPE_BLOCK : 0), sourceURL, name, returnType, compileUnit, compilationState, body, parameters, snapshot, hints)); 24.193 } 24.194 24.195 /** 24.196 @@ -688,7 +741,7 @@ 24.197 if (this.lastToken == lastToken) { 24.198 return this; 24.199 } 24.200 - return Node.replaceInLexicalContext(lc, this, new FunctionNode(this, lastToken, flags, name, returnType, compileUnit, compilationState, body, parameters, snapshot, hints)); 24.201 + return Node.replaceInLexicalContext(lc, this, new FunctionNode(this, lastToken, flags, sourceURL, name, returnType, compileUnit, compilationState, body, parameters, snapshot, hints)); 24.202 } 24.203 24.204 /** 24.205 @@ -710,7 +763,7 @@ 24.206 if (this.name.equals(name)) { 24.207 return this; 24.208 } 24.209 - return Node.replaceInLexicalContext(lc, this, new FunctionNode(this, lastToken, flags, name, returnType, compileUnit, compilationState, body, parameters, snapshot, hints)); 24.210 + return Node.replaceInLexicalContext(lc, this, new FunctionNode(this, lastToken, flags, sourceURL, name, returnType, compileUnit, compilationState, body, parameters, snapshot, hints)); 24.211 } 24.212 24.213 /** 24.214 @@ -760,7 +813,7 @@ 24.215 if (this.parameters == parameters) { 24.216 return this; 24.217 } 24.218 - return Node.replaceInLexicalContext(lc, this, new FunctionNode(this, lastToken, flags, name, returnType, compileUnit, compilationState, body, parameters, snapshot, hints)); 24.219 + return Node.replaceInLexicalContext(lc, this, new FunctionNode(this, lastToken, flags, sourceURL, name, returnType, compileUnit, compilationState, body, parameters, snapshot, hints)); 24.220 } 24.221 24.222 /** 24.223 @@ -825,6 +878,7 @@ 24.224 this, 24.225 lastToken, 24.226 flags, 24.227 + sourceURL, 24.228 name, 24.229 type, 24.230 compileUnit, 24.231 @@ -863,7 +917,7 @@ 24.232 if (this.compileUnit == compileUnit) { 24.233 return this; 24.234 } 24.235 - return Node.replaceInLexicalContext(lc, this, new FunctionNode(this, lastToken, flags, name, returnType, compileUnit, compilationState, body, parameters, snapshot, hints)); 24.236 + return Node.replaceInLexicalContext(lc, this, new FunctionNode(this, lastToken, flags, sourceURL, name, returnType, compileUnit, compilationState, body, parameters, snapshot, hints)); 24.237 } 24.238 24.239 /**
25.1 --- a/src/jdk/nashorn/internal/objects/AccessorPropertyDescriptor.java Wed Mar 26 12:01:34 2014 -0700 25.2 +++ b/src/jdk/nashorn/internal/objects/AccessorPropertyDescriptor.java Tue Apr 01 11:44:05 2014 -0700 25.3 @@ -67,12 +67,8 @@ 25.4 // initialized by nasgen 25.5 private static PropertyMap $nasgenmap$; 25.6 25.7 - static PropertyMap getInitialMap() { 25.8 - return $nasgenmap$; 25.9 - } 25.10 - 25.11 AccessorPropertyDescriptor(final boolean configurable, final boolean enumerable, final Object get, final Object set, final Global global) { 25.12 - super(global.getObjectPrototype(), global.getAccessorPropertyDescriptorMap()); 25.13 + super(global.getObjectPrototype(), $nasgenmap$); 25.14 this.configurable = configurable; 25.15 this.enumerable = enumerable; 25.16 this.get = get; 25.17 @@ -185,6 +181,18 @@ 25.18 } 25.19 25.20 @Override 25.21 + public boolean hasAndEquals(final PropertyDescriptor otherDesc) { 25.22 + if (! (otherDesc instanceof AccessorPropertyDescriptor)) { 25.23 + return false; 25.24 + } 25.25 + final AccessorPropertyDescriptor other = (AccessorPropertyDescriptor)otherDesc; 25.26 + return (!has(CONFIGURABLE) || sameValue(configurable, other.configurable)) && 25.27 + (!has(ENUMERABLE) || sameValue(enumerable, other.enumerable)) && 25.28 + (!has(GET) || sameValue(get, other.get)) && 25.29 + (!has(SET) || sameValue(set, other.set)); 25.30 + } 25.31 + 25.32 + @Override 25.33 public boolean equals(final Object obj) { 25.34 if (this == obj) { 25.35 return true;
26.1 --- a/src/jdk/nashorn/internal/objects/ArrayBufferView.java Wed Mar 26 12:01:34 2014 -0700 26.2 +++ b/src/jdk/nashorn/internal/objects/ArrayBufferView.java Tue Apr 01 11:44:05 2014 -0700 26.3 @@ -42,12 +42,8 @@ 26.4 // initialized by nasgen 26.5 private static PropertyMap $nasgenmap$; 26.6 26.7 - static PropertyMap getInitialMap() { 26.8 - return $nasgenmap$; 26.9 - } 26.10 - 26.11 private ArrayBufferView(final NativeArrayBuffer buffer, final int byteOffset, final int elementLength, final Global global) { 26.12 - super(global.getArrayBufferViewMap()); 26.13 + super($nasgenmap$); 26.14 checkConstructorArgs(buffer, byteOffset, elementLength); 26.15 this.setProto(getPrototype(global)); 26.16 this.setArray(factory().createArrayData(buffer, byteOffset, elementLength)); 26.17 @@ -386,7 +382,7 @@ 26.18 return (int) (length & Integer.MAX_VALUE); 26.19 } 26.20 26.21 - protected static Object subarrayImpl(final Object self, final Object begin0, final Object end0) { 26.22 + protected static ScriptObject subarrayImpl(final Object self, final Object begin0, final Object end0) { 26.23 final ArrayBufferView arrayView = ((ArrayBufferView)self); 26.24 final int elementLength = arrayView.elementLength(); 26.25 final int begin = NativeArrayBuffer.adjustIndex(JSType.toInt32(begin0), elementLength);
27.1 --- a/src/jdk/nashorn/internal/objects/DataPropertyDescriptor.java Wed Mar 26 12:01:34 2014 -0700 27.2 +++ b/src/jdk/nashorn/internal/objects/DataPropertyDescriptor.java Tue Apr 01 11:44:05 2014 -0700 27.3 @@ -64,12 +64,8 @@ 27.4 // initialized by nasgen 27.5 private static PropertyMap $nasgenmap$; 27.6 27.7 - static PropertyMap getInitialMap() { 27.8 - return $nasgenmap$; 27.9 - } 27.10 - 27.11 DataPropertyDescriptor(final boolean configurable, final boolean enumerable, final boolean writable, final Object value, final Global global) { 27.12 - super(global.getObjectPrototype(), global.getDataPropertyDescriptorMap()); 27.13 + super(global.getObjectPrototype(), $nasgenmap$); 27.14 this.configurable = configurable; 27.15 this.enumerable = enumerable; 27.16 this.writable = writable; 27.17 @@ -172,6 +168,19 @@ 27.18 } 27.19 27.20 @Override 27.21 + public boolean hasAndEquals(final PropertyDescriptor otherDesc) { 27.22 + if (! (otherDesc instanceof DataPropertyDescriptor)) { 27.23 + return false; 27.24 + } 27.25 + 27.26 + final DataPropertyDescriptor other = (DataPropertyDescriptor)otherDesc; 27.27 + return (!has(CONFIGURABLE) || sameValue(configurable, other.configurable)) && 27.28 + (!has(ENUMERABLE) || sameValue(enumerable, other.enumerable)) && 27.29 + (!has(WRITABLE) || sameValue(writable, other.writable)) && 27.30 + (!has(VALUE) || sameValue(value, other.value)); 27.31 + } 27.32 + 27.33 + @Override 27.34 public boolean equals(final Object obj) { 27.35 if (this == obj) { 27.36 return true;
28.1 --- a/src/jdk/nashorn/internal/objects/GenericPropertyDescriptor.java Wed Mar 26 12:01:34 2014 -0700 28.2 +++ b/src/jdk/nashorn/internal/objects/GenericPropertyDescriptor.java Tue Apr 01 11:44:05 2014 -0700 28.3 @@ -55,12 +55,8 @@ 28.4 // initialized by nasgen 28.5 private static PropertyMap $nasgenmap$; 28.6 28.7 - static PropertyMap getInitialMap() { 28.8 - return $nasgenmap$; 28.9 - } 28.10 - 28.11 GenericPropertyDescriptor(final boolean configurable, final boolean enumerable, final Global global) { 28.12 - super(global.getObjectPrototype(), global.getGenericPropertyDescriptorMap()); 28.13 + super(global.getObjectPrototype(), $nasgenmap$); 28.14 this.configurable = configurable; 28.15 this.enumerable = enumerable; 28.16 } 28.17 @@ -149,6 +145,23 @@ 28.18 } 28.19 28.20 @Override 28.21 + public boolean hasAndEquals(final PropertyDescriptor other) { 28.22 + if (has(CONFIGURABLE) && other.has(CONFIGURABLE)) { 28.23 + if (isConfigurable() != other.isConfigurable()) { 28.24 + return false; 28.25 + } 28.26 + } 28.27 + 28.28 + if (has(ENUMERABLE) && other.has(ENUMERABLE)) { 28.29 + if (isEnumerable() != other.isEnumerable()) { 28.30 + return false; 28.31 + } 28.32 + } 28.33 + 28.34 + return true; 28.35 + } 28.36 + 28.37 + @Override 28.38 public boolean equals(final Object obj) { 28.39 if (this == obj) { 28.40 return true;
29.1 --- a/src/jdk/nashorn/internal/objects/Global.java Wed Mar 26 12:01:34 2014 -0700 29.2 +++ b/src/jdk/nashorn/internal/objects/Global.java Tue Apr 01 11:44:05 2014 -0700 29.3 @@ -33,11 +33,8 @@ 29.4 import java.io.PrintWriter; 29.5 import java.lang.invoke.MethodHandle; 29.6 import java.lang.invoke.MethodHandles; 29.7 -import java.lang.ref.ReferenceQueue; 29.8 -import java.lang.ref.SoftReference; 29.9 import java.lang.reflect.Field; 29.10 import java.util.Arrays; 29.11 -import java.util.LinkedHashMap; 29.12 import java.util.List; 29.13 import java.util.Map; 29.14 import java.util.concurrent.Callable; 29.15 @@ -51,7 +48,6 @@ 29.16 import jdk.nashorn.internal.runtime.ConsString; 29.17 import jdk.nashorn.internal.runtime.Context; 29.18 import jdk.nashorn.internal.runtime.GlobalFunctions; 29.19 -import jdk.nashorn.internal.runtime.GlobalObject; 29.20 import jdk.nashorn.internal.runtime.JSType; 29.21 import jdk.nashorn.internal.runtime.NativeJavaPackage; 29.22 import jdk.nashorn.internal.runtime.PropertyDescriptor; 29.23 @@ -59,10 +55,10 @@ 29.24 import jdk.nashorn.internal.runtime.Scope; 29.25 import jdk.nashorn.internal.runtime.ScriptEnvironment; 29.26 import jdk.nashorn.internal.runtime.ScriptFunction; 29.27 +import jdk.nashorn.internal.runtime.ScriptFunctionData; 29.28 import jdk.nashorn.internal.runtime.ScriptObject; 29.29 import jdk.nashorn.internal.runtime.ScriptRuntime; 29.30 import jdk.nashorn.internal.runtime.ScriptingFunctions; 29.31 -import jdk.nashorn.internal.runtime.Source; 29.32 import jdk.nashorn.internal.runtime.arrays.ArrayData; 29.33 import jdk.nashorn.internal.runtime.linker.Bootstrap; 29.34 import jdk.nashorn.internal.runtime.linker.InvokeByName; 29.35 @@ -73,7 +69,7 @@ 29.36 * Representation of global scope. 29.37 */ 29.38 @ScriptClass("Global") 29.39 -public final class Global extends ScriptObject implements GlobalObject, Scope { 29.40 +public final class Global extends ScriptObject implements Scope { 29.41 private final InvokeByName TO_STRING = new InvokeByName("toString", ScriptObject.class); 29.42 private final InvokeByName VALUE_OF = new InvokeByName("valueOf", ScriptObject.class); 29.43 29.44 @@ -229,6 +225,10 @@ 29.45 @Property(name = "ArrayBuffer", attributes = Attribute.NOT_ENUMERABLE) 29.46 public volatile Object arrayBuffer; 29.47 29.48 + /** DataView object */ 29.49 + @Property(name = "DataView", attributes = Attribute.NOT_ENUMERABLE) 29.50 + public volatile Object dataView; 29.51 + 29.52 /** TypedArray (int8) */ 29.53 @Property(name = "Int8Array", attributes = Attribute.NOT_ENUMERABLE) 29.54 public volatile Object int8Array; 29.55 @@ -355,6 +355,7 @@ 29.56 private ScriptObject builtinJavaImporter; 29.57 private ScriptObject builtinJavaApi; 29.58 private ScriptObject builtinArrayBuffer; 29.59 + private ScriptObject builtinDataView; 29.60 private ScriptObject builtinInt8Array; 29.61 private ScriptObject builtinUint8Array; 29.62 private ScriptObject builtinUint8ClampedArray; 29.63 @@ -370,42 +371,9 @@ 29.64 */ 29.65 private ScriptFunction typeErrorThrower; 29.66 29.67 - private PropertyMap accessorPropertyDescriptorMap; 29.68 - private PropertyMap arrayBufferViewMap; 29.69 - private PropertyMap dataPropertyDescriptorMap; 29.70 - private PropertyMap genericPropertyDescriptorMap; 29.71 - private PropertyMap nativeArgumentsMap; 29.72 - private PropertyMap nativeArrayMap; 29.73 - private PropertyMap nativeArrayBufferMap; 29.74 - private PropertyMap nativeBooleanMap; 29.75 - private PropertyMap nativeDateMap; 29.76 - private PropertyMap nativeErrorMap; 29.77 - private PropertyMap nativeEvalErrorMap; 29.78 - private PropertyMap nativeJSAdapterMap; 29.79 - private PropertyMap nativeJavaImporterMap; 29.80 - private PropertyMap nativeNumberMap; 29.81 - private PropertyMap nativeRangeErrorMap; 29.82 - private PropertyMap nativeReferenceErrorMap; 29.83 - private PropertyMap nativeRegExpMap; 29.84 - private PropertyMap nativeRegExpExecResultMap; 29.85 - private PropertyMap nativeStrictArgumentsMap; 29.86 - private PropertyMap nativeStringMap; 29.87 - private PropertyMap nativeSyntaxErrorMap; 29.88 - private PropertyMap nativeTypeErrorMap; 29.89 - private PropertyMap nativeURIErrorMap; 29.90 - private PropertyMap prototypeObjectMap; 29.91 - private PropertyMap objectMap; 29.92 - private PropertyMap functionMap; 29.93 - private PropertyMap anonymousFunctionMap; 29.94 - private PropertyMap strictFunctionMap; 29.95 - private PropertyMap boundFunctionMap; 29.96 - 29.97 // Flag to indicate that a split method issued a return statement 29.98 private int splitState = -1; 29.99 29.100 - // class cache 29.101 - private ClassCache classCache; 29.102 - 29.103 // Used to store the last RegExp result to support deprecated RegExp constructor properties 29.104 private RegExpResult lastRegExpResult; 29.105 29.106 @@ -456,11 +424,6 @@ 29.107 super(checkAndGetMap(context)); 29.108 this.context = context; 29.109 this.setIsScope(); 29.110 - 29.111 - final int cacheSize = context.getEnv()._class_cache_size; 29.112 - if (cacheSize > 0) { 29.113 - classCache = new ClassCache(cacheSize); 29.114 - } 29.115 } 29.116 29.117 /** 29.118 @@ -469,11 +432,9 @@ 29.119 * @return the global singleton 29.120 */ 29.121 public static Global instance() { 29.122 - ScriptObject global = Context.getGlobal(); 29.123 - if (! (global instanceof Global)) { 29.124 - throw new IllegalStateException("no current global instance"); 29.125 - } 29.126 - return (Global)global; 29.127 + Global global = Context.getGlobal(); 29.128 + global.getClass(); // null check 29.129 + return global; 29.130 } 29.131 29.132 /** 29.133 @@ -494,19 +455,30 @@ 29.134 return instance().getContext(); 29.135 } 29.136 29.137 - // GlobalObject interface implementation 29.138 + // Runtime interface to Global 29.139 29.140 - @Override 29.141 + /** 29.142 + * Is this global of the given Context? 29.143 + * @param ctxt the context 29.144 + * @return true if this global belongs to the given Context 29.145 + */ 29.146 public boolean isOfContext(final Context ctxt) { 29.147 return this.context == ctxt; 29.148 } 29.149 29.150 - @Override 29.151 + /** 29.152 + * Does this global belong to a strict Context? 29.153 + * @return true if this global belongs to a strict Context 29.154 + */ 29.155 public boolean isStrictContext() { 29.156 return context.getEnv()._strict; 29.157 } 29.158 29.159 - @Override 29.160 + /** 29.161 + * Initialize standard builtin objects like "Object", "Array", "Function" etc. 29.162 + * as well as our extension builtin objects like "Java", "JSAdapter" as properties 29.163 + * of the global scope object. 29.164 + */ 29.165 public void initBuiltinObjects() { 29.166 if (this.builtinObject != null) { 29.167 // already initialized, just return 29.168 @@ -516,12 +488,26 @@ 29.169 init(); 29.170 } 29.171 29.172 - @Override 29.173 + /** 29.174 + * Create a new ScriptFunction object 29.175 + * 29.176 + * @param name function name 29.177 + * @param handle invocation handle for function 29.178 + * @param scope the scope 29.179 + * @param strict are we in strict mode 29.180 + * 29.181 + * @return new script function 29.182 + */ 29.183 public ScriptFunction newScriptFunction(final String name, final MethodHandle handle, final ScriptObject scope, final boolean strict) { 29.184 - return new ScriptFunctionImpl(name, handle, scope, null, strict, false, true); 29.185 + return new ScriptFunctionImpl(name, handle, scope, null, strict ? ScriptFunctionData.IS_STRICT_CONSTRUCTOR : ScriptFunctionData.IS_CONSTRUCTOR); 29.186 } 29.187 29.188 - @Override 29.189 + /** 29.190 + * Wrap a Java object as corresponding script object 29.191 + * 29.192 + * @param obj object to wrap 29.193 + * @return wrapped object 29.194 + */ 29.195 public Object wrapAsObject(final Object obj) { 29.196 if (obj instanceof Boolean) { 29.197 return new NativeBoolean((Boolean)obj, this); 29.198 @@ -543,7 +529,14 @@ 29.199 } 29.200 } 29.201 29.202 - @Override 29.203 + /** 29.204 + * Lookup helper for JS primitive types 29.205 + * 29.206 + * @param request the link request for the dynamic call site. 29.207 + * @param self self reference 29.208 + * 29.209 + * @return guarded invocation 29.210 + */ 29.211 public GuardedInvocation primitiveLookup(final LinkRequest request, final Object self) { 29.212 if (self instanceof String || self instanceof ConsString) { 29.213 return NativeString.lookupPrimitive(request, self); 29.214 @@ -555,12 +548,23 @@ 29.215 throw new IllegalArgumentException("Unsupported primitive: " + self); 29.216 } 29.217 29.218 - @Override 29.219 + /** 29.220 + * Create a new empty script object 29.221 + * 29.222 + * @return the new ScriptObject 29.223 + */ 29.224 public ScriptObject newObject() { 29.225 - return new JO(getObjectPrototype(), getObjectMap()); 29.226 + return new JO(getObjectPrototype(), JO.getInitialMap()); 29.227 } 29.228 29.229 - @Override 29.230 + /** 29.231 + * Default value of given type 29.232 + * 29.233 + * @param sobj script object 29.234 + * @param typeHint type hint 29.235 + * 29.236 + * @return default value 29.237 + */ 29.238 public Object getDefaultValue(final ScriptObject sobj, final Class<?> typeHint) { 29.239 // When the [[DefaultValue]] internal method of O is called with no hint, 29.240 // then it behaves as if the hint were Number, unless O is a Date object 29.241 @@ -620,7 +624,12 @@ 29.242 return UNDEFINED; 29.243 } 29.244 29.245 - @Override 29.246 + /** 29.247 + * Is the given ScriptObject an ECMAScript Error object? 29.248 + * 29.249 + * @param sobj the object being checked 29.250 + * @return true if sobj is an Error object 29.251 + */ 29.252 public boolean isError(final ScriptObject sobj) { 29.253 final ScriptObject errorProto = getErrorPrototype(); 29.254 ScriptObject proto = sobj.getProto(); 29.255 @@ -633,52 +642,108 @@ 29.256 return false; 29.257 } 29.258 29.259 - @Override 29.260 + /** 29.261 + * Create a new ECMAScript Error object. 29.262 + * 29.263 + * @param msg error message 29.264 + * @return newly created Error object 29.265 + */ 29.266 public ScriptObject newError(final String msg) { 29.267 return new NativeError(msg, this); 29.268 } 29.269 29.270 - @Override 29.271 + /** 29.272 + * Create a new ECMAScript EvalError object. 29.273 + * 29.274 + * @param msg error message 29.275 + * @return newly created EvalError object 29.276 + */ 29.277 public ScriptObject newEvalError(final String msg) { 29.278 return new NativeEvalError(msg, this); 29.279 } 29.280 29.281 - @Override 29.282 + /** 29.283 + * Create a new ECMAScript RangeError object. 29.284 + * 29.285 + * @param msg error message 29.286 + * @return newly created RangeError object 29.287 + */ 29.288 public ScriptObject newRangeError(final String msg) { 29.289 return new NativeRangeError(msg, this); 29.290 } 29.291 29.292 - @Override 29.293 + /** 29.294 + * Create a new ECMAScript ReferenceError object. 29.295 + * 29.296 + * @param msg error message 29.297 + * @return newly created ReferenceError object 29.298 + */ 29.299 public ScriptObject newReferenceError(final String msg) { 29.300 return new NativeReferenceError(msg, this); 29.301 } 29.302 29.303 - @Override 29.304 + /** 29.305 + * Create a new ECMAScript SyntaxError object. 29.306 + * 29.307 + * @param msg error message 29.308 + * @return newly created SyntaxError object 29.309 + */ 29.310 public ScriptObject newSyntaxError(final String msg) { 29.311 return new NativeSyntaxError(msg, this); 29.312 } 29.313 29.314 - @Override 29.315 + /** 29.316 + * Create a new ECMAScript TypeError object. 29.317 + * 29.318 + * @param msg error message 29.319 + * @return newly created TypeError object 29.320 + */ 29.321 public ScriptObject newTypeError(final String msg) { 29.322 return new NativeTypeError(msg, this); 29.323 } 29.324 29.325 - @Override 29.326 + /** 29.327 + * Create a new ECMAScript URIError object. 29.328 + * 29.329 + * @param msg error message 29.330 + * @return newly created URIError object 29.331 + */ 29.332 public ScriptObject newURIError(final String msg) { 29.333 return new NativeURIError(msg, this); 29.334 } 29.335 29.336 - @Override 29.337 + /** 29.338 + * Create a new ECMAScript GenericDescriptor object. 29.339 + * 29.340 + * @param configurable is the property configurable? 29.341 + * @param enumerable is the property enumerable? 29.342 + * @return newly created GenericDescriptor object 29.343 + */ 29.344 public PropertyDescriptor newGenericDescriptor(final boolean configurable, final boolean enumerable) { 29.345 return new GenericPropertyDescriptor(configurable, enumerable, this); 29.346 } 29.347 29.348 - @Override 29.349 + /** 29.350 + * Create a new ECMAScript DatePropertyDescriptor object. 29.351 + * 29.352 + * @param value of the data property 29.353 + * @param configurable is the property configurable? 29.354 + * @param enumerable is the property enumerable? 29.355 + * @return newly created DataPropertyDescriptor object 29.356 + */ 29.357 public PropertyDescriptor newDataDescriptor(final Object value, final boolean configurable, final boolean enumerable, final boolean writable) { 29.358 return new DataPropertyDescriptor(configurable, enumerable, writable, value, this); 29.359 } 29.360 29.361 - @Override 29.362 + /** 29.363 + * Create a new ECMAScript AccessorPropertyDescriptor object. 29.364 + * 29.365 + * @param get getter function of the user accessor property 29.366 + * @param set setter function of the user accessor property 29.367 + * @param configurable is the property configurable? 29.368 + * @param enumerable is the property enumerable? 29.369 + * @return newly created AccessorPropertyDescriptor object 29.370 + */ 29.371 public PropertyDescriptor newAccessorDescriptor(final Object get, final Object set, final boolean configurable, final boolean enumerable) { 29.372 final AccessorPropertyDescriptor desc = new AccessorPropertyDescriptor(configurable, enumerable, get == null ? UNDEFINED : get, set == null ? UNDEFINED : set, this); 29.373 29.374 @@ -694,62 +759,6 @@ 29.375 } 29.376 29.377 29.378 - /** 29.379 - * Cache for compiled script classes. 29.380 - */ 29.381 - @SuppressWarnings("serial") 29.382 - private static class ClassCache extends LinkedHashMap<Source, ClassReference> { 29.383 - private final int size; 29.384 - private final ReferenceQueue<Class<?>> queue; 29.385 - 29.386 - ClassCache(int size) { 29.387 - super(size, 0.75f, true); 29.388 - this.size = size; 29.389 - this.queue = new ReferenceQueue<>(); 29.390 - } 29.391 - 29.392 - void cache(final Source source, final Class<?> clazz) { 29.393 - put(source, new ClassReference(clazz, queue, source)); 29.394 - } 29.395 - 29.396 - @Override 29.397 - protected boolean removeEldestEntry(final Map.Entry<Source, ClassReference> eldest) { 29.398 - return size() > size; 29.399 - } 29.400 - 29.401 - @Override 29.402 - public ClassReference get(Object key) { 29.403 - for (ClassReference ref; (ref = (ClassReference)queue.poll()) != null; ) { 29.404 - remove(ref.source); 29.405 - } 29.406 - return super.get(key); 29.407 - } 29.408 - 29.409 - } 29.410 - 29.411 - private static class ClassReference extends SoftReference<Class<?>> { 29.412 - private final Source source; 29.413 - 29.414 - ClassReference(final Class<?> clazz, final ReferenceQueue<Class<?>> queue, final Source source) { 29.415 - super(clazz, queue); 29.416 - this.source = source; 29.417 - } 29.418 - } 29.419 - 29.420 - // Class cache management 29.421 - @Override 29.422 - public Class<?> findCachedClass(final Source source) { 29.423 - assert classCache != null : "Class cache used without being initialized"; 29.424 - ClassReference ref = classCache.get(source); 29.425 - return ref != null ? ref.get() : null; 29.426 - } 29.427 - 29.428 - @Override 29.429 - public void cacheClass(final Source source, final Class<?> clazz) { 29.430 - assert classCache != null : "Class cache used without being initialized"; 29.431 - classCache.cache(source, clazz); 29.432 - } 29.433 - 29.434 private static <T> T getLazilyCreatedValue(final Object key, final Callable<T> creator, final Map<Object, T> map) { 29.435 final T obj = map.get(key); 29.436 if (obj != null) { 29.437 @@ -767,14 +776,25 @@ 29.438 29.439 private final Map<Object, InvokeByName> namedInvokers = new ConcurrentHashMap<>(); 29.440 29.441 - @Override 29.442 + 29.443 + /** 29.444 + * Get cached InvokeByName object for the given key 29.445 + * @param key key to be associated with InvokeByName object 29.446 + * @param creator if InvokeByName is absent 'creator' is called to make one (lazy init) 29.447 + * @return InvokeByName object associated with the key. 29.448 + */ 29.449 public InvokeByName getInvokeByName(final Object key, final Callable<InvokeByName> creator) { 29.450 return getLazilyCreatedValue(key, creator, namedInvokers); 29.451 } 29.452 29.453 private final Map<Object, MethodHandle> dynamicInvokers = new ConcurrentHashMap<>(); 29.454 29.455 - @Override 29.456 + /** 29.457 + * Get cached dynamic method handle for the given key 29.458 + * @param key key to be associated with dynamic method handle 29.459 + * @param creator if method handle is absent 'creator' is called to make one (lazy init) 29.460 + * @return dynamic method handle associated with the key. 29.461 + */ 29.462 public MethodHandle getDynamicInvoker(final Object key, final Callable<MethodHandle> creator) { 29.463 return getLazilyCreatedValue(key, creator, dynamicInvokers); 29.464 } 29.465 @@ -963,6 +983,10 @@ 29.466 return ScriptFunction.getPrototype(builtinArrayBuffer); 29.467 } 29.468 29.469 + ScriptObject getDataViewPrototype() { 29.470 + return ScriptFunction.getPrototype(builtinDataView); 29.471 + } 29.472 + 29.473 ScriptObject getInt8ArrayPrototype() { 29.474 return ScriptFunction.getPrototype(builtinInt8Array); 29.475 } 29.476 @@ -999,123 +1023,6 @@ 29.477 return ScriptFunction.getPrototype(builtinFloat64Array); 29.478 } 29.479 29.480 - // Builtin PropertyMap accessors 29.481 - PropertyMap getAccessorPropertyDescriptorMap() { 29.482 - return accessorPropertyDescriptorMap; 29.483 - } 29.484 - 29.485 - PropertyMap getArrayBufferViewMap() { 29.486 - return arrayBufferViewMap; 29.487 - } 29.488 - 29.489 - PropertyMap getDataPropertyDescriptorMap() { 29.490 - return dataPropertyDescriptorMap; 29.491 - } 29.492 - 29.493 - PropertyMap getGenericPropertyDescriptorMap() { 29.494 - return genericPropertyDescriptorMap; 29.495 - } 29.496 - 29.497 - PropertyMap getArgumentsMap() { 29.498 - return nativeArgumentsMap; 29.499 - } 29.500 - 29.501 - PropertyMap getArrayMap() { 29.502 - return nativeArrayMap; 29.503 - } 29.504 - 29.505 - PropertyMap getArrayBufferMap() { 29.506 - return nativeArrayBufferMap; 29.507 - } 29.508 - 29.509 - PropertyMap getBooleanMap() { 29.510 - return nativeBooleanMap; 29.511 - } 29.512 - 29.513 - PropertyMap getDateMap() { 29.514 - return nativeDateMap; 29.515 - } 29.516 - 29.517 - PropertyMap getErrorMap() { 29.518 - return nativeErrorMap; 29.519 - } 29.520 - 29.521 - PropertyMap getEvalErrorMap() { 29.522 - return nativeEvalErrorMap; 29.523 - } 29.524 - 29.525 - PropertyMap getJSAdapterMap() { 29.526 - return nativeJSAdapterMap; 29.527 - } 29.528 - 29.529 - PropertyMap getJavaImporterMap() { 29.530 - return nativeJavaImporterMap; 29.531 - } 29.532 - 29.533 - PropertyMap getNumberMap() { 29.534 - return nativeNumberMap; 29.535 - } 29.536 - 29.537 - PropertyMap getRangeErrorMap() { 29.538 - return nativeRangeErrorMap; 29.539 - } 29.540 - 29.541 - PropertyMap getReferenceErrorMap() { 29.542 - return nativeReferenceErrorMap; 29.543 - } 29.544 - 29.545 - PropertyMap getRegExpMap() { 29.546 - return nativeRegExpMap; 29.547 - } 29.548 - 29.549 - PropertyMap getRegExpExecResultMap() { 29.550 - return nativeRegExpExecResultMap; 29.551 - } 29.552 - 29.553 - PropertyMap getStrictArgumentsMap() { 29.554 - return nativeStrictArgumentsMap; 29.555 - } 29.556 - 29.557 - PropertyMap getStringMap() { 29.558 - return nativeStringMap; 29.559 - } 29.560 - 29.561 - PropertyMap getSyntaxErrorMap() { 29.562 - return nativeSyntaxErrorMap; 29.563 - } 29.564 - 29.565 - PropertyMap getTypeErrorMap() { 29.566 - return nativeTypeErrorMap; 29.567 - } 29.568 - 29.569 - PropertyMap getURIErrorMap() { 29.570 - return nativeURIErrorMap; 29.571 - } 29.572 - 29.573 - PropertyMap getPrototypeObjectMap() { 29.574 - return prototypeObjectMap; 29.575 - } 29.576 - 29.577 - PropertyMap getObjectMap() { 29.578 - return objectMap; 29.579 - } 29.580 - 29.581 - PropertyMap getFunctionMap() { 29.582 - return functionMap; 29.583 - } 29.584 - 29.585 - PropertyMap getAnonymousFunctionMap() { 29.586 - return anonymousFunctionMap; 29.587 - } 29.588 - 29.589 - PropertyMap getStrictFunctionMap() { 29.590 - return strictFunctionMap; 29.591 - } 29.592 - 29.593 - PropertyMap getBoundFunctionMap() { 29.594 - return boundFunctionMap; 29.595 - } 29.596 - 29.597 private ScriptFunction getBuiltinArray() { 29.598 return builtinArray; 29.599 } 29.600 @@ -1631,14 +1538,11 @@ 29.601 29.602 final ScriptEnvironment env = getContext().getEnv(); 29.603 29.604 - // duplicate PropertyMaps of Native* classes 29.605 - copyInitialMaps(env); 29.606 - 29.607 // initialize Function and Object constructor 29.608 initFunctionAndObject(); 29.609 29.610 // Now fix Global's own proto. 29.611 - this.setProto(getObjectPrototype()); 29.612 + this.setInitialProto(getObjectPrototype()); 29.613 29.614 // initialize global function properties 29.615 this.eval = this.builtinEval = ScriptFunctionImpl.makeFunction("eval", EVAL); 29.616 @@ -1705,8 +1609,25 @@ 29.617 initScripting(env); 29.618 } 29.619 29.620 - if (Context.DEBUG && System.getSecurityManager() == null) { 29.621 - initDebug(); 29.622 + if (Context.DEBUG) { 29.623 + boolean debugOkay; 29.624 + final SecurityManager sm = System.getSecurityManager(); 29.625 + if (sm != null) { 29.626 + try { 29.627 + sm.checkPermission(new RuntimePermission(Context.NASHORN_DEBUG_MODE)); 29.628 + debugOkay = true; 29.629 + } catch (final SecurityException ignored) { 29.630 + // if no permission, don't initialize Debug object 29.631 + debugOkay = false; 29.632 + } 29.633 + 29.634 + } else { 29.635 + debugOkay = true; 29.636 + } 29.637 + 29.638 + if (debugOkay) { 29.639 + initDebug(); 29.640 + } 29.641 } 29.642 29.643 copyBuiltins(); 29.644 @@ -1766,7 +1687,7 @@ 29.645 final ScriptObject prototype = ScriptFunction.getPrototype(cons); 29.646 prototype.set(NativeError.NAME, name, false); 29.647 prototype.set(NativeError.MESSAGE, "", false); 29.648 - prototype.setProto(errorProto); 29.649 + prototype.setInitialProto(errorProto); 29.650 return (ScriptFunction)cons; 29.651 } 29.652 29.653 @@ -1834,6 +1755,7 @@ 29.654 29.655 private void initTypedArray() { 29.656 this.builtinArrayBuffer = initConstructor("ArrayBuffer"); 29.657 + this.builtinDataView = initConstructor("DataView"); 29.658 this.builtinInt8Array = initConstructor("Int8Array"); 29.659 this.builtinUint8Array = initConstructor("Uint8Array"); 29.660 this.builtinUint8ClampedArray = initConstructor("Uint8ClampedArray"); 29.661 @@ -1874,6 +1796,7 @@ 29.662 this.typeError = this.builtinTypeError; 29.663 this.uriError = this.builtinURIError; 29.664 this.arrayBuffer = this.builtinArrayBuffer; 29.665 + this.dataView = this.builtinDataView; 29.666 this.int8Array = this.builtinInt8Array; 29.667 this.uint8Array = this.builtinUint8Array; 29.668 this.uint8ClampedArray = this.builtinUint8ClampedArray; 29.669 @@ -1938,7 +1861,7 @@ 29.670 } 29.671 29.672 if (res.getProto() == null) { 29.673 - res.setProto(getObjectPrototype()); 29.674 + res.setInitialProto(getObjectPrototype()); 29.675 } 29.676 29.677 return res; 29.678 @@ -1948,46 +1871,6 @@ 29.679 } 29.680 } 29.681 29.682 - private void copyInitialMaps(final ScriptEnvironment env) { 29.683 - this.accessorPropertyDescriptorMap = AccessorPropertyDescriptor.getInitialMap().duplicate(); 29.684 - this.dataPropertyDescriptorMap = DataPropertyDescriptor.getInitialMap().duplicate(); 29.685 - this.genericPropertyDescriptorMap = GenericPropertyDescriptor.getInitialMap().duplicate(); 29.686 - this.nativeArgumentsMap = NativeArguments.getInitialMap().duplicate(); 29.687 - this.nativeArrayMap = NativeArray.getInitialMap().duplicate(); 29.688 - this.nativeBooleanMap = NativeBoolean.getInitialMap().duplicate(); 29.689 - this.nativeDateMap = NativeDate.getInitialMap().duplicate(); 29.690 - this.nativeErrorMap = NativeError.getInitialMap().duplicate(); 29.691 - this.nativeEvalErrorMap = NativeEvalError.getInitialMap().duplicate(); 29.692 - this.nativeJSAdapterMap = NativeJSAdapter.getInitialMap().duplicate(); 29.693 - this.nativeNumberMap = NativeNumber.getInitialMap().duplicate(); 29.694 - this.nativeRangeErrorMap = NativeRangeError.getInitialMap().duplicate(); 29.695 - this.nativeReferenceErrorMap = NativeReferenceError.getInitialMap().duplicate(); 29.696 - this.nativeRegExpMap = NativeRegExp.getInitialMap().duplicate(); 29.697 - this.nativeRegExpExecResultMap = NativeRegExpExecResult.getInitialMap().duplicate(); 29.698 - this.nativeStrictArgumentsMap = NativeStrictArguments.getInitialMap().duplicate(); 29.699 - this.nativeStringMap = NativeString.getInitialMap().duplicate(); 29.700 - this.nativeSyntaxErrorMap = NativeSyntaxError.getInitialMap().duplicate(); 29.701 - this.nativeTypeErrorMap = NativeTypeError.getInitialMap().duplicate(); 29.702 - this.nativeURIErrorMap = NativeURIError.getInitialMap().duplicate(); 29.703 - this.prototypeObjectMap = PrototypeObject.getInitialMap().duplicate(); 29.704 - this.objectMap = JO.getInitialMap().duplicate(); 29.705 - this.functionMap = ScriptFunctionImpl.getInitialMap().duplicate(); 29.706 - this.anonymousFunctionMap = ScriptFunctionImpl.getInitialAnonymousMap().duplicate(); 29.707 - this.strictFunctionMap = ScriptFunctionImpl.getInitialStrictMap().duplicate(); 29.708 - this.boundFunctionMap = ScriptFunctionImpl.getInitialBoundMap().duplicate(); 29.709 - 29.710 - // java 29.711 - if (! env._no_java) { 29.712 - this.nativeJavaImporterMap = NativeJavaImporter.getInitialMap().duplicate(); 29.713 - } 29.714 - 29.715 - // typed arrays 29.716 - if (! env._no_typed_arrays) { 29.717 - this.arrayBufferViewMap = ArrayBufferView.getInitialMap().duplicate(); 29.718 - this.nativeArrayBufferMap = NativeArrayBuffer.getInitialMap().duplicate(); 29.719 - } 29.720 - } 29.721 - 29.722 // Function and Object constructors are inter-dependent. Also, 29.723 // Function.prototype 29.724 // functions are not properly initialized. We fix the references here. 29.725 @@ -2005,13 +1888,13 @@ 29.726 29.727 // Function.prototype === Object.getPrototypeOf(Function) === 29.728 // <anon-function> 29.729 - builtinFunction.setProto(anon); 29.730 + builtinFunction.setInitialProto(anon); 29.731 builtinFunction.setPrototype(anon); 29.732 anon.set("constructor", builtinFunction, false); 29.733 anon.deleteOwnProperty(anon.getMap().findProperty("prototype")); 29.734 29.735 // use "getter" so that [[ThrowTypeError]] function's arity is 0 - as specified in step 10 of section 13.2.3 29.736 - this.typeErrorThrower = new ScriptFunctionImpl("TypeErrorThrower", Lookup.TYPE_ERROR_THROWER_GETTER, null, null, false, false, false); 29.737 + this.typeErrorThrower = new ScriptFunctionImpl("TypeErrorThrower", Lookup.TYPE_ERROR_THROWER_GETTER, null, null, 0); 29.738 typeErrorThrower.setPrototype(UNDEFINED); 29.739 // Non-constructor built-in functions do not have "prototype" property 29.740 typeErrorThrower.deleteOwnProperty(typeErrorThrower.getMap().findProperty("prototype")); 29.741 @@ -2021,7 +1904,7 @@ 29.742 this.builtinObject = (ScriptFunction)initConstructor("Object"); 29.743 final ScriptObject ObjectPrototype = getObjectPrototype(); 29.744 // Object.getPrototypeOf(Function.prototype) === Object.prototype 29.745 - anon.setProto(ObjectPrototype); 29.746 + anon.setInitialProto(ObjectPrototype); 29.747 29.748 // Function valued properties of Function.prototype were not properly 29.749 // initialized. Because, these were created before global.function and 29.750 @@ -2033,10 +1916,10 @@ 29.751 29.752 if (value instanceof ScriptFunction && value != anon) { 29.753 final ScriptFunction func = (ScriptFunction)value; 29.754 - func.setProto(getFunctionPrototype()); 29.755 + func.setInitialProto(getFunctionPrototype()); 29.756 final ScriptObject prototype = ScriptFunction.getPrototype(func); 29.757 if (prototype != null) { 29.758 - prototype.setProto(ObjectPrototype); 29.759 + prototype.setInitialProto(ObjectPrototype); 29.760 } 29.761 } 29.762 } 29.763 @@ -2051,7 +1934,7 @@ 29.764 final ScriptFunction func = (ScriptFunction)value; 29.765 final ScriptObject prototype = ScriptFunction.getPrototype(func); 29.766 if (prototype != null) { 29.767 - prototype.setProto(ObjectPrototype); 29.768 + prototype.setInitialProto(ObjectPrototype); 29.769 } 29.770 } 29.771 } 29.772 @@ -2069,7 +1952,7 @@ 29.773 final ScriptFunction func = (ScriptFunction)value; 29.774 final ScriptObject prototype = ScriptFunction.getPrototype(func); 29.775 if (prototype != null) { 29.776 - prototype.setProto(ObjectPrototype); 29.777 + prototype.setInitialProto(ObjectPrototype); 29.778 } 29.779 } 29.780 }
30.1 --- a/src/jdk/nashorn/internal/objects/NativeArguments.java Wed Mar 26 12:01:34 2014 -0700 30.2 +++ b/src/jdk/nashorn/internal/objects/NativeArguments.java Tue Apr 01 11:44:05 2014 -0700 30.3 @@ -68,7 +68,7 @@ 30.4 final ArrayList<Property> properties = new ArrayList<>(2); 30.5 properties.add(AccessorProperty.create("length", Property.NOT_ENUMERABLE, G$LENGTH, S$LENGTH)); 30.6 properties.add(AccessorProperty.create("callee", Property.NOT_ENUMERABLE, G$CALLEE, S$CALLEE)); 30.7 - map$ = PropertyMap.newMap(properties).setIsShared(); 30.8 + map$ = PropertyMap.newMap(properties); 30.9 } 30.10 30.11 static PropertyMap getInitialMap() { 30.12 @@ -267,9 +267,9 @@ 30.13 final Global global = Global.instance(); 30.14 final ScriptObject proto = global.getObjectPrototype(); 30.15 if (isStrict) { 30.16 - return new NativeStrictArguments(arguments, numParams, proto, global.getStrictArgumentsMap()); 30.17 + return new NativeStrictArguments(arguments, numParams, proto, NativeStrictArguments.getInitialMap()); 30.18 } 30.19 - return new NativeArguments(arguments, callee, numParams, proto, global.getArgumentsMap()); 30.20 + return new NativeArguments(arguments, callee, numParams, proto, NativeArguments.getInitialMap()); 30.21 } 30.22 30.23 /**
31.1 --- a/src/jdk/nashorn/internal/objects/NativeArray.java Wed Mar 26 12:01:34 2014 -0700 31.2 +++ b/src/jdk/nashorn/internal/objects/NativeArray.java Tue Apr 01 11:44:05 2014 -0700 31.3 @@ -31,6 +31,7 @@ 31.4 import static jdk.nashorn.internal.runtime.PropertyDescriptor.WRITABLE; 31.5 import static jdk.nashorn.internal.runtime.arrays.ArrayLikeIterator.arrayLikeIterator; 31.6 import static jdk.nashorn.internal.runtime.arrays.ArrayLikeIterator.reverseArrayLikeIterator; 31.7 +import static jdk.nashorn.internal.runtime.arrays.ArrayIndex.isValidArrayIndex; 31.8 31.9 import java.lang.invoke.MethodHandle; 31.10 import java.util.ArrayList; 31.11 @@ -156,10 +157,6 @@ 31.12 // initialized by nasgen 31.13 private static PropertyMap $nasgenmap$; 31.14 31.15 - static PropertyMap getInitialMap() { 31.16 - return $nasgenmap$; 31.17 - } 31.18 - 31.19 /* 31.20 * Constructors. 31.21 */ 31.22 @@ -208,7 +205,7 @@ 31.23 } 31.24 31.25 NativeArray(final ArrayData arrayData, final Global global) { 31.26 - super(global.getArrayPrototype(), global.getArrayMap()); 31.27 + super(global.getArrayPrototype(), $nasgenmap$); 31.28 this.setArray(arrayData); 31.29 this.setIsArray(); 31.30 } 31.31 @@ -354,6 +351,27 @@ 31.32 } 31.33 31.34 /** 31.35 + * Spec. mentions use of [[DefineOwnProperty]] for indexed properties in 31.36 + * certain places (eg. Array.prototype.map, filter). We can not use ScriptObject.set 31.37 + * method in such cases. This is because set method uses inherited setters (if any) 31.38 + * from any object in proto chain such as Array.prototype, Object.prototype. 31.39 + * This method directly sets a particular element value in the current object. 31.40 + * 31.41 + * @param index key for property 31.42 + * @param value value to define 31.43 + */ 31.44 + @Override 31.45 + public final void defineOwnProperty(final int index, final Object value) { 31.46 + assert isValidArrayIndex(index) : "invalid array index"; 31.47 + final long longIndex = ArrayIndex.toLongIndex(index); 31.48 + if (longIndex >= getArray().length()) { 31.49 + // make array big enough to hold.. 31.50 + setArray(getArray().ensure(longIndex)); 31.51 + } 31.52 + setArray(getArray().set(index, value, false)); 31.53 + } 31.54 + 31.55 + /** 31.56 * Return the array contents upcasted as an ObjectArray, regardless of 31.57 * representation 31.58 * 31.59 @@ -371,7 +389,7 @@ 31.60 * @return true if argument is an array 31.61 */ 31.62 @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 31.63 - public static Object isArray(final Object self, final Object arg) { 31.64 + public static boolean isArray(final Object self, final Object arg) { 31.65 return isArray(arg) || (arg instanceof JSObject && ((JSObject)arg).isArray()); 31.66 } 31.67 31.68 @@ -470,7 +488,7 @@ 31.69 * @return locale specific string representation for array 31.70 */ 31.71 @Function(attributes = Attribute.NOT_ENUMERABLE) 31.72 - public static Object toLocaleString(final Object self) { 31.73 + public static String toLocaleString(final Object self) { 31.74 final StringBuilder sb = new StringBuilder(); 31.75 final Iterator<Object> iter = arrayLikeIterator(self, true); 31.76 31.77 @@ -516,7 +534,7 @@ 31.78 * @return the new NativeArray 31.79 */ 31.80 @Constructor(arity = 1) 31.81 - public static Object construct(final boolean newObj, final Object self, final Object... args) { 31.82 + public static NativeArray construct(final boolean newObj, final Object self, final Object... args) { 31.83 switch (args.length) { 31.84 case 0: 31.85 return new NativeArray(0); 31.86 @@ -569,7 +587,7 @@ 31.87 * @return the new NativeArray 31.88 */ 31.89 @SpecializedConstructor 31.90 - public static Object construct(final boolean newObj, final Object self) { 31.91 + public static NativeArray construct(final boolean newObj, final Object self) { 31.92 return new NativeArray(0); 31.93 } 31.94 31.95 @@ -584,7 +602,7 @@ 31.96 * @return the new NativeArray 31.97 */ 31.98 @SpecializedConstructor 31.99 - public static Object construct(final boolean newObj, final Object self, final int length) { 31.100 + public static NativeArray construct(final boolean newObj, final Object self, final int length) { 31.101 if (length >= 0) { 31.102 return new NativeArray(length); 31.103 } 31.104 @@ -603,7 +621,7 @@ 31.105 * @return the new NativeArray 31.106 */ 31.107 @SpecializedConstructor 31.108 - public static Object construct(final boolean newObj, final Object self, final long length) { 31.109 + public static NativeArray construct(final boolean newObj, final Object self, final long length) { 31.110 if (length >= 0L && length <= JSType.MAX_UINT) { 31.111 return new NativeArray(length); 31.112 } 31.113 @@ -622,7 +640,7 @@ 31.114 * @return the new NativeArray 31.115 */ 31.116 @SpecializedConstructor 31.117 - public static Object construct(final boolean newObj, final Object self, final double length) { 31.118 + public static NativeArray construct(final boolean newObj, final Object self, final double length) { 31.119 final long uint32length = JSType.toUint32(length); 31.120 31.121 if (uint32length == length) { 31.122 @@ -640,7 +658,7 @@ 31.123 * @return resulting NativeArray 31.124 */ 31.125 @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) 31.126 - public static Object concat(final Object self, final Object... args) { 31.127 + public static NativeArray concat(final Object self, final Object... args) { 31.128 final ArrayList<Object> list = new ArrayList<>(); 31.129 concatToList(list, Global.toObject(self)); 31.130 31.131 @@ -687,7 +705,7 @@ 31.132 * @return string representation after join 31.133 */ 31.134 @Function(attributes = Attribute.NOT_ENUMERABLE) 31.135 - public static Object join(final Object self, final Object separator) { 31.136 + public static String join(final Object self, final Object separator) { 31.137 final StringBuilder sb = new StringBuilder(); 31.138 final Iterator<Object> iter = arrayLikeIterator(self, true); 31.139 final String sep = separator == ScriptRuntime.UNDEFINED ? "," : JSType.toString(separator); 31.140 @@ -955,7 +973,7 @@ 31.141 * @return sorted array 31.142 */ 31.143 @Function(attributes = Attribute.NOT_ENUMERABLE) 31.144 - public static Object sort(final Object self, final Object comparefn) { 31.145 + public static ScriptObject sort(final Object self, final Object comparefn) { 31.146 try { 31.147 final ScriptObject sobj = (ScriptObject) self; 31.148 final long len = JSType.toUint32(sobj.getLength()); 31.149 @@ -1159,7 +1177,7 @@ 31.150 * @return index of element, or -1 if not found 31.151 */ 31.152 @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) 31.153 - public static Object indexOf(final Object self, final Object searchElement, final Object fromIndex) { 31.154 + public static long indexOf(final Object self, final Object searchElement, final Object fromIndex) { 31.155 try { 31.156 final ScriptObject sobj = (ScriptObject)Global.toObject(self); 31.157 final long len = JSType.toUint32(sobj.getLength()); 31.158 @@ -1195,7 +1213,7 @@ 31.159 * @return index of element, or -1 if not found 31.160 */ 31.161 @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) 31.162 - public static Object lastIndexOf(final Object self, final Object... args) { 31.163 + public static long lastIndexOf(final Object self, final Object... args) { 31.164 try { 31.165 final ScriptObject sobj = (ScriptObject)Global.toObject(self); 31.166 final long len = JSType.toUint32(sobj.getLength()); 31.167 @@ -1230,7 +1248,7 @@ 31.168 * @return true if callback function return true for every element in the array, false otherwise 31.169 */ 31.170 @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) 31.171 - public static Object every(final Object self, final Object callbackfn, final Object thisArg) { 31.172 + public static boolean every(final Object self, final Object callbackfn, final Object thisArg) { 31.173 return applyEvery(Global.toObject(self), callbackfn, thisArg); 31.174 } 31.175 31.176 @@ -1254,7 +1272,7 @@ 31.177 * @return true if callback function returned true for any element in the array, false otherwise 31.178 */ 31.179 @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) 31.180 - public static Object some(final Object self, final Object callbackfn, final Object thisArg) { 31.181 + public static boolean some(final Object self, final Object callbackfn, final Object thisArg) { 31.182 return new IteratorAction<Boolean>(Global.toObject(self), callbackfn, thisArg, false) { 31.183 private final MethodHandle someInvoker = getSOME_CALLBACK_INVOKER(); 31.184 31.185 @@ -1295,7 +1313,7 @@ 31.186 * @return array with elements transformed by map function 31.187 */ 31.188 @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) 31.189 - public static Object map(final Object self, final Object callbackfn, final Object thisArg) { 31.190 + public static NativeArray map(final Object self, final Object callbackfn, final Object thisArg) { 31.191 return new IteratorAction<NativeArray>(Global.toObject(self), callbackfn, thisArg, null) { 31.192 private final MethodHandle mapInvoker = getMAP_CALLBACK_INVOKER(); 31.193 31.194 @@ -1324,7 +1342,7 @@ 31.195 * @return filtered array 31.196 */ 31.197 @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) 31.198 - public static Object filter(final Object self, final Object callbackfn, final Object thisArg) { 31.199 + public static NativeArray filter(final Object self, final Object callbackfn, final Object thisArg) { 31.200 return new IteratorAction<NativeArray>(Global.toObject(self), callbackfn, thisArg, new NativeArray()) { 31.201 private long to = 0; 31.202 private final MethodHandle filterInvoker = getFILTER_CALLBACK_INVOKER();
32.1 --- a/src/jdk/nashorn/internal/objects/NativeArrayBuffer.java Wed Mar 26 12:01:34 2014 -0700 32.2 +++ b/src/jdk/nashorn/internal/objects/NativeArrayBuffer.java Tue Apr 01 11:44:05 2014 -0700 32.3 @@ -25,6 +25,7 @@ 32.4 32.5 package jdk.nashorn.internal.objects; 32.6 32.7 +import java.nio.ByteBuffer; 32.8 import java.util.Arrays; 32.9 import jdk.nashorn.internal.objects.annotations.Attribute; 32.10 import jdk.nashorn.internal.objects.annotations.Constructor; 32.11 @@ -43,12 +44,8 @@ 32.12 // initialized by nasgen 32.13 private static PropertyMap $nasgenmap$; 32.14 32.15 - static PropertyMap getInitialMap() { 32.16 - return $nasgenmap$; 32.17 - } 32.18 - 32.19 @Constructor(arity = 1) 32.20 - public static Object constructor(final boolean newObj, final Object self, final Object... args) { 32.21 + public static NativeArrayBuffer constructor(final boolean newObj, final Object self, final Object... args) { 32.22 if (args.length == 0) { 32.23 throw new RuntimeException("missing length argument"); 32.24 } 32.25 @@ -57,7 +54,7 @@ 32.26 } 32.27 32.28 protected NativeArrayBuffer(final byte[] byteArray, final Global global) { 32.29 - super(global.getArrayBufferPrototype(), global.getArrayBufferMap()); 32.30 + super(global.getArrayBufferPrototype(), $nasgenmap$); 32.31 this.buffer = byteArray; 32.32 } 32.33 32.34 @@ -84,7 +81,7 @@ 32.35 } 32.36 32.37 @Function(attributes = Attribute.NOT_ENUMERABLE) 32.38 - public static Object slice(final Object self, final Object begin0, final Object end0) { 32.39 + public static NativeArrayBuffer slice(final Object self, final Object begin0, final Object end0) { 32.40 final NativeArrayBuffer arrayBuffer = (NativeArrayBuffer)self; 32.41 int begin = JSType.toInt32(begin0); 32.42 int end = end0 != ScriptRuntime.UNDEFINED ? JSType.toInt32(end0) : arrayBuffer.getByteLength(); 32.43 @@ -128,4 +125,16 @@ 32.44 public int getByteLength() { 32.45 return buffer.length; 32.46 } 32.47 + 32.48 + ByteBuffer getBuffer() { 32.49 + return ByteBuffer.wrap(buffer); 32.50 + } 32.51 + 32.52 + ByteBuffer getBuffer(final int offset) { 32.53 + return ByteBuffer.wrap(buffer, offset, buffer.length - offset); 32.54 + } 32.55 + 32.56 + ByteBuffer getBuffer(final int offset, final int length) { 32.57 + return ByteBuffer.wrap(buffer, offset, length); 32.58 + } 32.59 }
33.1 --- a/src/jdk/nashorn/internal/objects/NativeBoolean.java Wed Mar 26 12:01:34 2014 -0700 33.2 +++ b/src/jdk/nashorn/internal/objects/NativeBoolean.java Tue Apr 01 11:44:05 2014 -0700 33.3 @@ -30,6 +30,7 @@ 33.4 33.5 import java.lang.invoke.MethodHandle; 33.6 import java.lang.invoke.MethodHandles; 33.7 +import java.lang.invoke.MethodType; 33.8 import jdk.internal.dynalink.linker.GuardedInvocation; 33.9 import jdk.internal.dynalink.linker.LinkRequest; 33.10 import jdk.nashorn.internal.objects.annotations.Attribute; 33.11 @@ -50,22 +51,21 @@ 33.12 public final class NativeBoolean extends ScriptObject { 33.13 private final boolean value; 33.14 33.15 - final static MethodHandle WRAPFILTER = findWrapFilter(); 33.16 + // Method handle to create an object wrapper for a primitive boolean 33.17 + private static final MethodHandle WRAPFILTER = findOwnMH("wrapFilter", MH.type(NativeBoolean.class, Object.class)); 33.18 + // Method handle to retrieve the Boolean prototype object 33.19 + private static final MethodHandle PROTOFILTER = findOwnMH("protoFilter", MH.type(Object.class, Object.class)); 33.20 33.21 // initialized by nasgen 33.22 private static PropertyMap $nasgenmap$; 33.23 33.24 - static PropertyMap getInitialMap() { 33.25 - return $nasgenmap$; 33.26 - } 33.27 - 33.28 private NativeBoolean(final boolean value, final ScriptObject proto, final PropertyMap map) { 33.29 super(proto, map); 33.30 this.value = value; 33.31 } 33.32 33.33 NativeBoolean(final boolean flag, final Global global) { 33.34 - this(flag, global.getBooleanPrototype(), global.getBooleanMap()); 33.35 + this(flag, global.getBooleanPrototype(), $nasgenmap$); 33.36 } 33.37 33.38 NativeBoolean(final boolean flag) { 33.39 @@ -110,7 +110,7 @@ 33.40 * @return string representation of this boolean 33.41 */ 33.42 @Function(attributes = Attribute.NOT_ENUMERABLE) 33.43 - public static Object toString(final Object self) { 33.44 + public static String toString(final Object self) { 33.45 return getBoolean(self).toString(); 33.46 } 33.47 33.48 @@ -121,7 +121,7 @@ 33.49 * @return value of this boolean 33.50 */ 33.51 @Function(attributes = Attribute.NOT_ENUMERABLE) 33.52 - public static Object valueOf(final Object self) { 33.53 + public static boolean valueOf(final Object self) { 33.54 return getBoolean(self); 33.55 } 33.56 33.57 @@ -164,7 +164,7 @@ 33.58 * @return Link to be invoked at call site. 33.59 */ 33.60 public static GuardedInvocation lookupPrimitive(final LinkRequest request, final Object receiver) { 33.61 - return PrimitiveLookup.lookupPrimitive(request, Boolean.class, new NativeBoolean((Boolean)receiver), WRAPFILTER); 33.62 + return PrimitiveLookup.lookupPrimitive(request, Boolean.class, new NativeBoolean((Boolean)receiver), WRAPFILTER, PROTOFILTER); 33.63 } 33.64 33.65 /** 33.66 @@ -178,7 +178,12 @@ 33.67 return new NativeBoolean((Boolean)receiver); 33.68 } 33.69 33.70 - private static MethodHandle findWrapFilter() { 33.71 - return MH.findStatic(MethodHandles.lookup(), NativeBoolean.class, "wrapFilter", MH.type(NativeBoolean.class, Object.class)); 33.72 + @SuppressWarnings("unused") 33.73 + private static Object protoFilter(final Object object) { 33.74 + return Global.instance().getBooleanPrototype(); 33.75 + } 33.76 + 33.77 + private static MethodHandle findOwnMH(final String name, final MethodType type) { 33.78 + return MH.findStatic(MethodHandles.lookup(), NativeBoolean.class, name, type); 33.79 } 33.80 }
34.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 34.2 +++ b/src/jdk/nashorn/internal/objects/NativeDataView.java Tue Apr 01 11:44:05 2014 -0700 34.3 @@ -0,0 +1,1015 @@ 34.4 +/* 34.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 34.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 34.7 + * 34.8 + * This code is free software; you can redistribute it and/or modify it 34.9 + * under the terms of the GNU General Public License version 2 only, as 34.10 + * published by the Free Software Foundation. Oracle designates this 34.11 + * particular file as subject to the "Classpath" exception as provided 34.12 + * by Oracle in the LICENSE file that accompanied this code. 34.13 + * 34.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 34.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 34.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 34.17 + * version 2 for more details (a copy is included in the LICENSE file that 34.18 + * accompanied this code). 34.19 + * 34.20 + * You should have received a copy of the GNU General Public License version 34.21 + * 2 along with this work; if not, write to the Free Software Foundation, 34.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 34.23 + * 34.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 34.25 + * or visit www.oracle.com if you need additional information or have any 34.26 + * questions. 34.27 + */ 34.28 +package jdk.nashorn.internal.objects; 34.29 + 34.30 +import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED; 34.31 +import static jdk.nashorn.internal.runtime.ECMAErrors.rangeError; 34.32 +import static jdk.nashorn.internal.runtime.ECMAErrors.typeError; 34.33 + 34.34 +import java.nio.ByteBuffer; 34.35 +import java.nio.ByteOrder; 34.36 +import jdk.nashorn.internal.objects.annotations.Attribute; 34.37 +import jdk.nashorn.internal.objects.annotations.Constructor; 34.38 +import jdk.nashorn.internal.objects.annotations.Function; 34.39 +import jdk.nashorn.internal.objects.annotations.Property; 34.40 +import jdk.nashorn.internal.objects.annotations.ScriptClass; 34.41 +import jdk.nashorn.internal.objects.annotations.SpecializedConstructor; 34.42 +import jdk.nashorn.internal.objects.annotations.SpecializedFunction; 34.43 +import jdk.nashorn.internal.runtime.JSType; 34.44 +import jdk.nashorn.internal.runtime.PropertyMap; 34.45 +import jdk.nashorn.internal.runtime.ScriptObject; 34.46 +import jdk.nashorn.internal.runtime.ScriptRuntime; 34.47 + 34.48 +/** 34.49 + * <p> 34.50 + * DataView builtin constructor. Based on the specification here: 34.51 + * http://www.khronos.org/registry/typedarray/specs/latest/#8 34.52 + * </p> 34.53 + * <p> 34.54 + * An ArrayBuffer is a useful object for representing an arbitrary chunk of data. 34.55 + * In many cases, such data will be read from disk or from the network, and will 34.56 + * not follow the alignment restrictions that are imposed on the typed array views 34.57 + * described earlier. In addition, the data will often be heterogeneous in nature 34.58 + * and have a defined byte order. The DataView view provides a low-level interface 34.59 + * for reading such data from and writing it to an ArrayBuffer. 34.60 + * </p> 34.61 + * <p> 34.62 + * Regardless of the host computer's endianness, DataView reads or writes values 34.63 + * to or from main memory with a specified endianness: big or little. 34.64 + * </p> 34.65 + */ 34.66 +@ScriptClass("DataView") 34.67 +public class NativeDataView extends ScriptObject { 34.68 + // initialized by nasgen 34.69 + private static PropertyMap $nasgenmap$; 34.70 + 34.71 + // inherited ArrayBufferView properties 34.72 + 34.73 + /** 34.74 + * Underlying ArrayBuffer storage object 34.75 + */ 34.76 + @Property(attributes = Attribute.NON_ENUMERABLE_CONSTANT) 34.77 + public final Object buffer; 34.78 + 34.79 + /** 34.80 + * The offset in bytes from the start of the ArrayBuffer 34.81 + */ 34.82 + @Property(attributes = Attribute.NON_ENUMERABLE_CONSTANT) 34.83 + public final int byteOffset; 34.84 + 34.85 + /** 34.86 + * The number of bytes from the offset that this DataView will reference 34.87 + */ 34.88 + @Property(attributes = Attribute.NON_ENUMERABLE_CONSTANT) 34.89 + public final int byteLength; 34.90 + 34.91 + // underlying ByteBuffer 34.92 + private final ByteBuffer buf; 34.93 + 34.94 + private NativeDataView(NativeArrayBuffer arrBuf) { 34.95 + this(arrBuf, arrBuf.getBuffer(), 0); 34.96 + } 34.97 + 34.98 + private NativeDataView(NativeArrayBuffer arrBuf, int offset) { 34.99 + this(arrBuf, bufferFrom(arrBuf, offset), offset); 34.100 + } 34.101 + 34.102 + private NativeDataView(NativeArrayBuffer arrBuf, int offset, int length) { 34.103 + this(arrBuf, bufferFrom(arrBuf, offset, length), offset, length); 34.104 + } 34.105 + 34.106 + private NativeDataView(final NativeArrayBuffer arrBuf, final ByteBuffer buf, final int offset) { 34.107 + this(arrBuf, buf, offset, buf.capacity() - offset); 34.108 + } 34.109 + 34.110 + private NativeDataView(final NativeArrayBuffer arrBuf, final ByteBuffer buf, final int offset, final int length) { 34.111 + super(Global.instance().getDataViewPrototype(), $nasgenmap$); 34.112 + this.buffer = arrBuf; 34.113 + this.byteOffset = offset; 34.114 + this.byteLength = length; 34.115 + this.buf = buf; 34.116 + } 34.117 + 34.118 + /** 34.119 + * Create a new DataView object using the passed ArrayBuffer for its 34.120 + * storage. Optional byteOffset and byteLength can be used to limit the 34.121 + * section of the buffer referenced. The byteOffset indicates the offset in 34.122 + * bytes from the start of the ArrayBuffer, and the byteLength is the number 34.123 + * of bytes from the offset that this DataView will reference. If both 34.124 + * byteOffset and byteLength are omitted, the DataView spans the entire 34.125 + * ArrayBuffer range. If the byteLength is omitted, the DataView extends from 34.126 + * the given byteOffset until the end of the ArrayBuffer. 34.127 + * 34.128 + * If the given byteOffset and byteLength references an area beyond the end 34.129 + * of the ArrayBuffer an exception is raised. 34.130 + 34.131 + * @param newObj if this constructor was invoked with 'new' or not 34.132 + * @param self constructor function object 34.133 + * @param args arguments to the constructor 34.134 + * @return newly constructed DataView object 34.135 + */ 34.136 + @Constructor(arity = 1) 34.137 + public static NativeDataView constructor(final boolean newObj, final Object self, final Object... args) { 34.138 + if (args.length == 0 || !(args[0] instanceof NativeArrayBuffer)) { 34.139 + throw typeError("not.an.arraybuffer.in.dataview"); 34.140 + } 34.141 + 34.142 + final NativeArrayBuffer arrBuf = (NativeArrayBuffer) args[0]; 34.143 + switch (args.length) { 34.144 + case 1: 34.145 + return new NativeDataView(arrBuf); 34.146 + case 2: 34.147 + return new NativeDataView(arrBuf, JSType.toInt32(args[1])); 34.148 + default: 34.149 + return new NativeDataView(arrBuf, JSType.toInt32(args[1]), JSType.toInt32(args[2])); 34.150 + } 34.151 + } 34.152 + 34.153 + /** 34.154 + * Specialized version of DataView constructor 34.155 + * 34.156 + * @param newObj if this constructor was invoked with 'new' or not 34.157 + * @param self constructor function object 34.158 + * @param arrBuf underlying ArrayBuffer storage object 34.159 + * @param offset offset in bytes from the start of the ArrayBuffer 34.160 + * @return newly constructed DataView object 34.161 + */ 34.162 + @SpecializedConstructor 34.163 + public static NativeDataView constructor(final boolean newObj, final Object self, final Object arrBuf, final int offset) { 34.164 + if (!(arrBuf instanceof NativeArrayBuffer)) { 34.165 + throw typeError("not.an.arraybuffer.in.dataview"); 34.166 + } 34.167 + return new NativeDataView((NativeArrayBuffer) arrBuf, offset); 34.168 + } 34.169 + 34.170 + /** 34.171 + * Specialized version of DataView constructor 34.172 + * 34.173 + * @param newObj if this constructor was invoked with 'new' or not 34.174 + * @param self constructor function object 34.175 + * @param arrBuf underlying ArrayBuffer storage object 34.176 + * @param offset in bytes from the start of the ArrayBuffer 34.177 + * @param length is the number of bytes from the offset that this DataView will reference 34.178 + * @return newly constructed DataView object 34.179 + */ 34.180 + @SpecializedConstructor 34.181 + public static NativeDataView constructor(final boolean newObj, final Object self, final Object arrBuf, final int offset, final int length) { 34.182 + if (!(arrBuf instanceof NativeArrayBuffer)) { 34.183 + throw typeError("not.an.arraybuffer.in.dataview"); 34.184 + } 34.185 + return new NativeDataView((NativeArrayBuffer) arrBuf, offset, length); 34.186 + } 34.187 + 34.188 + // Gets the value of the given type at the specified byte offset 34.189 + // from the start of the view. There is no alignment constraint; 34.190 + // multi-byte values may be fetched from any offset. 34.191 + // 34.192 + // For multi-byte values, the optional littleEndian argument 34.193 + // indicates whether a big-endian or little-endian value should be 34.194 + // read. If false or undefined, a big-endian value is read. 34.195 + // 34.196 + // These methods raise an exception if they would read 34.197 + // beyond the end of the view. 34.198 + 34.199 + /** 34.200 + * Get 8-bit signed int from given byteOffset 34.201 + * 34.202 + * @param self DataView object 34.203 + * @param byteOffset byte offset to read from 34.204 + * @return 8-bit signed int value at the byteOffset 34.205 + */ 34.206 + @Function(attributes = Attribute.NOT_ENUMERABLE) 34.207 + public static int getInt8(final Object self, final Object byteOffset) { 34.208 + try { 34.209 + return getBuffer(self).get(JSType.toInt32(byteOffset)); 34.210 + } catch (final IndexOutOfBoundsException ioe) { 34.211 + throw rangeError(ioe, "dataview.offset"); 34.212 + } 34.213 + } 34.214 + 34.215 + /** 34.216 + * Get 8-bit signed int from given byteOffset 34.217 + * 34.218 + * @param self DataView object 34.219 + * @param byteOffset byte offset to read from 34.220 + * @return 8-bit signed int value at the byteOffset 34.221 + */ 34.222 + @SpecializedFunction 34.223 + public static int getInt8(final Object self, final int byteOffset) { 34.224 + try { 34.225 + return getBuffer(self).get(byteOffset); 34.226 + } catch (final IndexOutOfBoundsException ioe) { 34.227 + throw rangeError(ioe, "dataview.offset"); 34.228 + } 34.229 + } 34.230 + 34.231 + /** 34.232 + * Get 8-bit unsigned int from given byteOffset 34.233 + * 34.234 + * @param self DataView object 34.235 + * @param byteOffset byte offset to read from 34.236 + * @return 8-bit unsigned int value at the byteOffset 34.237 + */ 34.238 + @Function(attributes = Attribute.NOT_ENUMERABLE) 34.239 + public static int getUint8(final Object self, final Object byteOffset) { 34.240 + try { 34.241 + return (0xFF & getBuffer(self).get(JSType.toInt32(byteOffset))); 34.242 + } catch (final IndexOutOfBoundsException ioe) { 34.243 + throw rangeError(ioe, "dataview.offset"); 34.244 + } 34.245 + } 34.246 + 34.247 + /** 34.248 + * Get 8-bit unsigned int from given byteOffset 34.249 + * 34.250 + * @param self DataView object 34.251 + * @param byteOffset byte offset to read from 34.252 + * @return 8-bit unsigned int value at the byteOffset 34.253 + */ 34.254 + @SpecializedFunction 34.255 + public static int getUint8(final Object self, final int byteOffset) { 34.256 + try { 34.257 + return (0xFF & getBuffer(self).get(byteOffset)); 34.258 + } catch (final IndexOutOfBoundsException ioe) { 34.259 + throw rangeError(ioe, "dataview.offset"); 34.260 + } 34.261 + } 34.262 + 34.263 + /** 34.264 + * Get 16-bit signed int from given byteOffset 34.265 + * 34.266 + * @param self DataView object 34.267 + * @param byteOffset byte offset to read from 34.268 + * @param littleEndian (optional) flag indicating whether to read in little endian order 34.269 + * @return 16-bit signed int value at the byteOffset 34.270 + */ 34.271 + @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) 34.272 + public static int getInt16(final Object self, final Object byteOffset, final Object littleEndian) { 34.273 + try { 34.274 + return getBuffer(self, littleEndian).getShort(JSType.toInt32(byteOffset)); 34.275 + } catch (final IndexOutOfBoundsException ioe) { 34.276 + throw rangeError(ioe, "dataview.offset"); 34.277 + } 34.278 + } 34.279 + 34.280 + /** 34.281 + * Get 16-bit signed int from given byteOffset 34.282 + * 34.283 + * @param self DataView object 34.284 + * @param byteOffset byte offset to read from 34.285 + * @return 16-bit signed int value at the byteOffset 34.286 + */ 34.287 + @SpecializedFunction 34.288 + public static int getInt16(final Object self, final int byteOffset) { 34.289 + try { 34.290 + return getBuffer(self, false).getShort(byteOffset); 34.291 + } catch (final IndexOutOfBoundsException ioe) { 34.292 + throw rangeError(ioe, "dataview.offset"); 34.293 + } 34.294 + } 34.295 + 34.296 + /** 34.297 + * Get 16-bit signed int from given byteOffset 34.298 + * 34.299 + * @param self DataView object 34.300 + * @param byteOffset byte offset to read from 34.301 + * @param littleEndian (optional) flag indicating whether to read in little endian order 34.302 + * @return 16-bit signed int value at the byteOffset 34.303 + */ 34.304 + @SpecializedFunction 34.305 + public static int getInt16(final Object self, final int byteOffset, final boolean littleEndian) { 34.306 + try { 34.307 + return getBuffer(self, littleEndian).getShort(byteOffset); 34.308 + } catch (final IndexOutOfBoundsException ioe) { 34.309 + throw rangeError(ioe, "dataview.offset"); 34.310 + } 34.311 + } 34.312 + 34.313 + /** 34.314 + * Get 16-bit unsigned int from given byteOffset 34.315 + * 34.316 + * @param self DataView object 34.317 + * @param byteOffset byte offset to read from 34.318 + * @param littleEndian (optional) flag indicating whether to read in little endian order 34.319 + * @return 16-bit unsigned int value at the byteOffset 34.320 + */ 34.321 + @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) 34.322 + public static int getUint16(final Object self, final Object byteOffset, final Object littleEndian) { 34.323 + try { 34.324 + return (int) (0xFFFF & getBuffer(self, littleEndian).getShort(JSType.toInt32(byteOffset))); 34.325 + } catch (final IndexOutOfBoundsException ioe) { 34.326 + throw rangeError(ioe, "dataview.offset"); 34.327 + } 34.328 + } 34.329 + 34.330 + /** 34.331 + * Get 16-bit unsigned int from given byteOffset 34.332 + * 34.333 + * @param self DataView object 34.334 + * @param byteOffset byte offset to read from 34.335 + * @return 16-bit unsigned int value at the byteOffset 34.336 + */ 34.337 + @SpecializedFunction 34.338 + public static int getUint16(final Object self, final int byteOffset) { 34.339 + try { 34.340 + return (int) (0xFFFF & getBuffer(self, false).getShort(byteOffset)); 34.341 + } catch (final IndexOutOfBoundsException ioe) { 34.342 + throw rangeError(ioe, "dataview.offset"); 34.343 + } 34.344 + } 34.345 + 34.346 + /** 34.347 + * Get 16-bit unsigned int from given byteOffset 34.348 + * 34.349 + * @param self DataView object 34.350 + * @param byteOffset byte offset to read from 34.351 + * @param littleEndian (optional) flag indicating whether to read in little endian order 34.352 + * @return 16-bit unsigned int value at the byteOffset 34.353 + */ 34.354 + @SpecializedFunction 34.355 + public static int getUint16(final Object self, final int byteOffset, final boolean littleEndian) { 34.356 + try { 34.357 + return (int) (0xFFFF & getBuffer(self, littleEndian).getShort(byteOffset)); 34.358 + } catch (final IndexOutOfBoundsException ioe) { 34.359 + throw rangeError(ioe, "dataview.offset"); 34.360 + } 34.361 + } 34.362 + 34.363 + /** 34.364 + * Get 32-bit signed int from given byteOffset 34.365 + * 34.366 + * @param self DataView object 34.367 + * @param byteOffset byte offset to read from 34.368 + * @param littleEndian (optional) flag indicating whether to read in little endian order 34.369 + * @return 32-bit signed int value at the byteOffset 34.370 + */ 34.371 + @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) 34.372 + public static int getInt32(final Object self, final Object byteOffset, final Object littleEndian) { 34.373 + try { 34.374 + return getBuffer(self, littleEndian).getInt(JSType.toInt32(byteOffset)); 34.375 + } catch (final IndexOutOfBoundsException ioe) { 34.376 + throw rangeError(ioe, "dataview.offset"); 34.377 + } 34.378 + } 34.379 + 34.380 + /** 34.381 + * Get 32-bit signed int from given byteOffset 34.382 + * 34.383 + * @param self DataView object 34.384 + * @param byteOffset byte offset to read from 34.385 + * @return 32-bit signed int value at the byteOffset 34.386 + */ 34.387 + @SpecializedFunction 34.388 + public static int getInt32(final Object self, final int byteOffset) { 34.389 + try { 34.390 + return getBuffer(self, false).getInt(byteOffset); 34.391 + } catch (final IndexOutOfBoundsException ioe) { 34.392 + throw rangeError(ioe, "dataview.offset"); 34.393 + } 34.394 + } 34.395 + 34.396 + /** 34.397 + * Get 32-bit signed int from given byteOffset 34.398 + * 34.399 + * @param self DataView object 34.400 + * @param byteOffset byte offset to read from 34.401 + * @param littleEndian (optional) flag indicating whether to read in little endian order 34.402 + * @return 32-bit signed int value at the byteOffset 34.403 + */ 34.404 + @SpecializedFunction 34.405 + public static int getInt32(final Object self, final int byteOffset, final boolean littleEndian) { 34.406 + try { 34.407 + return getBuffer(self, littleEndian).getInt(byteOffset); 34.408 + } catch (final IndexOutOfBoundsException ioe) { 34.409 + throw rangeError(ioe, "dataview.offset"); 34.410 + } 34.411 + } 34.412 + 34.413 + /** 34.414 + * Get 32-bit unsigned int from given byteOffset 34.415 + * 34.416 + * @param self DataView object 34.417 + * @param byteOffset byte offset to read from 34.418 + * @param littleEndian (optional) flag indicating whether to read in little endian order 34.419 + * @return 32-bit unsigned int value at the byteOffset 34.420 + */ 34.421 + @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) 34.422 + public static long getUint32(final Object self, final Object byteOffset, final Object littleEndian) { 34.423 + try { 34.424 + return (long) (0xFFFFFFFFL & getBuffer(self, littleEndian).getInt(JSType.toInt32(byteOffset))); 34.425 + } catch (final IndexOutOfBoundsException ioe) { 34.426 + throw rangeError(ioe, "dataview.offset"); 34.427 + } 34.428 + } 34.429 + 34.430 + /** 34.431 + * Get 32-bit unsigned int from given byteOffset 34.432 + * 34.433 + * @param self DataView object 34.434 + * @param byteOffset byte offset to read from 34.435 + * @return 32-bit unsigned int value at the byteOffset 34.436 + */ 34.437 + @SpecializedFunction 34.438 + public static long getUint32(final Object self, final int byteOffset) { 34.439 + try { 34.440 + return (long) (0xFFFFFFFFL & getBuffer(self, false).getInt(JSType.toInt32(byteOffset))); 34.441 + } catch (final IndexOutOfBoundsException ioe) { 34.442 + throw rangeError(ioe, "dataview.offset"); 34.443 + } 34.444 + } 34.445 + 34.446 + /** 34.447 + * Get 32-bit unsigned int from given byteOffset 34.448 + * 34.449 + * @param self DataView object 34.450 + * @param byteOffset byte offset to read from 34.451 + * @param littleEndian (optional) flag indicating whether to read in little endian order 34.452 + * @return 32-bit unsigned int value at the byteOffset 34.453 + */ 34.454 + @SpecializedFunction 34.455 + public static long getUint32(final Object self, final int byteOffset, final boolean littleEndian) { 34.456 + try { 34.457 + return (long) (0xFFFFFFFFL & getBuffer(self, littleEndian).getInt(JSType.toInt32(byteOffset))); 34.458 + } catch (final IndexOutOfBoundsException ioe) { 34.459 + throw rangeError(ioe, "dataview.offset"); 34.460 + } 34.461 + } 34.462 + 34.463 + /** 34.464 + * Get 32-bit float value from given byteOffset 34.465 + * 34.466 + * @param self DataView object 34.467 + * @param byteOffset byte offset to read from 34.468 + * @param littleEndian (optional) flag indicating whether to read in little endian order 34.469 + * @return 32-bit float value at the byteOffset 34.470 + */ 34.471 + @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) 34.472 + public static double getFloat32(final Object self, final Object byteOffset, final Object littleEndian) { 34.473 + try { 34.474 + return getBuffer(self, littleEndian).getFloat(JSType.toInt32(byteOffset)); 34.475 + } catch (final IndexOutOfBoundsException ioe) { 34.476 + throw rangeError(ioe, "dataview.offset"); 34.477 + } 34.478 + } 34.479 + 34.480 + /** 34.481 + * Get 32-bit float value from given byteOffset 34.482 + * 34.483 + * @param self DataView object 34.484 + * @param byteOffset byte offset to read from 34.485 + * @return 32-bit float value at the byteOffset 34.486 + */ 34.487 + @SpecializedFunction 34.488 + public static double getFloat32(final Object self, final int byteOffset) { 34.489 + try { 34.490 + return getBuffer(self, false).getFloat(byteOffset); 34.491 + } catch (final IndexOutOfBoundsException ioe) { 34.492 + throw rangeError(ioe, "dataview.offset"); 34.493 + } 34.494 + } 34.495 + 34.496 + /** 34.497 + * Get 32-bit float value from given byteOffset 34.498 + * 34.499 + * @param self DataView object 34.500 + * @param byteOffset byte offset to read from 34.501 + * @param littleEndian (optional) flag indicating whether to read in little endian order 34.502 + * @return 32-bit float value at the byteOffset 34.503 + */ 34.504 + @SpecializedFunction 34.505 + public static double getFloat32(final Object self, final int byteOffset, final boolean littleEndian) { 34.506 + try { 34.507 + return getBuffer(self, littleEndian).getFloat(byteOffset); 34.508 + } catch (final IndexOutOfBoundsException ioe) { 34.509 + throw rangeError(ioe, "dataview.offset"); 34.510 + } 34.511 + } 34.512 + 34.513 + /** 34.514 + * Get 64-bit float value from given byteOffset 34.515 + * 34.516 + * @param self DataView object 34.517 + * @param byteOffset byte offset to read from 34.518 + * @param littleEndian (optional) flag indicating whether to read in little endian order 34.519 + * @return 64-bit float value at the byteOffset 34.520 + */ 34.521 + @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) 34.522 + public static double getFloat64(final Object self, final Object byteOffset, final Object littleEndian) { 34.523 + try { 34.524 + return getBuffer(self, littleEndian).getDouble(JSType.toInt32(byteOffset)); 34.525 + } catch (final IndexOutOfBoundsException ioe) { 34.526 + throw rangeError(ioe, "dataview.offset"); 34.527 + } 34.528 + } 34.529 + 34.530 + /** 34.531 + * Get 64-bit float value from given byteOffset 34.532 + * 34.533 + * @param self DataView object 34.534 + * @param byteOffset byte offset to read from 34.535 + * @return 64-bit float value at the byteOffset 34.536 + */ 34.537 + @SpecializedFunction 34.538 + public static double getFloat64(final Object self, final int byteOffset) { 34.539 + try { 34.540 + return getBuffer(self, false).getDouble(byteOffset); 34.541 + } catch (final IndexOutOfBoundsException ioe) { 34.542 + throw rangeError(ioe, "dataview.offset"); 34.543 + } 34.544 + } 34.545 + 34.546 + /** 34.547 + * Get 64-bit float value from given byteOffset 34.548 + * 34.549 + * @param self DataView object 34.550 + * @param byteOffset byte offset to read from 34.551 + * @param littleEndian (optional) flag indicating whether to read in little endian order 34.552 + * @return 64-bit float value at the byteOffset 34.553 + */ 34.554 + @SpecializedFunction 34.555 + public static double getFloat64(final Object self, final int byteOffset, final boolean littleEndian) { 34.556 + try { 34.557 + return getBuffer(self, littleEndian).getDouble(byteOffset); 34.558 + } catch (final IndexOutOfBoundsException ioe) { 34.559 + throw rangeError(ioe, "dataview.offset"); 34.560 + } 34.561 + } 34.562 + 34.563 + // Stores a value of the given type at the specified byte offset 34.564 + // from the start of the view. There is no alignment constraint; 34.565 + // multi-byte values may be stored at any offset. 34.566 + // 34.567 + // For multi-byte values, the optional littleEndian argument 34.568 + // indicates whether the value should be stored in big-endian or 34.569 + // little-endian byte order. If false or undefined, the value is 34.570 + // stored in big-endian byte order. 34.571 + // 34.572 + // These methods raise an exception if they would write 34.573 + // beyond the end of the view. 34.574 + 34.575 + /** 34.576 + * Set 8-bit signed int at the given byteOffset 34.577 + * 34.578 + * @param self DataView object 34.579 + * @param byteOffset byte offset to read from 34.580 + * @param value byte value to set 34.581 + * @return undefined 34.582 + */ 34.583 + @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2) 34.584 + public static Object setInt8(final Object self, final Object byteOffset, final Object value) { 34.585 + try { 34.586 + getBuffer(self).put(JSType.toInt32(byteOffset), (byte)JSType.toInt32(value)); 34.587 + return UNDEFINED; 34.588 + } catch (final IndexOutOfBoundsException ioe) { 34.589 + throw rangeError(ioe, "dataview.offset"); 34.590 + } 34.591 + } 34.592 + 34.593 + /** 34.594 + * Set 8-bit signed int at the given byteOffset 34.595 + * 34.596 + * @param self DataView object 34.597 + * @param byteOffset byte offset to read from 34.598 + * @param value byte value to set 34.599 + * @return undefined 34.600 + */ 34.601 + @SpecializedFunction 34.602 + public static Object setInt8(final Object self, final int byteOffset, final int value) { 34.603 + try { 34.604 + getBuffer(self).put(byteOffset, (byte)value); 34.605 + return UNDEFINED; 34.606 + } catch (final IndexOutOfBoundsException ioe) { 34.607 + throw rangeError(ioe, "dataview.offset"); 34.608 + } 34.609 + } 34.610 + 34.611 + /** 34.612 + * Set 8-bit unsigned int at the given byteOffset 34.613 + * 34.614 + * @param self DataView object 34.615 + * @param byteOffset byte offset to write at 34.616 + * @param value byte value to set 34.617 + * @return undefined 34.618 + */ 34.619 + @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2) 34.620 + public static Object setUint8(final Object self, final Object byteOffset, final Object value) { 34.621 + try { 34.622 + getBuffer(self).put(JSType.toInt32(byteOffset), (byte)JSType.toInt32(value)); 34.623 + return UNDEFINED; 34.624 + } catch (final IndexOutOfBoundsException ioe) { 34.625 + throw rangeError(ioe, "dataview.offset"); 34.626 + } 34.627 + } 34.628 + 34.629 + /** 34.630 + * Set 8-bit unsigned int at the given byteOffset 34.631 + * 34.632 + * @param self DataView object 34.633 + * @param byteOffset byte offset to write at 34.634 + * @param value byte value to set 34.635 + * @return undefined 34.636 + */ 34.637 + @SpecializedFunction 34.638 + public static Object setUint8(final Object self, final int byteOffset, final int value) { 34.639 + try { 34.640 + getBuffer(self).put(byteOffset, (byte)value); 34.641 + return UNDEFINED; 34.642 + } catch (final IndexOutOfBoundsException ioe) { 34.643 + throw rangeError(ioe, "dataview.offset"); 34.644 + } 34.645 + } 34.646 + 34.647 + /** 34.648 + * Set 16-bit signed int at the given byteOffset 34.649 + * 34.650 + * @param self DataView object 34.651 + * @param byteOffset byte offset to write at 34.652 + * @param value short value to set 34.653 + * @param littleEndian (optional) flag indicating whether to write in little endian order 34.654 + * @return undefined 34.655 + */ 34.656 + @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2) 34.657 + public static Object setInt16(final Object self, final Object byteOffset, final Object value, final Object littleEndian) { 34.658 + try { 34.659 + getBuffer(self, littleEndian).putShort(JSType.toInt32(byteOffset), (short)JSType.toInt32(value)); 34.660 + return UNDEFINED; 34.661 + } catch (final IndexOutOfBoundsException ioe) { 34.662 + throw rangeError(ioe, "dataview.offset"); 34.663 + } 34.664 + } 34.665 + 34.666 + /** 34.667 + * Set 16-bit signed int at the given byteOffset 34.668 + * 34.669 + * @param self DataView object 34.670 + * @param byteOffset byte offset to write at 34.671 + * @param value short value to set 34.672 + * @return undefined 34.673 + */ 34.674 + @SpecializedFunction 34.675 + public static Object setInt16(final Object self, final int byteOffset, final int value) { 34.676 + try { 34.677 + getBuffer(self, false).putShort(byteOffset, (short)value); 34.678 + return UNDEFINED; 34.679 + } catch (final IndexOutOfBoundsException ioe) { 34.680 + throw rangeError(ioe, "dataview.offset"); 34.681 + } 34.682 + } 34.683 + 34.684 + /** 34.685 + * Set 16-bit signed int at the given byteOffset 34.686 + * 34.687 + * @param self DataView object 34.688 + * @param byteOffset byte offset to write at 34.689 + * @param value short value to set 34.690 + * @param littleEndian (optional) flag indicating whether to write in little endian order 34.691 + * @return undefined 34.692 + */ 34.693 + @SpecializedFunction 34.694 + public static Object setInt16(final Object self, final int byteOffset, final int value, final boolean littleEndian) { 34.695 + try { 34.696 + getBuffer(self, littleEndian).putShort(byteOffset, (short)value); 34.697 + return UNDEFINED; 34.698 + } catch (final IndexOutOfBoundsException ioe) { 34.699 + throw rangeError(ioe, "dataview.offset"); 34.700 + } 34.701 + } 34.702 + 34.703 + /** 34.704 + * Set 16-bit unsigned int at the given byteOffset 34.705 + * 34.706 + * @param self DataView object 34.707 + * @param byteOffset byte offset to write at 34.708 + * @param value short value to set 34.709 + * @param littleEndian (optional) flag indicating whether to write in little endian order 34.710 + * @return undefined 34.711 + */ 34.712 + @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2) 34.713 + public static Object setUint16(final Object self, final Object byteOffset, final Object value, final Object littleEndian) { 34.714 + try { 34.715 + getBuffer(self, littleEndian).putShort(JSType.toInt32(byteOffset), (short)JSType.toInt32(value)); 34.716 + return UNDEFINED; 34.717 + } catch (final IndexOutOfBoundsException ioe) { 34.718 + throw rangeError(ioe, "dataview.offset"); 34.719 + } 34.720 + } 34.721 + 34.722 + /** 34.723 + * Set 16-bit unsigned int at the given byteOffset 34.724 + * 34.725 + * @param self DataView object 34.726 + * @param byteOffset byte offset to write at 34.727 + * @param value short value to set 34.728 + * @return undefined 34.729 + */ 34.730 + @SpecializedFunction 34.731 + public static Object setUint16(final Object self, final int byteOffset, final int value) { 34.732 + try { 34.733 + getBuffer(self, false).putShort(byteOffset, (short)value); 34.734 + return UNDEFINED; 34.735 + } catch (final IndexOutOfBoundsException ioe) { 34.736 + throw rangeError(ioe, "dataview.offset"); 34.737 + } 34.738 + } 34.739 + 34.740 + /** 34.741 + * Set 16-bit unsigned int at the given byteOffset 34.742 + * 34.743 + * @param self DataView object 34.744 + * @param byteOffset byte offset to write at 34.745 + * @param value short value to set 34.746 + * @param littleEndian (optional) flag indicating whether to write in little endian order 34.747 + * @return undefined 34.748 + */ 34.749 + @SpecializedFunction 34.750 + public static Object setUint16(final Object self, final int byteOffset, final int value, final boolean littleEndian) { 34.751 + try { 34.752 + getBuffer(self, littleEndian).putShort(byteOffset, (short)value); 34.753 + return UNDEFINED; 34.754 + } catch (final IndexOutOfBoundsException ioe) { 34.755 + throw rangeError(ioe, "dataview.offset"); 34.756 + } 34.757 + } 34.758 + 34.759 + /** 34.760 + * Set 32-bit signed int at the given byteOffset 34.761 + * 34.762 + * @param self DataView object 34.763 + * @param byteOffset byte offset to write at 34.764 + * @param value int value to set 34.765 + * @param littleEndian (optional) flag indicating whether to write in little endian order 34.766 + * @return undefined 34.767 + */ 34.768 + @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2) 34.769 + public static Object setInt32(final Object self, final Object byteOffset, final Object value, final Object littleEndian) { 34.770 + try { 34.771 + getBuffer(self, littleEndian).putInt(JSType.toInt32(byteOffset), (int)JSType.toInt32(value)); 34.772 + return UNDEFINED; 34.773 + } catch (final IndexOutOfBoundsException ioe) { 34.774 + throw rangeError(ioe, "dataview.offset"); 34.775 + } 34.776 + } 34.777 + 34.778 + /** 34.779 + * Set 32-bit signed int at the given byteOffset 34.780 + * 34.781 + * @param self DataView object 34.782 + * @param byteOffset byte offset to write at 34.783 + * @param value int value to set 34.784 + * @return undefined 34.785 + */ 34.786 + @SpecializedFunction 34.787 + public static Object setInt32(final Object self, final int byteOffset, final int value) { 34.788 + try { 34.789 + getBuffer(self, false).putInt(byteOffset, value); 34.790 + return UNDEFINED; 34.791 + } catch (final IndexOutOfBoundsException ioe) { 34.792 + throw rangeError(ioe, "dataview.offset"); 34.793 + } 34.794 + } 34.795 + 34.796 + /** 34.797 + * Set 32-bit signed int at the given byteOffset 34.798 + * 34.799 + * @param self DataView object 34.800 + * @param byteOffset byte offset to write at 34.801 + * @param value int value to set 34.802 + * @param littleEndian (optional) flag indicating whether to write in little endian order 34.803 + * @return undefined 34.804 + */ 34.805 + @SpecializedFunction 34.806 + public static Object setInt32(final Object self, final int byteOffset, final int value, final boolean littleEndian) { 34.807 + try { 34.808 + getBuffer(self, littleEndian).putInt(byteOffset, value); 34.809 + return UNDEFINED; 34.810 + } catch (final IndexOutOfBoundsException ioe) { 34.811 + throw rangeError(ioe, "dataview.offset"); 34.812 + } 34.813 + } 34.814 + 34.815 + /** 34.816 + * Set 32-bit unsigned int at the given byteOffset 34.817 + * 34.818 + * @param self DataView object 34.819 + * @param byteOffset byte offset to write at 34.820 + * @param value int value to set 34.821 + * @param littleEndian (optional) flag indicating whether to write in little endian order 34.822 + * @return undefined 34.823 + */ 34.824 + @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2) 34.825 + public static Object setUint32(final Object self, final Object byteOffset, final Object value, final Object littleEndian) { 34.826 + try { 34.827 + getBuffer(self, littleEndian).putInt(JSType.toInt32(byteOffset), (int)JSType.toUint32(value)); 34.828 + return UNDEFINED; 34.829 + } catch (final IndexOutOfBoundsException ioe) { 34.830 + throw rangeError(ioe, "dataview.offset"); 34.831 + } 34.832 + } 34.833 + 34.834 + /** 34.835 + * Set 32-bit unsigned int at the given byteOffset 34.836 + * 34.837 + * @param self DataView object 34.838 + * @param byteOffset byte offset to write at 34.839 + * @param value int value to set 34.840 + * @return undefined 34.841 + */ 34.842 + @SpecializedFunction 34.843 + public static Object setUint32(final Object self, final int byteOffset, final long value) { 34.844 + try { 34.845 + getBuffer(self, false).putInt(byteOffset, (int)value); 34.846 + return UNDEFINED; 34.847 + } catch (final IndexOutOfBoundsException ioe) { 34.848 + throw rangeError(ioe, "dataview.offset"); 34.849 + } 34.850 + } 34.851 + 34.852 + /** 34.853 + * Set 32-bit unsigned int at the given byteOffset 34.854 + * 34.855 + * @param self DataView object 34.856 + * @param byteOffset byte offset to write at 34.857 + * @param value int value to set 34.858 + * @param littleEndian (optional) flag indicating whether to write in little endian order 34.859 + * @return undefined 34.860 + */ 34.861 + @SpecializedFunction 34.862 + public static Object setUint32(final Object self, final int byteOffset, final long value, final boolean littleEndian) { 34.863 + try { 34.864 + getBuffer(self, littleEndian).putInt(byteOffset, (int)value); 34.865 + return UNDEFINED; 34.866 + } catch (final IndexOutOfBoundsException ioe) { 34.867 + throw rangeError(ioe, "dataview.offset"); 34.868 + } 34.869 + } 34.870 + 34.871 + /** 34.872 + * Set 32-bit float at the given byteOffset 34.873 + * 34.874 + * @param self DataView object 34.875 + * @param byteOffset byte offset to write at 34.876 + * @param value float value to set 34.877 + * @param littleEndian (optional) flag indicating whether to write in little endian order 34.878 + * @return undefined 34.879 + */ 34.880 + @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2) 34.881 + public static Object setFloat32(final Object self, final Object byteOffset, final Object value, final Object littleEndian) { 34.882 + try { 34.883 + getBuffer(self, littleEndian).putFloat((int)JSType.toUint32(byteOffset), (float)JSType.toNumber(value)); 34.884 + return UNDEFINED; 34.885 + } catch (final IndexOutOfBoundsException ioe) { 34.886 + throw rangeError(ioe, "dataview.offset"); 34.887 + } 34.888 + } 34.889 + 34.890 + /** 34.891 + * Set 32-bit float at the given byteOffset 34.892 + * 34.893 + * @param self DataView object 34.894 + * @param byteOffset byte offset to write at 34.895 + * @param value float value to set 34.896 + * @return undefined 34.897 + */ 34.898 + @SpecializedFunction 34.899 + public static Object setFloat32(final Object self, final int byteOffset, final double value) { 34.900 + try { 34.901 + getBuffer(self, false).putFloat(byteOffset, (float)value); 34.902 + return UNDEFINED; 34.903 + } catch (final IndexOutOfBoundsException ioe) { 34.904 + throw rangeError(ioe, "dataview.offset"); 34.905 + } 34.906 + } 34.907 + 34.908 + /** 34.909 + * Set 32-bit float at the given byteOffset 34.910 + * 34.911 + * @param self DataView object 34.912 + * @param byteOffset byte offset to write at 34.913 + * @param value float value to set 34.914 + * @param littleEndian (optional) flag indicating whether to write in little endian order 34.915 + * @return undefined 34.916 + */ 34.917 + @SpecializedFunction 34.918 + public static Object setFloat32(final Object self, final int byteOffset, final double value, final boolean littleEndian) { 34.919 + try { 34.920 + getBuffer(self, littleEndian).putFloat(byteOffset, (float)value); 34.921 + return UNDEFINED; 34.922 + } catch (final IndexOutOfBoundsException ioe) { 34.923 + throw rangeError(ioe, "dataview.offset"); 34.924 + } 34.925 + } 34.926 + 34.927 + /** 34.928 + * Set 64-bit float at the given byteOffset 34.929 + * 34.930 + * @param self DataView object 34.931 + * @param byteOffset byte offset to write at 34.932 + * @param value double value to set 34.933 + * @param littleEndian (optional) flag indicating whether to write in little endian order 34.934 + * @return undefined 34.935 + */ 34.936 + @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2) 34.937 + public static Object setFloat64(final Object self, final Object byteOffset, final Object value, final Object littleEndian) { 34.938 + try { 34.939 + getBuffer(self, littleEndian).putDouble((int)JSType.toUint32(byteOffset), JSType.toNumber(value)); 34.940 + return UNDEFINED; 34.941 + } catch (final IndexOutOfBoundsException ioe) { 34.942 + throw rangeError(ioe, "dataview.offset"); 34.943 + } 34.944 + } 34.945 + 34.946 + /** 34.947 + * Set 64-bit float at the given byteOffset 34.948 + * 34.949 + * @param self DataView object 34.950 + * @param byteOffset byte offset to write at 34.951 + * @param value double value to set 34.952 + * @return undefined 34.953 + */ 34.954 + @SpecializedFunction 34.955 + public static Object setFloat64(final Object self, final int byteOffset, final double value) { 34.956 + try { 34.957 + getBuffer(self, false).putDouble(byteOffset, value); 34.958 + return UNDEFINED; 34.959 + } catch (final IndexOutOfBoundsException ioe) { 34.960 + throw rangeError(ioe, "dataview.offset"); 34.961 + } 34.962 + } 34.963 + 34.964 + /** 34.965 + * Set 64-bit float at the given byteOffset 34.966 + * 34.967 + * @param self DataView object 34.968 + * @param byteOffset byte offset to write at 34.969 + * @param value double value to set 34.970 + * @param littleEndian (optional) flag indicating whether to write in little endian order 34.971 + * @return undefined 34.972 + */ 34.973 + @SpecializedFunction 34.974 + public static Object setFloat64(final Object self, final int byteOffset, final double value, final boolean littleEndian) { 34.975 + try { 34.976 + getBuffer(self, littleEndian).putDouble(byteOffset, value); 34.977 + return UNDEFINED; 34.978 + } catch (final IndexOutOfBoundsException ioe) { 34.979 + throw rangeError(ioe, "dataview.offset"); 34.980 + } 34.981 + } 34.982 + 34.983 + // internals only below this point 34.984 + private static ByteBuffer bufferFrom(final NativeArrayBuffer nab, final int offset) { 34.985 + try { 34.986 + return nab.getBuffer(offset); 34.987 + } catch (final IndexOutOfBoundsException ioe) { 34.988 + throw rangeError(ioe, "dataview.constructor.offset"); 34.989 + } 34.990 + } 34.991 + 34.992 + private static ByteBuffer bufferFrom(final NativeArrayBuffer nab, final int offset, final int length) { 34.993 + try { 34.994 + return nab.getBuffer(offset, length); 34.995 + } catch (final IndexOutOfBoundsException ioe) { 34.996 + throw rangeError(ioe, "dataview.constructor.offset"); 34.997 + } 34.998 + } 34.999 + 34.1000 + private static NativeDataView checkSelf(final Object self) { 34.1001 + if (!(self instanceof NativeDataView)) { 34.1002 + throw typeError("not.an.arraybuffer", ScriptRuntime.safeToString(self)); 34.1003 + } 34.1004 + return (NativeDataView)self; 34.1005 + } 34.1006 + 34.1007 + private static ByteBuffer getBuffer(final Object self) { 34.1008 + return checkSelf(self).buf; 34.1009 + } 34.1010 + 34.1011 + private static ByteBuffer getBuffer(final Object self, final Object littleEndian) { 34.1012 + return getBuffer(self, JSType.toBoolean(littleEndian)); 34.1013 + } 34.1014 + 34.1015 + private static ByteBuffer getBuffer(final Object self, final boolean littleEndian) { 34.1016 + return getBuffer(self).order(littleEndian? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN); 34.1017 + } 34.1018 +}
35.1 --- a/src/jdk/nashorn/internal/objects/NativeDate.java Wed Mar 26 12:01:34 2014 -0700 35.2 +++ b/src/jdk/nashorn/internal/objects/NativeDate.java Tue Apr 01 11:44:05 2014 -0700 35.3 @@ -114,10 +114,6 @@ 35.4 // initialized by nasgen 35.5 private static PropertyMap $nasgenmap$; 35.6 35.7 - static PropertyMap getInitialMap() { 35.8 - return $nasgenmap$; 35.9 - } 35.10 - 35.11 private NativeDate(final double time, final ScriptObject proto, final PropertyMap map) { 35.12 super(proto, map); 35.13 final ScriptEnvironment env = Global.getEnv(); 35.14 @@ -127,7 +123,7 @@ 35.15 } 35.16 35.17 NativeDate(final double time, final Global global) { 35.18 - this(time, global.getDatePrototype(), global.getDateMap()); 35.19 + this(time, global.getDatePrototype(), $nasgenmap$); 35.20 } 35.21 35.22 private NativeDate (final double time) { 35.23 @@ -230,7 +226,7 @@ 35.24 * @return Date interpreted from the string, or NaN for illegal values 35.25 */ 35.26 @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 35.27 - public static Object parse(final Object self, final Object string) { 35.28 + public static double parse(final Object self, final Object string) { 35.29 return parseDateString(JSType.toString(string)); 35.30 } 35.31 35.32 @@ -242,7 +238,7 @@ 35.33 * @return a time clip according to the ECMA specification 35.34 */ 35.35 @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 7, where = Where.CONSTRUCTOR) 35.36 - public static Object UTC(final Object self, final Object... args) { 35.37 + public static double UTC(final Object self, final Object... args) { 35.38 final NativeDate nd = new NativeDate(0); 35.39 final double[] d = convertCtorArgs(args); 35.40 final double time = d == null ? Double.NaN : timeClip(makeDate(d)); 35.41 @@ -257,8 +253,8 @@ 35.42 * @return a Date that points to the current moment in time 35.43 */ 35.44 @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 35.45 - public static Object now(final Object self) { 35.46 - return (double)System.currentTimeMillis(); 35.47 + public static long now(final Object self) { 35.48 + return System.currentTimeMillis(); 35.49 } 35.50 35.51 /** 35.52 @@ -268,7 +264,7 @@ 35.53 * @return string value that represents the Date in the current time zone 35.54 */ 35.55 @Function(attributes = Attribute.NOT_ENUMERABLE) 35.56 - public static Object toString(final Object self) { 35.57 + public static String toString(final Object self) { 35.58 return toStringImpl(self, FORMAT_DATE_TIME); 35.59 } 35.60 35.61 @@ -279,7 +275,7 @@ 35.62 * @return string value with the "date" part of the Date in the current time zone 35.63 */ 35.64 @Function(attributes = Attribute.NOT_ENUMERABLE) 35.65 - public static Object toDateString(final Object self) { 35.66 + public static String toDateString(final Object self) { 35.67 return toStringImpl(self, FORMAT_DATE); 35.68 } 35.69 35.70 @@ -290,7 +286,7 @@ 35.71 * @return string value with "time" part of Date in the current time zone 35.72 */ 35.73 @Function(attributes = Attribute.NOT_ENUMERABLE) 35.74 - public static Object toTimeString(final Object self) { 35.75 + public static String toTimeString(final Object self) { 35.76 return toStringImpl(self, FORMAT_TIME); 35.77 } 35.78 35.79 @@ -301,7 +297,7 @@ 35.80 * @return string value that represents the Data in the current time zone and locale 35.81 */ 35.82 @Function(attributes = Attribute.NOT_ENUMERABLE) 35.83 - public static Object toLocaleString(final Object self) { 35.84 + public static String toLocaleString(final Object self) { 35.85 return toStringImpl(self, FORMAT_LOCAL_DATE_TIME); 35.86 } 35.87 35.88 @@ -312,7 +308,7 @@ 35.89 * @return string value with the "date" part of the Date in the current time zone and locale 35.90 */ 35.91 @Function(attributes = Attribute.NOT_ENUMERABLE) 35.92 - public static Object toLocaleDateString(final Object self) { 35.93 + public static String toLocaleDateString(final Object self) { 35.94 return toStringImpl(self, FORMAT_LOCAL_DATE); 35.95 } 35.96 35.97 @@ -323,7 +319,7 @@ 35.98 * @return string value with the "time" part of Date in the current time zone and locale 35.99 */ 35.100 @Function(attributes = Attribute.NOT_ENUMERABLE) 35.101 - public static Object toLocaleTimeString(final Object self) { 35.102 + public static String toLocaleTimeString(final Object self) { 35.103 return toStringImpl(self, FORMAT_LOCAL_TIME); 35.104 } 35.105 35.106 @@ -334,7 +330,7 @@ 35.107 * @return valueOf - a number which is this time value 35.108 */ 35.109 @Function(attributes = Attribute.NOT_ENUMERABLE) 35.110 - public static Object valueOf(final Object self) { 35.111 + public static double valueOf(final Object self) { 35.112 final NativeDate nd = getNativeDate(self); 35.113 return (nd != null) ? nd.getTime() : Double.NaN; 35.114 } 35.115 @@ -346,7 +342,7 @@ 35.116 * @return time 35.117 */ 35.118 @Function(attributes = Attribute.NOT_ENUMERABLE) 35.119 - public static Object getTime(final Object self) { 35.120 + public static double getTime(final Object self) { 35.121 final NativeDate nd = getNativeDate(self); 35.122 return (nd != null) ? nd.getTime() : Double.NaN; 35.123 } 35.124 @@ -369,7 +365,7 @@ 35.125 * @return UTC full year 35.126 */ 35.127 @Function(attributes = Attribute.NOT_ENUMERABLE) 35.128 - public static Object getUTCFullYear(final Object self) { 35.129 + public static double getUTCFullYear(final Object self) { 35.130 return getUTCField(self, YEAR); 35.131 } 35.132 35.133 @@ -380,7 +376,7 @@ 35.134 * @return year 35.135 */ 35.136 @Function(attributes = Attribute.NOT_ENUMERABLE) 35.137 - public static Object getYear(final Object self) { 35.138 + public static double getYear(final Object self) { 35.139 final NativeDate nd = getNativeDate(self); 35.140 return (nd != null && nd.isValidDate()) ? (yearFromTime(nd.getLocalTime()) - 1900) : Double.NaN; 35.141 } 35.142 @@ -392,7 +388,7 @@ 35.143 * @return month 35.144 */ 35.145 @Function(attributes = Attribute.NOT_ENUMERABLE) 35.146 - public static Object getMonth(final Object self) { 35.147 + public static double getMonth(final Object self) { 35.148 return getField(self, MONTH); 35.149 } 35.150 35.151 @@ -403,7 +399,7 @@ 35.152 * @return UTC month 35.153 */ 35.154 @Function(attributes = Attribute.NOT_ENUMERABLE) 35.155 - public static Object getUTCMonth(final Object self) { 35.156 + public static double getUTCMonth(final Object self) { 35.157 return getUTCField(self, MONTH); 35.158 } 35.159 35.160 @@ -414,7 +410,7 @@ 35.161 * @return date 35.162 */ 35.163 @Function(attributes = Attribute.NOT_ENUMERABLE) 35.164 - public static Object getDate(final Object self) { 35.165 + public static double getDate(final Object self) { 35.166 return getField(self, DAY); 35.167 } 35.168 35.169 @@ -425,7 +421,7 @@ 35.170 * @return UTC Date 35.171 */ 35.172 @Function(attributes = Attribute.NOT_ENUMERABLE) 35.173 - public static Object getUTCDate(final Object self) { 35.174 + public static double getUTCDate(final Object self) { 35.175 return getUTCField(self, DAY); 35.176 } 35.177 35.178 @@ -436,7 +432,7 @@ 35.179 * @return day 35.180 */ 35.181 @Function(attributes = Attribute.NOT_ENUMERABLE) 35.182 - public static Object getDay(final Object self) { 35.183 + public static double getDay(final Object self) { 35.184 final NativeDate nd = getNativeDate(self); 35.185 return (nd != null && nd.isValidDate()) ? weekDay(nd.getLocalTime()) : Double.NaN; 35.186 } 35.187 @@ -448,7 +444,7 @@ 35.188 * @return UTC day 35.189 */ 35.190 @Function(attributes = Attribute.NOT_ENUMERABLE) 35.191 - public static Object getUTCDay(final Object self) { 35.192 + public static double getUTCDay(final Object self) { 35.193 final NativeDate nd = getNativeDate(self); 35.194 return (nd != null && nd.isValidDate()) ? weekDay(nd.getTime()) : Double.NaN; 35.195 } 35.196 @@ -460,7 +456,7 @@ 35.197 * @return hours 35.198 */ 35.199 @Function(attributes = Attribute.NOT_ENUMERABLE) 35.200 - public static Object getHours(final Object self) { 35.201 + public static double getHours(final Object self) { 35.202 return getField(self, HOUR); 35.203 } 35.204 35.205 @@ -471,7 +467,7 @@ 35.206 * @return UTC hours 35.207 */ 35.208 @Function(attributes = Attribute.NOT_ENUMERABLE) 35.209 - public static Object getUTCHours(final Object self) { 35.210 + public static double getUTCHours(final Object self) { 35.211 return getUTCField(self, HOUR); 35.212 } 35.213 35.214 @@ -482,7 +478,7 @@ 35.215 * @return minutes 35.216 */ 35.217 @Function(attributes = Attribute.NOT_ENUMERABLE) 35.218 - public static Object getMinutes(final Object self) { 35.219 + public static double getMinutes(final Object self) { 35.220 return getField(self, MINUTE); 35.221 } 35.222 35.223 @@ -493,7 +489,7 @@ 35.224 * @return UTC minutes 35.225 */ 35.226 @Function(attributes = Attribute.NOT_ENUMERABLE) 35.227 - public static Object getUTCMinutes(final Object self) { 35.228 + public static double getUTCMinutes(final Object self) { 35.229 return getUTCField(self, MINUTE); 35.230 } 35.231 35.232 @@ -504,7 +500,7 @@ 35.233 * @return seconds 35.234 */ 35.235 @Function(attributes = Attribute.NOT_ENUMERABLE) 35.236 - public static Object getSeconds(final Object self) { 35.237 + public static double getSeconds(final Object self) { 35.238 return getField(self, SECOND); 35.239 } 35.240 35.241 @@ -515,7 +511,7 @@ 35.242 * @return UTC seconds 35.243 */ 35.244 @Function(attributes = Attribute.NOT_ENUMERABLE) 35.245 - public static Object getUTCSeconds(final Object self) { 35.246 + public static double getUTCSeconds(final Object self) { 35.247 return getUTCField(self, SECOND); 35.248 } 35.249 35.250 @@ -526,7 +522,7 @@ 35.251 * @return milliseconds 35.252 */ 35.253 @Function(attributes = Attribute.NOT_ENUMERABLE) 35.254 - public static Object getMilliseconds(final Object self) { 35.255 + public static double getMilliseconds(final Object self) { 35.256 return getField(self, MILLISECOND); 35.257 } 35.258 35.259 @@ -537,7 +533,7 @@ 35.260 * @return UTC milliseconds 35.261 */ 35.262 @Function(attributes = Attribute.NOT_ENUMERABLE) 35.263 - public static Object getUTCMilliseconds(final Object self) { 35.264 + public static double getUTCMilliseconds(final Object self) { 35.265 return getUTCField(self, MILLISECOND); 35.266 } 35.267 35.268 @@ -548,7 +544,7 @@ 35.269 * @return time zone offset or NaN if N/A 35.270 */ 35.271 @Function(attributes = Attribute.NOT_ENUMERABLE) 35.272 - public static Object getTimezoneOffset(final Object self) { 35.273 + public static double getTimezoneOffset(final Object self) { 35.274 final NativeDate nd = getNativeDate(self); 35.275 if (nd != null && nd.isValidDate()) { 35.276 final long msec = (long) nd.getTime(); 35.277 @@ -565,7 +561,7 @@ 35.278 * @return time 35.279 */ 35.280 @Function(attributes = Attribute.NOT_ENUMERABLE) 35.281 - public static Object setTime(final Object self, final Object time) { 35.282 + public static double setTime(final Object self, final Object time) { 35.283 final NativeDate nd = getNativeDate(self); 35.284 final double num = timeClip(JSType.toNumber(time)); 35.285 nd.setTime(num); 35.286 @@ -580,7 +576,7 @@ 35.287 * @return time 35.288 */ 35.289 @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) 35.290 - public static Object setMilliseconds(final Object self, final Object... args) { 35.291 + public static double setMilliseconds(final Object self, final Object... args) { 35.292 final NativeDate nd = getNativeDate(self); 35.293 setFields(nd, MILLISECOND, args, true); 35.294 return nd.getTime(); 35.295 @@ -594,7 +590,7 @@ 35.296 * @return time 35.297 */ 35.298 @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) 35.299 - public static Object setUTCMilliseconds(final Object self, final Object... args) { 35.300 + public static double setUTCMilliseconds(final Object self, final Object... args) { 35.301 final NativeDate nd = getNativeDate(self); 35.302 setFields(nd, MILLISECOND, args, false); 35.303 return nd.getTime(); 35.304 @@ -608,7 +604,7 @@ 35.305 * @return time 35.306 */ 35.307 @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2) 35.308 - public static Object setSeconds(final Object self, final Object... args) { 35.309 + public static double setSeconds(final Object self, final Object... args) { 35.310 final NativeDate nd = getNativeDate(self); 35.311 setFields(nd, SECOND, args, true); 35.312 return nd.getTime(); 35.313 @@ -622,7 +618,7 @@ 35.314 * @return time 35.315 */ 35.316 @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2) 35.317 - public static Object setUTCSeconds(final Object self, final Object... args) { 35.318 + public static double setUTCSeconds(final Object self, final Object... args) { 35.319 final NativeDate nd = getNativeDate(self); 35.320 setFields(nd, SECOND, args, false); 35.321 return nd.getTime(); 35.322 @@ -636,7 +632,7 @@ 35.323 * @return time 35.324 */ 35.325 @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 3) 35.326 - public static Object setMinutes(final Object self, final Object... args) { 35.327 + public static double setMinutes(final Object self, final Object... args) { 35.328 final NativeDate nd = getNativeDate(self); 35.329 setFields(nd, MINUTE, args, true); 35.330 return nd.getTime(); 35.331 @@ -650,7 +646,7 @@ 35.332 * @return time 35.333 */ 35.334 @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 3) 35.335 - public static Object setUTCMinutes(final Object self, final Object... args) { 35.336 + public static double setUTCMinutes(final Object self, final Object... args) { 35.337 final NativeDate nd = getNativeDate(self); 35.338 setFields(nd, MINUTE, args, false); 35.339 return nd.getTime(); 35.340 @@ -664,7 +660,7 @@ 35.341 * @return time 35.342 */ 35.343 @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 4) 35.344 - public static Object setHours(final Object self, final Object... args) { 35.345 + public static double setHours(final Object self, final Object... args) { 35.346 final NativeDate nd = getNativeDate(self); 35.347 setFields(nd, HOUR, args, true); 35.348 return nd.getTime(); 35.349 @@ -678,7 +674,7 @@ 35.350 * @return time 35.351 */ 35.352 @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 4) 35.353 - public static Object setUTCHours(final Object self, final Object... args) { 35.354 + public static double setUTCHours(final Object self, final Object... args) { 35.355 final NativeDate nd = getNativeDate(self); 35.356 setFields(nd, HOUR, args, false); 35.357 return nd.getTime(); 35.358 @@ -692,7 +688,7 @@ 35.359 * @return time 35.360 */ 35.361 @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) 35.362 - public static Object setDate(final Object self, final Object... args) { 35.363 + public static double setDate(final Object self, final Object... args) { 35.364 final NativeDate nd = getNativeDate(self); 35.365 setFields(nd, DAY, args, true); 35.366 return nd.getTime(); 35.367 @@ -706,7 +702,7 @@ 35.368 * @return time 35.369 */ 35.370 @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) 35.371 - public static Object setUTCDate(final Object self, final Object... args) { 35.372 + public static double setUTCDate(final Object self, final Object... args) { 35.373 final NativeDate nd = getNativeDate(self); 35.374 setFields(nd, DAY, args, false); 35.375 return nd.getTime(); 35.376 @@ -720,7 +716,7 @@ 35.377 * @return time 35.378 */ 35.379 @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2) 35.380 - public static Object setMonth(final Object self, final Object... args) { 35.381 + public static double setMonth(final Object self, final Object... args) { 35.382 final NativeDate nd = getNativeDate(self); 35.383 setFields(nd, MONTH, args, true); 35.384 return nd.getTime(); 35.385 @@ -734,7 +730,7 @@ 35.386 * @return time 35.387 */ 35.388 @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2) 35.389 - public static Object setUTCMonth(final Object self, final Object... args) { 35.390 + public static double setUTCMonth(final Object self, final Object... args) { 35.391 final NativeDate nd = ensureNativeDate(self); 35.392 setFields(nd, MONTH, args, false); 35.393 return nd.getTime(); 35.394 @@ -748,7 +744,7 @@ 35.395 * @return time 35.396 */ 35.397 @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 3) 35.398 - public static Object setFullYear(final Object self, final Object... args) { 35.399 + public static double setFullYear(final Object self, final Object... args) { 35.400 final NativeDate nd = ensureNativeDate(self); 35.401 if (nd.isValidDate()) { 35.402 setFields(nd, YEAR, args, true); 35.403 @@ -771,7 +767,7 @@ 35.404 * @return time 35.405 */ 35.406 @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 3) 35.407 - public static Object setUTCFullYear(final Object self, final Object... args) { 35.408 + public static double setUTCFullYear(final Object self, final Object... args) { 35.409 final NativeDate nd = ensureNativeDate(self); 35.410 if (nd.isValidDate()) { 35.411 setFields(nd, YEAR, args, false); 35.412 @@ -790,7 +786,7 @@ 35.413 * @return NativeDate 35.414 */ 35.415 @Function(attributes = Attribute.NOT_ENUMERABLE) 35.416 - public static Object setYear(final Object self, final Object year) { 35.417 + public static double setYear(final Object self, final Object year) { 35.418 final NativeDate nd = getNativeDate(self); 35.419 if (isNaN(nd.getTime())) { 35.420 nd.setTime(utc(0, nd.getTimeZone())); 35.421 @@ -817,7 +813,7 @@ 35.422 * @return string representation of date 35.423 */ 35.424 @Function(attributes = Attribute.NOT_ENUMERABLE) 35.425 - public static Object toUTCString(final Object self) { 35.426 + public static String toUTCString(final Object self) { 35.427 return toGMTStringImpl(self); 35.428 } 35.429 35.430 @@ -830,7 +826,7 @@ 35.431 * @return string representation of date 35.432 */ 35.433 @Function(attributes = Attribute.NOT_ENUMERABLE) 35.434 - public static Object toGMTString(final Object self) { 35.435 + public static String toGMTString(final Object self) { 35.436 return toGMTStringImpl(self); 35.437 } 35.438 35.439 @@ -841,7 +837,7 @@ 35.440 * @return string representation of date 35.441 */ 35.442 @Function(attributes = Attribute.NOT_ENUMERABLE) 35.443 - public static Object toISOString(final Object self) { 35.444 + public static String toISOString(final Object self) { 35.445 return toISOStringImpl(self); 35.446 } 35.447 35.448 @@ -1286,14 +1282,14 @@ 35.449 } 35.450 } 35.451 35.452 - private static Object getField(final Object self, final int field) { 35.453 + private static double getField(final Object self, final int field) { 35.454 final NativeDate nd = getNativeDate(self); 35.455 - return (nd != null && nd.isValidDate()) ? valueFromTime(field, nd.getLocalTime()) : Double.NaN; 35.456 + return (nd != null && nd.isValidDate()) ? (double)valueFromTime(field, nd.getLocalTime()) : Double.NaN; 35.457 } 35.458 35.459 - private static Object getUTCField(final Object self, final int field) { 35.460 + private static double getUTCField(final Object self, final int field) { 35.461 final NativeDate nd = getNativeDate(self); 35.462 - return (nd != null && nd.isValidDate()) ? valueFromTime(field, nd.getTime()) : Double.NaN; 35.463 + return (nd != null && nd.isValidDate()) ? (double)valueFromTime(field, nd.getTime()) : Double.NaN; 35.464 } 35.465 35.466 private static void setFields(final NativeDate nd, final int fieldId, final Object[] args, final boolean local) { 35.467 @@ -1348,5 +1344,4 @@ 35.468 private TimeZone getTimeZone() { 35.469 return timezone; 35.470 } 35.471 - 35.472 }
36.1 --- a/src/jdk/nashorn/internal/objects/NativeDebug.java Wed Mar 26 12:01:34 2014 -0700 36.2 +++ b/src/jdk/nashorn/internal/objects/NativeDebug.java Tue Apr 01 11:44:05 2014 -0700 36.3 @@ -34,7 +34,7 @@ 36.4 import jdk.nashorn.internal.objects.annotations.ScriptClass; 36.5 import jdk.nashorn.internal.objects.annotations.Where; 36.6 import jdk.nashorn.internal.runtime.Context; 36.7 -import jdk.nashorn.internal.runtime.PropertyListenerManager; 36.8 +import jdk.nashorn.internal.runtime.PropertyListeners; 36.9 import jdk.nashorn.internal.runtime.PropertyMap; 36.10 import jdk.nashorn.internal.runtime.ScriptFunction; 36.11 import jdk.nashorn.internal.runtime.ScriptObject; 36.12 @@ -116,7 +116,7 @@ 36.13 * @return true if reference identity 36.14 */ 36.15 @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 36.16 - public static Object identical(final Object self, final Object obj1, final Object obj2) { 36.17 + public static boolean identical(final Object self, final Object obj1, final Object obj2) { 36.18 return obj1 == obj2; 36.19 } 36.20 36.21 @@ -144,7 +144,7 @@ 36.22 * @return return {@link Object#equals(Object)} for objects. 36.23 */ 36.24 @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 36.25 - public static Object equals(final Object self, final Object obj1, final Object obj2) { 36.26 + public static boolean equals(final Object self, final Object obj1, final Object obj2) { 36.27 return Objects.equals(obj1, obj2); 36.28 } 36.29 36.30 @@ -156,7 +156,7 @@ 36.31 * @return Java string representation of {@code obj} 36.32 */ 36.33 @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 36.34 - public static Object toJavaString(final Object self, final Object obj) { 36.35 + public static String toJavaString(final Object self, final Object obj) { 36.36 return Objects.toString(obj); 36.37 } 36.38 36.39 @@ -168,7 +168,7 @@ 36.40 * @return string representation 36.41 */ 36.42 @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 36.43 - public static Object toIdentString(final Object self, final Object obj) { 36.44 + public static String toIdentString(final Object self, final Object obj) { 36.45 if (obj == null) { 36.46 return "null"; 36.47 } 36.48 @@ -185,8 +185,8 @@ 36.49 * @return listener count 36.50 */ 36.51 @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 36.52 - public static Object getListenerCount(final Object self, final Object obj) { 36.53 - return (obj instanceof ScriptObject)? ((ScriptObject)obj).getListenerCount() : 0; 36.54 + public static int getListenerCount(final Object self, final Object obj) { 36.55 + return (obj instanceof ScriptObject) ? PropertyListeners.getListenerCount((ScriptObject) obj) : 0; 36.56 } 36.57 36.58 /** 36.59 @@ -203,14 +203,13 @@ 36.60 36.61 out.println("ScriptObject count " + ScriptObject.getCount()); 36.62 out.println("Scope count " + ScriptObject.getScopeCount()); 36.63 - out.println("ScriptObject listeners added " + PropertyListenerManager.getListenersAdded()); 36.64 - out.println("ScriptObject listeners removed " + PropertyListenerManager.getListenersRemoved()); 36.65 + out.println("ScriptObject listeners added " + PropertyListeners.getListenersAdded()); 36.66 + out.println("ScriptObject listeners removed " + PropertyListeners.getListenersRemoved()); 36.67 out.println("ScriptFunction constructor calls " + ScriptFunction.getConstructorCount()); 36.68 out.println("ScriptFunction invokes " + ScriptFunction.getInvokes()); 36.69 out.println("ScriptFunction allocations " + ScriptFunction.getAllocations()); 36.70 out.println("PropertyMap count " + PropertyMap.getCount()); 36.71 out.println("PropertyMap cloned " + PropertyMap.getClonedCount()); 36.72 - out.println("PropertyMap shared " + PropertyMap.getSharedCount()); 36.73 out.println("PropertyMap duplicated " + PropertyMap.getDuplicatedCount()); 36.74 out.println("PropertyMap history hit " + PropertyMap.getHistoryHit()); 36.75 out.println("PropertyMap proto invalidations " + PropertyMap.getProtoInvalidations());
37.1 --- a/src/jdk/nashorn/internal/objects/NativeError.java Wed Mar 26 12:01:34 2014 -0700 37.2 +++ b/src/jdk/nashorn/internal/objects/NativeError.java Tue Apr 01 11:44:05 2014 -0700 37.3 @@ -38,7 +38,6 @@ 37.4 import jdk.nashorn.internal.objects.annotations.Property; 37.5 import jdk.nashorn.internal.objects.annotations.ScriptClass; 37.6 import jdk.nashorn.internal.objects.annotations.Where; 37.7 -import jdk.nashorn.internal.objects.ScriptFunctionImpl; 37.8 import jdk.nashorn.internal.runtime.ECMAException; 37.9 import jdk.nashorn.internal.runtime.JSType; 37.10 import jdk.nashorn.internal.runtime.PropertyMap; 37.11 @@ -75,7 +74,7 @@ 37.12 static final String FILENAME = "__fileName__"; 37.13 37.14 /** Message property name */ 37.15 - @Property(name = NativeError.MESSAGE) 37.16 + @Property(name = NativeError.MESSAGE, attributes = Attribute.NOT_ENUMERABLE) 37.17 public Object instMessage; 37.18 37.19 /** ECMA 15.11.4.2 Error.prototype.name */ 37.20 @@ -86,13 +85,14 @@ 37.21 @Property(attributes = Attribute.NOT_ENUMERABLE, where = Where.PROTOTYPE) 37.22 public Object message; 37.23 37.24 + /** Nashorn extension: underlying exception */ 37.25 + @Property(attributes = Attribute.NOT_ENUMERABLE) 37.26 + public Object nashornException; 37.27 + 37.28 // initialized by nasgen 37.29 private static PropertyMap $nasgenmap$; 37.30 37.31 - static PropertyMap getInitialMap() { 37.32 - return $nasgenmap$; 37.33 - } 37.34 - 37.35 + @SuppressWarnings("LeakingThisInConstructor") 37.36 private NativeError(final Object msg, final ScriptObject proto, final PropertyMap map) { 37.37 super(proto, map); 37.38 if (msg != UNDEFINED) { 37.39 @@ -100,10 +100,11 @@ 37.40 } else { 37.41 this.delete(NativeError.MESSAGE, false); 37.42 } 37.43 + initException(this); 37.44 } 37.45 37.46 NativeError(final Object msg, final Global global) { 37.47 - this(msg, global.getErrorPrototype(), global.getErrorMap()); 37.48 + this(msg, global.getErrorPrototype(), $nasgenmap$); 37.49 } 37.50 37.51 private NativeError(final Object msg) { 37.52 @@ -125,10 +126,18 @@ 37.53 * @return NativeError instance 37.54 */ 37.55 @Constructor 37.56 - public static Object constructor(final boolean newObj, final Object self, final Object msg) { 37.57 + public static NativeError constructor(final boolean newObj, final Object self, final Object msg) { 37.58 return new NativeError(msg); 37.59 } 37.60 37.61 + // This is called NativeError, NativeTypeError etc. to 37.62 + // associate a ECMAException with the ECMA Error object. 37.63 + @SuppressWarnings("unused") 37.64 + static void initException(final ScriptObject self) { 37.65 + // ECMAException constructor has side effects 37.66 + new ECMAException(self, null); 37.67 + } 37.68 + 37.69 /** 37.70 * Nashorn extension: Error.captureStackTrace. Capture stack trace at the point of call into the Error object provided. 37.71 * 37.72 @@ -136,16 +145,17 @@ 37.73 * @param errorObj the error object 37.74 * @return undefined 37.75 */ 37.76 - @SuppressWarnings("unused") 37.77 @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 37.78 public static Object captureStackTrace(final Object self, final Object errorObj) { 37.79 Global.checkObject(errorObj); 37.80 final ScriptObject sobj = (ScriptObject)errorObj; 37.81 - new ECMAException(sobj, null); //constructor has side effects 37.82 - sobj.delete("stack", false); 37.83 - final ScriptFunction getStack = ScriptFunctionImpl.makeFunction("getStack", GET_STACK); 37.84 - final ScriptFunction setStack = ScriptFunctionImpl.makeFunction("setStack", SET_STACK); 37.85 - sobj.addOwnProperty("stack", Attribute.NOT_ENUMERABLE, getStack, setStack); 37.86 + initException(sobj); 37.87 + sobj.delete(STACK, false); 37.88 + if (! sobj.has("stack")) { 37.89 + final ScriptFunction getStack = ScriptFunctionImpl.makeFunction("getStack", GET_STACK); 37.90 + final ScriptFunction setStack = ScriptFunctionImpl.makeFunction("setStack", SET_STACK); 37.91 + sobj.addOwnProperty("stack", Attribute.NOT_ENUMERABLE, getStack, setStack); 37.92 + } 37.93 return UNDEFINED; 37.94 } 37.95 37.96 @@ -226,7 +236,11 @@ 37.97 public static Object setLineNumber(final Object self, final Object value) { 37.98 Global.checkObject(self); 37.99 final ScriptObject sobj = (ScriptObject)self; 37.100 - sobj.set(LINENUMBER, value, false); 37.101 + if (sobj.hasOwnProperty(LINENUMBER)) { 37.102 + sobj.put(LINENUMBER, value, false); 37.103 + } else { 37.104 + sobj.addOwnProperty(LINENUMBER, Attribute.NOT_ENUMERABLE, value); 37.105 + } 37.106 return value; 37.107 } 37.108 37.109 @@ -254,7 +268,11 @@ 37.110 public static Object setColumnNumber(final Object self, final Object value) { 37.111 Global.checkObject(self); 37.112 final ScriptObject sobj = (ScriptObject)self; 37.113 - sobj.set(COLUMNNUMBER, value, false); 37.114 + if (sobj.hasOwnProperty(COLUMNNUMBER)) { 37.115 + sobj.put(COLUMNNUMBER, value, false); 37.116 + } else { 37.117 + sobj.addOwnProperty(COLUMNNUMBER, Attribute.NOT_ENUMERABLE, value); 37.118 + } 37.119 return value; 37.120 } 37.121 37.122 @@ -282,7 +300,11 @@ 37.123 public static Object setFileName(final Object self, final Object value) { 37.124 Global.checkObject(self); 37.125 final ScriptObject sobj = (ScriptObject)self; 37.126 - sobj.set(FILENAME, value, false); 37.127 + if (sobj.hasOwnProperty(FILENAME)) { 37.128 + sobj.put(FILENAME, value, false); 37.129 + } else { 37.130 + sobj.addOwnProperty(FILENAME, Attribute.NOT_ENUMERABLE, value); 37.131 + } 37.132 return value; 37.133 } 37.134 37.135 @@ -304,10 +326,12 @@ 37.136 37.137 final Object exception = ECMAException.getException(sobj); 37.138 if (exception instanceof Throwable) { 37.139 - return getScriptStackString(sobj, (Throwable)exception); 37.140 + Object value = getScriptStackString(sobj, (Throwable)exception); 37.141 + sobj.put(STACK, value, false); 37.142 + return value; 37.143 } 37.144 37.145 - return ""; 37.146 + return UNDEFINED; 37.147 } 37.148 37.149 /**
38.1 --- a/src/jdk/nashorn/internal/objects/NativeEvalError.java Wed Mar 26 12:01:34 2014 -0700 38.2 +++ b/src/jdk/nashorn/internal/objects/NativeEvalError.java Tue Apr 01 11:44:05 2014 -0700 38.3 @@ -44,7 +44,7 @@ 38.4 public final class NativeEvalError extends ScriptObject { 38.5 38.6 /** message property in instance */ 38.7 - @Property(name = NativeError.MESSAGE) 38.8 + @Property(name = NativeError.MESSAGE, attributes = Attribute.NOT_ENUMERABLE) 38.9 public Object instMessage; 38.10 38.11 /** error name property */ 38.12 @@ -55,13 +55,14 @@ 38.13 @Property(attributes = Attribute.NOT_ENUMERABLE, where = Where.PROTOTYPE) 38.14 public Object message; 38.15 38.16 + /** Nashorn extension: underlying exception */ 38.17 + @Property(attributes = Attribute.NOT_ENUMERABLE) 38.18 + public Object nashornException; 38.19 + 38.20 // initialized by nasgen 38.21 private static PropertyMap $nasgenmap$; 38.22 38.23 - static PropertyMap getInitialMap() { 38.24 - return $nasgenmap$; 38.25 - } 38.26 - 38.27 + @SuppressWarnings("LeakingThisInConstructor") 38.28 private NativeEvalError(final Object msg, final ScriptObject proto, final PropertyMap map) { 38.29 super(proto, map); 38.30 if (msg != UNDEFINED) { 38.31 @@ -69,10 +70,11 @@ 38.32 } else { 38.33 this.delete(NativeError.MESSAGE, false); 38.34 } 38.35 + NativeError.initException(this); 38.36 } 38.37 38.38 NativeEvalError(final Object msg, final Global global) { 38.39 - this(msg, global.getEvalErrorPrototype(), global.getEvalErrorMap()); 38.40 + this(msg, global.getEvalErrorPrototype(), $nasgenmap$); 38.41 } 38.42 38.43 private NativeEvalError(final Object msg) { 38.44 @@ -96,7 +98,7 @@ 38.45 * @return new EvalError 38.46 */ 38.47 @Constructor(name = "EvalError") 38.48 - public static Object constructor(final boolean newObj, final Object self, final Object msg) { 38.49 + public static NativeEvalError constructor(final boolean newObj, final Object self, final Object msg) { 38.50 return new NativeEvalError(msg); 38.51 } 38.52 }
39.1 --- a/src/jdk/nashorn/internal/objects/NativeFloat32Array.java Wed Mar 26 12:01:34 2014 -0700 39.2 +++ b/src/jdk/nashorn/internal/objects/NativeFloat32Array.java Tue Apr 01 11:44:05 2014 -0700 39.3 @@ -136,8 +136,8 @@ 39.4 * @return new typed array 39.5 */ 39.6 @Constructor(arity = 1) 39.7 - public static Object constructor(final boolean newObj, final Object self, final Object... args) { 39.8 - return constructorImpl(args, FACTORY); 39.9 + public static NativeFloat32Array constructor(final boolean newObj, final Object self, final Object... args) { 39.10 + return (NativeFloat32Array)constructorImpl(args, FACTORY); 39.11 } 39.12 39.13 NativeFloat32Array(final NativeArrayBuffer buffer, final int byteOffset, final int length) { 39.14 @@ -192,8 +192,8 @@ 39.15 * @return sub array 39.16 */ 39.17 @Function(attributes = Attribute.NOT_ENUMERABLE) 39.18 - protected static Object subarray(final Object self, final Object begin, final Object end) { 39.19 - return ArrayBufferView.subarrayImpl(self, begin, end); 39.20 + protected static NativeFloat32Array subarray(final Object self, final Object begin, final Object end) { 39.21 + return (NativeFloat32Array)ArrayBufferView.subarrayImpl(self, begin, end); 39.22 } 39.23 39.24 @Override
40.1 --- a/src/jdk/nashorn/internal/objects/NativeFloat64Array.java Wed Mar 26 12:01:34 2014 -0700 40.2 +++ b/src/jdk/nashorn/internal/objects/NativeFloat64Array.java Tue Apr 01 11:44:05 2014 -0700 40.3 @@ -146,8 +146,8 @@ 40.4 * @return new typed array 40.5 */ 40.6 @Constructor(arity = 1) 40.7 - public static Object constructor(final boolean newObj, final Object self, final Object... args) { 40.8 - return constructorImpl(args, FACTORY); 40.9 + public static NativeFloat64Array constructor(final boolean newObj, final Object self, final Object... args) { 40.10 + return (NativeFloat64Array)constructorImpl(args, FACTORY); 40.11 } 40.12 40.13 NativeFloat64Array(final NativeArrayBuffer buffer, final int byteOffset, final int length) { 40.14 @@ -202,8 +202,8 @@ 40.15 * @return sub array 40.16 */ 40.17 @Function(attributes = Attribute.NOT_ENUMERABLE) 40.18 - protected static Object subarray(final Object self, final Object begin, final Object end) { 40.19 - return ArrayBufferView.subarrayImpl(self, begin, end); 40.20 + protected static NativeFloat64Array subarray(final Object self, final Object begin, final Object end) { 40.21 + return (NativeFloat64Array)ArrayBufferView.subarrayImpl(self, begin, end); 40.22 } 40.23 40.24 @Override
41.1 --- a/src/jdk/nashorn/internal/objects/NativeFunction.java Wed Mar 26 12:01:34 2014 -0700 41.2 +++ b/src/jdk/nashorn/internal/objects/NativeFunction.java Tue Apr 01 11:44:05 2014 -0700 41.3 @@ -71,7 +71,7 @@ 41.4 * @return string representation of Function 41.5 */ 41.6 @Function(attributes = Attribute.NOT_ENUMERABLE) 41.7 - public static Object toString(final Object self) { 41.8 + public static String toString(final Object self) { 41.9 if (!(self instanceof ScriptFunction)) { 41.10 throw typeError("not.a.function", ScriptRuntime.safeToString(self)); 41.11 } 41.12 @@ -174,7 +174,7 @@ 41.13 * @return function with bound arguments 41.14 */ 41.15 @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) 41.16 - public static Object bind(final Object self, final Object... args) { 41.17 + public static ScriptFunction bind(final Object self, final Object... args) { 41.18 if (!(self instanceof ScriptFunction)) { 41.19 throw typeError("not.a.function", ScriptRuntime.safeToString(self)); 41.20 } 41.21 @@ -199,7 +199,7 @@ 41.22 * @return source for function 41.23 */ 41.24 @Function(attributes = Attribute.NOT_ENUMERABLE) 41.25 - public static Object toSource(final Object self) { 41.26 + public static String toSource(final Object self) { 41.27 if (!(self instanceof ScriptFunction)) { 41.28 throw typeError("not.a.function", ScriptRuntime.safeToString(self)); 41.29 } 41.30 @@ -217,7 +217,7 @@ 41.31 * @return new NativeFunction 41.32 */ 41.33 @Constructor(arity = 1) 41.34 - public static Object function(final boolean newObj, final Object self, final Object... args) { 41.35 + public static ScriptFunction function(final boolean newObj, final Object self, final Object... args) { 41.36 final StringBuilder sb = new StringBuilder(); 41.37 41.38 sb.append("(function ("); 41.39 @@ -253,7 +253,7 @@ 41.40 41.41 final Global global = Global.instance(); 41.42 41.43 - return Global.directEval(global, sb.toString(), global, "<function>", global.isStrictContext()); 41.44 + return (ScriptFunction)Global.directEval(global, sb.toString(), global, "<function>", global.isStrictContext()); 41.45 } 41.46 41.47 private static void checkFunctionParameters(final String params) {
42.1 --- a/src/jdk/nashorn/internal/objects/NativeInt16Array.java Wed Mar 26 12:01:34 2014 -0700 42.2 +++ b/src/jdk/nashorn/internal/objects/NativeInt16Array.java Tue Apr 01 11:44:05 2014 -0700 42.3 @@ -100,8 +100,8 @@ 42.4 * @return new typed array 42.5 */ 42.6 @Constructor(arity = 1) 42.7 - public static Object constructor(final boolean newObj, final Object self, final Object... args) { 42.8 - return constructorImpl(args, FACTORY); 42.9 + public static NativeInt16Array constructor(final boolean newObj, final Object self, final Object... args) { 42.10 + return (NativeInt16Array)constructorImpl(args, FACTORY); 42.11 } 42.12 42.13 NativeInt16Array(final NativeArrayBuffer buffer, final int byteOffset, final int byteLength) { 42.14 @@ -151,8 +151,8 @@ 42.15 * @return sub array 42.16 */ 42.17 @Function(attributes = Attribute.NOT_ENUMERABLE) 42.18 - protected static Object subarray(final Object self, final Object begin, final Object end) { 42.19 - return ArrayBufferView.subarrayImpl(self, begin, end); 42.20 + protected static NativeInt16Array subarray(final Object self, final Object begin, final Object end) { 42.21 + return (NativeInt16Array)ArrayBufferView.subarrayImpl(self, begin, end); 42.22 } 42.23 42.24 @Override
43.1 --- a/src/jdk/nashorn/internal/objects/NativeInt32Array.java Wed Mar 26 12:01:34 2014 -0700 43.2 +++ b/src/jdk/nashorn/internal/objects/NativeInt32Array.java Tue Apr 01 11:44:05 2014 -0700 43.3 @@ -103,8 +103,8 @@ 43.4 * @return new typed array 43.5 */ 43.6 @Constructor(arity = 1) 43.7 - public static Object constructor(final boolean newObj, final Object self, final Object... args) { 43.8 - return constructorImpl(args, FACTORY); 43.9 + public static NativeInt32Array constructor(final boolean newObj, final Object self, final Object... args) { 43.10 + return (NativeInt32Array)constructorImpl(args, FACTORY); 43.11 } 43.12 43.13 NativeInt32Array(final NativeArrayBuffer buffer, final int byteOffset, final int length) { 43.14 @@ -154,8 +154,8 @@ 43.15 * @return sub array 43.16 */ 43.17 @Function(attributes = Attribute.NOT_ENUMERABLE) 43.18 - protected static Object subarray(final Object self, final Object begin, final Object end) { 43.19 - return ArrayBufferView.subarrayImpl(self, begin, end); 43.20 + protected static NativeInt32Array subarray(final Object self, final Object begin, final Object end) { 43.21 + return (NativeInt32Array)ArrayBufferView.subarrayImpl(self, begin, end); 43.22 } 43.23 43.24 @Override
44.1 --- a/src/jdk/nashorn/internal/objects/NativeInt8Array.java Wed Mar 26 12:01:34 2014 -0700 44.2 +++ b/src/jdk/nashorn/internal/objects/NativeInt8Array.java Tue Apr 01 11:44:05 2014 -0700 44.3 @@ -93,8 +93,8 @@ 44.4 * @return new typed array 44.5 */ 44.6 @Constructor(arity = 1) 44.7 - public static Object constructor(final boolean newObj, final Object self, final Object... args) { 44.8 - return constructorImpl(args, FACTORY); 44.9 + public static NativeInt8Array constructor(final boolean newObj, final Object self, final Object... args) { 44.10 + return (NativeInt8Array)constructorImpl(args, FACTORY); 44.11 } 44.12 44.13 NativeInt8Array(final NativeArrayBuffer buffer, final int byteOffset, final int length) { 44.14 @@ -144,8 +144,8 @@ 44.15 * @return sub array 44.16 */ 44.17 @Function(attributes = Attribute.NOT_ENUMERABLE) 44.18 - protected static Object subarray(final Object self, final Object begin, final Object end) { 44.19 - return ArrayBufferView.subarrayImpl(self, begin, end); 44.20 + protected static NativeInt8Array subarray(final Object self, final Object begin, final Object end) { 44.21 + return (NativeInt8Array)ArrayBufferView.subarrayImpl(self, begin, end); 44.22 } 44.23 44.24 @Override
45.1 --- a/src/jdk/nashorn/internal/objects/NativeJSAdapter.java Wed Mar 26 12:01:34 2014 -0700 45.2 +++ b/src/jdk/nashorn/internal/objects/NativeJSAdapter.java Tue Apr 01 11:44:05 2014 -0700 45.3 @@ -146,10 +146,6 @@ 45.4 // initialized by nasgen 45.5 private static PropertyMap $nasgenmap$; 45.6 45.7 - static PropertyMap getInitialMap() { 45.8 - return $nasgenmap$; 45.9 - } 45.10 - 45.11 NativeJSAdapter(final Object overrides, final ScriptObject adaptee, final ScriptObject proto, final PropertyMap map) { 45.12 super(proto, map); 45.13 this.adaptee = wrapAdaptee(adaptee); 45.14 @@ -163,7 +159,7 @@ 45.15 } 45.16 45.17 private static ScriptObject wrapAdaptee(final ScriptObject adaptee) { 45.18 - return new JO(adaptee, Global.instance().getObjectMap()); 45.19 + return new JO(adaptee, JO.getInitialMap()); 45.20 } 45.21 45.22 @Override 45.23 @@ -540,7 +536,7 @@ 45.24 * @return new NativeJSAdapter 45.25 */ 45.26 @Constructor 45.27 - public static Object construct(final boolean isNew, final Object self, final Object... args) { 45.28 + public static NativeJSAdapter construct(final boolean isNew, final Object self, final Object... args) { 45.29 Object proto = UNDEFINED; 45.30 Object overrides = UNDEFINED; 45.31 Object adaptee; 45.32 @@ -577,7 +573,7 @@ 45.33 proto = global.getJSAdapterPrototype(); 45.34 } 45.35 45.36 - return new NativeJSAdapter(overrides, (ScriptObject)adaptee, (ScriptObject)proto, global.getJSAdapterMap()); 45.37 + return new NativeJSAdapter(overrides, (ScriptObject)adaptee, (ScriptObject)proto, $nasgenmap$); 45.38 } 45.39 45.40 @Override 45.41 @@ -622,14 +618,14 @@ 45.42 case "getMethod": 45.43 final FindProperty find = adaptee.findProperty(__call__, true); 45.44 if (find != null) { 45.45 - final Object value = getObjectValue(find); 45.46 + final Object value = find.getObjectValue(); 45.47 if (value instanceof ScriptFunction) { 45.48 final ScriptFunctionImpl func = (ScriptFunctionImpl)value; 45.49 // TODO: It's a shame we need to produce a function bound to this and name, when we'd only need it bound 45.50 // to name. Probably not a big deal, but if we can ever make it leaner, it'd be nice. 45.51 return new GuardedInvocation(MH.dropArguments(MH.constant(Object.class, 45.52 func.makeBoundFunction(this, new Object[] { name })), 0, Object.class), 45.53 - adaptee.getMap().getProtoGetSwitchPoint(adaptee.getProto(), __call__), 45.54 + adaptee.getProtoSwitchPoint(__call__, find.getOwner()), 45.55 testJSAdaptor(adaptee, null, null, null)); 45.56 } 45.57 } 45.58 @@ -691,7 +687,7 @@ 45.59 final MethodType type = desc.getMethodType(); 45.60 if (findData != null) { 45.61 final String name = desc.getNameTokenCount() > 2 ? desc.getNameToken(2) : null; 45.62 - final Object value = getObjectValue(findData); 45.63 + final Object value = findData.getObjectValue(); 45.64 if (value instanceof ScriptFunction) { 45.65 final ScriptFunction func = (ScriptFunction)value; 45.66 45.67 @@ -700,7 +696,7 @@ 45.68 if (methodHandle != null) { 45.69 return new GuardedInvocation( 45.70 methodHandle, 45.71 - adaptee.getMap().getProtoGetSwitchPoint(adaptee.getProto(), hook), 45.72 + adaptee.getProtoSwitchPoint(hook, findData.getOwner()), 45.73 testJSAdaptor(adaptee, findData.getGetter(Object.class), findData.getOwner(), func)); 45.74 } 45.75 } 45.76 @@ -713,7 +709,7 @@ 45.77 final MethodHandle methodHandle = hook.equals(__put__) ? 45.78 MH.asType(Lookup.EMPTY_SETTER, type) : 45.79 Lookup.emptyGetter(type.returnType()); 45.80 - return new GuardedInvocation(methodHandle, adaptee.getMap().getProtoGetSwitchPoint(adaptee.getProto(), hook), testJSAdaptor(adaptee, null, null, null)); 45.81 + return new GuardedInvocation(methodHandle, adaptee.getProtoSwitchPoint(hook, null), testJSAdaptor(adaptee, null, null, null)); 45.82 } 45.83 } 45.84
46.1 --- a/src/jdk/nashorn/internal/objects/NativeJava.java Wed Mar 26 12:01:34 2014 -0700 46.2 +++ b/src/jdk/nashorn/internal/objects/NativeJava.java Tue Apr 01 11:44:05 2014 -0700 46.3 @@ -75,7 +75,7 @@ 46.4 * @see #type(Object, Object) 46.5 */ 46.6 @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 46.7 - public static Object isType(final Object self, final Object type) { 46.8 + public static boolean isType(final Object self, final Object type) { 46.9 return type instanceof StaticClass; 46.10 } 46.11 46.12 @@ -338,7 +338,7 @@ 46.13 * null. 46.14 */ 46.15 @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 46.16 - public static Object from(final Object self, final Object objArray) { 46.17 + public static NativeArray from(final Object self, final Object objArray) { 46.18 if (objArray == null) { 46.19 return null; 46.20 } else if (objArray instanceof Collection) {
47.1 --- a/src/jdk/nashorn/internal/objects/NativeJavaImporter.java Wed Mar 26 12:01:34 2014 -0700 47.2 +++ b/src/jdk/nashorn/internal/objects/NativeJavaImporter.java Tue Apr 01 11:44:05 2014 -0700 47.3 @@ -60,17 +60,13 @@ 47.4 // initialized by nasgen 47.5 private static PropertyMap $nasgenmap$; 47.6 47.7 - static PropertyMap getInitialMap() { 47.8 - return $nasgenmap$; 47.9 - } 47.10 - 47.11 private NativeJavaImporter(final Object[] args, final ScriptObject proto, final PropertyMap map) { 47.12 super(proto, map); 47.13 this.args = args; 47.14 } 47.15 47.16 private NativeJavaImporter(final Object[] args, final Global global) { 47.17 - this(args, global.getJavaImporterPrototype(), global.getJavaImporterMap()); 47.18 + this(args, global.getJavaImporterPrototype(), $nasgenmap$); 47.19 } 47.20 47.21 private NativeJavaImporter(final Object[] args) { 47.22 @@ -90,7 +86,7 @@ 47.23 * @return NativeJavaImporter instance 47.24 */ 47.25 @Constructor(arity = 1) 47.26 - public static Object constructor(final boolean isNew, final Object self, final Object... args) { 47.27 + public static NativeJavaImporter constructor(final boolean isNew, final Object self, final Object... args) { 47.28 return new NativeJavaImporter(args); 47.29 } 47.30 47.31 @@ -134,6 +130,11 @@ 47.32 return createAndSetProperty(desc) ? super.lookup(desc, request) : super.noSuchMethod(desc, request); 47.33 } 47.34 47.35 + @Override 47.36 + protected Object invokeNoSuchProperty(final String name) { 47.37 + return createProperty(name); 47.38 + } 47.39 + 47.40 private boolean createAndSetProperty(final CallSiteDescriptor desc) { 47.41 final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND); 47.42 final Object value = createProperty(name);
48.1 --- a/src/jdk/nashorn/internal/objects/NativeMath.java Wed Mar 26 12:01:34 2014 -0700 48.2 +++ b/src/jdk/nashorn/internal/objects/NativeMath.java Tue Apr 01 11:44:05 2014 -0700 48.3 @@ -92,7 +92,7 @@ 48.4 * @return abs of value 48.5 */ 48.6 @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 48.7 - public static Object abs(final Object self, final Object x) { 48.8 + public static double abs(final Object self, final Object x) { 48.9 return Math.abs(JSType.toNumber(x)); 48.10 } 48.11 48.12 @@ -144,7 +144,7 @@ 48.13 * @return acos of argument 48.14 */ 48.15 @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 48.16 - public static Object acos(final Object self, final Object x) { 48.17 + public static double acos(final Object self, final Object x) { 48.18 return Math.acos(JSType.toNumber(x)); 48.19 } 48.20 48.21 @@ -170,7 +170,7 @@ 48.22 * @return asin of argument 48.23 */ 48.24 @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 48.25 - public static Object asin(final Object self, final Object x) { 48.26 + public static double asin(final Object self, final Object x) { 48.27 return Math.asin(JSType.toNumber(x)); 48.28 } 48.29 48.30 @@ -196,7 +196,7 @@ 48.31 * @return atan of argument 48.32 */ 48.33 @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 48.34 - public static Object atan(final Object self, final Object x) { 48.35 + public static double atan(final Object self, final Object x) { 48.36 return Math.atan(JSType.toNumber(x)); 48.37 } 48.38 48.39 @@ -223,7 +223,7 @@ 48.40 * @return atan2 of x and y 48.41 */ 48.42 @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 48.43 - public static Object atan2(final Object self, final Object y, final Object x) { 48.44 + public static double atan2(final Object self, final Object y, final Object x) { 48.45 return Math.atan2(JSType.toNumber(y), JSType.toNumber(x)); 48.46 } 48.47 48.48 @@ -250,7 +250,7 @@ 48.49 * @return ceil of argument 48.50 */ 48.51 @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 48.52 - public static Object ceil(final Object self, final Object x) { 48.53 + public static double ceil(final Object self, final Object x) { 48.54 return Math.ceil(JSType.toNumber(x)); 48.55 } 48.56 48.57 @@ -302,7 +302,7 @@ 48.58 * @return cos of argument 48.59 */ 48.60 @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 48.61 - public static Object cos(final Object self, final Object x) { 48.62 + public static double cos(final Object self, final Object x) { 48.63 return Math.cos(JSType.toNumber(x)); 48.64 } 48.65 48.66 @@ -328,7 +328,7 @@ 48.67 * @return exp of argument 48.68 */ 48.69 @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 48.70 - public static Object exp(final Object self, final Object x) { 48.71 + public static double exp(final Object self, final Object x) { 48.72 return Math.exp(JSType.toNumber(x)); 48.73 } 48.74 48.75 @@ -341,7 +341,7 @@ 48.76 * @return floor of argument 48.77 */ 48.78 @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 48.79 - public static Object floor(final Object self, final Object x) { 48.80 + public static double floor(final Object self, final Object x) { 48.81 return Math.floor(JSType.toNumber(x)); 48.82 } 48.83 48.84 @@ -393,7 +393,7 @@ 48.85 * @return log of argument 48.86 */ 48.87 @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 48.88 - public static Object log(final Object self, final Object x) { 48.89 + public static double log(final Object self, final Object x) { 48.90 return Math.log(JSType.toNumber(x)); 48.91 } 48.92 48.93 @@ -419,7 +419,7 @@ 48.94 * @return the largest of the arguments, {@link Double#NEGATIVE_INFINITY} if no args given, or identity if one arg is given 48.95 */ 48.96 @Function(arity = 2, attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 48.97 - public static Object max(final Object self, final Object... args) { 48.98 + public static double max(final Object self, final Object... args) { 48.99 switch (args.length) { 48.100 case 0: 48.101 return Double.NEGATIVE_INFINITY; 48.102 @@ -497,7 +497,7 @@ 48.103 * @return the smallest of the arguments, {@link Double#NEGATIVE_INFINITY} if no args given, or identity if one arg is given 48.104 */ 48.105 @Function(arity = 2, attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 48.106 - public static Object min(final Object self, final Object... args) { 48.107 + public static double min(final Object self, final Object... args) { 48.108 switch (args.length) { 48.109 case 0: 48.110 return Double.POSITIVE_INFINITY; 48.111 @@ -576,7 +576,7 @@ 48.112 * @return x raised to the power of y 48.113 */ 48.114 @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 48.115 - public static Object pow(final Object self, final Object x, final Object y) { 48.116 + public static double pow(final Object self, final Object x, final Object y) { 48.117 return Math.pow(JSType.toNumber(x), JSType.toNumber(y)); 48.118 } 48.119 48.120 @@ -602,7 +602,7 @@ 48.121 * @return random number in the range [0..1) 48.122 */ 48.123 @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 48.124 - public static Object random(final Object self) { 48.125 + public static double random(final Object self) { 48.126 return Math.random(); 48.127 } 48.128 48.129 @@ -615,7 +615,7 @@ 48.130 * @return x rounded 48.131 */ 48.132 @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 48.133 - public static Object round(final Object self, final Object x) { 48.134 + public static double round(final Object self, final Object x) { 48.135 final double d = JSType.toNumber(x); 48.136 if (Math.getExponent(d) >= 52) { 48.137 return d; 48.138 @@ -632,7 +632,7 @@ 48.139 * @return sin of x 48.140 */ 48.141 @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 48.142 - public static Object sin(final Object self, final Object x) { 48.143 + public static double sin(final Object self, final Object x) { 48.144 return Math.sin(JSType.toNumber(x)); 48.145 } 48.146 48.147 @@ -658,7 +658,7 @@ 48.148 * @return sqrt of x 48.149 */ 48.150 @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 48.151 - public static Object sqrt(final Object self, final Object x) { 48.152 + public static double sqrt(final Object self, final Object x) { 48.153 return Math.sqrt(JSType.toNumber(x)); 48.154 } 48.155 48.156 @@ -684,7 +684,7 @@ 48.157 * @return tan of x 48.158 */ 48.159 @Function(attributes = Attribute.NOT_ENUMERABLE, where=Where.CONSTRUCTOR) 48.160 - public static Object tan(final Object self, final Object x) { 48.161 + public static double tan(final Object self, final Object x) { 48.162 return Math.tan(JSType.toNumber(x)); 48.163 } 48.164
49.1 --- a/src/jdk/nashorn/internal/objects/NativeNumber.java Wed Mar 26 12:01:34 2014 -0700 49.2 +++ b/src/jdk/nashorn/internal/objects/NativeNumber.java Tue Apr 01 11:44:05 2014 -0700 49.3 @@ -34,6 +34,7 @@ 49.4 49.5 import java.lang.invoke.MethodHandle; 49.6 import java.lang.invoke.MethodHandles; 49.7 +import java.lang.invoke.MethodType; 49.8 import java.text.NumberFormat; 49.9 import java.util.Locale; 49.10 import jdk.internal.dynalink.linker.GuardedInvocation; 49.11 @@ -57,7 +58,10 @@ 49.12 @ScriptClass("Number") 49.13 public final class NativeNumber extends ScriptObject { 49.14 49.15 - static final MethodHandle WRAPFILTER = findWrapFilter(); 49.16 + // Method handle to create an object wrapper for a primitive number 49.17 + private static final MethodHandle WRAPFILTER = findOwnMH("wrapFilter", MH.type(NativeNumber.class, Object.class)); 49.18 + // Method handle to retrieve the Number prototype object 49.19 + private static final MethodHandle PROTOFILTER = findOwnMH("protoFilter", MH.type(Object.class, Object.class)); 49.20 49.21 /** ECMA 15.7.3.2 largest positive finite value */ 49.22 @Property(attributes = Attribute.NON_ENUMERABLE_CONSTANT, where = Where.CONSTRUCTOR) 49.23 @@ -86,10 +90,6 @@ 49.24 // initialized by nasgen 49.25 private static PropertyMap $nasgenmap$; 49.26 49.27 - static PropertyMap getInitialMap() { 49.28 - return $nasgenmap$; 49.29 - } 49.30 - 49.31 private NativeNumber(final double value, final ScriptObject proto, final PropertyMap map) { 49.32 super(proto, map); 49.33 this.value = value; 49.34 @@ -98,7 +98,7 @@ 49.35 } 49.36 49.37 NativeNumber(final double value, final Global global) { 49.38 - this(value, global.getNumberPrototype(), global.getNumberMap()); 49.39 + this(value, global.getNumberPrototype(), $nasgenmap$); 49.40 } 49.41 49.42 private NativeNumber(final double value) { 49.43 @@ -185,7 +185,7 @@ 49.44 * @return number in decimal fixed point notation 49.45 */ 49.46 @Function(attributes = Attribute.NOT_ENUMERABLE) 49.47 - public static Object toFixed(final Object self, final Object fractionDigits) { 49.48 + public static String toFixed(final Object self, final Object fractionDigits) { 49.49 final int f = JSType.toInteger(fractionDigits); 49.50 if (f < 0 || f > 20) { 49.51 throw rangeError("invalid.fraction.digits", "toFixed"); 49.52 @@ -217,7 +217,7 @@ 49.53 * @return number in decimal exponential notation 49.54 */ 49.55 @Function(attributes = Attribute.NOT_ENUMERABLE) 49.56 - public static Object toExponential(final Object self, final Object fractionDigits) { 49.57 + public static String toExponential(final Object self, final Object fractionDigits) { 49.58 final double x = getNumberValue(self); 49.59 final boolean trimZeros = fractionDigits == UNDEFINED; 49.60 final int f = trimZeros ? 16 : JSType.toInteger(fractionDigits); 49.61 @@ -245,7 +245,7 @@ 49.62 * @return number in decimal exponentiation notation or decimal fixed notation depending on {@code precision} 49.63 */ 49.64 @Function(attributes = Attribute.NOT_ENUMERABLE) 49.65 - public static Object toPrecision(final Object self, final Object precision) { 49.66 + public static String toPrecision(final Object self, final Object precision) { 49.67 final double x = getNumberValue(self); 49.68 if (precision == UNDEFINED) { 49.69 return JSType.toString(x); 49.70 @@ -278,7 +278,7 @@ 49.71 * @return string representation of this Number in the given radix 49.72 */ 49.73 @Function(attributes = Attribute.NOT_ENUMERABLE) 49.74 - public static Object toString(final Object self, final Object radix) { 49.75 + public static String toString(final Object self, final Object radix) { 49.76 if (radix != UNDEFINED) { 49.77 final int intRadix = JSType.toInteger(radix); 49.78 if (intRadix != 10) { 49.79 @@ -299,7 +299,7 @@ 49.80 * @return localized string for this Number 49.81 */ 49.82 @Function(attributes = Attribute.NOT_ENUMERABLE) 49.83 - public static Object toLocaleString(final Object self) { 49.84 + public static String toLocaleString(final Object self) { 49.85 return JSType.toString(getNumberValue(self)); 49.86 } 49.87 49.88 @@ -308,10 +308,10 @@ 49.89 * ECMA 15.7.4.4 Number.prototype.valueOf ( ) 49.90 * 49.91 * @param self self reference 49.92 - * @return boxed number value for this Number 49.93 + * @return number value for this Number 49.94 */ 49.95 @Function(attributes = Attribute.NOT_ENUMERABLE) 49.96 - public static Object valueOf(final Object self) { 49.97 + public static double valueOf(final Object self) { 49.98 return getNumberValue(self); 49.99 } 49.100 49.101 @@ -322,7 +322,7 @@ 49.102 * @return Link to be invoked at call site. 49.103 */ 49.104 public static GuardedInvocation lookupPrimitive(final LinkRequest request, final Object receiver) { 49.105 - return PrimitiveLookup.lookupPrimitive(request, Number.class, new NativeNumber(((Number)receiver).doubleValue()), WRAPFILTER); 49.106 + return PrimitiveLookup.lookupPrimitive(request, Number.class, new NativeNumber(((Number)receiver).doubleValue()), WRAPFILTER, PROTOFILTER); 49.107 } 49.108 49.109 @SuppressWarnings("unused") 49.110 @@ -330,6 +330,11 @@ 49.111 return new NativeNumber(((Number)receiver).doubleValue()); 49.112 } 49.113 49.114 + @SuppressWarnings("unused") 49.115 + private static Object protoFilter(final Object object) { 49.116 + return Global.instance().getNumberPrototype(); 49.117 + } 49.118 + 49.119 private static double getNumberValue(final Object self) { 49.120 if (self instanceof Number) { 49.121 return ((Number)self).doubleValue(); 49.122 @@ -378,7 +383,7 @@ 49.123 return str; 49.124 } 49.125 49.126 - private static MethodHandle findWrapFilter() { 49.127 - return MH.findStatic(MethodHandles.lookup(), NativeNumber.class, "wrapFilter", MH.type(NativeNumber.class, Object.class)); 49.128 + private static MethodHandle findOwnMH(final String name, final MethodType type) { 49.129 + return MH.findStatic(MethodHandles.lookup(), NativeNumber.class, name, type); 49.130 } 49.131 }
50.1 --- a/src/jdk/nashorn/internal/objects/NativeObject.java Wed Mar 26 12:01:34 2014 -0700 50.2 +++ b/src/jdk/nashorn/internal/objects/NativeObject.java Tue Apr 01 11:44:05 2014 -0700 50.3 @@ -31,6 +31,7 @@ 50.4 import java.lang.invoke.MethodHandle; 50.5 import java.lang.invoke.MethodHandles; 50.6 import java.lang.invoke.MethodType; 50.7 +import java.nio.ByteBuffer; 50.8 import java.util.ArrayList; 50.9 import java.util.Collection; 50.10 import java.util.HashSet; 50.11 @@ -58,6 +59,7 @@ 50.12 import jdk.nashorn.internal.runtime.PropertyMap; 50.13 import jdk.nashorn.internal.runtime.ScriptObject; 50.14 import jdk.nashorn.internal.runtime.ScriptRuntime; 50.15 +import jdk.nashorn.internal.runtime.arrays.ArrayData; 50.16 import jdk.nashorn.internal.runtime.linker.Bootstrap; 50.17 import jdk.nashorn.internal.runtime.linker.InvokeByName; 50.18 import jdk.nashorn.internal.runtime.linker.NashornBeansLinker; 50.19 @@ -101,6 +103,27 @@ 50.20 } 50.21 50.22 /** 50.23 + * Nashorn extension: setIndexedPropertiesToExternalArrayData 50.24 + * 50.25 + * @param self self reference 50.26 + * @param obj object whose index properties are backed by buffer 50.27 + * @param buf external buffer - should be a nio ByteBuffer 50.28 + * @return the 'obj' object 50.29 + */ 50.30 + @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 50.31 + public static ScriptObject setIndexedPropertiesToExternalArrayData(final Object self, final Object obj, final Object buf) { 50.32 + Global.checkObject(obj); 50.33 + final ScriptObject sobj = (ScriptObject)obj; 50.34 + if (buf instanceof ByteBuffer) { 50.35 + sobj.setArray(ArrayData.allocate((ByteBuffer)buf)); 50.36 + } else { 50.37 + throw typeError("not.a.bytebuffer", "setIndexedPropertiesToExternalArrayData's buf argument"); 50.38 + } 50.39 + return sobj; 50.40 + } 50.41 + 50.42 + 50.43 + /** 50.44 * ECMA 15.2.3.2 Object.getPrototypeOf ( O ) 50.45 * 50.46 * @param self self reference 50.47 @@ -180,7 +203,7 @@ 50.48 * @return array of property names 50.49 */ 50.50 @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 50.51 - public static Object getOwnPropertyNames(final Object self, final Object obj) { 50.52 + public static ScriptObject getOwnPropertyNames(final Object self, final Object obj) { 50.53 if (obj instanceof ScriptObject) { 50.54 return new NativeArray(((ScriptObject)obj).getOwnKeys(true)); 50.55 } else if (obj instanceof ScriptObjectMirror) { 50.56 @@ -199,7 +222,7 @@ 50.57 * @return object created 50.58 */ 50.59 @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 50.60 - public static Object create(final Object self, final Object proto, final Object props) { 50.61 + public static ScriptObject create(final Object self, final Object proto, final Object props) { 50.62 if (proto != null) { 50.63 Global.checkObject(proto); 50.64 } 50.65 @@ -225,10 +248,11 @@ 50.66 * @return object 50.67 */ 50.68 @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 50.69 - public static Object defineProperty(final Object self, final Object obj, final Object prop, final Object attr) { 50.70 + public static ScriptObject defineProperty(final Object self, final Object obj, final Object prop, final Object attr) { 50.71 Global.checkObject(obj); 50.72 - ((ScriptObject)obj).defineOwnProperty(JSType.toString(prop), attr, true); 50.73 - return obj; 50.74 + final ScriptObject sobj = (ScriptObject)obj; 50.75 + sobj.defineOwnProperty(JSType.toString(prop), attr, true); 50.76 + return sobj; 50.77 } 50.78 50.79 /** 50.80 @@ -240,7 +264,7 @@ 50.81 * @return object 50.82 */ 50.83 @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 50.84 - public static Object defineProperties(final Object self, final Object obj, final Object props) { 50.85 + public static ScriptObject defineProperties(final Object self, final Object obj, final Object props) { 50.86 Global.checkObject(obj); 50.87 50.88 final ScriptObject sobj = (ScriptObject)obj; 50.89 @@ -319,7 +343,7 @@ 50.90 * @return true if sealed, false otherwise 50.91 */ 50.92 @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 50.93 - public static Object isSealed(final Object self, final Object obj) { 50.94 + public static boolean isSealed(final Object self, final Object obj) { 50.95 if (obj instanceof ScriptObject) { 50.96 return ((ScriptObject)obj).isSealed(); 50.97 } else if (obj instanceof ScriptObjectMirror) { 50.98 @@ -337,7 +361,7 @@ 50.99 * @return true if object is frozen, false otherwise 50.100 */ 50.101 @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 50.102 - public static Object isFrozen(final Object self, final Object obj) { 50.103 + public static boolean isFrozen(final Object self, final Object obj) { 50.104 if (obj instanceof ScriptObject) { 50.105 return ((ScriptObject)obj).isFrozen(); 50.106 } else if (obj instanceof ScriptObjectMirror) { 50.107 @@ -355,7 +379,7 @@ 50.108 * @return true if object is extensible, false otherwise 50.109 */ 50.110 @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 50.111 - public static Object isExtensible(final Object self, final Object obj) { 50.112 + public static boolean isExtensible(final Object self, final Object obj) { 50.113 if (obj instanceof ScriptObject) { 50.114 return ((ScriptObject)obj).isExtensible(); 50.115 } else if (obj instanceof ScriptObjectMirror) { 50.116 @@ -373,7 +397,7 @@ 50.117 * @return array of keys in object 50.118 */ 50.119 @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 50.120 - public static Object keys(final Object self, final Object obj) { 50.121 + public static ScriptObject keys(final Object self, final Object obj) { 50.122 if (obj instanceof ScriptObject) { 50.123 final ScriptObject sobj = (ScriptObject)obj; 50.124 return new NativeArray(sobj.getOwnKeys(false)); 50.125 @@ -430,7 +454,7 @@ 50.126 * @return ToString of object 50.127 */ 50.128 @Function(attributes = Attribute.NOT_ENUMERABLE) 50.129 - public static Object toString(final Object self) { 50.130 + public static String toString(final Object self) { 50.131 return ScriptRuntime.builtinObjectToString(self); 50.132 } 50.133 50.134 @@ -483,7 +507,7 @@ 50.135 * @return true if property exists in object 50.136 */ 50.137 @Function(attributes = Attribute.NOT_ENUMERABLE) 50.138 - public static Object hasOwnProperty(final Object self, final Object v) { 50.139 + public static boolean hasOwnProperty(final Object self, final Object v) { 50.140 // Convert ScriptObjects to primitive with String.class hint 50.141 // but no need to convert other primitives to string. 50.142 final Object key = JSType.toPrimitive(v, String.class); 50.143 @@ -500,7 +524,7 @@ 50.144 * @return true if object is prototype of v 50.145 */ 50.146 @Function(attributes = Attribute.NOT_ENUMERABLE) 50.147 - public static Object isPrototypeOf(final Object self, final Object v) { 50.148 + public static boolean isPrototypeOf(final Object self, final Object v) { 50.149 if (!(v instanceof ScriptObject)) { 50.150 return false; 50.151 } 50.152 @@ -526,7 +550,7 @@ 50.153 * @return true if property is enumerable 50.154 */ 50.155 @Function(attributes = Attribute.NOT_ENUMERABLE) 50.156 - public static Object propertyIsEnumerable(final Object self, final Object v) { 50.157 + public static boolean propertyIsEnumerable(final Object self, final Object v) { 50.158 final String str = JSType.toString(v); 50.159 final Object obj = Global.toObject(self); 50.160
51.1 --- a/src/jdk/nashorn/internal/objects/NativeRangeError.java Wed Mar 26 12:01:34 2014 -0700 51.2 +++ b/src/jdk/nashorn/internal/objects/NativeRangeError.java Tue Apr 01 11:44:05 2014 -0700 51.3 @@ -44,7 +44,7 @@ 51.4 public final class NativeRangeError extends ScriptObject { 51.5 51.6 /** message property in instance */ 51.7 - @Property(name = NativeError.MESSAGE) 51.8 + @Property(name = NativeError.MESSAGE, attributes = Attribute.NOT_ENUMERABLE) 51.9 public Object instMessage; 51.10 51.11 /** error name property */ 51.12 @@ -55,13 +55,14 @@ 51.13 @Property(attributes = Attribute.NOT_ENUMERABLE, where = Where.PROTOTYPE) 51.14 public Object message; 51.15 51.16 + /** Nashorn extension: underlying exception */ 51.17 + @Property(attributes = Attribute.NOT_ENUMERABLE) 51.18 + public Object nashornException; 51.19 + 51.20 // initialized by nasgen 51.21 private static PropertyMap $nasgenmap$; 51.22 51.23 - static PropertyMap getInitialMap() { 51.24 - return $nasgenmap$; 51.25 - } 51.26 - 51.27 + @SuppressWarnings("LeakingThisInConstructor") 51.28 private NativeRangeError(final Object msg, final ScriptObject proto, final PropertyMap map) { 51.29 super(proto, map); 51.30 if (msg != UNDEFINED) { 51.31 @@ -69,10 +70,11 @@ 51.32 } else { 51.33 this.delete(NativeError.MESSAGE, false); 51.34 } 51.35 + NativeError.initException(this); 51.36 } 51.37 51.38 NativeRangeError(final Object msg, final Global global) { 51.39 - this(msg, global.getRangeErrorPrototype(), global.getRangeErrorMap()); 51.40 + this(msg, global.getRangeErrorPrototype(), $nasgenmap$); 51.41 } 51.42 51.43 private NativeRangeError(final Object msg) { 51.44 @@ -96,7 +98,7 @@ 51.45 * @return new RangeError 51.46 */ 51.47 @Constructor(name = "RangeError") 51.48 - public static Object constructor(final boolean newObj, final Object self, final Object msg) { 51.49 + public static NativeRangeError constructor(final boolean newObj, final Object self, final Object msg) { 51.50 return new NativeRangeError(msg); 51.51 } 51.52 }
52.1 --- a/src/jdk/nashorn/internal/objects/NativeReferenceError.java Wed Mar 26 12:01:34 2014 -0700 52.2 +++ b/src/jdk/nashorn/internal/objects/NativeReferenceError.java Tue Apr 01 11:44:05 2014 -0700 52.3 @@ -44,7 +44,7 @@ 52.4 public final class NativeReferenceError extends ScriptObject { 52.5 52.6 /** message property in instance */ 52.7 - @Property(name = NativeError.MESSAGE) 52.8 + @Property(name = NativeError.MESSAGE, attributes = Attribute.NOT_ENUMERABLE) 52.9 public Object instMessage; 52.10 52.11 /** error name property */ 52.12 @@ -55,13 +55,14 @@ 52.13 @Property(attributes = Attribute.NOT_ENUMERABLE, where = Where.PROTOTYPE) 52.14 public Object message; 52.15 52.16 + /** Nashorn extension: underlying exception */ 52.17 + @Property(attributes = Attribute.NOT_ENUMERABLE) 52.18 + public Object nashornException; 52.19 + 52.20 // initialized by nasgen 52.21 private static PropertyMap $nasgenmap$; 52.22 52.23 - static PropertyMap getInitialMap() { 52.24 - return $nasgenmap$; 52.25 - } 52.26 - 52.27 + @SuppressWarnings("LeakingThisInConstructor") 52.28 private NativeReferenceError(final Object msg, final ScriptObject proto, final PropertyMap map) { 52.29 super(proto, map); 52.30 if (msg != UNDEFINED) { 52.31 @@ -69,10 +70,11 @@ 52.32 } else { 52.33 this.delete(NativeError.MESSAGE, false); 52.34 } 52.35 + NativeError.initException(this); 52.36 } 52.37 52.38 NativeReferenceError(final Object msg, final Global global) { 52.39 - this(msg, global.getReferenceErrorPrototype(), global.getReferenceErrorMap()); 52.40 + this(msg, global.getReferenceErrorPrototype(), $nasgenmap$); 52.41 } 52.42 52.43 private NativeReferenceError(final Object msg) { 52.44 @@ -96,7 +98,7 @@ 52.45 * @return new ReferenceError 52.46 */ 52.47 @Constructor(name = "ReferenceError") 52.48 - public static Object constructor(final boolean newObj, final Object self, final Object msg) { 52.49 + public static NativeReferenceError constructor(final boolean newObj, final Object self, final Object msg) { 52.50 return new NativeReferenceError(msg); 52.51 } 52.52 }
53.1 --- a/src/jdk/nashorn/internal/objects/NativeRegExp.java Wed Mar 26 12:01:34 2014 -0700 53.2 +++ b/src/jdk/nashorn/internal/objects/NativeRegExp.java Tue Apr 01 11:44:05 2014 -0700 53.3 @@ -70,12 +70,8 @@ 53.4 // initialized by nasgen 53.5 private static PropertyMap $nasgenmap$; 53.6 53.7 - static PropertyMap getInitialMap() { 53.8 - return $nasgenmap$; 53.9 - } 53.10 - 53.11 private NativeRegExp(final Global global) { 53.12 - super(global.getRegExpPrototype(), global.getRegExpMap()); 53.13 + super(global.getRegExpPrototype(), $nasgenmap$); 53.14 this.globalObject = global; 53.15 } 53.16 53.17 @@ -126,7 +122,7 @@ 53.18 * @return new NativeRegExp 53.19 */ 53.20 @Constructor(arity = 2) 53.21 - public static Object constructor(final boolean isNew, final Object self, final Object... args) { 53.22 + public static NativeRegExp constructor(final boolean isNew, final Object self, final Object... args) { 53.23 if (args.length > 1) { 53.24 return newRegExp(args[0], args[1]); 53.25 } else if (args.length > 0) { 53.26 @@ -146,7 +142,7 @@ 53.27 * @return new NativeRegExp 53.28 */ 53.29 @SpecializedConstructor 53.30 - public static Object constructor(final boolean isNew, final Object self) { 53.31 + public static NativeRegExp constructor(final boolean isNew, final Object self) { 53.32 return new NativeRegExp("", ""); 53.33 } 53.34 53.35 @@ -161,7 +157,7 @@ 53.36 * @return new NativeRegExp 53.37 */ 53.38 @SpecializedConstructor 53.39 - public static Object constructor(final boolean isNew, final Object self, final Object pattern) { 53.40 + public static NativeRegExp constructor(final boolean isNew, final Object self, final Object pattern) { 53.41 return newRegExp(pattern, UNDEFINED); 53.42 } 53.43 53.44 @@ -177,7 +173,7 @@ 53.45 * @return new NativeRegExp 53.46 */ 53.47 @SpecializedConstructor 53.48 - public static Object constructor(final boolean isNew, final Object self, final Object pattern, final Object flags) { 53.49 + public static NativeRegExp constructor(final boolean isNew, final Object self, final Object pattern, final Object flags) { 53.50 return newRegExp(pattern, flags); 53.51 } 53.52 53.53 @@ -287,7 +283,7 @@ 53.54 * @return new NativeRegExp 53.55 */ 53.56 @Function(attributes = Attribute.NOT_ENUMERABLE) 53.57 - public static Object compile(final Object self, final Object pattern, final Object flags) { 53.58 + public static ScriptObject compile(final Object self, final Object pattern, final Object flags) { 53.59 final NativeRegExp regExp = checkRegExp(self); 53.60 final NativeRegExp compiled = newRegExp(pattern, flags); 53.61 // copy over regexp to 'self' 53.62 @@ -306,7 +302,7 @@ 53.63 * @return array containing the matches or {@code null} if no match 53.64 */ 53.65 @Function(attributes = Attribute.NOT_ENUMERABLE) 53.66 - public static Object exec(final Object self, final Object string) { 53.67 + public static ScriptObject exec(final Object self, final Object string) { 53.68 return checkRegExp(self).exec(JSType.toString(string)); 53.69 } 53.70 53.71 @@ -318,7 +314,7 @@ 53.72 * @return true if matches found, false otherwise 53.73 */ 53.74 @Function(attributes = Attribute.NOT_ENUMERABLE) 53.75 - public static Object test(final Object self, final Object string) { 53.76 + public static boolean test(final Object self, final Object string) { 53.77 return checkRegExp(self).test(JSType.toString(string)); 53.78 } 53.79 53.80 @@ -329,7 +325,7 @@ 53.81 * @return string version of regexp 53.82 */ 53.83 @Function(attributes = Attribute.NOT_ENUMERABLE) 53.84 - public static Object toString(final Object self) { 53.85 + public static String toString(final Object self) { 53.86 return checkRegExp(self).toString(); 53.87 } 53.88 53.89 @@ -622,7 +618,7 @@ 53.90 * @param string String to match. 53.91 * @return NativeArray of matches, string or null. 53.92 */ 53.93 - public Object exec(final String string) { 53.94 + public NativeRegExpExecResult exec(final String string) { 53.95 final RegExpResult match = execInner(string); 53.96 53.97 if (match == null) { 53.98 @@ -639,7 +635,7 @@ 53.99 * @param string String to match. 53.100 * @return True if a match is found. 53.101 */ 53.102 - public Object test(final String string) { 53.103 + public boolean test(final String string) { 53.104 return execInner(string) != null; 53.105 } 53.106 53.107 @@ -653,7 +649,7 @@ 53.108 * @param replacement Replacement string. 53.109 * @return String with substitutions. 53.110 */ 53.111 - Object replace(final String string, final String replacement, final ScriptFunction function) { 53.112 + String replace(final String string, final String replacement, final ScriptFunction function) { 53.113 final RegExpMatcher matcher = regexp.match(string); 53.114 53.115 if (matcher == null) { 53.116 @@ -808,7 +804,7 @@ 53.117 * @param limit Split limit. 53.118 * @return Array of substrings. 53.119 */ 53.120 - Object split(final String string, final long limit) { 53.121 + NativeArray split(final String string, final long limit) { 53.122 if (limit == 0L) { 53.123 return new NativeArray(); 53.124 } 53.125 @@ -871,7 +867,7 @@ 53.126 * @param string String to match. 53.127 * @return Index of match. 53.128 */ 53.129 - Object search(final String string) { 53.130 + int search(final String string) { 53.131 final RegExpResult match = execInner(string); 53.132 53.133 if (match == null) {
54.1 --- a/src/jdk/nashorn/internal/objects/NativeRegExpExecResult.java Wed Mar 26 12:01:34 2014 -0700 54.2 +++ b/src/jdk/nashorn/internal/objects/NativeRegExpExecResult.java Tue Apr 01 11:44:05 2014 -0700 54.3 @@ -53,12 +53,8 @@ 54.4 // initialized by nasgen 54.5 private static PropertyMap $nasgenmap$; 54.6 54.7 - static PropertyMap getInitialMap() { 54.8 - return $nasgenmap$; 54.9 - } 54.10 - 54.11 NativeRegExpExecResult(final RegExpResult result, final Global global) { 54.12 - super(global.getArrayPrototype(), global.getRegExpExecResultMap()); 54.13 + super(global.getArrayPrototype(), $nasgenmap$); 54.14 setIsArray(); 54.15 this.setArray(ArrayData.allocate(result.getGroups().clone())); 54.16 this.index = result.getIndex();
55.1 --- a/src/jdk/nashorn/internal/objects/NativeStrictArguments.java Wed Mar 26 12:01:34 2014 -0700 55.2 +++ b/src/jdk/nashorn/internal/objects/NativeStrictArguments.java Tue Apr 01 11:44:05 2014 -0700 55.3 @@ -60,9 +60,9 @@ 55.4 // In strict mode, the caller and callee properties should throw TypeError 55.5 // Need to add properties directly to map since slots are assigned speculatively by newUserAccessors. 55.6 final int flags = Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE; 55.7 - map = map.addProperty(map.newUserAccessors("caller", flags)); 55.8 - map = map.addProperty(map.newUserAccessors("callee", flags)); 55.9 - map$ = map.setIsShared(); 55.10 + map = map.addPropertyNoHistory(map.newUserAccessors("caller", flags)); 55.11 + map = map.addPropertyNoHistory(map.newUserAccessors("callee", flags)); 55.12 + map$ = map; 55.13 } 55.14 55.15 static PropertyMap getInitialMap() {
56.1 --- a/src/jdk/nashorn/internal/objects/NativeString.java Wed Mar 26 12:01:34 2014 -0700 56.2 +++ b/src/jdk/nashorn/internal/objects/NativeString.java Tue Apr 01 11:44:05 2014 -0700 56.3 @@ -32,6 +32,7 @@ 56.4 56.5 import java.lang.invoke.MethodHandle; 56.6 import java.lang.invoke.MethodHandles; 56.7 +import java.lang.invoke.MethodType; 56.8 import java.text.Collator; 56.9 import java.util.ArrayList; 56.10 import java.util.Arrays; 56.11 @@ -69,21 +70,20 @@ 56.12 56.13 private final CharSequence value; 56.14 56.15 - static final MethodHandle WRAPFILTER = findWrapFilter(); 56.16 + // Method handle to create an object wrapper for a primitive string 56.17 + private static final MethodHandle WRAPFILTER = findOwnMH("wrapFilter", MH.type(NativeString.class, Object.class)); 56.18 + // Method handle to retrieve the String prototype object 56.19 + private static final MethodHandle PROTOFILTER = findOwnMH("protoFilter", MH.type(Object.class, Object.class)); 56.20 56.21 // initialized by nasgen 56.22 private static PropertyMap $nasgenmap$; 56.23 56.24 - static PropertyMap getInitialMap() { 56.25 - return $nasgenmap$; 56.26 - } 56.27 - 56.28 private NativeString(final CharSequence value) { 56.29 this(value, Global.instance()); 56.30 } 56.31 56.32 NativeString(final CharSequence value, final Global global) { 56.33 - this(value, global.getStringPrototype(), global.getStringMap()); 56.34 + this(value, global.getStringPrototype(), $nasgenmap$); 56.35 } 56.36 56.37 private NativeString(final CharSequence value, final ScriptObject proto, final PropertyMap map) { 56.38 @@ -425,7 +425,7 @@ 56.39 * @return string with arguments translated to charcodes 56.40 */ 56.41 @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1, where = Where.CONSTRUCTOR) 56.42 - public static Object fromCharCode(final Object self, final Object... args) { 56.43 + public static String fromCharCode(final Object self, final Object... args) { 56.44 final char[] buf = new char[args.length]; 56.45 int index = 0; 56.46 for (final Object arg : args) { 56.47 @@ -441,7 +441,7 @@ 56.48 * @return string with one charcode 56.49 */ 56.50 @SpecializedFunction 56.51 - public static Object fromCharCode(final Object self, final Object value) { 56.52 + public static String fromCharCode(final Object self, final Object value) { 56.53 try { 56.54 return "" + (char)JSType.toUint16(((Number)value).doubleValue()); 56.55 } catch (final ClassCastException e) { 56.56 @@ -456,7 +456,7 @@ 56.57 * @return string with one charcode 56.58 */ 56.59 @SpecializedFunction 56.60 - public static Object fromCharCode(final Object self, final int value) { 56.61 + public static String fromCharCode(final Object self, final int value) { 56.62 return "" + (char)(value & 0xffff); 56.63 } 56.64 56.65 @@ -467,7 +467,7 @@ 56.66 * @return string with one charcode 56.67 */ 56.68 @SpecializedFunction 56.69 - public static Object fromCharCode(final Object self, final long value) { 56.70 + public static String fromCharCode(final Object self, final long value) { 56.71 return "" + (char)((int)value & 0xffff); 56.72 } 56.73 56.74 @@ -478,7 +478,7 @@ 56.75 * @return string with one charcode 56.76 */ 56.77 @SpecializedFunction 56.78 - public static Object fromCharCode(final Object self, final double value) { 56.79 + public static String fromCharCode(final Object self, final double value) { 56.80 return "" + (char)JSType.toUint16(value); 56.81 } 56.82 56.83 @@ -488,7 +488,7 @@ 56.84 * @return self as string 56.85 */ 56.86 @Function(attributes = Attribute.NOT_ENUMERABLE) 56.87 - public static Object toString(final Object self) { 56.88 + public static String toString(final Object self) { 56.89 return getString(self); 56.90 } 56.91 56.92 @@ -498,7 +498,7 @@ 56.93 * @return self as string 56.94 */ 56.95 @Function(attributes = Attribute.NOT_ENUMERABLE) 56.96 - public static Object valueOf(final Object self) { 56.97 + public static String valueOf(final Object self) { 56.98 return getString(self); 56.99 } 56.100 56.101 @@ -509,7 +509,7 @@ 56.102 * @return string representing the char at the given position 56.103 */ 56.104 @Function(attributes = Attribute.NOT_ENUMERABLE) 56.105 - public static Object charAt(final Object self, final Object pos) { 56.106 + public static String charAt(final Object self, final Object pos) { 56.107 return charAtImpl(checkObjectToString(self), JSType.toInteger(pos)); 56.108 } 56.109 56.110 @@ -546,7 +546,7 @@ 56.111 * @return number representing charcode at position 56.112 */ 56.113 @Function(attributes = Attribute.NOT_ENUMERABLE) 56.114 - public static Object charCodeAt(final Object self, final Object pos) { 56.115 + public static double charCodeAt(final Object self, final Object pos) { 56.116 return charCodeAtImpl(checkObjectToString(self), JSType.toInteger(pos)); 56.117 } 56.118 56.119 @@ -601,7 +601,7 @@ 56.120 * @return position of first match or -1 56.121 */ 56.122 @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) 56.123 - public static Object indexOf(final Object self, final Object search, final Object pos) { 56.124 + public static int indexOf(final Object self, final Object search, final Object pos) { 56.125 final String str = checkObjectToString(self); 56.126 return str.indexOf(JSType.toString(search), JSType.toInteger(pos)); 56.127 } 56.128 @@ -649,7 +649,7 @@ 56.129 * @return last position of match or -1 56.130 */ 56.131 @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) 56.132 - public static Object lastIndexOf(final Object self, final Object search, final Object pos) { 56.133 + public static int lastIndexOf(final Object self, final Object search, final Object pos) { 56.134 56.135 final String str = checkObjectToString(self); 56.136 final String searchStr = JSType.toString(search); 56.137 @@ -680,7 +680,7 @@ 56.138 * @return result of locale sensitive comparison operation between {@code self} and {@code that} 56.139 */ 56.140 @Function(attributes = Attribute.NOT_ENUMERABLE) 56.141 - public static Object localeCompare(final Object self, final Object that) { 56.142 + public static double localeCompare(final Object self, final Object that) { 56.143 56.144 final String str = checkObjectToString(self); 56.145 final Collator collator = Collator.getInstance(Global.getEnv()._locale); 56.146 @@ -698,7 +698,7 @@ 56.147 * @return array of regexp matches 56.148 */ 56.149 @Function(attributes = Attribute.NOT_ENUMERABLE) 56.150 - public static Object match(final Object self, final Object regexp) { 56.151 + public static ScriptObject match(final Object self, final Object regexp) { 56.152 56.153 final String str = checkObjectToString(self); 56.154 56.155 @@ -745,7 +745,7 @@ 56.156 * @return string after replacement 56.157 */ 56.158 @Function(attributes = Attribute.NOT_ENUMERABLE) 56.159 - public static Object replace(final Object self, final Object string, final Object replacement) { 56.160 + public static String replace(final Object self, final Object string, final Object replacement) { 56.161 56.162 final String str = checkObjectToString(self); 56.163 56.164 @@ -771,7 +771,7 @@ 56.165 * @return offset where match occurred 56.166 */ 56.167 @Function(attributes = Attribute.NOT_ENUMERABLE) 56.168 - public static Object search(final Object self, final Object string) { 56.169 + public static int search(final Object self, final Object string) { 56.170 56.171 final String str = checkObjectToString(self); 56.172 final NativeRegExp nativeRegExp = Global.toRegExp(string == UNDEFINED ? "" : string); 56.173 @@ -788,7 +788,7 @@ 56.174 * @return sliced out substring 56.175 */ 56.176 @Function(attributes = Attribute.NOT_ENUMERABLE) 56.177 - public static Object slice(final Object self, final Object start, final Object end) { 56.178 + public static String slice(final Object self, final Object start, final Object end) { 56.179 56.180 final String str = checkObjectToString(self); 56.181 if (end == UNDEFINED) { 56.182 @@ -805,7 +805,7 @@ 56.183 * @return sliced out substring 56.184 */ 56.185 @SpecializedFunction 56.186 - public static Object slice(final Object self, final int start) { 56.187 + public static String slice(final Object self, final int start) { 56.188 final String str = checkObjectToString(self); 56.189 final int from = (start < 0) ? Math.max(str.length() + start, 0) : Math.min(start, str.length()); 56.190 56.191 @@ -820,7 +820,7 @@ 56.192 * @return sliced out substring 56.193 */ 56.194 @SpecializedFunction 56.195 - public static Object slice(final Object self, final double start) { 56.196 + public static String slice(final Object self, final double start) { 56.197 return slice(self, (int)start); 56.198 } 56.199 56.200 @@ -833,7 +833,7 @@ 56.201 * @return sliced out substring 56.202 */ 56.203 @SpecializedFunction 56.204 - public static Object slice(final Object self, final int start, final int end) { 56.205 + public static String slice(final Object self, final int start, final int end) { 56.206 56.207 final String str = checkObjectToString(self); 56.208 final int len = str.length(); 56.209 @@ -853,7 +853,7 @@ 56.210 * @return sliced out substring 56.211 */ 56.212 @SpecializedFunction 56.213 - public static Object slice(final Object self, final double start, final double end) { 56.214 + public static String slice(final Object self, final double start, final double end) { 56.215 return slice(self, (int)start, (int)end); 56.216 } 56.217 56.218 @@ -866,7 +866,7 @@ 56.219 * @return array object in which splits have been placed 56.220 */ 56.221 @Function(attributes = Attribute.NOT_ENUMERABLE) 56.222 - public static Object split(final Object self, final Object separator, final Object limit) { 56.223 + public static ScriptObject split(final Object self, final Object separator, final Object limit) { 56.224 final String str = checkObjectToString(self); 56.225 final long lim = (limit == UNDEFINED) ? JSType.MAX_UINT : JSType.toUint32(limit); 56.226 56.227 @@ -882,7 +882,7 @@ 56.228 return splitString(str, JSType.toString(separator), lim); 56.229 } 56.230 56.231 - private static Object splitString(String str, String separator, long limit) { 56.232 + private static ScriptObject splitString(String str, String separator, long limit) { 56.233 if (separator.isEmpty()) { 56.234 final int length = (int) Math.min(str.length(), limit); 56.235 final Object[] array = new Object[length]; 56.236 @@ -923,7 +923,7 @@ 56.237 * @return substring given start and length of section 56.238 */ 56.239 @Function(attributes = Attribute.NOT_ENUMERABLE) 56.240 - public static Object substr(final Object self, final Object start, final Object length) { 56.241 + public static String substr(final Object self, final Object start, final Object length) { 56.242 final String str = JSType.toString(self); 56.243 final int strLength = str.length(); 56.244 56.245 @@ -946,7 +946,7 @@ 56.246 * @return substring given start and end indexes 56.247 */ 56.248 @Function(attributes = Attribute.NOT_ENUMERABLE) 56.249 - public static Object substring(final Object self, final Object start, final Object end) { 56.250 + public static String substring(final Object self, final Object start, final Object end) { 56.251 56.252 final String str = checkObjectToString(self); 56.253 if (end == UNDEFINED) { 56.254 @@ -1026,7 +1026,7 @@ 56.255 * @return string to lower case 56.256 */ 56.257 @Function(attributes = Attribute.NOT_ENUMERABLE) 56.258 - public static Object toLowerCase(final Object self) { 56.259 + public static String toLowerCase(final Object self) { 56.260 return checkObjectToString(self).toLowerCase(Locale.ROOT); 56.261 } 56.262 56.263 @@ -1036,7 +1036,7 @@ 56.264 * @return string to locale sensitive lower case 56.265 */ 56.266 @Function(attributes = Attribute.NOT_ENUMERABLE) 56.267 - public static Object toLocaleLowerCase(final Object self) { 56.268 + public static String toLocaleLowerCase(final Object self) { 56.269 return checkObjectToString(self).toLowerCase(Global.getEnv()._locale); 56.270 } 56.271 56.272 @@ -1046,7 +1046,7 @@ 56.273 * @return string to upper case 56.274 */ 56.275 @Function(attributes = Attribute.NOT_ENUMERABLE) 56.276 - public static Object toUpperCase(final Object self) { 56.277 + public static String toUpperCase(final Object self) { 56.278 return checkObjectToString(self).toUpperCase(Locale.ROOT); 56.279 } 56.280 56.281 @@ -1056,7 +1056,7 @@ 56.282 * @return string to locale sensitive upper case 56.283 */ 56.284 @Function(attributes = Attribute.NOT_ENUMERABLE) 56.285 - public static Object toLocaleUpperCase(final Object self) { 56.286 + public static String toLocaleUpperCase(final Object self) { 56.287 return checkObjectToString(self).toUpperCase(Global.getEnv()._locale); 56.288 } 56.289 56.290 @@ -1066,7 +1066,7 @@ 56.291 * @return string trimmed from whitespace 56.292 */ 56.293 @Function(attributes = Attribute.NOT_ENUMERABLE) 56.294 - public static Object trim(final Object self) { 56.295 + public static String trim(final Object self) { 56.296 56.297 final String str = checkObjectToString(self); 56.298 int start = 0; 56.299 @@ -1088,7 +1088,7 @@ 56.300 * @return string trimmed left from whitespace 56.301 */ 56.302 @Function(attributes = Attribute.NOT_ENUMERABLE) 56.303 - public static Object trimLeft(final Object self) { 56.304 + public static String trimLeft(final Object self) { 56.305 56.306 final String str = checkObjectToString(self); 56.307 int start = 0; 56.308 @@ -1107,7 +1107,7 @@ 56.309 * @return string trimmed right from whitespace 56.310 */ 56.311 @Function(attributes = Attribute.NOT_ENUMERABLE) 56.312 - public static Object trimRight(final Object self) { 56.313 + public static String trimRight(final Object self) { 56.314 56.315 final String str = checkObjectToString(self); 56.316 int start = 0; 56.317 @@ -1120,7 +1120,7 @@ 56.318 return str.substring(start, end + 1); 56.319 } 56.320 56.321 - private static Object newObj(final Object self, final CharSequence str) { 56.322 + private static ScriptObject newObj(final Object self, final CharSequence str) { 56.323 return new NativeString(str); 56.324 } 56.325 56.326 @@ -1199,7 +1199,7 @@ 56.327 */ 56.328 public static GuardedInvocation lookupPrimitive(final LinkRequest request, final Object receiver) { 56.329 final MethodHandle guard = NashornGuards.getInstanceOf2Guard(String.class, ConsString.class); 56.330 - return PrimitiveLookup.lookupPrimitive(request, guard, new NativeString((CharSequence)receiver), WRAPFILTER); 56.331 + return PrimitiveLookup.lookupPrimitive(request, guard, new NativeString((CharSequence)receiver), WRAPFILTER, PROTOFILTER); 56.332 } 56.333 56.334 @SuppressWarnings("unused") 56.335 @@ -1207,6 +1207,11 @@ 56.336 return new NativeString((CharSequence)receiver); 56.337 } 56.338 56.339 + @SuppressWarnings("unused") 56.340 + private static Object protoFilter(final Object object) { 56.341 + return Global.instance().getStringPrototype(); 56.342 + } 56.343 + 56.344 private static CharSequence getCharSequence(final Object self) { 56.345 if (self instanceof String || self instanceof ConsString) { 56.346 return (CharSequence)self; 56.347 @@ -1254,7 +1259,7 @@ 56.348 return key >= 0 && key < value.length(); 56.349 } 56.350 56.351 - private static MethodHandle findWrapFilter() { 56.352 - return MH.findStatic(MethodHandles.lookup(), NativeString.class, "wrapFilter", MH.type(NativeString.class, Object.class)); 56.353 + private static MethodHandle findOwnMH(final String name, final MethodType type) { 56.354 + return MH.findStatic(MethodHandles.lookup(), NativeString.class, name, type); 56.355 } 56.356 }
57.1 --- a/src/jdk/nashorn/internal/objects/NativeSyntaxError.java Wed Mar 26 12:01:34 2014 -0700 57.2 +++ b/src/jdk/nashorn/internal/objects/NativeSyntaxError.java Tue Apr 01 11:44:05 2014 -0700 57.3 @@ -44,7 +44,7 @@ 57.4 public final class NativeSyntaxError extends ScriptObject { 57.5 57.6 /** message property in instance */ 57.7 - @Property(name = NativeError.MESSAGE) 57.8 + @Property(name = NativeError.MESSAGE, attributes = Attribute.NOT_ENUMERABLE) 57.9 public Object instMessage; 57.10 57.11 /** error name property */ 57.12 @@ -55,20 +55,22 @@ 57.13 @Property(attributes = Attribute.NOT_ENUMERABLE, where = Where.PROTOTYPE) 57.14 public Object message; 57.15 57.16 + /** Nashorn extension: underlying exception */ 57.17 + @Property(attributes = Attribute.NOT_ENUMERABLE) 57.18 + public Object nashornException; 57.19 + 57.20 // initialized by nasgen 57.21 private static PropertyMap $nasgenmap$; 57.22 57.23 - static PropertyMap getInitialMap() { 57.24 - return $nasgenmap$; 57.25 - } 57.26 - 57.27 + @SuppressWarnings("LeakingThisInConstructor") 57.28 NativeSyntaxError(final Object msg, final Global global) { 57.29 - super(global.getSyntaxErrorPrototype(), global.getSyntaxErrorMap()); 57.30 + super(global.getSyntaxErrorPrototype(), $nasgenmap$); 57.31 if (msg != UNDEFINED) { 57.32 this.instMessage = JSType.toString(msg); 57.33 } else { 57.34 this.delete(NativeError.MESSAGE, false); 57.35 } 57.36 + NativeError.initException(this); 57.37 } 57.38 57.39 private NativeSyntaxError(final Object msg) { 57.40 @@ -92,7 +94,7 @@ 57.41 * @return new SyntaxError 57.42 */ 57.43 @Constructor(name = "SyntaxError") 57.44 - public static Object constructor(final boolean newObj, final Object self, final Object msg) { 57.45 + public static NativeSyntaxError constructor(final boolean newObj, final Object self, final Object msg) { 57.46 return new NativeSyntaxError(msg); 57.47 } 57.48 }
58.1 --- a/src/jdk/nashorn/internal/objects/NativeTypeError.java Wed Mar 26 12:01:34 2014 -0700 58.2 +++ b/src/jdk/nashorn/internal/objects/NativeTypeError.java Tue Apr 01 11:44:05 2014 -0700 58.3 @@ -44,7 +44,7 @@ 58.4 public final class NativeTypeError extends ScriptObject { 58.5 58.6 /** message property in instance */ 58.7 - @Property(name = NativeError.MESSAGE) 58.8 + @Property(name = NativeError.MESSAGE, attributes = Attribute.NOT_ENUMERABLE) 58.9 public Object instMessage; 58.10 58.11 /** error name property */ 58.12 @@ -55,20 +55,22 @@ 58.13 @Property(attributes = Attribute.NOT_ENUMERABLE, where = Where.PROTOTYPE) 58.14 public Object message; 58.15 58.16 + /** Nashorn extension: underlying exception */ 58.17 + @Property(attributes = Attribute.NOT_ENUMERABLE) 58.18 + public Object nashornException; 58.19 + 58.20 // initialized by nasgen 58.21 private static PropertyMap $nasgenmap$; 58.22 58.23 - static PropertyMap getInitialMap() { 58.24 - return $nasgenmap$; 58.25 - } 58.26 - 58.27 + @SuppressWarnings("LeakingThisInConstructor") 58.28 NativeTypeError(final Object msg, final Global global) { 58.29 - super(global.getTypeErrorPrototype(), global.getTypeErrorMap()); 58.30 + super(global.getTypeErrorPrototype(), $nasgenmap$); 58.31 if (msg != UNDEFINED) { 58.32 this.instMessage = JSType.toString(msg); 58.33 } else { 58.34 delete(NativeError.MESSAGE, false); 58.35 } 58.36 + NativeError.initException(this); 58.37 } 58.38 58.39 private NativeTypeError(final Object msg) { 58.40 @@ -92,7 +94,7 @@ 58.41 * @return new TypeError 58.42 */ 58.43 @Constructor(name = "TypeError") 58.44 - public static Object constructor(final boolean newObj, final Object self, final Object msg) { 58.45 + public static NativeTypeError constructor(final boolean newObj, final Object self, final Object msg) { 58.46 return new NativeTypeError(msg); 58.47 } 58.48 }
59.1 --- a/src/jdk/nashorn/internal/objects/NativeURIError.java Wed Mar 26 12:01:34 2014 -0700 59.2 +++ b/src/jdk/nashorn/internal/objects/NativeURIError.java Tue Apr 01 11:44:05 2014 -0700 59.3 @@ -43,7 +43,7 @@ 59.4 public final class NativeURIError extends ScriptObject { 59.5 59.6 /** message property in instance */ 59.7 - @Property(name = NativeError.MESSAGE) 59.8 + @Property(name = NativeError.MESSAGE, attributes = Attribute.NOT_ENUMERABLE) 59.9 public Object instMessage; 59.10 59.11 /** error name property */ 59.12 @@ -54,20 +54,22 @@ 59.13 @Property(attributes = Attribute.NOT_ENUMERABLE, where = Where.PROTOTYPE) 59.14 public Object message; 59.15 59.16 + /** Nashorn extension: underlying exception */ 59.17 + @Property(attributes = Attribute.NOT_ENUMERABLE) 59.18 + public Object nashornException; 59.19 + 59.20 // initialized by nasgen 59.21 private static PropertyMap $nasgenmap$; 59.22 59.23 - static PropertyMap getInitialMap() { 59.24 - return $nasgenmap$; 59.25 - } 59.26 - 59.27 + @SuppressWarnings("LeakingThisInConstructor") 59.28 NativeURIError(final Object msg, final Global global) { 59.29 - super(global.getURIErrorPrototype(), global.getURIErrorMap()); 59.30 + super(global.getURIErrorPrototype(), $nasgenmap$); 59.31 if (msg != UNDEFINED) { 59.32 this.instMessage = JSType.toString(msg); 59.33 } else { 59.34 this.delete(NativeError.MESSAGE, false); 59.35 } 59.36 + NativeError.initException(this); 59.37 } 59.38 59.39 private NativeURIError(final Object msg) { 59.40 @@ -91,7 +93,7 @@ 59.41 * @return new URIError 59.42 */ 59.43 @Constructor(name = "URIError") 59.44 - public static Object constructor(final boolean newObj, final Object self, final Object msg) { 59.45 + public static NativeURIError constructor(final boolean newObj, final Object self, final Object msg) { 59.46 return new NativeURIError(msg); 59.47 } 59.48 }
60.1 --- a/src/jdk/nashorn/internal/objects/NativeUint16Array.java Wed Mar 26 12:01:34 2014 -0700 60.2 +++ b/src/jdk/nashorn/internal/objects/NativeUint16Array.java Tue Apr 01 11:44:05 2014 -0700 60.3 @@ -99,8 +99,8 @@ 60.4 * @return new typed array 60.5 */ 60.6 @Constructor(arity = 1) 60.7 - public static Object constructor(final boolean newObj, final Object self, final Object... args) { 60.8 - return constructorImpl(args, FACTORY); 60.9 + public static NativeUint16Array constructor(final boolean newObj, final Object self, final Object... args) { 60.10 + return (NativeUint16Array)constructorImpl(args, FACTORY); 60.11 } 60.12 60.13 NativeUint16Array(final NativeArrayBuffer buffer, final int byteOffset, final int length) { 60.14 @@ -150,8 +150,8 @@ 60.15 * @return sub array 60.16 */ 60.17 @Function(attributes = Attribute.NOT_ENUMERABLE) 60.18 - protected static Object subarray(final Object self, final Object begin, final Object end) { 60.19 - return ArrayBufferView.subarrayImpl(self, begin, end); 60.20 + protected static NativeUint16Array subarray(final Object self, final Object begin, final Object end) { 60.21 + return (NativeUint16Array)ArrayBufferView.subarrayImpl(self, begin, end); 60.22 } 60.23 60.24 @Override
61.1 --- a/src/jdk/nashorn/internal/objects/NativeUint32Array.java Wed Mar 26 12:01:34 2014 -0700 61.2 +++ b/src/jdk/nashorn/internal/objects/NativeUint32Array.java Tue Apr 01 11:44:05 2014 -0700 61.3 @@ -118,8 +118,8 @@ 61.4 * @return new typed array 61.5 */ 61.6 @Constructor(arity = 1) 61.7 - public static Object constructor(final boolean newObj, final Object self, final Object... args) { 61.8 - return constructorImpl(args, FACTORY); 61.9 + public static NativeUint32Array constructor(final boolean newObj, final Object self, final Object... args) { 61.10 + return (NativeUint32Array)constructorImpl(args, FACTORY); 61.11 } 61.12 61.13 NativeUint32Array(final NativeArrayBuffer buffer, final int byteOffset, final int length) { 61.14 @@ -169,8 +169,8 @@ 61.15 * @return sub array 61.16 */ 61.17 @Function(attributes = Attribute.NOT_ENUMERABLE) 61.18 - protected static Object subarray(final Object self, final Object begin, final Object end) { 61.19 - return ArrayBufferView.subarrayImpl(self, begin, end); 61.20 + protected static NativeUint32Array subarray(final Object self, final Object begin, final Object end) { 61.21 + return (NativeUint32Array)ArrayBufferView.subarrayImpl(self, begin, end); 61.22 } 61.23 61.24 @Override
62.1 --- a/src/jdk/nashorn/internal/objects/NativeUint8Array.java Wed Mar 26 12:01:34 2014 -0700 62.2 +++ b/src/jdk/nashorn/internal/objects/NativeUint8Array.java Tue Apr 01 11:44:05 2014 -0700 62.3 @@ -92,8 +92,8 @@ 62.4 * @return new typed array 62.5 */ 62.6 @Constructor(arity = 1) 62.7 - public static Object constructor(final boolean newObj, final Object self, final Object... args) { 62.8 - return constructorImpl(args, FACTORY); 62.9 + public static NativeUint8Array constructor(final boolean newObj, final Object self, final Object... args) { 62.10 + return (NativeUint8Array)constructorImpl(args, FACTORY); 62.11 } 62.12 62.13 NativeUint8Array(final NativeArrayBuffer buffer, final int byteOffset, final int length) { 62.14 @@ -143,8 +143,8 @@ 62.15 * @return sub array 62.16 */ 62.17 @Function(attributes = Attribute.NOT_ENUMERABLE) 62.18 - protected static Object subarray(final Object self, final Object begin, final Object end) { 62.19 - return ArrayBufferView.subarrayImpl(self, begin, end); 62.20 + protected static NativeUint8Array subarray(final Object self, final Object begin, final Object end) { 62.21 + return (NativeUint8Array)ArrayBufferView.subarrayImpl(self, begin, end); 62.22 } 62.23 62.24 @Override
63.1 --- a/src/jdk/nashorn/internal/objects/NativeUint8ClampedArray.java Wed Mar 26 12:01:34 2014 -0700 63.2 +++ b/src/jdk/nashorn/internal/objects/NativeUint8ClampedArray.java Tue Apr 01 11:44:05 2014 -0700 63.3 @@ -109,8 +109,8 @@ 63.4 * @return new typed array 63.5 */ 63.6 @Constructor(arity = 1) 63.7 - public static Object constructor(final boolean newObj, final Object self, final Object... args) { 63.8 - return constructorImpl(args, FACTORY); 63.9 + public static NativeUint8ClampedArray constructor(final boolean newObj, final Object self, final Object... args) { 63.10 + return (NativeUint8ClampedArray)constructorImpl(args, FACTORY); 63.11 } 63.12 63.13 NativeUint8ClampedArray(final NativeArrayBuffer buffer, final int byteOffset, final int length) { 63.14 @@ -160,8 +160,8 @@ 63.15 * @return sub array 63.16 */ 63.17 @Function(attributes = Attribute.NOT_ENUMERABLE) 63.18 - protected static Object subarray(final Object self, final Object begin, final Object end) { 63.19 - return ArrayBufferView.subarrayImpl(self, begin, end); 63.20 + protected static NativeUint8ClampedArray subarray(final Object self, final Object begin, final Object end) { 63.21 + return (NativeUint8ClampedArray)ArrayBufferView.subarrayImpl(self, begin, end); 63.22 } 63.23 63.24 @Override
64.1 --- a/src/jdk/nashorn/internal/objects/PrototypeObject.java Wed Mar 26 12:01:34 2014 -0700 64.2 +++ b/src/jdk/nashorn/internal/objects/PrototypeObject.java Tue Apr 01 11:44:05 2014 -0700 64.3 @@ -54,16 +54,11 @@ 64.4 static { 64.5 final ArrayList<Property> properties = new ArrayList<>(1); 64.6 properties.add(AccessorProperty.create("constructor", Property.NOT_ENUMERABLE, GET_CONSTRUCTOR, SET_CONSTRUCTOR)); 64.7 - map$ = PropertyMap.newMap(properties).setIsShared(); 64.8 - } 64.9 - 64.10 - static PropertyMap getInitialMap() { 64.11 - return map$; 64.12 + map$ = PropertyMap.newMap(properties); 64.13 } 64.14 64.15 private PrototypeObject(final Global global, final PropertyMap map) { 64.16 - super(map != map$? map.addAll(global.getPrototypeObjectMap()) : global.getPrototypeObjectMap()); 64.17 - setProto(global.getObjectPrototype()); 64.18 + super(global.getObjectPrototype(), map != map$? map.addAll(map$) : map$); 64.19 } 64.20 64.21 PrototypeObject() {
65.1 --- a/src/jdk/nashorn/internal/objects/ScriptFunctionImpl.java Wed Mar 26 12:01:34 2014 -0700 65.2 +++ b/src/jdk/nashorn/internal/objects/ScriptFunctionImpl.java Tue Apr 01 11:44:05 2014 -0700 65.3 @@ -37,7 +37,6 @@ 65.4 import jdk.nashorn.internal.runtime.ScriptFunction; 65.5 import jdk.nashorn.internal.runtime.ScriptFunctionData; 65.6 import jdk.nashorn.internal.runtime.ScriptObject; 65.7 -import jdk.nashorn.internal.lookup.Lookup; 65.8 import jdk.nashorn.internal.runtime.AccessorProperty; 65.9 65.10 /** 65.11 @@ -56,27 +55,11 @@ 65.12 // property map for non-strict, non-bound functions. 65.13 private static final PropertyMap map$; 65.14 65.15 - static PropertyMap getInitialMap() { 65.16 - return map$; 65.17 - } 65.18 - 65.19 - static PropertyMap getInitialAnonymousMap() { 65.20 - return AnonymousFunction.getInitialMap(); 65.21 - } 65.22 - 65.23 - static PropertyMap getInitialStrictMap() { 65.24 - return strictmodemap$; 65.25 - } 65.26 - 65.27 - static PropertyMap getInitialBoundMap() { 65.28 - return boundfunctionmap$; 65.29 - } 65.30 - 65.31 // Marker object for lazily initialized prototype object 65.32 private static final Object LAZY_PROTOTYPE = new Object(); 65.33 65.34 private ScriptFunctionImpl(final String name, final MethodHandle invokeHandle, final MethodHandle[] specs, final Global global) { 65.35 - super(name, invokeHandle, global.getFunctionMap(), null, specs, false, true, true); 65.36 + super(name, invokeHandle, map$, null, specs, ScriptFunctionData.IS_BUILTIN_CONSTRUCTOR); 65.37 init(global); 65.38 } 65.39 65.40 @@ -93,7 +76,7 @@ 65.41 } 65.42 65.43 private ScriptFunctionImpl(final String name, final MethodHandle invokeHandle, final PropertyMap map, final MethodHandle[] specs, final Global global) { 65.44 - super(name, invokeHandle, map.addAll(global.getFunctionMap()), null, specs, false, true, true); 65.45 + super(name, invokeHandle, map.addAll(map$), null, specs, ScriptFunctionData.IS_BUILTIN_CONSTRUCTOR); 65.46 init(global); 65.47 } 65.48 65.49 @@ -110,8 +93,8 @@ 65.50 this(name, invokeHandle, map, specs, Global.instance()); 65.51 } 65.52 65.53 - private ScriptFunctionImpl(final String name, final MethodHandle methodHandle, final ScriptObject scope, final MethodHandle[] specs, final boolean isStrict, final boolean isBuiltin, final boolean isConstructor, final Global global) { 65.54 - super(name, methodHandle, getMap(global, isStrict), scope, specs, isStrict, isBuiltin, isConstructor); 65.55 + private ScriptFunctionImpl(final String name, final MethodHandle methodHandle, final ScriptObject scope, final MethodHandle[] specs, final int flags, final Global global) { 65.56 + super(name, methodHandle, getMap(isStrict(flags)), scope, specs, flags); 65.57 init(global); 65.58 } 65.59 65.60 @@ -122,16 +105,14 @@ 65.61 * @param methodHandle handle for invocation 65.62 * @param scope scope object 65.63 * @param specs specialized versions of this method, if available, null otherwise 65.64 - * @param isStrict are we in strict mode 65.65 - * @param isBuiltin is this a built-in function 65.66 - * @param isConstructor can the function be used as a constructor (most can; some built-ins are restricted). 65.67 + * @param flags {@link ScriptFunctionData} flags 65.68 */ 65.69 - ScriptFunctionImpl(final String name, final MethodHandle methodHandle, final ScriptObject scope, final MethodHandle[] specs, final boolean isStrict, final boolean isBuiltin, final boolean isConstructor) { 65.70 - this(name, methodHandle, scope, specs, isStrict, isBuiltin, isConstructor, Global.instance()); 65.71 + ScriptFunctionImpl(final String name, final MethodHandle methodHandle, final ScriptObject scope, final MethodHandle[] specs, final int flags) { 65.72 + this(name, methodHandle, scope, specs, flags, Global.instance()); 65.73 } 65.74 65.75 private ScriptFunctionImpl(final RecompilableScriptFunctionData data, final ScriptObject scope, final Global global) { 65.76 - super(data, getMap(global, data.isStrict()), scope); 65.77 + super(data, getMap(data.isStrict()), scope); 65.78 init(global); 65.79 } 65.80 65.81 @@ -151,7 +132,7 @@ 65.82 * @param global the global object 65.83 */ 65.84 ScriptFunctionImpl(final ScriptFunctionData data, final Global global) { 65.85 - super(data, global.getBoundFunctionMap(), null); 65.86 + super(data, boundfunctionmap$, null); 65.87 init(global); 65.88 } 65.89 65.90 @@ -163,25 +144,24 @@ 65.91 map$ = PropertyMap.newMap(properties); 65.92 strictmodemap$ = createStrictModeMap(map$); 65.93 boundfunctionmap$ = createBoundFunctionMap(strictmodemap$); 65.94 - // There are order dependencies between normal map, struct map and bound map 65.95 - // We can make these 'shared' only after initialization of all three. 65.96 - map$.setIsShared(); 65.97 - strictmodemap$.setIsShared(); 65.98 - boundfunctionmap$.setIsShared(); 65.99 } 65.100 65.101 private static PropertyMap createStrictModeMap(final PropertyMap map) { 65.102 final int flags = Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE; 65.103 PropertyMap newMap = map; 65.104 // Need to add properties directly to map since slots are assigned speculatively by newUserAccessors. 65.105 - newMap = newMap.addProperty(map.newUserAccessors("arguments", flags)); 65.106 - newMap = newMap.addProperty(map.newUserAccessors("caller", flags)); 65.107 + newMap = newMap.addPropertyNoHistory(map.newUserAccessors("arguments", flags)); 65.108 + newMap = newMap.addPropertyNoHistory(map.newUserAccessors("caller", flags)); 65.109 return newMap; 65.110 } 65.111 65.112 + private static boolean isStrict(final int flags) { 65.113 + return (flags & ScriptFunctionData.IS_STRICT) != 0; 65.114 + } 65.115 + 65.116 // Choose the map based on strict mode! 65.117 - private static PropertyMap getMap(final Global global, final boolean strict) { 65.118 - return strict ? global.getStrictFunctionMap() : global.getFunctionMap(); 65.119 + private static PropertyMap getMap(final boolean strict) { 65.120 + return strict ? strictmodemap$ : map$; 65.121 } 65.122 65.123 private static PropertyMap createBoundFunctionMap(final PropertyMap strictModeMap) { 65.124 @@ -193,14 +173,10 @@ 65.125 // Instance of this class is used as global anonymous function which 65.126 // serves as Function.prototype object. 65.127 private static class AnonymousFunction extends ScriptFunctionImpl { 65.128 - private static final PropertyMap anonmap$ = PropertyMap.newMap().setIsShared(); 65.129 - 65.130 - static PropertyMap getInitialMap() { 65.131 - return anonmap$; 65.132 - } 65.133 + private static final PropertyMap anonmap$ = PropertyMap.newMap(); 65.134 65.135 AnonymousFunction(final Global global) { 65.136 - super("", GlobalFunctions.ANONYMOUS, global.getAnonymousFunctionMap(), null); 65.137 + super("", GlobalFunctions.ANONYMOUS, anonmap$, null); 65.138 } 65.139 } 65.140 65.141 @@ -217,7 +193,7 @@ 65.142 * @return new ScriptFunction 65.143 */ 65.144 static ScriptFunction makeFunction(final String name, final MethodHandle methodHandle, final MethodHandle[] specs) { 65.145 - final ScriptFunctionImpl func = new ScriptFunctionImpl(name, methodHandle, null, specs, false, true, false); 65.146 + final ScriptFunctionImpl func = new ScriptFunctionImpl(name, methodHandle, null, specs, ScriptFunctionData.IS_BUILTIN); 65.147 func.setPrototype(UNDEFINED); 65.148 // Non-constructor built-in functions do not have "prototype" property 65.149 func.deleteOwnProperty(func.getMap().findProperty("prototype")); 65.150 @@ -281,13 +257,17 @@ 65.151 } 65.152 65.153 @Override 65.154 - public final void setPrototype(final Object prototype) { 65.155 - this.prototype = prototype; 65.156 + public final void setPrototype(final Object newProto) { 65.157 + if (newProto instanceof ScriptObject && newProto != this.prototype && allocatorMap != null) { 65.158 + // Replace our current allocator map with one that is associated with the new prototype. 65.159 + allocatorMap = allocatorMap.changeProto((ScriptObject)newProto); 65.160 + } 65.161 + this.prototype = newProto; 65.162 } 65.163 65.164 // Internals below.. 65.165 private void init(final Global global) { 65.166 - this.setProto(global.getFunctionPrototype()); 65.167 + this.setInitialProto(global.getFunctionPrototype()); 65.168 this.prototype = LAZY_PROTOTYPE; 65.169 65.170 // We have to fill user accessor functions late as these are stored
66.1 --- a/src/jdk/nashorn/internal/parser/AbstractParser.java Wed Mar 26 12:01:34 2014 -0700 66.2 +++ b/src/jdk/nashorn/internal/parser/AbstractParser.java Tue Apr 01 11:44:05 2014 -0700 66.3 @@ -26,6 +26,7 @@ 66.4 package jdk.nashorn.internal.parser; 66.5 66.6 import static jdk.nashorn.internal.parser.TokenType.COMMENT; 66.7 +import static jdk.nashorn.internal.parser.TokenType.DIRECTIVE_COMMENT; 66.8 import static jdk.nashorn.internal.parser.TokenType.EOF; 66.9 import static jdk.nashorn.internal.parser.TokenType.EOL; 66.10 import static jdk.nashorn.internal.parser.TokenType.IDENT; 66.11 @@ -84,6 +85,9 @@ 66.12 /** Is this parser running under strict mode? */ 66.13 protected boolean isStrictMode; 66.14 66.15 + /** //@ sourceURL or //# sourceURL */ 66.16 + protected String sourceURL; 66.17 + 66.18 /** 66.19 * Construct a parser. 66.20 * 66.21 @@ -156,17 +160,38 @@ 66.22 protected final TokenType nextOrEOL() { 66.23 do { 66.24 nextToken(); 66.25 - } while (type == COMMENT); 66.26 + if (type == DIRECTIVE_COMMENT) { 66.27 + checkDirectiveComment(); 66.28 + } 66.29 + } while (type == COMMENT || type == DIRECTIVE_COMMENT); 66.30 66.31 return type; 66.32 } 66.33 66.34 + // sourceURL= after directive comment 66.35 + private static final String SOURCE_URL_PREFIX = "sourceURL="; 66.36 + 66.37 + // currently only @sourceURL=foo supported 66.38 + private void checkDirectiveComment() { 66.39 + // if already set, ignore this one 66.40 + if (sourceURL != null) { 66.41 + return; 66.42 + } 66.43 + 66.44 + final String comment = (String) lexer.getValueOf(token, isStrictMode); 66.45 + final int len = comment.length(); 66.46 + // 4 characters for directive comment marker //@\s or //#\s 66.47 + if (len > 4 && comment.substring(4).startsWith(SOURCE_URL_PREFIX)) { 66.48 + sourceURL = comment.substring(4 + SOURCE_URL_PREFIX.length()); 66.49 + } 66.50 + } 66.51 + 66.52 /** 66.53 * Seek next token. 66.54 * 66.55 * @return tokenType of next token. 66.56 */ 66.57 - private final TokenType nextToken() { 66.58 + private TokenType nextToken() { 66.59 // Capture last token tokenType. 66.60 last = type; 66.61 if (type != EOF) {
67.1 --- a/src/jdk/nashorn/internal/parser/Lexer.java Wed Mar 26 12:01:34 2014 -0700 67.2 +++ b/src/jdk/nashorn/internal/parser/Lexer.java Tue Apr 01 11:44:05 2014 -0700 67.3 @@ -27,6 +27,7 @@ 67.4 67.5 import static jdk.nashorn.internal.parser.TokenType.ADD; 67.6 import static jdk.nashorn.internal.parser.TokenType.COMMENT; 67.7 +import static jdk.nashorn.internal.parser.TokenType.DIRECTIVE_COMMENT; 67.8 import static jdk.nashorn.internal.parser.TokenType.DECIMAL; 67.9 import static jdk.nashorn.internal.parser.TokenType.EOF; 67.10 import static jdk.nashorn.internal.parser.TokenType.EOL; 67.11 @@ -434,12 +435,18 @@ 67.12 if (ch1 == '/') { 67.13 // Skip over //. 67.14 skip(2); 67.15 + 67.16 + boolean directiveComment = false; 67.17 + if ((ch0 == '#' || ch0 == '@') && (ch1 == ' ')) { 67.18 + directiveComment = true; 67.19 + } 67.20 + 67.21 // Scan for EOL. 67.22 while (!atEOF() && !isEOL(ch0)) { 67.23 skip(1); 67.24 } 67.25 // Did detect a comment. 67.26 - add(COMMENT, start); 67.27 + add(directiveComment? DIRECTIVE_COMMENT : COMMENT, start); 67.28 return true; 67.29 } else if (ch1 == '*') { 67.30 // Skip over /*. 67.31 @@ -1623,6 +1630,8 @@ 67.32 return valueOfPattern(start, len); // RegexToken::LexerToken 67.33 case XML: 67.34 return valueOfXML(start, len); // XMLToken::LexerToken 67.35 + case DIRECTIVE_COMMENT: 67.36 + return source.getString(start, len); 67.37 default: 67.38 break; 67.39 }
68.1 --- a/src/jdk/nashorn/internal/parser/Parser.java Wed Mar 26 12:01:34 2014 -0700 68.2 +++ b/src/jdk/nashorn/internal/parser/Parser.java Tue Apr 01 11:44:05 2014 -0700 68.3 @@ -26,7 +26,7 @@ 68.4 package jdk.nashorn.internal.parser; 68.5 68.6 import static jdk.nashorn.internal.codegen.CompilerConstants.EVAL; 68.7 -import static jdk.nashorn.internal.codegen.CompilerConstants.FUNCTION_PREFIX; 68.8 +import static jdk.nashorn.internal.codegen.CompilerConstants.ANON_FUNCTION_PREFIX; 68.9 import static jdk.nashorn.internal.codegen.CompilerConstants.RUN_SCRIPT; 68.10 import static jdk.nashorn.internal.parser.TokenType.ASSIGN; 68.11 import static jdk.nashorn.internal.parser.TokenType.CASE; 68.12 @@ -389,7 +389,9 @@ 68.13 sb.append(parentFunction.getName()).append('$'); 68.14 } 68.15 68.16 - sb.append(ident != null ? ident.getName() : FUNCTION_PREFIX.symbolName()); 68.17 + assert ident.getName() != null; 68.18 + sb.append(ident.getName()); 68.19 + 68.20 final String name = namespace.uniqueName(sb.toString()); 68.21 assert parentFunction != null || name.equals(RUN_SCRIPT.symbolName()) : "name = " + name;// must not rename runScript(). 68.22 68.23 @@ -419,7 +421,8 @@ 68.24 name, 68.25 parameters, 68.26 kind, 68.27 - flags); 68.28 + flags, 68.29 + sourceURL); 68.30 68.31 lc.push(functionNode); 68.32 // Create new block, and just put it on the context stack, restoreFunctionNode() will associate it with the 68.33 @@ -638,6 +641,10 @@ 68.34 68.35 script = restoreFunctionNode(script, token); //commit code 68.36 script = script.setBody(lc, script.getBody().setNeedsScope(lc)); 68.37 + // user may have directive comment to set sourceURL 68.38 + if (sourceURL != null) { 68.39 + script = script.setSourceURL(lc, sourceURL); 68.40 + } 68.41 68.42 return script; 68.43 } 68.44 @@ -1792,6 +1799,7 @@ 68.45 case THIS: 68.46 final String name = type.getName(); 68.47 next(); 68.48 + lc.setFlag(lc.getCurrentFunction(), FunctionNode.USES_THIS); 68.49 return new IdentNode(primaryToken, finish, name); 68.50 case IDENT: 68.51 final IdentNode ident = getIdent(); 68.52 @@ -2132,11 +2140,20 @@ 68.53 final String setterName = setIdent.getPropertyName(); 68.54 final IdentNode setNameNode = new IdentNode(((Node)setIdent).getToken(), finish, NameCodec.encode("set " + setterName)); 68.55 expect(LPAREN); 68.56 - final IdentNode argIdent = getIdent(); 68.57 - verifyStrictIdent(argIdent, "setter argument"); 68.58 + // be sloppy and allow missing setter parameter even though 68.59 + // spec does not permit it! 68.60 + final IdentNode argIdent; 68.61 + if (type == IDENT || isNonStrictModeIdent()) { 68.62 + argIdent = getIdent(); 68.63 + verifyStrictIdent(argIdent, "setter argument"); 68.64 + } else { 68.65 + argIdent = null; 68.66 + } 68.67 expect(RPAREN); 68.68 List<IdentNode> parameters = new ArrayList<>(); 68.69 - parameters.add(argIdent); 68.70 + if (argIdent != null) { 68.71 + parameters.add(argIdent); 68.72 + } 68.73 functionNode = functionBody(getSetToken, setNameNode, parameters, FunctionNode.Kind.SETTER); 68.74 return new PropertyNode(propertyToken, finish, setIdent, null, null, functionNode); 68.75 68.76 @@ -2448,7 +2465,7 @@ 68.77 // name is null, generate anonymous name 68.78 boolean isAnonymous = false; 68.79 if (name == null) { 68.80 - final String tmpName = "_L" + functionLine; 68.81 + final String tmpName = ANON_FUNCTION_PREFIX.symbolName() + functionLine; 68.82 name = new IdentNode(functionToken, Token.descPosition(functionToken), tmpName); 68.83 isAnonymous = true; 68.84 }
69.1 --- a/src/jdk/nashorn/internal/parser/TokenType.java Wed Mar 26 12:01:34 2014 -0700 69.2 +++ b/src/jdk/nashorn/internal/parser/TokenType.java Tue Apr 01 11:44:05 2014 -0700 69.3 @@ -41,10 +41,14 @@ 69.4 */ 69.5 @SuppressWarnings("javadoc") 69.6 public enum TokenType { 69.7 - ERROR (SPECIAL, null), 69.8 - EOF (SPECIAL, null), 69.9 - EOL (SPECIAL, null), 69.10 - COMMENT (SPECIAL, null), 69.11 + ERROR (SPECIAL, null), 69.12 + EOF (SPECIAL, null), 69.13 + EOL (SPECIAL, null), 69.14 + COMMENT (SPECIAL, null), 69.15 + // comments of the form //@ foo=bar or //# foo=bar 69.16 + // These comments are treated as special instructions 69.17 + // to the lexer, parser or codegenerator. 69.18 + DIRECTIVE_COMMENT (SPECIAL, null), 69.19 69.20 NOT (UNARY, "!", 14, false), 69.21 NE (BINARY, "!=", 9, true),
70.1 --- a/src/jdk/nashorn/internal/runtime/AccessorProperty.java Wed Mar 26 12:01:34 2014 -0700 70.2 +++ b/src/jdk/nashorn/internal/runtime/AccessorProperty.java Tue Apr 01 11:44:05 2014 -0700 70.3 @@ -141,10 +141,12 @@ 70.4 private Class<?> currentType; 70.5 70.6 /** 70.7 - * Delegate constructor. This is used when adding properties to the Global scope, which 70.8 - * is necessary for outermost levels in a script (the ScriptObject is represented by 70.9 - * a JO-prefixed ScriptObject class, but the properties need to be in the Global scope 70.10 - * and are thus rebound with that as receiver 70.11 + * Delegate constructor for bound properties. This is used for properties created by 70.12 + * {@link ScriptRuntime#mergeScope} and the Nashorn {@code Object.bindProperties} method. 70.13 + * The former is used to add a script's defined globals to the current global scope while 70.14 + * still storing them in a JO-prefixed ScriptObject class. 70.15 + * 70.16 + * <p>All properties created by this constructor have the {@link #IS_BOUND} flag set.</p> 70.17 * 70.18 * @param property accessor property to rebind 70.19 * @param delegate delegate object to rebind receiver to 70.20 @@ -157,6 +159,8 @@ 70.21 this.objectGetter = bindTo(property.ensureObjectGetter(), delegate); 70.22 this.objectSetter = bindTo(property.ensureObjectSetter(), delegate); 70.23 70.24 + // Properties created this way are bound to a delegate 70.25 + this.flags |= IS_BOUND; 70.26 setCurrentType(property.getCurrentType()); 70.27 } 70.28
71.1 --- a/src/jdk/nashorn/internal/runtime/Context.java Wed Mar 26 12:01:34 2014 -0700 71.2 +++ b/src/jdk/nashorn/internal/runtime/Context.java Tue Apr 01 11:44:05 2014 -0700 71.3 @@ -36,6 +36,8 @@ 71.4 import java.io.PrintWriter; 71.5 import java.lang.invoke.MethodHandle; 71.6 import java.lang.invoke.MethodHandles; 71.7 +import java.lang.ref.ReferenceQueue; 71.8 +import java.lang.ref.SoftReference; 71.9 import java.lang.reflect.Modifier; 71.10 import java.util.concurrent.atomic.AtomicLong; 71.11 import java.net.MalformedURLException; 71.12 @@ -47,6 +49,7 @@ 71.13 import java.security.Permissions; 71.14 import java.security.PrivilegedAction; 71.15 import java.security.ProtectionDomain; 71.16 +import java.util.LinkedHashMap; 71.17 import java.util.Map; 71.18 71.19 import jdk.internal.org.objectweb.asm.ClassReader; 71.20 @@ -91,6 +94,11 @@ 71.21 */ 71.22 public static final String NASHORN_JAVA_REFLECTION = "nashorn.JavaReflection"; 71.23 71.24 + /** 71.25 + * Permission to enable nashorn debug mode. 71.26 + */ 71.27 + public static final String NASHORN_DEBUG_MODE = "nashorn.debugMode"; 71.28 + 71.29 // nashorn load psuedo URL prefixes 71.30 private static final String LOAD_CLASSPATH = "classpath:"; 71.31 private static final String LOAD_FX = "fx:"; 71.32 @@ -149,16 +157,19 @@ 71.33 /** Is Context global debug mode enabled ? */ 71.34 public static final boolean DEBUG = Options.getBooleanProperty("nashorn.debug"); 71.35 71.36 - private static final ThreadLocal<ScriptObject> currentGlobal = new ThreadLocal<>(); 71.37 + private static final ThreadLocal<Global> currentGlobal = new ThreadLocal<>(); 71.38 + 71.39 + // class cache 71.40 + private ClassCache classCache; 71.41 71.42 /** 71.43 * Get the current global scope 71.44 * @return the current global scope 71.45 */ 71.46 - public static ScriptObject getGlobal() { 71.47 + public static Global getGlobal() { 71.48 // This class in a package.access protected package. 71.49 // Trusted code only can call this method. 71.50 - return getGlobalTrusted(); 71.51 + return currentGlobal.get(); 71.52 } 71.53 71.54 /** 71.55 @@ -167,10 +178,19 @@ 71.56 */ 71.57 public static void setGlobal(final ScriptObject global) { 71.58 if (global != null && !(global instanceof Global)) { 71.59 - throw new IllegalArgumentException("global is not an instance of Global!"); 71.60 + throw new IllegalArgumentException("not a global!"); 71.61 } 71.62 + setGlobal((Global)global); 71.63 + } 71.64 71.65 - setGlobalTrusted(global); 71.66 + /** 71.67 + * Set the current global scope 71.68 + * @param global the global scope 71.69 + */ 71.70 + public static void setGlobal(final Global global) { 71.71 + // This class in a package.access protected package. 71.72 + // Trusted code only can call this method. 71.73 + currentGlobal.set(global); 71.74 } 71.75 71.76 /** 71.77 @@ -191,7 +211,7 @@ 71.78 * @return error writer of the current context 71.79 */ 71.80 public static PrintWriter getCurrentErr() { 71.81 - final ScriptObject global = getGlobalTrusted(); 71.82 + final ScriptObject global = getGlobal(); 71.83 return (global != null)? global.getContext().getErr() : new PrintWriter(System.err); 71.84 } 71.85 71.86 @@ -344,6 +364,11 @@ 71.87 this.classPathLoader = null; 71.88 } 71.89 71.90 + final int cacheSize = env._class_cache_size; 71.91 + if (cacheSize > 0) { 71.92 + classCache = new ClassCache(cacheSize); 71.93 + } 71.94 + 71.95 // print version info if asked. 71.96 if (env._version) { 71.97 getErr().println("nashorn " + Version.version()); 71.98 @@ -391,7 +416,7 @@ 71.99 * @return the property map of the current global scope 71.100 */ 71.101 public static PropertyMap getGlobalMap() { 71.102 - return Context.getGlobalTrusted().getMap(); 71.103 + return Context.getGlobal().getMap(); 71.104 } 71.105 71.106 /** 71.107 @@ -421,7 +446,7 @@ 71.108 final String file = (location == UNDEFINED || location == null) ? "<eval>" : location.toString(); 71.109 final Source source = new Source(file, string); 71.110 final boolean directEval = location != UNDEFINED; // is this direct 'eval' call or indirectly invoked eval? 71.111 - final ScriptObject global = Context.getGlobalTrusted(); 71.112 + final Global global = Context.getGlobal(); 71.113 71.114 ScriptObject scope = initialScope; 71.115 71.116 @@ -453,7 +478,7 @@ 71.117 // in the caller's environment. A new environment is created! 71.118 if (strictFlag) { 71.119 // Create a new scope object 71.120 - final ScriptObject strictEvalScope = ((GlobalObject)global).newObject(); 71.121 + final ScriptObject strictEvalScope = global.newObject(); 71.122 71.123 // bless it as a "scope" 71.124 strictEvalScope.setIsScope(); 71.125 @@ -578,10 +603,10 @@ 71.126 * @throws IOException if source cannot be found or loaded 71.127 */ 71.128 public Object loadWithNewGlobal(final Object from, final Object...args) throws IOException { 71.129 - final ScriptObject oldGlobal = getGlobalTrusted(); 71.130 - final ScriptObject newGlobal = AccessController.doPrivileged(new PrivilegedAction<ScriptObject>() { 71.131 + final Global oldGlobal = getGlobal(); 71.132 + final Global newGlobal = AccessController.doPrivileged(new PrivilegedAction<Global>() { 71.133 @Override 71.134 - public ScriptObject run() { 71.135 + public Global run() { 71.136 try { 71.137 return newGlobal(); 71.138 } catch (final RuntimeException e) { 71.139 @@ -594,17 +619,17 @@ 71.140 }, CREATE_GLOBAL_ACC_CTXT); 71.141 // initialize newly created Global instance 71.142 initGlobal(newGlobal); 71.143 - setGlobalTrusted(newGlobal); 71.144 + setGlobal(newGlobal); 71.145 71.146 final Object[] wrapped = args == null? ScriptRuntime.EMPTY_ARRAY : ScriptObjectMirror.wrapArray(args, oldGlobal); 71.147 - newGlobal.put("arguments", ((GlobalObject)newGlobal).wrapAsObject(wrapped), env._strict); 71.148 + newGlobal.put("arguments", newGlobal.wrapAsObject(wrapped), env._strict); 71.149 71.150 try { 71.151 // wrap objects from newGlobal's world as mirrors - but if result 71.152 // is from oldGlobal's world, unwrap it! 71.153 return ScriptObjectMirror.unwrap(ScriptObjectMirror.wrap(load(newGlobal, from), newGlobal), oldGlobal); 71.154 } finally { 71.155 - setGlobalTrusted(oldGlobal); 71.156 + setGlobal(oldGlobal); 71.157 } 71.158 } 71.159 71.160 @@ -633,7 +658,7 @@ 71.161 * Checks that the given Class can be accessed from no permissions context. 71.162 * 71.163 * @param clazz Class object 71.164 - * @throw SecurityException if not accessible 71.165 + * @throws SecurityException if not accessible 71.166 */ 71.167 public static void checkPackageAccess(final Class<?> clazz) { 71.168 final SecurityManager sm = System.getSecurityManager(); 71.169 @@ -650,12 +675,12 @@ 71.170 * Checks that the given package name can be accessed from no permissions context. 71.171 * 71.172 * @param pkgName package name 71.173 - * @throw SecurityException if not accessible 71.174 + * @throws SecurityException if not accessible 71.175 */ 71.176 public static void checkPackageAccess(final String pkgName) { 71.177 final SecurityManager sm = System.getSecurityManager(); 71.178 if (sm != null) { 71.179 - checkPackageAccess(sm, pkgName.endsWith(".")? pkgName : pkgName + "."); 71.180 + checkPackageAccess(sm, pkgName.endsWith(".") ? pkgName : pkgName + "."); 71.181 } 71.182 } 71.183 71.184 @@ -779,7 +804,7 @@ 71.185 * 71.186 * @return the initialized global scope object. 71.187 */ 71.188 - public ScriptObject createGlobal() { 71.189 + public Global createGlobal() { 71.190 return initGlobal(newGlobal()); 71.191 } 71.192 71.193 @@ -787,7 +812,7 @@ 71.194 * Create a new uninitialized global scope object 71.195 * @return the global script object 71.196 */ 71.197 - public ScriptObject newGlobal() { 71.198 + public Global newGlobal() { 71.199 return new Global(this); 71.200 } 71.201 71.202 @@ -797,20 +822,16 @@ 71.203 * @param global the global 71.204 * @return the initialized global scope object. 71.205 */ 71.206 - public ScriptObject initGlobal(final ScriptObject global) { 71.207 - if (! (global instanceof GlobalObject)) { 71.208 - throw new IllegalArgumentException("not a global object!"); 71.209 - } 71.210 - 71.211 + public Global initGlobal(final Global global) { 71.212 // Need only minimal global object, if we are just compiling. 71.213 if (!env._compile_only) { 71.214 - final ScriptObject oldGlobal = Context.getGlobalTrusted(); 71.215 + final Global oldGlobal = Context.getGlobal(); 71.216 try { 71.217 - Context.setGlobalTrusted(global); 71.218 + Context.setGlobal(global); 71.219 // initialize global scope with builtin global objects 71.220 - ((GlobalObject)global).initBuiltinObjects(); 71.221 + global.initBuiltinObjects(); 71.222 } finally { 71.223 - Context.setGlobalTrusted(oldGlobal); 71.224 + Context.setGlobal(oldGlobal); 71.225 } 71.226 } 71.227 71.228 @@ -818,30 +839,15 @@ 71.229 } 71.230 71.231 /** 71.232 - * Trusted variants - package-private 71.233 + * Trusted variant - package-private 71.234 */ 71.235 71.236 /** 71.237 - * Return the current global scope 71.238 - * @return current global scope 71.239 - */ 71.240 - static ScriptObject getGlobalTrusted() { 71.241 - return currentGlobal.get(); 71.242 - } 71.243 - 71.244 - /** 71.245 - * Set the current global scope 71.246 - */ 71.247 - static void setGlobalTrusted(ScriptObject global) { 71.248 - currentGlobal.set(global); 71.249 - } 71.250 - 71.251 - /** 71.252 * Return the current global's context 71.253 * @return current global's context 71.254 */ 71.255 static Context getContextTrusted() { 71.256 - return Context.getGlobalTrusted().getContext(); 71.257 + return ((ScriptObject)Context.getGlobal()).getContext(); 71.258 } 71.259 71.260 /** 71.261 @@ -910,7 +916,7 @@ 71.262 } 71.263 71.264 // Package as a JavaScript function and pass function back to shell. 71.265 - return ((GlobalObject)Context.getGlobalTrusted()).newScriptFunction(RUN_SCRIPT.symbolName(), runMethodHandle, scope, strict); 71.266 + return Context.getGlobal().newScriptFunction(RUN_SCRIPT.symbolName(), runMethodHandle, scope, strict); 71.267 } 71.268 71.269 private ScriptFunction compileScript(final Source source, final ScriptObject scope, final ErrorManager errMan) { 71.270 @@ -921,16 +927,10 @@ 71.271 // start with no errors, no warnings. 71.272 errMan.reset(); 71.273 71.274 - GlobalObject global = null; 71.275 - Class<?> script; 71.276 - 71.277 - if (env._class_cache_size > 0) { 71.278 - global = (GlobalObject)Context.getGlobalTrusted(); 71.279 - script = global.findCachedClass(source); 71.280 - if (script != null) { 71.281 - Compiler.LOG.fine("Code cache hit for ", source, " avoiding recompile."); 71.282 - return script; 71.283 - } 71.284 + Class<?> script = findCachedClass(source); 71.285 + if (script != null) { 71.286 + Compiler.LOG.fine("Code cache hit for ", source, " avoiding recompile."); 71.287 + return script; 71.288 } 71.289 71.290 final FunctionNode functionNode = new Parser(env, source, errMan, strict).parse(); 71.291 @@ -952,17 +952,14 @@ 71.292 71.293 final URL url = source.getURL(); 71.294 final ScriptLoader loader = env._loader_per_compile ? createNewLoader() : scriptLoader; 71.295 - final CodeSource cs = url == null ? null : new CodeSource(url, (CodeSigner[])null); 71.296 + final CodeSource cs = new CodeSource(url, (CodeSigner[])null); 71.297 final CodeInstaller<ScriptEnvironment> installer = new ContextCodeInstaller(this, loader, cs); 71.298 71.299 final Compiler compiler = new Compiler(installer, strict); 71.300 71.301 final FunctionNode newFunctionNode = compiler.compile(functionNode); 71.302 script = compiler.install(newFunctionNode); 71.303 - 71.304 - if (global != null) { 71.305 - global.cacheClass(source, script); 71.306 - } 71.307 + cacheClass(source, script); 71.308 71.309 return script; 71.310 } 71.311 @@ -984,4 +981,60 @@ 71.312 private long getUniqueScriptId() { 71.313 return uniqueScriptId.getAndIncrement(); 71.314 } 71.315 + 71.316 + /** 71.317 + * Cache for compiled script classes. 71.318 + */ 71.319 + @SuppressWarnings("serial") 71.320 + private static class ClassCache extends LinkedHashMap<Source, ClassReference> { 71.321 + private final int size; 71.322 + private final ReferenceQueue<Class<?>> queue; 71.323 + 71.324 + ClassCache(int size) { 71.325 + super(size, 0.75f, true); 71.326 + this.size = size; 71.327 + this.queue = new ReferenceQueue<>(); 71.328 + } 71.329 + 71.330 + void cache(final Source source, final Class<?> clazz) { 71.331 + put(source, new ClassReference(clazz, queue, source)); 71.332 + } 71.333 + 71.334 + @Override 71.335 + protected boolean removeEldestEntry(final Map.Entry<Source, ClassReference> eldest) { 71.336 + return size() > size; 71.337 + } 71.338 + 71.339 + @Override 71.340 + public ClassReference get(Object key) { 71.341 + for (ClassReference ref; (ref = (ClassReference)queue.poll()) != null; ) { 71.342 + remove(ref.source); 71.343 + } 71.344 + return super.get(key); 71.345 + } 71.346 + 71.347 + } 71.348 + 71.349 + private static class ClassReference extends SoftReference<Class<?>> { 71.350 + private final Source source; 71.351 + 71.352 + ClassReference(final Class<?> clazz, final ReferenceQueue<Class<?>> queue, final Source source) { 71.353 + super(clazz, queue); 71.354 + this.source = source; 71.355 + } 71.356 + } 71.357 + 71.358 + // Class cache management 71.359 + private Class<?> findCachedClass(final Source source) { 71.360 + ClassReference ref = classCache == null ? null : classCache.get(source); 71.361 + return ref != null ? ref.get() : null; 71.362 + } 71.363 + 71.364 + private void cacheClass(final Source source, final Class<?> clazz) { 71.365 + if (classCache != null) { 71.366 + classCache.cache(source, clazz); 71.367 + } 71.368 + } 71.369 + 71.370 + 71.371 }
72.1 --- a/src/jdk/nashorn/internal/runtime/DebuggerSupport.java Wed Mar 26 12:01:34 2014 -0700 72.2 +++ b/src/jdk/nashorn/internal/runtime/DebuggerSupport.java Tue Apr 01 11:44:05 2014 -0700 72.3 @@ -75,7 +75,7 @@ 72.4 * @return context global. 72.5 */ 72.6 static Object getGlobal() { 72.7 - return Context.getGlobalTrusted(); 72.8 + return Context.getGlobal(); 72.9 } 72.10 72.11 /** 72.12 @@ -87,7 +87,7 @@ 72.13 * @return Result of eval as string, or, an exception or null depending on returnException. 72.14 */ 72.15 static Object eval(final ScriptObject scope, final Object self, final String string, final boolean returnException) { 72.16 - final ScriptObject global = Context.getGlobalTrusted(); 72.17 + final ScriptObject global = Context.getGlobal(); 72.18 final ScriptObject initialScope = scope != null ? scope : global; 72.19 final Object callThis = self != null ? self : global; 72.20 final Context context = global.getContext();
73.1 --- a/src/jdk/nashorn/internal/runtime/ECMAErrors.java Wed Mar 26 12:01:34 2014 -0700 73.2 +++ b/src/jdk/nashorn/internal/runtime/ECMAErrors.java Tue Apr 01 11:44:05 2014 -0700 73.3 @@ -30,6 +30,8 @@ 73.4 import java.util.ResourceBundle; 73.5 import jdk.nashorn.api.scripting.NashornException; 73.6 import jdk.nashorn.internal.scripts.JS; 73.7 +import jdk.nashorn.internal.codegen.CompilerConstants; 73.8 +import jdk.nashorn.internal.objects.Global; 73.9 73.10 /** 73.11 * Helper class to throw various standard "ECMA error" exceptions such as Error, ReferenceError, TypeError etc. 73.12 @@ -65,7 +67,7 @@ 73.13 * @return the resulting {@link ECMAException} 73.14 */ 73.15 public static ECMAException asEcmaException(final ParserException e) { 73.16 - return asEcmaException(Context.getGlobalTrusted(), e); 73.17 + return asEcmaException(Context.getGlobal(), e); 73.18 } 73.19 73.20 /** 73.21 @@ -77,11 +79,11 @@ 73.22 * 73.23 * @return the resulting {@link ECMAException} 73.24 */ 73.25 - public static ECMAException asEcmaException(final ScriptObject global, final ParserException e) { 73.26 + public static ECMAException asEcmaException(final Global global, final ParserException e) { 73.27 final JSErrorType errorType = e.getErrorType(); 73.28 assert errorType != null : "error type for " + e + " was null"; 73.29 73.30 - final GlobalObject globalObj = (GlobalObject)global; 73.31 + final Global globalObj = global; 73.32 final String msg = e.getMessage(); 73.33 73.34 // translate to ECMAScript Error object using error type 73.35 @@ -115,7 +117,7 @@ 73.36 * @return the resulting {@link ECMAException} 73.37 */ 73.38 public static ECMAException syntaxError(final String msgId, final String... args) { 73.39 - return syntaxError(Context.getGlobalTrusted(), msgId, args); 73.40 + return syntaxError(Context.getGlobal(), msgId, args); 73.41 } 73.42 73.43 /** 73.44 @@ -127,7 +129,7 @@ 73.45 * 73.46 * @return the resulting {@link ECMAException} 73.47 */ 73.48 - public static ECMAException syntaxError(final ScriptObject global, final String msgId, final String... args) { 73.49 + public static ECMAException syntaxError(final Global global, final String msgId, final String... args) { 73.50 return syntaxError(global, null, msgId, args); 73.51 } 73.52 73.53 @@ -141,7 +143,7 @@ 73.54 * @return the resulting {@link ECMAException} 73.55 */ 73.56 public static ECMAException syntaxError(final Throwable cause, final String msgId, final String... args) { 73.57 - return syntaxError(Context.getGlobalTrusted(), cause, msgId, args); 73.58 + return syntaxError(Context.getGlobal(), cause, msgId, args); 73.59 } 73.60 73.61 /** 73.62 @@ -154,9 +156,9 @@ 73.63 * 73.64 * @return the resulting {@link ECMAException} 73.65 */ 73.66 - public static ECMAException syntaxError(final ScriptObject global, final Throwable cause, final String msgId, final String... args) { 73.67 + public static ECMAException syntaxError(final Global global, final Throwable cause, final String msgId, final String... args) { 73.68 final String msg = getMessage("syntax.error." + msgId, args); 73.69 - return error(((GlobalObject)global).newSyntaxError(msg), cause); 73.70 + return error(global.newSyntaxError(msg), cause); 73.71 } 73.72 73.73 /** 73.74 @@ -168,7 +170,7 @@ 73.75 * @return the resulting {@link ECMAException} 73.76 */ 73.77 public static ECMAException typeError(final String msgId, final String... args) { 73.78 - return typeError(Context.getGlobalTrusted(), msgId, args); 73.79 + return typeError(Context.getGlobal(), msgId, args); 73.80 } 73.81 73.82 /** 73.83 @@ -180,7 +182,7 @@ 73.84 * 73.85 * @return the resulting {@link ECMAException} 73.86 */ 73.87 - public static ECMAException typeError(final ScriptObject global, final String msgId, final String... args) { 73.88 + public static ECMAException typeError(final Global global, final String msgId, final String... args) { 73.89 return typeError(global, null, msgId, args); 73.90 } 73.91 73.92 @@ -194,7 +196,7 @@ 73.93 * @return the resulting {@link ECMAException} 73.94 */ 73.95 public static ECMAException typeError(final Throwable cause, final String msgId, final String... args) { 73.96 - return typeError(Context.getGlobalTrusted(), cause, msgId, args); 73.97 + return typeError(Context.getGlobal(), cause, msgId, args); 73.98 } 73.99 73.100 /** 73.101 @@ -207,9 +209,9 @@ 73.102 * 73.103 * @return the resulting {@link ECMAException} 73.104 */ 73.105 - public static ECMAException typeError(final ScriptObject global, final Throwable cause, final String msgId, final String... args) { 73.106 + public static ECMAException typeError(final Global global, final Throwable cause, final String msgId, final String... args) { 73.107 final String msg = getMessage("type.error." + msgId, args); 73.108 - return error(((GlobalObject)global).newTypeError(msg), cause); 73.109 + return error(global.newTypeError(msg), cause); 73.110 } 73.111 73.112 /** 73.113 @@ -221,7 +223,7 @@ 73.114 * @return the resulting {@link ECMAException} 73.115 */ 73.116 public static ECMAException rangeError(final String msgId, final String... args) { 73.117 - return rangeError(Context.getGlobalTrusted(), msgId, args); 73.118 + return rangeError(Context.getGlobal(), msgId, args); 73.119 } 73.120 73.121 /** 73.122 @@ -233,7 +235,7 @@ 73.123 * 73.124 * @return the resulting {@link ECMAException} 73.125 */ 73.126 - public static ECMAException rangeError(final ScriptObject global, final String msgId, final String... args) { 73.127 + public static ECMAException rangeError(final Global global, final String msgId, final String... args) { 73.128 return rangeError(global, null, msgId, args); 73.129 } 73.130 73.131 @@ -247,7 +249,7 @@ 73.132 * @return the resulting {@link ECMAException} 73.133 */ 73.134 public static ECMAException rangeError(final Throwable cause, final String msgId, final String... args) { 73.135 - return rangeError(Context.getGlobalTrusted(), cause, msgId, args); 73.136 + return rangeError(Context.getGlobal(), cause, msgId, args); 73.137 } 73.138 73.139 /** 73.140 @@ -260,9 +262,9 @@ 73.141 * 73.142 * @return the resulting {@link ECMAException} 73.143 */ 73.144 - public static ECMAException rangeError(final ScriptObject global, final Throwable cause, final String msgId, final String... args) { 73.145 + public static ECMAException rangeError(final Global global, final Throwable cause, final String msgId, final String... args) { 73.146 final String msg = getMessage("range.error." + msgId, args); 73.147 - return error(((GlobalObject)global).newRangeError(msg), cause); 73.148 + return error(global.newRangeError(msg), cause); 73.149 } 73.150 73.151 /** 73.152 @@ -274,7 +276,7 @@ 73.153 * @return the resulting {@link ECMAException} 73.154 */ 73.155 public static ECMAException referenceError(final String msgId, final String... args) { 73.156 - return referenceError(Context.getGlobalTrusted(), msgId, args); 73.157 + return referenceError(Context.getGlobal(), msgId, args); 73.158 } 73.159 73.160 /** 73.161 @@ -286,7 +288,7 @@ 73.162 * 73.163 * @return the resulting {@link ECMAException} 73.164 */ 73.165 - public static ECMAException referenceError(final ScriptObject global, final String msgId, final String... args) { 73.166 + public static ECMAException referenceError(final Global global, final String msgId, final String... args) { 73.167 return referenceError(global, null, msgId, args); 73.168 } 73.169 73.170 @@ -300,7 +302,7 @@ 73.171 * @return the resulting {@link ECMAException} 73.172 */ 73.173 public static ECMAException referenceError(final Throwable cause, final String msgId, final String... args) { 73.174 - return referenceError(Context.getGlobalTrusted(), cause, msgId, args); 73.175 + return referenceError(Context.getGlobal(), cause, msgId, args); 73.176 } 73.177 73.178 /** 73.179 @@ -313,9 +315,9 @@ 73.180 * 73.181 * @return the resulting {@link ECMAException} 73.182 */ 73.183 - public static ECMAException referenceError(final ScriptObject global, final Throwable cause, final String msgId, final String... args) { 73.184 + public static ECMAException referenceError(final Global global, final Throwable cause, final String msgId, final String... args) { 73.185 final String msg = getMessage("reference.error." + msgId, args); 73.186 - return error(((GlobalObject)global).newReferenceError(msg), cause); 73.187 + return error(global.newReferenceError(msg), cause); 73.188 } 73.189 73.190 /** 73.191 @@ -327,7 +329,7 @@ 73.192 * @return the resulting {@link ECMAException} 73.193 */ 73.194 public static ECMAException uriError(final String msgId, final String... args) { 73.195 - return uriError(Context.getGlobalTrusted(), msgId, args); 73.196 + return uriError(Context.getGlobal(), msgId, args); 73.197 } 73.198 73.199 /** 73.200 @@ -339,7 +341,7 @@ 73.201 * 73.202 * @return the resulting {@link ECMAException} 73.203 */ 73.204 - public static ECMAException uriError(final ScriptObject global, final String msgId, final String... args) { 73.205 + public static ECMAException uriError(final Global global, final String msgId, final String... args) { 73.206 return uriError(global, null, msgId, args); 73.207 } 73.208 73.209 @@ -353,7 +355,7 @@ 73.210 * @return the resulting {@link ECMAException} 73.211 */ 73.212 public static ECMAException uriError(final Throwable cause, final String msgId, final String... args) { 73.213 - return uriError(Context.getGlobalTrusted(), cause, msgId, args); 73.214 + return uriError(Context.getGlobal(), cause, msgId, args); 73.215 } 73.216 73.217 /** 73.218 @@ -366,9 +368,9 @@ 73.219 * 73.220 * @return the resulting {@link ECMAException} 73.221 */ 73.222 - public static ECMAException uriError(final ScriptObject global, final Throwable cause, final String msgId, final String... args) { 73.223 + public static ECMAException uriError(final Global global, final Throwable cause, final String msgId, final String... args) { 73.224 final String msg = getMessage("uri.error." + msgId, args); 73.225 - return error(((GlobalObject)global).newURIError(msg), cause); 73.226 + return error(global.newURIError(msg), cause); 73.227 } 73.228 73.229 /** 73.230 @@ -401,7 +403,7 @@ 73.231 final String className = frame.getClassName(); 73.232 73.233 // Look for script package in class name (into which compiler puts generated code) 73.234 - if (className.startsWith(scriptPackage)) { 73.235 + if (className.startsWith(scriptPackage) && !frame.getMethodName().startsWith(CompilerConstants.INTERNAL_METHOD_PREFIX)) { 73.236 final String source = frame.getFileName(); 73.237 /* 73.238 * Make sure that it is not some Java code that Nashorn has in that package!
74.1 --- a/src/jdk/nashorn/internal/runtime/ECMAException.java Wed Mar 26 12:01:34 2014 -0700 74.2 +++ b/src/jdk/nashorn/internal/runtime/ECMAException.java Tue Apr 01 11:44:05 2014 -0700 74.3 @@ -25,7 +25,7 @@ 74.4 74.5 package jdk.nashorn.internal.runtime; 74.6 74.7 -import static jdk.nashorn.internal.codegen.CompilerConstants.constructorNoLookup; 74.8 +import static jdk.nashorn.internal.codegen.CompilerConstants.staticCallNoLookup; 74.9 import static jdk.nashorn.internal.codegen.CompilerConstants.virtualField; 74.10 import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED; 74.11 74.12 @@ -44,9 +44,9 @@ 74.13 @SuppressWarnings("serial") 74.14 public final class ECMAException extends NashornException { 74.15 /** 74.16 - * Method handle pointing to the constructor {@link ECMAException#ECMAException(Object, String, int, int)}, 74.17 + * Method handle pointing to the constructor {@link ECMAException#create(Object, String, int, int)}, 74.18 */ 74.19 - public static final Call THROW_INIT = constructorNoLookup(ECMAException.class, Object.class, String.class, int.class, int.class); 74.20 + public static final Call CREATE = staticCallNoLookup(ECMAException.class, "create", ECMAException.class, Object.class, String.class, int.class, int.class); 74.21 74.22 /** Field handle to the{@link ECMAException#thrown} field, so that it can be accessed from generated code */ 74.23 public static final FieldAccess THROWN = virtualField(ECMAException.class, "thrown", Object.class); 74.24 @@ -57,23 +57,21 @@ 74.25 public final Object thrown; 74.26 74.27 /** 74.28 - * Constructor. This is called from generated code to implement the {@code throw} 74.29 - * instruction from generated script code 74.30 + * Constructor. Called from the factory method 'create'. 74.31 * 74.32 * @param thrown object to be thrown 74.33 * @param fileName script file name 74.34 * @param line line number of throw 74.35 * @param column column number of throw 74.36 */ 74.37 - public ECMAException(final Object thrown, final String fileName, final int line, final int column) { 74.38 + private ECMAException(final Object thrown, final String fileName, final int line, final int column) { 74.39 super(ScriptRuntime.safeToString(thrown), asThrowable(thrown), fileName, line, column); 74.40 this.thrown = thrown; 74.41 setExceptionToThrown(); 74.42 } 74.43 74.44 /** 74.45 - * Constructor. This is called from runtime code in Nashorn to throw things like 74.46 - * type errors. 74.47 + * Constructor. This is called from the runtime code. 74.48 * 74.49 * @param thrown object to be thrown 74.50 * @param cause Java exception that triggered this throw 74.51 @@ -85,9 +83,39 @@ 74.52 } 74.53 74.54 /** 74.55 + * Factory method to retrieve the underlying exception or create an exception. 74.56 + * This method is called from the generated code. 74.57 + * 74.58 + * @param thrown object to be thrown 74.59 + * @param fileName script file name 74.60 + * @param line line number of throw 74.61 + * @param column column number of throw 74.62 + * @return ECMAException object 74.63 + */ 74.64 + public static ECMAException create(final Object thrown, final String fileName, final int line, final int column) { 74.65 + // If thrown object is an Error or sub-object like TypeError, then 74.66 + // an ECMAException object has been already initialized at constructor. 74.67 + if (thrown instanceof ScriptObject) { 74.68 + ScriptObject sobj = (ScriptObject)thrown; 74.69 + Object exception = getException(sobj); 74.70 + if (exception instanceof ECMAException) { 74.71 + // copy over file name, line number and column number. 74.72 + final ECMAException ee = (ECMAException)exception; 74.73 + ee.setFileName(fileName); 74.74 + ee.setLineNumber(line); 74.75 + ee.setColumnNumber(column); 74.76 + return ee; 74.77 + } 74.78 + } 74.79 + 74.80 + return new ECMAException(thrown, fileName, line, column); 74.81 + } 74.82 + 74.83 + /** 74.84 * Get the thrown object 74.85 * @return thrown object 74.86 */ 74.87 + @Override 74.88 public Object getThrown() { 74.89 return thrown; 74.90 } 74.91 @@ -256,6 +284,8 @@ 74.92 final ScriptObject sobj = (ScriptObject)thrown; 74.93 if (!sobj.has(EXCEPTION_PROPERTY)) { 74.94 sobj.addOwnProperty(EXCEPTION_PROPERTY, Property.NOT_ENUMERABLE, this); 74.95 + } else { 74.96 + sobj.set(EXCEPTION_PROPERTY, this, false); 74.97 } 74.98 } 74.99 }
75.1 --- a/src/jdk/nashorn/internal/runtime/FinalScriptFunctionData.java Wed Mar 26 12:01:34 2014 -0700 75.2 +++ b/src/jdk/nashorn/internal/runtime/FinalScriptFunctionData.java Tue Apr 01 11:44:05 2014 -0700 75.3 @@ -38,31 +38,27 @@ 75.4 /** 75.5 * Constructor - used for bind 75.6 * 75.7 - * @param name name 75.8 - * @param arity arity 75.9 - * @param functions precompiled code 75.10 - * @param isStrict strict 75.11 - * @param isBuiltin builtin 75.12 - * @param isConstructor constructor 75.13 + * @param name name 75.14 + * @param arity arity 75.15 + * @param functions precompiled code 75.16 + * @param flags {@link ScriptFunctionData} flags 75.17 */ 75.18 - FinalScriptFunctionData(final String name, int arity, CompiledFunctions functions, final boolean isStrict, final boolean isBuiltin, final boolean isConstructor) { 75.19 - super(name, arity, isStrict, isBuiltin, isConstructor); 75.20 + FinalScriptFunctionData(final String name, final int arity, final CompiledFunctions functions, final int flags) { 75.21 + super(name, arity, flags); 75.22 code.addAll(functions); 75.23 } 75.24 75.25 /** 75.26 - * Constructor - used from ScriptFunction. This assumes that we have code alraedy for the 75.27 + * Constructor - used from ScriptFunction. This assumes that we have code already for the 75.28 * method (typically a native method) and possibly specializations. 75.29 * 75.30 - * @param name name 75.31 - * @param mh method handle for generic version of method 75.32 - * @param specs specializations 75.33 - * @param isStrict strict 75.34 - * @param isBuiltin builtin 75.35 - * @param isConstructor constructor 75.36 + * @param name name 75.37 + * @param mh method handle for generic version of method 75.38 + * @param specs specializations 75.39 + * @param flags {@link ScriptFunctionData} flags 75.40 */ 75.41 - FinalScriptFunctionData(final String name, final MethodHandle mh, final MethodHandle[] specs, final boolean isStrict, final boolean isBuiltin, final boolean isConstructor) { 75.42 - super(name, arity(mh), isStrict, isBuiltin, isConstructor); 75.43 + FinalScriptFunctionData(final String name, final MethodHandle mh, final MethodHandle[] specs, final int flags) { 75.44 + super(name, arity(mh), flags); 75.45 75.46 addInvoker(mh); 75.47 if (specs != null) {
76.1 --- a/src/jdk/nashorn/internal/runtime/FindProperty.java Wed Mar 26 12:01:34 2014 -0700 76.2 +++ b/src/jdk/nashorn/internal/runtime/FindProperty.java Tue Apr 01 11:44:05 2014 -0700 76.3 @@ -112,7 +112,7 @@ 76.4 return property != null && property.hasGetterFunction(prototype) ? self : prototype; 76.5 } 76.6 76.7 - /** 76.8 + /** 76.9 * Return the appropriate receiver for a setter. 76.10 * @return appropriate receiver 76.11 */ 76.12 @@ -172,5 +172,20 @@ 76.13 property.setObjectValue(getSetterReceiver(), getOwner(), value, strict); 76.14 } 76.15 76.16 + /** 76.17 + * Get the number of objects in the prototype chain between the {@code self} and the 76.18 + * {@code owner} objects. 76.19 + * @return the prototype chain length 76.20 + */ 76.21 + int getProtoChainLength() { 76.22 + assert self != null; 76.23 + int length = 0; 76.24 + for (ScriptObject obj = self; obj != prototype; obj = obj.getProto()) { 76.25 + assert !(obj instanceof WithObject); 76.26 + ++length; 76.27 + } 76.28 + return length; 76.29 + } 76.30 + 76.31 } 76.32
77.1 --- a/src/jdk/nashorn/internal/runtime/GlobalObject.java Wed Mar 26 12:01:34 2014 -0700 77.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 77.3 @@ -1,244 +0,0 @@ 77.4 -/* 77.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 77.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 77.7 - * 77.8 - * This code is free software; you can redistribute it and/or modify it 77.9 - * under the terms of the GNU General Public License version 2 only, as 77.10 - * published by the Free Software Foundation. Oracle designates this 77.11 - * particular file as subject to the "Classpath" exception as provided 77.12 - * by Oracle in the LICENSE file that accompanied this code. 77.13 - * 77.14 - * This code is distributed in the hope that it will be useful, but WITHOUT 77.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 77.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 77.17 - * version 2 for more details (a copy is included in the LICENSE file that 77.18 - * accompanied this code). 77.19 - * 77.20 - * You should have received a copy of the GNU General Public License version 77.21 - * 2 along with this work; if not, write to the Free Software Foundation, 77.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 77.23 - * 77.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 77.25 - * or visit www.oracle.com if you need additional information or have any 77.26 - * questions. 77.27 - */ 77.28 - 77.29 -package jdk.nashorn.internal.runtime; 77.30 - 77.31 -import java.lang.invoke.MethodHandle; 77.32 -import java.util.concurrent.Callable; 77.33 -import jdk.internal.dynalink.linker.GuardedInvocation; 77.34 -import jdk.internal.dynalink.linker.LinkRequest; 77.35 -import jdk.nashorn.internal.runtime.linker.InvokeByName; 77.36 - 77.37 -/** 77.38 - * Runtime interface to the global scope objects. 77.39 - */ 77.40 - 77.41 -public interface GlobalObject { 77.42 - /** 77.43 - * Is this global of the given Context? 77.44 - * @param ctxt the context 77.45 - * @return true if this global belongs to the given Context 77.46 - */ 77.47 - public boolean isOfContext(final Context ctxt); 77.48 - 77.49 - /** 77.50 - * Does this global belong to a strict Context? 77.51 - * @return true if this global belongs to a strict Context 77.52 - */ 77.53 - public boolean isStrictContext(); 77.54 - 77.55 - /** 77.56 - * Initialize standard builtin objects like "Object", "Array", "Function" etc. 77.57 - * as well as our extension builtin objects like "Java", "JSAdapter" as properties 77.58 - * of the global scope object. 77.59 - */ 77.60 - public void initBuiltinObjects(); 77.61 - 77.62 - /** 77.63 - * Wrapper for {@link jdk.nashorn.internal.objects.Global#newScriptFunction(String, MethodHandle, ScriptObject, boolean)} 77.64 - * 77.65 - * @param name function name 77.66 - * @param handle invocation handle for function 77.67 - * @param scope the scope 77.68 - * @param strict are we in strict mode 77.69 - * 77.70 - * @return new script function 77.71 - */ 77.72 - public ScriptFunction newScriptFunction(String name, MethodHandle handle, ScriptObject scope, boolean strict); 77.73 - 77.74 - /** 77.75 - * Wrapper for {@link jdk.nashorn.internal.objects.Global#wrapAsObject(Object)} 77.76 - * 77.77 - * @param obj object to wrap 77.78 - * @return wrapped object 77.79 - */ 77.80 - public Object wrapAsObject(Object obj); 77.81 - 77.82 - 77.83 - /** 77.84 - * Wrapper for {@link jdk.nashorn.internal.objects.Global#primitiveLookup(LinkRequest, Object)} 77.85 - * 77.86 - * @param request the link request for the dynamic call site. 77.87 - * @param self self reference 77.88 - * 77.89 - * @return guarded invocation 77.90 - */ 77.91 - public GuardedInvocation primitiveLookup(LinkRequest request, Object self); 77.92 - 77.93 - 77.94 - /** 77.95 - * Wrapper for {@link jdk.nashorn.internal.objects.Global#newObject()} 77.96 - * 77.97 - * @return the new ScriptObject 77.98 - */ 77.99 - public ScriptObject newObject(); 77.100 - 77.101 - /** 77.102 - * Wrapper for {@link jdk.nashorn.internal.objects.Global#isError(ScriptObject)} 77.103 - * 77.104 - * @param sobj to check if it is an error object 77.105 - * @return true if error object 77.106 - */ 77.107 - public boolean isError(ScriptObject sobj); 77.108 - 77.109 - /** 77.110 - * Wrapper for {@link jdk.nashorn.internal.objects.Global#newError(String)} 77.111 - * 77.112 - * @param msg the error message 77.113 - * 77.114 - * @return the new ScriptObject representing the error 77.115 - */ 77.116 - public ScriptObject newError(String msg); 77.117 - 77.118 - /** 77.119 - * Wrapper for {@link jdk.nashorn.internal.objects.Global#newEvalError(String)} 77.120 - * 77.121 - * @param msg the error message 77.122 - * 77.123 - * @return the new ScriptObject representing the eval error 77.124 - */ 77.125 - public ScriptObject newEvalError(String msg); 77.126 - 77.127 - /** 77.128 - * Wrapper for {@link jdk.nashorn.internal.objects.Global#newRangeError(String)} 77.129 - * 77.130 - * @param msg the error message 77.131 - * 77.132 - * @return the new ScriptObject representing the range error 77.133 - */ 77.134 - public ScriptObject newRangeError(String msg); 77.135 - 77.136 - /** 77.137 - * Wrapper for {@link jdk.nashorn.internal.objects.Global#newReferenceError(String)} 77.138 - * 77.139 - * @param msg the error message 77.140 - * 77.141 - * @return the new ScriptObject representing the reference error 77.142 - */ 77.143 - public ScriptObject newReferenceError(String msg); 77.144 - 77.145 - /** 77.146 - * Wrapper for {@link jdk.nashorn.internal.objects.Global#newSyntaxError(String)} 77.147 - * 77.148 - * @param msg the error message 77.149 - * 77.150 - * @return the new ScriptObject representing the syntax error 77.151 - */ 77.152 - public ScriptObject newSyntaxError(String msg); 77.153 - 77.154 - /** 77.155 - * Wrapper for {@link jdk.nashorn.internal.objects.Global#newTypeError(String)} 77.156 - * 77.157 - * @param msg the error message 77.158 - * 77.159 - * @return the new ScriptObject representing the type error 77.160 - */ 77.161 - public ScriptObject newTypeError(String msg); 77.162 - 77.163 - /** 77.164 - * Wrapper for {@link jdk.nashorn.internal.objects.Global#newURIError(String)} 77.165 - * 77.166 - * @param msg the error message 77.167 - * 77.168 - * @return the new ScriptObject representing the URI error 77.169 - */ 77.170 - public ScriptObject newURIError(String msg); 77.171 - 77.172 - /** 77.173 - * Wrapper for {@link jdk.nashorn.internal.objects.Global#newGenericDescriptor(boolean, boolean)} 77.174 - * 77.175 - * @param configurable is the described property configurable 77.176 - * @param enumerable is the described property enumerable 77.177 - * 77.178 - * @return property descriptor 77.179 - */ 77.180 - public PropertyDescriptor newGenericDescriptor(boolean configurable, boolean enumerable); 77.181 - 77.182 - /** 77.183 - * Wrapper for {@link jdk.nashorn.internal.objects.Global#newDataDescriptor(Object, boolean, boolean, boolean)} 77.184 - * 77.185 - * @param value data value 77.186 - * @param configurable is the described property configurable 77.187 - * @param enumerable is the described property enumerable 77.188 - * @param writable is the described property writable 77.189 - * 77.190 - * @return property descriptor 77.191 - */ 77.192 - public PropertyDescriptor newDataDescriptor(Object value, boolean configurable, boolean enumerable, boolean writable); 77.193 - 77.194 - /** 77.195 - * Wrapper for {@link jdk.nashorn.internal.objects.Global#newAccessorDescriptor(Object, Object, boolean, boolean)} 77.196 - * 77.197 - * @param get property getter, or null if none 77.198 - * @param set property setter, or null if none 77.199 - * @param configurable is the described property configurable 77.200 - * @param enumerable is the described property enumerable 77.201 - * 77.202 - * @return property descriptor 77.203 - */ 77.204 - public PropertyDescriptor newAccessorDescriptor(Object get, Object set, boolean configurable, boolean enumerable); 77.205 - 77.206 - /** 77.207 - * Wrapper for {@link jdk.nashorn.internal.objects.Global#getDefaultValue(ScriptObject, Class)} 77.208 - * 77.209 - * @param sobj script object 77.210 - * @param typeHint type hint 77.211 - * 77.212 - * @return default value 77.213 - */ 77.214 - public Object getDefaultValue(ScriptObject sobj, Class<?> typeHint); 77.215 - 77.216 - /** 77.217 - * Find the compiled Class for the given script source, if available 77.218 - * 77.219 - * @param source Source object of the script 77.220 - * @return compiled Class object or null 77.221 - */ 77.222 - public Class<?> findCachedClass(Source source); 77.223 - 77.224 - /** 77.225 - * Put the Source associated Class object in the Source-to-Class cache 77.226 - * 77.227 - * @param source Source of the script 77.228 - * @param clazz compiled Class object for the source 77.229 - */ 77.230 - public void cacheClass(Source source, Class<?> clazz); 77.231 - 77.232 - /** 77.233 - * Get cached InvokeByName object for the given key 77.234 - * @param key key to be associated with InvokeByName object 77.235 - * @param creator if InvokeByName is absent 'creator' is called to make one (lazy init) 77.236 - * @return InvokeByName object associated with the key. 77.237 - */ 77.238 - public InvokeByName getInvokeByName(final Object key, final Callable<InvokeByName> creator); 77.239 - 77.240 - /** 77.241 - * Get cached dynamic method handle for the given key 77.242 - * @param key key to be associated with dynamic method handle 77.243 - * @param creator if method handle is absent 'creator' is called to make one (lazy init) 77.244 - * @return dynamic method handle associated with the key. 77.245 - */ 77.246 - public MethodHandle getDynamicInvoker(final Object key, final Callable<MethodHandle> creator); 77.247 -}
78.1 --- a/src/jdk/nashorn/internal/runtime/JSONFunctions.java Wed Mar 26 12:01:34 2014 -0700 78.2 +++ b/src/jdk/nashorn/internal/runtime/JSONFunctions.java Tue Apr 01 11:44:05 2014 -0700 78.3 @@ -33,6 +33,7 @@ 78.4 import jdk.nashorn.internal.ir.ObjectNode; 78.5 import jdk.nashorn.internal.ir.PropertyNode; 78.6 import jdk.nashorn.internal.ir.UnaryNode; 78.7 +import jdk.nashorn.internal.objects.Global; 78.8 import jdk.nashorn.internal.parser.JSONParser; 78.9 import jdk.nashorn.internal.parser.TokenType; 78.10 import jdk.nashorn.internal.runtime.arrays.ArrayIndex; 78.11 @@ -47,7 +48,7 @@ 78.12 private static final Object REVIVER_INVOKER = new Object(); 78.13 78.14 private static MethodHandle getREVIVER_INVOKER() { 78.15 - return ((GlobalObject)Context.getGlobal()).getDynamicInvoker(REVIVER_INVOKER, 78.16 + return Context.getGlobal().getDynamicInvoker(REVIVER_INVOKER, 78.17 new Callable<MethodHandle>() { 78.18 @Override 78.19 public MethodHandle call() { 78.20 @@ -88,7 +89,7 @@ 78.21 throw ECMAErrors.syntaxError(e, "invalid.json", e.getMessage()); 78.22 } 78.23 78.24 - final ScriptObject global = Context.getGlobalTrusted(); 78.25 + final Global global = Context.getGlobal(); 78.26 Object unfiltered = convertNode(global, node); 78.27 return applyReviver(global, unfiltered, reviver); 78.28 } 78.29 @@ -98,10 +99,9 @@ 78.30 // parse helpers 78.31 78.32 // apply 'reviver' function if available 78.33 - private static Object applyReviver(final ScriptObject global, final Object unfiltered, final Object reviver) { 78.34 + private static Object applyReviver(final Global global, final Object unfiltered, final Object reviver) { 78.35 if (reviver instanceof ScriptFunction) { 78.36 - assert global instanceof GlobalObject; 78.37 - final ScriptObject root = ((GlobalObject)global).newObject(); 78.38 + final ScriptObject root = global.newObject(); 78.39 root.addOwnProperty("", Property.WRITABLE_ENUMERABLE_CONFIGURABLE, unfiltered); 78.40 return walk(root, "", (ScriptFunction)reviver); 78.41 } 78.42 @@ -138,8 +138,8 @@ 78.43 } 78.44 78.45 // Converts IR node to runtime value 78.46 - private static Object convertNode(final ScriptObject global, final Node node) { 78.47 - assert global instanceof GlobalObject; 78.48 + private static Object convertNode(final Global global, final Node node) { 78.49 + assert global instanceof Global; 78.50 78.51 if (node instanceof LiteralNode) { 78.52 // check for array literal 78.53 @@ -157,7 +157,7 @@ 78.54 for (final Node elem : elements) { 78.55 values[index++] = JSType.toNumber(convertNode(global, elem)); 78.56 } 78.57 - return ((GlobalObject)global).wrapAsObject(values); 78.58 + return global.wrapAsObject(values); 78.59 } 78.60 78.61 final Object[] values = new Object[elements.length]; 78.62 @@ -167,14 +167,14 @@ 78.63 values[index++] = convertNode(global, elem); 78.64 } 78.65 78.66 - return ((GlobalObject)global).wrapAsObject(values); 78.67 + return global.wrapAsObject(values); 78.68 } 78.69 78.70 return ((LiteralNode<?>)node).getValue(); 78.71 78.72 } else if (node instanceof ObjectNode) { 78.73 final ObjectNode objNode = (ObjectNode) node; 78.74 - final ScriptObject object = ((GlobalObject)global).newObject(); 78.75 + final ScriptObject object = global.newObject(); 78.76 78.77 for (final PropertyNode pNode: objNode.getElements()) { 78.78 final Node valueNode = pNode.getValue();
79.1 --- a/src/jdk/nashorn/internal/runtime/JSType.java Wed Mar 26 12:01:34 2014 -0700 79.2 +++ b/src/jdk/nashorn/internal/runtime/JSType.java Tue Apr 01 11:44:05 2014 -0700 79.3 @@ -36,6 +36,7 @@ 79.4 import jdk.internal.dynalink.beans.StaticClass; 79.5 import jdk.nashorn.api.scripting.JSObject; 79.6 import jdk.nashorn.internal.codegen.CompilerConstants.Call; 79.7 +import jdk.nashorn.internal.objects.Global; 79.8 import jdk.nashorn.internal.parser.Lexer; 79.9 import jdk.nashorn.internal.runtime.arrays.ArrayLikeIterator; 79.10 import jdk.nashorn.internal.runtime.linker.Bootstrap; 79.11 @@ -852,7 +853,7 @@ 79.12 * @return the wrapped object 79.13 */ 79.14 public static Object toScriptObject(final Object obj) { 79.15 - return toScriptObject(Context.getGlobalTrusted(), obj); 79.16 + return toScriptObject(Context.getGlobal(), obj); 79.17 } 79.18 79.19 /** 79.20 @@ -865,7 +866,7 @@ 79.21 * 79.22 * @return the wrapped object 79.23 */ 79.24 - public static Object toScriptObject(final ScriptObject global, final Object obj) { 79.25 + public static Object toScriptObject(final Global global, final Object obj) { 79.26 if (nullOrUndefined(obj)) { 79.27 throw typeError(global, "not.an.object", ScriptRuntime.safeToString(obj)); 79.28 } 79.29 @@ -874,7 +875,7 @@ 79.30 return obj; 79.31 } 79.32 79.33 - return ((GlobalObject)global).wrapAsObject(obj); 79.34 + return global.wrapAsObject(obj); 79.35 } 79.36 79.37 /** 79.38 @@ -984,7 +985,7 @@ 79.39 if (obj instanceof ScriptObject) { 79.40 if (safe) { 79.41 final ScriptObject sobj = (ScriptObject)obj; 79.42 - final GlobalObject gobj = (GlobalObject)Context.getGlobalTrusted(); 79.43 + final Global gobj = Context.getGlobal(); 79.44 return gobj.isError(sobj) ? 79.45 ECMAException.safeToString(sobj) : 79.46 sobj.safeToString();
80.1 --- a/src/jdk/nashorn/internal/runtime/ListAdapter.java Wed Mar 26 12:01:34 2014 -0700 80.2 +++ b/src/jdk/nashorn/internal/runtime/ListAdapter.java Tue Apr 01 11:44:05 2014 -0700 80.3 @@ -34,6 +34,7 @@ 80.4 import java.util.concurrent.Callable; 80.5 import jdk.nashorn.api.scripting.JSObject; 80.6 import jdk.nashorn.api.scripting.ScriptObjectMirror; 80.7 +import jdk.nashorn.internal.objects.Global; 80.8 import jdk.nashorn.internal.runtime.linker.Bootstrap; 80.9 import jdk.nashorn.internal.runtime.linker.InvokeByName; 80.10 80.11 @@ -54,7 +55,7 @@ 80.12 // These add to the back and front of the list 80.13 private static final Object PUSH = new Object(); 80.14 private static InvokeByName getPUSH() { 80.15 - return ((GlobalObject)Context.getGlobal()).getInvokeByName(PUSH, 80.16 + return Context.getGlobal().getInvokeByName(PUSH, 80.17 new Callable<InvokeByName>() { 80.18 @Override 80.19 public InvokeByName call() { 80.20 @@ -65,7 +66,7 @@ 80.21 80.22 private static final Object UNSHIFT = new Object(); 80.23 private static InvokeByName getUNSHIFT() { 80.24 - return ((GlobalObject)Context.getGlobal()).getInvokeByName(UNSHIFT, 80.25 + return Context.getGlobal().getInvokeByName(UNSHIFT, 80.26 new Callable<InvokeByName>() { 80.27 @Override 80.28 public InvokeByName call() { 80.29 @@ -77,7 +78,7 @@ 80.30 // These remove from the back and front of the list 80.31 private static final Object POP = new Object(); 80.32 private static InvokeByName getPOP() { 80.33 - return ((GlobalObject)Context.getGlobal()).getInvokeByName(POP, 80.34 + return Context.getGlobal().getInvokeByName(POP, 80.35 new Callable<InvokeByName>() { 80.36 @Override 80.37 public InvokeByName call() { 80.38 @@ -88,7 +89,7 @@ 80.39 80.40 private static final Object SHIFT = new Object(); 80.41 private static InvokeByName getSHIFT() { 80.42 - return ((GlobalObject)Context.getGlobal()).getInvokeByName(SHIFT, 80.43 + return Context.getGlobal().getInvokeByName(SHIFT, 80.44 new Callable<InvokeByName>() { 80.45 @Override 80.46 public InvokeByName call() { 80.47 @@ -100,7 +101,7 @@ 80.48 // These insert and remove in the middle of the list 80.49 private static final Object SPLICE_ADD = new Object(); 80.50 private static InvokeByName getSPLICE_ADD() { 80.51 - return ((GlobalObject)Context.getGlobal()).getInvokeByName(SPLICE_ADD, 80.52 + return Context.getGlobal().getInvokeByName(SPLICE_ADD, 80.53 new Callable<InvokeByName>() { 80.54 @Override 80.55 public InvokeByName call() { 80.56 @@ -111,7 +112,7 @@ 80.57 80.58 private static final Object SPLICE_REMOVE = new Object(); 80.59 private static InvokeByName getSPLICE_REMOVE() { 80.60 - return ((GlobalObject)Context.getGlobal()).getInvokeByName(SPLICE_REMOVE, 80.61 + return Context.getGlobal().getInvokeByName(SPLICE_REMOVE, 80.62 new Callable<InvokeByName>() { 80.63 @Override 80.64 public InvokeByName call() {
81.1 --- a/src/jdk/nashorn/internal/runtime/NativeJavaPackage.java Wed Mar 26 12:01:34 2014 -0700 81.2 +++ b/src/jdk/nashorn/internal/runtime/NativeJavaPackage.java Tue Apr 01 11:44:05 2014 -0700 81.3 @@ -35,7 +35,6 @@ 81.4 import jdk.internal.dynalink.support.Guards; 81.5 import jdk.nashorn.internal.lookup.MethodHandleFactory; 81.6 import jdk.nashorn.internal.lookup.MethodHandleFunctionality; 81.7 -import jdk.nashorn.internal.objects.NativeJava; 81.8 import jdk.nashorn.internal.objects.annotations.Attribute; 81.9 import jdk.nashorn.internal.objects.annotations.Function; 81.10 81.11 @@ -52,7 +51,7 @@ 81.12 * var ArrayList = java.util.ArrayList 81.13 * var list = new ArrayList 81.14 * </pre> 81.15 - * You can also use {@link NativeJava#type(Object, Object)} to access Java classes. These two statements are mostly 81.16 + * You can also use {@link jdk.nashorn.internal.objects.NativeJava#type(Object, Object)} to access Java classes. These two statements are mostly 81.17 * equivalent: 81.18 * <pre> 81.19 * var listType1 = java.util.ArrayList 81.20 @@ -198,24 +197,13 @@ 81.21 @Override 81.22 public GuardedInvocation noSuchProperty(final CallSiteDescriptor desc, final LinkRequest request) { 81.23 final String propertyName = desc.getNameToken(2); 81.24 - final String fullName = name.isEmpty() ? propertyName : name + "." + propertyName; 81.25 + createProperty(propertyName); 81.26 + return super.lookup(desc, request); 81.27 + } 81.28 81.29 - final Context context = Context.getContextTrusted(); 81.30 - 81.31 - Class<?> javaClass = null; 81.32 - try { 81.33 - javaClass = context.findClass(fullName); 81.34 - } catch (final NoClassDefFoundError | ClassNotFoundException e) { 81.35 - //ignored 81.36 - } 81.37 - 81.38 - if (javaClass == null) { 81.39 - set(propertyName, new NativeJavaPackage(fullName, getProto()), false); 81.40 - } else { 81.41 - set(propertyName, StaticClass.forClass(javaClass), false); 81.42 - } 81.43 - 81.44 - return super.lookup(desc, request); 81.45 + @Override 81.46 + protected Object invokeNoSuchProperty(final String name) { 81.47 + return createProperty(name); 81.48 } 81.49 81.50 @Override 81.51 @@ -226,4 +214,26 @@ 81.52 private static MethodHandle findOwnMH(final String name, final Class<?> rtype, final Class<?>... types) { 81.53 return MH.findStatic(MethodHandles.lookup(), NativeJavaPackage.class, name, MH.type(rtype, types)); 81.54 } 81.55 + 81.56 + private Object createProperty(final String propertyName) { 81.57 + final String fullName = name.isEmpty() ? propertyName : name + "." + propertyName; 81.58 + final Context context = Context.getContextTrusted(); 81.59 + 81.60 + Class<?> javaClass = null; 81.61 + try { 81.62 + javaClass = context.findClass(fullName); 81.63 + } catch (final NoClassDefFoundError | ClassNotFoundException e) { 81.64 + //ignored 81.65 + } 81.66 + 81.67 + final Object propertyValue; 81.68 + if (javaClass == null) { 81.69 + propertyValue = new NativeJavaPackage(fullName, getProto()); 81.70 + } else { 81.71 + propertyValue = StaticClass.forClass(javaClass); 81.72 + } 81.73 + 81.74 + set(propertyName, propertyValue, false); 81.75 + return propertyValue; 81.76 + } 81.77 }
82.1 --- a/src/jdk/nashorn/internal/runtime/ParserException.java Wed Mar 26 12:01:34 2014 -0700 82.2 +++ b/src/jdk/nashorn/internal/runtime/ParserException.java Tue Apr 01 11:44:05 2014 -0700 82.3 @@ -26,6 +26,7 @@ 82.4 package jdk.nashorn.internal.runtime; 82.5 82.6 import jdk.nashorn.api.scripting.NashornException; 82.7 +import jdk.nashorn.internal.objects.Global; 82.8 import jdk.nashorn.internal.parser.Token; 82.9 82.10 /** 82.11 @@ -110,7 +111,7 @@ 82.12 * Throw this {@code ParserException} as one of the 7 native JavaScript errors 82.13 * @param global global scope object 82.14 */ 82.15 - public void throwAsEcmaException(final ScriptObject global) { 82.16 + public void throwAsEcmaException(final Global global) { 82.17 throw ECMAErrors.asEcmaException(global, this); 82.18 } 82.19 }
83.1 --- a/src/jdk/nashorn/internal/runtime/Property.java Wed Mar 26 12:01:34 2014 -0700 83.2 +++ b/src/jdk/nashorn/internal/runtime/Property.java Tue Apr 01 11:44:05 2014 -0700 83.3 @@ -84,9 +84,13 @@ 83.4 /** Can this property be undefined? */ 83.5 public static final int CAN_BE_UNDEFINED = 1 << 8; 83.6 83.7 - /* Is this a function declaration property ? */ 83.8 + /** Is this a function declaration property ? */ 83.9 public static final int IS_FUNCTION_DECLARATION = 1 << 9; 83.10 83.11 + /** Is this property bound to a receiver? This means get/set operations will be delegated to 83.12 + * a statically defined object instead of the object passed as callsite parameter. */ 83.13 + public static final int IS_BOUND = 1 << 10; 83.14 + 83.15 /** Property key. */ 83.16 private final String key; 83.17 83.18 @@ -252,6 +256,16 @@ 83.19 } 83.20 83.21 /** 83.22 + * Is this property bound to a receiver? If this method returns {@code true} get and set operations 83.23 + * will be delegated to a statically bound object instead of the object passed as parameter. 83.24 + * 83.25 + * @return true if this is a bound property 83.26 + */ 83.27 + public boolean isBound() { 83.28 + return (flags & IS_BOUND) == IS_BOUND; 83.29 + } 83.30 + 83.31 + /** 83.32 * Does this property use any slots in the spill array described in 83.33 * {@link Property#isSpill}? In that case how many. Currently a property 83.34 * only uses max one spill slot, but this may change in future representations
84.1 --- a/src/jdk/nashorn/internal/runtime/PropertyDescriptor.java Wed Mar 26 12:01:34 2014 -0700 84.2 +++ b/src/jdk/nashorn/internal/runtime/PropertyDescriptor.java Tue Apr 01 11:44:05 2014 -0700 84.3 @@ -151,5 +151,12 @@ 84.4 * @return true if property exists in implementor 84.5 */ 84.6 public boolean has(Object key); 84.7 + 84.8 + /** 84.9 + * Check existence and compare attributes of descriptors. 84.10 + * 84.11 + * @return true if every field of this desc exists in otherDesc and has the same value. 84.12 + */ 84.13 + public boolean hasAndEquals(PropertyDescriptor otherDesc); 84.14 } 84.15
85.1 --- a/src/jdk/nashorn/internal/runtime/PropertyListener.java Wed Mar 26 12:01:34 2014 -0700 85.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 85.3 @@ -1,66 +0,0 @@ 85.4 -/* 85.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 85.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 85.7 - * 85.8 - * This code is free software; you can redistribute it and/or modify it 85.9 - * under the terms of the GNU General Public License version 2 only, as 85.10 - * published by the Free Software Foundation. Oracle designates this 85.11 - * particular file as subject to the "Classpath" exception as provided 85.12 - * by Oracle in the LICENSE file that accompanied this code. 85.13 - * 85.14 - * This code is distributed in the hope that it will be useful, but WITHOUT 85.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 85.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 85.17 - * version 2 for more details (a copy is included in the LICENSE file that 85.18 - * accompanied this code). 85.19 - * 85.20 - * You should have received a copy of the GNU General Public License version 85.21 - * 2 along with this work; if not, write to the Free Software Foundation, 85.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 85.23 - * 85.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 85.25 - * or visit www.oracle.com if you need additional information or have any 85.26 - * questions. 85.27 - */ 85.28 - 85.29 -package jdk.nashorn.internal.runtime; 85.30 - 85.31 -/** 85.32 - * Property change listener gets notified whenever properties are added/deleted/modified. 85.33 - */ 85.34 -public interface PropertyListener { 85.35 - /** 85.36 - * A new property is being added. 85.37 - * 85.38 - * @param object The ScriptObject to which property was added. 85.39 - * @param prop The new Property added. 85.40 - */ 85.41 - public void propertyAdded(ScriptObject object, Property prop); 85.42 - 85.43 - /** 85.44 - * An existing property is being deleted. 85.45 - * 85.46 - * @param object The ScriptObject whose property is being deleted. 85.47 - * @param prop The property being deleted. 85.48 - */ 85.49 - public void propertyDeleted(ScriptObject object, Property prop); 85.50 - 85.51 - /** 85.52 - * An existing Property is being replaced with a new Property. 85.53 - * 85.54 - * @param object The ScriptObject whose property is being modified. 85.55 - * @param oldProp The old property that is being replaced. 85.56 - * @param newProp The new property that replaces the old property. 85.57 - * 85.58 - */ 85.59 - public void propertyModified(ScriptObject object, Property oldProp, Property newProp); 85.60 - 85.61 - /** 85.62 - * Given object's __proto__ has changed. 85.63 - * 85.64 - * @param object object whose __proto__ has changed. 85.65 - * @param oldProto old __proto__ 85.66 - * @param newProto new __proto__ 85.67 - */ 85.68 - public void protoChanged(ScriptObject object, ScriptObject oldProto, ScriptObject newProto); 85.69 -}
86.1 --- a/src/jdk/nashorn/internal/runtime/PropertyListenerManager.java Wed Mar 26 12:01:34 2014 -0700 86.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 86.3 @@ -1,179 +0,0 @@ 86.4 -/* 86.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 86.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 86.7 - * 86.8 - * This code is free software; you can redistribute it and/or modify it 86.9 - * under the terms of the GNU General Public License version 2 only, as 86.10 - * published by the Free Software Foundation. Oracle designates this 86.11 - * particular file as subject to the "Classpath" exception as provided 86.12 - * by Oracle in the LICENSE file that accompanied this code. 86.13 - * 86.14 - * This code is distributed in the hope that it will be useful, but WITHOUT 86.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 86.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 86.17 - * version 2 for more details (a copy is included in the LICENSE file that 86.18 - * accompanied this code). 86.19 - * 86.20 - * You should have received a copy of the GNU General Public License version 86.21 - * 2 along with this work; if not, write to the Free Software Foundation, 86.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 86.23 - * 86.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 86.25 - * or visit www.oracle.com if you need additional information or have any 86.26 - * questions. 86.27 - */ 86.28 - 86.29 -package jdk.nashorn.internal.runtime; 86.30 - 86.31 -import java.util.Map; 86.32 -import java.util.WeakHashMap; 86.33 - 86.34 -/** 86.35 - * Helper class to manage property listeners and notification. 86.36 - */ 86.37 -public class PropertyListenerManager implements PropertyListener { 86.38 - PropertyListenerManager() {} 86.39 - 86.40 - /** property listeners for this object. */ 86.41 - private Map<PropertyListener,Boolean> listeners; 86.42 - 86.43 - // These counters are updated in debug mode 86.44 - private static int listenersAdded; 86.45 - private static int listenersRemoved; 86.46 - 86.47 - /** 86.48 - * Return aggregate listeners added to all PropertyListenerManagers 86.49 - * @return the listenersAdded 86.50 - */ 86.51 - public static int getListenersAdded() { 86.52 - return listenersAdded; 86.53 - } 86.54 - 86.55 - /** 86.56 - * Return aggregate listeners removed from all PropertyListenerManagers 86.57 - * @return the listenersRemoved 86.58 - */ 86.59 - public static int getListenersRemoved() { 86.60 - return listenersRemoved; 86.61 - } 86.62 - 86.63 - /** 86.64 - * Return listeners added to this PropertyListenerManager. 86.65 - * @return the listener count 86.66 - */ 86.67 - public final int getListenerCount() { 86.68 - return listeners != null? listeners.size() : 0; 86.69 - } 86.70 - 86.71 - // Property listener management methods 86.72 - 86.73 - /** 86.74 - * Add a property listener to this object. 86.75 - * 86.76 - * @param listener The property listener that is added. 86.77 - */ 86.78 - public synchronized final void addPropertyListener(final PropertyListener listener) { 86.79 - if (listeners == null) { 86.80 - listeners = new WeakHashMap<>(); 86.81 - } 86.82 - 86.83 - if (Context.DEBUG) { 86.84 - listenersAdded++; 86.85 - } 86.86 - listeners.put(listener, Boolean.TRUE); 86.87 - } 86.88 - 86.89 - /** 86.90 - * Remove a property listener from this object. 86.91 - * 86.92 - * @param listener The property listener that is removed. 86.93 - */ 86.94 - public synchronized final void removePropertyListener(final PropertyListener listener) { 86.95 - if (listeners != null) { 86.96 - if (Context.DEBUG) { 86.97 - listenersRemoved++; 86.98 - } 86.99 - listeners.remove(listener); 86.100 - } 86.101 - } 86.102 - 86.103 - /** 86.104 - * This method can be called to notify property addition to this object's listeners. 86.105 - * 86.106 - * @param object The ScriptObject to which property was added. 86.107 - * @param prop The property being added. 86.108 - */ 86.109 - protected synchronized final void notifyPropertyAdded(final ScriptObject object, final Property prop) { 86.110 - if (listeners != null) { 86.111 - for (PropertyListener listener : listeners.keySet()) { 86.112 - listener.propertyAdded(object, prop); 86.113 - } 86.114 - } 86.115 - } 86.116 - 86.117 - /** 86.118 - * This method can be called to notify property deletion to this object's listeners. 86.119 - * 86.120 - * @param object The ScriptObject from which property was deleted. 86.121 - * @param prop The property being deleted. 86.122 - */ 86.123 - protected synchronized final void notifyPropertyDeleted(final ScriptObject object, final Property prop) { 86.124 - if (listeners != null) { 86.125 - for (PropertyListener listener : listeners.keySet()) { 86.126 - listener.propertyDeleted(object, prop); 86.127 - } 86.128 - } 86.129 - } 86.130 - 86.131 - /** 86.132 - * This method can be called to notify property modification to this object's listeners. 86.133 - * 86.134 - * @param object The ScriptObject to which property was modified. 86.135 - * @param oldProp The old property being replaced. 86.136 - * @param newProp The new property that replaces the old property. 86.137 - */ 86.138 - protected synchronized final void notifyPropertyModified(final ScriptObject object, final Property oldProp, final Property newProp) { 86.139 - if (listeners != null) { 86.140 - for (PropertyListener listener : listeners.keySet()) { 86.141 - listener.propertyModified(object, oldProp, newProp); 86.142 - } 86.143 - } 86.144 - } 86.145 - 86.146 - /** 86.147 - * This method can be called to notify __proto__ modification to this object's listeners. 86.148 - * 86.149 - * @param object The ScriptObject whose __proto__ was changed. 86.150 - * @param oldProto old __proto__ 86.151 - * @param newProto new __proto__ 86.152 - */ 86.153 - protected synchronized final void notifyProtoChanged(final ScriptObject object, final ScriptObject oldProto, final ScriptObject newProto) { 86.154 - if (listeners != null) { 86.155 - for (PropertyListener listener : listeners.keySet()) { 86.156 - listener.protoChanged(object, oldProto, newProto); 86.157 - } 86.158 - } 86.159 - } 86.160 - 86.161 - // PropertyListener methods 86.162 - 86.163 - @Override 86.164 - public final void propertyAdded(final ScriptObject object, final Property prop) { 86.165 - notifyPropertyAdded(object, prop); 86.166 - } 86.167 - 86.168 - @Override 86.169 - public final void propertyDeleted(final ScriptObject object, final Property prop) { 86.170 - notifyPropertyDeleted(object, prop); 86.171 - } 86.172 - 86.173 - @Override 86.174 - public final void propertyModified(final ScriptObject object, final Property oldProp, final Property newProp) { 86.175 - notifyPropertyModified(object, oldProp, newProp); 86.176 - } 86.177 - 86.178 - @Override 86.179 - public final void protoChanged(final ScriptObject object, final ScriptObject oldProto, final ScriptObject newProto) { 86.180 - notifyProtoChanged(object, oldProto, newProto); 86.181 - } 86.182 -}
87.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 87.2 +++ b/src/jdk/nashorn/internal/runtime/PropertyListeners.java Tue Apr 01 11:44:05 2014 -0700 87.3 @@ -0,0 +1,222 @@ 87.4 +/* 87.5 + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. 87.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 87.7 + * 87.8 + * This code is free software; you can redistribute it and/or modify it 87.9 + * under the terms of the GNU General Public License version 2 only, as 87.10 + * published by the Free Software Foundation. Oracle designates this 87.11 + * particular file as subject to the "Classpath" exception as provided 87.12 + * by Oracle in the LICENSE file that accompanied this code. 87.13 + * 87.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 87.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 87.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 87.17 + * version 2 for more details (a copy is included in the LICENSE file that 87.18 + * accompanied this code). 87.19 + * 87.20 + * You should have received a copy of the GNU General Public License version 87.21 + * 2 along with this work; if not, write to the Free Software Foundation, 87.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 87.23 + * 87.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 87.25 + * or visit www.oracle.com if you need additional information or have any 87.26 + * questions. 87.27 + */ 87.28 + 87.29 +package jdk.nashorn.internal.runtime; 87.30 + 87.31 +import java.util.Map; 87.32 +import java.util.Set; 87.33 +import java.util.WeakHashMap; 87.34 + 87.35 +/** 87.36 + * Helper class to manage property listeners and notification. 87.37 + */ 87.38 +public class PropertyListeners { 87.39 + 87.40 + private Map<String, WeakPropertyMapSet> listeners; 87.41 + 87.42 + // These counters are updated in debug mode 87.43 + private static int listenersAdded; 87.44 + private static int listenersRemoved; 87.45 + 87.46 + /** 87.47 + * Copy constructor 87.48 + * @param listener listener to copy 87.49 + */ 87.50 + PropertyListeners(final PropertyListeners listener) { 87.51 + if (listener != null && listener.listeners != null) { 87.52 + this.listeners = new WeakHashMap<>(listener.listeners); 87.53 + } 87.54 + } 87.55 + 87.56 + /** 87.57 + * Return aggregate listeners added to all PropertyListenerManagers 87.58 + * @return the listenersAdded 87.59 + */ 87.60 + public static int getListenersAdded() { 87.61 + return listenersAdded; 87.62 + } 87.63 + 87.64 + /** 87.65 + * Return aggregate listeners removed from all PropertyListenerManagers 87.66 + * @return the listenersRemoved 87.67 + */ 87.68 + public static int getListenersRemoved() { 87.69 + return listenersRemoved; 87.70 + } 87.71 + 87.72 + /** 87.73 + * Return listeners added to this ScriptObject. 87.74 + * @param obj the object 87.75 + * @return the listener count 87.76 + */ 87.77 + public static int getListenerCount(final ScriptObject obj) { 87.78 + final PropertyListeners propertyListeners = obj.getMap().getListeners(); 87.79 + if (propertyListeners != null) { 87.80 + return propertyListeners.listeners == null ? 0 : propertyListeners.listeners.size(); 87.81 + } 87.82 + return 0; 87.83 + } 87.84 + 87.85 + // Property listener management methods 87.86 + 87.87 + /** 87.88 + * Add {@code propertyMap} as property listener to {@code listeners} using key {@code key} by 87.89 + * creating and returning a new {@code PropertyListeners} instance. 87.90 + * 87.91 + * @param listeners the original property listeners instance, may be null 87.92 + * @param key the property key 87.93 + * @param propertyMap the property map 87.94 + * @return the new property map 87.95 + */ 87.96 + public static PropertyListeners addListener(final PropertyListeners listeners, final String key, final PropertyMap propertyMap) { 87.97 + final PropertyListeners newListeners; 87.98 + if (listeners == null || !listeners.containsListener(key, propertyMap)) { 87.99 + newListeners = new PropertyListeners(listeners); 87.100 + newListeners.addListener(key, propertyMap); 87.101 + return newListeners; 87.102 + } 87.103 + return listeners; 87.104 + } 87.105 + 87.106 + /** 87.107 + * Checks whether {@code propertyMap} is registered as listener with {@code key}. 87.108 + * 87.109 + * @param key the property key 87.110 + * @param propertyMap the property map 87.111 + * @return true if property map is registered with property key 87.112 + */ 87.113 + synchronized boolean containsListener(final String key, final PropertyMap propertyMap) { 87.114 + if (listeners == null) { 87.115 + return false; 87.116 + } 87.117 + WeakPropertyMapSet set = listeners.get(key); 87.118 + return set != null && set.contains(propertyMap); 87.119 + } 87.120 + 87.121 + /** 87.122 + * Add a property listener to this object. 87.123 + * 87.124 + * @param propertyMap The property listener that is added. 87.125 + */ 87.126 + synchronized final void addListener(final String key, final PropertyMap propertyMap) { 87.127 + if (Context.DEBUG) { 87.128 + listenersAdded++; 87.129 + } 87.130 + if (listeners == null) { 87.131 + listeners = new WeakHashMap<>(); 87.132 + } 87.133 + 87.134 + WeakPropertyMapSet set = listeners.get(key); 87.135 + if (set == null) { 87.136 + set = new WeakPropertyMapSet(); 87.137 + listeners.put(key, set); 87.138 + } 87.139 + if (!set.contains(propertyMap)) { 87.140 + set.add(propertyMap); 87.141 + } 87.142 + } 87.143 + 87.144 + /** 87.145 + * A new property is being added. 87.146 + * 87.147 + * @param prop The new Property added. 87.148 + */ 87.149 + public synchronized void propertyAdded(final Property prop) { 87.150 + if (listeners != null) { 87.151 + WeakPropertyMapSet set = listeners.get(prop.getKey()); 87.152 + if (set != null) { 87.153 + for (PropertyMap propertyMap : set.elements()) { 87.154 + propertyMap.propertyAdded(prop); 87.155 + } 87.156 + listeners.remove(prop.getKey()); 87.157 + } 87.158 + } 87.159 + } 87.160 + 87.161 + /** 87.162 + * An existing property is being deleted. 87.163 + * 87.164 + * @param prop The property being deleted. 87.165 + */ 87.166 + public synchronized void propertyDeleted(final Property prop) { 87.167 + if (listeners != null) { 87.168 + WeakPropertyMapSet set = listeners.get(prop.getKey()); 87.169 + if (set != null) { 87.170 + for (PropertyMap propertyMap : set.elements()) { 87.171 + propertyMap.propertyDeleted(prop); 87.172 + } 87.173 + listeners.remove(prop.getKey()); 87.174 + } 87.175 + } 87.176 + } 87.177 + 87.178 + /** 87.179 + * An existing Property is being replaced with a new Property. 87.180 + * 87.181 + * @param oldProp The old property that is being replaced. 87.182 + * @param newProp The new property that replaces the old property. 87.183 + * 87.184 + */ 87.185 + public synchronized void propertyModified(final Property oldProp, final Property newProp) { 87.186 + if (listeners != null) { 87.187 + WeakPropertyMapSet set = listeners.get(oldProp.getKey()); 87.188 + if (set != null) { 87.189 + for (PropertyMap propertyMap : set.elements()) { 87.190 + propertyMap.propertyModified(oldProp, newProp); 87.191 + } 87.192 + listeners.remove(oldProp.getKey()); 87.193 + } 87.194 + } 87.195 + } 87.196 + 87.197 + public synchronized void protoChanged() { 87.198 + if (listeners != null) { 87.199 + for (WeakPropertyMapSet set : listeners.values()) { 87.200 + for (PropertyMap propertyMap : set.elements()) { 87.201 + propertyMap.protoChanged(); 87.202 + } 87.203 + } 87.204 + listeners.clear(); 87.205 + } 87.206 + } 87.207 + 87.208 + private static class WeakPropertyMapSet { 87.209 + 87.210 + private WeakHashMap<PropertyMap, Boolean> map = new WeakHashMap<>(); 87.211 + 87.212 + void add(final PropertyMap propertyMap) { 87.213 + map.put(propertyMap, Boolean.TRUE); 87.214 + } 87.215 + 87.216 + boolean contains(final PropertyMap propertyMap) { 87.217 + return map.containsKey(propertyMap); 87.218 + } 87.219 + 87.220 + Set<PropertyMap> elements() { 87.221 + return map.keySet(); 87.222 + } 87.223 + 87.224 + } 87.225 +}
88.1 --- a/src/jdk/nashorn/internal/runtime/PropertyMap.java Wed Mar 26 12:01:34 2014 -0700 88.2 +++ b/src/jdk/nashorn/internal/runtime/PropertyMap.java Tue Apr 01 11:44:05 2014 -0700 88.3 @@ -30,13 +30,11 @@ 88.4 import static jdk.nashorn.internal.runtime.arrays.ArrayIndex.isValidArrayIndex; 88.5 88.6 import java.lang.invoke.SwitchPoint; 88.7 -import java.lang.ref.WeakReference; 88.8 +import java.lang.ref.SoftReference; 88.9 import java.util.Arrays; 88.10 import java.util.Collection; 88.11 import java.util.HashMap; 88.12 import java.util.Iterator; 88.13 -import java.util.LinkedHashMap; 88.14 -import java.util.Map; 88.15 import java.util.NoSuchElementException; 88.16 import java.util.WeakHashMap; 88.17 88.18 @@ -49,17 +47,11 @@ 88.19 * All property maps are immutable. If a property is added, modified or removed, the mutator 88.20 * will return a new map. 88.21 */ 88.22 -public final class PropertyMap implements Iterable<Object>, PropertyListener { 88.23 +public final class PropertyMap implements Iterable<Object> { 88.24 /** Used for non extensible PropertyMaps, negative logic as the normal case is extensible. See {@link ScriptObject#preventExtensions()} */ 88.25 public static final int NOT_EXTENSIBLE = 0b0000_0001; 88.26 /** Does this map contain valid array keys? */ 88.27 public static final int CONTAINS_ARRAY_KEYS = 0b0000_0010; 88.28 - /** This mask is used to preserve certain flags when cloning the PropertyMap. Others should not be copied */ 88.29 - private static final int CLONEABLE_FLAGS_MASK = 0b0000_1111; 88.30 - /** Has a listener been added to this property map. This flag is not copied when cloning a map. See {@link PropertyListener} */ 88.31 - public static final int IS_LISTENER_ADDED = 0b0001_0000; 88.32 - /** Is this process wide "shared" map?. This flag is not copied when cloning a map */ 88.33 - public static final int IS_SHARED = 0b0010_0000; 88.34 88.35 /** Map status flags. */ 88.36 private int flags; 88.37 @@ -77,16 +69,16 @@ 88.38 private int spillLength; 88.39 88.40 /** {@link SwitchPoint}s for gets on inherited properties. */ 88.41 - private Map<String, SwitchPoint> protoGetSwitches; 88.42 + private HashMap<String, SwitchPoint> protoGetSwitches; 88.43 88.44 /** History of maps, used to limit map duplication. */ 88.45 - private HashMap<Property, PropertyMap> history; 88.46 + private WeakHashMap<Property, SoftReference<PropertyMap>> history; 88.47 88.48 /** History of prototypes, used to limit map duplication. */ 88.49 - private WeakHashMap<ScriptObject, WeakReference<PropertyMap>> protoHistory; 88.50 + private WeakHashMap<PropertyMap, SoftReference<PropertyMap>> protoHistory; 88.51 88.52 - /** Cache for hashCode */ 88.53 - private int hashCode; 88.54 + /** property listeners */ 88.55 + private PropertyListeners listeners; 88.56 88.57 /** 88.58 * Constructor. 88.59 @@ -119,10 +111,12 @@ 88.60 */ 88.61 private PropertyMap(final PropertyMap propertyMap, final PropertyHashMap properties) { 88.62 this.properties = properties; 88.63 - this.flags = propertyMap.getClonedFlags(); 88.64 + this.flags = propertyMap.flags; 88.65 this.spillLength = propertyMap.spillLength; 88.66 this.fieldCount = propertyMap.fieldCount; 88.67 this.fieldMaximum = propertyMap.fieldMaximum; 88.68 + // We inherit the parent property listeners instance. It will be cloned when a new listener is added. 88.69 + this.listeners = propertyMap.listeners; 88.70 88.71 if (Context.DEBUG) { 88.72 count++; 88.73 @@ -203,35 +197,92 @@ 88.74 } 88.75 88.76 /** 88.77 + * Get the listeners of this map, or null if none exists 88.78 + * 88.79 + * @return the listeners 88.80 + */ 88.81 + public PropertyListeners getListeners() { 88.82 + return listeners; 88.83 + } 88.84 + 88.85 + /** 88.86 + * Add {@code listenerMap} as a listener to this property map for the given {@code key}. 88.87 + * 88.88 + * @param key the property name 88.89 + * @param listenerMap the listener map 88.90 + */ 88.91 + public void addListener(final String key, final PropertyMap listenerMap) { 88.92 + if (listenerMap != this) { 88.93 + // We need to clone listener instance when adding a new listener since we share 88.94 + // the listeners instance with our parent maps that don't need to see the new listener. 88.95 + listeners = PropertyListeners.addListener(listeners, key, listenerMap); 88.96 + } 88.97 + } 88.98 + 88.99 + /** 88.100 + * A new property is being added. 88.101 + * 88.102 + * @param property The new Property added. 88.103 + */ 88.104 + public void propertyAdded(final Property property) { 88.105 + invalidateProtoGetSwitchPoint(property); 88.106 + if (listeners != null) { 88.107 + listeners.propertyAdded(property); 88.108 + } 88.109 + } 88.110 + 88.111 + /** 88.112 + * An existing property is being deleted. 88.113 + * 88.114 + * @param property The property being deleted. 88.115 + */ 88.116 + public void propertyDeleted(final Property property) { 88.117 + invalidateProtoGetSwitchPoint(property); 88.118 + if (listeners != null) { 88.119 + listeners.propertyDeleted(property); 88.120 + } 88.121 + } 88.122 + 88.123 + /** 88.124 + * An existing property is being redefined. 88.125 + * 88.126 + * @param oldProperty The old property 88.127 + * @param newProperty The new property 88.128 + */ 88.129 + public void propertyModified(final Property oldProperty, final Property newProperty) { 88.130 + invalidateProtoGetSwitchPoint(oldProperty); 88.131 + if (listeners != null) { 88.132 + listeners.propertyModified(oldProperty, newProperty); 88.133 + } 88.134 + } 88.135 + 88.136 + /** 88.137 + * The prototype of an object associated with this {@link PropertyMap} is changed. 88.138 + */ 88.139 + public void protoChanged() { 88.140 + invalidateAllProtoGetSwitchPoints(); 88.141 + if (listeners != null) { 88.142 + listeners.protoChanged(); 88.143 + } 88.144 + } 88.145 + 88.146 + /** 88.147 * Return a SwitchPoint used to track changes of a property in a prototype. 88.148 * 88.149 - * @param proto Object prototype. 88.150 - * @param key {@link Property} key. 88.151 - * 88.152 + * @param key Property key. 88.153 * @return A shared {@link SwitchPoint} for the property. 88.154 */ 88.155 - public SwitchPoint getProtoGetSwitchPoint(final ScriptObject proto, final String key) { 88.156 - assert !isShared() : "proto SwitchPoint from a shared PropertyMap"; 88.157 - 88.158 - if (proto == null) { 88.159 - return null; 88.160 + public synchronized SwitchPoint getSwitchPoint(final String key) { 88.161 + if (protoGetSwitches == null) { 88.162 + protoGetSwitches = new HashMap<>(); 88.163 } 88.164 88.165 - if (protoGetSwitches == null) { 88.166 - protoGetSwitches = new HashMap<>(); 88.167 - if (! isListenerAdded()) { 88.168 - proto.addPropertyListener(this); 88.169 - setIsListenerAdded(); 88.170 - } 88.171 + SwitchPoint switchPoint = protoGetSwitches.get(key); 88.172 + if (switchPoint == null) { 88.173 + switchPoint = new SwitchPoint(); 88.174 + protoGetSwitches.put(key, switchPoint); 88.175 } 88.176 88.177 - if (protoGetSwitches.containsKey(key)) { 88.178 - return protoGetSwitches.get(key); 88.179 - } 88.180 - 88.181 - final SwitchPoint switchPoint = new SwitchPoint(); 88.182 - protoGetSwitches.put(key, switchPoint); 88.183 - 88.184 return switchPoint; 88.185 } 88.186 88.187 @@ -240,14 +291,13 @@ 88.188 * 88.189 * @param property {@link Property} to invalidate. 88.190 */ 88.191 - private void invalidateProtoGetSwitchPoint(final Property property) { 88.192 - assert !isShared() : "proto invalidation on a shared PropertyMap"; 88.193 + synchronized void invalidateProtoGetSwitchPoint(final Property property) { 88.194 + if (protoGetSwitches != null) { 88.195 88.196 - if (protoGetSwitches != null) { 88.197 final String key = property.getKey(); 88.198 final SwitchPoint sp = protoGetSwitches.get(key); 88.199 if (sp != null) { 88.200 - protoGetSwitches.put(key, new SwitchPoint()); 88.201 + protoGetSwitches.remove(key); 88.202 if (Context.DEBUG) { 88.203 protoInvalidations++; 88.204 } 88.205 @@ -257,14 +307,15 @@ 88.206 } 88.207 88.208 /** 88.209 - * Indicate that proto itself has changed in hierachy somewhere. 88.210 + * Indicate that proto itself has changed in hierarchy somewhere. 88.211 */ 88.212 - private void invalidateAllProtoGetSwitchPoints() { 88.213 - assert !isShared() : "proto invalidation on a shared PropertyMap"; 88.214 - 88.215 - if (protoGetSwitches != null) { 88.216 - final Collection<SwitchPoint> sws = protoGetSwitches.values(); 88.217 - SwitchPoint.invalidateAll(sws.toArray(new SwitchPoint[sws.size()])); 88.218 + synchronized void invalidateAllProtoGetSwitchPoints() { 88.219 + if (protoGetSwitches != null && !protoGetSwitches.isEmpty()) { 88.220 + if (Context.DEBUG) { 88.221 + protoInvalidations += protoGetSwitches.size(); 88.222 + } 88.223 + SwitchPoint.invalidateAll(protoGetSwitches.values().toArray(new SwitchPoint[protoGetSwitches.values().size()])); 88.224 + protoGetSwitches.clear(); 88.225 } 88.226 } 88.227 88.228 @@ -279,7 +330,33 @@ 88.229 * @return New {@link PropertyMap} with {@link Property} added. 88.230 */ 88.231 PropertyMap addPropertyBind(final AccessorProperty property, final Object bindTo) { 88.232 - return addProperty(new AccessorProperty(property, bindTo)); 88.233 + // No need to store bound property in the history as bound properties can't be reused. 88.234 + return addPropertyNoHistory(new AccessorProperty(property, bindTo)); 88.235 + } 88.236 + 88.237 + /** 88.238 + * Add a property to the map without adding it to the history. This should be used for properties that 88.239 + * can't be shared such as bound properties, or properties that are expected to be added only once. 88.240 + * 88.241 + * @param property {@link Property} being added. 88.242 + * @return New {@link PropertyMap} with {@link Property} added. 88.243 + */ 88.244 + public PropertyMap addPropertyNoHistory(final Property property) { 88.245 + if (listeners != null) { 88.246 + listeners.propertyAdded(property); 88.247 + } 88.248 + final PropertyHashMap newProperties = properties.immutableAdd(property); 88.249 + final PropertyMap newMap = new PropertyMap(this, newProperties); 88.250 + 88.251 + if(!property.isSpill()) { 88.252 + newMap.fieldCount = Math.max(newMap.fieldCount, property.getSlot() + 1); 88.253 + } 88.254 + if (isValidArrayIndex(getArrayIndex(property.getKey()))) { 88.255 + newMap.setContainsArrayKeys(); 88.256 + } 88.257 + 88.258 + newMap.spillLength += property.getSpillCount(); 88.259 + return newMap; 88.260 } 88.261 88.262 /** 88.263 @@ -290,6 +367,9 @@ 88.264 * @return New {@link PropertyMap} with {@link Property} added. 88.265 */ 88.266 public PropertyMap addProperty(final Property property) { 88.267 + if (listeners != null) { 88.268 + listeners.propertyAdded(property); 88.269 + } 88.270 PropertyMap newMap = checkHistory(property); 88.271 88.272 if (newMap == null) { 88.273 @@ -318,6 +398,9 @@ 88.274 * @return New {@link PropertyMap} with {@link Property} removed or {@code null} if not found. 88.275 */ 88.276 public PropertyMap deleteProperty(final Property property) { 88.277 + if (listeners != null) { 88.278 + listeners.propertyDeleted(property); 88.279 + } 88.280 PropertyMap newMap = checkHistory(property); 88.281 final String key = property.getKey(); 88.282 88.283 @@ -339,6 +422,9 @@ 88.284 * @return New {@link PropertyMap} with {@link Property} replaced. 88.285 */ 88.286 PropertyMap replaceProperty(final Property oldProperty, final Property newProperty) { 88.287 + if (listeners != null) { 88.288 + listeners.propertyModified(oldProperty, newProperty); 88.289 + } 88.290 // Add replaces existing property. 88.291 final PropertyHashMap newProperties = properties.immutableAdd(newProperty); 88.292 final PropertyMap newMap = new PropertyMap(this, newProperties); 88.293 @@ -363,7 +449,7 @@ 88.294 (oldProperty instanceof AccessorProperty && 88.295 newProperty instanceof UserAccessorProperty) : "arbitrary replaceProperty attempted"; 88.296 88.297 - newMap.flags = getClonedFlags(); 88.298 + newMap.flags = flags; 88.299 88.300 /* 88.301 * spillLength remains same in case (1) and (2) because of slot reuse. Only for case (3), we need 88.302 @@ -491,28 +577,6 @@ 88.303 } 88.304 88.305 /** 88.306 - * Make this property map 'shared' one. Shared property map instances are 88.307 - * process wide singleton objects. A shaped map should never be added as a listener 88.308 - * to a proto object. Nor it should have history or proto history. A shared map 88.309 - * is just a template that is meant to be duplicated before use. All nasgen initialized 88.310 - * property maps are shared. 88.311 - * 88.312 - * @return this map after making it as shared 88.313 - */ 88.314 - public PropertyMap setIsShared() { 88.315 - assert !isListenerAdded() : "making PropertyMap shared after listener added"; 88.316 - assert protoHistory == null : "making PropertyMap shared after associating a proto with it"; 88.317 - if (Context.DEBUG) { 88.318 - sharedCount++; 88.319 - } 88.320 - 88.321 - flags |= IS_SHARED; 88.322 - // clear any history on this PropertyMap, won't be used. 88.323 - history = null; 88.324 - return this; 88.325 - } 88.326 - 88.327 - /** 88.328 * Check for any configurable properties. 88.329 * 88.330 * @return {@code true} if any configurable. 88.331 @@ -551,14 +615,14 @@ 88.332 /** 88.333 * Check prototype history for an existing property map with specified prototype. 88.334 * 88.335 - * @param newProto New prototype object. 88.336 + * @param parentMap New prototype object. 88.337 * 88.338 * @return Existing {@link PropertyMap} or {@code null} if not found. 88.339 */ 88.340 - private PropertyMap checkProtoHistory(final ScriptObject newProto) { 88.341 + private PropertyMap checkProtoHistory(final PropertyMap parentMap) { 88.342 final PropertyMap cachedMap; 88.343 if (protoHistory != null) { 88.344 - final WeakReference<PropertyMap> weakMap = protoHistory.get(newProto); 88.345 + final SoftReference<PropertyMap> weakMap = protoHistory.get(parentMap); 88.346 cachedMap = (weakMap != null ? weakMap.get() : null); 88.347 } else { 88.348 cachedMap = null; 88.349 @@ -574,17 +638,15 @@ 88.350 /** 88.351 * Add a map to the prototype history. 88.352 * 88.353 - * @param newProto Prototype to add (key.) 88.354 + * @param parentMap Prototype to add (key.) 88.355 * @param newMap {@link PropertyMap} associated with prototype. 88.356 */ 88.357 - private void addToProtoHistory(final ScriptObject newProto, final PropertyMap newMap) { 88.358 - assert !isShared() : "proto history modified on a shared PropertyMap"; 88.359 - 88.360 + private void addToProtoHistory(final PropertyMap parentMap, final PropertyMap newMap) { 88.361 if (protoHistory == null) { 88.362 protoHistory = new WeakHashMap<>(); 88.363 } 88.364 88.365 - protoHistory.put(newProto, new WeakReference<>(newMap)); 88.366 + protoHistory.put(parentMap, new SoftReference<>(newMap)); 88.367 } 88.368 88.369 /** 88.370 @@ -594,14 +656,12 @@ 88.371 * @param newMap Modified {@link PropertyMap}. 88.372 */ 88.373 private void addToHistory(final Property property, final PropertyMap newMap) { 88.374 - assert !isShared() : "history modified on a shared PropertyMap"; 88.375 - 88.376 if (!properties.isEmpty()) { 88.377 if (history == null) { 88.378 - history = new LinkedHashMap<>(); 88.379 + history = new WeakHashMap<>(); 88.380 } 88.381 88.382 - history.put(property, newMap); 88.383 + history.put(property, new SoftReference<>(newMap)); 88.384 } 88.385 } 88.386 88.387 @@ -613,8 +673,10 @@ 88.388 * @return Existing map or {@code null} if not found. 88.389 */ 88.390 private PropertyMap checkHistory(final Property property) { 88.391 + 88.392 if (history != null) { 88.393 - PropertyMap historicMap = history.get(property); 88.394 + SoftReference<PropertyMap> ref = history.get(property); 88.395 + final PropertyMap historicMap = ref == null ? null : ref.get(); 88.396 88.397 if (historicMap != null) { 88.398 if (Context.DEBUG) { 88.399 @@ -628,54 +690,6 @@ 88.400 return null; 88.401 } 88.402 88.403 - /** 88.404 - * Calculate the hash code for the map. 88.405 - * 88.406 - * @return Computed hash code. 88.407 - */ 88.408 - private int computeHashCode() { 88.409 - int hash = 0; 88.410 - 88.411 - for (final Property property : getProperties()) { 88.412 - hash = hash << 7 ^ hash >> 7; 88.413 - hash ^= property.hashCode(); 88.414 - } 88.415 - 88.416 - return hash; 88.417 - } 88.418 - 88.419 - @Override 88.420 - public int hashCode() { 88.421 - if (hashCode == 0 && !properties.isEmpty()) { 88.422 - hashCode = computeHashCode(); 88.423 - } 88.424 - return hashCode; 88.425 - } 88.426 - 88.427 - @Override 88.428 - public boolean equals(final Object other) { 88.429 - if (!(other instanceof PropertyMap)) { 88.430 - return false; 88.431 - } 88.432 - 88.433 - final PropertyMap otherMap = (PropertyMap)other; 88.434 - 88.435 - if (properties.size() != otherMap.properties.size()) { 88.436 - return false; 88.437 - } 88.438 - 88.439 - final Iterator<Property> iter = properties.values().iterator(); 88.440 - final Iterator<Property> otherIter = otherMap.properties.values().iterator(); 88.441 - 88.442 - while (iter.hasNext() && otherIter.hasNext()) { 88.443 - if (!iter.next().equals(otherIter.next())) { 88.444 - return false; 88.445 - } 88.446 - } 88.447 - 88.448 - return true; 88.449 - } 88.450 - 88.451 @Override 88.452 public String toString() { 88.453 final StringBuilder sb = new StringBuilder(); 88.454 @@ -728,24 +742,6 @@ 88.455 } 88.456 88.457 /** 88.458 - * Check whether a {@link PropertyListener} has been added to this map. 88.459 - * 88.460 - * @return {@code true} if {@link PropertyListener} exists 88.461 - */ 88.462 - public boolean isListenerAdded() { 88.463 - return (flags & IS_LISTENER_ADDED) != 0; 88.464 - } 88.465 - 88.466 - /** 88.467 - * Check if this map shared or not. 88.468 - * 88.469 - * @return true if this map is shared. 88.470 - */ 88.471 - public boolean isShared() { 88.472 - return (flags & IS_SHARED) != 0; 88.473 - } 88.474 - 88.475 - /** 88.476 * Test to see if {@link PropertyMap} is extensible. 88.477 * 88.478 * @return {@code true} if {@link PropertyMap} can be added to. 88.479 @@ -800,50 +796,29 @@ 88.480 } 88.481 88.482 /** 88.483 - * Change the prototype of objects associated with this {@link PropertyMap}. 88.484 + * Return a property map with the same layout that is associated with the new prototype object. 88.485 * 88.486 - * @param oldProto Current prototype object. 88.487 * @param newProto New prototype object to replace oldProto. 88.488 - * 88.489 * @return New {@link PropertyMap} with prototype changed. 88.490 */ 88.491 - PropertyMap changeProto(final ScriptObject oldProto, final ScriptObject newProto) { 88.492 - assert !isShared() : "proto associated with a shared PropertyMap"; 88.493 + public PropertyMap changeProto(final ScriptObject newProto) { 88.494 88.495 - if (oldProto == newProto) { 88.496 - return this; 88.497 - } 88.498 - 88.499 - final PropertyMap nextMap = checkProtoHistory(newProto); 88.500 + final PropertyMap parentMap = newProto == null ? null : newProto.getMap(); 88.501 + final PropertyMap nextMap = checkProtoHistory(parentMap); 88.502 if (nextMap != null) { 88.503 return nextMap; 88.504 } 88.505 88.506 if (Context.DEBUG) { 88.507 - incrementSetProtoNewMapCount(); 88.508 + setProtoNewMapCount++; 88.509 } 88.510 88.511 final PropertyMap newMap = new PropertyMap(this); 88.512 - addToProtoHistory(newProto, newMap); 88.513 + addToProtoHistory(parentMap, newMap); 88.514 88.515 return newMap; 88.516 } 88.517 88.518 - /** 88.519 - * Indicate that the map has listeners. 88.520 - */ 88.521 - private void setIsListenerAdded() { 88.522 - flags |= IS_LISTENER_ADDED; 88.523 - } 88.524 - 88.525 - /** 88.526 - * Return only the flags that should be copied during cloning. 88.527 - * 88.528 - * @return Subset of flags that should be copied. 88.529 - */ 88.530 - private int getClonedFlags() { 88.531 - return flags & CLONEABLE_FLAGS_MASK; 88.532 - } 88.533 88.534 /** 88.535 * {@link PropertyMap} iterator. 88.536 @@ -900,41 +875,12 @@ 88.537 } 88.538 88.539 /* 88.540 - * PropertyListener implementation. 88.541 - */ 88.542 - 88.543 - @Override 88.544 - public void propertyAdded(final ScriptObject object, final Property prop) { 88.545 - invalidateProtoGetSwitchPoint(prop); 88.546 - } 88.547 - 88.548 - @Override 88.549 - public void propertyDeleted(final ScriptObject object, final Property prop) { 88.550 - invalidateProtoGetSwitchPoint(prop); 88.551 - } 88.552 - 88.553 - @Override 88.554 - public void propertyModified(final ScriptObject object, final Property oldProp, final Property newProp) { 88.555 - invalidateProtoGetSwitchPoint(oldProp); 88.556 - } 88.557 - 88.558 - @Override 88.559 - public void protoChanged(final ScriptObject object, final ScriptObject oldProto, final ScriptObject newProto) { 88.560 - // We may walk and invalidate SwitchPoints for properties inherited 88.561 - // from 'object' or it's old proto chain. But, it may not be worth it. 88.562 - // For example, a new proto may have a user defined getter/setter for 88.563 - // a data property down the chain. So, invalidating all is better. 88.564 - invalidateAllProtoGetSwitchPoints(); 88.565 - } 88.566 - 88.567 - /* 88.568 * Debugging and statistics. 88.569 */ 88.570 88.571 // counters updated only in debug mode 88.572 private static int count; 88.573 private static int clonedCount; 88.574 - private static int sharedCount; 88.575 private static int duplicatedCount; 88.576 private static int historyHit; 88.577 private static int protoInvalidations; 88.578 @@ -956,13 +902,6 @@ 88.579 } 88.580 88.581 /** 88.582 - * @return The number of maps that are shared. 88.583 - */ 88.584 - public static int getSharedCount() { 88.585 - return sharedCount; 88.586 - } 88.587 - 88.588 - /** 88.589 * @return The number of maps that are duplicated. 88.590 */ 88.591 public static int getDuplicatedCount() { 88.592 @@ -997,10 +936,4 @@ 88.593 return setProtoNewMapCount; 88.594 } 88.595 88.596 - /** 88.597 - * Increment the prototype set count. 88.598 - */ 88.599 - private static void incrementSetProtoNewMapCount() { 88.600 - setProtoNewMapCount++; 88.601 - } 88.602 }
89.1 --- a/src/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java Wed Mar 26 12:01:34 2014 -0700 89.2 +++ b/src/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java Tue Apr 01 11:44:05 2014 -0700 89.3 @@ -103,9 +103,7 @@ 89.4 public RecompilableScriptFunctionData(final FunctionNode functionNode, final CodeInstaller<ScriptEnvironment> installer, final String allocatorClassName, final PropertyMap allocatorMap) { 89.5 super(functionName(functionNode), 89.6 functionNode.getParameters().size(), 89.7 - functionNode.isStrict(), 89.8 - false, 89.9 - true); 89.10 + getFlags(functionNode)); 89.11 89.12 this.functionNode = functionNode; 89.13 this.source = functionNode.getSource(); 89.14 @@ -129,10 +127,11 @@ 89.15 final StringBuilder sb = new StringBuilder(); 89.16 89.17 if (source != null) { 89.18 - sb.append(source.getName()) 89.19 - .append(':') 89.20 - .append(functionNode.getLineNumber()) 89.21 - .append(' '); 89.22 + sb.append(source.getName()); 89.23 + if (functionNode != null) { 89.24 + sb.append(':').append(functionNode.getLineNumber()); 89.25 + } 89.26 + sb.append(' '); 89.27 } 89.28 89.29 return sb.toString() + super.toString(); 89.30 @@ -159,11 +158,25 @@ 89.31 return Token.toDesc(TokenType.FUNCTION, position, length); 89.32 } 89.33 89.34 + private static int getFlags(final FunctionNode functionNode) { 89.35 + int flags = IS_CONSTRUCTOR; 89.36 + if (functionNode.isStrict()) { 89.37 + flags |= IS_STRICT; 89.38 + } 89.39 + if (functionNode.needsCallee()) { 89.40 + flags |= NEEDS_CALLEE; 89.41 + } 89.42 + if (functionNode.usesThis() || functionNode.hasEval()) { 89.43 + flags |= USES_THIS; 89.44 + } 89.45 + return flags; 89.46 + } 89.47 + 89.48 @Override 89.49 - ScriptObject allocate() { 89.50 + ScriptObject allocate(final PropertyMap map) { 89.51 try { 89.52 ensureHasAllocator(); //if allocatorClass name is set to null (e.g. for bound functions) we don't even try 89.53 - return allocator == null ? null : (ScriptObject)allocator.invokeExact(allocatorMap); 89.54 + return allocator == null ? null : (ScriptObject)allocator.invokeExact(map); 89.55 } catch (final RuntimeException | Error e) { 89.56 throw e; 89.57 } catch (final Throwable t) { 89.58 @@ -178,40 +191,46 @@ 89.59 } 89.60 89.61 @Override 89.62 + PropertyMap getAllocatorMap() { 89.63 + return allocatorMap; 89.64 + } 89.65 + 89.66 + 89.67 + @Override 89.68 + protected void ensureCompiled() { 89.69 + if (functionNode != null && functionNode.isLazy()) { 89.70 + Compiler.LOG.info("Trampoline hit: need to do lazy compilation of '", functionNode.getName(), "'"); 89.71 + final Compiler compiler = new Compiler(installer); 89.72 + functionNode = compiler.compile(functionNode); 89.73 + assert !functionNode.isLazy(); 89.74 + compiler.install(functionNode); 89.75 + flags = getFlags(functionNode); 89.76 + } 89.77 + } 89.78 + 89.79 + @Override 89.80 protected synchronized void ensureCodeGenerated() { 89.81 - if (!code.isEmpty()) { 89.82 - return; // nothing to do, we have code, at least some. 89.83 - } 89.84 + if (!code.isEmpty()) { 89.85 + return; // nothing to do, we have code, at least some. 89.86 + } 89.87 89.88 - if (functionNode.isLazy()) { 89.89 - Compiler.LOG.info("Trampoline hit: need to do lazy compilation of '", functionNode.getName(), "'"); 89.90 - final Compiler compiler = new Compiler(installer); 89.91 - functionNode = compiler.compile(functionNode); 89.92 - assert !functionNode.isLazy(); 89.93 - compiler.install(functionNode); 89.94 + ensureCompiled(); 89.95 89.96 - /* 89.97 - * We don't need to update any flags - varArgs and needsCallee are instrincic 89.98 - * in the function world we need to get a destination node from the compile instead 89.99 - * and replace it with our function node. TODO 89.100 - */ 89.101 - } 89.102 + /* 89.103 + * We can't get to this program point unless we have bytecode, either from 89.104 + * eager compilation or from running a lazy compile on the lines above 89.105 + */ 89.106 89.107 - /* 89.108 - * We can't get to this program point unless we have bytecode, either from 89.109 - * eager compilation or from running a lazy compile on the lines above 89.110 - */ 89.111 + assert functionNode.hasState(CompilationState.EMITTED) : functionNode.getName() + " " + functionNode.getState() + " " + Debug.id(functionNode); 89.112 89.113 - assert functionNode.hasState(CompilationState.EMITTED) : functionNode.getName() + " " + functionNode.getState() + " " + Debug.id(functionNode); 89.114 + // code exists - look it up and add it into the automatically sorted invoker list 89.115 + addCode(functionNode); 89.116 89.117 - // code exists - look it up and add it into the automatically sorted invoker list 89.118 - addCode(functionNode); 89.119 - 89.120 - if (! functionNode.canSpecialize()) { 89.121 - // allow GC to claim IR stuff that is not needed anymore 89.122 - functionNode = null; 89.123 - installer = null; 89.124 - } 89.125 + if (! functionNode.canSpecialize()) { 89.126 + // allow GC to claim IR stuff that is not needed anymore 89.127 + functionNode = null; 89.128 + installer = null; 89.129 + } 89.130 } 89.131 89.132 private MethodHandle addCode(final FunctionNode fn) {
90.1 --- a/src/jdk/nashorn/internal/runtime/ScriptFunction.java Wed Mar 26 12:01:34 2014 -0700 90.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptFunction.java Tue Apr 01 11:44:05 2014 -0700 90.3 @@ -38,6 +38,7 @@ 90.4 import jdk.internal.dynalink.linker.LinkRequest; 90.5 import jdk.nashorn.internal.codegen.CompilerConstants.Call; 90.6 import jdk.nashorn.internal.lookup.MethodHandleFactory; 90.7 +import jdk.nashorn.internal.objects.Global; 90.8 import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor; 90.9 import jdk.nashorn.internal.runtime.linker.NashornGuards; 90.10 90.11 @@ -66,6 +67,8 @@ 90.12 90.13 private static final MethodHandle WRAPFILTER = findOwnMH("wrapFilter", Object.class, Object.class); 90.14 90.15 + private static final MethodHandle GLOBALFILTER = findOwnMH("globalFilter", Object.class, Object.class); 90.16 + 90.17 /** method handle to scope getter for this ScriptFunction */ 90.18 public static final Call GET_SCOPE = virtualCallNoLookup(ScriptFunction.class, "getScope", ScriptObject.class); 90.19 90.20 @@ -80,6 +83,9 @@ 90.21 90.22 private final ScriptFunctionData data; 90.23 90.24 + /** The property map used for newly allocated object when function is used as constructor. */ 90.25 + protected PropertyMap allocatorMap; 90.26 + 90.27 /** 90.28 * Constructor 90.29 * 90.30 @@ -88,9 +94,7 @@ 90.31 * @param map property map 90.32 * @param scope scope 90.33 * @param specs specialized version of this function - other method handles 90.34 - * @param strict is this a strict mode function? 90.35 - * @param builtin is this a built in function? 90.36 - * @param isConstructor is this a constructor? 90.37 + * @param flags {@link ScriptFunctionData} flags 90.38 */ 90.39 protected ScriptFunction( 90.40 final String name, 90.41 @@ -98,11 +102,9 @@ 90.42 final PropertyMap map, 90.43 final ScriptObject scope, 90.44 final MethodHandle[] specs, 90.45 - final boolean strict, 90.46 - final boolean builtin, 90.47 - final boolean isConstructor) { 90.48 + final int flags) { 90.49 90.50 - this(new FinalScriptFunctionData(name, methodHandle, specs, strict, builtin, isConstructor), map, scope); 90.51 + this(new FinalScriptFunctionData(name, methodHandle, specs, flags), map, scope); 90.52 } 90.53 90.54 /** 90.55 @@ -125,6 +127,7 @@ 90.56 90.57 this.data = data; 90.58 this.scope = scope; 90.59 + this.allocatorMap = data.getAllocatorMap(); 90.60 } 90.61 90.62 @Override 90.63 @@ -229,16 +232,16 @@ 90.64 } 90.65 assert !isBoundFunction(); // allocate never invoked on bound functions 90.66 90.67 - final ScriptObject object = data.allocate(); 90.68 + final ScriptObject object = data.allocate(allocatorMap); 90.69 90.70 if (object != null) { 90.71 Object prototype = getPrototype(); 90.72 if (prototype instanceof ScriptObject) { 90.73 - object.setProto((ScriptObject)prototype); 90.74 + object.setInitialProto((ScriptObject)prototype); 90.75 } 90.76 90.77 if (object.getProto() == null) { 90.78 - object.setProto(getObjectPrototype()); 90.79 + object.setInitialProto(getObjectPrototype()); 90.80 } 90.81 } 90.82 90.83 @@ -473,7 +476,14 @@ 90.84 if (obj instanceof ScriptObject || !ScriptFunctionData.isPrimitiveThis(obj)) { 90.85 return obj; 90.86 } 90.87 - return ((GlobalObject)Context.getGlobalTrusted()).wrapAsObject(obj); 90.88 + return Context.getGlobal().wrapAsObject(obj); 90.89 + } 90.90 + 90.91 + 90.92 + @SuppressWarnings("unused") 90.93 + private static Object globalFilter(final Object object) { 90.94 + // replace whatever we get with the current global object 90.95 + return Context.getGlobal(); 90.96 } 90.97 90.98 /** 90.99 @@ -491,11 +501,11 @@ 90.100 @Override 90.101 protected GuardedInvocation findCallMethod(final CallSiteDescriptor desc, final LinkRequest request) { 90.102 final MethodType type = desc.getMethodType(); 90.103 + final boolean scopeCall = NashornCallSiteDescriptor.isScope(desc); 90.104 90.105 if (request.isCallSiteUnstable()) { 90.106 - // (this, callee, args...) => (this, callee, args[]) 90.107 - final MethodHandle collector = MH.asCollector(ScriptRuntime.APPLY.methodHandle(), Object[].class, 90.108 - type.parameterCount() - 2); 90.109 + // (callee, this, args...) => (callee, this, args[]) 90.110 + final MethodHandle collector = MH.asCollector(ScriptRuntime.APPLY.methodHandle(), Object[].class, type.parameterCount() - 2); 90.111 90.112 // If call site is statically typed to take a ScriptFunction, we don't need a guard, otherwise we need a 90.113 // generic "is this a ScriptFunction?" guard. 90.114 @@ -506,17 +516,12 @@ 90.115 MethodHandle boundHandle; 90.116 MethodHandle guard = null; 90.117 90.118 - final boolean scopeCall = NashornCallSiteDescriptor.isScope(desc); 90.119 - 90.120 if (data.needsCallee()) { 90.121 final MethodHandle callHandle = getBestInvoker(type, request.getArguments()); 90.122 - if (scopeCall) { 90.123 + if (scopeCall && needsWrappedThis()) { 90.124 // Make a handle that drops the passed "this" argument and substitutes either Global or Undefined 90.125 - // (callee, this, args...) => (callee, args...) 90.126 - boundHandle = MH.insertArguments(callHandle, 1, needsWrappedThis() ? Context.getGlobalTrusted() : ScriptRuntime.UNDEFINED); 90.127 - // (callee, args...) => (callee, [this], args...) 90.128 - boundHandle = MH.dropArguments(boundHandle, 1, Object.class); 90.129 - 90.130 + // (callee, this, args...) => (callee, [this], args...) 90.131 + boundHandle = MH.filterArguments(callHandle, 1, GLOBALFILTER); 90.132 } else { 90.133 // It's already (callee, this, args...), just what we need 90.134 boundHandle = callHandle; 90.135 @@ -527,12 +532,12 @@ 90.136 // NOTE: the only built-in named "extend" is NativeJava.extend. As a special-case we're binding the 90.137 // current lookup as its "this" so it can do security-sensitive creation of adapter classes. 90.138 boundHandle = MH.dropArguments(MH.bindTo(callHandle, desc.getLookup()), 0, Object.class, Object.class); 90.139 - } else if (scopeCall) { 90.140 + } else if (scopeCall && needsWrappedThis()) { 90.141 // Make a handle that drops the passed "this" argument and substitutes either Global or Undefined 90.142 - // (this, args...) => (args...) 90.143 - boundHandle = MH.bindTo(callHandle, needsWrappedThis() ? Context.getGlobalTrusted() : ScriptRuntime.UNDEFINED); 90.144 - // (args...) => ([callee], [this], args...) 90.145 - boundHandle = MH.dropArguments(boundHandle, 0, Object.class, Object.class); 90.146 + // (this, args...) => ([this], args...) 90.147 + boundHandle = MH.filterArguments(callHandle, 0, GLOBALFILTER); 90.148 + // ([this], args...) => ([callee], [this], args...) 90.149 + boundHandle = MH.dropArguments(boundHandle, 0, Object.class); 90.150 } else { 90.151 // (this, args...) => ([callee], this, args...) 90.152 boundHandle = MH.dropArguments(callHandle, 0, Object.class);
91.1 --- a/src/jdk/nashorn/internal/runtime/ScriptFunctionData.java Wed Mar 26 12:01:34 2014 -0700 91.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptFunctionData.java Tue Apr 01 11:44:05 2014 -0700 91.3 @@ -32,6 +32,7 @@ 91.4 import java.lang.invoke.MethodHandle; 91.5 import java.lang.invoke.MethodHandles; 91.6 import java.lang.invoke.MethodType; 91.7 +import jdk.nashorn.internal.objects.Global; 91.8 import jdk.nashorn.internal.runtime.linker.JavaAdapterFactory; 91.9 91.10 /** 91.11 @@ -47,33 +48,44 @@ 91.12 /** All versions of this function that have been generated to code */ 91.13 protected final CompiledFunctions code; 91.14 91.15 + /** Function flags */ 91.16 + protected int flags; 91.17 + 91.18 private int arity; 91.19 91.20 - private final boolean isStrict; 91.21 - 91.22 - private final boolean isBuiltin; 91.23 - 91.24 - private final boolean isConstructor; 91.25 - 91.26 private static final MethodHandle NEWFILTER = findOwnMH("newFilter", Object.class, Object.class, Object.class); 91.27 private static final MethodHandle BIND_VAR_ARGS = findOwnMH("bindVarArgs", Object[].class, Object[].class, Object[].class); 91.28 91.29 + /** Is this a strict mode function? */ 91.30 + public static final int IS_STRICT = 1 << 0; 91.31 + /** Is this a built-in function? */ 91.32 + public static final int IS_BUILTIN = 1 << 1; 91.33 + /** Is this a constructor function? */ 91.34 + public static final int IS_CONSTRUCTOR = 1 << 2; 91.35 + /** Does this function expect a callee argument? */ 91.36 + public static final int NEEDS_CALLEE = 1 << 3; 91.37 + /** Does this function make use of the this-object argument? */ 91.38 + public static final int USES_THIS = 1 << 4; 91.39 + 91.40 + /** Flag for strict or built-in functions */ 91.41 + public static final int IS_STRICT_OR_BUILTIN = IS_STRICT | IS_BUILTIN; 91.42 + /** Flag for built-in constructors */ 91.43 + public static final int IS_BUILTIN_CONSTRUCTOR = IS_BUILTIN | IS_CONSTRUCTOR; 91.44 + /** Flag for strict constructors */ 91.45 + public static final int IS_STRICT_CONSTRUCTOR = IS_STRICT | IS_CONSTRUCTOR; 91.46 + 91.47 /** 91.48 * Constructor 91.49 * 91.50 * @param name script function name 91.51 * @param arity arity 91.52 - * @param isStrict is the function strict 91.53 - * @param isBuiltin is the function built in 91.54 - * @param isConstructor is the function a constructor 91.55 + * @param flags the function flags 91.56 */ 91.57 - ScriptFunctionData(final String name, final int arity, final boolean isStrict, final boolean isBuiltin, final boolean isConstructor) { 91.58 - this.name = name; 91.59 - this.arity = arity; 91.60 - this.code = new CompiledFunctions(); 91.61 - this.isStrict = isStrict; 91.62 - this.isBuiltin = isBuiltin; 91.63 - this.isConstructor = isConstructor; 91.64 + ScriptFunctionData(final String name, final int arity, final int flags) { 91.65 + this.name = name; 91.66 + this.arity = arity; 91.67 + this.code = new CompiledFunctions(); 91.68 + this.flags = flags; 91.69 } 91.70 91.71 final int getArity() { 91.72 @@ -105,21 +117,21 @@ 91.73 * @return true if strict, false otherwise 91.74 */ 91.75 public boolean isStrict() { 91.76 - return isStrict; 91.77 + return (flags & IS_STRICT) != 0; 91.78 } 91.79 91.80 boolean isBuiltin() { 91.81 - return isBuiltin; 91.82 + return (flags & IS_BUILTIN) != 0; 91.83 } 91.84 91.85 boolean isConstructor() { 91.86 - return isConstructor; 91.87 + return (flags & IS_CONSTRUCTOR) != 0; 91.88 } 91.89 91.90 boolean needsCallee() { 91.91 - // we don't know if we need a callee or not unless we are generated 91.92 - ensureCodeGenerated(); 91.93 - return code.needsCallee(); 91.94 + // we don't know if we need a callee or not unless code has been compiled 91.95 + ensureCompiled(); 91.96 + return (flags & NEEDS_CALLEE) != 0; 91.97 } 91.98 91.99 /** 91.100 @@ -128,7 +140,7 @@ 91.101 * @return true if this argument must be an object 91.102 */ 91.103 boolean needsWrappedThis() { 91.104 - return !isStrict && !isBuiltin; 91.105 + return (flags & USES_THIS) != 0 && (flags & IS_STRICT_OR_BUILTIN) == 0; 91.106 } 91.107 91.108 String toSource() { 91.109 @@ -202,6 +214,15 @@ 91.110 } 91.111 91.112 /** 91.113 + * If we can have lazy code generation, this is a hook to ensure that the code has been compiled. 91.114 + * This does not guarantee the code been installed in this {@code ScriptFunctionData} instance; 91.115 + * use {@link #ensureCodeGenerated()} to install the actual method handles. 91.116 + */ 91.117 + protected void ensureCompiled() { 91.118 + //empty 91.119 + } 91.120 + 91.121 + /** 91.122 * Return a generic Object/Object invoker for this method. It will ensure code 91.123 * is generated, get the most generic of all versions of this function and adapt it 91.124 * to Objects. 91.125 @@ -229,9 +250,20 @@ 91.126 91.127 /** 91.128 * Allocates an object using this function's allocator. 91.129 + * 91.130 + * @param map the property map for the allocated object. 91.131 * @return the object allocated using this function's allocator, or null if the function doesn't have an allocator. 91.132 */ 91.133 - ScriptObject allocate() { 91.134 + ScriptObject allocate(final PropertyMap map) { 91.135 + return null; 91.136 + } 91.137 + 91.138 + /** 91.139 + * Get the property map to use for objects allocated by this function. 91.140 + * 91.141 + * @return the property map for allocated objects. 91.142 + */ 91.143 + PropertyMap getAllocatorMap() { 91.144 return null; 91.145 } 91.146 91.147 @@ -248,6 +280,8 @@ 91.148 91.149 final Object[] allArgs = args == null ? ScriptRuntime.EMPTY_ARRAY : args; 91.150 final int length = args == null ? 0 : args.length; 91.151 + // Clear the callee and this flags 91.152 + final int boundFlags = flags & ~NEEDS_CALLEE & ~USES_THIS; 91.153 91.154 CompiledFunctions boundList = new CompiledFunctions(); 91.155 if (code.size() == 1) { 91.156 @@ -262,8 +296,7 @@ 91.157 boundList.add(bind(inv, fn, self, allArgs)); 91.158 } 91.159 91.160 - ScriptFunctionData boundData = new FinalScriptFunctionData(name, arity == -1 ? -1 : Math.max(0, arity - length), boundList, isStrict(), isBuiltin(), isConstructor()); 91.161 - return boundData; 91.162 + return new FinalScriptFunctionData(name, arity == -1 ? -1 : Math.max(0, arity - length), boundList, boundFlags); 91.163 } 91.164 91.165 /** 91.166 @@ -340,11 +373,11 @@ 91.167 private Object convertThisObject(final Object thiz) { 91.168 if (!(thiz instanceof ScriptObject) && needsWrappedThis()) { 91.169 if (JSType.nullOrUndefined(thiz)) { 91.170 - return Context.getGlobalTrusted(); 91.171 + return Context.getGlobal(); 91.172 } 91.173 91.174 if (isPrimitiveThis(thiz)) { 91.175 - return ((GlobalObject)Context.getGlobalTrusted()).wrapAsObject(thiz); 91.176 + return Context.getGlobal().wrapAsObject(thiz); 91.177 } 91.178 } 91.179
92.1 --- a/src/jdk/nashorn/internal/runtime/ScriptLoader.java Wed Mar 26 12:01:34 2014 -0700 92.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptLoader.java Tue Apr 01 11:44:05 2014 -0700 92.3 @@ -70,9 +70,8 @@ 92.4 * @return Installed class. 92.5 */ 92.6 synchronized Class<?> installClass(final String name, final byte[] data, final CodeSource cs) { 92.7 - if (cs == null) { 92.8 - return defineClass(name, data, 0, data.length, new ProtectionDomain(null, getPermissions(null))); 92.9 - } 92.10 + // null check 92.11 + cs.getClass(); 92.12 return defineClass(name, data, 0, data.length, cs); 92.13 } 92.14 }
93.1 --- a/src/jdk/nashorn/internal/runtime/ScriptObject.java Wed Mar 26 12:01:34 2014 -0700 93.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptObject.java Tue Apr 01 11:44:05 2014 -0700 93.3 @@ -43,6 +43,7 @@ 93.4 import java.lang.invoke.MethodHandle; 93.5 import java.lang.invoke.MethodHandles; 93.6 import java.lang.invoke.MethodType; 93.7 +import java.lang.invoke.SwitchPoint; 93.8 import java.util.AbstractMap; 93.9 import java.util.ArrayList; 93.10 import java.util.Arrays; 93.11 @@ -65,6 +66,7 @@ 93.12 import jdk.nashorn.internal.lookup.MethodHandleFactory; 93.13 import jdk.nashorn.internal.objects.AccessorPropertyDescriptor; 93.14 import jdk.nashorn.internal.objects.DataPropertyDescriptor; 93.15 +import jdk.nashorn.internal.objects.Global; 93.16 import jdk.nashorn.internal.runtime.arrays.ArrayData; 93.17 import jdk.nashorn.internal.runtime.arrays.ArrayIndex; 93.18 import jdk.nashorn.internal.runtime.linker.Bootstrap; 93.19 @@ -88,7 +90,7 @@ 93.20 * </ul> 93.21 */ 93.22 93.23 -public abstract class ScriptObject extends PropertyListenerManager implements PropertyAccess { 93.24 +public abstract class ScriptObject implements PropertyAccess { 93.25 /** __proto__ special property name */ 93.26 public static final String PROTO_PROPERTY_NAME = "__proto__"; 93.27 93.28 @@ -107,9 +109,6 @@ 93.29 /** Per ScriptObject flag - is this an arguments object? */ 93.30 public static final int IS_ARGUMENTS = 0b0000_0100; 93.31 93.32 - /** Is this a prototype PropertyMap? */ 93.33 - public static final int IS_PROTOTYPE = 0b0000_1000; 93.34 - 93.35 /** Is length property not-writable? */ 93.36 public static final int IS_LENGTH_NOT_WRITABLE = 0b0001_0000; 93.37 93.38 @@ -133,7 +132,8 @@ 93.39 93.40 static final MethodHandle GETPROTO = findOwnMH("getProto", ScriptObject.class); 93.41 static final MethodHandle SETPROTOCHECK = findOwnMH("setProtoCheck", void.class, Object.class); 93.42 - static final MethodHandle MEGAMORPHIC_GET = findOwnMH("megamorphicGet", Object.class, String.class, boolean.class); 93.43 + static final MethodHandle MEGAMORPHIC_GET = findOwnMH("megamorphicGet", Object.class, String.class, boolean.class, boolean.class); 93.44 + static final MethodHandle GLOBALFILTER = findOwnMH("globalFilter", Object.class, Object.class); 93.45 93.46 static final MethodHandle SETFIELD = findOwnMH("setField", void.class, CallSiteDescriptor.class, PropertyMap.class, PropertyMap.class, MethodHandle.class, Object.class, Object.class); 93.47 static final MethodHandle SETSPILL = findOwnMH("setSpill", void.class, CallSiteDescriptor.class, PropertyMap.class, PropertyMap.class, int.class, Object.class, Object.class); 93.48 @@ -143,6 +143,8 @@ 93.49 private static final MethodHandle TRUNCATINGFILTER = findOwnMH("truncatingFilter", Object[].class, int.class, Object[].class); 93.50 private static final MethodHandle KNOWNFUNCPROPGUARD = findOwnMH("knownFunctionPropertyGuard", boolean.class, Object.class, PropertyMap.class, MethodHandle.class, Object.class, ScriptFunction.class); 93.51 93.52 + private static final ArrayList<MethodHandle> protoFilters = new ArrayList<>(); 93.53 + 93.54 /** Method handle for getting a function argument at a given index. Used from MapCreator */ 93.55 public static final Call GET_ARGUMENT = virtualCall(MethodHandles.lookup(), ScriptObject.class, "getArgument", Object.class, int.class); 93.56 93.57 @@ -153,7 +155,7 @@ 93.58 public static final Call GET_PROTO = virtualCallNoLookup(ScriptObject.class, "getProto", ScriptObject.class); 93.59 93.60 /** Method handle for setting the proto of a ScriptObject */ 93.61 - public static final Call SET_PROTO = virtualCallNoLookup(ScriptObject.class, "setProto", void.class, ScriptObject.class); 93.62 + public static final Call SET_PROTO = virtualCallNoLookup(ScriptObject.class, "setInitialProto", void.class, ScriptObject.class); 93.63 93.64 /** Method handle for setting the proto of a ScriptObject after checking argument */ 93.65 public static final Call SET_PROTO_CHECK = virtualCallNoLookup(ScriptObject.class, "setProtoCheck", void.class, Object.class); 93.66 @@ -199,10 +201,6 @@ 93.67 this.arrayData = ArrayData.EMPTY_ARRAY; 93.68 this.setMap(map == null ? PropertyMap.newMap() : map); 93.69 this.proto = proto; 93.70 - 93.71 - if (proto != null) { 93.72 - proto.setIsPrototype(); 93.73 - } 93.74 } 93.75 93.76 /** 93.77 @@ -229,8 +227,9 @@ 93.78 final Property oldProp = newMap.findProperty(key); 93.79 if (oldProp == null) { 93.80 if (property instanceof UserAccessorProperty) { 93.81 + // Note: we copy accessor functions to this object which is semantically different from binding. 93.82 final UserAccessorProperty prop = this.newUserAccessors(key, property.getFlags(), property.getGetterFunction(source), property.getSetterFunction(source)); 93.83 - newMap = newMap.addProperty(prop); 93.84 + newMap = newMap.addPropertyNoHistory(prop); 93.85 } else { 93.86 newMap = newMap.addPropertyBind((AccessorProperty)property, source); 93.87 } 93.88 @@ -326,18 +325,18 @@ 93.89 * @return property descriptor 93.90 */ 93.91 public final PropertyDescriptor toPropertyDescriptor() { 93.92 - final GlobalObject global = (GlobalObject) Context.getGlobalTrusted(); 93.93 + final Global global = Context.getGlobal(); 93.94 93.95 final PropertyDescriptor desc; 93.96 if (isDataDescriptor()) { 93.97 if (has(SET) || has(GET)) { 93.98 - throw typeError((ScriptObject)global, "inconsistent.property.descriptor"); 93.99 + throw typeError(global, "inconsistent.property.descriptor"); 93.100 } 93.101 93.102 desc = global.newDataDescriptor(UNDEFINED, false, false, false); 93.103 } else if (isAccessorDescriptor()) { 93.104 if (has(VALUE) || has(WRITABLE)) { 93.105 - throw typeError((ScriptObject)global, "inconsistent.property.descriptor"); 93.106 + throw typeError(global, "inconsistent.property.descriptor"); 93.107 } 93.108 93.109 desc = global.newAccessorDescriptor(UNDEFINED, UNDEFINED, false, false); 93.110 @@ -356,7 +355,7 @@ 93.111 * 93.112 * @return property descriptor 93.113 */ 93.114 - public static PropertyDescriptor toPropertyDescriptor(final ScriptObject global, final Object obj) { 93.115 + public static PropertyDescriptor toPropertyDescriptor(final Global global, final Object obj) { 93.116 if (obj instanceof ScriptObject) { 93.117 return ((ScriptObject)obj).toPropertyDescriptor(); 93.118 } 93.119 @@ -375,7 +374,7 @@ 93.120 public Object getOwnPropertyDescriptor(final String key) { 93.121 final Property property = getMap().findProperty(key); 93.122 93.123 - final GlobalObject global = (GlobalObject)Context.getGlobalTrusted(); 93.124 + final Global global = Context.getGlobal(); 93.125 93.126 if (property != null) { 93.127 final ScriptFunction get = property.getGetterFunction(this); 93.128 @@ -440,7 +439,7 @@ 93.129 * @return true if property was successfully defined 93.130 */ 93.131 public boolean defineOwnProperty(final String key, final Object propertyDesc, final boolean reject) { 93.132 - final ScriptObject global = Context.getGlobalTrusted(); 93.133 + final Global global = Context.getGlobal(); 93.134 final PropertyDescriptor desc = toPropertyDescriptor(global, propertyDesc); 93.135 final Object current = getOwnPropertyDescriptor(key); 93.136 final String name = JSType.toString(key); 93.137 @@ -467,7 +466,7 @@ 93.138 return true; 93.139 } 93.140 93.141 - if (currentDesc.equals(newDesc)) { 93.142 + if (newDesc.hasAndEquals(currentDesc)) { 93.143 // every descriptor field of the new is same as the current 93.144 return true; 93.145 } 93.146 @@ -594,23 +593,16 @@ 93.147 } 93.148 93.149 /** 93.150 - * Spec. mentions use of [[DefineOwnProperty]] for indexed properties in 93.151 - * certain places (eg. Array.prototype.map, filter). We can not use ScriptObject.set 93.152 - * method in such cases. This is because set method uses inherited setters (if any) 93.153 - * from any object in proto chain such as Array.prototype, Object.prototype. 93.154 - * This method directly sets a particular element value in the current object. 93.155 + * Almost like defineOwnProperty(int,Object) for arrays this one does 93.156 + * not add 'gap' elements (like the array one does). 93.157 * 93.158 * @param index key for property 93.159 * @param value value to define 93.160 */ 93.161 - public final void defineOwnProperty(final int index, final Object value) { 93.162 + public void defineOwnProperty(final int index, final Object value) { 93.163 assert isValidArrayIndex(index) : "invalid array index"; 93.164 final long longIndex = ArrayIndex.toLongIndex(index); 93.165 - if (longIndex >= getArray().length()) { 93.166 - // make array big enough to hold.. 93.167 - setArray(getArray().ensure(longIndex)); 93.168 - } 93.169 - setArray(getArray().set(index, value, false)); 93.170 + setValueAtArrayIndex(longIndex, index, value, false); 93.171 } 93.172 93.173 private void checkIntegerKey(final String key) { 93.174 @@ -638,7 +630,7 @@ 93.175 final int propFlags = Property.toFlags(pdesc); 93.176 93.177 if (pdesc.type() == PropertyDescriptor.GENERIC) { 93.178 - final GlobalObject global = (GlobalObject) Context.getGlobalTrusted(); 93.179 + final Global global = Context.getGlobal(); 93.180 final PropertyDescriptor dDesc = global.newDataDescriptor(UNDEFINED, false, false, false); 93.181 93.182 dDesc.fillFrom((ScriptObject)pdesc); 93.183 @@ -873,8 +865,6 @@ 93.184 newProperty = newUserAccessors(oldProperty.getKey(), propertyFlags, getter, setter); 93.185 } 93.186 93.187 - notifyPropertyModified(this, oldProperty, newProperty); 93.188 - 93.189 return modifyOwnProperty(oldProperty, newProperty); 93.190 } 93.191 93.192 @@ -981,17 +971,6 @@ 93.193 } 93.194 93.195 /** 93.196 - * Get the object value of a property 93.197 - * 93.198 - * @param find {@link FindProperty} lookup result 93.199 - * 93.200 - * @return the value of the property 93.201 - */ 93.202 - protected static Object getObjectValue(final FindProperty find) { 93.203 - return find.getObjectValue(); 93.204 - } 93.205 - 93.206 - /** 93.207 * Return methodHandle of value function for call. 93.208 * 93.209 * @param find data from find property. 93.210 @@ -1001,7 +980,7 @@ 93.211 * @return value of property as a MethodHandle or null. 93.212 */ 93.213 protected MethodHandle getCallMethodHandle(final FindProperty find, final MethodType type, final String bindName) { 93.214 - return getCallMethodHandle(getObjectValue(find), type, bindName); 93.215 + return getCallMethodHandle(find.getObjectValue(), type, bindName); 93.216 } 93.217 93.218 /** 93.219 @@ -1025,7 +1004,7 @@ 93.220 * @return Value of property. 93.221 */ 93.222 public final Object getWithProperty(final Property property) { 93.223 - return getObjectValue(new FindProperty(this, this, property)); 93.224 + return new FindProperty(this, this, property).getObjectValue(); 93.225 } 93.226 93.227 /** 93.228 @@ -1118,26 +1097,30 @@ 93.229 */ 93.230 public synchronized final void setProto(final ScriptObject newProto) { 93.231 final ScriptObject oldProto = proto; 93.232 - map = map.changeProto(oldProto, newProto); 93.233 - 93.234 - if (newProto != null) { 93.235 - newProto.setIsPrototype(); 93.236 + 93.237 + if (oldProto != newProto) { 93.238 + proto = newProto; 93.239 + 93.240 + // Let current listeners know that the protototype has changed and set our map 93.241 + final PropertyListeners listeners = getMap().getListeners(); 93.242 + if (listeners != null) { 93.243 + listeners.protoChanged(); 93.244 + } 93.245 + // Replace our current allocator map with one that is associated with the new prototype. 93.246 + setMap(getMap().changeProto(newProto)); 93.247 } 93.248 - 93.249 - proto = newProto; 93.250 - 93.251 - if (isPrototype()) { 93.252 - // tell listeners that my __proto__ has been changed 93.253 - notifyProtoChanged(this, oldProto, newProto); 93.254 - 93.255 - if (oldProto != null) { 93.256 - oldProto.removePropertyListener(this); 93.257 - } 93.258 - 93.259 - if (newProto != null) { 93.260 - newProto.addPropertyListener(this); 93.261 - } 93.262 - } 93.263 + } 93.264 + 93.265 + /** 93.266 + * Set the initial __proto__ of this object. This should be used instead of 93.267 + * {@link #setProto} if it is known that the current property map will not be 93.268 + * used on a new object with any other parent property map, so we can pass over 93.269 + * property map invalidation/evolution. 93.270 + * 93.271 + * @param initialProto the initial __proto__ to set. 93.272 + */ 93.273 + public void setInitialProto(final ScriptObject initialProto) { 93.274 + this.proto = initialProto; 93.275 } 93.276 93.277 /** 93.278 @@ -1160,7 +1143,7 @@ 93.279 } 93.280 setProto((ScriptObject)newProto); 93.281 } else { 93.282 - final ScriptObject global = Context.getGlobalTrusted(); 93.283 + final Global global = Context.getGlobal(); 93.284 final Object newProtoObject = JSType.toScriptObject(global, newProto); 93.285 93.286 if (newProtoObject instanceof ScriptObject) { 93.287 @@ -1250,11 +1233,11 @@ 93.288 * @return the default value 93.289 */ 93.290 public Object getDefaultValue(final Class<?> typeHint) { 93.291 - // We delegate to GlobalObject, as the implementation uses dynamic call sites to invoke object's "toString" and 93.292 + // We delegate to Global, as the implementation uses dynamic call sites to invoke object's "toString" and 93.293 // "valueOf" methods, and in order to avoid those call sites from becoming megamorphic when multiple contexts 93.294 // are being executed in a long-running program, we move the code and their associated dynamic call sites 93.295 // (Global.TO_STRING and Global.VALUE_OF) into per-context code. 93.296 - return ((GlobalObject)Context.getGlobalTrusted()).getDefaultValue(this, typeHint); 93.297 + return Context.getGlobal().getDefaultValue(this, typeHint); 93.298 } 93.299 93.300 /** 93.301 @@ -1330,25 +1313,6 @@ 93.302 } 93.303 93.304 /** 93.305 - * Check if this object is a prototype 93.306 - * 93.307 - * @return {@code true} if is prototype 93.308 - */ 93.309 - public final boolean isPrototype() { 93.310 - return (flags & IS_PROTOTYPE) != 0; 93.311 - } 93.312 - 93.313 - /** 93.314 - * Flag this object as having a prototype. 93.315 - */ 93.316 - public final void setIsPrototype() { 93.317 - if (proto != null && !isPrototype()) { 93.318 - proto.addPropertyListener(this); 93.319 - } 93.320 - flags |= IS_PROTOTYPE; 93.321 - } 93.322 - 93.323 - /** 93.324 * Check if this object has non-writable length property 93.325 * 93.326 * @return {@code true} if 'length' property is non-writable 93.327 @@ -1712,6 +1676,44 @@ 93.328 } 93.329 93.330 /** 93.331 + * Test whether this object contains in its prototype chain or is itself a with-object. 93.332 + * @return true if a with-object was found 93.333 + */ 93.334 + final boolean hasWithScope() { 93.335 + if (isScope()) { 93.336 + for (ScriptObject obj = this; obj != null; obj = obj.getProto()) { 93.337 + if (obj instanceof WithObject) { 93.338 + return true; 93.339 + } 93.340 + } 93.341 + } 93.342 + return false; 93.343 + } 93.344 + 93.345 + /** 93.346 + * Add a filter to the first argument of {@code methodHandle} that calls its {@link #getProto()} method 93.347 + * {@code depth} times. 93.348 + * @param methodHandle a method handle 93.349 + * @param depth distance to target prototype 93.350 + * @return the filtered method handle 93.351 + */ 93.352 + static MethodHandle addProtoFilter(final MethodHandle methodHandle, final int depth) { 93.353 + if (depth == 0) { 93.354 + return methodHandle; 93.355 + } 93.356 + final int listIndex = depth - 1; // We don't need 0-deep walker 93.357 + MethodHandle filter = listIndex < protoFilters.size() ? protoFilters.get(listIndex) : null; 93.358 + 93.359 + if(filter == null) { 93.360 + filter = addProtoFilter(GETPROTO, depth - 1); 93.361 + protoFilters.add(null); 93.362 + protoFilters.set(listIndex, filter); 93.363 + } 93.364 + 93.365 + return MH.filterArguments(methodHandle, 0, filter.asType(filter.type().changeReturnType(methodHandle.type().parameterType(0)))); 93.366 + } 93.367 + 93.368 + /** 93.369 * Find the appropriate GET method for an invoke dynamic call. 93.370 * 93.371 * @param desc the call site descriptor 93.372 @@ -1722,8 +1724,8 @@ 93.373 */ 93.374 protected GuardedInvocation findGetMethod(final CallSiteDescriptor desc, final LinkRequest request, final String operator) { 93.375 final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND); 93.376 - if (request.isCallSiteUnstable()) { 93.377 - return findMegaMorphicGetMethod(desc, name, "getMethod".equals(operator)); 93.378 + if (request.isCallSiteUnstable() || hasWithScope()) { 93.379 + return findMegaMorphicGetMethod(desc, name, "getMethod".equals(operator), isScope() && NashornCallSiteDescriptor.isScope(desc)); 93.380 } 93.381 93.382 final FindProperty find = findProperty(name, true); 93.383 @@ -1748,40 +1750,43 @@ 93.384 final Property property = find.getProperty(); 93.385 methodHandle = find.getGetter(returnType); 93.386 93.387 - // getMap() is fine as we have the prototype switchpoint depending on where the property was found 93.388 - final MethodHandle guard = NashornGuards.getMapGuard(getMap()); 93.389 + // Get the appropriate guard for this callsite and property. 93.390 + final MethodHandle guard = NashornGuards.getGuard(this, property, desc); 93.391 + final ScriptObject owner = find.getOwner(); 93.392 93.393 if (methodHandle != null) { 93.394 assert methodHandle.type().returnType().equals(returnType); 93.395 if (find.isSelf()) { 93.396 - return new GuardedInvocation(methodHandle, ObjectClassGenerator.OBJECT_FIELDS_ONLY && 93.397 - NashornCallSiteDescriptor.isFastScope(desc) && !property.canChangeType() ? null : guard); 93.398 + return new GuardedInvocation(methodHandle, guard); 93.399 } 93.400 93.401 - final ScriptObject prototype = find.getOwner(); 93.402 - 93.403 - if (!property.hasGetterFunction(prototype)) { 93.404 - methodHandle = bindTo(methodHandle, prototype); 93.405 + if (!property.hasGetterFunction(owner)) { 93.406 + // Add a filter that replaces the self object with the prototype owning the property. 93.407 + methodHandle = addProtoFilter(methodHandle, find.getProtoChainLength()); 93.408 } 93.409 - return new GuardedInvocation(methodHandle, getMap().getProtoGetSwitchPoint(proto, name), guard); 93.410 + return new GuardedInvocation(methodHandle, guard == null ? null : getProtoSwitchPoint(name, owner), guard); 93.411 } 93.412 93.413 assert !NashornCallSiteDescriptor.isFastScope(desc); 93.414 - return new GuardedInvocation(Lookup.emptyGetter(returnType), getMap().getProtoGetSwitchPoint(proto, name), guard); 93.415 + return new GuardedInvocation(Lookup.emptyGetter(returnType), getProtoSwitchPoint(name, owner), guard); 93.416 } 93.417 93.418 - private static GuardedInvocation findMegaMorphicGetMethod(final CallSiteDescriptor desc, final String name, final boolean isMethod) { 93.419 - final MethodHandle invoker = MH.insertArguments(MEGAMORPHIC_GET, 1, name, isMethod); 93.420 + private static GuardedInvocation findMegaMorphicGetMethod(final CallSiteDescriptor desc, final String name, 93.421 + final boolean isMethod, final boolean isScope) { 93.422 + final MethodHandle invoker = MH.insertArguments(MEGAMORPHIC_GET, 1, name, isMethod, isScope); 93.423 final MethodHandle guard = getScriptObjectGuard(desc.getMethodType()); 93.424 return new GuardedInvocation(invoker, guard); 93.425 } 93.426 93.427 @SuppressWarnings("unused") 93.428 - private Object megamorphicGet(final String key, final boolean isMethod) { 93.429 + private Object megamorphicGet(final String key, final boolean isMethod, final boolean isScope) { 93.430 final FindProperty find = findProperty(key, true); 93.431 93.432 if (find != null) { 93.433 - return getObjectValue(find); 93.434 + return find.getObjectValue(); 93.435 + } 93.436 + if (isScope) { 93.437 + throw referenceError("not.defined", key); 93.438 } 93.439 93.440 return isMethod ? getNoSuchMethod(key) : invokeNoSuchProperty(key); 93.441 @@ -1824,6 +1829,28 @@ 93.442 } 93.443 93.444 /** 93.445 + * Get a switch point for a property with the given {@code name} that will be invalidated when 93.446 + * the property definition is changed in this object's prototype chain. Returns {@code null} if 93.447 + * the property is defined in this object itself. 93.448 + * 93.449 + * @param name the property name 93.450 + * @param owner the property owner, null if property is not defined 93.451 + * @return a SwitchPoint or null 93.452 + */ 93.453 + public final SwitchPoint getProtoSwitchPoint(final String name, final ScriptObject owner) { 93.454 + if (owner == this || getProto() == null) { 93.455 + return null; 93.456 + } 93.457 + 93.458 + for (ScriptObject obj = this; obj != owner && obj.getProto() != null; obj = obj.getProto()) { 93.459 + ScriptObject parent = obj.getProto(); 93.460 + parent.getMap().addListener(name, obj.getMap()); 93.461 + } 93.462 + 93.463 + return getMap().getSwitchPoint(name); 93.464 + } 93.465 + 93.466 + /** 93.467 * Find the appropriate SET method for an invoke dynamic call. 93.468 * 93.469 * @param desc the call site descriptor 93.470 @@ -1833,7 +1860,7 @@ 93.471 */ 93.472 protected GuardedInvocation findSetMethod(final CallSiteDescriptor desc, final LinkRequest request) { 93.473 final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND); 93.474 - if (request.isCallSiteUnstable()) { 93.475 + if (request.isCallSiteUnstable() || hasWithScope()) { 93.476 return findMegaMorphicSetMethod(desc, name); 93.477 } 93.478 93.479 @@ -1879,8 +1906,7 @@ 93.480 throw typeError(strictErrorMessage, name, ScriptRuntime.safeToString((this))); 93.481 } 93.482 assert canBeFastScope || !NashornCallSiteDescriptor.isFastScope(desc); 93.483 - final PropertyMap myMap = getMap(); 93.484 - return new GuardedInvocation(Lookup.EMPTY_SETTER, myMap.getProtoGetSwitchPoint(proto, name), NashornGuards.getMapGuard(myMap)); 93.485 + return new GuardedInvocation(Lookup.EMPTY_SETTER, getProtoSwitchPoint(name, null), NashornGuards.getMapGuard(getMap())); 93.486 } 93.487 93.488 @SuppressWarnings("unused") 93.489 @@ -1888,7 +1914,9 @@ 93.490 final ScriptObject obj = (ScriptObject)self; 93.491 final boolean isStrict = NashornCallSiteDescriptor.isStrict(desc); 93.492 if (!obj.isExtensible()) { 93.493 - throw typeError("object.non.extensible", desc.getNameToken(2), ScriptRuntime.safeToString(obj)); 93.494 + if (isStrict) { 93.495 + throw typeError("object.non.extensible", desc.getNameToken(2), ScriptRuntime.safeToString(obj)); 93.496 + } 93.497 } else if (obj.compareAndSetMap(oldMap, newMap)) { 93.498 setter.invokeExact(self, value); 93.499 } else { 93.500 @@ -1953,6 +1981,15 @@ 93.501 } 93.502 } 93.503 93.504 + @SuppressWarnings("unused") 93.505 + private static Object globalFilter(final Object object) { 93.506 + ScriptObject sobj = (ScriptObject) object; 93.507 + while (sobj != null && !(sobj instanceof Global)) { 93.508 + sobj = sobj.getProto(); 93.509 + } 93.510 + return sobj; 93.511 + } 93.512 + 93.513 private static GuardedInvocation findMegaMorphicSetMethod(final CallSiteDescriptor desc, final String name) { 93.514 final MethodType type = desc.getMethodType().insertParameterTypes(1, Object.class); 93.515 final GuardedInvocation inv = findSetIndexMethod(type, NashornCallSiteDescriptor.isStrict(desc)); 93.516 @@ -1998,7 +2035,7 @@ 93.517 return noSuchProperty(desc, request); 93.518 } 93.519 93.520 - final Object value = getObjectValue(find); 93.521 + final Object value = find.getObjectValue(); 93.522 if (! (value instanceof ScriptFunction)) { 93.523 return createEmptyGetter(desc, name); 93.524 } 93.525 @@ -2024,7 +2061,7 @@ 93.526 final boolean scopeAccess = isScope() && NashornCallSiteDescriptor.isScope(desc); 93.527 93.528 if (find != null) { 93.529 - final Object value = getObjectValue(find); 93.530 + final Object value = find.getObjectValue(); 93.531 ScriptFunction func = null; 93.532 MethodHandle methodHandle = null; 93.533 93.534 @@ -2038,7 +2075,7 @@ 93.535 methodHandle = bindTo(methodHandle, UNDEFINED); 93.536 } 93.537 return new GuardedInvocation(methodHandle, 93.538 - find.isInherited()? getMap().getProtoGetSwitchPoint(proto, NO_SUCH_PROPERTY_NAME) : null, 93.539 + getProtoSwitchPoint(NO_SUCH_PROPERTY_NAME, find.getOwner()), 93.540 getKnownFunctionPropertyGuard(getMap(), find.getGetter(Object.class), find.getOwner(), func)); 93.541 } 93.542 } 93.543 @@ -2049,16 +2086,17 @@ 93.544 93.545 return createEmptyGetter(desc, name); 93.546 } 93.547 + 93.548 /** 93.549 * Invoke fall back if a property is not found. 93.550 * @param name Name of property. 93.551 * @return Result from call. 93.552 */ 93.553 - private Object invokeNoSuchProperty(final String name) { 93.554 + protected Object invokeNoSuchProperty(final String name) { 93.555 final FindProperty find = findProperty(NO_SUCH_PROPERTY_NAME, true); 93.556 93.557 if (find != null) { 93.558 - final Object func = getObjectValue(find); 93.559 + final Object func = find.getObjectValue(); 93.560 93.561 if (func instanceof ScriptFunction) { 93.562 return ScriptRuntime.apply((ScriptFunction)func, this, name); 93.563 @@ -2080,7 +2118,7 @@ 93.564 return invokeNoSuchProperty(name); 93.565 } 93.566 93.567 - final Object value = getObjectValue(find); 93.568 + final Object value = find.getObjectValue(); 93.569 if (! (value instanceof ScriptFunction)) { 93.570 return UNDEFINED; 93.571 } 93.572 @@ -2089,7 +2127,8 @@ 93.573 } 93.574 93.575 private GuardedInvocation createEmptyGetter(final CallSiteDescriptor desc, final String name) { 93.576 - return new GuardedInvocation(Lookup.emptyGetter(desc.getMethodType().returnType()), getMap().getProtoGetSwitchPoint(proto, name), NashornGuards.getMapGuard(getMap())); 93.577 + return new GuardedInvocation(Lookup.emptyGetter(desc.getMethodType().returnType()), 93.578 + getProtoSwitchPoint(name, null), NashornGuards.getMapGuard(getMap())); 93.579 } 93.580 93.581 private abstract static class ScriptObjectIterator <T extends Object> implements Iterator<T> { 93.582 @@ -2170,12 +2209,10 @@ 93.583 93.584 if (fieldCount < fieldMaximum) { 93.585 property = new AccessorProperty(key, propertyFlags & ~Property.IS_SPILL, getClass(), fieldCount); 93.586 - notifyPropertyAdded(this, property); 93.587 property = addOwnProperty(property); 93.588 } else { 93.589 int i = getMap().getSpillLength(); 93.590 property = new AccessorProperty(key, propertyFlags | Property.IS_SPILL, i); 93.591 - notifyPropertyAdded(this, property); 93.592 property = addOwnProperty(property); 93.593 i = property.getSlot(); 93.594 93.595 @@ -2621,7 +2658,7 @@ 93.596 final FindProperty find = object.findProperty(key, false, false, this); 93.597 93.598 if (find != null) { 93.599 - return getObjectValue(find); 93.600 + return find.getObjectValue(); 93.601 } 93.602 } 93.603 93.604 @@ -2639,7 +2676,7 @@ 93.605 final FindProperty find = findProperty(key, true); 93.606 93.607 if (find != null) { 93.608 - return getObjectValue(find); 93.609 + return find.getObjectValue(); 93.610 } 93.611 } 93.612 93.613 @@ -2703,9 +2740,7 @@ 93.614 * @param strict are we in strict mode 93.615 */ 93.616 private void doesNotHave(final int index, final Object value, final boolean strict) { 93.617 - final long oldLength = getArray().length(); 93.618 final long longIndex = ArrayIndex.toLongIndex(index); 93.619 - 93.620 if (getMap().containsArrayKeys()) { 93.621 final String key = JSType.toString(longIndex); 93.622 final FindProperty find = findProperty(key, true); 93.623 @@ -2716,6 +2751,18 @@ 93.624 } 93.625 } 93.626 93.627 + setValueAtArrayIndex(longIndex, index, value, strict); 93.628 + } 93.629 + 93.630 + /** 93.631 + * Handle when an array doesn't have a slot - possibly grow and/or convert array. 93.632 + * 93.633 + * @param index key as index 93.634 + * @param value element value 93.635 + * @param strict are we in strict mode 93.636 + */ 93.637 + private void setValueAtArrayIndex(final long longIndex, final int index, final Object value, final boolean strict) { 93.638 + final long oldLength = getArray().length(); 93.639 if (longIndex >= oldLength) { 93.640 if (!isExtensible()) { 93.641 if (strict) { 93.642 @@ -2759,7 +2806,8 @@ 93.643 public final void setObject(final FindProperty find, final boolean strict, final String key, final Object value) { 93.644 FindProperty f = find; 93.645 93.646 - if (f != null && f.isInherited() && !(f.getProperty() instanceof UserAccessorProperty)) { 93.647 + if (f != null && f.isInherited() && !(f.getProperty() instanceof UserAccessorProperty) && !isScope()) { 93.648 + // Setting a property should not modify the property in prototype unless this is a scope object. 93.649 f = null; 93.650 } 93.651 93.652 @@ -2779,7 +2827,15 @@ 93.653 throw typeError("object.non.extensible", key, ScriptRuntime.safeToString(this)); 93.654 } 93.655 } else { 93.656 - spill(key, value); 93.657 + ScriptObject sobj = this; 93.658 + // undefined scope properties are set in the global object. 93.659 + if (isScope()) { 93.660 + while (sobj != null && !(sobj instanceof Global)) { 93.661 + sobj = sobj.getProto(); 93.662 + } 93.663 + assert sobj != null : "no parent global object in scope"; 93.664 + } 93.665 + sobj.spill(key, value); 93.666 } 93.667 } 93.668 93.669 @@ -3228,7 +3284,6 @@ 93.670 } 93.671 93.672 final Property prop = find.getProperty(); 93.673 - notifyPropertyDeleted(this, prop); 93.674 deleteOwnProperty(prop); 93.675 93.676 return true;
94.1 --- a/src/jdk/nashorn/internal/runtime/ScriptRuntime.java Wed Mar 26 12:01:34 2014 -0700 94.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptRuntime.java Tue Apr 01 11:44:05 2014 -0700 94.3 @@ -474,7 +474,7 @@ 94.4 * @return {@link WithObject} that is the new scope 94.5 */ 94.6 public static ScriptObject openWith(final ScriptObject scope, final Object expression) { 94.7 - final ScriptObject global = Context.getGlobalTrusted(); 94.8 + final Global global = Context.getGlobal(); 94.9 if (expression == UNDEFINED) { 94.10 throw typeError(global, "cant.apply.with.to.undefined"); 94.11 } else if (expression == null) {
95.1 --- a/src/jdk/nashorn/internal/runtime/SetMethodCreator.java Wed Mar 26 12:01:34 2014 -0700 95.2 +++ b/src/jdk/nashorn/internal/runtime/SetMethodCreator.java Tue Apr 01 11:44:05 2014 -0700 95.3 @@ -31,7 +31,6 @@ 95.4 import java.lang.invoke.MethodHandle; 95.5 import jdk.internal.dynalink.CallSiteDescriptor; 95.6 import jdk.internal.dynalink.linker.GuardedInvocation; 95.7 -import jdk.nashorn.internal.codegen.ObjectClassGenerator; 95.8 import jdk.nashorn.internal.lookup.Lookup; 95.9 import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor; 95.10 import jdk.nashorn.internal.runtime.linker.NashornGuards; 95.11 @@ -80,7 +79,7 @@ 95.12 } 95.13 95.14 /** 95.15 - * This class encapsulates the results of looking up a setter method; it's basically a triple of a method hanle, 95.16 + * This class encapsulates the results of looking up a setter method; it's basically a triple of a method handle, 95.17 * a Property object, and flags for invocation. 95.18 * 95.19 */ 95.20 @@ -104,21 +103,9 @@ 95.21 * @return the composed guarded invocation that represents the dynamic setter method for the property. 95.22 */ 95.23 GuardedInvocation createGuardedInvocation() { 95.24 - return new GuardedInvocation(methodHandle, getGuard()); 95.25 + return new GuardedInvocation(methodHandle, NashornGuards.getGuard(sobj, property, desc)); 95.26 } 95.27 95.28 - private MethodHandle getGuard() { 95.29 - return needsNoGuard() ? null : NashornGuards.getMapGuard(getMap()); 95.30 - } 95.31 - 95.32 - private boolean needsNoGuard() { 95.33 - return NashornCallSiteDescriptor.isFastScope(desc) && 95.34 - (ObjectClassGenerator.OBJECT_FIELDS_ONLY || isPropertyTypeStable()); 95.35 - } 95.36 - 95.37 - private boolean isPropertyTypeStable() { 95.38 - return property == null || !property.canChangeType(); 95.39 - } 95.40 } 95.41 95.42 private SetMethod createSetMethod() { 95.43 @@ -151,10 +138,9 @@ 95.44 assert methodHandle != null; 95.45 assert property != null; 95.46 95.47 - final ScriptObject prototype = find.getOwner(); 95.48 final MethodHandle boundHandle; 95.49 - if (!property.hasSetterFunction(prototype) && find.isInherited()) { 95.50 - boundHandle = ScriptObject.bindTo(methodHandle, prototype); 95.51 + if (!property.hasSetterFunction(find.getOwner()) && find.isInherited()) { 95.52 + boundHandle = ScriptObject.addProtoFilter(methodHandle, find.getProtoChainLength()); 95.53 } else { 95.54 boundHandle = methodHandle; 95.55 } 95.56 @@ -162,13 +148,16 @@ 95.57 } 95.58 95.59 private SetMethod createGlobalPropertySetter() { 95.60 - final ScriptObject global = Context.getGlobalTrusted(); 95.61 - return new SetMethod(ScriptObject.bindTo(global.addSpill(getName()), global), null); 95.62 + final ScriptObject global = Context.getGlobal(); 95.63 + return new SetMethod(MH.filterArguments(global.addSpill(getName()), 0, ScriptObject.GLOBALFILTER), null); 95.64 } 95.65 95.66 private SetMethod createNewPropertySetter() { 95.67 final SetMethod sm = map.getFieldCount() < map.getFieldMaximum() ? createNewFieldSetter() : createNewSpillPropertySetter(); 95.68 - sobj.notifyPropertyAdded(sobj, sm.property); 95.69 + final PropertyListeners listeners = map.getListeners(); 95.70 + if (listeners != null) { 95.71 + listeners.propertyAdded(sm.property); 95.72 + } 95.73 return sm; 95.74 } 95.75
96.1 --- a/src/jdk/nashorn/internal/runtime/UserAccessorProperty.java Wed Mar 26 12:01:34 2014 -0700 96.2 +++ b/src/jdk/nashorn/internal/runtime/UserAccessorProperty.java Tue Apr 01 11:44:05 2014 -0700 96.3 @@ -34,6 +34,7 @@ 96.4 import jdk.nashorn.internal.runtime.linker.Bootstrap; 96.5 96.6 import static jdk.nashorn.internal.codegen.CompilerConstants.staticCall; 96.7 +import jdk.nashorn.internal.objects.Global; 96.8 import static jdk.nashorn.internal.runtime.ECMAErrors.typeError; 96.9 import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED; 96.10 96.11 @@ -73,7 +74,7 @@ 96.12 96.13 private static MethodHandle getINVOKE_UA_GETTER() { 96.14 96.15 - return ((GlobalObject)Context.getGlobal()).getDynamicInvoker(INVOKE_UA_GETTER, 96.16 + return Context.getGlobal().getDynamicInvoker(INVOKE_UA_GETTER, 96.17 new Callable<MethodHandle>() { 96.18 @Override 96.19 public MethodHandle call() { 96.20 @@ -86,7 +87,7 @@ 96.21 /** Dynamic invoker for setter */ 96.22 private static Object INVOKE_UA_SETTER = new Object(); 96.23 private static MethodHandle getINVOKE_UA_SETTER() { 96.24 - return ((GlobalObject)Context.getGlobal()).getDynamicInvoker(INVOKE_UA_SETTER, 96.25 + return Context.getGlobal().getDynamicInvoker(INVOKE_UA_SETTER, 96.26 new Callable<MethodHandle>() { 96.27 @Override 96.28 public MethodHandle call() {
97.1 --- a/src/jdk/nashorn/internal/runtime/WithObject.java Wed Mar 26 12:01:34 2014 -0700 97.2 +++ b/src/jdk/nashorn/internal/runtime/WithObject.java Tue Apr 01 11:44:05 2014 -0700 97.3 @@ -36,6 +36,7 @@ 97.4 import jdk.internal.dynalink.linker.LinkRequest; 97.5 import jdk.internal.dynalink.support.CallSiteDescriptorFactory; 97.6 import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor; 97.7 +import jdk.nashorn.internal.runtime.linker.NashornGuards; 97.8 97.9 /** 97.10 * This class supports the handling of scope in a with body. 97.11 @@ -87,6 +88,11 @@ 97.12 97.13 @Override 97.14 public GuardedInvocation lookup(final CallSiteDescriptor desc, final LinkRequest request) { 97.15 + if (request.isCallSiteUnstable()) { 97.16 + // Fall back to megamorphic invocation which performs a complete lookup each time without further relinking. 97.17 + return super.lookup(desc, request); 97.18 + } 97.19 + 97.20 // With scopes can never be observed outside of Nashorn code, so all call sites that can address it will of 97.21 // necessity have a Nashorn descriptor - it is safe to cast. 97.22 final NashornCallSiteDescriptor ndesc = (NashornCallSiteDescriptor)desc; 97.23 @@ -123,7 +129,7 @@ 97.24 } 97.25 97.26 if (find != null) { 97.27 - return fixScopeCallSite(scope.lookup(desc, request), name); 97.28 + return fixScopeCallSite(scope.lookup(desc, request), name, find.getOwner()); 97.29 } 97.30 97.31 // the property is not found - now check for 97.32 @@ -175,7 +181,7 @@ 97.33 link = scope.lookup(desc, request); 97.34 97.35 if (link != null) { 97.36 - return fixScopeCallSite(link, name); 97.37 + return fixScopeCallSite(link, name, null); 97.38 } 97.39 97.40 return null; 97.41 @@ -252,13 +258,10 @@ 97.42 filterGuard(link, WITHEXPRESSIONFILTER)); 97.43 } 97.44 97.45 - private GuardedInvocation fixScopeCallSite(final GuardedInvocation link, final String name) { 97.46 + private GuardedInvocation fixScopeCallSite(final GuardedInvocation link, final String name, final ScriptObject owner) { 97.47 final GuardedInvocation newLink = fixReceiverType(link, WITHSCOPEFILTER); 97.48 return link.replaceMethods(filter(newLink.getInvocation(), WITHSCOPEFILTER), 97.49 - MH.guardWithTest( 97.50 - expressionGuard(name), 97.51 - filterGuard(newLink, WITHSCOPEFILTER), 97.52 - MH.dropArguments(MH.constant(boolean.class, false), 0, Object.class))); 97.53 + NashornGuards.combineGuards(expressionGuard(name, owner), filterGuard(newLink, WITHSCOPEFILTER))); 97.54 } 97.55 97.56 private static MethodHandle filterGuard(final GuardedInvocation link, final MethodHandle filter) { 97.57 @@ -267,7 +270,7 @@ 97.58 } 97.59 97.60 private static MethodHandle filter(final MethodHandle mh, final MethodHandle filter) { 97.61 - return MH.filterArguments(mh, 0, filter); 97.62 + return MH.filterArguments(mh, 0, filter.asType(filter.type().changeReturnType(mh.type().parameterType(0)))); 97.63 } 97.64 97.65 /** 97.66 @@ -288,9 +291,9 @@ 97.67 return fn.makeBoundFunction(withFilterExpression(receiver), new Object[0]); 97.68 } 97.69 97.70 - private MethodHandle expressionGuard(final String name) { 97.71 + private MethodHandle expressionGuard(final String name, final ScriptObject owner) { 97.72 final PropertyMap map = expression.getMap(); 97.73 - final SwitchPoint sp = map.getProtoGetSwitchPoint(expression.getProto(), name); 97.74 + final SwitchPoint sp = expression.getProtoSwitchPoint(name, owner); 97.75 return MH.insertArguments(WITHEXPRESSIONGUARD, 1, map, sp); 97.76 } 97.77
98.1 --- a/src/jdk/nashorn/internal/runtime/arrays/ArrayData.java Wed Mar 26 12:01:34 2014 -0700 98.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/ArrayData.java Tue Apr 01 11:44:05 2014 -0700 98.3 @@ -26,7 +26,8 @@ 98.4 package jdk.nashorn.internal.runtime.arrays; 98.5 98.6 import java.lang.invoke.MethodHandle; 98.7 -import jdk.nashorn.internal.runtime.GlobalObject; 98.8 +import java.nio.ByteBuffer; 98.9 +import jdk.nashorn.internal.objects.Global; 98.10 import jdk.nashorn.internal.runtime.JSType; 98.11 import jdk.nashorn.internal.runtime.PropertyDescriptor; 98.12 98.13 @@ -144,6 +145,16 @@ 98.14 } 98.15 98.16 /** 98.17 + * Allocate an ArrayData wrapping a given nio ByteBuffer 98.18 + * 98.19 + * @param buf the nio ByteBuffer to wrap 98.20 + * @return the ArrayData 98.21 + */ 98.22 + public static ArrayData allocate(final ByteBuffer buf) { 98.23 + return new ByteBufferArrayData((ByteBuffer)buf); 98.24 + } 98.25 + 98.26 + /** 98.27 * Apply a freeze filter to an ArrayData. 98.28 * 98.29 * @param underlying the underlying ArrayData to wrap in the freeze filter 98.30 @@ -388,7 +399,7 @@ 98.31 * 98.32 * @return property descriptor for element 98.33 */ 98.34 - public PropertyDescriptor getDescriptor(final GlobalObject global, final int index) { 98.35 + public PropertyDescriptor getDescriptor(final Global global, final int index) { 98.36 return global.newDataDescriptor(getObject(index), true, true, true); 98.37 } 98.38
99.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 99.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/ByteBufferArrayData.java Tue Apr 01 11:44:05 2014 -0700 99.3 @@ -0,0 +1,204 @@ 99.4 +/* 99.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 99.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 99.7 + * 99.8 + * This code is free software; you can redistribute it and/or modify it 99.9 + * under the terms of the GNU General Public License version 2 only, as 99.10 + * published by the Free Software Foundation. Oracle designates this 99.11 + * particular file as subject to the "Classpath" exception as provided 99.12 + * by Oracle in the LICENSE file that accompanied this code. 99.13 + * 99.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 99.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 99.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 99.17 + * version 2 for more details (a copy is included in the LICENSE file that 99.18 + * accompanied this code). 99.19 + * 99.20 + * You should have received a copy of the GNU General Public License version 99.21 + * 2 along with this work; if not, write to the Free Software Foundation, 99.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 99.23 + * 99.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 99.25 + * or visit www.oracle.com if you need additional information or have any 99.26 + * questions. 99.27 + */ 99.28 +package jdk.nashorn.internal.runtime.arrays; 99.29 + 99.30 +import static jdk.nashorn.internal.runtime.ECMAErrors.typeError; 99.31 + 99.32 +import java.nio.ByteBuffer; 99.33 +import jdk.nashorn.internal.objects.Global; 99.34 +import jdk.nashorn.internal.runtime.PropertyDescriptor; 99.35 +import jdk.nashorn.internal.runtime.ScriptRuntime; 99.36 + 99.37 +/** 99.38 + * Implementation of {@link ArrayData} that wraps a nio ByteBuffer 99.39 + */ 99.40 +final class ByteBufferArrayData extends ArrayData { 99.41 + private final ByteBuffer buf; 99.42 + 99.43 + ByteBufferArrayData(final int length) { 99.44 + super(length); 99.45 + this.buf = ByteBuffer.allocateDirect(length); 99.46 + } 99.47 + 99.48 + /** 99.49 + * Constructor 99.50 + * 99.51 + * @param buf ByteBuffer to create array data with. 99.52 + */ 99.53 + ByteBufferArrayData(final ByteBuffer buf) { 99.54 + super(buf.capacity()); 99.55 + this.buf = buf; 99.56 + } 99.57 + 99.58 + /** 99.59 + * Returns property descriptor for element at a given index 99.60 + * 99.61 + * @param global the global object 99.62 + * @param index the index 99.63 + * 99.64 + * @return property descriptor for element 99.65 + */ 99.66 + @Override 99.67 + public PropertyDescriptor getDescriptor(final Global global, final int index) { 99.68 + // make the index properties not configurable 99.69 + return global.newDataDescriptor(getObject(index), false, true, true); 99.70 + } 99.71 + 99.72 + @Override 99.73 + public ArrayData copy() { 99.74 + throw unsupported("copy"); 99.75 + } 99.76 + 99.77 + @Override 99.78 + public Object[] asObjectArray() { 99.79 + throw unsupported("asObjectArray"); 99.80 + } 99.81 + 99.82 + @Override 99.83 + public void setLength(final long length) { 99.84 + throw new UnsupportedOperationException("setLength"); 99.85 + } 99.86 + 99.87 + @Override 99.88 + public void shiftLeft(int by) { 99.89 + throw unsupported("shiftLeft"); 99.90 + } 99.91 + 99.92 + @Override 99.93 + public ArrayData shiftRight(int by) { 99.94 + throw unsupported("shiftRight"); 99.95 + } 99.96 + 99.97 + @Override 99.98 + public ArrayData ensure(long safeIndex) { 99.99 + if (safeIndex < buf.capacity()) { 99.100 + return this; 99.101 + } 99.102 + 99.103 + throw unsupported("ensure"); 99.104 + } 99.105 + 99.106 + @Override 99.107 + public ArrayData shrink(long newLength) { 99.108 + throw unsupported("shrink"); 99.109 + } 99.110 + 99.111 + @Override 99.112 + public ArrayData set(int index, Object value, boolean strict) { 99.113 + if (value instanceof Number) { 99.114 + buf.put(index, ((Number)value).byteValue()); 99.115 + return this; 99.116 + } 99.117 + 99.118 + throw typeError("not.a.number", ScriptRuntime.safeToString(value)); 99.119 + } 99.120 + 99.121 + @Override 99.122 + public ArrayData set(int index, int value, boolean strict) { 99.123 + buf.put(index, (byte)value); 99.124 + return this; 99.125 + } 99.126 + 99.127 + @Override 99.128 + public ArrayData set(int index, long value, boolean strict) { 99.129 + buf.put(index, (byte)value); 99.130 + return this; 99.131 + } 99.132 + 99.133 + @Override 99.134 + public ArrayData set(int index, double value, boolean strict) { 99.135 + buf.put(index, (byte)value); 99.136 + return this; 99.137 + } 99.138 + 99.139 + @Override 99.140 + public int getInt(int index) { 99.141 + return 0x0ff & buf.get(index); 99.142 + } 99.143 + 99.144 + @Override 99.145 + public long getLong(int index) { 99.146 + return 0x0ff & buf.get(index); 99.147 + } 99.148 + 99.149 + @Override 99.150 + public double getDouble(int index) { 99.151 + return 0x0ff & buf.get(index); 99.152 + } 99.153 + 99.154 + @Override 99.155 + public Object getObject(int index) { 99.156 + return (int)(0x0ff & buf.get(index)); 99.157 + } 99.158 + 99.159 + @Override 99.160 + public boolean has(int index) { 99.161 + return index > -1 && index < buf.capacity(); 99.162 + } 99.163 + 99.164 + @Override 99.165 + public boolean canDelete(final int index, final boolean strict) { 99.166 + return false; 99.167 + } 99.168 + 99.169 + @Override 99.170 + public boolean canDelete(final long fromIndex, final long toIndex, final boolean strict) { 99.171 + return false; 99.172 + } 99.173 + 99.174 + @Override 99.175 + public ArrayData delete(int index) { 99.176 + throw unsupported("delete"); 99.177 + } 99.178 + 99.179 + @Override 99.180 + public ArrayData delete(long fromIndex, long toIndex) { 99.181 + throw unsupported("delete"); 99.182 + } 99.183 + 99.184 + @Override 99.185 + public ArrayData push(final boolean strict, final Object... items) { 99.186 + throw unsupported("push"); 99.187 + } 99.188 + 99.189 + @Override 99.190 + public Object pop() { 99.191 + throw unsupported("pop"); 99.192 + } 99.193 + 99.194 + @Override 99.195 + public ArrayData slice(long from, long to) { 99.196 + throw unsupported("slice"); 99.197 + } 99.198 + 99.199 + @Override 99.200 + public ArrayData convert(final Class<?> type) { 99.201 + throw unsupported("convert"); 99.202 + } 99.203 + 99.204 + private UnsupportedOperationException unsupported(final String method) { 99.205 + return new UnsupportedOperationException(method); 99.206 + } 99.207 +}
100.1 --- a/src/jdk/nashorn/internal/runtime/arrays/FrozenArrayFilter.java Wed Mar 26 12:01:34 2014 -0700 100.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/FrozenArrayFilter.java Tue Apr 01 11:44:05 2014 -0700 100.3 @@ -25,9 +25,9 @@ 100.4 100.5 package jdk.nashorn.internal.runtime.arrays; 100.6 100.7 +import jdk.nashorn.internal.objects.Global; 100.8 import static jdk.nashorn.internal.runtime.ECMAErrors.typeError; 100.9 100.10 -import jdk.nashorn.internal.runtime.GlobalObject; 100.11 import jdk.nashorn.internal.runtime.PropertyDescriptor; 100.12 100.13 /** 100.14 @@ -44,7 +44,7 @@ 100.15 } 100.16 100.17 @Override 100.18 - public PropertyDescriptor getDescriptor(final GlobalObject global, final int index) { 100.19 + public PropertyDescriptor getDescriptor(final Global global, final int index) { 100.20 return global.newDataDescriptor(getObject(index), false, true, false); 100.21 } 100.22
101.1 --- a/src/jdk/nashorn/internal/runtime/arrays/SealedArrayFilter.java Wed Mar 26 12:01:34 2014 -0700 101.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/SealedArrayFilter.java Tue Apr 01 11:44:05 2014 -0700 101.3 @@ -25,9 +25,9 @@ 101.4 101.5 package jdk.nashorn.internal.runtime.arrays; 101.6 101.7 +import jdk.nashorn.internal.objects.Global; 101.8 import static jdk.nashorn.internal.runtime.ECMAErrors.typeError; 101.9 101.10 -import jdk.nashorn.internal.runtime.GlobalObject; 101.11 import jdk.nashorn.internal.runtime.PropertyDescriptor; 101.12 101.13 /** 101.14 @@ -62,7 +62,7 @@ 101.15 } 101.16 101.17 @Override 101.18 - public PropertyDescriptor getDescriptor(final GlobalObject global, final int index) { 101.19 + public PropertyDescriptor getDescriptor(final Global global, final int index) { 101.20 return global.newDataDescriptor(getObject(index), false, true, true); 101.21 } 101.22 }
102.1 --- a/src/jdk/nashorn/internal/runtime/linker/JavaAdapterBytecodeGenerator.java Wed Mar 26 12:01:34 2014 -0700 102.2 +++ b/src/jdk/nashorn/internal/runtime/linker/JavaAdapterBytecodeGenerator.java Tue Apr 01 11:44:05 2014 -0700 102.3 @@ -64,6 +64,7 @@ 102.4 import jdk.internal.org.objectweb.asm.Opcodes; 102.5 import jdk.internal.org.objectweb.asm.Type; 102.6 import jdk.internal.org.objectweb.asm.commons.InstructionAdapter; 102.7 +import jdk.nashorn.internal.objects.Global; 102.8 import jdk.nashorn.internal.runtime.Context; 102.9 import jdk.nashorn.internal.runtime.ScriptFunction; 102.10 import jdk.nashorn.internal.runtime.ScriptObject; 102.11 @@ -134,6 +135,7 @@ 102.12 static final Type CONTEXT_TYPE = Type.getType(Context.class); 102.13 static final Type OBJECT_TYPE = Type.getType(Object.class); 102.14 static final Type SCRIPT_OBJECT_TYPE = Type.getType(ScriptObject.class); 102.15 + static final Type GLOBAL_TYPE = Type.getType(Global.class); 102.16 102.17 static final String CONTEXT_TYPE_NAME = CONTEXT_TYPE.getInternalName(); 102.18 static final String OBJECT_TYPE_NAME = OBJECT_TYPE.getInternalName(); 102.19 @@ -143,8 +145,10 @@ 102.20 static final String GLOBAL_FIELD_NAME = "global"; 102.21 102.22 static final String SCRIPT_OBJECT_TYPE_DESCRIPTOR = SCRIPT_OBJECT_TYPE.getDescriptor(); 102.23 + static final String GLOBAL_TYPE_DESCRIPTOR = GLOBAL_TYPE.getDescriptor(); 102.24 102.25 - static final String SET_GLOBAL_METHOD_DESCRIPTOR = Type.getMethodDescriptor(Type.VOID_TYPE, SCRIPT_OBJECT_TYPE); 102.26 + 102.27 + static final String SET_GLOBAL_METHOD_DESCRIPTOR = Type.getMethodDescriptor(Type.VOID_TYPE, GLOBAL_TYPE); 102.28 static final String VOID_NOARG_METHOD_DESCRIPTOR = Type.getMethodDescriptor(Type.VOID_TYPE); 102.29 102.30 private static final Type SCRIPT_FUNCTION_TYPE = Type.getType(ScriptFunction.class); 102.31 @@ -167,7 +171,7 @@ 102.32 private static final String UNSUPPORTED_OPERATION_TYPE_NAME = UNSUPPORTED_OPERATION_TYPE.getInternalName(); 102.33 102.34 private static final String METHOD_HANDLE_TYPE_DESCRIPTOR = METHOD_HANDLE_TYPE.getDescriptor(); 102.35 - private static final String GET_GLOBAL_METHOD_DESCRIPTOR = Type.getMethodDescriptor(SCRIPT_OBJECT_TYPE); 102.36 + private static final String GET_GLOBAL_METHOD_DESCRIPTOR = Type.getMethodDescriptor(GLOBAL_TYPE); 102.37 private static final String GET_CLASS_METHOD_DESCRIPTOR = Type.getMethodDescriptor(Type.getType(Class.class)); 102.38 102.39 // Package used when the adapter can't be defined in the adaptee's package (either because it's sealed, or because 102.40 @@ -259,7 +263,7 @@ 102.41 } 102.42 102.43 private void generateGlobalFields() { 102.44 - cw.visitField(ACC_PRIVATE | ACC_FINAL | (classOverride ? ACC_STATIC : 0), GLOBAL_FIELD_NAME, SCRIPT_OBJECT_TYPE_DESCRIPTOR, null, null).visitEnd(); 102.45 + cw.visitField(ACC_PRIVATE | ACC_FINAL | (classOverride ? ACC_STATIC : 0), GLOBAL_FIELD_NAME, GLOBAL_TYPE_DESCRIPTOR, null, null).visitEnd(); 102.46 usedFieldNames.add(GLOBAL_FIELD_NAME); 102.47 } 102.48 102.49 @@ -321,7 +325,7 @@ 102.50 final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_STATIC, CLASS_INIT, 102.51 Type.getMethodDescriptor(Type.VOID_TYPE), null, null)); 102.52 102.53 - mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "getClassOverrides", GET_CLASS_INITIALIZER_DESCRIPTOR); 102.54 + mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "getClassOverrides", GET_CLASS_INITIALIZER_DESCRIPTOR, false); 102.55 final Label initGlobal; 102.56 if(samName != null) { 102.57 // If the class is a SAM, allow having a ScriptFunction passed as class overrides 102.58 @@ -337,7 +341,7 @@ 102.59 if(mi.getName().equals(samName)) { 102.60 mv.dup(); 102.61 mv.aconst(Type.getMethodType(mi.type.toMethodDescriptorString())); 102.62 - mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "getHandle", GET_HANDLE_FUNCTION_DESCRIPTOR); 102.63 + mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "getHandle", GET_HANDLE_FUNCTION_DESCRIPTOR, false); 102.64 } else { 102.65 mv.visitInsn(ACONST_NULL); 102.66 } 102.67 @@ -354,7 +358,7 @@ 102.68 mv.dup(); 102.69 mv.aconst(mi.getName()); 102.70 mv.aconst(Type.getMethodType(mi.type.toMethodDescriptorString())); 102.71 - mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "getHandle", GET_HANDLE_OBJECT_DESCRIPTOR); 102.72 + mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "getHandle", GET_HANDLE_OBJECT_DESCRIPTOR, false); 102.73 mv.putstatic(generatedClassName, mi.methodHandleFieldName, METHOD_HANDLE_TYPE_DESCRIPTOR); 102.74 } 102.75 102.76 @@ -363,7 +367,7 @@ 102.77 } 102.78 // Assign "global = Context.getGlobal()" 102.79 invokeGetGlobalWithNullCheck(mv); 102.80 - mv.putstatic(generatedClassName, GLOBAL_FIELD_NAME, SCRIPT_OBJECT_TYPE_DESCRIPTOR); 102.81 + mv.putstatic(generatedClassName, GLOBAL_FIELD_NAME, GLOBAL_TYPE_DESCRIPTOR); 102.82 102.83 endInitMethod(mv); 102.84 } 102.85 @@ -371,7 +375,7 @@ 102.86 private static void invokeGetGlobalWithNullCheck(final InstructionAdapter mv) { 102.87 invokeGetGlobal(mv); 102.88 mv.dup(); 102.89 - mv.invokevirtual(OBJECT_TYPE_NAME, "getClass", GET_CLASS_METHOD_DESCRIPTOR); // check against null Context 102.90 + mv.invokevirtual(OBJECT_TYPE_NAME, "getClass", GET_CLASS_METHOD_DESCRIPTOR, false); // check against null Context 102.91 mv.pop(); 102.92 } 102.93 102.94 @@ -428,7 +432,7 @@ 102.95 mv.load(offset, argType); 102.96 offset += argType.getSize(); 102.97 } 102.98 - mv.invokespecial(superClassName, INIT, originalCtorType.getDescriptor()); 102.99 + mv.invokespecial(superClassName, INIT, originalCtorType.getDescriptor(), false); 102.100 102.101 endInitMethod(mv); 102.102 } 102.103 @@ -481,7 +485,7 @@ 102.104 mv.load(offset, argType); 102.105 offset += argType.getSize(); 102.106 } 102.107 - mv.invokespecial(superClassName, INIT, originalCtorType.getDescriptor()); 102.108 + mv.invokespecial(superClassName, INIT, originalCtorType.getDescriptor(), false); 102.109 102.110 // Get a descriptor to the appropriate "JavaAdapterFactory.getHandle" method. 102.111 final String getHandleDescriptor = fromFunction ? GET_HANDLE_FUNCTION_DESCRIPTOR : GET_HANDLE_OBJECT_DESCRIPTOR; 102.112 @@ -500,7 +504,7 @@ 102.113 mv.aconst(mi.getName()); 102.114 } 102.115 mv.aconst(Type.getMethodType(mi.type.toMethodDescriptorString())); 102.116 - mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "getHandle", getHandleDescriptor); 102.117 + mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "getHandle", getHandleDescriptor, false); 102.118 } 102.119 mv.putfield(generatedClassName, mi.methodHandleFieldName, METHOD_HANDLE_TYPE_DESCRIPTOR); 102.120 } 102.121 @@ -508,7 +512,7 @@ 102.122 // Assign "this.global = Context.getGlobal()" 102.123 mv.visitVarInsn(ALOAD, 0); 102.124 invokeGetGlobalWithNullCheck(mv); 102.125 - mv.putfield(generatedClassName, GLOBAL_FIELD_NAME, SCRIPT_OBJECT_TYPE_DESCRIPTOR); 102.126 + mv.putfield(generatedClassName, GLOBAL_FIELD_NAME, GLOBAL_TYPE_DESCRIPTOR); 102.127 102.128 endInitMethod(mv); 102.129 } 102.130 @@ -524,11 +528,11 @@ 102.131 } 102.132 102.133 private static void invokeGetGlobal(final InstructionAdapter mv) { 102.134 - mv.invokestatic(CONTEXT_TYPE_NAME, "getGlobal", GET_GLOBAL_METHOD_DESCRIPTOR); 102.135 + mv.invokestatic(CONTEXT_TYPE_NAME, "getGlobal", GET_GLOBAL_METHOD_DESCRIPTOR, false); 102.136 } 102.137 102.138 private static void invokeSetGlobal(final InstructionAdapter mv) { 102.139 - mv.invokestatic(CONTEXT_TYPE_NAME, "setGlobal", SET_GLOBAL_METHOD_DESCRIPTOR); 102.140 + mv.invokestatic(CONTEXT_TYPE_NAME, "setGlobal", SET_GLOBAL_METHOD_DESCRIPTOR, false); 102.141 } 102.142 102.143 /** 102.144 @@ -641,21 +645,21 @@ 102.145 // If the super method is abstract, throw an exception 102.146 mv.anew(UNSUPPORTED_OPERATION_TYPE); 102.147 mv.dup(); 102.148 - mv.invokespecial(UNSUPPORTED_OPERATION_TYPE_NAME, INIT, VOID_NOARG_METHOD_DESCRIPTOR); 102.149 + mv.invokespecial(UNSUPPORTED_OPERATION_TYPE_NAME, INIT, VOID_NOARG_METHOD_DESCRIPTOR, false); 102.150 mv.athrow(); 102.151 } else { 102.152 // If the super method is not abstract, delegate to it. 102.153 - emitSuperCall(mv, name, methodDesc); 102.154 + emitSuperCall(mv, method.getDeclaringClass(), name, methodDesc); 102.155 } 102.156 102.157 mv.visitLabel(handleDefined); 102.158 // Load the creatingGlobal object 102.159 if(classOverride) { 102.160 // If class handle is defined, load the static defining global 102.161 - mv.getstatic(generatedClassName, GLOBAL_FIELD_NAME, SCRIPT_OBJECT_TYPE_DESCRIPTOR); 102.162 + mv.getstatic(generatedClassName, GLOBAL_FIELD_NAME, GLOBAL_TYPE_DESCRIPTOR); 102.163 } else { 102.164 mv.visitVarInsn(ALOAD, 0); 102.165 - mv.getfield(generatedClassName, GLOBAL_FIELD_NAME, SCRIPT_OBJECT_TYPE_DESCRIPTOR); 102.166 + mv.getfield(generatedClassName, GLOBAL_FIELD_NAME, GLOBAL_TYPE_DESCRIPTOR); 102.167 } 102.168 // stack: [creatingGlobal, handle] 102.169 final Label setupGlobal = new Label(); 102.170 @@ -674,7 +678,7 @@ 102.171 // stack: [creatingGlobal, creatingGlobal, handle] 102.172 102.173 // Emit code for switching to the creating global 102.174 - // ScriptObject currentGlobal = Context.getGlobal(); 102.175 + // Global currentGlobal = Context.getGlobal(); 102.176 invokeGetGlobal(mv); 102.177 mv.dup(); 102.178 102.179 @@ -715,7 +719,7 @@ 102.180 // Invoke the target method handle 102.181 final Label tryBlockStart = new Label(); 102.182 mv.visitLabel(tryBlockStart); 102.183 - mv.invokevirtual(METHOD_HANDLE_TYPE.getInternalName(), "invokeExact", type.toMethodDescriptorString()); 102.184 + mv.invokevirtual(METHOD_HANDLE_TYPE.getInternalName(), "invokeExact", type.toMethodDescriptorString(), false); 102.185 final Label tryBlockEnd = new Label(); 102.186 mv.visitLabel(tryBlockEnd); 102.187 emitFinally(mv, currentGlobalVar, globalsDifferVar); 102.188 @@ -731,7 +735,7 @@ 102.189 mv.anew(RUNTIME_EXCEPTION_TYPE); 102.190 mv.dupX1(); 102.191 mv.swap(); 102.192 - mv.invokespecial(RUNTIME_EXCEPTION_TYPE_NAME, INIT, Type.getMethodDescriptor(Type.VOID_TYPE, THROWABLE_TYPE)); 102.193 + mv.invokespecial(RUNTIME_EXCEPTION_TYPE_NAME, INIT, Type.getMethodDescriptor(Type.VOID_TYPE, THROWABLE_TYPE), false); 102.194 // Fall through to rethrow handler 102.195 } else { 102.196 throwableHandler = null; 102.197 @@ -744,7 +748,7 @@ 102.198 final Label methodEnd = new Label(); 102.199 mv.visitLabel(methodEnd); 102.200 102.201 - mv.visitLocalVariable("currentGlobal", SCRIPT_OBJECT_TYPE_DESCRIPTOR, null, setupGlobal, methodEnd, currentGlobalVar); 102.202 + mv.visitLocalVariable("currentGlobal", GLOBAL_TYPE_DESCRIPTOR, null, setupGlobal, methodEnd, currentGlobalVar); 102.203 mv.visitLocalVariable("globalsDiffer", Type.INT_TYPE.getDescriptor(), null, setupGlobal, methodEnd, globalsDifferVar); 102.204 102.205 if(throwableDeclared) { 102.206 @@ -817,12 +821,12 @@ 102.207 SUPER_PREFIX + name, methodDesc, null, getExceptionNames(method.getExceptionTypes()))); 102.208 mv.visitCode(); 102.209 102.210 - emitSuperCall(mv, name, methodDesc); 102.211 + emitSuperCall(mv, method.getDeclaringClass(), name, methodDesc); 102.212 102.213 endMethod(mv); 102.214 } 102.215 102.216 - private void emitSuperCall(final InstructionAdapter mv, final String name, final String methodDesc) { 102.217 + private void emitSuperCall(final InstructionAdapter mv, final Class owner, final String name, final String methodDesc) { 102.218 mv.visitVarInsn(ALOAD, 0); 102.219 int nextParam = 1; 102.220 final Type methodType = Type.getMethodType(methodDesc); 102.221 @@ -830,7 +834,13 @@ 102.222 mv.load(nextParam, t); 102.223 nextParam += t.getSize(); 102.224 } 102.225 - mv.invokespecial(superClassName, name, methodDesc); 102.226 + 102.227 + // default method - non-abstract, interface method 102.228 + if (Modifier.isInterface(owner.getModifiers())) { 102.229 + mv.invokespecial(Type.getInternalName(owner), name, methodDesc, false); 102.230 + } else { 102.231 + mv.invokespecial(superClassName, name, methodDesc, false); 102.232 + } 102.233 mv.areturn(methodType.getReturnType()); 102.234 } 102.235
103.1 --- a/src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java Wed Mar 26 12:01:34 2014 -0700 103.2 +++ b/src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java Tue Apr 01 11:44:05 2014 -0700 103.3 @@ -48,7 +48,6 @@ 103.4 import java.util.concurrent.ConcurrentHashMap; 103.5 import jdk.internal.dynalink.beans.StaticClass; 103.6 import jdk.internal.dynalink.support.LinkRequestImpl; 103.7 -import jdk.nashorn.internal.objects.NativeJava; 103.8 import jdk.nashorn.internal.runtime.Context; 103.9 import jdk.nashorn.internal.runtime.ECMAException; 103.10 import jdk.nashorn.internal.runtime.ScriptFunction; 103.11 @@ -68,8 +67,8 @@ 103.12 * generate the adapter class itself; see its documentation for details about the generated class. 103.13 * </p><p> 103.14 * You normally don't use this class directly, but rather either create adapters from script using 103.15 - * {@link NativeJava#extend(Object, Object...)}, using the {@code new} operator on abstract classes and interfaces (see 103.16 - * {@link NativeJava#type(Object, Object)}), or implicitly when passing script functions to Java methods expecting SAM 103.17 + * {@link jdk.nashorn.internal.objects.NativeJava#extend(Object, Object...)}, using the {@code new} operator on abstract classes and interfaces (see 103.18 + * {@link jdk.nashorn.internal.objects.NativeJava#type(Object, Object)}), or implicitly when passing script functions to Java methods expecting SAM 103.19 * types. 103.20 * </p> 103.21 */ 103.22 @@ -337,6 +336,7 @@ 103.23 private static ProtectionDomain createMinimalPermissionDomain() { 103.24 // Generated classes need to have at least the permission to access Nashorn runtime and runtime.linker packages. 103.25 final Permissions permissions = new Permissions(); 103.26 + permissions.add(new RuntimePermission("accessClassInPackage.jdk.nashorn.internal.objects")); 103.27 permissions.add(new RuntimePermission("accessClassInPackage.jdk.nashorn.internal.runtime")); 103.28 permissions.add(new RuntimePermission("accessClassInPackage.jdk.nashorn.internal.runtime.linker")); 103.29 return new ProtectionDomain(new CodeSource(null, (CodeSigner[])null), permissions);
104.1 --- a/src/jdk/nashorn/internal/runtime/linker/NashornGuards.java Wed Mar 26 12:01:34 2014 -0700 104.2 +++ b/src/jdk/nashorn/internal/runtime/linker/NashornGuards.java Tue Apr 01 11:44:05 2014 -0700 104.3 @@ -29,6 +29,11 @@ 104.4 104.5 import java.lang.invoke.MethodHandle; 104.6 import java.lang.invoke.MethodHandles; 104.7 +import java.lang.ref.WeakReference; 104.8 +import jdk.internal.dynalink.CallSiteDescriptor; 104.9 +import jdk.nashorn.internal.codegen.ObjectClassGenerator; 104.10 +import jdk.nashorn.internal.objects.Global; 104.11 +import jdk.nashorn.internal.runtime.Property; 104.12 import jdk.nashorn.internal.runtime.PropertyMap; 104.13 import jdk.nashorn.internal.runtime.ScriptFunction; 104.14 import jdk.nashorn.internal.runtime.ScriptObject; 104.15 @@ -37,10 +42,11 @@ 104.16 * Constructor of method handles used to guard call sites. 104.17 */ 104.18 public final class NashornGuards { 104.19 - private static final MethodHandle IS_SCRIPTOBJECT = findOwnMH("isScriptObject", boolean.class, Object.class); 104.20 - private static final MethodHandle IS_SCRIPTFUNCTION = findOwnMH("isScriptFunction", boolean.class, Object.class); 104.21 - private static final MethodHandle IS_MAP = findOwnMH("isMap", boolean.class, Object.class, PropertyMap.class); 104.22 - private static final MethodHandle IS_INSTANCEOF_2 = findOwnMH("isInstanceOf2", boolean.class, Object.class, Class.class, Class.class); 104.23 + private static final MethodHandle IS_SCRIPTOBJECT = findOwnMH("isScriptObject", boolean.class, Object.class); 104.24 + private static final MethodHandle IS_SCRIPTFUNCTION = findOwnMH("isScriptFunction", boolean.class, Object.class); 104.25 + private static final MethodHandle IS_MAP = findOwnMH("isMap", boolean.class, Object.class, PropertyMap.class); 104.26 + private static final MethodHandle SAME_OBJECT = findOwnMH("sameObject", boolean.class, Object.class, WeakReference.class); 104.27 + private static final MethodHandle IS_INSTANCEOF_2 = findOwnMH("isInstanceOf2", boolean.class, Object.class, Class.class, Class.class); 104.28 104.29 // don't create me! 104.30 private NashornGuards() { 104.31 @@ -75,6 +81,55 @@ 104.32 } 104.33 104.34 /** 104.35 + * Determine whether the given callsite needs a guard. 104.36 + * @param property the property, or null 104.37 + * @param desc the callsite descriptor 104.38 + * @return true if a guard should be used for this callsite 104.39 + */ 104.40 + static boolean needsGuard(final Property property, final CallSiteDescriptor desc) { 104.41 + return property == null || property.isConfigurable() 104.42 + || property.isBound() || !ObjectClassGenerator.OBJECT_FIELDS_ONLY 104.43 + || !NashornCallSiteDescriptor.isFastScope(desc) || property.canChangeType(); 104.44 + } 104.45 + 104.46 + /** 104.47 + * Get the guard for a property access. This returns an identity guard for non-configurable global properties 104.48 + * and a map guard for everything else. 104.49 + * 104.50 + * @param sobj the first object in the prototype chain 104.51 + * @param property the property 104.52 + * @param desc the callsite descriptor 104.53 + * @return method handle for guard 104.54 + */ 104.55 + public static MethodHandle getGuard(final ScriptObject sobj, final Property property, final CallSiteDescriptor desc) { 104.56 + if (!needsGuard(property, desc)) { 104.57 + return null; 104.58 + } 104.59 + if (NashornCallSiteDescriptor.isScope(desc)) { 104.60 + if (property != null && property.isBound()) { 104.61 + // This is a declared top level variables in main script or eval, use identity guard. 104.62 + return getIdentityGuard(sobj); 104.63 + } 104.64 + if (!(sobj instanceof Global) && (property == null || property.isConfigurable())) { 104.65 + // Undeclared variables in nested evals need stronger guards 104.66 + return combineGuards(getIdentityGuard(sobj), getMapGuard(sobj.getMap())); 104.67 + } 104.68 + } 104.69 + return getMapGuard(sobj.getMap()); 104.70 + } 104.71 + 104.72 + 104.73 + /** 104.74 + * Get a guard that checks referential identity of the current object. 104.75 + * 104.76 + * @param sobj the self object 104.77 + * @return true if same self object instance 104.78 + */ 104.79 + public static MethodHandle getIdentityGuard(final ScriptObject sobj) { 104.80 + return MH.insertArguments(SAME_OBJECT, 1, new WeakReference<>(sobj)); 104.81 + } 104.82 + 104.83 + /** 104.84 * Get a guard that checks if in item is an instance of either of two classes. 104.85 * 104.86 * @param class1 the first class 104.87 @@ -85,6 +140,17 @@ 104.88 return MH.insertArguments(IS_INSTANCEOF_2, 1, class1, class2); 104.89 } 104.90 104.91 + /** 104.92 + * Combine two method handles of type {@code (Object)boolean} using logical AND. 104.93 + * 104.94 + * @param guard1 the first guard 104.95 + * @param guard2 the second guard, only invoked if guard1 returns true 104.96 + * @return true if both guard1 and guard2 returned true 104.97 + */ 104.98 + public static MethodHandle combineGuards(final MethodHandle guard1, final MethodHandle guard2) { 104.99 + return MH.guardWithTest(guard1, guard2, MH.dropArguments(MH.constant(boolean.class, false), 0, Object.class)); 104.100 + } 104.101 + 104.102 @SuppressWarnings("unused") 104.103 private static boolean isScriptObject(final Object self) { 104.104 return self instanceof ScriptObject; 104.105 @@ -101,6 +167,11 @@ 104.106 } 104.107 104.108 @SuppressWarnings("unused") 104.109 + private static boolean sameObject(final Object self, final WeakReference<ScriptObject> ref) { 104.110 + return self == ref.get(); 104.111 + } 104.112 + 104.113 + @SuppressWarnings("unused") 104.114 private static boolean isInstanceOf2(final Object self, final Class<?> class1, final Class<?> class2) { 104.115 return class1.isInstance(self) || class2.isInstance(self); 104.116 }
105.1 --- a/src/jdk/nashorn/internal/runtime/linker/NashornPrimitiveLinker.java Wed Mar 26 12:01:34 2014 -0700 105.2 +++ b/src/jdk/nashorn/internal/runtime/linker/NashornPrimitiveLinker.java Tue Apr 01 11:44:05 2014 -0700 105.3 @@ -37,9 +37,9 @@ 105.4 import jdk.internal.dynalink.linker.LinkerServices; 105.5 import jdk.internal.dynalink.linker.TypeBasedGuardingDynamicLinker; 105.6 import jdk.internal.dynalink.support.TypeUtilities; 105.7 +import jdk.nashorn.internal.objects.Global; 105.8 import jdk.nashorn.internal.runtime.ConsString; 105.9 import jdk.nashorn.internal.runtime.Context; 105.10 -import jdk.nashorn.internal.runtime.GlobalObject; 105.11 105.12 /** 105.13 * Internal linker for String, Boolean, and Number objects, only ever used by Nashorn engine and not exposed to other 105.14 @@ -62,7 +62,7 @@ 105.15 final LinkRequest request = origRequest.withoutRuntimeContext(); // Nashorn has no runtime context 105.16 105.17 final Object self = request.getReceiver(); 105.18 - final GlobalObject global = (GlobalObject) Context.getGlobal(); 105.19 + final Global global = Context.getGlobal(); 105.20 final NashornCallSiteDescriptor desc = (NashornCallSiteDescriptor) request.getCallSiteDescriptor(); 105.21 105.22 return Bootstrap.asType(global.primitiveLookup(request, self), linkerServices, desc);
106.1 --- a/src/jdk/nashorn/internal/runtime/linker/PrimitiveLookup.java Wed Mar 26 12:01:34 2014 -0700 106.2 +++ b/src/jdk/nashorn/internal/runtime/linker/PrimitiveLookup.java Tue Apr 01 11:44:05 2014 -0700 106.3 @@ -35,6 +35,7 @@ 106.4 import jdk.internal.dynalink.support.CallSiteDescriptorFactory; 106.5 import jdk.internal.dynalink.support.Guards; 106.6 import jdk.nashorn.internal.lookup.Lookup; 106.7 +import jdk.nashorn.internal.runtime.FindProperty; 106.8 import jdk.nashorn.internal.runtime.ScriptObject; 106.9 106.10 /** 106.11 @@ -61,8 +62,9 @@ 106.12 * type {@code receiverClass}. 106.13 */ 106.14 public static GuardedInvocation lookupPrimitive(final LinkRequest request, final Class<?> receiverClass, 106.15 - final ScriptObject wrappedReceiver, final MethodHandle wrapFilter) { 106.16 - return lookupPrimitive(request, Guards.getInstanceOfGuard(receiverClass), wrappedReceiver, wrapFilter); 106.17 + final ScriptObject wrappedReceiver, final MethodHandle wrapFilter, 106.18 + final MethodHandle protoFilter) { 106.19 + return lookupPrimitive(request, Guards.getInstanceOfGuard(receiverClass), wrappedReceiver, wrapFilter, protoFilter); 106.20 } 106.21 106.22 /** 106.23 @@ -79,7 +81,8 @@ 106.24 * type (that is implied by both {@code guard} and {@code wrappedReceiver}). 106.25 */ 106.26 public static GuardedInvocation lookupPrimitive(final LinkRequest request, final MethodHandle guard, 106.27 - final ScriptObject wrappedReceiver, final MethodHandle wrapFilter) { 106.28 + final ScriptObject wrappedReceiver, final MethodHandle wrapFilter, 106.29 + final MethodHandle protoFilter) { 106.30 final CallSiteDescriptor desc = request.getCallSiteDescriptor(); 106.31 final String operator = CallSiteDescriptorFactory.tokenizeOperators(desc).get(0); 106.32 if ("setProp".equals(operator) || "setElem".equals(operator)) { 106.33 @@ -93,9 +96,23 @@ 106.34 106.35 if(desc.getNameTokenCount() > 2) { 106.36 final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND); 106.37 - if(wrappedReceiver.findProperty(name, true) == null) { 106.38 + final FindProperty find = wrappedReceiver.findProperty(name, true); 106.39 + if(find == null) { 106.40 // Give up early, give chance to BeanLinker and NashornBottomLinker to deal with it. 106.41 return null; 106.42 + } else if (find.isInherited() && !find.getProperty().hasGetterFunction(find.getOwner())) { 106.43 + // If property is found in the prototype object bind the method handle directly to 106.44 + // the proto filter instead of going through wrapper instantiation below. 106.45 + final ScriptObject proto = wrappedReceiver.getProto(); 106.46 + final GuardedInvocation link = proto.lookup(desc, request); 106.47 + 106.48 + if (link != null) { 106.49 + final MethodHandle invocation = link.getInvocation(); 106.50 + final MethodHandle adaptedInvocation = MH.asType(invocation, invocation.type().changeParameterType(0, Object.class)); 106.51 + final MethodHandle method = MH.filterArguments(adaptedInvocation, 0, protoFilter); 106.52 + final MethodHandle protoGuard = MH.filterArguments(link.getGuard(), 0, protoFilter); 106.53 + return new GuardedInvocation(method, NashornGuards.combineGuards(guard, protoGuard)); 106.54 + } 106.55 } 106.56 } 106.57 final GuardedInvocation link = wrappedReceiver.lookup(desc, request);
107.1 --- a/src/jdk/nashorn/internal/runtime/linker/ReflectionCheckLinker.java Wed Mar 26 12:01:34 2014 -0700 107.2 +++ b/src/jdk/nashorn/internal/runtime/linker/ReflectionCheckLinker.java Tue Apr 01 11:44:05 2014 -0700 107.3 @@ -93,7 +93,8 @@ 107.4 if ((self instanceof Class) && Modifier.isPublic(((Class<?>)self).getModifiers())) { 107.5 final CallSiteDescriptor desc = requestWithoutContext.getCallSiteDescriptor(); 107.6 if(CallSiteDescriptorFactory.tokenizeOperators(desc).contains("getProp")) { 107.7 - if ("static".equals(desc.getNameToken(CallSiteDescriptor.NAME_OPERAND))) { 107.8 + if (desc.getNameTokenCount() > CallSiteDescriptor.NAME_OPERAND && 107.9 + "static".equals(desc.getNameToken(CallSiteDescriptor.NAME_OPERAND))) { 107.10 if (Context.isAccessibleClass((Class<?>)self) && !isReflectionClass((Class<?>)self)) { 107.11 107.12 // If "getProp:static" passes access checks, allow access.
108.1 --- a/src/jdk/nashorn/internal/runtime/resources/Messages.properties Wed Mar 26 12:01:34 2014 -0700 108.2 +++ b/src/jdk/nashorn/internal/runtime/resources/Messages.properties Tue Apr 01 11:44:05 2014 -0700 108.3 @@ -78,6 +78,8 @@ 108.4 type.error.not.a.function={0} is not a function 108.5 type.error.not.a.constructor={0} is not a constructor function 108.6 type.error.not.a.file={0} is not a File 108.7 +type.error.not.a.bytebuffer={0} is not a java.nio.ByteBuffer 108.8 +type.error.not.an.arraybuffer.in.dataview=First arg to DataView constructor must be an ArrayBuffer 108.9 108.10 # operations not permitted on undefined 108.11 type.error.cant.call.undefined=Cannot call undefined 108.12 @@ -136,6 +138,9 @@ 108.13 type.error.method.not.constructor=Java method {0} can't be used as a constructor. 108.14 type.error.env.not.object=$ENV must be an Object. 108.15 type.error.unsupported.java.to.type=Unsupported Java.to target type {0}. 108.16 + 108.17 +range.error.dataview.constructor.offset=Wrong offset or length in DataView constructor 108.18 +range.error.dataview.offset=Offset is outside the bounds of the DataView 108.19 range.error.inappropriate.array.length=inappropriate array length: {0} 108.20 range.error.inappropriate.array.buffer.length=inappropriate array buffer length: {0} 108.21 range.error.invalid.fraction.digits=fractionDigits argument to {0} must be in [0, 20]
109.1 --- a/src/jdk/nashorn/internal/scripts/JO.java Wed Mar 26 12:01:34 2014 -0700 109.2 +++ b/src/jdk/nashorn/internal/scripts/JO.java Tue Apr 01 11:44:05 2014 -0700 109.3 @@ -33,7 +33,7 @@ 109.4 */ 109.5 public class JO extends ScriptObject { 109.6 109.7 - private static final PropertyMap map$ = PropertyMap.newMap().setIsShared(); 109.8 + private static final PropertyMap map$ = PropertyMap.newMap(); 109.9 109.10 /** 109.11 * Returns the initial property map to be used.
110.1 --- a/src/jdk/nashorn/tools/Shell.java Wed Mar 26 12:01:34 2014 -0700 110.2 +++ b/src/jdk/nashorn/tools/Shell.java Tue Apr 01 11:44:05 2014 -0700 110.3 @@ -42,6 +42,7 @@ 110.4 import jdk.nashorn.internal.ir.FunctionNode; 110.5 import jdk.nashorn.internal.ir.debug.ASTWriter; 110.6 import jdk.nashorn.internal.ir.debug.PrintVisitor; 110.7 +import jdk.nashorn.internal.objects.Global; 110.8 import jdk.nashorn.internal.parser.Parser; 110.9 import jdk.nashorn.internal.runtime.Context; 110.10 import jdk.nashorn.internal.runtime.ErrorManager; 110.11 @@ -148,7 +149,7 @@ 110.12 return COMMANDLINE_ERROR; 110.13 } 110.14 110.15 - final ScriptObject global = context.createGlobal(); 110.16 + final Global global = context.createGlobal(); 110.17 final ScriptEnvironment env = context.getEnv(); 110.18 final List<String> files = env.getFiles(); 110.19 if (files.isEmpty()) { 110.20 @@ -231,8 +232,8 @@ 110.21 * @return error code 110.22 * @throws IOException when any script file read results in I/O error 110.23 */ 110.24 - private static int compileScripts(final Context context, final ScriptObject global, final List<String> files) throws IOException { 110.25 - final ScriptObject oldGlobal = Context.getGlobal(); 110.26 + private static int compileScripts(final Context context, final Global global, final List<String> files) throws IOException { 110.27 + final Global oldGlobal = Context.getGlobal(); 110.28 final boolean globalChanged = (oldGlobal != global); 110.29 final ScriptEnvironment env = context.getEnv(); 110.30 try { 110.31 @@ -281,8 +282,8 @@ 110.32 * @return error code 110.33 * @throws IOException when any script file read results in I/O error 110.34 */ 110.35 - private int runScripts(final Context context, final ScriptObject global, final List<String> files) throws IOException { 110.36 - final ScriptObject oldGlobal = Context.getGlobal(); 110.37 + private int runScripts(final Context context, final Global global, final List<String> files) throws IOException { 110.38 + final Global oldGlobal = Context.getGlobal(); 110.39 final boolean globalChanged = (oldGlobal != global); 110.40 try { 110.41 if (globalChanged) { 110.42 @@ -339,8 +340,8 @@ 110.43 * @return error code 110.44 * @throws IOException when any script file read results in I/O error 110.45 */ 110.46 - private static int runFXScripts(final Context context, final ScriptObject global, final List<String> files) throws IOException { 110.47 - final ScriptObject oldGlobal = Context.getGlobal(); 110.48 + private static int runFXScripts(final Context context, final Global global, final List<String> files) throws IOException { 110.49 + final Global oldGlobal = Context.getGlobal(); 110.50 final boolean globalChanged = (oldGlobal != global); 110.51 try { 110.52 if (globalChanged) { 110.53 @@ -389,11 +390,11 @@ 110.54 * @return return code 110.55 */ 110.56 @SuppressWarnings("resource") 110.57 - private static int readEvalPrint(final Context context, final ScriptObject global) { 110.58 + private static int readEvalPrint(final Context context, final Global global) { 110.59 final String prompt = bundle.getString("shell.prompt"); 110.60 final BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); 110.61 final PrintWriter err = context.getErr(); 110.62 - final ScriptObject oldGlobal = Context.getGlobal(); 110.63 + final Global oldGlobal = Context.getGlobal(); 110.64 final boolean globalChanged = (oldGlobal != global); 110.65 final ScriptEnvironment env = context.getEnv(); 110.66
111.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 111.2 +++ b/test/script/basic/JDK-8011964.js Tue Apr 01 11:44:05 2014 -0700 111.3 @@ -0,0 +1,60 @@ 111.4 +/* 111.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 111.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 111.7 + * 111.8 + * This code is free software; you can redistribute it and/or modify it 111.9 + * under the terms of the GNU General Public License version 2 only, as 111.10 + * published by the Free Software Foundation. 111.11 + * 111.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 111.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 111.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 111.15 + * version 2 for more details (a copy is included in the LICENSE file that 111.16 + * accompanied this code). 111.17 + * 111.18 + * You should have received a copy of the GNU General Public License version 111.19 + * 2 along with this work; if not, write to the Free Software Foundation, 111.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 111.21 + * 111.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 111.23 + * or visit www.oracle.com if you need additional information or have any 111.24 + * questions. 111.25 + */ 111.26 + 111.27 +/** 111.28 + * JDK-8011964: need indexed access to externally-managed ByteBuffer 111.29 + * 111.30 + * @test 111.31 + * @run 111.32 + */ 111.33 + 111.34 + 111.35 +var ByteBuffer = Java.type("java.nio.ByteBuffer"); 111.36 +var buf = ByteBuffer.allocate(5); 111.37 + 111.38 +var obj = {} 111.39 +Object.setIndexedPropertiesToExternalArrayData(obj, buf); 111.40 + 111.41 +obj[0] = 'A'.charCodeAt(0); 111.42 +obj[1] = 'B'.charCodeAt(0); 111.43 +obj[2] = 'C'.charCodeAt(0); 111.44 +obj[3] = 'D'.charCodeAt(0); 111.45 +obj[4] = 'E'.charCodeAt(0); 111.46 + 111.47 +for (var i = 0; i < buf.capacity(); i++) { 111.48 + print("obj[" + i + "] = " + obj[i]); 111.49 + print("buf.get(" + i + ") = " + buf.get(i)); 111.50 +} 111.51 + 111.52 +var arr = []; 111.53 +Object.setIndexedPropertiesToExternalArrayData(arr, buf); 111.54 +obj[0] = 'a'.charCodeAt(0); 111.55 +obj[1] = 'b'.charCodeAt(0); 111.56 +obj[2] = 'c'.charCodeAt(0); 111.57 +obj[3] = 'd'.charCodeAt(0); 111.58 +obj[4] = 'e'.charCodeAt(0); 111.59 + 111.60 +for (var i in arr) { 111.61 + print("arr[" + i + "] = " + arr[i]); 111.62 + print("buf.get(" + i + ") = " + buf.get(i)); 111.63 +}
112.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 112.2 +++ b/test/script/basic/JDK-8011964.js.EXPECTED Tue Apr 01 11:44:05 2014 -0700 112.3 @@ -0,0 +1,20 @@ 112.4 +obj[0] = 65 112.5 +buf.get(0) = 65 112.6 +obj[1] = 66 112.7 +buf.get(1) = 66 112.8 +obj[2] = 67 112.9 +buf.get(2) = 67 112.10 +obj[3] = 68 112.11 +buf.get(3) = 68 112.12 +obj[4] = 69 112.13 +buf.get(4) = 69 112.14 +arr[0] = 97 112.15 +buf.get(0) = 97 112.16 +arr[1] = 98 112.17 +buf.get(1) = 98 112.18 +arr[2] = 99 112.19 +buf.get(2) = 99 112.20 +arr[3] = 100 112.21 +buf.get(3) = 100 112.22 +arr[4] = 101 112.23 +buf.get(4) = 101
113.1 --- a/test/script/basic/JDK-8025515.js Wed Mar 26 12:01:34 2014 -0700 113.2 +++ b/test/script/basic/JDK-8025515.js Tue Apr 01 11:44:05 2014 -0700 113.3 @@ -30,13 +30,23 @@ 113.4 113.5 // Make sure synthetic names of anonymous functions have correct line numbers 113.6 113.7 +function getFirstScriptFrame(stack) { 113.8 + for (frameNum in stack) { 113.9 + var frame = stack[frameNum]; 113.10 + if (frame.className.startsWith("jdk.nashorn.internal.scripts.Script$")) { 113.11 + return frame; 113.12 + } 113.13 + } 113.14 +} 113.15 + 113.16 function testMethodName(f, expected) { 113.17 try { 113.18 f(); 113.19 fail("expected error"); 113.20 } catch (e) { 113.21 - var stack = e.getStackTrace(); 113.22 - if (stack[0].methodName !== expected) { 113.23 + var stack = e.nashornException.getStackTrace(); 113.24 + var name = getFirstScriptFrame(stack).methodName; 113.25 + if (name !== expected) { 113.26 fail("got " + stack[0].methodName + ", expected " + expected); 113.27 } 113.28 } 113.29 @@ -44,15 +54,15 @@ 113.30 113.31 testMethodName(function() { 113.32 return a.b.c; 113.33 -}, "_L45"); 113.34 +}, "L:55"); 113.35 113.36 -testMethodName(function() { throw new Error() }, "_L49"); 113.37 +testMethodName(function() { throw new Error() }, "L:59"); 113.38 113.39 var f = (function() { 113.40 return function() { a.b.c; }; 113.41 })(); 113.42 -testMethodName(f, "_L51$_L52"); 113.43 +testMethodName(f, "L:61$L:62"); 113.44 113.45 testMethodName((function() { 113.46 return function() { return a.b.c; }; 113.47 -})(), "_L56$_L57"); 113.48 +})(), "L:66$L:67");
114.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 114.2 +++ b/test/script/basic/JDK-8029364.js Tue Apr 01 11:44:05 2014 -0700 114.3 @@ -0,0 +1,49 @@ 114.4 +/* 114.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 114.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 114.7 + * 114.8 + * This code is free software; you can redistribute it and/or modify it 114.9 + * under the terms of the GNU General Public License version 2 only, as 114.10 + * published by the Free Software Foundation. 114.11 + * 114.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 114.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 114.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 114.15 + * version 2 for more details (a copy is included in the LICENSE file that 114.16 + * accompanied this code). 114.17 + * 114.18 + * You should have received a copy of the GNU General Public License version 114.19 + * 2 along with this work; if not, write to the Free Software Foundation, 114.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 114.21 + * 114.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 114.23 + * or visit www.oracle.com if you need additional information or have any 114.24 + * questions. 114.25 + */ 114.26 + 114.27 +/** 114.28 + * JDK-8029364: NashornException to expose thrown object 114.29 + * 114.30 + * @test 114.31 + * @run 114.32 + */ 114.33 + 114.34 +var m = new javax.script.ScriptEngineManager(); 114.35 +var e = m.getEngineByName("nashorn"); 114.36 +var g = e.eval("this"); 114.37 +try { 114.38 + e.eval("var e = new Error('foo'); e.bar = 33; throw e"); 114.39 +} catch (se) { 114.40 + // ScriptException instance's cause is a NashornException 114.41 + print(se.getClass()); 114.42 + var cause = se.cause; 114.43 + print(cause.getClass()); 114.44 + // NashornException instance has 'ecmaError' bean getter 114.45 + print(cause.ecmaError); 114.46 + // access to underlying ECMA Error object 114.47 + print(cause.ecmaError instanceof g.Error); 114.48 + print(cause.ecmaError.name); 114.49 + print(cause.ecmaError.message); 114.50 + print(cause.ecmaError.bar); 114.51 +} 114.52 +
115.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 115.2 +++ b/test/script/basic/JDK-8029364.js.EXPECTED Tue Apr 01 11:44:05 2014 -0700 115.3 @@ -0,0 +1,7 @@ 115.4 +class javax.script.ScriptException 115.5 +class jdk.nashorn.internal.runtime.ECMAException 115.6 +Error: foo 115.7 +true 115.8 +Error 115.9 +foo 115.10 +33
116.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 116.2 +++ b/test/script/basic/JDK-8029667.js Tue Apr 01 11:44:05 2014 -0700 116.3 @@ -0,0 +1,91 @@ 116.4 +/* 116.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 116.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 116.7 + * 116.8 + * This code is free software; you can redistribute it and/or modify it 116.9 + * under the terms of the GNU General Public License version 2 only, as 116.10 + * published by the Free Software Foundation. 116.11 + * 116.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 116.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 116.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 116.15 + * version 2 for more details (a copy is included in the LICENSE file that 116.16 + * accompanied this code). 116.17 + * 116.18 + * You should have received a copy of the GNU General Public License version 116.19 + * 2 along with this work; if not, write to the Free Software Foundation, 116.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 116.21 + * 116.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 116.23 + * or visit www.oracle.com if you need additional information or have any 116.24 + * questions. 116.25 + */ 116.26 + 116.27 +/** 116.28 + * JDK-8029667: Prototype linking is incorrect 116.29 + * 116.30 + * @test 116.31 + * @run 116.32 + */ 116.33 + 116.34 +function f(x) { 116.35 + return (function inner() { 116.36 + var y; (function dummy() { return y })() // force own scope for the inner function 116.37 + with({}) { // 'with' block turns off fast scopes 116.38 + return x 116.39 + } 116.40 + })(); 116.41 +} 116.42 +print(f(1)); 116.43 +print(f(2)); 116.44 + 116.45 +function g(x) { 116.46 + (function inner() { 116.47 + var y; (function dummy() { return y })() // force own scope for the inner function 116.48 + with({}) { // 'with' block turns off fast scopes 116.49 + // Test setter as well as getter 116.50 + x = x + 2; 116.51 + } 116.52 + })(); 116.53 + print(x); 116.54 +} 116.55 + 116.56 +g(1); 116.57 +g(2); 116.58 + 116.59 +var withScopes = [{ func: function() { print("called 1");} }, { func: function() { print("called 2");} }]; 116.60 + 116.61 +for(var i in withScopes) { 116.62 + with (withScopes[i]) { 116.63 + var main = function() { 116.64 + var frame; // <---- this local variable caused scope to be not set properly prior to fix 116.65 + 116.66 + function callFunc() { 116.67 + frame = func(); 116.68 + } 116.69 + 116.70 + callFunc(); 116.71 + } 116.72 + } 116.73 + main(); 116.74 +} 116.75 + 116.76 +for(var i in withScopes) { 116.77 + with (withScopes[i]) { 116.78 + var main = function() { 116.79 + var frame; // <---- this local variable caused scope to be not set properly prior to fix 116.80 + 116.81 + function callFunc() { 116.82 + frame = func = i; 116.83 + } 116.84 + 116.85 + callFunc(); 116.86 + } 116.87 + } 116.88 + main(); 116.89 +} 116.90 + 116.91 +print(withScopes[0].func); 116.92 +print(withScopes[1].func); 116.93 + 116.94 +
117.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 117.2 +++ b/test/script/basic/JDK-8029667.js.EXPECTED Tue Apr 01 11:44:05 2014 -0700 117.3 @@ -0,0 +1,8 @@ 117.4 +1 117.5 +2 117.6 +3 117.7 +4 117.8 +called 1 117.9 +called 2 117.10 +0 117.11 +1
118.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 118.2 +++ b/test/script/basic/JDK-8030182.js Tue Apr 01 11:44:05 2014 -0700 118.3 @@ -0,0 +1,46 @@ 118.4 +/* 118.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 118.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 118.7 + * 118.8 + * This code is free software; you can redistribute it and/or modify it 118.9 + * under the terms of the GNU General Public License version 2 only, as 118.10 + * published by the Free Software Foundation. 118.11 + * 118.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 118.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 118.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 118.15 + * version 2 for more details (a copy is included in the LICENSE file that 118.16 + * accompanied this code). 118.17 + * 118.18 + * You should have received a copy of the GNU General Public License version 118.19 + * 2 along with this work; if not, write to the Free Software Foundation, 118.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 118.21 + * 118.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 118.23 + * or visit www.oracle.com if you need additional information or have any 118.24 + * questions. 118.25 + */ 118.26 + 118.27 +/** 118.28 + * JDK-8030182: scopeCall with -1 as line number 118.29 + * 118.30 + * @test 118.31 + * @run 118.32 + */ 118.33 + 118.34 +function func() { 118.35 + throw new Error("Strange..."); 118.36 +} 118.37 + 118.38 +var f2 = func; 118.39 +var f3 = func; 118.40 +var f4 = func; 118.41 +var f5 = func; 118.42 + 118.43 +// check that "scopeCall" or some such internal method 118.44 +// does not appear in script stack trace. 118.45 +try { 118.46 + func(); 118.47 +} catch(err) { 118.48 + print(err.stack.replace(/\\/g, '/')); 118.49 +}
119.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 119.2 +++ b/test/script/basic/JDK-8030182.js.EXPECTED Tue Apr 01 11:44:05 2014 -0700 119.3 @@ -0,0 +1,3 @@ 119.4 +Error: Strange... 119.5 + at func (test/script/basic/JDK-8030182.js:32) 119.6 + at <program> (test/script/basic/JDK-8030182.js:43)
120.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 120.2 +++ b/test/script/basic/JDK-8030182_2.js Tue Apr 01 11:44:05 2014 -0700 120.3 @@ -0,0 +1,46 @@ 120.4 +/* 120.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 120.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 120.7 + * 120.8 + * This code is free software; you can redistribute it and/or modify it 120.9 + * under the terms of the GNU General Public License version 2 only, as 120.10 + * published by the Free Software Foundation. 120.11 + * 120.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 120.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 120.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 120.15 + * version 2 for more details (a copy is included in the LICENSE file that 120.16 + * accompanied this code). 120.17 + * 120.18 + * You should have received a copy of the GNU General Public License version 120.19 + * 2 along with this work; if not, write to the Free Software Foundation, 120.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 120.21 + * 120.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 120.23 + * or visit www.oracle.com if you need additional information or have any 120.24 + * questions. 120.25 + */ 120.26 + 120.27 +/** 120.28 + * JDK-8030182: scopeCall with -1 as line number 120.29 + * 120.30 + * @test 120.31 + * @run 120.32 + */ 120.33 + 120.34 +var str = ""; 120.35 + 120.36 +// large code to force splitting 120.37 +for (i = 0; i < 1000; ++i) 120.38 + str +="o = new Object()\n"; 120.39 + 120.40 +str +="g()"; 120.41 + 120.42 +// check that "$split" or some such internal method 120.43 +// does not appear in script stack trace!! 120.44 +try { 120.45 + eval(str); 120.46 +} catch (e) { 120.47 + print(e.stack.replace(/\\/g, '/')); 120.48 +} 120.49 +
121.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 121.2 +++ b/test/script/basic/JDK-8030182_2.js.EXPECTED Tue Apr 01 11:44:05 2014 -0700 121.3 @@ -0,0 +1,3 @@ 121.4 +ReferenceError: "g" is not defined 121.5 + at <program> (test/script/basic/JDK-8030182_2.js#42:4<eval>@0:-1) 121.6 + at <program> (test/script/basic/JDK-8030182_2.js:42)
122.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 122.2 +++ b/test/script/basic/JDK-8030197.js Tue Apr 01 11:44:05 2014 -0700 122.3 @@ -0,0 +1,46 @@ 122.4 +/* 122.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 122.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 122.7 + * 122.8 + * This code is free software; you can redistribute it and/or modify it 122.9 + * under the terms of the GNU General Public License version 2 only, as 122.10 + * published by the Free Software Foundation. 122.11 + * 122.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 122.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 122.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 122.15 + * version 2 for more details (a copy is included in the LICENSE file that 122.16 + * accompanied this code). 122.17 + * 122.18 + * You should have received a copy of the GNU General Public License version 122.19 + * 2 along with this work; if not, write to the Free Software Foundation, 122.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 122.21 + * 122.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 122.23 + * or visit www.oracle.com if you need additional information or have any 122.24 + * questions. 122.25 + */ 122.26 + 122.27 + 122.28 +/** 122.29 + * JDK-8030197: Nashorn: Object.defineProperty() can be lured to change fixed NaN property 122.30 + * 122.31 + * @test 122.32 + * @run 122.33 + */ 122.34 + 122.35 +function str(n) { 122.36 + var a = new Uint8Array(new Float64Array([n]).buffer); 122.37 + return Array.apply(null, a).reduceRight( 122.38 + function(acc, v){ 122.39 + return acc + (v < 10 ? "0" : "") + v.toString(16); 122.40 + }, ""); 122.41 +} 122.42 + 122.43 +var o = Object.defineProperty({}, "NaN", { value: NaN }) 122.44 +var str1 = str(o.NaN); 122.45 +Object.defineProperty(o, "NaN", { value: 0/0 }) 122.46 +var str2 = str(o.NaN); 122.47 +if (str1 != str2) { 122.48 + fail("NaN bit pattern changed"); 122.49 +}
123.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 123.2 +++ b/test/script/basic/JDK-8030809.js Tue Apr 01 11:44:05 2014 -0700 123.3 @@ -0,0 +1,41 @@ 123.4 +/* 123.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 123.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 123.7 + * 123.8 + * This code is free software; you can redistribute it and/or modify it 123.9 + * under the terms of the GNU General Public License version 2 only, as 123.10 + * published by the Free Software Foundation. 123.11 + * 123.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 123.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 123.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 123.15 + * version 2 for more details (a copy is included in the LICENSE file that 123.16 + * accompanied this code). 123.17 + * 123.18 + * You should have received a copy of the GNU General Public License version 123.19 + * 2 along with this work; if not, write to the Free Software Foundation, 123.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 123.21 + * 123.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 123.23 + * or visit www.oracle.com if you need additional information or have any 123.24 + * questions. 123.25 + */ 123.26 + 123.27 +/** 123.28 + * JDK-8030809: Anonymous functions should not be shown with internal names in script stack trace 123.29 + * 123.30 + * @test 123.31 + * @run 123.32 + */ 123.33 + 123.34 +function func() { 123.35 + (function() { 123.36 + throw new Error(); 123.37 + })(); 123.38 +} 123.39 + 123.40 +try { 123.41 + func(); 123.42 +} catch (e) { 123.43 + print(e.stack.replace(/\\/g, '/')); 123.44 +}
124.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 124.2 +++ b/test/script/basic/JDK-8030809.js.EXPECTED Tue Apr 01 11:44:05 2014 -0700 124.3 @@ -0,0 +1,4 @@ 124.4 +Error 124.5 + at <anonymous> (test/script/basic/JDK-8030809.js:33) 124.6 + at func (test/script/basic/JDK-8030809.js:32) 124.7 + at <program> (test/script/basic/JDK-8030809.js:38)
125.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 125.2 +++ b/test/script/basic/JDK-8031317.js Tue Apr 01 11:44:05 2014 -0700 125.3 @@ -0,0 +1,41 @@ 125.4 +/* 125.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 125.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 125.7 + * 125.8 + * This code is free software; you can redistribute it and/or modify it 125.9 + * under the terms of the GNU General Public License version 2 only, as 125.10 + * published by the Free Software Foundation. 125.11 + * 125.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 125.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 125.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 125.15 + * version 2 for more details (a copy is included in the LICENSE file that 125.16 + * accompanied this code). 125.17 + * 125.18 + * You should have received a copy of the GNU General Public License version 125.19 + * 2 along with this work; if not, write to the Free Software Foundation, 125.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 125.21 + * 125.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 125.23 + * or visit www.oracle.com if you need additional information or have any 125.24 + * questions. 125.25 + */ 125.26 + 125.27 +/** 125.28 + * JDK-8031317: SyntaxError when property setter has no parameter 125.29 + * 125.30 + * @test 125.31 + * @run 125.32 + */ 125.33 + 125.34 +var obj = { 125.35 + get toto() { 125.36 + print("in getter for 'toto'"); 125.37 + }, 125.38 + set toto() { 125.39 + print("in setter for 'toto'"); 125.40 + } 125.41 +} 125.42 + 125.43 +obj.toto; 125.44 +obj.toto = 344;
126.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 126.2 +++ b/test/script/basic/JDK-8031317.js.EXPECTED Tue Apr 01 11:44:05 2014 -0700 126.3 @@ -0,0 +1,2 @@ 126.4 +in getter for 'toto' 126.5 +in setter for 'toto'
127.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 127.2 +++ b/test/script/basic/JDK-8031359.js Tue Apr 01 11:44:05 2014 -0700 127.3 @@ -0,0 +1,62 @@ 127.4 +/* 127.5 + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. 127.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 127.7 + * 127.8 + * This code is free software; you can redistribute it and/or modify it 127.9 + * under the terms of the GNU General Public License version 2 only, as 127.10 + * published by the Free Software Foundation. 127.11 + * 127.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 127.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 127.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 127.15 + * version 2 for more details (a copy is included in the LICENSE file that 127.16 + * accompanied this code). 127.17 + * 127.18 + * You should have received a copy of the GNU General Public License version 127.19 + * 2 along with this work; if not, write to the Free Software Foundation, 127.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 127.21 + * 127.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 127.23 + * or visit www.oracle.com if you need additional information or have any 127.24 + * questions. 127.25 + */ 127.26 + 127.27 +/** 127.28 + * JDK-8031359: Invocable.getInterface() works incorrectly if interface has default methods 127.29 + * 127.30 + * @test 127.31 + * @run 127.32 + */ 127.33 + 127.34 +var func = new java.util.function.Function() { 127.35 + apply: function(arg) { 127.36 + print("func called with " + arg); 127.37 + return arg.toUpperCase(); 127.38 + } 127.39 +}; 127.40 + 127.41 +// Function.andThen is a default method 127.42 +func.andThen(func)("hello"); 127.43 + 127.44 +// Function.compose is another default method 127.45 +func.compose(new java.util.function.Function() { 127.46 + apply: function(arg) { 127.47 + print("compose called with " + arg); 127.48 + return arg.charAt(0); 127.49 + } 127.50 +})("hello"); 127.51 + 127.52 +var func2 = new java.util.function.Function() { 127.53 + apply: function(arg) { 127.54 + print("I am func2: " + arg); 127.55 + return arg; 127.56 + }, 127.57 + 127.58 + andThen: function(func) { 127.59 + print("This is my andThen!"); 127.60 + return func; 127.61 + } 127.62 +}; 127.63 + 127.64 +func2.apply("hello"); 127.65 +func2.andThen(func);
128.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 128.2 +++ b/test/script/basic/JDK-8031359.js.EXPECTED Tue Apr 01 11:44:05 2014 -0700 128.3 @@ -0,0 +1,6 @@ 128.4 +func called with hello 128.5 +func called with HELLO 128.6 +compose called with hello 128.7 +func called with h 128.8 +I am func2: hello 128.9 +This is my andThen!
129.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 129.2 +++ b/test/script/basic/JDK-8031715.js Tue Apr 01 11:44:05 2014 -0700 129.3 @@ -0,0 +1,49 @@ 129.4 +/* 129.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 129.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 129.7 + * 129.8 + * This code is free software; you can redistribute it and/or modify it 129.9 + * under the terms of the GNU General Public License version 2 only, as 129.10 + * published by the Free Software Foundation. 129.11 + * 129.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 129.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 129.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 129.15 + * version 2 for more details (a copy is included in the LICENSE file that 129.16 + * accompanied this code). 129.17 + * 129.18 + * You should have received a copy of the GNU General Public License version 129.19 + * 2 along with this work; if not, write to the Free Software Foundation, 129.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 129.21 + * 129.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 129.23 + * or visit www.oracle.com if you need additional information or have any 129.24 + * questions. 129.25 + */ 129.26 + 129.27 +/** 129.28 + * JDK-8031715: Indexed access to java package not working 129.29 + * @test 129.30 + * @run 129.31 + */ 129.32 + 129.33 +print(java["net"]); 129.34 +print(java["net"]["URL"]); 129.35 +print(java["net"].URL); 129.36 +print(java.net["URL"]); 129.37 + 129.38 +var is = "InputStream"; 129.39 +var io = "io"; 129.40 + 129.41 +print(java.io[is]); 129.42 +print(java[io]); 129.43 +print(java[io][is]); 129.44 + 129.45 +var ji = new JavaImporter(java.util, java.io); 129.46 +print(ji["InputStream"]); 129.47 +print(ji['Vector']); 129.48 + 129.49 +var hash = "Hashtable"; 129.50 +var printStream = "PrintStream"; 129.51 +print(ji[hash]); 129.52 +print(ji[printStream]);
130.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 130.2 +++ b/test/script/basic/JDK-8031715.js.EXPECTED Tue Apr 01 11:44:05 2014 -0700 130.3 @@ -0,0 +1,11 @@ 130.4 +[JavaPackage java.net] 130.5 +[JavaClass java.net.URL] 130.6 +[JavaClass java.net.URL] 130.7 +[JavaClass java.net.URL] 130.8 +[JavaClass java.io.InputStream] 130.9 +[JavaPackage java.io] 130.10 +[JavaClass java.io.InputStream] 130.11 +[JavaClass java.io.InputStream] 130.12 +[JavaClass java.util.Vector] 130.13 +[JavaClass java.util.Hashtable] 130.14 +[JavaClass java.io.PrintStream]
131.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 131.2 +++ b/test/script/basic/JDK-8031983.js Tue Apr 01 11:44:05 2014 -0700 131.3 @@ -0,0 +1,55 @@ 131.4 +/* 131.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 131.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 131.7 + * 131.8 + * This code is free software; you can redistribute it and/or modify it 131.9 + * under the terms of the GNU General Public License version 2 only, as 131.10 + * published by the Free Software Foundation. 131.11 + * 131.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 131.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 131.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 131.15 + * version 2 for more details (a copy is included in the LICENSE file that 131.16 + * accompanied this code). 131.17 + * 131.18 + * You should have received a copy of the GNU General Public License version 131.19 + * 2 along with this work; if not, write to the Free Software Foundation, 131.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 131.21 + * 131.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 131.23 + * or visit www.oracle.com if you need additional information or have any 131.24 + * questions. 131.25 + */ 131.26 + 131.27 +/** 131.28 + * JDK-8031983: Error objects should capture stack at the constructor 131.29 + * 131.30 + * @test 131.31 + * @run 131.32 + */ 131.33 + 131.34 +var e = new Error(); 131.35 +print("hello"); 131.36 + 131.37 +try { 131.38 + throw e; 131.39 +} catch (e) { 131.40 + print(e.lineNumber); 131.41 + print(e.stack.replace(/\\/g, '/')); 131.42 +} 131.43 + 131.44 +Error.captureStackTrace(e); 131.45 +try { 131.46 + throw e; 131.47 +} catch (e) { 131.48 + print(e.lineNumber); 131.49 + print(e.stack.replace(/\\/g, '/')); 131.50 +} 131.51 + 131.52 +var obj = {}; 131.53 +Error.captureStackTrace(obj); 131.54 +try { 131.55 + throw obj; 131.56 +} catch (e) { 131.57 + print(e.stack.replace(/\\/g, '/')); 131.58 +}
132.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 132.2 +++ b/test/script/basic/JDK-8031983.js.EXPECTED Tue Apr 01 11:44:05 2014 -0700 132.3 @@ -0,0 +1,9 @@ 132.4 +hello 132.5 +35 132.6 +Error 132.7 + at <program> (test/script/basic/JDK-8031983.js:31) 132.8 +43 132.9 +Error 132.10 + at <program> (test/script/basic/JDK-8031983.js:41) 132.11 +[object Object] 132.12 + at <program> (test/script/basic/JDK-8031983.js:50)
133.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 133.2 +++ b/test/script/basic/JDK-8032004.js Tue Apr 01 11:44:05 2014 -0700 133.3 @@ -0,0 +1,43 @@ 133.4 +/* 133.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 133.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 133.7 + * 133.8 + * This code is free software; you can redistribute it and/or modify it 133.9 + * under the terms of the GNU General Public License version 2 only, as 133.10 + * published by the Free Software Foundation. 133.11 + * 133.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 133.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 133.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 133.15 + * version 2 for more details (a copy is included in the LICENSE file that 133.16 + * accompanied this code). 133.17 + * 133.18 + * You should have received a copy of the GNU General Public License version 133.19 + * 2 along with this work; if not, write to the Free Software Foundation, 133.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 133.21 + * 133.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 133.23 + * or visit www.oracle.com if you need additional information or have any 133.24 + * questions. 133.25 + */ 133.26 + 133.27 +/** 133.28 + * JDK-8032004: instance property "message" of Error objects should be non-enumerable 133.29 + * 133.30 + * @test 133.31 + * @run 133.32 + */ 133.33 + 133.34 +function check(obj) { 133.35 + if (obj.propertyIsEnumerable("message")) { 133.36 + fail(obj.name + " object's message property is enumerable!"); 133.37 + } 133.38 +} 133.39 + 133.40 +check(new Error("test")); 133.41 +check(new EvalError("test")); 133.42 +check(new RangeError("test")); 133.43 +check(new ReferenceError("test")); 133.44 +check(new SyntaxError("test")); 133.45 +check(new TypeError("test")); 133.46 +check(new URIError("test"));
134.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 134.2 +++ b/test/script/basic/JDK-8032068.js Tue Apr 01 11:44:05 2014 -0700 134.3 @@ -0,0 +1,56 @@ 134.4 +/* 134.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 134.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 134.7 + * 134.8 + * This code is free software; you can redistribute it and/or modify it 134.9 + * under the terms of the GNU General Public License version 2 only, as 134.10 + * published by the Free Software Foundation. 134.11 + * 134.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 134.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 134.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 134.15 + * version 2 for more details (a copy is included in the LICENSE file that 134.16 + * accompanied this code). 134.17 + * 134.18 + * You should have received a copy of the GNU General Public License version 134.19 + * 2 along with this work; if not, write to the Free Software Foundation, 134.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 134.21 + * 134.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 134.23 + * or visit www.oracle.com if you need additional information or have any 134.24 + * questions. 134.25 + */ 134.26 + 134.27 +/** 134.28 + * JDK-8032068: implement @sourceURL and #sourceURL directives. 134.29 + * 134.30 + * @test 134.31 + * @run 134.32 + */ 134.33 + 134.34 + 134.35 +try { 134.36 + Function("throw new Error();\n//# sourceURL=foo.js")(); 134.37 +} catch (e) { 134.38 + print(e.stack.replace(/\\/g, '/')); 134.39 +} 134.40 + 134.41 +try { 134.42 + eval("function g() { throw Error('x');\n } g();\n//# sourceURL=bar.js"); 134.43 +} catch (e) { 134.44 + print(e.stack.replace(/\\/g, '/')); 134.45 +} 134.46 + 134.47 +// check @sourceURL for compatibility 134.48 +try { 134.49 + Function("throw new Error();\n//@ sourceURL=foo2.js")(); 134.50 +} catch (e) { 134.51 + print(e.stack.replace(/\\/g, '/')); 134.52 +} 134.53 + 134.54 +try { 134.55 + eval("function g() { throw Error('x');\n } g();\n//@ sourceURL=bar2.js"); 134.56 +} catch (e) { 134.57 + print(e.stack.replace(/\\/g, '/')); 134.58 +} 134.59 +
135.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 135.2 +++ b/test/script/basic/JDK-8032068.js.EXPECTED Tue Apr 01 11:44:05 2014 -0700 135.3 @@ -0,0 +1,14 @@ 135.4 +Error 135.5 + at <anonymous> (foo.js:2) 135.6 + at <program> (test/script/basic/JDK-8032068.js:33) 135.7 +Error: x 135.8 + at g (bar.js:1) 135.9 + at <program> (bar.js:2) 135.10 + at <program> (test/script/basic/JDK-8032068.js:39) 135.11 +Error 135.12 + at <anonymous> (foo2.js:2) 135.13 + at <program> (test/script/basic/JDK-8032068.js:46) 135.14 +Error: x 135.15 + at g (bar2.js:1) 135.16 + at <program> (bar2.js:2) 135.17 + at <program> (test/script/basic/JDK-8032068.js:52)
136.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 136.2 +++ b/test/script/basic/JDK-8034055.js Tue Apr 01 11:44:05 2014 -0700 136.3 @@ -0,0 +1,55 @@ 136.4 +/* 136.5 + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. 136.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 136.7 + * 136.8 + * This code is free software; you can redistribute it and/or modify it 136.9 + * under the terms of the GNU General Public License version 2 only, as 136.10 + * published by the Free Software Foundation. 136.11 + * 136.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 136.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 136.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 136.15 + * version 2 for more details (a copy is included in the LICENSE file that 136.16 + * accompanied this code). 136.17 + * 136.18 + * You should have received a copy of the GNU General Public License version 136.19 + * 2 along with this work; if not, write to the Free Software Foundation, 136.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 136.21 + * 136.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 136.23 + * or visit www.oracle.com if you need additional information or have any 136.24 + * questions. 136.25 + */ 136.26 + 136.27 +/** 136.28 + * JDK-8034055: delete on global object not properly guarded 136.29 + * 136.30 + * @test 136.31 + * @run 136.32 + */ 136.33 + 136.34 + 136.35 +var global = this; 136.36 +var x; 136.37 + 136.38 +function test(defineGlobals) { 136.39 + if (defineGlobals) { 136.40 + global.x = 1; 136.41 + global.y = 2; 136.42 + } 136.43 + try { 136.44 + print(x); 136.45 + print(y); 136.46 + } catch (e) { 136.47 + print(e); 136.48 + } finally { 136.49 + print(delete global.x); 136.50 + print(delete global.y); 136.51 + } 136.52 +} 136.53 + 136.54 +// Repeatedly set and delete global variables 136.55 +test(true); 136.56 +test(false); 136.57 +test(true); 136.58 +test(false);
137.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 137.2 +++ b/test/script/basic/JDK-8034055.js.EXPECTED Tue Apr 01 11:44:05 2014 -0700 137.3 @@ -0,0 +1,16 @@ 137.4 +1 137.5 +2 137.6 +false 137.7 +true 137.8 +1 137.9 +ReferenceError: "y" is not defined 137.10 +false 137.11 +true 137.12 +1 137.13 +2 137.14 +false 137.15 +true 137.16 +1 137.17 +ReferenceError: "y" is not defined 137.18 +false 137.19 +true
138.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 138.2 +++ b/test/script/basic/JDK-8037562.js Tue Apr 01 11:44:05 2014 -0700 138.3 @@ -0,0 +1,41 @@ 138.4 +/* 138.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 138.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 138.7 + * 138.8 + * This code is free software; you can redistribute it and/or modify it 138.9 + * under the terms of the GNU General Public License version 2 only, as 138.10 + * published by the Free Software Foundation. 138.11 + * 138.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 138.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 138.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 138.15 + * version 2 for more details (a copy is included in the LICENSE file that 138.16 + * accompanied this code). 138.17 + * 138.18 + * You should have received a copy of the GNU General Public License version 138.19 + * 2 along with this work; if not, write to the Free Software Foundation, 138.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 138.21 + * 138.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 138.23 + * or visit www.oracle.com if you need additional information or have any 138.24 + * questions. 138.25 + */ 138.26 + 138.27 + 138.28 +/** 138.29 + * JDK-8037562: Nashorn: JSON.parse comes up with nonexistent entries if there are gaps between the keys 138.30 + * 138.31 + * @test 138.32 + * @run 138.33 + */ 138.34 + 138.35 +var strs = [ 138.36 + '{ "0":0, "2":2 }', 138.37 + '{ "0":"", "2":"" }', 138.38 + '{ "0":0, "5":"hello" }', 138.39 + '{ "0":"", "15":3234 }', 138.40 +] 138.41 + 138.42 +for (var i in strs) { 138.43 + print(JSON.stringify(JSON.parse(strs[i]))); 138.44 +}
139.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 139.2 +++ b/test/script/basic/JDK-8037562.js.EXPECTED Tue Apr 01 11:44:05 2014 -0700 139.3 @@ -0,0 +1,4 @@ 139.4 +{"0":0,"2":2} 139.5 +{"0":"","2":""} 139.6 +{"0":0,"5":"hello"} 139.7 +{"0":"","15":3234}
140.1 --- a/test/script/basic/NASHORN-111.js.EXPECTED Wed Mar 26 12:01:34 2014 -0700 140.2 +++ b/test/script/basic/NASHORN-111.js.EXPECTED Tue Apr 01 11:44:05 2014 -0700 140.3 @@ -1,1 +1,1 @@ 140.4 -{"message":"type error"} 140.5 +{}
141.1 --- a/test/script/basic/NASHORN-441.js.EXPECTED Wed Mar 26 12:01:34 2014 -0700 141.2 +++ b/test/script/basic/NASHORN-441.js.EXPECTED Tue Apr 01 11:44:05 2014 -0700 141.3 @@ -12,6 +12,6 @@ 141.4 try 5 141.5 rethrow 5 141.6 finally 5 141.7 -Error: try 5 thrown in line 71 141.8 +Error: try 5 thrown in line 74 141.9 try 6 141.10 finally 6
142.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 142.2 +++ b/test/script/basic/dataview_endian.js Tue Apr 01 11:44:05 2014 -0700 142.3 @@ -0,0 +1,70 @@ 142.4 +/* 142.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 142.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 142.7 + * 142.8 + * This code is free software; you can redistribute it and/or modify it 142.9 + * under the terms of the GNU General Public License version 2 only, as 142.10 + * published by the Free Software Foundation. 142.11 + * 142.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 142.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 142.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 142.15 + * version 2 for more details (a copy is included in the LICENSE file that 142.16 + * accompanied this code). 142.17 + * 142.18 + * You should have received a copy of the GNU General Public License version 142.19 + * 2 along with this work; if not, write to the Free Software Foundation, 142.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 142.21 + * 142.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 142.23 + * or visit www.oracle.com if you need additional information or have any 142.24 + * questions. 142.25 + */ 142.26 + 142.27 +/** 142.28 + * JDK-8015958: DataView constructor is not defined 142.29 + * 142.30 + * @test 142.31 + * @run 142.32 + */ 142.33 + 142.34 +// set/get endianess checks 142.35 + 142.36 +var buffer = new ArrayBuffer(4); 142.37 +var dv = new DataView(buffer); 142.38 + 142.39 +// write (default) big endian, read big/little endian 142.40 +dv.setUint16(0, 0xABCD); 142.41 +Assert.assertEquals(dv.getUint16(0), 0xABCD); 142.42 +Assert.assertEquals(dv.getUint16(0, false), 0xABCD); 142.43 +Assert.assertEquals(dv.getUint16(0, true), 0xCDAB); 142.44 + 142.45 +// write little endian, read big/little endian 142.46 +dv.setUint16(0, 0xABCD, true); 142.47 +Assert.assertEquals(dv.getUint16(0), 0xCDAB); 142.48 +Assert.assertEquals(dv.getUint16(0, false), 0xCDAB); 142.49 +Assert.assertEquals(dv.getUint16(0, true), 0xABCD); 142.50 + 142.51 +// write explicit big endian, read big/little endian 142.52 +dv.setUint16(0, 0xABCD, false); 142.53 +Assert.assertEquals(dv.getUint16(0), 0xABCD); 142.54 +Assert.assertEquals(dv.getUint16(0, false), 0xABCD); 142.55 +Assert.assertEquals(dv.getUint16(0, true), 0xCDAB); 142.56 + 142.57 +// write (default) big endian, read big/little endian 142.58 +dv.setUint32(0, 0xABCDEF89); 142.59 +Assert.assertEquals(dv.getUint32(0), 0xABCDEF89); 142.60 +Assert.assertEquals(dv.getUint32(0, false), 0xABCDEF89); 142.61 +Assert.assertEquals(dv.getUint32(0, true), 0x89EFCDAB); 142.62 + 142.63 +// write little endian, read big/little endian 142.64 +dv.setUint32(0, 0xABCDEF89, true); 142.65 +Assert.assertEquals(dv.getUint32(0), 0x89EFCDAB); 142.66 +Assert.assertEquals(dv.getUint32(0, false), 0x89EFCDAB); 142.67 +Assert.assertEquals(dv.getUint32(0, true), 0xABCDEF89); 142.68 + 142.69 +// write explicit big endian, read big/little endian 142.70 +dv.setUint32(0, 0xABCDEF89, false); 142.71 +Assert.assertEquals(dv.getUint32(0), 0xABCDEF89); 142.72 +Assert.assertEquals(dv.getUint32(0, false), 0xABCDEF89); 142.73 +Assert.assertEquals(dv.getUint32(0, true), 0x89EFCDAB);
143.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 143.2 +++ b/test/script/basic/dataview_getset.js Tue Apr 01 11:44:05 2014 -0700 143.3 @@ -0,0 +1,93 @@ 143.4 +/* 143.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 143.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 143.7 + * 143.8 + * This code is free software; you can redistribute it and/or modify it 143.9 + * under the terms of the GNU General Public License version 2 only, as 143.10 + * published by the Free Software Foundation. 143.11 + * 143.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 143.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 143.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 143.15 + * version 2 for more details (a copy is included in the LICENSE file that 143.16 + * accompanied this code). 143.17 + * 143.18 + * You should have received a copy of the GNU General Public License version 143.19 + * 2 along with this work; if not, write to the Free Software Foundation, 143.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 143.21 + * 143.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 143.23 + * or visit www.oracle.com if you need additional information or have any 143.24 + * questions. 143.25 + */ 143.26 + 143.27 +/** 143.28 + * JDK-8015958: DataView constructor is not defined 143.29 + * 143.30 + * @test 143.31 + * @run 143.32 + */ 143.33 + 143.34 +// checking get/set of values of various types 143.35 +// Also basic endianess check. 143.36 + 143.37 +var Float = Java.type("java.lang.Float"); 143.38 +var Double = Java.type("java.lang.Double"); 143.39 + 143.40 +var DOUBLE_MIN = Double.MIN_VALUE; 143.41 +var DOUBLE_MIN_NORMAL = Double.MIN_NORMAL; 143.42 +var FLOAT_MIN = Float.MIN_VALUE; 143.43 +var FLOAT_MIN_NORMAL = Float.MIN_NORMAL; 143.44 + 143.45 +var buffer = new ArrayBuffer(12); 143.46 +var dv = new DataView(buffer); 143.47 + 143.48 +dv.setInt8(1, 123); 143.49 +Assert.assertEquals(dv.getInt8(1), 123); 143.50 +dv.setInt8(1, 123, true); 143.51 +Assert.assertEquals(dv.getInt8(1, true), 123); 143.52 + 143.53 +dv.setUint8(1, 255); 143.54 +Assert.assertEquals(dv.getUint8(1), 255); 143.55 +dv.setUint8(1, 255, true); 143.56 +Assert.assertEquals(dv.getUint8(1, true), 255); 143.57 + 143.58 +dv.setInt16(1, 1234); 143.59 +Assert.assertEquals(dv.getInt16(1), 1234); 143.60 +dv.setInt16(1, 1234, true); 143.61 +Assert.assertEquals(dv.getInt16(1, true), 1234); 143.62 + 143.63 +dv.setUint16(1, 65535); 143.64 +Assert.assertEquals(dv.getUint16(1), 65535); 143.65 +dv.setUint16(1, 65535, true); 143.66 +Assert.assertEquals(dv.getUint16(1, true), 65535); 143.67 + 143.68 +dv.setInt32(1, 1234); 143.69 +Assert.assertEquals(dv.getInt32(1), 1234); 143.70 +dv.setInt32(1, 1234, true); 143.71 +Assert.assertEquals(dv.getInt32(1, true), 1234); 143.72 + 143.73 +dv.setUint32(1, 4294967295); 143.74 +Assert.assertEquals(dv.getUint32(1), 4294967295); 143.75 +dv.setUint32(1, 4294967295, true); 143.76 +Assert.assertEquals(dv.getUint32(1, true), 4294967295); 143.77 + 143.78 +dv.setFloat64(1, Math.PI); 143.79 +Assert.assertEquals(dv.getFloat64(1), Math.PI, DOUBLE_MIN); 143.80 +dv.setFloat64(1, Math.PI, true); 143.81 +Assert.assertEquals(dv.getFloat64(1, true), Math.PI, DOUBLE_MIN); 143.82 + 143.83 +dv.setFloat64(1, DOUBLE_MIN_NORMAL); 143.84 +Assert.assertEquals(dv.getFloat64(1), DOUBLE_MIN_NORMAL, DOUBLE_MIN); 143.85 +dv.setFloat64(1, DOUBLE_MIN_NORMAL, true); 143.86 +Assert.assertEquals(dv.getFloat64(1, true), DOUBLE_MIN_NORMAL, DOUBLE_MIN); 143.87 + 143.88 +dv.setFloat32(1, 1.414); 143.89 +Assert["assertEquals(float, float, float)"](dv.getFloat32(1), 1.414, FLOAT_MIN); 143.90 +dv.setFloat32(1, 1.414, true); 143.91 +Assert["assertEquals(float, float, float)"](dv.getFloat32(1, true), 1.414, FLOAT_MIN); 143.92 + 143.93 +dv.setFloat32(1, FLOAT_MIN_NORMAL); 143.94 +Assert["assertEquals(float, float, float)"](dv.getFloat32(1), FLOAT_MIN_NORMAL, FLOAT_MIN); 143.95 +dv.setFloat32(1, FLOAT_MIN_NORMAL, true); 143.96 +Assert["assertEquals(float, float, float)"](dv.getFloat32(1, true), FLOAT_MIN_NORMAL, FLOAT_MIN);
144.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 144.2 +++ b/test/script/basic/dataview_new.js Tue Apr 01 11:44:05 2014 -0700 144.3 @@ -0,0 +1,71 @@ 144.4 +/* 144.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 144.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 144.7 + * 144.8 + * This code is free software; you can redistribute it and/or modify it 144.9 + * under the terms of the GNU General Public License version 2 only, as 144.10 + * published by the Free Software Foundation. 144.11 + * 144.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 144.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 144.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 144.15 + * version 2 for more details (a copy is included in the LICENSE file that 144.16 + * accompanied this code). 144.17 + * 144.18 + * You should have received a copy of the GNU General Public License version 144.19 + * 2 along with this work; if not, write to the Free Software Foundation, 144.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 144.21 + * 144.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 144.23 + * or visit www.oracle.com if you need additional information or have any 144.24 + * questions. 144.25 + */ 144.26 + 144.27 +/** 144.28 + * JDK-8015958: DataView constructor is not defined 144.29 + * 144.30 + * @test 144.31 + * @run 144.32 + */ 144.33 + 144.34 +// basic DataView constructor checks. 144.35 + 144.36 +// check ArrayBufferView property values of DataView instance 144.37 +function check(dv, buf, offset, length) { 144.38 + if (dv.buffer !== buf) { 144.39 + fail("DataView.buffer is wrong"); 144.40 + } 144.41 + 144.42 + if (dv.byteOffset != offset) { 144.43 + fail("DataView.byteOffset = " + dv.byteOffset + ", expected " + offset); 144.44 + } 144.45 + 144.46 + if (dv.byteLength != length) { 144.47 + fail("DataView.byteLength = " + dv.byteLength + ", expected " + length); 144.48 + } 144.49 +} 144.50 + 144.51 +var buffer = new ArrayBuffer(12); 144.52 +check(new DataView(buffer), buffer, 0, 12); 144.53 +check(new DataView(buffer, 2), buffer, 2, 10); 144.54 +check(new DataView(buffer, 4, 8), buffer, 4, 8); 144.55 + 144.56 +// make sure expected error is thrown 144.57 +function checkError(callback, ErrorType) { 144.58 + try { 144.59 + callback(); 144.60 + fail("Should have thrown " + ErrorType.name); 144.61 + } catch (e) { 144.62 + if (! (e instanceof ErrorType)) { 144.63 + fail("Expected " + ErrorType.name + " got " + e); 144.64 + } 144.65 + } 144.66 +} 144.67 + 144.68 +// non ArrayBuffer as first arg 144.69 +checkError(function() { new DataView(344) }, TypeError); 144.70 + 144.71 +// illegal offset/length values 144.72 +checkError(function() { new DataView(buffer, -1) }, RangeError); 144.73 +checkError(function() { new DataView(buffer, 15) }, RangeError); 144.74 +checkError(function() { new DataView(buffer, 1, 32) }, RangeError);
145.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 145.2 +++ b/test/script/currently-failing/gettersetter.js Tue Apr 01 11:44:05 2014 -0700 145.3 @@ -0,0 +1,48 @@ 145.4 +/* 145.5 + * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved. 145.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 145.7 + * 145.8 + * This code is free software; you can redistribute it and/or modify it 145.9 + * under the terms of the GNU General Public License version 2 only, as 145.10 + * published by the Free Software Foundation. 145.11 + * 145.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 145.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 145.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 145.15 + * version 2 for more details (a copy is included in the LICENSE file that 145.16 + * accompanied this code). 145.17 + * 145.18 + * You should have received a copy of the GNU General Public License version 145.19 + * 2 along with this work; if not, write to the Free Software Foundation, 145.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 145.21 + * 145.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 145.23 + * or visit www.oracle.com if you need additional information or have any 145.24 + * questions. 145.25 + */ 145.26 + 145.27 +/** 145.28 + * @test 145.29 + * @option -Dnashorn.debug=true 145.30 + * @fork 145.31 + */ 145.32 + 145.33 +load(__DIR__ + "maputil.js"); 145.34 + 145.35 +function Foo() { 145.36 + return { 145.37 + get foo() { return 42; }, 145.38 + set foo(x) {} 145.39 + } 145.40 +} 145.41 + 145.42 +var obj1 = Foo(); 145.43 +var obj2 = Foo(); 145.44 + 145.45 +assertSameMap(obj1, obj2, "Object literals before change"); 145.46 + 145.47 +Object.defineProperty(obj2, "foo", { get: function() { return 'hello' } }); 145.48 +assertSameMap(obj1, obj2); 145.49 + 145.50 +Object.defineProperty(obj2, "foo", { set: function(x) { print(x) } }); 145.51 +assertSameMap(obj1, obj2);
146.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 146.2 +++ b/test/script/maptests/builtins.js Tue Apr 01 11:44:05 2014 -0700 146.3 @@ -0,0 +1,58 @@ 146.4 +/* 146.5 + * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved. 146.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 146.7 + * 146.8 + * This code is free software; you can redistribute it and/or modify it 146.9 + * under the terms of the GNU General Public License version 2 only, as 146.10 + * published by the Free Software Foundation. 146.11 + * 146.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 146.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 146.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 146.15 + * version 2 for more details (a copy is included in the LICENSE file that 146.16 + * accompanied this code). 146.17 + * 146.18 + * You should have received a copy of the GNU General Public License version 146.19 + * 2 along with this work; if not, write to the Free Software Foundation, 146.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 146.21 + * 146.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 146.23 + * or visit www.oracle.com if you need additional information or have any 146.24 + * questions. 146.25 + */ 146.26 + 146.27 +/** 146.28 + * @test 146.29 + * @option -Dnashorn.debug=true 146.30 + * @fork 146.31 + */ 146.32 + 146.33 +load(__DIR__ + "maputil.js"); 146.34 + 146.35 +// check that builtin objects share property map 146.36 + 146.37 +assertSameMap(new Boolean(true), new Boolean(false)); 146.38 +assertSameMap(new Number(3), new Number(Math.PI)); 146.39 +assertSameMap(new String('hello'), new String('world')); 146.40 +assertSameMap(new Object(), new Object()); 146.41 +assertSameMap(/hello/, /world/); 146.42 +// try w/without regexp flags 146.43 +assertSameMap(/hello/i, /world/g); 146.44 +assertSameMap(new Date(), new Date()); 146.45 +assertSameMap(new Date(2000, 1, 1), new Date(1972, 5, 6)); 146.46 +assertSameMap(Function(), Function()); 146.47 +assertSameMap(Function("x", "return x"), Function("x", "return x*x")); 146.48 +assertSameMap(new Error(), new Error()); 146.49 +assertSameMap(new Error('foo'), new Error('bar')); 146.50 +assertSameMap(new EvalError(), new EvalError()); 146.51 +assertSameMap(new EvalError('foo'), new EvalError('bar')); 146.52 +assertSameMap(new RangeError(), new RangeError()); 146.53 +assertSameMap(new RangeError('foo'), new RangeError('bar')); 146.54 +assertSameMap(new ReferenceError(), new ReferenceError()); 146.55 +assertSameMap(new ReferenceError('foo'), new ReferenceError('bar')); 146.56 +assertSameMap(new SyntaxError(), new SyntaxError()); 146.57 +assertSameMap(new SyntaxError('foo'), new SyntaxError('bar')); 146.58 +assertSameMap(new TypeError(), new TypeError()); 146.59 +assertSameMap(new TypeError('foo'), new TypeError('bar')); 146.60 +assertSameMap(new URIError(), new URIError()); 146.61 +assertSameMap(new URIError('foo'), new URIError('bar'));
147.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 147.2 +++ b/test/script/maptests/constructor.js Tue Apr 01 11:44:05 2014 -0700 147.3 @@ -0,0 +1,36 @@ 147.4 +/* 147.5 + * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved. 147.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 147.7 + * 147.8 + * This code is free software; you can redistribute it and/or modify it 147.9 + * under the terms of the GNU General Public License version 2 only, as 147.10 + * published by the Free Software Foundation. 147.11 + * 147.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 147.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 147.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 147.15 + * version 2 for more details (a copy is included in the LICENSE file that 147.16 + * accompanied this code). 147.17 + * 147.18 + * You should have received a copy of the GNU General Public License version 147.19 + * 2 along with this work; if not, write to the Free Software Foundation, 147.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 147.21 + * 147.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 147.23 + * or visit www.oracle.com if you need additional information or have any 147.24 + * questions. 147.25 + */ 147.26 + 147.27 +/** 147.28 + * @test 147.29 + * @option -Dnashorn.debug=true 147.30 + * @fork 147.31 + */ 147.32 + 147.33 +load(__DIR__ + "point.js"); 147.34 + 147.35 +// use constructor defined in a different script file 147.36 +// These objects should share the map 147.37 +assertSameMap(new Point(2, 3), new Point(43, 23)); 147.38 +assertSameMap(new Point(), new Point()); 147.39 +assertSameMap(new Point(), new Point(3, 1));
148.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 148.2 +++ b/test/script/maptests/maputil.js Tue Apr 01 11:44:05 2014 -0700 148.3 @@ -0,0 +1,38 @@ 148.4 +/* 148.5 + * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved. 148.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 148.7 + * 148.8 + * This code is free software; you can redistribute it and/or modify it 148.9 + * under the terms of the GNU General Public License version 2 only, as 148.10 + * published by the Free Software Foundation. 148.11 + * 148.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 148.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 148.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 148.15 + * version 2 for more details (a copy is included in the LICENSE file that 148.16 + * accompanied this code). 148.17 + * 148.18 + * You should have received a copy of the GNU General Public License version 148.19 + * 2 along with this work; if not, write to the Free Software Foundation, 148.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 148.21 + * 148.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 148.23 + * or visit www.oracle.com if you need additional information or have any 148.24 + * questions. 148.25 + */ 148.26 + 148.27 +/** 148.28 + * @subtest 148.29 + */ 148.30 + 148.31 +function assertSameMap(obj1, obj2, msg) { 148.32 + if (! Debug.identical(Debug.map(obj1), Debug.map(obj2))) { 148.33 + fail(obj1.constructor + " instances don't share map"); 148.34 + } 148.35 +} 148.36 + 148.37 +function assertNotSameMap(obj1, obj2, msg) { 148.38 + if (Debug.identical(Debug.map(obj1), Debug.map(obj2))) { 148.39 + fail(obj1.constructor + " and " + obj2.constructor + " instances share map"); 148.40 + } 148.41 +}
149.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 149.2 +++ b/test/script/maptests/object_create.js Tue Apr 01 11:44:05 2014 -0700 149.3 @@ -0,0 +1,40 @@ 149.4 +/* 149.5 + * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved. 149.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 149.7 + * 149.8 + * This code is free software; you can redistribute it and/or modify it 149.9 + * under the terms of the GNU General Public License version 2 only, as 149.10 + * published by the Free Software Foundation. 149.11 + * 149.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 149.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 149.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 149.15 + * version 2 for more details (a copy is included in the LICENSE file that 149.16 + * accompanied this code). 149.17 + * 149.18 + * You should have received a copy of the GNU General Public License version 149.19 + * 2 along with this work; if not, write to the Free Software Foundation, 149.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 149.21 + * 149.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 149.23 + * or visit www.oracle.com if you need additional information or have any 149.24 + * questions. 149.25 + */ 149.26 + 149.27 +/** 149.28 + * @test 149.29 + * @option -Dnashorn.debug=true 149.30 + * @fork 149.31 + */ 149.32 + 149.33 +load(__DIR__ + "maputil.js"); 149.34 + 149.35 +// Objects created by Object.create 149.36 +var obj1 = Object.create(Object.prototype); 149.37 +var obj2 = Object.create(Object.prototype); 149.38 +assertSameMap(obj1, obj2); 149.39 + 149.40 +var proto = { foo: 233 }; 149.41 +obj1 = Object.create(proto); 149.42 +obj2 = Object.create(proto); 149.43 +assertSameMap(obj1, obj2);
150.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 150.2 +++ b/test/script/maptests/object_literals.js Tue Apr 01 11:44:05 2014 -0700 150.3 @@ -0,0 +1,46 @@ 150.4 +/* 150.5 + * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved. 150.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 150.7 + * 150.8 + * This code is free software; you can redistribute it and/or modify it 150.9 + * under the terms of the GNU General Public License version 2 only, as 150.10 + * published by the Free Software Foundation. 150.11 + * 150.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 150.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 150.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 150.15 + * version 2 for more details (a copy is included in the LICENSE file that 150.16 + * accompanied this code). 150.17 + * 150.18 + * You should have received a copy of the GNU General Public License version 150.19 + * 2 along with this work; if not, write to the Free Software Foundation, 150.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 150.21 + * 150.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 150.23 + * or visit www.oracle.com if you need additional information or have any 150.24 + * questions. 150.25 + */ 150.26 + 150.27 +/** 150.28 + * @test 150.29 + * @option -Dnashorn.debug=true 150.30 + * @fork 150.31 + */ 150.32 + 150.33 +load(__DIR__ + "maputil.js"); 150.34 + 150.35 +// Object literals created at the same callsite 150.36 +function makeObject() { 150.37 + return { foo: 34 } 150.38 +} 150.39 +assertSameMap(makeObject(), makeObject()); 150.40 + 150.41 +function makeObject2() { 150.42 + return { foo: 42, bar: 'hello' } 150.43 +} 150.44 +assertSameMap(makeObject2(), makeObject2()); 150.45 + 150.46 +// Object literals created at different callsites 150.47 +assertSameMap({}, {}); 150.48 +assertSameMap({foo: 4}, {foo: 'hello'}); 150.49 +assertSameMap({foo: 34, bar: 'fdgd'}, {foo: 'world', bar: 54});
151.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 151.2 +++ b/test/script/maptests/point.js Tue Apr 01 11:44:05 2014 -0700 151.3 @@ -0,0 +1,49 @@ 151.4 +/* 151.5 + * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved. 151.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 151.7 + * 151.8 + * This code is free software; you can redistribute it and/or modify it 151.9 + * under the terms of the GNU General Public License version 2 only, as 151.10 + * published by the Free Software Foundation. 151.11 + * 151.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 151.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 151.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 151.15 + * version 2 for more details (a copy is included in the LICENSE file that 151.16 + * accompanied this code). 151.17 + * 151.18 + * You should have received a copy of the GNU General Public License version 151.19 + * 2 along with this work; if not, write to the Free Software Foundation, 151.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 151.21 + * 151.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 151.23 + * or visit www.oracle.com if you need additional information or have any 151.24 + * questions. 151.25 + */ 151.26 + 151.27 + 151.28 +/** 151.29 + * @subtest 151.30 + */ 151.31 + 151.32 +function Point(x, y) { 151.33 + this.x =x; this.y =y; 151.34 +} 151.35 + 151.36 +Point.prototype.toString = function() { 151.37 + return "(" + this.x + "," + this.y + ")"; 151.38 +} 151.39 + 151.40 +Point.prototype.modulus = function() { 151.41 + return Math.sqrt(this.x*this.x + this.y*this.y); 151.42 +} 151.43 + 151.44 +Point.prototype.argument = function() { 151.45 + return Math.atan2(this.y, this.x); 151.46 +} 151.47 + 151.48 +load(__DIR__ + "maputil.js"); 151.49 + 151.50 +assertSameMap(new Point(2, 3), new Point(43, 23)); 151.51 +assertSameMap(new Point(), new Point()); 151.52 +assertSameMap(new Point(), new Point(3, 1));
152.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 152.2 +++ b/test/script/maptests/property_add.js Tue Apr 01 11:44:05 2014 -0700 152.3 @@ -0,0 +1,46 @@ 152.4 +/* 152.5 + * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved. 152.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 152.7 + * 152.8 + * This code is free software; you can redistribute it and/or modify it 152.9 + * under the terms of the GNU General Public License version 2 only, as 152.10 + * published by the Free Software Foundation. 152.11 + * 152.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 152.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 152.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 152.15 + * version 2 for more details (a copy is included in the LICENSE file that 152.16 + * accompanied this code). 152.17 + * 152.18 + * You should have received a copy of the GNU General Public License version 152.19 + * 2 along with this work; if not, write to the Free Software Foundation, 152.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 152.21 + * 152.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 152.23 + * or visit www.oracle.com if you need additional information or have any 152.24 + * questions. 152.25 + */ 152.26 + 152.27 +/** 152.28 + * @test 152.29 + * @option -Dnashorn.debug=true 152.30 + * @fork 152.31 + */ 152.32 + 152.33 +load(__DIR__ + "maputil.js"); 152.34 + 152.35 +function Foo() {} 152.36 + 152.37 +var obj1 = new Foo(); 152.38 +var obj2 = new Foo(); 152.39 + 152.40 +assertSameMap(obj1, obj2); 152.41 + 152.42 +// property addition at same callsite 152.43 +function addX(obj, val) { 152.44 + obj.x = val; 152.45 +} 152.46 +addX(obj1, 3); 152.47 +addX(obj2, 'hello'); 152.48 + 152.49 +assertSameMap(obj1, obj2);
153.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 153.2 +++ b/test/script/maptests/property_delete.js Tue Apr 01 11:44:05 2014 -0700 153.3 @@ -0,0 +1,48 @@ 153.4 +/* 153.5 + * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved. 153.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 153.7 + * 153.8 + * This code is free software; you can redistribute it and/or modify it 153.9 + * under the terms of the GNU General Public License version 2 only, as 153.10 + * published by the Free Software Foundation. 153.11 + * 153.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 153.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 153.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 153.15 + * version 2 for more details (a copy is included in the LICENSE file that 153.16 + * accompanied this code). 153.17 + * 153.18 + * You should have received a copy of the GNU General Public License version 153.19 + * 2 along with this work; if not, write to the Free Software Foundation, 153.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 153.21 + * 153.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 153.23 + * or visit www.oracle.com if you need additional information or have any 153.24 + * questions. 153.25 + */ 153.26 + 153.27 +/** 153.28 + * @test 153.29 + * @option -Dnashorn.debug=true 153.30 + * @fork 153.31 + */ 153.32 + 153.33 +load(__DIR__ + "maputil.js"); 153.34 + 153.35 +function Foo() { 153.36 + this.x = 33; 153.37 +} 153.38 + 153.39 +var obj1 = new Foo(); 153.40 +var obj2 = new Foo(); 153.41 + 153.42 +assertSameMap(obj1, obj2); 153.43 + 153.44 +// property deletion at same callsite 153.45 +function deleteX(obj) { 153.46 + delete obj.x; 153.47 +} 153.48 +deleteX(obj1); 153.49 +deleteX(obj2); 153.50 + 153.51 +assertSameMap(obj1, obj2);
154.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 154.2 +++ b/test/script/maptests/proto.js Tue Apr 01 11:44:05 2014 -0700 154.3 @@ -0,0 +1,56 @@ 154.4 +/* 154.5 + * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved. 154.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 154.7 + * 154.8 + * This code is free software; you can redistribute it and/or modify it 154.9 + * under the terms of the GNU General Public License version 2 only, as 154.10 + * published by the Free Software Foundation. 154.11 + * 154.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 154.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 154.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 154.15 + * version 2 for more details (a copy is included in the LICENSE file that 154.16 + * accompanied this code). 154.17 + * 154.18 + * You should have received a copy of the GNU General Public License version 154.19 + * 2 along with this work; if not, write to the Free Software Foundation, 154.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 154.21 + * 154.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 154.23 + * or visit www.oracle.com if you need additional information or have any 154.24 + * questions. 154.25 + */ 154.26 + 154.27 +/** 154.28 + * @test 154.29 + * @option -Dnashorn.debug=true 154.30 + * @fork 154.31 + */ 154.32 + 154.33 +load(__DIR__ + "maputil.js"); 154.34 + 154.35 +// add/delete property to proto (direct/indirect) should 154.36 +// not affect the property map of the objects 154.37 + 154.38 +var proto2 = { foo: 334 } 154.39 +var proto = Object.create(proto2); 154.40 +proto.bar = "hello"; 154.41 + 154.42 +var obj1 = Object.create(proto); 154.43 +var obj2 = Object.create(proto); 154.44 + 154.45 +assertSameMap(obj1, obj2); 154.46 + 154.47 +proto.newX = 'world'; 154.48 +assertSameMap(obj1, obj2); 154.49 + 154.50 +delete proto.newX; 154.51 +assertSameMap(obj1, obj2); 154.52 + 154.53 +proto2.newX = "foo"; 154.54 +assertSameMap(obj1, obj2); 154.55 + 154.56 +delete proto2.newX; 154.57 +assertSameMap(obj1, obj2); 154.58 + 154.59 +
155.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 155.2 +++ b/test/script/sandbox/JDK-8031106.js Tue Apr 01 11:44:05 2014 -0700 155.3 @@ -0,0 +1,39 @@ 155.4 +/* 155.5 + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. 155.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 155.7 + * 155.8 + * This code is free software; you can redistribute it and/or modify it 155.9 + * under the terms of the GNU General Public License version 2 only, as 155.10 + * published by the Free Software Foundation. 155.11 + * 155.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 155.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 155.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 155.15 + * version 2 for more details (a copy is included in the LICENSE file that 155.16 + * accompanied this code). 155.17 + * 155.18 + * You should have received a copy of the GNU General Public License version 155.19 + * 2 along with this work; if not, write to the Free Software Foundation, 155.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 155.21 + * 155.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 155.23 + * or visit www.oracle.com if you need additional information or have any 155.24 + * questions. 155.25 + */ 155.26 + 155.27 +/** 155.28 + * JDK-8031106: Nashorn: IndexOutOfBoundsException in NashornCallSiteDescriptor.getNameToken() 155.29 + * 155.30 + * @test 155.31 + * @run 155.32 + */ 155.33 + 155.34 +var cl = new java.lang.Object().getClass(); 155.35 +try { 155.36 + cl["forName"]; 155.37 + fail("Should have thrown exception!"); 155.38 +} catch (e) { 155.39 + if (! (e instanceof java.lang.SecurityException)) { 155.40 + fail("SecurityException expected, got " + e); 155.41 + } 155.42 +}
156.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 156.2 +++ b/test/script/sandbox/safeprops.js Tue Apr 01 11:44:05 2014 -0700 156.3 @@ -0,0 +1,65 @@ 156.4 +/* 156.5 + * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved. 156.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 156.7 + * 156.8 + * This code is free software; you can redistribute it and/or modify it 156.9 + * under the terms of the GNU General Public License version 2 only, as 156.10 + * published by the Free Software Foundation. 156.11 + * 156.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 156.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 156.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 156.15 + * version 2 for more details (a copy is included in the LICENSE file that 156.16 + * accompanied this code). 156.17 + * 156.18 + * You should have received a copy of the GNU General Public License version 156.19 + * 2 along with this work; if not, write to the Free Software Foundation, 156.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 156.21 + * 156.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 156.23 + * or visit www.oracle.com if you need additional information or have any 156.24 + * questions. 156.25 + */ 156.26 + 156.27 +/** 156.28 + * Try to access System properties safe to read for any code. 156.29 + * No security exception expected. 156.30 + * 156.31 + * @test 156.32 + * @security 156.33 + * @run 156.34 + * @bug 8033924: Default permissions are not given for eval code 156.35 + */ 156.36 + 156.37 +var propNames = [ 156.38 + "java.version", 156.39 + "java.vendor", 156.40 + "java.vendor.url", 156.41 + "java.class.version", 156.42 + "os.name", 156.43 + "os.version", 156.44 + "os.arch", 156.45 + "file.separator", 156.46 + "path.separator", 156.47 + "line.separator", 156.48 + "java.specification.version", 156.49 + "java.specification.vendor", 156.50 + "java.specification.name", 156.51 + "java.vm.specification.version", 156.52 + "java.vm.specification.vendor", 156.53 + "java.vm.specification.name", 156.54 + "java.vm.version", 156.55 + "java.vm.vendor", 156.56 + "java.vm.name" 156.57 +]; 156.58 + 156.59 +// no security exception expected 156.60 +for (var p in propNames) { 156.61 + java.lang.System.getProperty(propNames[p]); 156.62 +} 156.63 + 156.64 +// no security exception expected 156.65 +for (var p in propNames) { 156.66 + var name = propNames[p]; 156.67 + eval('java.lang.System.getProperty(name)'); 156.68 +}
157.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 157.2 +++ b/test/script/trusted/JDK-8032060.js Tue Apr 01 11:44:05 2014 -0700 157.3 @@ -0,0 +1,72 @@ 157.4 +/* 157.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 157.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 157.7 + * 157.8 + * This code is free software; you can redistribute it and/or modify it 157.9 + * under the terms of the GNU General Public License version 2 only, as 157.10 + * published by the Free Software Foundation. 157.11 + * 157.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 157.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 157.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 157.15 + * version 2 for more details (a copy is included in the LICENSE file that 157.16 + * accompanied this code). 157.17 + * 157.18 + * You should have received a copy of the GNU General Public License version 157.19 + * 2 along with this work; if not, write to the Free Software Foundation, 157.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 157.21 + * 157.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 157.23 + * or visit www.oracle.com if you need additional information or have any 157.24 + * questions. 157.25 + */ 157.26 + 157.27 +/** 157.28 + * JDK-8032060: PropertyMap of Error objects is not stable 157.29 + * 157.30 + * @test 157.31 + * @option -Dnashorn.debug=true 157.32 + * @fork 157.33 + * @run 157.34 + */ 157.35 + 157.36 +function checkMap(e1, e2) { 157.37 + if (! Debug.identical(Debug.map(e1), Debug.map(e2))) { 157.38 + fail("e1 and e2 have different maps"); 157.39 + } 157.40 + 157.41 + var m1, m2; 157.42 + 157.43 + try { 157.44 + throw e1 157.45 + } catch (e) { 157.46 + m1 = Debug.map(e) 157.47 + } 157.48 + 157.49 + try { 157.50 + throw e2 157.51 + } catch (e) { 157.52 + m2 = Debug.map(e) 157.53 + } 157.54 + 157.55 + if (! Debug.identical(m1, m2)) { 157.56 + fail("e1 and e2 have different maps after being thrown"); 157.57 + } 157.58 +} 157.59 + 157.60 +checkMap(new Error(), new Error()); 157.61 +checkMap(new EvalError(), new EvalError()); 157.62 +checkMap(new RangeError(), new RangeError()); 157.63 +checkMap(new ReferenceError(), new ReferenceError()); 157.64 +checkMap(new SyntaxError(), new SyntaxError()); 157.65 +checkMap(new TypeError(), new TypeError()); 157.66 +checkMap(new URIError(), new URIError()); 157.67 + 157.68 +// now try with message param 157.69 +checkMap(new Error("x"), new Error("y")); 157.70 +checkMap(new EvalError("x"), new EvalError("y")); 157.71 +checkMap(new RangeError("x"), new RangeError("y")); 157.72 +checkMap(new ReferenceError("x"), new ReferenceError("y")); 157.73 +checkMap(new SyntaxError("x"), new SyntaxError("y")); 157.74 +checkMap(new TypeError("x"), new TypeError("y")); 157.75 +checkMap(new URIError("x"), new URIError("y"));
158.1 --- a/test/src/jdk/nashorn/api/scripting/InvocableTest.java Wed Mar 26 12:01:34 2014 -0700 158.2 +++ b/test/src/jdk/nashorn/api/scripting/InvocableTest.java Tue Apr 01 11:44:05 2014 -0700 158.3 @@ -26,6 +26,7 @@ 158.4 package jdk.nashorn.api.scripting; 158.5 158.6 import java.util.Objects; 158.7 +import java.util.function.Function; 158.8 import javax.script.Invocable; 158.9 import javax.script.ScriptContext; 158.10 import javax.script.ScriptEngine; 158.11 @@ -522,4 +523,16 @@ 158.12 Assert.assertEquals(itf.test1(42, "a", "b"), "i == 42, strings instanceof java.lang.String[] == true, strings == [a, b]"); 158.13 Assert.assertEquals(itf.test2(44, "c", "d", "e"), "arguments[0] == 44, arguments[1] instanceof java.lang.String[] == true, arguments[1] == [c, d, e]"); 158.14 } 158.15 + 158.16 + @Test 158.17 + @SuppressWarnings("unchecked") 158.18 + public void defaultMethodTest() throws ScriptException { 158.19 + final ScriptEngineManager m = new ScriptEngineManager(); 158.20 + final ScriptEngine e = m.getEngineByName("nashorn"); 158.21 + final Invocable inv = (Invocable) e; 158.22 + 158.23 + Object obj = e.eval("({ apply: function(arg) { return arg.toUpperCase(); }})"); 158.24 + Function<String, String> func = inv.getInterface(obj, Function.class); 158.25 + assertEquals(func.apply("hello"), "HELLO"); 158.26 + } 158.27 }
159.1 --- a/test/src/jdk/nashorn/api/scripting/ScopeTest.java Wed Mar 26 12:01:34 2014 -0700 159.2 +++ b/test/src/jdk/nashorn/api/scripting/ScopeTest.java Tue Apr 01 11:44:05 2014 -0700 159.3 @@ -245,4 +245,320 @@ 159.4 sb.put("x", "newX"); 159.5 assertTrue(e.eval("x", ctx).equals("newX")); 159.6 } 159.7 + 159.8 + /** 159.9 + * Test multi-threaded access to defined global variables for shared script classes with multiple globals. 159.10 + */ 159.11 + @Test 159.12 + public static void multiThreadedVarTest() throws ScriptException, InterruptedException { 159.13 + final ScriptEngineManager m = new ScriptEngineManager(); 159.14 + final ScriptEngine e = m.getEngineByName("nashorn"); 159.15 + final Bindings b = e.createBindings(); 159.16 + final ScriptContext origContext = e.getContext(); 159.17 + final ScriptContext newCtxt = new SimpleScriptContext(); 159.18 + newCtxt.setBindings(b, ScriptContext.ENGINE_SCOPE); 159.19 + final String sharedScript = "foo"; 159.20 + 159.21 + assertEquals(e.eval("var foo = 'original context';", origContext), null); 159.22 + assertEquals(e.eval("var foo = 'new context';", newCtxt), null); 159.23 + 159.24 + final Thread t1 = new Thread(new ScriptRunner(e, origContext, sharedScript, "original context", 1000)); 159.25 + final Thread t2 = new Thread(new ScriptRunner(e, newCtxt, sharedScript, "new context", 1000)); 159.26 + t1.start(); 159.27 + t2.start(); 159.28 + t1.join(); 159.29 + t2.join(); 159.30 + 159.31 + assertEquals(e.eval("var foo = 'newer context';", newCtxt), null); 159.32 + final Thread t3 = new Thread(new ScriptRunner(e, origContext, sharedScript, "original context", 1000)); 159.33 + final Thread t4 = new Thread(new ScriptRunner(e, newCtxt, sharedScript, "newer context", 1000)); 159.34 + 159.35 + t3.start(); 159.36 + t4.start(); 159.37 + t3.join(); 159.38 + t4.join(); 159.39 + 159.40 + assertEquals(e.eval(sharedScript), "original context"); 159.41 + assertEquals(e.eval(sharedScript, newCtxt), "newer context"); 159.42 + } 159.43 + 159.44 + /** 159.45 + * Test multi-threaded access to undefined global variables for shared script classes with multiple globals. 159.46 + */ 159.47 + @Test 159.48 + public static void multiThreadedGlobalTest() throws ScriptException, InterruptedException { 159.49 + final ScriptEngineManager m = new ScriptEngineManager(); 159.50 + final ScriptEngine e = m.getEngineByName("nashorn"); 159.51 + final Bindings b = e.createBindings(); 159.52 + final ScriptContext origContext = e.getContext(); 159.53 + final ScriptContext newCtxt = new SimpleScriptContext(); 159.54 + newCtxt.setBindings(b, ScriptContext.ENGINE_SCOPE); 159.55 + 159.56 + assertEquals(e.eval("foo = 'original context';", origContext), "original context"); 159.57 + assertEquals(e.eval("foo = 'new context';", newCtxt), "new context"); 159.58 + final String sharedScript = "foo"; 159.59 + 159.60 + final Thread t1 = new Thread(new ScriptRunner(e, origContext, sharedScript, "original context", 1000)); 159.61 + final Thread t2 = new Thread(new ScriptRunner(e, newCtxt, sharedScript, "new context", 1000)); 159.62 + t1.start(); 159.63 + t2.start(); 159.64 + t1.join(); 159.65 + t2.join(); 159.66 + 159.67 + Object obj3 = e.eval("delete foo; foo = 'newer context';", newCtxt); 159.68 + assertEquals(obj3, "newer context"); 159.69 + final Thread t3 = new Thread(new ScriptRunner(e, origContext, sharedScript, "original context", 1000)); 159.70 + final Thread t4 = new Thread(new ScriptRunner(e, newCtxt, sharedScript, "newer context", 1000)); 159.71 + 159.72 + t3.start(); 159.73 + t4.start(); 159.74 + t3.join(); 159.75 + t4.join(); 159.76 + 159.77 + Assert.assertEquals(e.eval(sharedScript), "original context"); 159.78 + Assert.assertEquals(e.eval(sharedScript, newCtxt), "newer context"); 159.79 + } 159.80 + 159.81 + /** 159.82 + * Test multi-threaded access using the postfix ++ operator for shared script classes with multiple globals. 159.83 + */ 159.84 + @Test 159.85 + public static void multiThreadedIncTest() throws ScriptException, InterruptedException { 159.86 + final ScriptEngineManager m = new ScriptEngineManager(); 159.87 + final ScriptEngine e = m.getEngineByName("nashorn"); 159.88 + final Bindings b = e.createBindings(); 159.89 + final ScriptContext origContext = e.getContext(); 159.90 + final ScriptContext newCtxt = new SimpleScriptContext(); 159.91 + newCtxt.setBindings(b, ScriptContext.ENGINE_SCOPE); 159.92 + 159.93 + assertEquals(e.eval("var x = 0;", origContext), null); 159.94 + assertEquals(e.eval("var x = 2;", newCtxt), null); 159.95 + final String sharedScript = "x++;"; 159.96 + 159.97 + final Thread t1 = new Thread(new Runnable() { 159.98 + @Override 159.99 + public void run() { 159.100 + try { 159.101 + for (int i = 0; i < 1000; i++) { 159.102 + assertEquals(e.eval(sharedScript, origContext), (double)i); 159.103 + } 159.104 + } catch (ScriptException se) { 159.105 + fail(se.toString()); 159.106 + } 159.107 + } 159.108 + }); 159.109 + final Thread t2 = new Thread(new Runnable() { 159.110 + @Override 159.111 + public void run() { 159.112 + try { 159.113 + for (int i = 2; i < 1000; i++) { 159.114 + assertEquals(e.eval(sharedScript, newCtxt), (double)i); 159.115 + } 159.116 + } catch (ScriptException se) { 159.117 + fail(se.toString()); 159.118 + } 159.119 + } 159.120 + }); 159.121 + t1.start(); 159.122 + t2.start(); 159.123 + t1.join(); 159.124 + t2.join(); 159.125 + } 159.126 + 159.127 + /** 159.128 + * Test multi-threaded access to primitive prototype properties for shared script classes with multiple globals. 159.129 + */ 159.130 + @Test 159.131 + public static void multiThreadedPrimitiveTest() throws ScriptException, InterruptedException { 159.132 + final ScriptEngineManager m = new ScriptEngineManager(); 159.133 + final ScriptEngine e = m.getEngineByName("nashorn"); 159.134 + final Bindings b = e.createBindings(); 159.135 + final ScriptContext origContext = e.getContext(); 159.136 + final ScriptContext newCtxt = new SimpleScriptContext(); 159.137 + newCtxt.setBindings(b, ScriptContext.ENGINE_SCOPE); 159.138 + 159.139 + Object obj1 = e.eval("String.prototype.foo = 'original context';", origContext); 159.140 + Object obj2 = e.eval("String.prototype.foo = 'new context';", newCtxt); 159.141 + assertEquals(obj1, "original context"); 159.142 + assertEquals(obj2, "new context"); 159.143 + final String sharedScript = "''.foo"; 159.144 + 159.145 + final Thread t1 = new Thread(new ScriptRunner(e, origContext, sharedScript, "original context", 1000)); 159.146 + final Thread t2 = new Thread(new ScriptRunner(e, newCtxt, sharedScript, "new context", 1000)); 159.147 + t1.start(); 159.148 + t2.start(); 159.149 + t1.join(); 159.150 + t2.join(); 159.151 + 159.152 + Object obj3 = e.eval("delete String.prototype.foo; Object.prototype.foo = 'newer context';", newCtxt); 159.153 + assertEquals(obj3, "newer context"); 159.154 + final Thread t3 = new Thread(new ScriptRunner(e, origContext, sharedScript, "original context", 1000)); 159.155 + final Thread t4 = new Thread(new ScriptRunner(e, newCtxt, sharedScript, "newer context", 1000)); 159.156 + 159.157 + t3.start(); 159.158 + t4.start(); 159.159 + t3.join(); 159.160 + t4.join(); 159.161 + 159.162 + Assert.assertEquals(e.eval(sharedScript), "original context"); 159.163 + Assert.assertEquals(e.eval(sharedScript, newCtxt), "newer context"); 159.164 + } 159.165 + 159.166 + /** 159.167 + * Test multi-threaded scope function invocation for shared script classes with multiple globals. 159.168 + */ 159.169 + @Test 159.170 + public static void multiThreadedFunctionTest() throws ScriptException, InterruptedException { 159.171 + final ScriptEngineManager m = new ScriptEngineManager(); 159.172 + final ScriptEngine e = m.getEngineByName("nashorn"); 159.173 + final Bindings b = e.createBindings(); 159.174 + final ScriptContext origContext = e.getContext(); 159.175 + final ScriptContext newCtxt = new SimpleScriptContext(); 159.176 + newCtxt.setBindings(b, ScriptContext.ENGINE_SCOPE); 159.177 + 159.178 + e.eval(new URLReader(ScopeTest.class.getResource("resources/func.js")), origContext); 159.179 + assertEquals(origContext.getAttribute("scopeVar"), 1); 159.180 + assertEquals(e.eval("scopeTest()"), 1); 159.181 + 159.182 + e.eval(new URLReader(ScopeTest.class.getResource("resources/func.js")), newCtxt); 159.183 + assertEquals(newCtxt.getAttribute("scopeVar"), 1); 159.184 + assertEquals(e.eval("scopeTest();", newCtxt), 1); 159.185 + 159.186 + assertEquals(e.eval("scopeVar = 3;", newCtxt), 3); 159.187 + assertEquals(newCtxt.getAttribute("scopeVar"), 3); 159.188 + 159.189 + 159.190 + final Thread t1 = new Thread(new ScriptRunner(e, origContext, "scopeTest()", 1, 1000)); 159.191 + final Thread t2 = new Thread(new ScriptRunner(e, newCtxt, "scopeTest()", 3, 1000)); 159.192 + 159.193 + t1.start(); 159.194 + t2.start(); 159.195 + t1.join(); 159.196 + t2.join(); 159.197 + 159.198 + } 159.199 + 159.200 + /** 159.201 + * Test multi-threaded access to global getters and setters for shared script classes with multiple globals. 159.202 + */ 159.203 + @Test 159.204 + public static void getterSetterTest() throws ScriptException, InterruptedException { 159.205 + final ScriptEngineManager m = new ScriptEngineManager(); 159.206 + final ScriptEngine e = m.getEngineByName("nashorn"); 159.207 + final Bindings b = e.createBindings(); 159.208 + final ScriptContext origContext = e.getContext(); 159.209 + final ScriptContext newCtxt = new SimpleScriptContext(); 159.210 + newCtxt.setBindings(b, ScriptContext.ENGINE_SCOPE); 159.211 + final String sharedScript = "accessor1"; 159.212 + 159.213 + e.eval(new URLReader(ScopeTest.class.getResource("resources/gettersetter.js")), origContext); 159.214 + assertEquals(e.eval("accessor1 = 1;"), 1); 159.215 + assertEquals(e.eval(sharedScript), 1); 159.216 + 159.217 + e.eval(new URLReader(ScopeTest.class.getResource("resources/gettersetter.js")), newCtxt); 159.218 + assertEquals(e.eval("accessor1 = 2;", newCtxt), 2); 159.219 + assertEquals(e.eval(sharedScript, newCtxt), 2); 159.220 + 159.221 + 159.222 + final Thread t1 = new Thread(new ScriptRunner(e, origContext, sharedScript, 1, 1000)); 159.223 + final Thread t2 = new Thread(new ScriptRunner(e, newCtxt, sharedScript, 2, 1000)); 159.224 + 159.225 + t1.start(); 159.226 + t2.start(); 159.227 + t1.join(); 159.228 + t2.join(); 159.229 + 159.230 + assertEquals(e.eval(sharedScript), 1); 159.231 + assertEquals(e.eval(sharedScript, newCtxt), 2); 159.232 + assertEquals(e.eval("v"), 1); 159.233 + assertEquals(e.eval("v", newCtxt), 2); 159.234 + } 159.235 + 159.236 + /** 159.237 + * Test multi-threaded access to global getters and setters for shared script classes with multiple globals. 159.238 + */ 159.239 + @Test 159.240 + public static void getterSetter2Test() throws ScriptException, InterruptedException { 159.241 + final ScriptEngineManager m = new ScriptEngineManager(); 159.242 + final ScriptEngine e = m.getEngineByName("nashorn"); 159.243 + final Bindings b = e.createBindings(); 159.244 + final ScriptContext origContext = e.getContext(); 159.245 + final ScriptContext newCtxt = new SimpleScriptContext(); 159.246 + newCtxt.setBindings(b, ScriptContext.ENGINE_SCOPE); 159.247 + final String sharedScript = "accessor2"; 159.248 + 159.249 + e.eval(new URLReader(ScopeTest.class.getResource("resources/gettersetter.js")), origContext); 159.250 + assertEquals(e.eval("accessor2 = 1;"), 1); 159.251 + assertEquals(e.eval(sharedScript), 1); 159.252 + 159.253 + e.eval(new URLReader(ScopeTest.class.getResource("resources/gettersetter.js")), newCtxt); 159.254 + assertEquals(e.eval("accessor2 = 2;", newCtxt), 2); 159.255 + assertEquals(e.eval(sharedScript, newCtxt), 2); 159.256 + 159.257 + 159.258 + final Thread t1 = new Thread(new ScriptRunner(e, origContext, sharedScript, 1, 1000)); 159.259 + final Thread t2 = new Thread(new ScriptRunner(e, newCtxt, sharedScript, 2, 1000)); 159.260 + 159.261 + t1.start(); 159.262 + t2.start(); 159.263 + t1.join(); 159.264 + t2.join(); 159.265 + 159.266 + assertEquals(e.eval(sharedScript), 1); 159.267 + assertEquals(e.eval(sharedScript, newCtxt), 2); 159.268 + assertEquals(e.eval("x"), 1); 159.269 + assertEquals(e.eval("x", newCtxt), 2); 159.270 + } 159.271 + 159.272 + /** 159.273 + * Test "slow" scopes involving {@code with} and {@code eval} statements for shared script classes with multiple globals. 159.274 + */ 159.275 + @Test 159.276 + public static void testSlowScope() throws ScriptException, InterruptedException { 159.277 + final ScriptEngineManager m = new ScriptEngineManager(); 159.278 + final ScriptEngine e = m.getEngineByName("nashorn"); 159.279 + 159.280 + for (int i = 0; i < 100; i++) { 159.281 + final Bindings b = e.createBindings(); 159.282 + final ScriptContext ctxt = new SimpleScriptContext(); 159.283 + ctxt.setBindings(b, ScriptContext.ENGINE_SCOPE); 159.284 + 159.285 + e.eval(new URLReader(ScopeTest.class.getResource("resources/witheval.js")), ctxt); 159.286 + assertEquals(e.eval("a", ctxt), 1); 159.287 + assertEquals(b.get("a"), 1); 159.288 + assertEquals(e.eval("b", ctxt), 3); 159.289 + assertEquals(b.get("b"), 3); 159.290 + assertEquals(e.eval("c", ctxt), 10); 159.291 + assertEquals(b.get("c"), 10); 159.292 + } 159.293 + } 159.294 + 159.295 + private static class ScriptRunner implements Runnable { 159.296 + 159.297 + final ScriptEngine engine; 159.298 + final ScriptContext context; 159.299 + final String source; 159.300 + final Object expected; 159.301 + final int iterations; 159.302 + 159.303 + ScriptRunner(final ScriptEngine engine, final ScriptContext context, final String source, final Object expected, final int iterations) { 159.304 + this.engine = engine; 159.305 + this.context = context; 159.306 + this.source = source; 159.307 + this.expected = expected; 159.308 + this.iterations = iterations; 159.309 + } 159.310 + 159.311 + @Override 159.312 + public void run() { 159.313 + try { 159.314 + for (int i = 0; i < iterations; i++) { 159.315 + assertEquals(engine.eval(source, context), expected); 159.316 + } 159.317 + } catch (ScriptException se) { 159.318 + throw new RuntimeException(se); 159.319 + } 159.320 + } 159.321 + } 159.322 + 159.323 }
160.1 --- a/test/src/jdk/nashorn/api/scripting/ScriptEngineTest.java Wed Mar 26 12:01:34 2014 -0700 160.2 +++ b/test/src/jdk/nashorn/api/scripting/ScriptEngineTest.java Tue Apr 01 11:44:05 2014 -0700 160.3 @@ -560,6 +560,47 @@ 160.4 assertTrue(reached[0]); 160.5 } 160.6 160.7 + // properties that can be read by any code 160.8 + private static String[] propNames = { 160.9 + "java.version", 160.10 + "java.vendor", 160.11 + "java.vendor.url", 160.12 + "java.class.version", 160.13 + "os.name", 160.14 + "os.version", 160.15 + "os.arch", 160.16 + "file.separator", 160.17 + "path.separator", 160.18 + "line.separator", 160.19 + "java.specification.version", 160.20 + "java.specification.vendor", 160.21 + "java.specification.name", 160.22 + "java.vm.specification.version", 160.23 + "java.vm.specification.vendor", 160.24 + "java.vm.specification.name", 160.25 + "java.vm.version", 160.26 + "java.vm.vendor", 160.27 + "java.vm.name" 160.28 + }; 160.29 + 160.30 + // @bug 8033924: Default permissions are not given for eval code 160.31 + @Test 160.32 + public void checkPropertyReadPermissions() throws ScriptException { 160.33 + final ScriptEngineManager m = new ScriptEngineManager(); 160.34 + final ScriptEngine e = m.getEngineByName("nashorn"); 160.35 + 160.36 + for (final String name : propNames) { 160.37 + checkProperty(e, name); 160.38 + } 160.39 + } 160.40 + 160.41 + private static void checkProperty(final ScriptEngine e, final String name) 160.42 + throws ScriptException { 160.43 + String value = System.getProperty(name); 160.44 + e.put("name", name); 160.45 + assertEquals(value, e.eval("java.lang.System.getProperty(name)")); 160.46 + } 160.47 + 160.48 private static final String LINE_SEPARATOR = System.getProperty("line.separator"); 160.49 160.50 // Returns String that would be the result of calling PrintWriter.println
161.1 --- a/test/src/jdk/nashorn/api/scripting/ScriptObjectMirrorTest.java Wed Mar 26 12:01:34 2014 -0700 161.2 +++ b/test/src/jdk/nashorn/api/scripting/ScriptObjectMirrorTest.java Tue Apr 01 11:44:05 2014 -0700 161.3 @@ -25,6 +25,7 @@ 161.4 161.5 package jdk.nashorn.api.scripting; 161.6 161.7 +import java.nio.ByteBuffer; 161.8 import java.util.HashMap; 161.9 import java.util.List; 161.10 import java.util.Map; 161.11 @@ -230,6 +231,29 @@ 161.12 } 161.13 161.14 @Test 161.15 + public void indexPropertiesExternalBufferTest() throws ScriptException { 161.16 + final ScriptEngineManager m = new ScriptEngineManager(); 161.17 + final ScriptEngine e = m.getEngineByName("nashorn"); 161.18 + final ScriptObjectMirror obj = (ScriptObjectMirror)e.eval("var obj = {}; obj"); 161.19 + final ByteBuffer buf = ByteBuffer.allocate(5); 161.20 + int i; 161.21 + for (i = 0; i < 5; i++) { 161.22 + buf.put(i, (byte)(i+10)); 161.23 + } 161.24 + obj.setIndexedPropertiesToExternalArrayData(buf); 161.25 + 161.26 + for (i = 0; i < 5; i++) { 161.27 + assertEquals((byte)(i+10), ((Number)e.eval("obj[" + i + "]")).byteValue()); 161.28 + } 161.29 + 161.30 + e.eval("for (i = 0; i < 5; i++) obj[i] = 0"); 161.31 + for (i = 0; i < 5; i++) { 161.32 + assertEquals((byte)0, ((Number)e.eval("obj[" + i + "]")).byteValue()); 161.33 + assertEquals((byte)0, buf.get(i)); 161.34 + } 161.35 + } 161.36 + 161.37 + @Test 161.38 public void conversionTest() throws ScriptException { 161.39 final ScriptEngineManager m = new ScriptEngineManager(); 161.40 final ScriptEngine e = m.getEngineByName("nashorn");
162.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 162.2 +++ b/test/src/jdk/nashorn/api/scripting/resources/func.js Tue Apr 01 11:44:05 2014 -0700 162.3 @@ -0,0 +1,42 @@ 162.4 +/* 162.5 + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. 162.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 162.7 + * 162.8 + * This code is free software; you can redistribute it and/or modify it 162.9 + * under the terms of the GNU General Public License version 2 only, as 162.10 + * published by the Free Software Foundation. Oracle designates this 162.11 + * particular file as subject to the "Classpath" exception as provided 162.12 + * by Oracle in the LICENSE file that accompanied this code. 162.13 + * 162.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 162.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 162.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 162.17 + * version 2 for more details (a copy is included in the LICENSE file that 162.18 + * accompanied this code). 162.19 + * 162.20 + * You should have received a copy of the GNU General Public License version 162.21 + * 2 along with this work; if not, write to the Free Software Foundation, 162.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 162.23 + * 162.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 162.25 + * or visit www.oracle.com if you need additional information or have any 162.26 + * questions. 162.27 + */ 162.28 + 162.29 +// This script is loaded from jdk.nashorn.api.scripting.ScopeTest to test script class sharing and reuse. 162.30 + 162.31 +var scopeVar = 1; 162.32 +var global = this; 162.33 +undefGlobal = this; 162.34 + 162.35 +function scopeTest() { 162.36 + if (this !== global) { 162.37 + throw new Error("this !== global"); 162.38 + } 162.39 + if (this !== undefGlobal) { 162.40 + throw new Error("this !== undefinedGlobal") 162.41 + } 162.42 + return scopeVar; 162.43 +} 162.44 + 162.45 +scopeTest();
163.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 163.2 +++ b/test/src/jdk/nashorn/api/scripting/resources/gettersetter.js Tue Apr 01 11:44:05 2014 -0700 163.3 @@ -0,0 +1,38 @@ 163.4 +/* 163.5 + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. 163.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 163.7 + * 163.8 + * This code is free software; you can redistribute it and/or modify it 163.9 + * under the terms of the GNU General Public License version 2 only, as 163.10 + * published by the Free Software Foundation. Oracle designates this 163.11 + * particular file as subject to the "Classpath" exception as provided 163.12 + * by Oracle in the LICENSE file that accompanied this code. 163.13 + * 163.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 163.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 163.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 163.17 + * version 2 for more details (a copy is included in the LICENSE file that 163.18 + * accompanied this code). 163.19 + * 163.20 + * You should have received a copy of the GNU General Public License version 163.21 + * 2 along with this work; if not, write to the Free Software Foundation, 163.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 163.23 + * 163.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 163.25 + * or visit www.oracle.com if you need additional information or have any 163.26 + * questions. 163.27 + */ 163.28 + 163.29 +// This script is loaded from jdk.nashorn.api.scripting.ScopeTest to test script class sharing and reuse. 163.30 + 163.31 +var v; 163.32 + 163.33 +Object.defineProperty(this, "accessor1", { 163.34 + get: function() { return v; }, 163.35 + set: function(n) { v = n; } 163.36 +}); 163.37 + 163.38 +Object.defineProperty(this, "accessor2", { 163.39 + get: function() { return x; }, 163.40 + set: function(n) { x = n; } 163.41 +});
164.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 164.2 +++ b/test/src/jdk/nashorn/api/scripting/resources/witheval.js Tue Apr 01 11:44:05 2014 -0700 164.3 @@ -0,0 +1,60 @@ 164.4 +/* 164.5 + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. 164.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 164.7 + * 164.8 + * This code is free software; you can redistribute it and/or modify it 164.9 + * under the terms of the GNU General Public License version 2 only, as 164.10 + * published by the Free Software Foundation. Oracle designates this 164.11 + * particular file as subject to the "Classpath" exception as provided 164.12 + * by Oracle in the LICENSE file that accompanied this code. 164.13 + * 164.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 164.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 164.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 164.17 + * version 2 for more details (a copy is included in the LICENSE file that 164.18 + * accompanied this code). 164.19 + * 164.20 + * You should have received a copy of the GNU General Public License version 164.21 + * 2 along with this work; if not, write to the Free Software Foundation, 164.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 164.23 + * 164.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 164.25 + * or visit www.oracle.com if you need additional information or have any 164.26 + * questions. 164.27 + */ 164.28 + 164.29 +// This script is loaded from jdk.nashorn.api.scripting.ScopeTest to test script class sharing and reuse. 164.30 + 164.31 +var a; 164.32 + 164.33 +function outer(p, e) { 164.34 + eval(e); 164.35 + with(p) { 164.36 + function inner() { 164.37 + a = 1; 164.38 + c = 10; 164.39 + if (a !== 1) { 164.40 + throw new Error("a !== 1"); 164.41 + } 164.42 + if (b !== 3) { 164.43 + throw new Error("b !== 3"); 164.44 + } 164.45 + if (c !== 10) { 164.46 + throw new Error("c !== 10"); 164.47 + } 164.48 + } 164.49 + inner(); 164.50 + } 164.51 +} 164.52 + 164.53 +outer({}, "b = 3;"); 164.54 + 164.55 +if (a !== 1) { 164.56 + throw new Error("a !== 1"); 164.57 +} 164.58 +if (b !== 3) { 164.59 + throw new Error("b !== 3"); 164.60 +} 164.61 +if (c !== 10) { 164.62 + throw new Error("c !== 10"); 164.63 +}
165.1 --- a/test/src/jdk/nashorn/internal/codegen/CompilerTest.java Wed Mar 26 12:01:34 2014 -0700 165.2 +++ b/test/src/jdk/nashorn/internal/codegen/CompilerTest.java Tue Apr 01 11:44:05 2014 -0700 165.3 @@ -28,6 +28,7 @@ 165.4 import java.io.File; 165.5 import java.io.PrintWriter; 165.6 import java.io.StringWriter; 165.7 +import jdk.nashorn.internal.objects.Global; 165.8 import jdk.nashorn.internal.runtime.Context; 165.9 import jdk.nashorn.internal.runtime.ErrorManager; 165.10 import jdk.nashorn.internal.runtime.ScriptFunction; 165.11 @@ -58,7 +59,7 @@ 165.12 } 165.13 165.14 private Context context; 165.15 - private ScriptObject global; 165.16 + private Global global; 165.17 165.18 @BeforeClass 165.19 public void setupTest() { 165.20 @@ -146,7 +147,7 @@ 165.21 log("Begin compiling " + file.getAbsolutePath()); 165.22 } 165.23 165.24 - final ScriptObject oldGlobal = Context.getGlobal(); 165.25 + final Global oldGlobal = Context.getGlobal(); 165.26 final boolean globalChanged = (oldGlobal != global); 165.27 165.28 try {
166.1 --- a/test/src/jdk/nashorn/internal/performance/PerformanceWrapper.java Wed Mar 26 12:01:34 2014 -0700 166.2 +++ b/test/src/jdk/nashorn/internal/performance/PerformanceWrapper.java Tue Apr 01 11:44:05 2014 -0700 166.3 @@ -31,9 +31,9 @@ 166.4 import java.util.concurrent.Future; 166.5 import java.util.concurrent.TimeUnit; 166.6 import java.util.concurrent.TimeoutException; 166.7 +import jdk.nashorn.internal.objects.Global; 166.8 import jdk.nashorn.internal.runtime.Context; 166.9 import jdk.nashorn.internal.runtime.ScriptFunction; 166.10 -import jdk.nashorn.internal.runtime.ScriptObject; 166.11 import jdk.nashorn.internal.runtime.ScriptRuntime; 166.12 166.13 /** 166.14 @@ -89,7 +89,7 @@ 166.15 @Override 166.16 protected Object apply(final ScriptFunction target, final Object self) { 166.17 if (_runsPerIteration == 0 && _numberOfIterations == 0) { 166.18 - final ScriptObject global = jdk.nashorn.internal.runtime.Context.getGlobal(); 166.19 + final Global global = jdk.nashorn.internal.runtime.Context.getGlobal(); 166.20 final ScriptFunction _target = target; 166.21 final Object _self = self; 166.22
167.1 --- a/test/src/jdk/nashorn/internal/runtime/ContextTest.java Wed Mar 26 12:01:34 2014 -0700 167.2 +++ b/test/src/jdk/nashorn/internal/runtime/ContextTest.java Tue Apr 01 11:44:05 2014 -0700 167.3 @@ -29,6 +29,7 @@ 167.4 import static org.testng.Assert.assertTrue; 167.5 167.6 import java.util.Map; 167.7 +import jdk.nashorn.internal.objects.Global; 167.8 import jdk.nashorn.internal.runtime.options.Options; 167.9 import org.testng.annotations.Test; 167.10 167.11 @@ -45,7 +46,7 @@ 167.12 final Options options = new Options(""); 167.13 final ErrorManager errors = new ErrorManager(); 167.14 final Context cx = new Context(options, errors, Thread.currentThread().getContextClassLoader()); 167.15 - final ScriptObject oldGlobal = Context.getGlobal(); 167.16 + final Global oldGlobal = Context.getGlobal(); 167.17 Context.setGlobal(cx.createGlobal()); 167.18 try { 167.19 String code = "22 + 10"; 167.20 @@ -65,7 +66,7 @@ 167.21 final ErrorManager errors = new ErrorManager(); 167.22 final Context cx = new Context(options, errors, Thread.currentThread().getContextClassLoader()); 167.23 final boolean strict = cx.getEnv()._strict; 167.24 - final ScriptObject oldGlobal = Context.getGlobal(); 167.25 + final Global oldGlobal = Context.getGlobal(); 167.26 Context.setGlobal(cx.createGlobal()); 167.27 167.28 try {
168.1 --- a/test/src/jdk/nashorn/internal/test/framework/SharedContextEvaluator.java Wed Mar 26 12:01:34 2014 -0700 168.2 +++ b/test/src/jdk/nashorn/internal/test/framework/SharedContextEvaluator.java Tue Apr 01 11:44:05 2014 -0700 168.3 @@ -34,10 +34,10 @@ 168.4 import java.io.OutputStream; 168.5 import java.io.PrintWriter; 168.6 import jdk.nashorn.api.scripting.NashornException; 168.7 +import jdk.nashorn.internal.objects.Global; 168.8 import jdk.nashorn.internal.runtime.Context; 168.9 import jdk.nashorn.internal.runtime.ErrorManager; 168.10 import jdk.nashorn.internal.runtime.ScriptFunction; 168.11 -import jdk.nashorn.internal.runtime.ScriptObject; 168.12 import jdk.nashorn.internal.runtime.ScriptRuntime; 168.13 import jdk.nashorn.internal.runtime.Source; 168.14 import jdk.nashorn.internal.runtime.options.Options; 168.15 @@ -110,12 +110,12 @@ 168.16 168.17 @Override 168.18 public int run(final OutputStream out, final OutputStream err, final String[] args) throws IOException { 168.19 - final ScriptObject oldGlobal = Context.getGlobal(); 168.20 + final Global oldGlobal = Context.getGlobal(); 168.21 try { 168.22 ctxOut.setDelegatee(out); 168.23 ctxErr.setDelegatee(err); 168.24 final ErrorManager errors = context.getErrorManager(); 168.25 - final ScriptObject global = context.createGlobal(); 168.26 + final Global global = context.createGlobal(); 168.27 Context.setGlobal(global); 168.28 168.29 // For each file on the command line.