Skip to content

Commit 8465776

Browse files
committed
Use 'super' in Uint8ClampedArray#__set
1 parent ddde13a commit 8465776

File tree

5 files changed

+72
-65
lines changed

5 files changed

+72
-65
lines changed

dist/asc.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/asc.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

std/assembly/typedarray.ts

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ import {
99
export class Int8Array extends TypedArray<i8> {
1010
static readonly BYTES_PER_ELEMENT: usize = sizeof<i8>();
1111

12-
subarray(begin: i32 = 0, end: i32 = this.length): Int8Array {
12+
subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Int8Array {
1313
return changetype<Int8Array>(super.subarray(begin, end));
1414
}
1515
}
1616

1717
export class Uint8Array extends TypedArray<u8> {
1818
static readonly BYTES_PER_ELEMENT: usize = sizeof<u8>();
1919

20-
subarray(begin: i32 = 0, end: i32 = this.length): Uint8Array {
20+
subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Uint8Array {
2121
return changetype<Uint8Array>(super.subarray(begin, end));
2222
}
2323
}
@@ -27,78 +27,74 @@ export class Uint8ClampedArray extends TypedArray<u8> {
2727

2828
@operator("[]=")
2929
protected __set(index: i32, value: i32): void {
30-
var byteOffset = this.byteOffset;
31-
var elementLength = (this.byteLength - byteOffset) >>> alignof<u8>();
32-
if (<u32>index >= <u32>elementLength) throw new Error("Index out of bounds");
33-
var clampedValue = <u8>max(0, min(0xFF, value));
34-
storeUnsafeWithOffset<u8>(this.buffer, index, clampedValue, byteOffset);
30+
super.__set(index, <u8>max(0, min(0xFF, value)));
3531
}
3632

37-
subarray(begin: i32 = 0, end: i32 = this.length): Uint8ClampedArray {
33+
subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Uint8ClampedArray {
3834
return changetype<Uint8ClampedArray>(super.subarray(begin, end));
3935
}
4036
}
4137

4238
export class Int16Array extends TypedArray<i16> {
4339
static readonly BYTES_PER_ELEMENT: usize = sizeof<i16>();
4440

45-
subarray(begin: i32 = 0, end: i32 = this.length): Int16Array {
41+
subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Int16Array {
4642
return changetype<Int16Array>(super.subarray(begin, end));
4743
}
4844
}
4945

5046
export class Uint16Array extends TypedArray<u16> {
5147
static readonly BYTES_PER_ELEMENT: usize = sizeof<u16>();
5248

53-
subarray(begin: i32 = 0, end: i32 = this.length): Uint16Array {
49+
subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Uint16Array {
5450
return changetype<Uint16Array>(super.subarray(begin, end));
5551
}
5652
}
5753

5854
export class Int32Array extends TypedArray<i32> {
5955
static readonly BYTES_PER_ELEMENT: usize = sizeof<i32>();
6056

61-
subarray(begin: i32 = 0, end: i32 = this.length): Int32Array {
57+
subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Int32Array {
6258
return changetype<Int32Array>(super.subarray(begin, end));
6359
}
6460
}
6561

6662
export class Uint32Array extends TypedArray<u32> {
6763
static readonly BYTES_PER_ELEMENT: usize = sizeof<u32>();
6864

69-
subarray(begin: i32 = 0, end: i32 = this.length): Uint32Array {
65+
subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Uint32Array {
7066
return changetype<Uint32Array>(super.subarray(begin, end));
7167
}
7268
}
7369

7470
export class Int64Array extends TypedArray<i64> {
7571
static readonly BYTES_PER_ELEMENT: usize = sizeof<i64>();
7672

77-
subarray(begin: i32 = 0, end: i32 = this.length): Int64Array {
73+
subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Int64Array {
7874
return changetype<Int64Array>(super.subarray(begin, end));
7975
}
8076
}
8177

8278
export class Uint64Array extends TypedArray<u64> {
8379
static readonly BYTES_PER_ELEMENT: usize = sizeof<u64>();
8480

85-
subarray(begin: i32 = 0, end: i32 = this.length): Uint64Array {
81+
subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Uint64Array {
8682
return changetype<Uint64Array>(super.subarray(begin, end));
8783
}
8884
}
8985

9086
export class Float32Array extends TypedArray<f32> {
9187
static readonly BYTES_PER_ELEMENT: usize = sizeof<f32>();
9288

93-
subarray(begin: i32 = 0, end: i32 = this.length): Float32Array {
89+
subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Float32Array {
9490
return changetype<Float32Array>(super.subarray(begin, end));
9591
}
9692
}
9793

9894
export class Float64Array extends TypedArray<f64> {
9995
static readonly BYTES_PER_ELEMENT: usize = sizeof<f64>();
10096

101-
subarray(begin: i32 = 0, end: i32 = this.length): Float64Array {
97+
subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Float64Array {
10298
return changetype<Float64Array>(super.subarray(begin, end));
10399
}
104100
}

tests/compiler/std/typedarray.optimized.wat

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@
1111
(global $~lib/allocator/arena/offset (mut i32) (i32.const 0))
1212
(global $std/typedarray/arr (mut i32) (i32.const 0))
1313
(global $std/typedarray/clampedArr (mut i32) (i32.const 0))
14-
(global $HEAP_BASE i32 (i32.const 204))
14+
(global $HEAP_BASE i32 (i32.const 164))
1515
(memory $0 1)
1616
(data (i32.const 4) "\11\00\00\00s\00t\00d\00/\00t\00y\00p\00e\00d\00a\00r\00r\00a\00y\00.\00t\00s")
1717
(data (i32.const 44) "\1b\00\00\00~\00l\00i\00b\00/\00i\00n\00t\00e\00r\00n\00a\00l\00/\00t\00y\00p\00e\00d\00a\00r\00r\00a\00y\00.\00t\00s")
1818
(data (i32.const 104) "\1c\00\00\00~\00l\00i\00b\00/\00i\00n\00t\00e\00r\00n\00a\00l\00/\00a\00r\00r\00a\00y\00b\00u\00f\00f\00e\00r\00.\00t\00s")
19-
(data (i32.const 164) "\12\00\00\00~\00l\00i\00b\00/\00t\00y\00p\00e\00d\00a\00r\00r\00a\00y\00.\00t\00s")
2019
(export "memory" (memory $0))
2120
(start $start)
2221
(func $~lib/internal/arraybuffer/computeSize (; 1 ;) (type $ii) (param $0 i32) (result i32)
@@ -1628,7 +1627,7 @@
16281627
)
16291628
(get_local $2)
16301629
)
1631-
(func $~lib/typedarray/Uint8ClampedArray#__set (; 17 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
1630+
(func $~lib/internal/typedarray/TypedArray<u8>#__set (; 17 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
16321631
(local $3 i32)
16331632
(if
16341633
(i32.ge_u
@@ -1647,8 +1646,8 @@
16471646
(block
16481647
(call $abort
16491648
(i32.const 0)
1650-
(i32.const 164)
1651-
(i32.const 32)
1649+
(i32.const 44)
1650+
(i32.const 47)
16521651
(i32.const 42)
16531652
)
16541653
(unreachable)
@@ -1664,20 +1663,30 @@
16641663
)
16651664
(get_local $1)
16661665
)
1667-
(i32.trunc_u/f64
1668-
(f64.max
1669-
(f64.const 0)
1670-
(f64.min
1671-
(f64.const 255)
1672-
(f64.convert_s/i32
1673-
(get_local $2)
1666+
(get_local $2)
1667+
)
1668+
)
1669+
(func $~lib/typedarray/Uint8ClampedArray#__set (; 18 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
1670+
(call $~lib/internal/typedarray/TypedArray<u8>#__set
1671+
(get_local $0)
1672+
(get_local $1)
1673+
(i32.and
1674+
(i32.trunc_u/f64
1675+
(f64.max
1676+
(f64.const 0)
1677+
(f64.min
1678+
(f64.const 255)
1679+
(f64.convert_s/i32
1680+
(get_local $2)
1681+
)
16741682
)
16751683
)
16761684
)
1685+
(i32.const 255)
16771686
)
16781687
)
16791688
)
1680-
(func $~lib/internal/typedarray/TypedArray<u8>#__get (; 18 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
1689+
(func $~lib/internal/typedarray/TypedArray<u8>#__get (; 19 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
16811690
(local $2 i32)
16821691
(if
16831692
(i32.ge_u
@@ -1715,7 +1724,7 @@
17151724
)
17161725
)
17171726
)
1718-
(func $start (; 19 ;) (type $v)
1727+
(func $start (; 20 ;) (type $v)
17191728
(set_global $~lib/allocator/arena/startOffset
17201729
(i32.and
17211730
(i32.add

tests/compiler/std/typedarray.untouched.wat

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@
1919
(global $std/typedarray/arr (mut i32) (i32.const 0))
2020
(global $std/typedarray/clampedArr (mut i32) (i32.const 0))
2121
(global $std/typedarray/MAX_F64LENGTH i32 (i32.const 134217727))
22-
(global $HEAP_BASE i32 (i32.const 204))
22+
(global $HEAP_BASE i32 (i32.const 164))
2323
(memory $0 1)
2424
(data (i32.const 4) "\11\00\00\00s\00t\00d\00/\00t\00y\00p\00e\00d\00a\00r\00r\00a\00y\00.\00t\00s\00")
2525
(data (i32.const 44) "\1b\00\00\00~\00l\00i\00b\00/\00i\00n\00t\00e\00r\00n\00a\00l\00/\00t\00y\00p\00e\00d\00a\00r\00r\00a\00y\00.\00t\00s\00")
2626
(data (i32.const 104) "\1c\00\00\00~\00l\00i\00b\00/\00i\00n\00t\00e\00r\00n\00a\00l\00/\00a\00r\00r\00a\00y\00b\00u\00f\00f\00e\00r\00.\00t\00s\00")
27-
(data (i32.const 164) "\12\00\00\00~\00l\00i\00b\00/\00t\00y\00p\00e\00d\00a\00r\00r\00a\00y\00.\00t\00s\00")
2827
(export "memory" (memory $0))
2928
(start $start)
3029
(func $~lib/internal/arraybuffer/computeSize (; 1 ;) (type $ii) (param $0 i32) (result i32)
@@ -2522,14 +2521,13 @@
25222521
)
25232522
)
25242523
)
2525-
(func $~lib/typedarray/Uint8ClampedArray#__set (; 29 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
2524+
(func $~lib/internal/typedarray/TypedArray<u8>#__set (; 29 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
25262525
(local $3 i32)
25272526
(local $4 i32)
25282527
(local $5 i32)
25292528
(local $6 i32)
25302529
(local $7 i32)
25312530
(local $8 i32)
2532-
(local $9 i32)
25332531
(set_local $3
25342532
(i32.load offset=4
25352533
(get_local $0)
@@ -2554,60 +2552,64 @@
25542552
(block
25552553
(call $abort
25562554
(i32.const 0)
2557-
(i32.const 164)
2558-
(i32.const 32)
2555+
(i32.const 44)
2556+
(i32.const 47)
25592557
(i32.const 42)
25602558
)
25612559
(unreachable)
25622560
)
25632561
)
2564-
(set_local $5
2565-
(i32.and
2566-
(i32.trunc_u/f64
2567-
(f64.max
2568-
(f64.const 0)
2569-
(f64.min
2570-
(f64.const 255)
2571-
(f64.convert_s/i32
2572-
(get_local $2)
2573-
)
2574-
)
2575-
)
2576-
)
2577-
(i32.const 255)
2578-
)
2579-
)
25802562
(block $~lib/internal/arraybuffer/storeUnsafeWithOffset<u8>|inlined.0
2581-
(set_local $6
2563+
(set_local $5
25822564
(i32.load
25832565
(get_local $0)
25842566
)
25852567
)
2586-
(set_local $7
2568+
(set_local $6
25872569
(get_local $1)
25882570
)
2589-
(set_local $8
2590-
(get_local $5)
2571+
(set_local $7
2572+
(get_local $2)
25912573
)
2592-
(set_local $9
2574+
(set_local $8
25932575
(get_local $3)
25942576
)
25952577
(i32.store8 offset=8
25962578
(i32.add
25972579
(i32.add
2598-
(get_local $6)
2599-
(get_local $9)
2580+
(get_local $5)
2581+
(get_local $8)
26002582
)
26012583
(i32.shl
2602-
(get_local $7)
2584+
(get_local $6)
26032585
(i32.const 0)
26042586
)
26052587
)
2606-
(get_local $8)
2588+
(get_local $7)
2589+
)
2590+
)
2591+
)
2592+
(func $~lib/typedarray/Uint8ClampedArray#__set (; 30 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
2593+
(call $~lib/internal/typedarray/TypedArray<u8>#__set
2594+
(get_local $0)
2595+
(get_local $1)
2596+
(i32.and
2597+
(i32.trunc_u/f64
2598+
(f64.max
2599+
(f64.const 0)
2600+
(f64.min
2601+
(f64.const 255)
2602+
(f64.convert_s/i32
2603+
(get_local $2)
2604+
)
2605+
)
2606+
)
2607+
)
2608+
(i32.const 255)
26072609
)
26082610
)
26092611
)
2610-
(func $~lib/internal/typedarray/TypedArray<u8>#__get (; 30 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
2612+
(func $~lib/internal/typedarray/TypedArray<u8>#__get (; 31 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
26112613
(local $2 i32)
26122614
(local $3 i32)
26132615
(local $4 i32)
@@ -2674,7 +2676,7 @@
26742676
)
26752677
)
26762678
)
2677-
(func $start (; 31 ;) (type $v)
2679+
(func $start (; 32 ;) (type $v)
26782680
(if
26792681
(i32.eqz
26802682
(i32.eq

0 commit comments

Comments
 (0)