test/script/basic/funcbind2.js

Tue, 15 Jan 2019 10:36:25 +0000

author
aefimov
date
Tue, 15 Jan 2019 10:36:25 +0000
changeset 2462
e9169a96a3d1
parent 962
ac62e33a99b0
permissions
-rw-r--r--

Added tag jdk8u202-ga for changeset 7aeae6eb6236

     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  * Test the functionality of Function.prototype.bind.
    26  *
    27  * @test
    28  * @run
    29  */
    31 function f(a, b) {
    32     print("f: this=" + this + ", a=" + a + ", b=" + b);
    33 }
    34 function v(a, b) {
    35     print("v: this=" + this + ", a=" + a + ", b=" + b + ", c=" + arguments[2]);
    36 }
    38 (f.bind(null))();
    39 (v.bind(null))();
    41 var boundThis = "boundThis";
    42 (f.bind(boundThis))();
    43 (v.bind(boundThis))();
    45 (f.bind(boundThis))("a0");
    46 (v.bind(boundThis))("a1");
    48 (f.bind(boundThis, "a2"))();
    49 (v.bind(boundThis, "a3"))();
    51 (f.bind(boundThis, "a4"))("b4");
    52 (v.bind(boundThis, "a5"))("b5");
    54 (f.bind(boundThis, "a6", "b6"))();
    55 (v.bind(boundThis, "a7", "b7"))();
    57 (f.bind(boundThis, "a8", "b8"))("c8"); // invoking with extra args after all were bound!
    58 (v.bind(boundThis, "a9", "b9"))("c9");
    60 (f.bind(boundThis, "a10", "b10", "c10"))(); // binding more args than it receives!
    61 (v.bind(boundThis, "a11", "b11", "c11"))();
    63 print("\nTest constructors\n");
    65 new (f.bind(boundThis))();
    66 new (v.bind(boundThis))();
    68 new (f.bind(boundThis))("a0");
    69 new (v.bind(boundThis))("a1");
    71 new (f.bind(boundThis, "a2"))();
    72 new (v.bind(boundThis, "a3"))();
    74 new (f.bind(boundThis, "a4"))("b4");
    75 new (v.bind(boundThis, "a5"))("b5");
    77 new (f.bind(boundThis, "a6", "b6"))();
    78 new (v.bind(boundThis, "a7", "b7"))();
    80 new (f.bind(boundThis, "a8", "b8"))("c8");
    81 new (v.bind(boundThis, "a9", "b9"))("c9");
    83 new (f.bind(boundThis, "a10", "b10", "c10"))();
    84 new (v.bind(boundThis, "a11", "b11", "c11"))();
    86 print("\nTest double binding\n");
    88 (f.bind(boundThis).bind("thisIsIgnored"))();
    89 new (f.bind("thisIsIgnored").bind("thisIsIgnoredToo"))();
    90 new (f.bind("thisIsIgnored", "a12").bind("thisIsIgnoredToo"))();
    92 (v.bind(boundThis).bind("thisIsIgnored"))();
    93 new (v.bind("thisIsIgnored").bind("thisIsIgnoredToo"))();
    94 new (v.bind("thisIsIgnored", "a13").bind("thisIsIgnoredToo"))();

mercurial