Wed, 21 Aug 2013 17:28:53 +0530
8023368: Instance __proto__ property should exist and be writable.
Reviewed-by: attila, hannesw
1.1 --- a/src/jdk/nashorn/api/scripting/ScriptObjectMirror.java Wed Aug 21 13:39:40 2013 +0200 1.2 +++ b/src/jdk/nashorn/api/scripting/ScriptObjectMirror.java Wed Aug 21 17:28:53 2013 +0530 1.3 @@ -374,6 +374,19 @@ 1.4 } 1.5 1.6 /** 1.7 + * Set the __proto__ of this object. 1.8 + * @param proto new proto for this object 1.9 + */ 1.10 + public void setProto(final Object proto) { 1.11 + inGlobal(new Callable<Void>() { 1.12 + @Override public Void call() { 1.13 + sobj.setProtoCheck(unwrap(proto, global)); 1.14 + return null; 1.15 + } 1.16 + }); 1.17 + } 1.18 + 1.19 + /** 1.20 * ECMA 8.12.1 [[GetOwnProperty]] (P) 1.21 * 1.22 * @param key property key
2.1 --- a/src/jdk/nashorn/internal/objects/NativeObject.java Wed Aug 21 13:39:40 2013 +0200 2.2 +++ b/src/jdk/nashorn/internal/objects/NativeObject.java Wed Aug 21 17:28:53 2013 +0530 2.3 @@ -125,6 +125,28 @@ 2.4 } 2.5 2.6 /** 2.7 + * Nashorn extension: Object.setPrototypeOf ( O, proto ) 2.8 + * Also found in ES6 draft specification. 2.9 + * 2.10 + * @param self self reference 2.11 + * @param obj object to set prototype for 2.12 + * @param proto prototype object to be used 2.13 + * @return object whose prototype is set 2.14 + */ 2.15 + @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 2.16 + public static Object setPrototypeOf(final Object self, final Object obj, final Object proto) { 2.17 + if (obj instanceof ScriptObject) { 2.18 + ((ScriptObject)obj).setProtoCheck(proto); 2.19 + return obj; 2.20 + } else if (obj instanceof ScriptObjectMirror) { 2.21 + ((ScriptObjectMirror)obj).setProto(proto); 2.22 + return obj; 2.23 + } 2.24 + 2.25 + throw notAnObject(obj); 2.26 + } 2.27 + 2.28 + /** 2.29 * ECMA 15.2.3.3 Object.getOwnPropertyDescriptor ( O, P ) 2.30 * 2.31 * @param self self reference 2.32 @@ -184,7 +206,7 @@ 2.33 // FIXME: should we create a proper object with correct number of 2.34 // properties? 2.35 final ScriptObject newObj = Global.newEmptyInstance(); 2.36 - newObj.setProtoCheck(proto); 2.37 + newObj.setProto((ScriptObject)proto); 2.38 if (props != UNDEFINED) { 2.39 NativeObject.defineProperties(self, newObj, props); 2.40 }
3.1 --- a/src/jdk/nashorn/internal/runtime/PropertyListener.java Wed Aug 21 13:39:40 2013 +0200 3.2 +++ b/src/jdk/nashorn/internal/runtime/PropertyListener.java Wed Aug 21 17:28:53 2013 +0530 3.3 @@ -54,4 +54,13 @@ 3.4 * 3.5 */ 3.6 public void propertyModified(ScriptObject object, Property oldProp, Property newProp); 3.7 + 3.8 + /** 3.9 + * Given object's __proto__ has changed. 3.10 + * 3.11 + * @param object object whose __proto__ has changed. 3.12 + * @param oldProto old __proto__ 3.13 + * @param newProto new __proto__ 3.14 + */ 3.15 + public void protoChanged(ScriptObject object, ScriptObject oldProto, ScriptObject newProto); 3.16 }
4.1 --- a/src/jdk/nashorn/internal/runtime/PropertyListenerManager.java Wed Aug 21 13:39:40 2013 +0200 4.2 +++ b/src/jdk/nashorn/internal/runtime/PropertyListenerManager.java Wed Aug 21 17:28:53 2013 +0530 4.3 @@ -140,6 +140,21 @@ 4.4 } 4.5 } 4.6 4.7 + /** 4.8 + * This method can be called to notify __proto__ modification to this object's listeners. 4.9 + * 4.10 + * @param object The ScriptObject whose __proto__ was changed. 4.11 + * @param oldProto old __proto__ 4.12 + * @param newProto new __proto__ 4.13 + */ 4.14 + protected synchronized final void notifyProtoChanged(final ScriptObject object, final ScriptObject oldProto, final ScriptObject newProto) { 4.15 + if (listeners != null) { 4.16 + for (PropertyListener listener : listeners.keySet()) { 4.17 + listener.protoChanged(object, oldProto, newProto); 4.18 + } 4.19 + } 4.20 + } 4.21 + 4.22 // PropertyListener methods 4.23 4.24 @Override 4.25 @@ -156,4 +171,9 @@ 4.26 public final void propertyModified(final ScriptObject object, final Property oldProp, final Property newProp) { 4.27 notifyPropertyModified(object, oldProp, newProp); 4.28 } 4.29 + 4.30 + @Override 4.31 + public final void protoChanged(final ScriptObject object, final ScriptObject oldProto, final ScriptObject newProto) { 4.32 + notifyProtoChanged(object, oldProto, newProto); 4.33 + } 4.34 }
5.1 --- a/src/jdk/nashorn/internal/runtime/PropertyMap.java Wed Aug 21 13:39:40 2013 +0200 5.2 +++ b/src/jdk/nashorn/internal/runtime/PropertyMap.java Wed Aug 21 17:28:53 2013 +0530 5.3 @@ -230,7 +230,7 @@ 5.4 } 5.5 5.6 /** 5.7 - * Indicate that a prototype property hash changed. 5.8 + * Indicate that a prototype property has changed. 5.9 * 5.10 * @param property {@link Property} to invalidate. 5.11 */ 5.12 @@ -251,6 +251,18 @@ 5.13 } 5.14 5.15 /** 5.16 + * Indicate that proto itself has changed in hierachy somewhere. 5.17 + */ 5.18 + private void invalidateAllProtoGetSwitchPoints() { 5.19 + assert !isShared() : "proto invalidation on a shared PropertyMap"; 5.20 + 5.21 + if (protoGetSwitches != null) { 5.22 + final Collection<SwitchPoint> sws = protoGetSwitches.values(); 5.23 + SwitchPoint.invalidateAll(sws.toArray(new SwitchPoint[sws.size()])); 5.24 + } 5.25 + } 5.26 + 5.27 + /** 5.28 * Add a property to the map, re-binding its getters and setters, 5.29 * if available, to a given receiver. This is typically the global scope. See 5.30 * {@link ScriptObject#addBoundProperties(ScriptObject)} 5.31 @@ -878,6 +890,15 @@ 5.32 invalidateProtoGetSwitchPoint(oldProp); 5.33 } 5.34 5.35 + @Override 5.36 + public void protoChanged(final ScriptObject object, final ScriptObject oldProto, final ScriptObject newProto) { 5.37 + // We may walk and invalidate SwitchPoints for properties inherited 5.38 + // from 'object' or it's old proto chain. But, it may not be worth it. 5.39 + // For example, a new proto may have a user defined getter/setter for 5.40 + // a data property down the chain. So, invalidating all is better. 5.41 + invalidateAllProtoGetSwitchPoints(); 5.42 + } 5.43 + 5.44 /* 5.45 * Debugging and statistics. 5.46 */
6.1 --- a/src/jdk/nashorn/internal/runtime/ScriptEnvironment.java Wed Aug 21 13:39:40 2013 +0200 6.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptEnvironment.java Wed Aug 21 17:28:53 2013 +0530 6.3 @@ -128,9 +128,6 @@ 6.4 /** Do not support typed arrays. */ 6.5 public final boolean _no_typed_arrays; 6.6 6.7 - /** Package to which generated class files are added */ 6.8 - public final String _package; 6.9 - 6.10 /** Only parse the source code, do not compile */ 6.11 public final boolean _parse_only; 6.12 6.13 @@ -216,7 +213,6 @@ 6.14 _no_java = options.getBoolean("no.java"); 6.15 _no_syntax_extensions = options.getBoolean("no.syntax.extensions"); 6.16 _no_typed_arrays = options.getBoolean("no.typed.arrays"); 6.17 - _package = options.getString("package"); 6.18 _parse_only = options.getBoolean("parse.only"); 6.19 _print_ast = options.getBoolean("print.ast"); 6.20 _print_lower_ast = options.getBoolean("print.lower.ast");
7.1 --- a/src/jdk/nashorn/internal/runtime/ScriptObject.java Wed Aug 21 13:39:40 2013 +0200 7.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptObject.java Wed Aug 21 17:28:53 2013 +0530 7.3 @@ -1129,6 +1129,9 @@ 7.4 proto = newProto; 7.5 7.6 if (isPrototype()) { 7.7 + // tell listeners that my __proto__ has been changed 7.8 + notifyProtoChanged(this, oldProto, newProto); 7.9 + 7.10 if (oldProto != null) { 7.11 oldProto.removePropertyListener(this); 7.12 } 7.13 @@ -1144,7 +1147,19 @@ 7.14 * @param newProto Prototype to set. 7.15 */ 7.16 public final void setProtoCheck(final Object newProto) { 7.17 + if (!isExtensible()) { 7.18 + throw typeError("__proto__.set.non.extensible", ScriptRuntime.safeToString(this)); 7.19 + } 7.20 + 7.21 if (newProto == null || newProto instanceof ScriptObject) { 7.22 + // check for circularity 7.23 + ScriptObject proto = (ScriptObject)newProto; 7.24 + while (proto != null) { 7.25 + if (proto == this) { 7.26 + throw typeError("circular.__proto__.set", ScriptRuntime.safeToString(this)); 7.27 + } 7.28 + proto = proto.getProto(); 7.29 + } 7.30 setProto((ScriptObject)newProto); 7.31 } else { 7.32 final ScriptObject global = Context.getGlobalTrusted();
8.1 --- a/src/jdk/nashorn/internal/runtime/resources/Messages.properties Wed Aug 21 13:39:40 2013 +0200 8.2 +++ b/src/jdk/nashorn/internal/runtime/resources/Messages.properties Wed Aug 21 17:28:53 2013 +0530 8.3 @@ -94,6 +94,8 @@ 8.4 type.error.cant.redefine.property=Cannot redefine property "{0}" of {1} 8.5 type.error.property.not.writable="{0}" is not a writable property of {1} 8.6 type.error.object.non.extensible=Cannot add new property "{0}" to non-extensible {1} 8.7 +type.error.__proto__.set.non.extensible=Cannot set __proto__ of non-extensible {0} 8.8 +type.error.circular.__proto__.set=Cannot create__proto__ cycle for {0} 8.9 8.10 # miscellaneous 8.11 type.error.regex.cant.supply.flags=Cannot supply flags when constructing one RegExp from another
9.1 --- a/src/jdk/nashorn/internal/runtime/resources/Options.properties Wed Aug 21 13:39:40 2013 +0200 9.2 +++ b/src/jdk/nashorn/internal/runtime/resources/Options.properties Wed Aug 21 17:28:53 2013 +0530 9.3 @@ -216,15 +216,6 @@ 9.4 default=false \ 9.5 } 9.6 9.7 -nashorn.option.package = { \ 9.8 - name="--package", \ 9.9 - is_undocumented=true, \ 9.10 - desc="Package to which generated .class files are added.", \ 9.11 - params="<package>", \ 9.12 - type=String, \ 9.13 - default="" \ 9.14 -} 9.15 - 9.16 nashorn.option.parse.only = { \ 9.17 name="--parse-only", \ 9.18 is_undocumented=true, \
10.1 --- a/src/jdk/nashorn/internal/runtime/resources/mozilla_compat.js Wed Aug 21 13:39:40 2013 +0200 10.2 +++ b/src/jdk/nashorn/internal/runtime/resources/mozilla_compat.js Wed Aug 21 17:28:53 2013 +0530 10.3 @@ -144,7 +144,7 @@ 10.4 return Object.getPrototypeOf(this); 10.5 }, 10.6 set: function(x) { 10.7 - throw new TypeError("__proto__ set not supported"); 10.8 + Object.setPrototypeOf(this, x); 10.9 } 10.10 }); 10.11
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 11.2 +++ b/test/script/basic/JDK-8023368.js Wed Aug 21 17:28:53 2013 +0530 11.3 @@ -0,0 +1,73 @@ 11.4 +/* 11.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 11.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 11.7 + * 11.8 + * This code is free software; you can redistribute it and/or modify it 11.9 + * under the terms of the GNU General Public License version 2 only, as 11.10 + * published by the Free Software Foundation. 11.11 + * 11.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 11.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11.15 + * version 2 for more details (a copy is included in the LICENSE file that 11.16 + * accompanied this code). 11.17 + * 11.18 + * You should have received a copy of the GNU General Public License version 11.19 + * 2 along with this work; if not, write to the Free Software Foundation, 11.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 11.21 + * 11.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 11.23 + * or visit www.oracle.com if you need additional information or have any 11.24 + * questions. 11.25 + */ 11.26 + 11.27 +/** 11.28 + * JDK-8023368: Instance __proto__ property should exist and be writable. 11.29 + * 11.30 + * @test 11.31 + * @run 11.32 + */ 11.33 + 11.34 +load("nashorn:mozilla_compat.js"); 11.35 + 11.36 +// function to force same callsites 11.37 +function check(obj) { 11.38 + print(obj.func()); 11.39 + print(obj.x); 11.40 + print(obj.toString()); 11.41 +} 11.42 + 11.43 +function Func() { 11.44 +} 11.45 + 11.46 +Func.prototype.func = function() { 11.47 + return "Func.prototype.func"; 11.48 +} 11.49 + 11.50 +Func.prototype.x = "hello"; 11.51 + 11.52 +var obj = new Func(); 11.53 +var obj2 = Object.create(obj); 11.54 + 11.55 +// check direct and indirect __proto__ change 11.56 +check(obj); 11.57 +check(obj2); 11.58 +obj.__proto__ = { 11.59 + func: function() { 11.60 + return "obj.__proto__.func @ " + __LINE__; 11.61 + }, 11.62 + x: 344 11.63 +}; 11.64 + 11.65 +check(obj); 11.66 +check(obj2); 11.67 + 11.68 +// check indirect (1 and 2 levels) __proto__ function change 11.69 +obj.__proto__.__proto__ = { 11.70 + toString: function() { 11.71 + return "new object.toString"; 11.72 + } 11.73 +}; 11.74 + 11.75 +check(obj); 11.76 +check(obj2);
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 12.2 +++ b/test/script/basic/JDK-8023368.js.EXPECTED Wed Aug 21 17:28:53 2013 +0530 12.3 @@ -0,0 +1,18 @@ 12.4 +Func.prototype.func 12.5 +hello 12.6 +[object Object] 12.7 +Func.prototype.func 12.8 +hello 12.9 +[object Object] 12.10 +obj.__proto__.func @ 57 12.11 +344 12.12 +[object Object] 12.13 +obj.__proto__.func @ 57 12.14 +344 12.15 +[object Object] 12.16 +obj.__proto__.func @ 57 12.17 +344 12.18 +new object.toString 12.19 +obj.__proto__.func @ 57 12.20 +344 12.21 +new object.toString
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 13.2 +++ b/test/script/basic/JDK-8023368_2.js Wed Aug 21 17:28:53 2013 +0530 13.3 @@ -0,0 +1,73 @@ 13.4 +/* 13.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 13.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 13.7 + * 13.8 + * This code is free software; you can redistribute it and/or modify it 13.9 + * under the terms of the GNU General Public License version 2 only, as 13.10 + * published by the Free Software Foundation. 13.11 + * 13.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 13.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13.15 + * version 2 for more details (a copy is included in the LICENSE file that 13.16 + * accompanied this code). 13.17 + * 13.18 + * You should have received a copy of the GNU General Public License version 13.19 + * 2 along with this work; if not, write to the Free Software Foundation, 13.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 13.21 + * 13.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 13.23 + * or visit www.oracle.com if you need additional information or have any 13.24 + * questions. 13.25 + */ 13.26 + 13.27 +/** 13.28 + * JDK-8023368: Instance __proto__ property should exist and be writable. 13.29 + * 13.30 + * @test 13.31 + * @run 13.32 + */ 13.33 + 13.34 +// check Object.setPrototypeOf extension rather than using __proto__ 13.35 + 13.36 +// function to force same callsites 13.37 +function check(obj) { 13.38 + print(obj.func()); 13.39 + print(obj.x); 13.40 + print(obj.toString()); 13.41 +} 13.42 + 13.43 +function Func() { 13.44 +} 13.45 + 13.46 +Func.prototype.func = function() { 13.47 + return "Func.prototype.func"; 13.48 +} 13.49 + 13.50 +Func.prototype.x = "hello"; 13.51 + 13.52 +var obj = new Func(); 13.53 +var obj2 = Object.create(obj); 13.54 + 13.55 +// check direct and indirect __proto__ change 13.56 +check(obj); 13.57 +check(obj2); 13.58 +Object.setPrototypeOf(obj, { 13.59 + func: function() { 13.60 + return "obj.__proto__.func @ " + __LINE__; 13.61 + }, 13.62 + x: 344 13.63 +}); 13.64 + 13.65 +check(obj); 13.66 +check(obj2); 13.67 + 13.68 +// check indirect (1 and 2 levels) __proto__ function change 13.69 +Object.setPrototypeOf(Object.getPrototypeOf(obj), { 13.70 + toString: function() { 13.71 + return "new object.toString"; 13.72 + } 13.73 +}); 13.74 + 13.75 +check(obj); 13.76 +check(obj2);
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 14.2 +++ b/test/script/basic/JDK-8023368_2.js.EXPECTED Wed Aug 21 17:28:53 2013 +0530 14.3 @@ -0,0 +1,18 @@ 14.4 +Func.prototype.func 14.5 +hello 14.6 +[object Object] 14.7 +Func.prototype.func 14.8 +hello 14.9 +[object Object] 14.10 +obj.__proto__.func @ 57 14.11 +344 14.12 +[object Object] 14.13 +obj.__proto__.func @ 57 14.14 +344 14.15 +[object Object] 14.16 +obj.__proto__.func @ 57 14.17 +344 14.18 +new object.toString 14.19 +obj.__proto__.func @ 57 14.20 +344 14.21 +new object.toString
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 15.2 +++ b/test/script/basic/circular_proto.js Wed Aug 21 17:28:53 2013 +0530 15.3 @@ -0,0 +1,46 @@ 15.4 +/* 15.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 15.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 15.7 + * 15.8 + * This code is free software; you can redistribute it and/or modify it 15.9 + * under the terms of the GNU General Public License version 2 only, as 15.10 + * published by the Free Software Foundation. 15.11 + * 15.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 15.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15.15 + * version 2 for more details (a copy is included in the LICENSE file that 15.16 + * accompanied this code). 15.17 + * 15.18 + * You should have received a copy of the GNU General Public License version 15.19 + * 2 along with this work; if not, write to the Free Software Foundation, 15.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 15.21 + * 15.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 15.23 + * or visit www.oracle.com if you need additional information or have any 15.24 + * questions. 15.25 + */ 15.26 + 15.27 +/** 15.28 + * JDK-8023368: Instance __proto__ property should exist and be writable. 15.29 + * 15.30 + * @test 15.31 + * @run 15.32 + */ 15.33 + 15.34 +// check that we cannot create __proto__ cycle 15.35 +load("nashorn:mozilla_compat.js"); 15.36 + 15.37 +var obj = {}; 15.38 +var obj2 = Object.create(obj); 15.39 + 15.40 +// attempt to create __proto__ cycle 15.41 +try { 15.42 + obj.__proto__ = obj2; 15.43 + fail("Should have thrown TypeError"); 15.44 +} catch (e) { 15.45 + if (! (e instanceof TypeError)) { 15.46 + fail("Expected TypeError, got " + e); 15.47 + } 15.48 + print(e); 15.49 +}
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 16.2 +++ b/test/script/basic/circular_proto.js.EXPECTED Wed Aug 21 17:28:53 2013 +0530 16.3 @@ -0,0 +1,1 @@ 16.4 +TypeError: Cannot create__proto__ cycle for [object Object]
17.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 17.2 +++ b/test/script/basic/mirror_proto_assign.js Wed Aug 21 17:28:53 2013 +0530 17.3 @@ -0,0 +1,52 @@ 17.4 +/* 17.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 17.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 17.7 + * 17.8 + * This code is free software; you can redistribute it and/or modify it 17.9 + * under the terms of the GNU General Public License version 2 only, as 17.10 + * published by the Free Software Foundation. 17.11 + * 17.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 17.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 17.15 + * version 2 for more details (a copy is included in the LICENSE file that 17.16 + * accompanied this code). 17.17 + * 17.18 + * You should have received a copy of the GNU General Public License version 17.19 + * 2 along with this work; if not, write to the Free Software Foundation, 17.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 17.21 + * 17.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 17.23 + * or visit www.oracle.com if you need additional information or have any 17.24 + * questions. 17.25 + */ 17.26 + 17.27 +/** 17.28 + * JDK-8023368: Instance __proto__ property should exist and be writable. 17.29 + * 17.30 + * @test 17.31 + * @run 17.32 + */ 17.33 + 17.34 +// check that Object.setPrototypeOf works for mirror objects as well. 17.35 + 17.36 +var global = loadWithNewGlobal({ 17.37 + name: "test", 17.38 + script: "var obj = {}; this" 17.39 +}); 17.40 + 17.41 +var proto = global.eval("({ foo: 323 })"); 17.42 + 17.43 +Object.setPrototypeOf(global.obj, proto); 17.44 + 17.45 +function func(obj) { 17.46 + // check proto inherited value 17.47 + print("obj.foo = " + obj.foo); 17.48 +} 17.49 + 17.50 +func(global.obj); 17.51 + 17.52 +var newProto = global.eval("({ foo: 'hello' })"); 17.53 +Object.setPrototypeOf(global.obj, newProto); 17.54 + 17.55 +func(global.obj);
18.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 18.2 +++ b/test/script/basic/mirror_proto_assign.js.EXPECTED Wed Aug 21 17:28:53 2013 +0530 18.3 @@ -0,0 +1,2 @@ 18.4 +obj.foo = 323 18.5 +obj.foo = hello
19.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 19.2 +++ b/test/script/basic/nonextensible_proto_assign.js Wed Aug 21 17:28:53 2013 +0530 19.3 @@ -0,0 +1,44 @@ 19.4 +/* 19.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 19.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 19.7 + * 19.8 + * This code is free software; you can redistribute it and/or modify it 19.9 + * under the terms of the GNU General Public License version 2 only, as 19.10 + * published by the Free Software Foundation. 19.11 + * 19.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 19.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 19.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19.15 + * version 2 for more details (a copy is included in the LICENSE file that 19.16 + * accompanied this code). 19.17 + * 19.18 + * You should have received a copy of the GNU General Public License version 19.19 + * 2 along with this work; if not, write to the Free Software Foundation, 19.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19.21 + * 19.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 19.23 + * or visit www.oracle.com if you need additional information or have any 19.24 + * questions. 19.25 + */ 19.26 + 19.27 +/** 19.28 + * JDK-8023368: Instance __proto__ property should exist and be writable. 19.29 + * 19.30 + * @test 19.31 + * @run 19.32 + */ 19.33 + 19.34 +load("nashorn:mozilla_compat.js") 19.35 + 19.36 +// check that we cannot assign to __proto__ of a non-extensible object 19.37 +try { 19.38 + var obj = {} 19.39 + Object.preventExtensions(obj); 19.40 + obj.__proto__ = { }; 19.41 + fail("Should have thrown TypeError"); 19.42 +} catch (e) { 19.43 + if (! (e instanceof TypeError)) { 19.44 + fail("Expected TypeError, got " + e); 19.45 + } 19.46 + print(e); 19.47 +}
20.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 20.2 +++ b/test/script/basic/nonextensible_proto_assign.js.EXPECTED Wed Aug 21 17:28:53 2013 +0530 20.3 @@ -0,0 +1,1 @@ 20.4 +TypeError: Cannot set __proto__ of non-extensible [object Object]