author | hannesw |
Wed, 25 Jun 2014 14:36:24 +0200 | |
changeset 25243 | 7a1edca6ce94 |
parent 16246 | f60e04200be3 |
permissions | -rw-r--r-- |
16246
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
1 |
/* |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
2 |
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
4 |
* |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
8 |
* |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
13 |
* accompanied this code). |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
14 |
* |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
18 |
* |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
21 |
* questions. |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
22 |
*/ |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
23 |
|
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
24 |
/** |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
25 |
* JSObject tests |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
26 |
* |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
27 |
* @test |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
28 |
* @run |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
29 |
*/ |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
30 |
|
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
31 |
var m = new javax.script.ScriptEngineManager(); |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
32 |
var e = m.getEngineByName("nashorn"); |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
33 |
|
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
34 |
e.eval("obj = { foo:'hello', 0: 'world', func: function(x) { return x.toUpperCase() } } "); |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
35 |
var obj = e.get("obj"); |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
36 |
|
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
37 |
|
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
38 |
// try various getters |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
39 |
if (obj.foo != 'hello') { |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
40 |
fail("obj.foo does have expected value"); |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
41 |
} |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
42 |
|
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
43 |
function checkPropGetter(obj, prop, expected) { |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
44 |
if (obj[prop] != expected) { |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
45 |
fail(prop + " does not have value: " + expected); |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
46 |
} |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
47 |
} |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
48 |
|
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
49 |
checkPropGetter(obj, "foo", "hello"); |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
50 |
checkPropGetter(obj, 0, "world"); |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
51 |
checkPropGetter(obj, "0", "world"); |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
52 |
|
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
53 |
// try various setters |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
54 |
|
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
55 |
obj.foo = "HELLO"; |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
56 |
if (obj.foo != "HELLO") { |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
57 |
fail("obj.foo set does not work as expected"); |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
58 |
} |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
59 |
|
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
60 |
function checkPropSetter(obj, prop, newValue) { |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
61 |
obj[prop] = newValue; |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
62 |
checkPropGetter(obj, prop, newValue); |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
63 |
} |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
64 |
|
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
65 |
checkPropSetter(obj, "foo", "NASHORN"); |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
66 |
checkPropSetter(obj, 0, "ECMASCRIPT"); |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
67 |
checkPropSetter(obj, "0", "CHANGED"); |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
68 |
|
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
69 |
function callFunc(input, expected) { |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
70 |
if (obj.func(input) != expected) { |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
71 |
fail("obj.func(..) does not work as expected"); |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
72 |
} |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
73 |
} |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
74 |
|
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
75 |
callFunc("nashorn", "NASHORN"); |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
76 |
callFunc("javascript", "JAVASCRIPT"); |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
77 |
callFunc("hello", "HELLO"); |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
78 |
|
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
79 |
var Func = obj.func; |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
80 |
|
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
81 |
function callWithoutObject(input, expected) { |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
82 |
if (Func(input) != expected) { |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
83 |
fail("obj.func(..) does not work as expected"); |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
84 |
} |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
85 |
} |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
86 |
|
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
87 |
callWithoutObject("nashorn", "NASHORN"); |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
88 |
callWithoutObject("javascript", "JAVASCRIPT"); |
f60e04200be3
8008387: Improve code coverage tests for JSObjectLinker and NashornBottomLinker
sundar
parents:
diff
changeset
|
89 |
callWithoutObject("hello", "HELLO"); |