Wed, 01 Oct 2014 07:47:24 -0700
Added tag jdk8u40-b08 for changeset 89551828b279
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 * Verify that JSAdapter works as expected.
26 *
27 * @test
28 * @run
29 */
31 var obj = new JSAdapter() {
32 __get__: function(name) {
33 print("getter called for '" + name + "'"); return name;
34 },
36 __put__: function(name, value) {
37 print("setter called for '" + name + "' with " + value);
38 },
40 __call__: function(name, arg1, arg2) {
41 print("method '" + name + "' called with " + arg1 + ", " + arg2);
42 },
44 __new__: function(arg1, arg2) {
45 print("new with " + arg1 + ", " + arg2);
46 },
48 __getIds__: function() {
49 print("__getIds__ called");
50 return [ "foo", "bar" ];
51 },
53 __getValues__: function() {
54 print("__getValues__ called");
55 return [ "fooval", "barval" ];
56 },
58 __has__: function(name) {
59 print("__has__ called with '" + name + "'");
60 return name == "js";
61 },
63 __delete__: function(name) {
64 print("__delete__ called with '" + name + "'");
65 return true;
66 }
67 };
69 // calls __get__
70 print(obj.foo);
72 // calls __put__
73 obj.foo = 33;
75 // calls __call__
76 obj.func("hello", "world");
78 // calls __new__
79 new obj("hey!", "it works!");
81 for (i in obj) {
82 print(i);
83 }
85 for each (i in obj) {
86 print(i);
87 }
89 var x = "foo" in obj;
90 print(x);
92 var y = "js" in obj;
93 print(y);
95 print(delete obj.prop);
97 print(obj["js"]);
98 obj["js"] = "javascript";
99 print(obj["javascript"]);