Wed, 03 Jul 2013 13:03:36 +0200
8019585: Sometimes a var declaration using itself in its init wasn't declared as canBeUndefined, causing erroneous bytecode
Reviewed-by: sundar, attila
jlaskey@3 | 1 | /* |
jlaskey@7 | 2 | * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
jlaskey@3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jlaskey@3 | 4 | * |
jlaskey@3 | 5 | * This code is free software; you can redistribute it and/or modify it |
jlaskey@3 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jlaskey@3 | 7 | * published by the Free Software Foundation. Oracle designates this |
jlaskey@3 | 8 | * particular file as subject to the "Classpath" exception as provided |
jlaskey@3 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
jlaskey@3 | 10 | * |
jlaskey@3 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jlaskey@3 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jlaskey@3 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jlaskey@3 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
jlaskey@3 | 15 | * accompanied this code). |
jlaskey@3 | 16 | * |
jlaskey@3 | 17 | * You should have received a copy of the GNU General Public License version |
jlaskey@3 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
jlaskey@3 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jlaskey@3 | 20 | * |
jlaskey@3 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
jlaskey@3 | 22 | * or visit www.oracle.com if you need additional information or have any |
jlaskey@3 | 23 | * questions. |
jlaskey@3 | 24 | */ |
jlaskey@3 | 25 | |
jlaskey@3 | 26 | package jdk.nashorn.internal.objects; |
jlaskey@3 | 27 | |
jlaskey@3 | 28 | import jdk.nashorn.internal.objects.annotations.Attribute; |
jlaskey@3 | 29 | import jdk.nashorn.internal.objects.annotations.Constructor; |
jlaskey@3 | 30 | import jdk.nashorn.internal.objects.annotations.Function; |
sundar@284 | 31 | import jdk.nashorn.internal.objects.annotations.Property; |
jlaskey@3 | 32 | import jdk.nashorn.internal.objects.annotations.ScriptClass; |
sundar@284 | 33 | import jdk.nashorn.internal.objects.annotations.Where; |
hannesw@380 | 34 | import jdk.nashorn.internal.runtime.PropertyMap; |
jlaskey@3 | 35 | import jdk.nashorn.internal.runtime.ScriptObject; |
jlaskey@3 | 36 | import jdk.nashorn.internal.runtime.arrays.ArrayData; |
jlaskey@3 | 37 | |
jlaskey@3 | 38 | /** |
jlaskey@3 | 39 | * Uint16 array for TypedArray extension |
jlaskey@3 | 40 | */ |
jlaskey@3 | 41 | @ScriptClass("Uint16Array") |
sundar@82 | 42 | public final class NativeUint16Array extends ArrayBufferView { |
sundar@292 | 43 | /** |
sundar@292 | 44 | * The size in bytes of each element in the array. |
sundar@292 | 45 | */ |
sundar@284 | 46 | @Property(attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_WRITABLE | Attribute.NOT_CONFIGURABLE, where = Where.CONSTRUCTOR) |
sundar@284 | 47 | public static final int BYTES_PER_ELEMENT = 2; |
sundar@284 | 48 | |
hannesw@380 | 49 | // initialized by nasgen |
lagergren@405 | 50 | @SuppressWarnings("unused") |
hannesw@380 | 51 | private static PropertyMap $nasgenmap$; |
hannesw@380 | 52 | |
jlaskey@3 | 53 | private static final Factory FACTORY = new Factory(BYTES_PER_ELEMENT) { |
jlaskey@3 | 54 | @Override |
jlaskey@3 | 55 | public ArrayBufferView construct(final NativeArrayBuffer buffer, final int byteOffset, final int length) { |
jlaskey@3 | 56 | return new NativeUint16Array(buffer, byteOffset, length); |
jlaskey@3 | 57 | } |
jlaskey@3 | 58 | @Override |
jlaskey@3 | 59 | public ArrayData createArrayData(final NativeArrayBuffer buffer, final int byteOffset, final int length) { |
jlaskey@3 | 60 | return new Uint16ArrayData(buffer, byteOffset, length); |
jlaskey@3 | 61 | } |
jlaskey@3 | 62 | }; |
jlaskey@3 | 63 | |
jlaskey@3 | 64 | private static final class Uint16ArrayData extends ArrayDataImpl { |
jlaskey@3 | 65 | private Uint16ArrayData(final NativeArrayBuffer buffer, final int byteOffset, final int elementLength) { |
jlaskey@3 | 66 | super(buffer, byteOffset, elementLength); |
jlaskey@3 | 67 | } |
jlaskey@3 | 68 | |
jlaskey@3 | 69 | @Override |
jlaskey@3 | 70 | protected int byteIndex(final int index) { |
jlaskey@3 | 71 | return index * BYTES_PER_ELEMENT + byteOffset; |
jlaskey@3 | 72 | } |
jlaskey@3 | 73 | |
jlaskey@3 | 74 | @Override |
jlaskey@3 | 75 | protected int getIntImpl(final int index) { |
jlaskey@3 | 76 | final int byteIndex = byteIndex(index); |
jlaskey@3 | 77 | final byte[] byteArray = buffer.getByteArray(); |
jlaskey@3 | 78 | return byteArray[byteIndex ] & 0x0000_00ff | |
jlaskey@3 | 79 | byteArray[byteIndex+1] << 8 & 0x0000_ff00 ; |
jlaskey@3 | 80 | } |
jlaskey@3 | 81 | |
jlaskey@3 | 82 | @Override |
jlaskey@3 | 83 | protected void setImpl(final int index, final int value) { |
jlaskey@3 | 84 | final int byteIndex = byteIndex(index); |
jlaskey@3 | 85 | @SuppressWarnings("MismatchedReadAndWriteOfArray") |
jlaskey@3 | 86 | final byte[] byteArray = buffer.getByteArray(); |
jlaskey@3 | 87 | byteArray[byteIndex ] = (byte)(value & 0xff); |
jlaskey@3 | 88 | byteArray[byteIndex+1] = (byte)(value >>> 8 & 0xff); |
jlaskey@3 | 89 | } |
jlaskey@3 | 90 | } |
jlaskey@3 | 91 | |
jlaskey@3 | 92 | /** |
jlaskey@3 | 93 | * Constructor |
jlaskey@3 | 94 | * |
jlaskey@3 | 95 | * @param newObj is this typed array instantiated with the new operator |
jlaskey@3 | 96 | * @param self self reference |
jlaskey@3 | 97 | * @param args args |
jlaskey@3 | 98 | * |
jlaskey@3 | 99 | * @return new typed array |
jlaskey@3 | 100 | */ |
jlaskey@3 | 101 | @Constructor(arity = 1) |
jlaskey@3 | 102 | public static Object constructor(final boolean newObj, final Object self, final Object... args) { |
jlaskey@3 | 103 | return constructorImpl(args, FACTORY); |
jlaskey@3 | 104 | } |
jlaskey@3 | 105 | |
jlaskey@3 | 106 | NativeUint16Array(final NativeArrayBuffer buffer, final int byteOffset, final int length) { |
jlaskey@3 | 107 | super(buffer, byteOffset, length); |
jlaskey@3 | 108 | } |
jlaskey@3 | 109 | |
jlaskey@3 | 110 | @Override |
jlaskey@3 | 111 | protected Factory factory() { |
jlaskey@3 | 112 | return FACTORY; |
jlaskey@3 | 113 | } |
jlaskey@3 | 114 | |
jlaskey@3 | 115 | /** |
jlaskey@3 | 116 | * Set values |
jlaskey@3 | 117 | * @param self self reference |
jlaskey@3 | 118 | * @param array multiple values of array's type to set |
jlaskey@3 | 119 | * @param offset optional start index, interpreted 0 if undefined |
jlaskey@3 | 120 | * @return undefined |
jlaskey@3 | 121 | */ |
jlaskey@3 | 122 | @Function(attributes = Attribute.NOT_ENUMERABLE) |
jlaskey@3 | 123 | protected static Object set(final Object self, final Object array, final Object offset) { |
jlaskey@3 | 124 | return ArrayBufferView.setImpl(self, array, offset); |
jlaskey@3 | 125 | } |
jlaskey@3 | 126 | |
jlaskey@3 | 127 | /** |
jlaskey@3 | 128 | * Returns a new TypedArray view of the ArrayBuffer store for this TypedArray, |
jlaskey@3 | 129 | * referencing the elements at begin, inclusive, up to end, exclusive. If either |
jlaskey@3 | 130 | * begin or end is negative, it refers to an index from the end of the array, |
jlaskey@3 | 131 | * as opposed to from the beginning. |
jlaskey@3 | 132 | * <p> |
jlaskey@3 | 133 | * If end is unspecified, the subarray contains all elements from begin to the end |
jlaskey@3 | 134 | * of the TypedArray. The range specified by the begin and end values is clamped to |
jlaskey@3 | 135 | * the valid index range for the current array. If the computed length of the new |
jlaskey@3 | 136 | * TypedArray would be negative, it is clamped to zero. |
jlaskey@3 | 137 | * <p> |
jlaskey@3 | 138 | * The returned TypedArray will be of the same type as the array on which this |
jlaskey@3 | 139 | * method is invoked. |
jlaskey@3 | 140 | * |
jlaskey@3 | 141 | * @param self self reference |
jlaskey@3 | 142 | * @param begin begin position |
jlaskey@3 | 143 | * @param end end position |
jlaskey@3 | 144 | * |
jlaskey@3 | 145 | * @return sub array |
jlaskey@3 | 146 | */ |
jlaskey@3 | 147 | @Function(attributes = Attribute.NOT_ENUMERABLE) |
jlaskey@3 | 148 | protected static Object subarray(final Object self, final Object begin, final Object end) { |
jlaskey@3 | 149 | return ArrayBufferView.subarrayImpl(self, begin, end); |
jlaskey@3 | 150 | } |
jlaskey@3 | 151 | |
jlaskey@3 | 152 | @Override |
jlaskey@3 | 153 | protected ScriptObject getPrototype() { |
jlaskey@3 | 154 | return Global.instance().getUint16ArrayPrototype(); |
jlaskey@3 | 155 | } |
jlaskey@3 | 156 | } |