You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ha...@apache.org on 2026/02/10 22:32:21 UTC
(royale-asjs) branch develop updated: BinaryData in JS can accept a number array or a ArrayBuffer view.
This is an automated email from the ASF dual-hosted git repository.
harbs pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git
The following commit(s) were added to refs/heads/develop by this push:
new ac64ed648e BinaryData in JS can accept a number array or a ArrayBuffer view.
ac64ed648e is described below
commit ac64ed648eeb9383bd3d22695ea1434725e169a0
Author: Harbs <ha...@in-tools.com>
AuthorDate: Wed Feb 11 00:32:16 2026 +0200
BinaryData in JS can accept a number array or a ArrayBuffer view.
---
.../src/main/royale/org/apache/royale/utils/BinaryData.as | 13 ++++++++++++-
.../src/test/royale/flexUnitTests/BinaryDataTesterTest.as | 10 ++++++++++
2 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/BinaryData.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/BinaryData.as
index 11f692dfa5..21dcb2f6e2 100644
--- a/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/BinaryData.as
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/BinaryData.as
@@ -52,7 +52,12 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
{
/**
* Constructor. The constructor takes an optional bytes argument.
- * In Flash this should be a ByteArray. In JS this should be an ArrayBuffer
+ * In Flash this should be a ByteArray.
+ * In JS this should be an ArrayBuffer.
+ *
+ * The JS constructor also accepts an Array of numbers,
+ * or any ArrayBufferView (like Uint8Array) as a parameter,
+ * but these are not valid types for the Flash constructor.
*
* @langversion 3.0
* @playerversion Flash 10.2
@@ -66,11 +71,17 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
}
/**
+ * @royaleignorecoercion Array
* @royaleignorecoercion ArrayBuffer
+ * @royaleignorecoercion ArrayBufferView
*/
COMPILE::JS
public function BinaryData(bytes:Object = null)
{
+ if(bytes is Array)
+ bytes = new Uint8Array(bytes);
+ if(ArrayBuffer.isView(bytes))
+ bytes = (bytes as ArrayBufferView).buffer;
if(goog.DEBUG)
{
if(bytes && typeof bytes.byteLength != "number" && bytes.buffer !== undefined)
diff --git a/frameworks/projects/Core/src/test/royale/flexUnitTests/BinaryDataTesterTest.as b/frameworks/projects/Core/src/test/royale/flexUnitTests/BinaryDataTesterTest.as
index caadcf7c02..1572be3b7f 100644
--- a/frameworks/projects/Core/src/test/royale/flexUnitTests/BinaryDataTesterTest.as
+++ b/frameworks/projects/Core/src/test/royale/flexUnitTests/BinaryDataTesterTest.as
@@ -630,6 +630,16 @@ package flexUnitTests {
assertEquals(0, ba.position, "BinaryData position after clear: should be 0");
assertNotEquals(ba.data, olddata, "BinaryData data accessor after clear: should be new internal instance");
}
+ [Test]
+ public function testArray():void
+ {
+ COMPILE::JS {
+ var ba:BinaryData = new BinaryData([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]);
+ assertEquals(15, ba.length, "BinaryData length should be 15");
+ assertEquals(0, ba.position, "BinaryData position should be 0");
+ assertTrue(ba.data instanceof ArrayBuffer, "BinaryData data accessor should be an ArrayBuffer");
+ }
+ }
}
}