author | martin |
Wed, 10 Dec 2014 09:23:00 -0800 | |
changeset 28057 | 1a47ceecdba5 |
parent 24778 | 2ff5d7041566 |
child 32939 | 9887198000ec |
permissions | -rw-r--r-- |
16147 | 1 |
/* |
16151 | 2 |
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
16147 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
4 |
* |
16147 | 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. |
|
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
8 |
* |
16147 | 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). |
|
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
14 |
* |
16147 | 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. |
|
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
18 |
* |
16147 | 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 |
*/ |
|
23 |
||
24 |
/** |
|
25 |
* Verify that JSAdapter works as expected. |
|
26 |
* |
|
27 |
* @test |
|
28 |
* @run |
|
29 |
*/ |
|
30 |
||
31 |
var obj = new JSAdapter() { |
|
32 |
__get__: function(name) { |
|
33 |
print("getter called for '" + name + "'"); return name; |
|
34 |
}, |
|
35 |
||
36 |
__put__: function(name, value) { |
|
37 |
print("setter called for '" + name + "' with " + value); |
|
38 |
}, |
|
39 |
||
40 |
__call__: function(name, arg1, arg2) { |
|
41 |
print("method '" + name + "' called with " + arg1 + ", " + arg2); |
|
42 |
}, |
|
43 |
||
44 |
__new__: function(arg1, arg2) { |
|
45 |
print("new with " + arg1 + ", " + arg2); |
|
46 |
}, |
|
47 |
||
48 |
__getIds__: function() { |
|
49 |
print("__getIds__ called"); |
|
50 |
return [ "foo", "bar" ]; |
|
51 |
}, |
|
52 |
||
53 |
__getValues__: function() { |
|
54 |
print("__getValues__ called"); |
|
55 |
return [ "fooval", "barval" ]; |
|
56 |
}, |
|
57 |
||
58 |
__has__: function(name) { |
|
59 |
print("__has__ called with '" + name + "'"); |
|
60 |
return name == "js"; |
|
61 |
}, |
|
62 |
||
63 |
__delete__: function(name) { |
|
64 |
print("__delete__ called with '" + name + "'"); |
|
65 |
return true; |
|
66 |
} |
|
67 |
}; |
|
68 |
||
69 |
// calls __get__ |
|
70 |
print(obj.foo); |
|
71 |
||
72 |
// calls __put__ |
|
73 |
obj.foo = 33; |
|
74 |
||
75 |
// calls __call__ |
|
76 |
obj.func("hello", "world"); |
|
77 |
||
78 |
// calls __new__ |
|
79 |
new obj("hey!", "it works!"); |
|
80 |
||
81 |
for (i in obj) { |
|
82 |
print(i); |
|
83 |
} |
|
84 |
||
85 |
for each (i in obj) { |
|
86 |
print(i); |
|
87 |
} |
|
88 |
||
89 |
var x = "foo" in obj; |
|
90 |
print(x); |
|
91 |
||
92 |
var y = "js" in obj; |
|
93 |
print(y); |
|
94 |
||
95 |
print(delete obj.prop); |
|
96 |
||
97 |
print(obj["js"]); |
|
98 |
obj["js"] = "javascript"; |
|
99 |
print(obj["javascript"]); |