8023780: Gracefully handle @CS methods while binding bean properties

Tue, 27 Aug 2013 13:17:00 +0200

author
attila
date
Tue, 27 Aug 2013 13:17:00 +0200
changeset 531
47f0a4c4b729
parent 530
3bd077423a08
child 532
bda0e89f88ae

8023780: Gracefully handle @CS methods while binding bean properties
Reviewed-by: jlaskey, lagergren, sundar

src/jdk/nashorn/internal/objects/NativeObject.java file | annotate | diff | comparison | revisions
test/script/basic/JDK-8023780.js file | annotate | diff | comparison | revisions
test/script/basic/JDK-8023780.js.EXPECTED file | annotate | diff | comparison | revisions
     1.1 --- a/src/jdk/nashorn/internal/objects/NativeObject.java	Tue Aug 27 15:54:45 2013 +0530
     1.2 +++ b/src/jdk/nashorn/internal/objects/NativeObject.java	Tue Aug 27 13:17:00 2013 +0200
     1.3 @@ -669,15 +669,43 @@
     1.4  
     1.5          final List<AccessorProperty> properties = new ArrayList<>(propertyNames.size() + methodNames.size());
     1.6          for(final String methodName: methodNames) {
     1.7 -            properties.add(AccessorProperty.create(methodName, Property.NOT_WRITABLE,
     1.8 -                    getBoundBeanMethodGetter(source, getBeanOperation(linker, "dyn:getMethod:" + methodName, getterType, source)),
     1.9 -                    null));
    1.10 +            final MethodHandle method;
    1.11 +            try {
    1.12 +                method = getBeanOperation(linker, "dyn:getMethod:" + methodName, getterType, source);
    1.13 +            } catch(final IllegalAccessError e) {
    1.14 +                // Presumably, this was a caller sensitive method. Ignore it and carry on.
    1.15 +                continue;
    1.16 +            }
    1.17 +            properties.add(AccessorProperty.create(methodName, Property.NOT_WRITABLE, getBoundBeanMethodGetter(source,
    1.18 +                    method), null));
    1.19          }
    1.20          for(final String propertyName: propertyNames) {
    1.21 +            MethodHandle getter;
    1.22 +            if(readablePropertyNames.contains(propertyName)) {
    1.23 +                try {
    1.24 +                    getter = getBeanOperation(linker, "dyn:getProp:" + propertyName, getterType, source);
    1.25 +                } catch(final IllegalAccessError e) {
    1.26 +                    // Presumably, this was a caller sensitive method. Ignore it and carry on.
    1.27 +                    getter = Lookup.EMPTY_GETTER;
    1.28 +                }
    1.29 +            } else {
    1.30 +                getter = Lookup.EMPTY_GETTER;
    1.31 +            }
    1.32              final boolean isWritable = writablePropertyNames.contains(propertyName);
    1.33 -            properties.add(AccessorProperty.create(propertyName, isWritable ? 0 : Property.NOT_WRITABLE,
    1.34 -                    readablePropertyNames.contains(propertyName) ? getBeanOperation(linker, "dyn:getProp:" + propertyName, getterType, source) : Lookup.EMPTY_GETTER,
    1.35 -                    isWritable ? getBeanOperation(linker, "dyn:setProp:" + propertyName, setterType, source) : Lookup.EMPTY_SETTER));
    1.36 +            MethodHandle setter;
    1.37 +            if(isWritable) {
    1.38 +                try {
    1.39 +                    setter = getBeanOperation(linker, "dyn:setProp:" + propertyName, setterType, source);
    1.40 +                } catch(final IllegalAccessError e) {
    1.41 +                    // Presumably, this was a caller sensitive method. Ignore it and carry on.
    1.42 +                    setter = Lookup.EMPTY_SETTER;
    1.43 +                }
    1.44 +            } else {
    1.45 +                setter = Lookup.EMPTY_SETTER;
    1.46 +            }
    1.47 +            if(getter != Lookup.EMPTY_GETTER || setter != Lookup.EMPTY_SETTER) {
    1.48 +                properties.add(AccessorProperty.create(propertyName, isWritable ? 0 : Property.NOT_WRITABLE, getter, setter));
    1.49 +            }
    1.50          }
    1.51  
    1.52          targetObj.addBoundProperties(source, properties.toArray(new AccessorProperty[properties.size()]));
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/script/basic/JDK-8023780.js	Tue Aug 27 13:17:00 2013 +0200
     2.3 @@ -0,0 +1,38 @@
     2.4 +/*
     2.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
     2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.7 + * 
     2.8 + * This code is free software; you can redistribute it and/or modify it
     2.9 + * under the terms of the GNU General Public License version 2 only, as
    2.10 + * published by the Free Software Foundation.
    2.11 + * 
    2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    2.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    2.15 + * version 2 for more details (a copy is included in the LICENSE file that
    2.16 + * accompanied this code).
    2.17 + * 
    2.18 + * You should have received a copy of the GNU General Public License version
    2.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    2.21 + * 
    2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    2.23 + * or visit www.oracle.com if you need additional information or have any
    2.24 + * questions.
    2.25 + */
    2.26 +
    2.27 +/**
    2.28 + * JDK-8023780: Gracefully handle @CS methods while binding bean properties
    2.29 + *
    2.30 + * @test
    2.31 + * @run
    2.32 + */
    2.33 +
    2.34 +var obj = {}
    2.35 +Object.bindProperties(obj, java.lang.Thread.currentThread());
    2.36 +
    2.37 +print(typeof obj.getName === "function")
    2.38 +print(typeof obj.getCurrentContext === "undefined")
    2.39 +
    2.40 +print(Object.hasOwnProperty("name"))
    2.41 +print(!Object.hasOwnProperty("currentContext"))
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/script/basic/JDK-8023780.js.EXPECTED	Tue Aug 27 13:17:00 2013 +0200
     3.3 @@ -0,0 +1,4 @@
     3.4 +true
     3.5 +true
     3.6 +true
     3.7 +true

mercurial