nashorn/test/script/basic/funcbind3.js
author attila
Tue, 12 Feb 2013 12:47:51 +0100
changeset 16228 df28320aa080
child 24778 2ff5d7041566
permissions -rw-r--r--
8007900: Function binding is inefficient Reviewed-by: jlaskey, lagergren
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.
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
     4
 * 
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.
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
     8
 * 
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).
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    14
 * 
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.
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    18
 * 
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 assumptions about bound function prototypes
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 printAssumption(__x__) {
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    32
  print(__x__ + ": " + eval(__x__));
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    33
}
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    34
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    35
function f() { }
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    36
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    37
var b = f.bind(null)
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    38
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    39
var x = new f()
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    40
var y = new b()
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    41
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    42
printAssumption("x instanceof f")
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    43
printAssumption("x instanceof b")
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    44
printAssumption("y instanceof f")
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    45
printAssumption("y instanceof b")
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    46
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    47
print("\nChanging prototype\n");
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    48
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    49
f.prototype=new Object()
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    50
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    51
printAssumption("x instanceof f")
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    52
printAssumption("x instanceof b")
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    53
printAssumption("y instanceof f")
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    54
printAssumption("y instanceof b")
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    55
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    56
print("\Bound function prototype\n");
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    57
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    58
printAssumption("f.hasOwnProperty('prototype')")
df28320aa080 8007900: Function binding is inefficient
attila
parents:
diff changeset
    59
printAssumption("b.hasOwnProperty('prototype')")