[HtmlUnit] SVN: [15537] trunk/htmlunit/src
rbri--- via HtmlUnit-develop <[email protected]> Thu, 23 Aug 2018 07:21:18 +0000
| Newsgroups | gmane.comp.java.htmlunit.devel |
|---|---|
| Message-ID | <[email protected]> |
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 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 32-bit integers.
- *
- * @author Ahmed Ashour
- * @author Frank Danek
- * @author Ronald Brill
- * @author Michael Rimov
- */
-@JsxClass
-public class Uint32Array 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) & 0xFFFFFFFFL;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected int getBytesPerElement() {
- return BYTES_PER_ELEMENT;
- }
-
-}
Deleted: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Uint8Array.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Uint8Array.java 2018-08-21 05:38:42 UTC (rev 15536)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Uint8Array.java 2018-08-23 07:21:10 UTC (rev 15537)
@@ -1,103 +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 com.gargoylesoftware.htmlunit.javascript.host.Window;
-
-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 Uint8Array extends ArrayBufferViewBase {
-
- /**
- * Ctor.
- */
- public Uint8Array() {
- super();
- }
-
- /**
- * Ctor.
- *
- * @param bytes the bytes to store
- * @param window the context
- */
- public Uint8Array(final byte[] bytes, final Window window) {
- this();
- setPrototype(window.getPrototype(getClass()));
- setParentScope(getParentScope());
-
- setByteLength(bytes.length);
-
- final ArrayBuffer buffer = new ArrayBuffer(bytes);
- buffer.setPrototype(window.getPrototype(buffer.getClass()));
- buffer.setParentScope(getParentScope());
- setBuffer(buffer);
- }
-
- /** 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] & 0xFF;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected int getBytesPerElement() {
- return BYTES_PER_ELEMENT;
- }
-}
Deleted: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Uint8ClampedArray.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Uint8ClampedArray.java 2018-08-21 05:38:42 UTC (rev 15536)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Uint8ClampedArray.java 2018-08-23 07:21:10 UTC (rev 15537)
@@ -1,79 +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 unsigned 16-bit integers. Values stored in this array are clamped to the range 0-255.
- *
- * @author Ahmed Ashour
- * @author Ronald Brill
- * @author Michael Rimov
- */
-@JsxClass
-public class Uint8ClampedArray 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(Number number) {
- if (number == null || number.intValue() < 0) {
- number = 0;
- }
- else if (number.intValue() > 255) {
- number = 255;
- }
- 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] & 0xFF;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected int getBytesPerElement() {
- return BYTES_PER_ELEMENT;
- }
-
-}
Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/canvas/ImageData.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/canvas/ImageData.java 2018-08-21 05:38:42 UTC (rev 15536)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/canvas/ImageData.java 2018-08-23 07:21:10 UTC (rev 15537)
@@ -22,10 +22,12 @@
import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass;
import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor;
import com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter;
-import com.gargoylesoftware.htmlunit.javascript.host.arrays.ArrayBuffer;
-import com.gargoylesoftware.htmlunit.javascript.host.arrays.Uint8ClampedArray;
import com.gargoylesoftware.htmlunit.javascript.host.canvas.rendering.RenderingBackend;
+import net.sourceforge.htmlunit.corejs.javascript.ScriptableObject;
+import net.sourceforge.htmlunit.corejs.javascript.typedarrays.NativeArrayBuffer;
+import net.sourceforge.htmlunit.corejs.javascript.typedarrays.NativeUint8ClampedArray;
+
/**
* A JavaScript object for {@code ImageData}.
*
@@ -40,7 +42,7 @@
private final int sy_;
private final int width_;
private final int height_;
- private Uint8ClampedArray data_;
+ private NativeUint8ClampedArray data_;
/**
* Default constructor.
@@ -77,23 +79,20 @@
}
/**
- * Returns a {@link Uint8ClampedArray} representing a one-dimensional array containing
+ * Returns a {@link NativeUint8ClampedArray} representing a one-dimensional array containing
* the data in the RGBA order, with integer values between 0 and 255 (included).
* @return the {@code data} property
*/
@JsxGetter
- public Uint8ClampedArray getData() {
+ public NativeUint8ClampedArray getData() {
if (data_ == null) {
final byte[] bytes = renderingContext_.getBytes(width_, height_, sx_, sy_);
- final ArrayBuffer arrayBuffer = new ArrayBuffer();
- arrayBuffer.constructor(bytes.length);
- arrayBuffer.setBytes(0, bytes);
+ final NativeArrayBuffer arrayBuffer = new NativeArrayBuffer(bytes.length);
+ System.arraycopy(bytes, 0, arrayBuffer.getBuffer(), 0, bytes.length);
- data_ = new Uint8ClampedArray();
+ data_ = new NativeUint8ClampedArray(arrayBuffer, 0, bytes.length);
data_.setParentScope(getParentScope());
- data_.setPrototype(getPrototype(data_.getClass()));
-
- data_.constructor(arrayBuffer, 0, bytes.length);
+ data_.setPrototype(ScriptableObject.getClassPrototype(getWindow(this), data_.getClassName()));
}
return data_;
Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/crypto/Crypto.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/crypto/Crypto.java 2018-08-21 05:38:42 UTC (rev 15536)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/crypto/Crypto.java 2018-08-23 07:21:10 UTC (rev 15537)
@@ -26,9 +26,9 @@
import com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction;
import com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter;
import com.gargoylesoftware.htmlunit.javascript.host.Window;
-import com.gargoylesoftware.htmlunit.javascript.host.arrays.ArrayBufferViewBase;
import net.sourceforge.htmlunit.corejs.javascript.Context;
+import net.sourceforge.htmlunit.corejs.javascript.typedarrays.NativeTypedArrayView;
/**
* A JavaScript object for {@code Crypto}.
@@ -62,13 +62,13 @@
* @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/RandomSource/getRandomValues">MDN Doc</a>
*/
@JsxFunction
- public void getRandomValues(final ArrayBufferViewBase array) {
+ public void getRandomValues(final NativeTypedArrayView<?> array) {
if (array == null) {
throw Context.reportRuntimeError("TypeError: Argument 1 of Crypto.getRandomValues is not an object.");
}
final Random random = new Random();
- for (int i = 0; i < array.getLength(); i++) {
+ for (int i = 0; i < array.getByteLength() / array.getBytesPerElement(); i++) {
array.put(i, array, random.nextInt());
}
}
Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileReader.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileReader.java 2018-08-21 05:38:42 UTC (rev 15536)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileReader.java 2018-08-23 07:21:10 UTC (rev 15537)
@@ -31,11 +31,12 @@
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.Event;
import com.gargoylesoftware.htmlunit.javascript.host.event.EventTarget;
import net.sourceforge.htmlunit.corejs.javascript.Function;
+import net.sourceforge.htmlunit.corejs.javascript.ScriptableObject;
+import net.sourceforge.htmlunit.corejs.javascript.typedarrays.NativeArrayBuffer;
/**
* A JavaScript object for {@code FileReader}.
@@ -141,9 +142,11 @@
final byte[] bytes = bos.toByteArray();
- final ArrayBuffer buffer = new ArrayBuffer(bytes);
+ final NativeArrayBuffer buffer = new NativeArrayBuffer(bytes.length);
+ System.arraycopy(bytes, 0, buffer.getBuffer(), 0, bytes.length);
buffer.setParentScope(getParentScope());
- buffer.setPrototype(getPrototype(buffer.getClass()));
+ buffer.setPrototype(ScriptableObject.getClassPrototype(getWindow(), buffer.getClassName()));
+
result_ = buffer;
}
readyState_ = DONE;
Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfigurationTest.java
===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfigurationTest.java 2018-08-21 05:38:42 UTC (rev 15536)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfigurationTest.java 2018-08-23 07:21:10 UTC (rev 15537)
@@ -16,8 +16,8 @@
import static com.gargoylesoftware.htmlunit.BrowserVersion.CHROME;
import static com.gargoylesoftware.htmlunit.BrowserVersion.EDGE;
+import static com.gargoylesoftware.htmlunit.BrowserVersion.FIREFOX_52;
import static com.gargoylesoftware.htmlunit.BrowserVersion.FIREFOX_60;
-import static com.gargoylesoftware.htmlunit.BrowserVersion.FIREFOX_52;
import static com.gargoylesoftware.htmlunit.BrowserVersion.INTERNET_EXPLORER;
import static org.junit.Assert.fail;
@@ -29,13 +29,10 @@
import java.net.URL;
import java.text.MessageFormat;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Enumeration;
-import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
-import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
@@ -50,19 +47,6 @@
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine;
import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable;
-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.worker.DedicatedWorkerGlobalScope;
/**
@@ -299,21 +283,8 @@
*/
@Test
public void lexicographicOrder() {
- // we will use the Rhino stuff as soon as possible
- final Set<Class> ignore = new HashSet<Class>(Arrays.asList(
- 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
- ));
-
String lastClassName = null;
for (final Class<?> c : JavaScriptConfiguration.CLASSES_) {
- if (ignore.contains(c)) {
- continue;
- }
-
final String name = c.getSimpleName();
if (lastClassName != null && name.compareToIgnoreCase(lastClassName) < 0) {
fail("JavaScriptConfiguration.CLASSES_: '"
Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/TextEncoderTest.java
===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/TextEncoderTest.java 2018-08-21 05:38:42 UTC (rev 15536)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/TextEncoderTest.java 2018-08-23 07:21:10 UTC (rev 15537)
@@ -85,7 +85,7 @@
+ "<body onload='doTest()'>\n"
+ "</body></html>";
- loadPageWithAlerts2(html);
+ loadPageWithAlerts2(html, 7777777);
}
/**
Deleted: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/ArrayBuffer2Test.java
===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/ArrayBuffer2Test.java 2018-08-21 05:38:42 UTC (rev 15536)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/ArrayBuffer2Test.java 2018-08-23 07:21:10 UTC (rev 15537)
@@ -1,48 +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 org.junit.Assert.assertArrayEquals;
-
-import org.junit.Test;
-
-/**
- * Tests for {@link ArrayBuffer}.
- *
- * @author Ahmed Ashour
- */
-public class ArrayBuffer2Test {
-
- /**
- * @throws Exception if the test fails
- */
- @Test
- public void outOfRange() throws Exception {
- final ArrayBuffer arrayBuffer = new ArrayBuffer();
- arrayBuffer.constructor(5);
-
- arrayBuffer.setBytes(0, new byte[] {10, 11, 12, 13, 14});
- assertArrayEquals(new byte[] {10, 11, 12, 13, 14}, arrayBuffer.getBytes());
-
- arrayBuffer.setBytes(3, new byte[] {100, 101, 102, 103});
- assertArrayEquals(new byte[] {10, 11, 12, 100, 101}, arrayBuffer.getBytes());
-
- arrayBuffer.setBytes(4, new byte[] {40, 41, 42, 43});
- assertArrayEquals(new byte[] {10, 11, 12, 100, 40}, arrayBuffer.getBytes());
-
- arrayBuffer.setBytes(5, new byte[] {50, 51, 52, 53});
- assertArrayEquals(new byte[] {10, 11, 12, 100, 40}, arrayBuffer.getBytes());
- }
-}
Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/crypto/CryptoTest.java
===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/crypto/CryptoTest.java 2018-08-21 05:38:42 UTC (rev 15536)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/crypto/CryptoTest.java 2018-08-23 07:21:10 UTC (rev 15537)
@@ -34,20 +34,24 @@
* @throws Exception if the test fails
*/
@Test
- @Alerts(DEFAULT = {"true", "false"},
+ @Alerts(DEFAULT = {"true", "true", "true", "false", "false", "false"},
IE = {"true", "exception"})
public void getRandomValues() throws Exception {
final String html = "<html><head><script>\n"
+ "try {\n"
+ " var array = new Uint32Array(10);\n"
+ + " alert(array[0] == 0);\n"
+ " alert(array[3] == 0);\n"
+ + " alert(array[9] == 0);\n"
+ " window.crypto.getRandomValues(array);\n"
+ + " alert(array[0] == 0);\n"
+ " alert(array[3] == 0);\n"
+ + " alert(array[9] == 0);\n"
+ "}\n"
+ "catch(e) { alert('exception'); }\n"
+ "</script></head></html>";
- loadPageWithAlerts2(html);
+ loadPageWithAlerts2(html, 777777);
}
/**
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot