test/script/basic/JDK-8021122.js

Tue, 21 Mar 2017 13:41:57 -0700

author
asaha
date
Tue, 21 Mar 2017 13:41:57 -0700
changeset 2160
1df40fe54cd6
parent 962
ac62e33a99b0
permissions
-rw-r--r--

Merge

     1 /*
     2  * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  */
    24 /**
    25  * JDK-8021122: Not all callables are handled for toString and other function valued properties
    26  *
    27  * @test
    28  * @run
    29  */
    31 var a = {}
    32 var obj = new java.util.HashMap();
    33 Object.bindProperties(a, obj);
    34 try {
    35     print(a);
    36 } catch (e) {
    37     print(e);
    38 }
    40 var a = {}
    41 var global = loadWithNewGlobal({ name:"xx", script: "this" });
    42 var obj = global.eval("({ toString: function() { return 'hello'; } })");
    43 Object.bindProperties(a, obj);
    44 try {
    45     print(a);
    46 } catch (e) {
    47     print(e);
    48 }
    50 function runLambdaTests() {
    51     var r = new java.lang.Runnable() {
    52         run: function() { print("I am runnable"); }
    53     };
    55     // call any @FunctionalInterface object as though it is a function
    56     r();
    58     var twice = new java.util.function.Function() {
    59         apply: function(x) 2*x
    60     };
    62     print(twice(34));
    64     var sum = new java.util.function.BiFunction() {
    65         apply: function(x, y) x + y
    66     };
    68     print(sum(32, 12))
    70     // make toString to be a @FunctionalInterface object
    71     var a = {};
    72     a.toString = new java.util.function.Supplier() {
    73         get: function() { return "MyString"; }
    74     };
    76     try {
    77         print(a);
    78     } catch (e) {
    79         print(e);
    80     }
    81 }
    83 try {
    84     // check for java.util.function.Function class
    85     Java.type("java.util.function.Function");
    86     runLambdaTests();
    87 } catch (e) {
    88     // fake output to match .EXPECTED values
    89     print("I am runnable");
    90     print("68");
    91     print("44");
    92     print("MyString");
    93 }

mercurial