author | hannesw |
Fri, 03 Feb 2017 13:28:00 +0100 | |
changeset 43555 | 1bb10bccf057 |
parent 33686 | 1391474a6405 |
permissions | -rw-r--r-- |
24777
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
1 |
/* |
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
2 |
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
26067
b32ccc3a76c9
8055199: Tidy up Nashorn codebase for code standards (August 2014)
attila
parents:
24777
diff
changeset
|
4 |
* |
24777
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
26067
b32ccc3a76c9
8055199: Tidy up Nashorn codebase for code standards (August 2014)
attila
parents:
24777
diff
changeset
|
8 |
* |
24777
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
13 |
* accompanied this code). |
26067
b32ccc3a76c9
8055199: Tidy up Nashorn codebase for code standards (August 2014)
attila
parents:
24777
diff
changeset
|
14 |
* |
24777
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
26067
b32ccc3a76c9
8055199: Tidy up Nashorn codebase for code standards (August 2014)
attila
parents:
24777
diff
changeset
|
18 |
* |
24777
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
21 |
* questions. |
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
22 |
*/ |
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
23 |
|
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
24 |
/** |
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
25 |
* JDK-8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook |
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
26 |
* |
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
27 |
* @test |
33686
1391474a6405
8141550: Introduce a command line option instead of nashorn.unstable.relink.threshold system property
attila
parents:
32698
diff
changeset
|
28 |
* @option --unstable-relink-threshold=16 |
24777
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
29 |
* @run |
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
30 |
*/ |
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
31 |
|
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
32 |
__noSuchProperty__ = function(name) { |
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
33 |
return 1; |
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
34 |
} |
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
35 |
|
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
36 |
function func(obj) { |
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
37 |
with(obj) { |
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
38 |
// this "foo" getter site becomes megamorphic |
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
39 |
// due to different 'with' scope objects. |
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
40 |
foo; |
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
41 |
} |
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
42 |
} |
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
43 |
|
32698
927e0fd20492
8136694: Megemorphic scope access does not throw ReferenceError when property is missing
sundar
parents:
26067
diff
changeset
|
44 |
var LIMIT = 20; // should be more than megamorphic threshold set via @option |
927e0fd20492
8136694: Megemorphic scope access does not throw ReferenceError when property is missing
sundar
parents:
26067
diff
changeset
|
45 |
|
927e0fd20492
8136694: Megemorphic scope access does not throw ReferenceError when property is missing
sundar
parents:
26067
diff
changeset
|
46 |
for (var i = 0; i < LIMIT; i++) { |
24777
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
47 |
var obj = {}; |
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
48 |
obj.foo = i; |
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
49 |
obj[i] = i; |
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
50 |
func(obj); |
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
51 |
} |
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
52 |
|
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
53 |
// pass a 'with' scope object that does not have 'foo'. |
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
54 |
// callsite inside func should see __noSuchProperty__ |
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
55 |
// hook on global scope object. |
ed1974940ff4
8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
sundar
parents:
diff
changeset
|
56 |
func({}); |
32698
927e0fd20492
8136694: Megemorphic scope access does not throw ReferenceError when property is missing
sundar
parents:
26067
diff
changeset
|
57 |
|
927e0fd20492
8136694: Megemorphic scope access does not throw ReferenceError when property is missing
sundar
parents:
26067
diff
changeset
|
58 |
function checkFoo() { |
927e0fd20492
8136694: Megemorphic scope access does not throw ReferenceError when property is missing
sundar
parents:
26067
diff
changeset
|
59 |
with({}) { |
927e0fd20492
8136694: Megemorphic scope access does not throw ReferenceError when property is missing
sundar
parents:
26067
diff
changeset
|
60 |
try { |
927e0fd20492
8136694: Megemorphic scope access does not throw ReferenceError when property is missing
sundar
parents:
26067
diff
changeset
|
61 |
foo; |
927e0fd20492
8136694: Megemorphic scope access does not throw ReferenceError when property is missing
sundar
parents:
26067
diff
changeset
|
62 |
return true; |
927e0fd20492
8136694: Megemorphic scope access does not throw ReferenceError when property is missing
sundar
parents:
26067
diff
changeset
|
63 |
} catch (e) { |
927e0fd20492
8136694: Megemorphic scope access does not throw ReferenceError when property is missing
sundar
parents:
26067
diff
changeset
|
64 |
return false; |
927e0fd20492
8136694: Megemorphic scope access does not throw ReferenceError when property is missing
sundar
parents:
26067
diff
changeset
|
65 |
} |
927e0fd20492
8136694: Megemorphic scope access does not throw ReferenceError when property is missing
sundar
parents:
26067
diff
changeset
|
66 |
} |
927e0fd20492
8136694: Megemorphic scope access does not throw ReferenceError when property is missing
sundar
parents:
26067
diff
changeset
|
67 |
} |
927e0fd20492
8136694: Megemorphic scope access does not throw ReferenceError when property is missing
sundar
parents:
26067
diff
changeset
|
68 |
|
927e0fd20492
8136694: Megemorphic scope access does not throw ReferenceError when property is missing
sundar
parents:
26067
diff
changeset
|
69 |
var oldNoSuchProperty = this.__noSuchProperty__; |
927e0fd20492
8136694: Megemorphic scope access does not throw ReferenceError when property is missing
sundar
parents:
26067
diff
changeset
|
70 |
delete this.__noSuchProperty__; |
927e0fd20492
8136694: Megemorphic scope access does not throw ReferenceError when property is missing
sundar
parents:
26067
diff
changeset
|
71 |
|
927e0fd20492
8136694: Megemorphic scope access does not throw ReferenceError when property is missing
sundar
parents:
26067
diff
changeset
|
72 |
// keep deleting/restorting __noSuchProperty__ alternatively |
927e0fd20492
8136694: Megemorphic scope access does not throw ReferenceError when property is missing
sundar
parents:
26067
diff
changeset
|
73 |
// to make "foo" access in checkFoo function megamorphic! |
927e0fd20492
8136694: Megemorphic scope access does not throw ReferenceError when property is missing
sundar
parents:
26067
diff
changeset
|
74 |
|
927e0fd20492
8136694: Megemorphic scope access does not throw ReferenceError when property is missing
sundar
parents:
26067
diff
changeset
|
75 |
for (var i = 0; i < LIMIT; i++) { |
927e0fd20492
8136694: Megemorphic scope access does not throw ReferenceError when property is missing
sundar
parents:
26067
diff
changeset
|
76 |
// no __noSuchProperty__ and 'with' scope object has no 'foo' |
927e0fd20492
8136694: Megemorphic scope access does not throw ReferenceError when property is missing
sundar
parents:
26067
diff
changeset
|
77 |
delete __noSuchProperty__; |
927e0fd20492
8136694: Megemorphic scope access does not throw ReferenceError when property is missing
sundar
parents:
26067
diff
changeset
|
78 |
Assert.assertFalse(checkFoo(), "Expected false in iteration " + i); |
927e0fd20492
8136694: Megemorphic scope access does not throw ReferenceError when property is missing
sundar
parents:
26067
diff
changeset
|
79 |
|
927e0fd20492
8136694: Megemorphic scope access does not throw ReferenceError when property is missing
sundar
parents:
26067
diff
changeset
|
80 |
// __noSuchProperty__ is exists but 'with' scope object has no 'foo' |
927e0fd20492
8136694: Megemorphic scope access does not throw ReferenceError when property is missing
sundar
parents:
26067
diff
changeset
|
81 |
this.__noSuchProperty__ = oldNoSuchProperty; |
927e0fd20492
8136694: Megemorphic scope access does not throw ReferenceError when property is missing
sundar
parents:
26067
diff
changeset
|
82 |
Assert.assertTrue(checkFoo(), "Expected true in iteration " + i); |
927e0fd20492
8136694: Megemorphic scope access does not throw ReferenceError when property is missing
sundar
parents:
26067
diff
changeset
|
83 |
} |