From: <rb...@us...> - 2018-08-23 07:21:24
|
Revision: 15537 http://sourceforge.net/p/htmlunit/code/15537 Author: rbri Date: 2018-08-23 07:21:10 +0000 (Thu, 23 Aug 2018) Log Message: ----------- switch to rhino for the typed arrays Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfiguration.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/TextDecoder.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/TextEncoder.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/WebSocket.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/canvas/ImageData.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/crypto/Crypto.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileReader.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfigurationTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/TextEncoderTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/crypto/CryptoTest.java Removed Paths: ------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/ArrayBuffer.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/ArrayBufferView.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/ArrayBufferViewBase.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/DataView.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Float32Array.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Float64Array.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Int16Array.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Int32Array.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Int8Array.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Uint16Array.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Uint32Array.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Uint8Array.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Uint8ClampedArray.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/ArrayBuffer2Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2018-08-21 05:38:42 UTC (rev 15536) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2018-08-23 07:21:10 UTC (rev 15537) @@ -1363,10 +1363,6 @@ @BrowserFeature(IE) JS_TREEWALKER_FILTER_FUNCTION_ONLY, - /** Types arrays can be constructed with {@code null}. */ - @BrowserFeature({CHROME, FF60}) - JS_TYPED_ARRAYS_NULL, - /** Setting the property align to arbitrary values is allowed. */ @BrowserFeature({CHROME, FF}) JS_TYPE_ACCEPTS_ARBITRARY_VALUES, Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfiguration.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfiguration.java 2018-08-21 05:38:42 UTC (rev 15536) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfiguration.java 2018-08-23 07:21:10 UTC (rev 15537) @@ -81,19 +81,6 @@ import com.gargoylesoftware.htmlunit.javascript.host.Window; import com.gargoylesoftware.htmlunit.javascript.host.XPathExpression; import com.gargoylesoftware.htmlunit.javascript.host.webkitURL; -import com.gargoylesoftware.htmlunit.javascript.host.arrays.ArrayBuffer; -import com.gargoylesoftware.htmlunit.javascript.host.arrays.ArrayBufferView; -import com.gargoylesoftware.htmlunit.javascript.host.arrays.ArrayBufferViewBase; -import com.gargoylesoftware.htmlunit.javascript.host.arrays.DataView; -import com.gargoylesoftware.htmlunit.javascript.host.arrays.Float32Array; -import com.gargoylesoftware.htmlunit.javascript.host.arrays.Float64Array; -import com.gargoylesoftware.htmlunit.javascript.host.arrays.Int16Array; -import com.gargoylesoftware.htmlunit.javascript.host.arrays.Int32Array; -import com.gargoylesoftware.htmlunit.javascript.host.arrays.Int8Array; -import com.gargoylesoftware.htmlunit.javascript.host.arrays.Uint16Array; -import com.gargoylesoftware.htmlunit.javascript.host.arrays.Uint32Array; -import com.gargoylesoftware.htmlunit.javascript.host.arrays.Uint8Array; -import com.gargoylesoftware.htmlunit.javascript.host.arrays.Uint8ClampedArray; import com.gargoylesoftware.htmlunit.javascript.host.budget.BudgetService; import com.gargoylesoftware.htmlunit.javascript.host.canvas.CanvasCaptureMediaStream; import com.gargoylesoftware.htmlunit.javascript.host.canvas.CanvasCaptureMediaStreamTrack; @@ -614,14 +601,7 @@ WebSocket.class, WheelEvent.class, Window.class, Worker.class, XMLDocument.class, XMLHttpRequest.class, XMLHttpRequestEventTarget.class, XMLHttpRequestUpload.class, XMLSerializer.class, XPathEvaluator.class, XPathExpression.class, - XPathNSResolver.class, XPathResult.class, XSLTProcessor.class, - - // we will use the Rhino stuff as soon as possible - ArrayBuffer.class, ArrayBufferView.class, ArrayBufferViewBase.class, - DataView.class, - Float32Array.class, Float64Array.class, - Int16Array.class, Int32Array.class, Int8Array.class, - Uint16Array.class, Uint32Array.class, Uint8Array.class, Uint8ClampedArray.class + XPathNSResolver.class, XPathResult.class, XSLTProcessor.class }; /** Cache of browser versions and their corresponding JavaScript configurations. */ Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/TextDecoder.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/TextDecoder.java 2018-08-21 05:38:42 UTC (rev 15536) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/TextDecoder.java 2018-08-23 07:21:10 UTC (rev 15537) @@ -26,12 +26,12 @@ import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter; -import com.gargoylesoftware.htmlunit.javascript.host.arrays.ArrayBuffer; -import com.gargoylesoftware.htmlunit.javascript.host.arrays.ArrayBufferView; import net.sourceforge.htmlunit.corejs.javascript.Context; import net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime; import net.sourceforge.htmlunit.corejs.javascript.Undefined; +import net.sourceforge.htmlunit.corejs.javascript.typedarrays.NativeArrayBuffer; +import net.sourceforge.htmlunit.corejs.javascript.typedarrays.NativeArrayBufferView; /** * A JavaScript object for {@code TextDecoder}. @@ -388,16 +388,16 @@ return ""; } - ArrayBuffer arrayBuffer = null; - if (buffer instanceof ArrayBuffer) { - arrayBuffer = (ArrayBuffer) buffer; + NativeArrayBuffer arrayBuffer = null; + if (buffer instanceof NativeArrayBuffer) { + arrayBuffer = (NativeArrayBuffer) buffer; } - else if (buffer instanceof ArrayBufferView) { - arrayBuffer = ((ArrayBufferView) buffer).getBuffer(); + else if (buffer instanceof NativeArrayBufferView) { + arrayBuffer = ((NativeArrayBufferView) buffer).getBuffer(); } if (arrayBuffer != null) { - return new String(arrayBuffer.getBytes(), Charset.forName(encoding_)); + return new String(arrayBuffer.getBuffer(), Charset.forName(encoding_)); } throw ScriptRuntime.typeError("Argument 1 of TextDecoder.decode could not be" Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/TextEncoder.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/TextEncoder.java 2018-08-21 05:38:42 UTC (rev 15536) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/TextEncoder.java 2018-08-23 07:21:10 UTC (rev 15537) @@ -24,10 +24,12 @@ import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter; -import com.gargoylesoftware.htmlunit.javascript.host.arrays.Uint8Array; import net.sourceforge.htmlunit.corejs.javascript.Context; +import net.sourceforge.htmlunit.corejs.javascript.ScriptableObject; import net.sourceforge.htmlunit.corejs.javascript.Undefined; +import net.sourceforge.htmlunit.corejs.javascript.typedarrays.NativeArrayBuffer; +import net.sourceforge.htmlunit.corejs.javascript.typedarrays.NativeUint8Array; /** * A JavaScript object for {@code TextEncoder}. @@ -58,9 +60,12 @@ * @return returns a Uint8Array containing the text given encoded . */ @JsxFunction - public Uint8Array encode(final Object toEncode) { + public NativeUint8Array encode(final Object toEncode) { if (Undefined.instance == toEncode) { - return new Uint8Array(new byte[0], getWindow()); + final NativeUint8Array result = new NativeUint8Array(0); + result.setParentScope(getParentScope()); + result.setPrototype(ScriptableObject.getClassPrototype(getWindow(this), result.getClassName())); + return result; } final String txt; @@ -72,6 +77,13 @@ } final byte[] bytes = txt.getBytes(StandardCharsets.UTF_8); - return new Uint8Array(bytes, getWindow()); + + final NativeArrayBuffer arrayBuffer = new NativeArrayBuffer(bytes.length); + System.arraycopy(bytes, 0, arrayBuffer.getBuffer(), 0, bytes.length); + + final NativeUint8Array result = new NativeUint8Array(arrayBuffer, 0, bytes.length); + result.setParentScope(getParentScope()); + result.setPrototype(ScriptableObject.getClassPrototype(getWindow(this), result.getClassName())); + return result; } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/WebSocket.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/WebSocket.java 2018-08-21 05:38:42 UTC (rev 15536) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/WebSocket.java 2018-08-23 07:21:10 UTC (rev 15537) @@ -17,7 +17,6 @@ import java.io.IOException; import java.net.URI; import java.nio.ByteBuffer; -import java.util.Arrays; import java.util.concurrent.Future; import org.apache.commons.lang3.ArrayUtils; @@ -41,7 +40,6 @@ import com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter; -import com.gargoylesoftware.htmlunit.javascript.host.arrays.ArrayBuffer; import com.gargoylesoftware.htmlunit.javascript.host.event.CloseEvent; import com.gargoylesoftware.htmlunit.javascript.host.event.Event; import com.gargoylesoftware.htmlunit.javascript.host.event.EventTarget; @@ -51,7 +49,9 @@ import net.sourceforge.htmlunit.corejs.javascript.Function; import net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime; import net.sourceforge.htmlunit.corejs.javascript.Scriptable; +import net.sourceforge.htmlunit.corejs.javascript.ScriptableObject; import net.sourceforge.htmlunit.corejs.javascript.Undefined; +import net.sourceforge.htmlunit.corejs.javascript.typedarrays.NativeArrayBuffer; /** * A JavaScript object for {@code WebSocket}. @@ -391,8 +391,8 @@ if (content instanceof String) { outgoingSession_.getRemote().sendString((String) content); } - else if (content instanceof ArrayBuffer) { - final byte[] bytes = ((ArrayBuffer) content).getBytes(); + else if (content instanceof NativeArrayBuffer) { + final byte[] bytes = ((NativeArrayBuffer) content).getBuffer(); final ByteBuffer buffer = ByteBuffer.wrap(bytes); outgoingSession_.getRemote().sendBytes(buffer); } @@ -460,9 +460,10 @@ } super.onWebSocketBinary(data, offset, length); - final ArrayBuffer buffer = new ArrayBuffer(Arrays.copyOfRange(data, offset, length)); + final NativeArrayBuffer buffer = new NativeArrayBuffer(length); + System.arraycopy(data, offset, buffer.getBuffer(), 0, length); buffer.setParentScope(getParentScope()); - buffer.setPrototype(getPrototype(buffer.getClass())); + buffer.setPrototype(ScriptableObject.getClassPrototype(getWindow(), buffer.getClassName())); final MessageEvent msgEvent = new MessageEvent(buffer); msgEvent.setOrigin(getUrl()); Deleted: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/ArrayBuffer.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/ArrayBuffer.java 2018-08-21 05:38:42 UTC (rev 15536) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/ArrayBuffer.java 2018-08-23 07:21:10 UTC (rev 15537) @@ -1,148 +0,0 @@ -/* - * Copyright (c) 2002-2018 Gargoyle Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.gargoylesoftware.htmlunit.javascript.host.arrays; - -import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter; - -import net.sourceforge.htmlunit.corejs.javascript.Context; -import net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime; -import net.sourceforge.htmlunit.corejs.javascript.Undefined; - -/** - * A data type that is used to represent a generic, fixed-length binary data buffer. - * - * @author Ahmed Ashour - * @author Frank Danek - * @author Ronald Brill - */ -@JsxClass -public class ArrayBuffer extends SimpleScriptable { - - private byte[] bytes_; - - /** - * Ctor. - */ - public ArrayBuffer() { - } - - /** - * Ctor with given bytes. - * @param bytes the initial bytes - */ - public ArrayBuffer(final byte[] bytes) { - bytes_ = bytes; - } - - /** - * The constructor. - * @param length the size, in bytes, of the array buffer to create. - */ - @JsxConstructor - public void constructor(final int length) { - if (length < 0) { - throw ScriptRuntime.rangeError("invalid array length '" + length + "'."); - } - bytes_ = new byte[length]; - } - - /** - * Returns the size, in bytes, of the array. This is established during construction and cannot be changed. - * @return the byte length. - */ - @JsxGetter - public int getByteLength() { - return bytes_.length; - } - - /** - * Returns a new ArrayBuffer whose contents are a copy of this ArrayBuffer's bytes - * from begin, inclusive, up to end, exclusive. - * @param begin byte index to start slicing - * @param end (optional) byte index to end slicing - * @return the newly created ArrayBuffer - */ - @JsxFunction - public ArrayBuffer slice(final Object begin, final Object end) { - if (begin == Undefined.instance || begin instanceof Boolean) { - throw Context.reportRuntimeError("Invalid type " + begin.getClass().getName()); - } - - final double beginNumber = Context.toNumber(begin); - final int beginInt; - if (Double.isNaN(beginNumber)) { - beginInt = 0; - } - else if (Double.isInfinite(beginNumber)) { - if (beginNumber > 0) { - final byte[] byteArray = new byte[0]; - return new ArrayBuffer(byteArray); - } - beginInt = 0; - } - else { - beginInt = (int) beginNumber; - if (beginInt != beginNumber) { - throw Context.reportRuntimeError("Invalid type " + begin.getClass().getName()); - } - } - - double endNumber; - if (end == Undefined.instance) { - endNumber = getByteLength(); - } - else { - endNumber = Context.toNumber(end); - } - - if (Double.isNaN(endNumber) || Double.isInfinite(endNumber) || endNumber < beginInt) { - endNumber = beginInt; - } - - final byte[] byteArray = new byte[(int) endNumber - beginInt]; - System.arraycopy(bytes_, beginInt, byteArray, 0, byteArray.length); - return new ArrayBuffer(byteArray); - } - - byte getByte(final int index) { - return bytes_[index]; - } - - /** - * Sets the bytes. - * @param index the starting index - * @param array the array - */ - public void setBytes(final int index, final byte[] array) { - int i = array.length - 1; - if (index + i >= bytes_.length) { - i = bytes_.length - index - 1; - } - for ( ; i >= 0; i--) { - bytes_[index + i] = array[i]; - } - } - - /** - * @return the bytes - */ - public byte[] getBytes() { - return bytes_; - } -} Deleted: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/ArrayBufferView.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/ArrayBufferView.java 2018-08-21 05:38:42 UTC (rev 15536) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/ArrayBufferView.java 2018-08-23 07:21:10 UTC (rev 15537) @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2002-2018 Gargoyle Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.gargoylesoftware.htmlunit.javascript.host.arrays; - -import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter; - -/** - * The ArrayBufferView type describes a particular view on the contents of an {@link ArrayBuffer}'s data. - * - * @author Ahmed Ashour - * @author Frank Danek - */ -@JsxClass(isJSObject = false) -public class ArrayBufferView extends SimpleScriptable { - - private ArrayBuffer buffer_; - private int byteLength_; - private int byteOffset_; - - /** - * The constructor. - * @param buffer the array buffer - * @param byteOffset the byte offset - * @param length the length - */ - protected void constructor(final ArrayBuffer buffer, final int byteOffset, final int length) { - buffer_ = buffer; - byteOffset_ = byteOffset; - byteLength_ = length; - } - - /** - * Returns the buffer this view references. - * @return the buffer - */ - @JsxGetter - public ArrayBuffer getBuffer() { - return buffer_; - } - - /** - * Sets the buffer. - * @param buffer the buffer - */ - protected void setBuffer(final ArrayBuffer buffer) { - buffer_ = buffer; - } - - /** - * Returns the length, in bytes, of the view. - * @return the length - */ - @JsxGetter - public int getByteLength() { - return byteLength_; - } - - /** - * Sets the bytes length. - * @param byteLength the bytes length - */ - protected void setByteLength(final int byteLength) { - byteLength_ = byteLength; - } - - /** - * Returns the offset, in bytes, to the first byte of the view within the {@link ArrayBuffer}. - * @return the offset - */ - @JsxGetter - public int getByteOffset() { - return byteOffset_; - } -} Deleted: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/ArrayBufferViewBase.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/ArrayBufferViewBase.java 2018-08-21 05:38:42 UTC (rev 15536) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/ArrayBufferViewBase.java 2018-08-23 07:21:10 UTC (rev 15537) @@ -1,245 +0,0 @@ -/* - * Copyright (c) 2002-2018 Gargoyle Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.gargoylesoftware.htmlunit.javascript.host.arrays; - -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_TYPED_ARRAYS_NULL; - -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter; - -import net.sourceforge.htmlunit.corejs.javascript.Context; -import net.sourceforge.htmlunit.corejs.javascript.NativeArray; -import net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime; -import net.sourceforge.htmlunit.corejs.javascript.Scriptable; -import net.sourceforge.htmlunit.corejs.javascript.ScriptableObject; -import net.sourceforge.htmlunit.corejs.javascript.Undefined; -import net.sourceforge.htmlunit.corejs.javascript.Wrapper; - -/** - * The parent class of all typed arrays, {@link DataView} is not included. - * - * @author Ahmed Ashour - * @author Marc Guillemot - * @author Frank Danek - * @author Ronald Brill - */ -@JsxClass(isJSObject = false) -public class ArrayBufferViewBase extends ArrayBufferView { - - /** - * The constructor. - * - * @param object the object - * @param byteOffset optional byteOffset - * @param length optional length - */ - public void constructor(final Object object, final Object byteOffset, final Object length) { - if (object instanceof Number) { - constructor(((Number) object).intValue()); - } - else if (object instanceof NativeArray) { - constructor((NativeArray) object); - } - else if (object instanceof ArrayBufferViewBase) { - constructor((ArrayBufferViewBase) object); - } - else if (object instanceof ArrayBuffer) { - final ArrayBuffer array = (ArrayBuffer) object; - - double dbByteOffset = Context.toNumber(byteOffset); - if (Double.isNaN(dbByteOffset)) { - dbByteOffset = 0; - } - - double dbLength = Context.toNumber(length); - if (Double.isNaN(dbLength)) { - dbLength = array.getByteLength(); - } - super.constructor(array, (int) dbByteOffset, (int) dbLength); - } - else if (object == Undefined.instance || getBrowserVersion().hasFeature(JS_TYPED_ARRAYS_NULL)) { - constructor(0); - } - else { - throw ScriptRuntime.typeError("invalid arguments"); - } - } - - private void constructor(final int length) { - final int byteLength = length * getBytesPerElement(); - setByteLength(byteLength); - initBuffer(byteLength); - } - - private void constructor(final NativeArray array) { - final int byteLength = (int) array.getLength() * getBytesPerElement(); - setByteLength(byteLength); - initBuffer(byteLength); - set(array, 0); - } - - private void constructor(final ArrayBufferViewBase array) { - final int byteLength = array.getLength() * getBytesPerElement(); - setByteLength(byteLength); - initBuffer(byteLength); - set(array, 0); - } - - private void initBuffer(final int lengthInBytes) { - final ArrayBuffer buffer = new ArrayBuffer(); - buffer.constructor(lengthInBytes); - buffer.setPrototype(getPrototype(buffer.getClass())); - buffer.setParentScope(getParentScope()); - setBuffer(buffer); - } - - /** - * Returns the number of entries in the array. - * @return the number of entries - */ - @JsxGetter - public int getLength() { - return getByteLength() / getBytesPerElement(); - } - - /** - * Sets multiple values in the typed array, reading input values from a specified array. - * @param sourceArray the source array - * @param offset the offset into the target array at which to begin writing values from the source one - */ - @JsxFunction - public void set(final ScriptableObject sourceArray, final int offset) { - final Object lengthProperty = ScriptableObject.getProperty(sourceArray, "length"); - if (lengthProperty instanceof Number) { - final int length = ((Number) lengthProperty).intValue(); - for (int i = 0; i < length; i++) { - final Object value = sourceArray.get(i, sourceArray); - if (value == Scriptable.NOT_FOUND || value == Undefined.instance) { - put(i + offset, this, Double.NaN); - } - else if (value == null) { - put(i + offset, this, 0); - } - else if (value instanceof Wrapper) { - put(i + offset, this, ((Wrapper) value).unwrap()); - } - else { - put(i + offset, this, value); - } - } - } - } - - /** - * {@inheritDoc} - */ - @Override - public Object get(final int index, final Scriptable start) { - final int offset = index * getBytesPerElement() + getByteOffset(); - final ArrayBuffer buffer = getBuffer(); - if (buffer == null) { - return Scriptable.NOT_FOUND; - } - return fromArray(buffer.getBytes(), offset); - } - - /** - * {@inheritDoc} - */ - @Override - public void put(final int index, final Scriptable start, final Object value) { - getBuffer().setBytes(index * getBytesPerElement() + getByteOffset(), - value == null ? toByteArray(null) : toByteArray(Context.toNumber(value))); - } - - /** - * Converts the provided number to byte array. - * @param number the number - * @return the byte array - */ - protected byte[] toByteArray(final Number number) { - return null; - } - - /** - * Converts the provided byte array to number. - * @param array the array - * @param offset the offset - * @return the byte array - */ - protected Object fromArray(final byte[] array, final int offset) { - return null; - } - - /** - * Returns a new view on the ArrayBuffer store for this object. - * @param begin the offset to the first element in the array to be referenced by the new object - * @param end the end offset (exclusive), optional to return at the end. - * @return the newly created array - */ - @JsxFunction - public ArrayBufferView subarray(final int begin, Object end) { - if (end == Undefined.instance) { - end = getLength(); - } - try { - final ArrayBufferView object = getClass().newInstance(); - object.setPrototype(getPrototype()); - object.setParentScope(getParentScope()); - object.constructor(getBuffer(), begin, ((Number) end).intValue() - begin); - return object; - } - catch (final Exception e) { - throw new RuntimeException(e); - } - } - - /** - * Returns the size in bytes of an item in this array. - * @return the size of bytes of an item - */ - protected int getBytesPerElement() { - return 1; - } - - /** - * @return the string version - */ - @JsxFunction(functionName = "toString") - public String jsToString() { - final int arrayLength = getLength(); - final StringBuilder builder = new StringBuilder(); - if (arrayLength > 0) { - builder.append(ScriptRuntime.toString(get(0, this))); - } - for (int i = 1; i < arrayLength; i++) { - builder.append(','); - builder.append(ScriptRuntime.toString(get(i, this))); - } - return builder.toString(); - } - - /** - * {@inheritDoc} - */ - @Override - public Object getDefaultValue(final Class<?> hint) { - if (String.class.equals(hint) || hint == null) { - return jsToString(); - } - return super.getDefaultValue(hint); - } -} Deleted: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/DataView.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/DataView.java 2018-08-21 05:38:42 UTC (rev 15536) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/DataView.java 2018-08-23 07:21:10 UTC (rev 15537) @@ -1,265 +0,0 @@ -/* - * Copyright (c) 2002-2018 Gargoyle Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.gargoylesoftware.htmlunit.javascript.host.arrays; - -import java.nio.ByteBuffer; -import java.nio.ByteOrder; - -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction; - -import net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime; -import net.sourceforge.htmlunit.corejs.javascript.Undefined; - -/** - * The ArrayBufferView type describes a particular view on the contents of an {@link ArrayBuffer}'s data. - * - * @author Ahmed Ashour - * @author Frank Danek - */ -@JsxClass -public class DataView extends ArrayBufferView { - - /** - * JavaScript constructor. - * @param array the array - * @param byteOffset the byte offset - * @param length the length - */ - @JsxConstructor - public void constructor(final Object array, final int byteOffset, Object length) { - if (!(array instanceof ArrayBuffer)) { - throw ScriptRuntime.typeError("First argument to DataView constructor must be an ArrayBuffer"); - } - if (length == Undefined.instance) { - length = ((ArrayBuffer) array).getByteLength(); - } - super.constructor((ArrayBuffer) array, byteOffset, ((Number) length).intValue()); - } - - /** - * Gets a signed 8-bit integer at the specified byte offset from the start of the view. - * @param byteOffset the byte offset - * @return the byte - */ - @JsxFunction - public byte getInt8(final int byteOffset) { - return getBuffer().getBytes()[getByteOffset() + byteOffset]; - } - - /** - * Sets the given signed 8-bit integer at the specified offset. - * @param byteOffset the byte offset - * @param value the value - */ - @JsxFunction - public void setInt8(final int byteOffset, final int value) { - final byte[] array = getBuffer().getBytes(); - array[getByteOffset() + byteOffset] = (byte) value; - } - - /** - * Gets a signed 16-bit integer at the specified byte offset from the start of the view. - * @param byteOffset the byte offset - * @param littleEndian whether the value is stored in little- or big-endian format - * @return the value - */ - @JsxFunction - public short getInt16(final int byteOffset, final boolean littleEndian) { - final ByteBuffer buff = ByteBuffer.wrap(getBuffer().getBytes()); - if (littleEndian) { - buff.order(ByteOrder.LITTLE_ENDIAN); - } - return buff.getShort(getByteOffset() + byteOffset); - } - - /** - * Sets the given signed 16-bit integer at the specified offset. - * @param byteOffset the byte offset - * @param value the value - * @param littleEndian whether the value is stored in little- or big-endian format - */ - @JsxFunction - public void setInt16(final int byteOffset, final int value, final boolean littleEndian) { - final ByteBuffer buff = ByteBuffer.wrap(getBuffer().getBytes()); - if (littleEndian) { - buff.order(ByteOrder.LITTLE_ENDIAN); - } - buff.putShort(getByteOffset() + byteOffset, (short) value); - } - - /** - * Gets a signed 32-bit integer at the specified byte offset from the start of the view. - * @param byteOffset the byte offset - * @param littleEndian whether the value is stored in little- or big-endian format - * @return the value - */ - @JsxFunction - public int getInt32(final int byteOffset, final boolean littleEndian) { - final ByteBuffer buff = ByteBuffer.wrap(getBuffer().getBytes()); - if (littleEndian) { - buff.order(ByteOrder.LITTLE_ENDIAN); - } - return buff.getInt(getByteOffset() + byteOffset); - } - - /** - * Sets the given signed 32-bit integer at the specified offset. - * @param byteOffset the byte offset - * @param value the value - * @param littleEndian whether the value is stored in little- or big-endian format - */ - @JsxFunction - public void setInt32(final int byteOffset, final int value, final boolean littleEndian) { - final ByteBuffer buff = ByteBuffer.wrap(getBuffer().getBytes()); - if (littleEndian) { - buff.order(ByteOrder.LITTLE_ENDIAN); - } - buff.putInt(getByteOffset() + byteOffset, value); - } - - /** - * Gets an unsigned 8-bit integer at the specified byte offset from the start of the view. - * @param byteOffset the byte offset - * @return the value - */ - @JsxFunction - public int getUint8(final int byteOffset) { - return getBuffer().getBytes()[getByteOffset() + byteOffset] & 0xFF; - } - - /** - * Sets the given unsigned 8-bit integer at the specified offset. - * @param byteOffset the byte offset - * @param value the value - */ - @JsxFunction - public void setUint8(final int byteOffset, final int value) { - setInt8(byteOffset, value); - } - - /** - * Gets an unsigned 16-bit integer at the specified byte offset from the start of the view. - * @param byteOffset the byte offset - * @param littleEndian whether the value is stored in little- or big-endian format - * @return the value - */ - @JsxFunction - public int getUint16(final int byteOffset, final boolean littleEndian) { - final ByteBuffer buff = ByteBuffer.wrap(getBuffer().getBytes()); - if (littleEndian) { - buff.order(ByteOrder.LITTLE_ENDIAN); - } - return buff.getShort(getByteOffset() + byteOffset) & 0xFFFF; - } - - /** - * Sets the given unsigned 16-bit integer at the specified offset. - * @param byteOffset the byte offset - * @param value the value - * @param littleEndian whether the value is stored in little- or big-endian format - */ - @JsxFunction - public void setUint16(final int byteOffset, final int value, final boolean littleEndian) { - setInt16(byteOffset, value, littleEndian); - } - - /** - * Gets an unsigned 32-bit integer at the specified byte offset from the start of the view. - * @param byteOffset the byte offset - * @param littleEndian whether the value is stored in little- or big-endian format - * @return the value - */ - @JsxFunction - public long getUint32(final int byteOffset, final boolean littleEndian) { - final ByteBuffer buff = ByteBuffer.wrap(getBuffer().getBytes()); - if (littleEndian) { - buff.order(ByteOrder.LITTLE_ENDIAN); - } - return buff.getInt(getByteOffset() + byteOffset) & 0xFFFFFFFFL; - } - - /** - * Sets the given unsigned 32-bit integer at the specified offset. - * @param byteOffset the byte offset - * @param value the value - * @param littleEndian whether the value is stored in little- or big-endian format - */ - @JsxFunction - public void setUint32(final int byteOffset, final int value, final boolean littleEndian) { - setInt32(byteOffset, value, littleEndian); - } - - /** - * Gets a 32-bit floating point number at the specified byte offset from the start of the view. - * @param byteOffset the byte offset - * @param littleEndian whether the value is stored in little- or big-endian format - * @return the value - */ - @JsxFunction - public float getFloat32(final int byteOffset, final boolean littleEndian) { - final ByteBuffer buff = ByteBuffer.wrap(getBuffer().getBytes()); - if (littleEndian) { - buff.order(ByteOrder.LITTLE_ENDIAN); - } - return buff.getFloat(getByteOffset() + byteOffset); - } - - /** - * Sets the given 32-bit floating point number at the specified offset. - * @param byteOffset the byte offset - * @param value the value - * @param littleEndian whether the value is stored in little- or big-endian format - */ - @JsxFunction - public void setFloat32(final int byteOffset, final double value, final boolean littleEndian) { - final ByteBuffer buff = ByteBuffer.wrap(getBuffer().getBytes()); - if (littleEndian) { - buff.order(ByteOrder.LITTLE_ENDIAN); - } - buff.putFloat(getByteOffset() + byteOffset, (float) value); - } - - /** - * Gets a 64-bit floating point number at the specified byte offset from the start of the view. - * @param byteOffset the byte offset - * @param littleEndian whether the value is stored in little- or big-endian format - * @return the value - */ - @JsxFunction - public double getFloat64(final int byteOffset, final boolean littleEndian) { - final ByteBuffer buff = ByteBuffer.wrap(getBuffer().getBytes()); - if (littleEndian) { - buff.order(ByteOrder.LITTLE_ENDIAN); - } - return buff.getDouble(getByteOffset() + byteOffset); - } - - /** - * Sets the given 32-bit floating point number at the specified offset. - * @param byteOffset the byte offset - * @param value the value - * @param littleEndian whether the value is stored in little- or big-endian format - */ - @JsxFunction - public void setFloat64(final int byteOffset, final double value, final boolean littleEndian) { - final ByteBuffer buff = ByteBuffer.wrap(getBuffer().getBytes()); - if (littleEndian) { - buff.order(ByteOrder.LITTLE_ENDIAN); - } - buff.putDouble(getByteOffset() + byteOffset, value); - } -} Deleted: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Float32Array.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Float32Array.java 2018-08-21 05:38:42 UTC (rev 15536) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Float32Array.java 2018-08-23 07:21:10 UTC (rev 15537) @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2002-2018 Gargoyle Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.gargoylesoftware.htmlunit.javascript.host.arrays; - -import java.nio.ByteBuffer; -import java.nio.ByteOrder; - -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstant; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor; - -import net.sourceforge.htmlunit.corejs.javascript.Scriptable; - -/** - * Represents an array of 32-bit floating point numbers. - * - * @author Ahmed Ashour - * @author Frank Danek - * @author Ronald Brill - * @author Michael Rimov - */ -@JsxClass -public class Float32Array extends ArrayBufferViewBase { - - /** The size, in bytes, of each array element. */ - @JsxConstant - public static final int BYTES_PER_ELEMENT = 4; - - /** - * {@inheritDoc} - */ - @Override - @JsxConstructor - public void constructor(final Object object, final Object byteOffset, final Object length) { - super.constructor(object, byteOffset, length); - } - - /** - * {@inheritDoc} - */ - @Override - protected byte[] toByteArray(final Number number) { - final ByteBuffer buff = ByteBuffer.allocate(BYTES_PER_ELEMENT); - buff.order(ByteOrder.LITTLE_ENDIAN); - buff.putFloat(number != null ? number.floatValue() : Float.NaN); - return buff.array(); - } - - /** - * {@inheritDoc} - */ - @Override - protected Object fromArray(final byte[] array, final int offset) { - if (offset < 0 || offset >= array.length) { - return Scriptable.NOT_FOUND; - } - final ByteBuffer buff = ByteBuffer.wrap(array); - buff.order(ByteOrder.LITTLE_ENDIAN); - return buff.getFloat(offset); - } - - /** - * {@inheritDoc} - */ - @Override - protected int getBytesPerElement() { - return BYTES_PER_ELEMENT; - } - -} Deleted: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Float64Array.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Float64Array.java 2018-08-21 05:38:42 UTC (rev 15536) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Float64Array.java 2018-08-23 07:21:10 UTC (rev 15537) @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2002-2018 Gargoyle Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.gargoylesoftware.htmlunit.javascript.host.arrays; - -import java.nio.ByteBuffer; -import java.nio.ByteOrder; - -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstant; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor; - -import net.sourceforge.htmlunit.corejs.javascript.Scriptable; - -/** - * Represents an array of 64-bit floating point numbers. - * - * @author Ahmed Ashour - * @author Frank Danek - * @author Ronald Brill - * @author Michael Rimov - */ -@JsxClass -public class Float64Array extends ArrayBufferViewBase { - - /** The size, in bytes, of each array element. */ - @JsxConstant - public static final int BYTES_PER_ELEMENT = 8; - - /** - * {@inheritDoc} - */ - @Override - @JsxConstructor - public void constructor(final Object object, final Object byteOffset, final Object length) { - super.constructor(object, byteOffset, length); - } - - /** - * {@inheritDoc} - */ - @Override - protected byte[] toByteArray(final Number number) { - final ByteBuffer buff = ByteBuffer.allocate(BYTES_PER_ELEMENT); - buff.order(ByteOrder.LITTLE_ENDIAN); - buff.putDouble(number != null ? number.doubleValue() : Double.NaN); - return buff.array(); - } - - /** - * {@inheritDoc} - */ - @Override - protected Object fromArray(final byte[] array, final int offset) { - if (offset < 0 || offset >= array.length) { - return Scriptable.NOT_FOUND; - } - final ByteBuffer buff = ByteBuffer.wrap(array); - buff.order(ByteOrder.LITTLE_ENDIAN); - return buff.getDouble(offset); - } - - /** - * {@inheritDoc} - */ - @Override - protected int getBytesPerElement() { - return BYTES_PER_ELEMENT; - } - -} Deleted: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Int16Array.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Int16Array.java 2018-08-21 05:38:42 UTC (rev 15536) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Int16Array.java 2018-08-23 07:21:10 UTC (rev 15537) @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2002-2018 Gargoyle Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.gargoylesoftware.htmlunit.javascript.host.arrays; - -import java.nio.ByteBuffer; -import java.nio.ByteOrder; - -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstant; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor; - -import net.sourceforge.htmlunit.corejs.javascript.Scriptable; - -/** - * Represents an array of twos-complement 16-bit signed integers. - * - * @author Ahmed Ashour - * @author Frank Danek - * @author Ronald Brill - * @author Michael Rimov - */ -@JsxClass -public class Int16Array extends ArrayBufferViewBase { - - /** The size, in bytes, of each array element. */ - @JsxConstant - public static final int BYTES_PER_ELEMENT = 2; - - /** - * {@inheritDoc} - */ - @Override - @JsxConstructor - public void constructor(final Object object, final Object byteOffset, final Object length) { - super.constructor(object, byteOffset, length); - } - - /** - * {@inheritDoc} - */ - @Override - protected byte[] toByteArray(final Number number) { - final ByteBuffer buff = ByteBuffer.allocate(BYTES_PER_ELEMENT); - buff.order(ByteOrder.LITTLE_ENDIAN); - if (number == null || Double.isInfinite(number.doubleValue())) { - buff.putShort((short) 0); - return buff.array(); - } - buff.putShort(number.shortValue()); - return buff.array(); - } - - /** - * {@inheritDoc} - */ - @Override - protected Object fromArray(final byte[] array, final int offset) { - if (offset < 0 || offset >= array.length) { - return Scriptable.NOT_FOUND; - } - final ByteBuffer buff = ByteBuffer.wrap(array); - buff.order(ByteOrder.LITTLE_ENDIAN); - return buff.getShort(offset); - } - - /** - * {@inheritDoc} - */ - @Override - protected int getBytesPerElement() { - return BYTES_PER_ELEMENT; - } - -} Deleted: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Int32Array.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Int32Array.java 2018-08-21 05:38:42 UTC (rev 15536) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Int32Array.java 2018-08-23 07:21:10 UTC (rev 15537) @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2002-2018 Gargoyle Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.gargoylesoftware.htmlunit.javascript.host.arrays; - -import java.nio.ByteBuffer; -import java.nio.ByteOrder; - -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstant; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor; - -import net.sourceforge.htmlunit.corejs.javascript.Scriptable; - -/** - * Represents an array of twos-complement 32-bit signed integers. - * - * @author Ahmed Ashour - * @author Frank Danek - * @author Ronald Brill - * @author Michael Rimov - */ -@JsxClass -public class Int32Array extends ArrayBufferViewBase { - - /** The size, in bytes, of each array element. */ - @JsxConstant - public static final int BYTES_PER_ELEMENT = 4; - - /** - * {@inheritDoc} - */ - @Override - @JsxConstructor - public void constructor(final Object object, final Object byteOffset, final Object length) { - super.constructor(object, byteOffset, length); - } - - /** - * {@inheritDoc} - */ - @Override - protected byte[] toByteArray(final Number number) { - final ByteBuffer buff = ByteBuffer.allocate(BYTES_PER_ELEMENT); - buff.order(ByteOrder.LITTLE_ENDIAN); - if (number == null || Double.isInfinite(number.doubleValue())) { - buff.putInt(0); - return buff.array(); - } - buff.putInt(number.intValue()); - return buff.array(); - } - - /** - * {@inheritDoc} - */ - @Override - protected Object fromArray(final byte[] array, final int offset) { - if (offset < 0 || offset >= array.length) { - return Scriptable.NOT_FOUND; - } - final ByteBuffer buff = ByteBuffer.wrap(array); - buff.order(ByteOrder.LITTLE_ENDIAN); - return buff.getInt(offset); - } - - /** - * {@inheritDoc} - */ - @Override - protected int getBytesPerElement() { - return BYTES_PER_ELEMENT; - } - -} Deleted: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Int8Array.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Int8Array.java 2018-08-21 05:38:42 UTC (rev 15536) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Int8Array.java 2018-08-23 07:21:10 UTC (rev 15537) @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2002-2018 Gargoyle Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.gargoylesoftware.htmlunit.javascript.host.arrays; - -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstant; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor; - -import net.sourceforge.htmlunit.corejs.javascript.Scriptable; - -/** - * Represents an array of twos-complement 8-bit signed integers. - * - * @author Ahmed Ashour - * @author Frank Danek - * @author Ronald Brill - * @author Michael Rimov - */ -@JsxClass -public class Int8Array extends ArrayBufferViewBase { - - /** The size, in bytes, of each array element. */ - @JsxConstant - public static final int BYTES_PER_ELEMENT = 1; - - /** - * {@inheritDoc} - */ - @Override - @JsxConstructor - public void constructor(final Object object, final Object byteOffset, final Object length) { - super.constructor(object, byteOffset, length); - } - - /** - * {@inheritDoc} - */ - @Override - protected byte[] toByteArray(final Number number) { - if (number == null || Double.isInfinite(number.doubleValue())) { - return new byte[] {0}; - } - return new byte[] {number.byteValue()}; - } - - /** - * {@inheritDoc} - */ - @Override - protected Object fromArray(final byte[] array, final int offset) { - if (offset < 0 || offset >= array.length) { - return Scriptable.NOT_FOUND; - } - return array[offset]; - } - - /** - * {@inheritDoc} - */ - @Override - protected int getBytesPerElement() { - return BYTES_PER_ELEMENT; - } - -} Deleted: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Uint16Array.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Uint16Array.java 2018-08-21 05:38:42 UTC (rev 15536) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Uint16Array.java 2018-08-23 07:21:10 UTC (rev 15537) @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2002-2018 Gargoyle Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.gargoylesoftware.htmlunit.javascript.host.arrays; - -import java.nio.ByteBuffer; -import java.nio.ByteOrder; - -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstant; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor; - -import net.sourceforge.htmlunit.corejs.javascript.Scriptable; - -/** - * Represents an array of unsigned 16-bit integers. - * - * @author Ahmed Ashour - * @author Frank Danek - * @author Ronald Brill - * @author Michael Rimov - */ -@JsxClass -public class Uint16Array extends ArrayBufferViewBase { - - /** The size, in bytes, of each array element. */ - @JsxConstant - public static final int BYTES_PER_ELEMENT = 2; - - /** - * {@inheritDoc} - */ - @Override - @JsxConstructor - public void constructor(final Object object, final Object byteOffset, final Object length) { - super.constructor(object, byteOffset, length); - } - - /** - * {@inheritDoc} - */ - @Override - protected byte[] toByteArray(final Number number) { - final ByteBuffer buff = ByteBuffer.allocate(BYTES_PER_ELEMENT); - buff.order(ByteOrder.LITTLE_ENDIAN); - if (number == null || Double.isInfinite(number.doubleValue())) { - buff.putShort((short) 0); - return buff.array(); - } - buff.putShort(number.shortValue()); - return buff.array(); - } - - /** - * {@inheritDoc} - */ - @Override - protected Object fromArray(final byte[] array, final int offset) { - if (offset < 0 || offset >= array.length) { - return Scriptable.NOT_FOUND; - } - final ByteBuffer buff = ByteBuffer.wrap(array); - buff.order(ByteOrder.LITTLE_ENDIAN); - return buff.getShort(offset) & 0xFFFF; - } - - /** - * {@inheritDoc} - */ - @Override - protected int getBytesPerElement() { - return BYTES_PER_ELEMENT; - } - -} Deleted: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Uint32Array.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Uint32Array.java 2018-08-21 05:38:42 UTC (rev 15536) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Uint32Array.java 2018-08-23 07:21:10 UTC (rev 15537) @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2002-2018 Garg... [truncated message content] |