author | lagergren |
Fri, 26 Sep 2014 18:47:20 +0200 | |
changeset 26886 | 18c744ab4df2 |
parent 26768 | 751b0f427090 |
child 27525 | e7d3c00b9fb8 |
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. |
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. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package jdk.nashorn.internal.runtime.arrays; |
|
27 |
||
24719 | 28 |
import jdk.nashorn.internal.codegen.types.Type; |
16147 | 29 |
import jdk.nashorn.internal.runtime.ScriptRuntime; |
30 |
import jdk.nashorn.internal.runtime.Undefined; |
|
31 |
import jdk.nashorn.internal.runtime.linker.Bootstrap; |
|
32 |
||
33 |
/** |
|
34 |
* Base class for array filters. Implements all core routines so that the |
|
35 |
* filter only has to implement those needed. |
|
36 |
*/ |
|
37 |
abstract class ArrayFilter extends ArrayData { |
|
38 |
/** Underlying array. */ |
|
39 |
protected ArrayData underlying; |
|
40 |
||
41 |
ArrayFilter(final ArrayData underlying) { |
|
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
42 |
super(underlying.length); |
16147 | 43 |
this.underlying = underlying; |
44 |
} |
|
45 |
||
46 |
/** |
|
47 |
* Get the underlying {@link ArrayData} that this filter wraps |
|
48 |
* @return array data |
|
49 |
*/ |
|
50 |
protected ArrayData getUnderlying() { |
|
51 |
return underlying; |
|
52 |
} |
|
53 |
||
54 |
@Override |
|
55 |
public void setLength(final long length) { |
|
56 |
super.setLength(length); |
|
57 |
underlying.setLength(length); |
|
58 |
} |
|
59 |
||
60 |
@Override |
|
61 |
public Object[] asObjectArray() { |
|
62 |
return underlying.asObjectArray(); |
|
63 |
} |
|
64 |
||
65 |
@Override |
|
66 |
public Object asArrayOfType(final Class<?> componentType) { |
|
67 |
return underlying.asArrayOfType(componentType); |
|
68 |
} |
|
69 |
||
70 |
@Override |
|
71 |
public void shiftLeft(final int by) { |
|
72 |
underlying.shiftLeft(by); |
|
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
73 |
setLength(underlying.length); |
16147 | 74 |
} |
75 |
||
76 |
@Override |
|
77 |
public ArrayData shiftRight(final int by) { |
|
78 |
underlying = underlying.shiftRight(by); |
|
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
79 |
setLength(underlying.length); |
16147 | 80 |
|
81 |
return this; |
|
82 |
} |
|
83 |
||
84 |
@Override |
|
85 |
public ArrayData ensure(final long safeIndex) { |
|
86 |
underlying = underlying.ensure(safeIndex); |
|
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
87 |
setLength(underlying.length); |
16147 | 88 |
|
89 |
return this; |
|
90 |
} |
|
91 |
||
92 |
@Override |
|
93 |
public ArrayData shrink(final long newLength) { |
|
94 |
underlying = underlying.shrink(newLength); |
|
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
95 |
setLength(underlying.length); |
16147 | 96 |
|
97 |
return this; |
|
98 |
} |
|
99 |
||
100 |
@Override |
|
101 |
public ArrayData set(final int index, final Object value, final boolean strict) { |
|
102 |
underlying = underlying.set(index, value, strict); |
|
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
103 |
setLength(underlying.length); |
16147 | 104 |
|
105 |
return this; |
|
106 |
} |
|
107 |
||
108 |
@Override |
|
109 |
public ArrayData set(final int index, final int value, final boolean strict) { |
|
110 |
underlying = underlying.set(index, value, strict); |
|
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
111 |
setLength(underlying.length); |
16147 | 112 |
|
113 |
return this; |
|
114 |
} |
|
115 |
||
116 |
@Override |
|
117 |
public ArrayData set(final int index, final long value, final boolean strict) { |
|
118 |
underlying = underlying.set(index, value, strict); |
|
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
119 |
setLength(underlying.length); |
16147 | 120 |
|
121 |
return this; |
|
122 |
} |
|
123 |
||
124 |
@Override |
|
125 |
public ArrayData set(final int index, final double value, final boolean strict) { |
|
126 |
underlying = underlying.set(index, value, strict); |
|
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
127 |
setLength(underlying.length); |
16147 | 128 |
|
129 |
return this; |
|
130 |
} |
|
131 |
||
132 |
@Override |
|
18606 | 133 |
public ArrayData setEmpty(final int index) { |
134 |
underlying.setEmpty(index); |
|
135 |
return this; |
|
136 |
} |
|
137 |
||
138 |
@Override |
|
139 |
public ArrayData setEmpty(final long lo, final long hi) { |
|
140 |
underlying.setEmpty(lo, hi); |
|
141 |
return this; |
|
142 |
} |
|
143 |
||
144 |
@Override |
|
24719 | 145 |
public Type getOptimisticType() { |
146 |
return underlying.getOptimisticType(); |
|
147 |
} |
|
148 |
||
149 |
@Override |
|
16147 | 150 |
public int getInt(final int index) { |
151 |
return underlying.getInt(index); |
|
152 |
} |
|
153 |
||
154 |
@Override |
|
24719 | 155 |
public int getIntOptimistic(final int index, final int programPoint) { |
156 |
return underlying.getIntOptimistic(index, programPoint); |
|
157 |
} |
|
158 |
||
159 |
@Override |
|
16147 | 160 |
public long getLong(final int index) { |
161 |
return underlying.getLong(index); |
|
162 |
} |
|
163 |
||
164 |
@Override |
|
24719 | 165 |
public long getLongOptimistic(final int index, final int programPoint) { |
166 |
return underlying.getLongOptimistic(index, programPoint); |
|
167 |
} |
|
168 |
||
169 |
@Override |
|
16147 | 170 |
public double getDouble(final int index) { |
171 |
return underlying.getDouble(index); |
|
172 |
} |
|
173 |
||
174 |
@Override |
|
24719 | 175 |
public double getDoubleOptimistic(final int index, final int programPoint) { |
176 |
return underlying.getDoubleOptimistic(index, programPoint); |
|
177 |
} |
|
178 |
||
179 |
@Override |
|
16147 | 180 |
public Object getObject(final int index) { |
181 |
return underlying.getObject(index); |
|
182 |
} |
|
183 |
||
184 |
@Override |
|
185 |
public boolean has(final int index) { |
|
186 |
return underlying.has(index); |
|
187 |
} |
|
188 |
||
189 |
@Override |
|
190 |
public ArrayData delete(final int index) { |
|
191 |
underlying = underlying.delete(index); |
|
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
192 |
setLength(underlying.length); |
16147 | 193 |
return this; |
194 |
} |
|
195 |
||
196 |
@Override |
|
197 |
public ArrayData delete(final long from, final long to) { |
|
198 |
underlying = underlying.delete(from, to); |
|
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
199 |
setLength(underlying.length); |
16147 | 200 |
return this; |
201 |
} |
|
202 |
||
203 |
@Override |
|
26768
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
25865
diff
changeset
|
204 |
public ArrayData convert(final Class<?> type) { |
16147 | 205 |
underlying = underlying.convert(type); |
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
206 |
setLength(underlying.length); |
16147 | 207 |
return this; |
208 |
} |
|
209 |
||
210 |
@Override |
|
211 |
public Object pop() { |
|
212 |
final Object value = underlying.pop(); |
|
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
213 |
setLength(underlying.length); |
16147 | 214 |
|
215 |
return value; |
|
216 |
} |
|
217 |
||
218 |
@Override |
|
219 |
public long nextIndex(final long index) { |
|
220 |
return underlying.nextIndex(index); |
|
221 |
} |
|
222 |
||
223 |
static Object convertUndefinedValue(final Class<?> targetType) { |
|
224 |
return invoke(Bootstrap.getLinkerServices().getTypeConverter(Undefined.class, targetType), |
|
225 |
ScriptRuntime.UNDEFINED); |
|
226 |
} |
|
227 |
} |