nashorn/test/script/basic/funcbind2.js
author twisti
Wed, 11 Nov 2015 14:40:38 -1000
changeset 34173 01bb07d23a5b
parent 24778 2ff5d7041566
permissions -rw-r--r--
8141133: [JVMCI] crash during safepoint deopt if rethrow_exception is set Reviewed-by: twisti Contributed-by: Gilles Duboscq <gilles.m.duboscq@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16228
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
     1
/*
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
     2
 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16228
diff changeset
     4
 *
16228
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
     7
 * published by the Free Software Foundation.
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16228
diff changeset
     8
 *
16228
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    13
 * accompanied this code).
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16228
diff changeset
    14
 *
16228
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16228
diff changeset
    18
 *
16228
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    21
 * questions.
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    22
 */
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    23
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    24
/**
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    25
 * Test the functionality of Function.prototype.bind.
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    26
 *
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    27
 * @test
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    28
 * @run
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    29
 */
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    30
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    31
function f(a, b) {
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    32
    print("f: this=" + this + ", a=" + a + ", b=" + b);
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    33
}
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    34
function v(a, b) {
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    35
    print("v: this=" + this + ", a=" + a + ", b=" + b + ", c=" + arguments[2]);
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    36
}
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    37
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    38
(f.bind(null))();
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    39
(v.bind(null))();
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    40
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    41
var boundThis = "boundThis";
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    42
(f.bind(boundThis))();
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    43
(v.bind(boundThis))();
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    44
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    45
(f.bind(boundThis))("a0");
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    46
(v.bind(boundThis))("a1");
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    47
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    48
(f.bind(boundThis, "a2"))();
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    49
(v.bind(boundThis, "a3"))();
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    50
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    51
(f.bind(boundThis, "a4"))("b4");
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    52
(v.bind(boundThis, "a5"))("b5");
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    53
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    54
(f.bind(boundThis, "a6", "b6"))();
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    55
(v.bind(boundThis, "a7", "b7"))();
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    56
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    57
(f.bind(boundThis, "a8", "b8"))("c8"); // invoking with extra args after all were bound!
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    58
(v.bind(boundThis, "a9", "b9"))("c9");
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    59
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    60
(f.bind(boundThis, "a10", "b10", "c10"))(); // binding more args than it receives!
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    61
(v.bind(boundThis, "a11", "b11", "c11"))();
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    62
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    63
print("\nTest constructors\n");
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    64
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    65
new (f.bind(boundThis))();
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    66
new (v.bind(boundThis))();
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    67
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    68
new (f.bind(boundThis))("a0");
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    69
new (v.bind(boundThis))("a1");
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    70
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    71
new (f.bind(boundThis, "a2"))();
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    72
new (v.bind(boundThis, "a3"))();
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    73
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    74
new (f.bind(boundThis, "a4"))("b4");
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    75
new (v.bind(boundThis, "a5"))("b5");
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    76
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    77
new (f.bind(boundThis, "a6", "b6"))();
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    78
new (v.bind(boundThis, "a7", "b7"))();
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    79
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    80
new (f.bind(boundThis, "a8", "b8"))("c8");
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    81
new (v.bind(boundThis, "a9", "b9"))("c9");
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    82
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    83
new (f.bind(boundThis, "a10", "b10", "c10"))();
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    84
new (v.bind(boundThis, "a11", "b11", "c11"))();
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    85
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    86
print("\nTest double binding\n");
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    87
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    88
(f.bind(boundThis).bind("thisIsIgnored"))();
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    89
new (f.bind("thisIsIgnored").bind("thisIsIgnoredToo"))();
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    90
new (f.bind("thisIsIgnored", "a12").bind("thisIsIgnoredToo"))();
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    91
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    92
(v.bind(boundThis).bind("thisIsIgnored"))();
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    93
new (v.bind("thisIsIgnored").bind("thisIsIgnoredToo"))();
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    94
new (v.bind("thisIsIgnored", "a13").bind("thisIsIgnoredToo"))();