You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: implement comprehensive TypedArray support for efficient binary data handling
Add complete support for all 11 JavaScript TypedArray types (Int8Array, Uint8Array,
Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array,
Float64Array, BigInt64Array, BigUint64Array) with proper C++ type mapping and runtime
implementation.
Key Features:
- TypedArray type recognition in SimpleTypeChecker for all 11 types
- Comprehensive C++ type mapping (Int8Array → js::Int8Array, etc.)
- TypedArray base class template inheriting from array<T>
- Full method implementations: subarray(), set(), fill()
- Property support: length, byteLength, BYTES_PER_ELEMENT
- Constructor overloads for size initialization and data initialization
- Special Uint8ClampedArray with value clamping (0-255)
- 10 comprehensive test scenarios covering all TypedArray usage patterns
Applications:
- Graphics programming (vertex data with Float32Array)
- Audio processing (samples with Int16Array)
- Binary data manipulation (bytes with Uint8Array)
- Game engines (efficient data structures)
- Mathematical computations (typed numeric arrays)
Technical Implementation:
- Added TypedArray type detection in getTypeString() method
- Enhanced mapToCppType() with specific C++ type mappings
- Runtime library expanded with 167 lines of TypedArray implementations
- Template-based inheritance ensuring type safety and JavaScript semantics
- Memory-efficient binary data handling with proper byte calculations
All tests pass (10/10) demonstrating complete functionality for:
✅ Basic TypedArray operations and property access
✅ Mathematical operations and audio processing
✅ Graphics data handling and vertex operations
✅ Binary data manipulation and storage
✅ Multiple TypedArray type interactions
✅ Advanced methods (subarray, set, fill)
Copy file name to clipboardExpand all lines: RELEASE_NOTES_v0.8.x.md
+117-2Lines changed: 117 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -781,7 +781,7 @@ const strings = createArray(3, "hello" as string); // T inferred as string from
781
781
// Function with mixed inference suppression
782
782
function processData<T extends object>(
783
783
processor: (item: T) => void,
784
-
data: NoInfer<T>[]
784
+
data: NoInfer<T>[],
785
785
): void {
786
786
data.forEach(processor);
787
787
}
@@ -797,7 +797,7 @@ type Optional<T> = {
797
797
798
798
function applyDefaults<T>(
799
799
defaults: T,
800
-
overrides: Optional<T>
800
+
overrides: Optional<T>,
801
801
): T {
802
802
return { ...defaults, ...overrides };
803
803
}
@@ -831,6 +831,114 @@ T applyDefaults(T defaults, js::object overrides) {
831
831
832
832
**Note:** NoInfer is a compile-time TypeScript utility that controls type inference behavior. TypeScript2Cxx processes NoInfer by extracting the inner type and using it directly in C++ generation, since C++ template type deduction works differently from TypeScript's inference system. The utility serves its purpose during the TypeScript compilation phase and doesn't require special runtime handling in C++.
833
833
834
+
#### TypedArray Support
835
+
836
+
TypeScript2Cxx now includes comprehensive support for all JavaScript TypedArray types, providing efficient binary data handling for applications like graphics programming, audio processing, and data manipulation. TypedArrays are mapped to specific C++ template classes that inherit from the base array type while providing TypedArray-specific methods and properties.
837
+
838
+
**TypeScript Code:**
839
+
840
+
```typescript
841
+
// Basic TypedArray usage
842
+
const data = new Uint8Array(10);
843
+
data[0] = 255;
844
+
data[1] = 128;
845
+
846
+
const buffer = new Float32Array([1.1, 2.2, 3.3, 4.4]);
847
+
const subBuffer = buffer.subarray(1, 3);
848
+
849
+
// Audio processing example with Int16Array
850
+
const audioSamples = new Int16Array(1024);
851
+
852
+
function generateSineWave(
853
+
buffer: Int16Array,
854
+
frequency: number,
855
+
sampleRate: number
856
+
): void {
857
+
for (let i = 0; i < buffer.length; i++) {
858
+
const t = i / sampleRate;
859
+
const sample = Math.sin(2 * Math.PI * frequency * t);
- `BYTES_PER_ELEMENT` - Bytes per element (static property)
936
+
- `subarray(start, end)` - Create a typed view of a portion
937
+
- `set(source, offset)` - Copy data from another array
938
+
- `fill(value, start, end)` - Fill with a specific value
939
+
940
+
**Note:** TypedArrays provide memory-efficient binary data handling and are essential for performance-critical applications like game engines, audio processing, and graphics programming. The C++ implementation uses template specialization to ensure type safety while maintaining JavaScript semantics.
941
+
834
942
### 🔧 Implementation Details
835
943
836
944
- **Type System**:
@@ -856,11 +964,18 @@ T applyDefaults(T defaults, js::object overrides) {
856
964
- Enhanced `IRTemplateParameter` interface with `isConst` flag for const type parameter tracking
857
965
- Added NoInfer utility type support in SimpleTypeChecker for type inference control
858
966
- NoInfer<T> types extract inner type T during compilation for C++ template compatibility
967
+
- Added comprehensive TypedArray type recognition for all 11 JavaScript TypedArray types
968
+
- TypedArray types mapped to specific C++ template classes (Int8Array → js::Int8Array, etc.)
859
969
- **Code Generation**:
860
970
- Fixed Object identifier mapping (was incorrectly dual-mapped to both js::Object and js::object)
861
971
- Enhanced template parameter generation to include `/* const */` comments for const type parameters
862
972
- **Runtime Library**:
863
973
- Added `js::Object` namespace with static utility methods
974
+
- Added comprehensive TypedArray base class template with inheritance from array<T>
975
+
- Implemented all 11 TypedArray types (Int8Array through BigUint64Array)
0 commit comments