mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-15 18:33:41 +00:00
8023780: Gracefully handle @CS methods while binding bean properties
Reviewed-by: jlaskey, lagergren, sundar
This commit is contained in:
parent
359034825f
commit
a9796aeea0
@ -669,15 +669,43 @@ public final class NativeObject {
|
||||
|
||||
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()]));
|
||||
|
||||
38
nashorn/test/script/basic/JDK-8023780.js
Normal file
38
nashorn/test/script/basic/JDK-8023780.js
Normal file
@ -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"))
|
||||
4
nashorn/test/script/basic/JDK-8023780.js.EXPECTED
Normal file
4
nashorn/test/script/basic/JDK-8023780.js.EXPECTED
Normal file
@ -0,0 +1,4 @@
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
Loading…
x
Reference in New Issue
Block a user