Mercurial > hg > icedtea9-forest > nashorn
changeset 530:47f0a4c4b729
8023780: Gracefully handle @CS methods while binding bean properties
Reviewed-by: jlaskey, lagergren, sundar
author | attila |
---|---|
date | Tue, 27 Aug 2013 13:17:00 +0200 |
parents | 3bd077423a08 |
children | bda0e89f88ae |
files | src/jdk/nashorn/internal/objects/NativeObject.java test/script/basic/JDK-8023780.js test/script/basic/JDK-8023780.js.EXPECTED |
diffstat | 3 files changed, 76 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/src/jdk/nashorn/internal/objects/NativeObject.java Tue Aug 27 15:54:45 2013 +0530 +++ b/src/jdk/nashorn/internal/objects/NativeObject.java Tue Aug 27 13:17:00 2013 +0200 @@ -669,15 +669,43 @@ final List<AccessorProperty> properties = new ArrayList<>(propertyNames.size() + methodNames.size()); for(final String methodName: methodNames) { - properties.add(AccessorProperty.create(methodName, Property.NOT_WRITABLE, - getBoundBeanMethodGetter(source, getBeanOperation(linker, "dyn:getMethod:" + methodName, getterType, source)), - null)); + final MethodHandle method; + try { + method = getBeanOperation(linker, "dyn:getMethod:" + methodName, getterType, source); + } catch(final IllegalAccessError e) { + // Presumably, this was a caller sensitive method. Ignore it and carry on. + continue; + } + properties.add(AccessorProperty.create(methodName, Property.NOT_WRITABLE, getBoundBeanMethodGetter(source, + method), null)); } for(final String propertyName: propertyNames) { + MethodHandle getter; + if(readablePropertyNames.contains(propertyName)) { + try { + getter = getBeanOperation(linker, "dyn:getProp:" + propertyName, getterType, source); + } catch(final IllegalAccessError e) { + // Presumably, this was a caller sensitive method. Ignore it and carry on. + getter = Lookup.EMPTY_GETTER; + } + } else { + getter = Lookup.EMPTY_GETTER; + } final boolean isWritable = writablePropertyNames.contains(propertyName); - properties.add(AccessorProperty.create(propertyName, isWritable ? 0 : Property.NOT_WRITABLE, - readablePropertyNames.contains(propertyName) ? getBeanOperation(linker, "dyn:getProp:" + propertyName, getterType, source) : Lookup.EMPTY_GETTER, - isWritable ? getBeanOperation(linker, "dyn:setProp:" + propertyName, setterType, source) : Lookup.EMPTY_SETTER)); + MethodHandle setter; + if(isWritable) { + try { + setter = getBeanOperation(linker, "dyn:setProp:" + propertyName, setterType, source); + } catch(final IllegalAccessError e) { + // Presumably, this was a caller sensitive method. Ignore it and carry on. + setter = Lookup.EMPTY_SETTER; + } + } else { + setter = Lookup.EMPTY_SETTER; + } + if(getter != Lookup.EMPTY_GETTER || setter != Lookup.EMPTY_SETTER) { + properties.add(AccessorProperty.create(propertyName, isWritable ? 0 : Property.NOT_WRITABLE, getter, setter)); + } } targetObj.addBoundProperties(source, properties.toArray(new AccessorProperty[properties.size()]));
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/JDK-8023780.js Tue Aug 27 13:17:00 2013 +0200 @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * JDK-8023780: Gracefully handle @CS methods while binding bean properties + * + * @test + * @run + */ + +var obj = {} +Object.bindProperties(obj, java.lang.Thread.currentThread()); + +print(typeof obj.getName === "function") +print(typeof obj.getCurrentContext === "undefined") + +print(Object.hasOwnProperty("name")) +print(!Object.hasOwnProperty("currentContext"))