Use 'super' in Uint8ClampedArray#__set

This commit is contained in:
dcodeIO 2018-04-24 00:42:17 +02:00
parent ddde13a648
commit 8465776a1d
5 changed files with 77 additions and 70 deletions

2
dist/asc.js vendored

File diff suppressed because one or more lines are too long

2
dist/asc.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -9,7 +9,7 @@ import {
export class Int8Array extends TypedArray<i8> { export class Int8Array extends TypedArray<i8> {
static readonly BYTES_PER_ELEMENT: usize = sizeof<i8>(); static readonly BYTES_PER_ELEMENT: usize = sizeof<i8>();
subarray(begin: i32 = 0, end: i32 = this.length): Int8Array { subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Int8Array {
return changetype<Int8Array>(super.subarray(begin, end)); return changetype<Int8Array>(super.subarray(begin, end));
} }
} }
@ -17,7 +17,7 @@ export class Int8Array extends TypedArray<i8> {
export class Uint8Array extends TypedArray<u8> { export class Uint8Array extends TypedArray<u8> {
static readonly BYTES_PER_ELEMENT: usize = sizeof<u8>(); static readonly BYTES_PER_ELEMENT: usize = sizeof<u8>();
subarray(begin: i32 = 0, end: i32 = this.length): Uint8Array { subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Uint8Array {
return changetype<Uint8Array>(super.subarray(begin, end)); return changetype<Uint8Array>(super.subarray(begin, end));
} }
} }
@ -27,14 +27,10 @@ export class Uint8ClampedArray extends TypedArray<u8> {
@operator("[]=") @operator("[]=")
protected __set(index: i32, value: i32): void { protected __set(index: i32, value: i32): void {
var byteOffset = this.byteOffset; super.__set(index, <u8>max(0, min(0xFF, value)));
var elementLength = (this.byteLength - byteOffset) >>> alignof<u8>();
if (<u32>index >= <u32>elementLength) throw new Error("Index out of bounds");
var clampedValue = <u8>max(0, min(0xFF, value));
storeUnsafeWithOffset<u8>(this.buffer, index, clampedValue, byteOffset);
} }
subarray(begin: i32 = 0, end: i32 = this.length): Uint8ClampedArray { subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Uint8ClampedArray {
return changetype<Uint8ClampedArray>(super.subarray(begin, end)); return changetype<Uint8ClampedArray>(super.subarray(begin, end));
} }
} }
@ -42,7 +38,7 @@ export class Uint8ClampedArray extends TypedArray<u8> {
export class Int16Array extends TypedArray<i16> { export class Int16Array extends TypedArray<i16> {
static readonly BYTES_PER_ELEMENT: usize = sizeof<i16>(); static readonly BYTES_PER_ELEMENT: usize = sizeof<i16>();
subarray(begin: i32 = 0, end: i32 = this.length): Int16Array { subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Int16Array {
return changetype<Int16Array>(super.subarray(begin, end)); return changetype<Int16Array>(super.subarray(begin, end));
} }
} }
@ -50,7 +46,7 @@ export class Int16Array extends TypedArray<i16> {
export class Uint16Array extends TypedArray<u16> { export class Uint16Array extends TypedArray<u16> {
static readonly BYTES_PER_ELEMENT: usize = sizeof<u16>(); static readonly BYTES_PER_ELEMENT: usize = sizeof<u16>();
subarray(begin: i32 = 0, end: i32 = this.length): Uint16Array { subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Uint16Array {
return changetype<Uint16Array>(super.subarray(begin, end)); return changetype<Uint16Array>(super.subarray(begin, end));
} }
} }
@ -58,7 +54,7 @@ export class Uint16Array extends TypedArray<u16> {
export class Int32Array extends TypedArray<i32> { export class Int32Array extends TypedArray<i32> {
static readonly BYTES_PER_ELEMENT: usize = sizeof<i32>(); static readonly BYTES_PER_ELEMENT: usize = sizeof<i32>();
subarray(begin: i32 = 0, end: i32 = this.length): Int32Array { subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Int32Array {
return changetype<Int32Array>(super.subarray(begin, end)); return changetype<Int32Array>(super.subarray(begin, end));
} }
} }
@ -66,7 +62,7 @@ export class Int32Array extends TypedArray<i32> {
export class Uint32Array extends TypedArray<u32> { export class Uint32Array extends TypedArray<u32> {
static readonly BYTES_PER_ELEMENT: usize = sizeof<u32>(); static readonly BYTES_PER_ELEMENT: usize = sizeof<u32>();
subarray(begin: i32 = 0, end: i32 = this.length): Uint32Array { subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Uint32Array {
return changetype<Uint32Array>(super.subarray(begin, end)); return changetype<Uint32Array>(super.subarray(begin, end));
} }
} }
@ -74,7 +70,7 @@ export class Uint32Array extends TypedArray<u32> {
export class Int64Array extends TypedArray<i64> { export class Int64Array extends TypedArray<i64> {
static readonly BYTES_PER_ELEMENT: usize = sizeof<i64>(); static readonly BYTES_PER_ELEMENT: usize = sizeof<i64>();
subarray(begin: i32 = 0, end: i32 = this.length): Int64Array { subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Int64Array {
return changetype<Int64Array>(super.subarray(begin, end)); return changetype<Int64Array>(super.subarray(begin, end));
} }
} }
@ -82,7 +78,7 @@ export class Int64Array extends TypedArray<i64> {
export class Uint64Array extends TypedArray<u64> { export class Uint64Array extends TypedArray<u64> {
static readonly BYTES_PER_ELEMENT: usize = sizeof<u64>(); static readonly BYTES_PER_ELEMENT: usize = sizeof<u64>();
subarray(begin: i32 = 0, end: i32 = this.length): Uint64Array { subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Uint64Array {
return changetype<Uint64Array>(super.subarray(begin, end)); return changetype<Uint64Array>(super.subarray(begin, end));
} }
} }
@ -90,7 +86,7 @@ export class Uint64Array extends TypedArray<u64> {
export class Float32Array extends TypedArray<f32> { export class Float32Array extends TypedArray<f32> {
static readonly BYTES_PER_ELEMENT: usize = sizeof<f32>(); static readonly BYTES_PER_ELEMENT: usize = sizeof<f32>();
subarray(begin: i32 = 0, end: i32 = this.length): Float32Array { subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Float32Array {
return changetype<Float32Array>(super.subarray(begin, end)); return changetype<Float32Array>(super.subarray(begin, end));
} }
} }
@ -98,7 +94,7 @@ export class Float32Array extends TypedArray<f32> {
export class Float64Array extends TypedArray<f64> { export class Float64Array extends TypedArray<f64> {
static readonly BYTES_PER_ELEMENT: usize = sizeof<f64>(); static readonly BYTES_PER_ELEMENT: usize = sizeof<f64>();
subarray(begin: i32 = 0, end: i32 = this.length): Float64Array { subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Float64Array {
return changetype<Float64Array>(super.subarray(begin, end)); return changetype<Float64Array>(super.subarray(begin, end));
} }
} }

View File

@ -11,12 +11,11 @@
(global $~lib/allocator/arena/offset (mut i32) (i32.const 0)) (global $~lib/allocator/arena/offset (mut i32) (i32.const 0))
(global $std/typedarray/arr (mut i32) (i32.const 0)) (global $std/typedarray/arr (mut i32) (i32.const 0))
(global $std/typedarray/clampedArr (mut i32) (i32.const 0)) (global $std/typedarray/clampedArr (mut i32) (i32.const 0))
(global $HEAP_BASE i32 (i32.const 204)) (global $HEAP_BASE i32 (i32.const 164))
(memory $0 1) (memory $0 1)
(data (i32.const 4) "\11\00\00\00s\00t\00d\00/\00t\00y\00p\00e\00d\00a\00r\00r\00a\00y\00.\00t\00s") (data (i32.const 4) "\11\00\00\00s\00t\00d\00/\00t\00y\00p\00e\00d\00a\00r\00r\00a\00y\00.\00t\00s")
(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") (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")
(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") (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")
(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")
(export "memory" (memory $0)) (export "memory" (memory $0))
(start $start) (start $start)
(func $~lib/internal/arraybuffer/computeSize (; 1 ;) (type $ii) (param $0 i32) (result i32) (func $~lib/internal/arraybuffer/computeSize (; 1 ;) (type $ii) (param $0 i32) (result i32)
@ -1628,7 +1627,7 @@
) )
(get_local $2) (get_local $2)
) )
(func $~lib/typedarray/Uint8ClampedArray#__set (; 17 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (func $~lib/internal/typedarray/TypedArray<u8>#__set (; 17 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(local $3 i32) (local $3 i32)
(if (if
(i32.ge_u (i32.ge_u
@ -1647,8 +1646,8 @@
(block (block
(call $abort (call $abort
(i32.const 0) (i32.const 0)
(i32.const 164) (i32.const 44)
(i32.const 32) (i32.const 47)
(i32.const 42) (i32.const 42)
) )
(unreachable) (unreachable)
@ -1664,20 +1663,30 @@
) )
(get_local $1) (get_local $1)
) )
(i32.trunc_u/f64 (get_local $2)
(f64.max )
(f64.const 0) )
(f64.min (func $~lib/typedarray/Uint8ClampedArray#__set (; 18 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(f64.const 255) (call $~lib/internal/typedarray/TypedArray<u8>#__set
(f64.convert_s/i32 (get_local $0)
(get_local $2) (get_local $1)
(i32.and
(i32.trunc_u/f64
(f64.max
(f64.const 0)
(f64.min
(f64.const 255)
(f64.convert_s/i32
(get_local $2)
)
) )
) )
) )
(i32.const 255)
) )
) )
) )
(func $~lib/internal/typedarray/TypedArray<u8>#__get (; 18 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (func $~lib/internal/typedarray/TypedArray<u8>#__get (; 19 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(local $2 i32) (local $2 i32)
(if (if
(i32.ge_u (i32.ge_u
@ -1715,7 +1724,7 @@
) )
) )
) )
(func $start (; 19 ;) (type $v) (func $start (; 20 ;) (type $v)
(set_global $~lib/allocator/arena/startOffset (set_global $~lib/allocator/arena/startOffset
(i32.and (i32.and
(i32.add (i32.add

View File

@ -19,12 +19,11 @@
(global $std/typedarray/arr (mut i32) (i32.const 0)) (global $std/typedarray/arr (mut i32) (i32.const 0))
(global $std/typedarray/clampedArr (mut i32) (i32.const 0)) (global $std/typedarray/clampedArr (mut i32) (i32.const 0))
(global $std/typedarray/MAX_F64LENGTH i32 (i32.const 134217727)) (global $std/typedarray/MAX_F64LENGTH i32 (i32.const 134217727))
(global $HEAP_BASE i32 (i32.const 204)) (global $HEAP_BASE i32 (i32.const 164))
(memory $0 1) (memory $0 1)
(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") (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")
(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") (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")
(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") (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")
(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")
(export "memory" (memory $0)) (export "memory" (memory $0))
(start $start) (start $start)
(func $~lib/internal/arraybuffer/computeSize (; 1 ;) (type $ii) (param $0 i32) (result i32) (func $~lib/internal/arraybuffer/computeSize (; 1 ;) (type $ii) (param $0 i32) (result i32)
@ -2522,14 +2521,13 @@
) )
) )
) )
(func $~lib/typedarray/Uint8ClampedArray#__set (; 29 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (func $~lib/internal/typedarray/TypedArray<u8>#__set (; 29 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(local $3 i32) (local $3 i32)
(local $4 i32) (local $4 i32)
(local $5 i32) (local $5 i32)
(local $6 i32) (local $6 i32)
(local $7 i32) (local $7 i32)
(local $8 i32) (local $8 i32)
(local $9 i32)
(set_local $3 (set_local $3
(i32.load offset=4 (i32.load offset=4
(get_local $0) (get_local $0)
@ -2554,14 +2552,47 @@
(block (block
(call $abort (call $abort
(i32.const 0) (i32.const 0)
(i32.const 164) (i32.const 44)
(i32.const 32) (i32.const 47)
(i32.const 42) (i32.const 42)
) )
(unreachable) (unreachable)
) )
) )
(set_local $5 (block $~lib/internal/arraybuffer/storeUnsafeWithOffset<u8>|inlined.0
(set_local $5
(i32.load
(get_local $0)
)
)
(set_local $6
(get_local $1)
)
(set_local $7
(get_local $2)
)
(set_local $8
(get_local $3)
)
(i32.store8 offset=8
(i32.add
(i32.add
(get_local $5)
(get_local $8)
)
(i32.shl
(get_local $6)
(i32.const 0)
)
)
(get_local $7)
)
)
)
(func $~lib/typedarray/Uint8ClampedArray#__set (; 30 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(call $~lib/internal/typedarray/TypedArray<u8>#__set
(get_local $0)
(get_local $1)
(i32.and (i32.and
(i32.trunc_u/f64 (i32.trunc_u/f64
(f64.max (f64.max
@ -2577,37 +2608,8 @@
(i32.const 255) (i32.const 255)
) )
) )
(block $~lib/internal/arraybuffer/storeUnsafeWithOffset<u8>|inlined.0
(set_local $6
(i32.load
(get_local $0)
)
)
(set_local $7
(get_local $1)
)
(set_local $8
(get_local $5)
)
(set_local $9
(get_local $3)
)
(i32.store8 offset=8
(i32.add
(i32.add
(get_local $6)
(get_local $9)
)
(i32.shl
(get_local $7)
(i32.const 0)
)
)
(get_local $8)
)
)
) )
(func $~lib/internal/typedarray/TypedArray<u8>#__get (; 30 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (func $~lib/internal/typedarray/TypedArray<u8>#__get (; 31 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(local $2 i32) (local $2 i32)
(local $3 i32) (local $3 i32)
(local $4 i32) (local $4 i32)
@ -2674,7 +2676,7 @@
) )
) )
) )
(func $start (; 31 ;) (type $v) (func $start (; 32 ;) (type $v)
(if (if
(i32.eqz (i32.eqz
(i32.eq (i32.eq