test/script/basic/apply_to_call/apply_to_call5.js

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

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

Added tag jdk8u202-ga for changeset 7aeae6eb6236

lagergren@1028 1 /*
lagergren@1028 2 * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
lagergren@1028 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
lagergren@1028 4 *
lagergren@1028 5 * This code is free software; you can redistribute it and/or modify it
lagergren@1028 6 * under the terms of the GNU General Public License version 2 only, as
lagergren@1028 7 * published by the Free Software Foundation.
lagergren@1028 8 *
lagergren@1028 9 * This code is distributed in the hope that it will be useful, but WITHOUT
lagergren@1028 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
lagergren@1028 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
lagergren@1028 12 * version 2 for more details (a copy is included in the LICENSE file that
lagergren@1028 13 * accompanied this code).
lagergren@1028 14 *
lagergren@1028 15 * You should have received a copy of the GNU General Public License version
lagergren@1028 16 * 2 along with this work; if not, write to the Free Software Foundation,
lagergren@1028 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
lagergren@1028 18 *
lagergren@1028 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
lagergren@1028 20 * or visit www.oracle.com if you need additional information or have any
lagergren@1028 21 * questions.
lagergren@1028 22 */
lagergren@1028 23
lagergren@1028 24 /**
lagergren@1028 25 * apply_to_call5.js - do one apply to call specialization, then override, apply and make sure it reverts (i.e. stops
lagergren@1028 26 * calling call)
lagergren@1028 27 *
lagergren@1028 28 * @test
lagergren@1028 29 * @run
lagergren@1028 30 */
lagergren@1028 31
lagergren@1028 32 print("start");
lagergren@1028 33
lagergren@1028 34 var x = {
lagergren@1028 35 a : 0,
lagergren@1028 36 b : 0,
lagergren@1028 37 c : 0,
lagergren@1028 38 initialize : function(x,y,z) {
lagergren@1028 39 this.a = x;
lagergren@1028 40 this.b = y;
lagergren@1028 41 this.c = z;
lagergren@1028 42 }
lagergren@1028 43 };
lagergren@1028 44
lagergren@1028 45 function test() {
lagergren@1028 46 x.initialize.apply(x, arguments);
lagergren@1028 47 }
lagergren@1028 48
lagergren@1028 49 test(4711,23,17);
lagergren@1028 50 print(x.a);
lagergren@1028 51 print(x.b);
lagergren@1028 52 print(x.c);
lagergren@1028 53
lagergren@1028 54 print("Overwriting apply now");
lagergren@1028 55 x.initialize.apply = function() { print("New function for apply - not a property"); }
lagergren@1028 56
lagergren@1028 57 test(4712);
lagergren@1028 58 print(x.a);
lagergren@1028 59
lagergren@1028 60
lagergren@1028 61 var x2 = {
lagergren@1028 62 a : 0,
lagergren@1028 63 b : 0,
lagergren@1028 64 c : 0,
lagergren@1028 65 initialize : function(x,y,z) {
lagergren@1028 66 this.a = x;
lagergren@1028 67 this.b = y;
lagergren@1028 68 this.c = z;
lagergren@1028 69 }
lagergren@1028 70 };
lagergren@1028 71
lagergren@1028 72 function test2() {
lagergren@1028 73 x2.initialize.apply(x2, arguments);
lagergren@1028 74 }
lagergren@1028 75
lagergren@1028 76 test2(4711,23,17);
lagergren@1028 77 print(x2.a);
lagergren@1028 78 print(x2.b);
lagergren@1028 79 print(x2.c);
lagergren@1028 80
lagergren@1028 81 print("Overwriting apply now");
lagergren@1028 82 x2.initialize['apply'] = function() { print("New function for apply - not a property"); }
lagergren@1028 83
lagergren@1028 84 test(4712);
lagergren@1028 85 print(x2.a);
lagergren@1028 86
lagergren@1028 87 var x3 = {
lagergren@1028 88 a : 0,
lagergren@1028 89 b : 0,
lagergren@1028 90 c : 0,
lagergren@1028 91 initialize : function(x,y,z) {
lagergren@1028 92 this.a = x;
lagergren@1028 93 this.b = y;
lagergren@1028 94 this.c = z;
lagergren@1028 95 }
lagergren@1028 96 };
lagergren@1028 97
lagergren@1028 98 function test3() {
lagergren@1028 99 x3.initialize.apply(x3, arguments);
lagergren@1028 100 }
lagergren@1028 101
lagergren@1028 102 test3(4711,23,17);
lagergren@1028 103 print(x3.a);
lagergren@1028 104 print(x3.b);
lagergren@1028 105 print(x3.c);
lagergren@1028 106
lagergren@1028 107 print("Overwriting apply now");
lagergren@1028 108 eval("x3.initialize['apply'] = function() { print('New function for apply - not a property'); }");
lagergren@1028 109
lagergren@1028 110 test(4712);
lagergren@1028 111 print(x3.a);

mercurial