From ddde13a6480669bae567d1e8143c88ad910b3ab3 Mon Sep 17 00:00:00 2001 From: Max Graey Date: Tue, 24 Apr 2018 01:33:21 +0300 Subject: [PATCH] Implement Uint8ClampedArray (#82) --- std/assembly/internal/typedarray.ts | 4 +- std/assembly/typedarray.ts | 21 + tests/compiler/std/typedarray.optimized.wat | 582 ++++++++++------ tests/compiler/std/typedarray.ts | 15 + tests/compiler/std/typedarray.untouched.wat | 693 ++++++++++++++------ 5 files changed, 942 insertions(+), 373 deletions(-) diff --git a/std/assembly/internal/typedarray.ts b/std/assembly/internal/typedarray.ts index 2123fed2..d6e8b5c1 100644 --- a/std/assembly/internal/typedarray.ts +++ b/std/assembly/internal/typedarray.ts @@ -33,7 +33,7 @@ export abstract class TypedArray implements ArrayBufferView { } @operator("[]") - private __get(index: i32): T { + protected __get(index: i32): T { var byteOffset = this.byteOffset; var elementLength = (this.byteLength - byteOffset) >>> alignof(); if (index >= elementLength) throw new Error("Index out of bounds"); @@ -41,7 +41,7 @@ export abstract class TypedArray implements ArrayBufferView { } @operator("[]=") - private __set(index: i32, value: T): void { + protected __set(index: i32, value: T): void { var byteOffset = this.byteOffset; var elementLength = (this.byteLength - byteOffset) >>> alignof(); if (index >= elementLength) throw new Error("Index out of bounds"); diff --git a/std/assembly/typedarray.ts b/std/assembly/typedarray.ts index f93ff414..3de019c7 100644 --- a/std/assembly/typedarray.ts +++ b/std/assembly/typedarray.ts @@ -2,6 +2,10 @@ import { TypedArray } from "./internal/typedarray"; +import { + storeUnsafeWithOffset +} from "./internal/arraybuffer"; + export class Int8Array extends TypedArray { static readonly BYTES_PER_ELEMENT: usize = sizeof(); @@ -18,6 +22,23 @@ export class Uint8Array extends TypedArray { } } +export class Uint8ClampedArray extends TypedArray { + static readonly BYTES_PER_ELEMENT: usize = sizeof(); + + @operator("[]=") + protected __set(index: i32, value: i32): void { + var byteOffset = this.byteOffset; + var elementLength = (this.byteLength - byteOffset) >>> alignof(); + if (index >= elementLength) throw new Error("Index out of bounds"); + var clampedValue = max(0, min(0xFF, value)); + storeUnsafeWithOffset(this.buffer, index, clampedValue, byteOffset); + } + + subarray(begin: i32 = 0, end: i32 = this.length): Uint8ClampedArray { + return changetype(super.subarray(begin, end)); + } +} + export class Int16Array extends TypedArray { static readonly BYTES_PER_ELEMENT: usize = sizeof(); diff --git a/tests/compiler/std/typedarray.optimized.wat b/tests/compiler/std/typedarray.optimized.wat index f75d8a87..95bc9cea 100644 --- a/tests/compiler/std/typedarray.optimized.wat +++ b/tests/compiler/std/typedarray.optimized.wat @@ -10,11 +10,13 @@ (global $~lib/allocator/arena/startOffset (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 $HEAP_BASE i32 (i32.const 164)) + (global $std/typedarray/clampedArr (mut i32) (i32.const 0)) + (global $HEAP_BASE i32 (i32.const 204)) (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 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 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)) (start $start) (func $~lib/internal/arraybuffer/computeSize (; 1 ;) (type $ii) (param $0 i32) (result i32) @@ -821,7 +823,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 17) + (i32.const 18) (i32.const 2) ) (unreachable) @@ -838,7 +840,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 18) + (i32.const 19) (i32.const 2) ) (unreachable) @@ -855,7 +857,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 19) + (i32.const 20) (i32.const 2) ) (unreachable) @@ -874,7 +876,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 22) + (i32.const 23) (i32.const 2) ) (unreachable) @@ -891,7 +893,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 23) + (i32.const 24) (i32.const 2) ) (unreachable) @@ -908,7 +910,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 24) + (i32.const 25) (i32.const 2) ) (unreachable) @@ -917,32 +919,12 @@ (if (i32.load offset=4 (tee_local $1 - (call $~lib/internal/typedarray/TypedArray#constructor + (call $~lib/internal/typedarray/TypedArray#constructor (i32.const 0) (get_local $0) ) ) ) - (block - (call $abort - (i32.const 0) - (i32.const 4) - (i32.const 27) - (i32.const 2) - ) - (unreachable) - ) - ) - (if - (i32.ne - (i32.load offset=8 - (get_local $1) - ) - (i32.shl - (get_local $0) - (i32.const 1) - ) - ) (block (call $abort (i32.const 0) @@ -955,7 +937,7 @@ ) (if (i32.ne - (call $~lib/internal/typedarray/TypedArray#get:length + (i32.load offset=8 (get_local $1) ) (get_local $0) @@ -970,6 +952,23 @@ (unreachable) ) ) + (if + (i32.ne + (call $~lib/internal/typedarray/TypedArray#get:length + (get_local $1) + ) + (get_local $0) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 30) + (i32.const 2) + ) + (unreachable) + ) + ) (if (i32.load offset=4 (tee_local $1 @@ -983,7 +982,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 32) + (i32.const 33) (i32.const 2) ) (unreachable) @@ -1003,7 +1002,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 33) + (i32.const 34) (i32.const 2) ) (unreachable) @@ -1020,7 +1019,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 34) + (i32.const 35) (i32.const 2) ) (unreachable) @@ -1029,32 +1028,12 @@ (if (i32.load offset=4 (tee_local $1 - (call $~lib/internal/typedarray/TypedArray#constructor + (call $~lib/internal/typedarray/TypedArray#constructor (i32.const 0) (get_local $0) ) ) ) - (block - (call $abort - (i32.const 0) - (i32.const 4) - (i32.const 37) - (i32.const 2) - ) - (unreachable) - ) - ) - (if - (i32.ne - (i32.load offset=8 - (get_local $1) - ) - (i32.shl - (get_local $0) - (i32.const 2) - ) - ) (block (call $abort (i32.const 0) @@ -1067,10 +1046,13 @@ ) (if (i32.ne - (call $~lib/internal/typedarray/TypedArray#get:length + (i32.load offset=8 (get_local $1) ) - (get_local $0) + (i32.shl + (get_local $0) + (i32.const 1) + ) ) (block (call $abort @@ -1083,32 +1065,29 @@ ) ) (if - (i32.load offset=4 - (tee_local $1 - (call $~lib/internal/typedarray/TypedArray#constructor - (i32.const 0) - (get_local $0) - ) + (i32.ne + (call $~lib/internal/typedarray/TypedArray#get:length + (get_local $1) ) + (get_local $0) ) (block (call $abort (i32.const 0) (i32.const 4) - (i32.const 42) + (i32.const 40) (i32.const 2) ) (unreachable) ) ) (if - (i32.ne - (i32.load offset=8 - (get_local $1) - ) - (i32.shl - (get_local $0) - (i32.const 2) + (i32.load offset=4 + (tee_local $1 + (call $~lib/internal/typedarray/TypedArray#constructor + (i32.const 0) + (get_local $0) + ) ) ) (block @@ -1123,10 +1102,13 @@ ) (if (i32.ne - (call $~lib/internal/typedarray/TypedArray#get:length + (i32.load offset=8 (get_local $1) ) - (get_local $0) + (i32.shl + (get_local $0) + (i32.const 2) + ) ) (block (call $abort @@ -1138,48 +1120,9 @@ (unreachable) ) ) - (if - (i32.load offset=4 - (tee_local $1 - (call $~lib/internal/typedarray/TypedArray#constructor - (i32.const 0) - (get_local $0) - ) - ) - ) - (block - (call $abort - (i32.const 0) - (i32.const 4) - (i32.const 47) - (i32.const 2) - ) - (unreachable) - ) - ) (if (i32.ne - (i32.load offset=8 - (get_local $1) - ) - (i32.shl - (get_local $0) - (i32.const 3) - ) - ) - (block - (call $abort - (i32.const 0) - (i32.const 4) - (i32.const 48) - (i32.const 2) - ) - (unreachable) - ) - ) - (if - (i32.ne - (call $~lib/internal/typedarray/TypedArray#get:length + (call $~lib/internal/typedarray/TypedArray#get:length (get_local $1) ) (get_local $0) @@ -1188,63 +1131,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 49) - (i32.const 2) - ) - (unreachable) - ) - ) - (if - (i32.load offset=4 - (tee_local $1 - (call $~lib/internal/typedarray/TypedArray#constructor - (i32.const 0) - (get_local $0) - ) - ) - ) - (block - (call $abort - (i32.const 0) - (i32.const 4) - (i32.const 52) - (i32.const 2) - ) - (unreachable) - ) - ) - (if - (i32.ne - (i32.load offset=8 - (get_local $1) - ) - (i32.shl - (get_local $0) - (i32.const 3) - ) - ) - (block - (call $abort - (i32.const 0) - (i32.const 4) - (i32.const 53) - (i32.const 2) - ) - (unreachable) - ) - ) - (if - (i32.ne - (call $~lib/internal/typedarray/TypedArray#get:length - (get_local $1) - ) - (get_local $0) - ) - (block - (call $abort - (i32.const 0) - (i32.const 4) - (i32.const 54) + (i32.const 45) (i32.const 2) ) (unreachable) @@ -1263,7 +1150,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 57) + (i32.const 48) (i32.const 2) ) (unreachable) @@ -1283,7 +1170,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 58) + (i32.const 49) (i32.const 2) ) (unreachable) @@ -1300,7 +1187,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 59) + (i32.const 50) (i32.const 2) ) (unreachable) @@ -1319,7 +1206,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 62) + (i32.const 53) (i32.const 2) ) (unreachable) @@ -1339,7 +1226,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 63) + (i32.const 54) (i32.const 2) ) (unreachable) @@ -1352,6 +1239,101 @@ ) (get_local $0) ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 55) + (i32.const 2) + ) + (unreachable) + ) + ) + (if + (i32.load offset=4 + (tee_local $1 + (call $~lib/internal/typedarray/TypedArray#constructor + (i32.const 0) + (get_local $0) + ) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 58) + (i32.const 2) + ) + (unreachable) + ) + ) + (if + (i32.ne + (i32.load offset=8 + (get_local $1) + ) + (i32.shl + (get_local $0) + (i32.const 3) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 59) + (i32.const 2) + ) + (unreachable) + ) + ) + (if + (i32.ne + (call $~lib/internal/typedarray/TypedArray#get:length + (get_local $1) + ) + (get_local $0) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 60) + (i32.const 2) + ) + (unreachable) + ) + ) + (if + (i32.load offset=4 + (tee_local $1 + (call $~lib/internal/typedarray/TypedArray#constructor + (i32.const 0) + (get_local $0) + ) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 63) + (i32.const 2) + ) + (unreachable) + ) + ) + (if + (i32.ne + (i32.load offset=8 + (get_local $1) + ) + (i32.shl + (get_local $0) + (i32.const 2) + ) + ) (block (call $abort (i32.const 0) @@ -1362,6 +1344,79 @@ (unreachable) ) ) + (if + (i32.ne + (call $~lib/internal/typedarray/TypedArray#get:length + (get_local $1) + ) + (get_local $0) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 65) + (i32.const 2) + ) + (unreachable) + ) + ) + (if + (i32.load offset=4 + (tee_local $1 + (call $~lib/internal/typedarray/TypedArray#constructor + (i32.const 0) + (get_local $0) + ) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 68) + (i32.const 2) + ) + (unreachable) + ) + ) + (if + (i32.ne + (i32.load offset=8 + (get_local $1) + ) + (i32.shl + (get_local $0) + (i32.const 3) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 69) + (i32.const 2) + ) + (unreachable) + ) + ) + (if + (i32.ne + (call $~lib/internal/typedarray/TypedArray#get:length + (get_local $1) + ) + (get_local $0) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 70) + (i32.const 2) + ) + (unreachable) + ) + ) ) (func $~lib/internal/typedarray/TypedArray#__set (; 14 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) @@ -1573,7 +1628,94 @@ ) (get_local $2) ) - (func $start (; 17 ;) (type $v) + (func $~lib/typedarray/Uint8ClampedArray#__set (; 17 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (local $3 i32) + (if + (i32.ge_u + (get_local $1) + (i32.sub + (i32.load offset=8 + (get_local $0) + ) + (tee_local $3 + (i32.load offset=4 + (get_local $0) + ) + ) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 164) + (i32.const 32) + (i32.const 42) + ) + (unreachable) + ) + ) + (i32.store8 offset=8 + (i32.add + (i32.add + (i32.load + (get_local $0) + ) + (get_local $3) + ) + (get_local $1) + ) + (i32.trunc_u/f64 + (f64.max + (f64.const 0) + (f64.min + (f64.const 255) + (f64.convert_s/i32 + (get_local $2) + ) + ) + ) + ) + ) + ) + (func $~lib/internal/typedarray/TypedArray#__get (; 18 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + (if + (i32.ge_u + (get_local $1) + (i32.sub + (i32.load offset=8 + (get_local $0) + ) + (tee_local $2 + (i32.load offset=4 + (get_local $0) + ) + ) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 44) + (i32.const 39) + (i32.const 42) + ) + (unreachable) + ) + ) + (i32.load8_u offset=8 + (i32.add + (i32.add + (i32.load + (get_local $0) + ) + (get_local $2) + ) + (get_local $1) + ) + ) + ) + (func $start (; 19 ;) (type $v) (set_global $~lib/allocator/arena/startOffset (i32.and (i32.add @@ -1624,7 +1766,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 74) + (i32.const 80) (i32.const 0) ) (unreachable) @@ -1638,7 +1780,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 75) + (i32.const 81) (i32.const 0) ) (unreachable) @@ -1655,7 +1797,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 76) + (i32.const 82) (i32.const 0) ) (unreachable) @@ -1673,7 +1815,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 77) + (i32.const 83) (i32.const 0) ) (unreachable) @@ -1691,7 +1833,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 78) + (i32.const 84) (i32.const 0) ) (unreachable) @@ -1709,7 +1851,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 79) + (i32.const 85) (i32.const 0) ) (unreachable) @@ -1733,7 +1875,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 82) + (i32.const 88) (i32.const 0) ) (unreachable) @@ -1750,7 +1892,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 83) + (i32.const 89) (i32.const 0) ) (unreachable) @@ -1767,7 +1909,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 84) + (i32.const 90) (i32.const 0) ) (unreachable) @@ -1785,7 +1927,79 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 85) + (i32.const 91) + (i32.const 0) + ) + (unreachable) + ) + ) + (set_global $std/typedarray/clampedArr + (call $~lib/internal/typedarray/TypedArray#constructor + (i32.const 0) + (i32.const 3) + ) + ) + (call $~lib/typedarray/Uint8ClampedArray#__set + (get_global $std/typedarray/clampedArr) + (i32.const 0) + (i32.const -32) + ) + (call $~lib/typedarray/Uint8ClampedArray#__set + (get_global $std/typedarray/clampedArr) + (i32.const 1) + (i32.const 2) + ) + (call $~lib/typedarray/Uint8ClampedArray#__set + (get_global $std/typedarray/clampedArr) + (i32.const 2) + (i32.const 256) + ) + (if + (call $~lib/internal/typedarray/TypedArray#__get + (get_global $std/typedarray/clampedArr) + (i32.const 0) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 98) + (i32.const 0) + ) + (unreachable) + ) + ) + (if + (i32.ne + (call $~lib/internal/typedarray/TypedArray#__get + (get_global $std/typedarray/clampedArr) + (i32.const 1) + ) + (i32.const 2) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 99) + (i32.const 0) + ) + (unreachable) + ) + ) + (if + (i32.ne + (call $~lib/internal/typedarray/TypedArray#__get + (get_global $std/typedarray/clampedArr) + (i32.const 2) + ) + (i32.const 255) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 100) (i32.const 0) ) (unreachable) diff --git a/tests/compiler/std/typedarray.ts b/tests/compiler/std/typedarray.ts index b7b87a4e..e0fb62ff 100644 --- a/tests/compiler/std/typedarray.ts +++ b/tests/compiler/std/typedarray.ts @@ -1,5 +1,6 @@ assert(Int8Array.BYTES_PER_ELEMENT == 1); assert(Uint8Array.BYTES_PER_ELEMENT == 1); +assert(Uint8ClampedArray.BYTES_PER_ELEMENT == 1); assert(Int16Array.BYTES_PER_ELEMENT == 2); assert(Uint16Array.BYTES_PER_ELEMENT == 2); assert(Int32Array.BYTES_PER_ELEMENT == 4); @@ -23,6 +24,11 @@ function testInstantiate(len: i32): void { assert(u8a.byteLength == len * Uint8Array.BYTES_PER_ELEMENT); assert(u8a.length == len); + var c8a = new Uint8ClampedArray(len); + assert(c8a.byteOffset == 0); + assert(c8a.byteLength == len * Uint8Array.BYTES_PER_ELEMENT); + assert(c8a.length == len); + var i16a = new Int16Array(len); assert(i16a.byteOffset == 0); assert(i16a.byteLength == len * Int16Array.BYTES_PER_ELEMENT); @@ -84,6 +90,15 @@ assert(arr.byteOffset == 1 * sizeof()); assert(arr.byteLength == 2 * sizeof()); assert(arr[0] == 2); +var clampedArr = new Uint8ClampedArray(3); +clampedArr[0] = -32; +clampedArr[1] = 2; +clampedArr[2] = 256; + +assert(clampedArr[0] == 0); +assert(clampedArr[1] == 2); +assert(clampedArr[2] == 255); + import { MAX_BLENGTH } from "internal/arraybuffer"; const MAX_F64LENGTH = MAX_BLENGTH >> alignof(); diff --git a/tests/compiler/std/typedarray.untouched.wat b/tests/compiler/std/typedarray.untouched.wat index 41671c66..76468f3e 100644 --- a/tests/compiler/std/typedarray.untouched.wat +++ b/tests/compiler/std/typedarray.untouched.wat @@ -17,12 +17,14 @@ (global $~lib/internal/arraybuffer/HEADER_SIZE i32 (i32.const 8)) (global $~lib/internal/arraybuffer/MAX_BLENGTH i32 (i32.const 1073741816)) (global $std/typedarray/arr (mut i32) (i32.const 0)) + (global $std/typedarray/clampedArr (mut i32) (i32.const 0)) (global $std/typedarray/MAX_F64LENGTH i32 (i32.const 134217727)) - (global $HEAP_BASE i32 (i32.const 164)) + (global $HEAP_BASE i32 (i32.const 204)) (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 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 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)) (start $start) (func $~lib/internal/arraybuffer/computeSize (; 1 ;) (type $ii) (param $0 i32) (result i32) @@ -1518,6 +1520,7 @@ (local $8 i32) (local $9 i32) (local $10 i32) + (local $11 i32) (set_local $1 (call $~lib/internal/typedarray/TypedArray#constructor (i32.const 0) @@ -1537,7 +1540,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 17) + (i32.const 18) (i32.const 2) ) (unreachable) @@ -1559,7 +1562,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 18) + (i32.const 19) (i32.const 2) ) (unreachable) @@ -1578,7 +1581,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 19) + (i32.const 20) (i32.const 2) ) (unreachable) @@ -1603,7 +1606,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 22) + (i32.const 23) (i32.const 2) ) (unreachable) @@ -1625,7 +1628,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 23) + (i32.const 24) (i32.const 2) ) (unreachable) @@ -1644,14 +1647,14 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 24) + (i32.const 25) (i32.const 2) ) (unreachable) ) ) (set_local $3 - (call $~lib/internal/typedarray/TypedArray#constructor + (call $~lib/internal/typedarray/TypedArray#constructor (i32.const 0) (get_local $0) ) @@ -1665,28 +1668,6 @@ (i32.const 0) ) ) - (block - (call $abort - (i32.const 0) - (i32.const 4) - (i32.const 27) - (i32.const 2) - ) - (unreachable) - ) - ) - (if - (i32.eqz - (i32.eq - (i32.load offset=8 - (get_local $3) - ) - (i32.mul - (get_local $0) - (i32.const 2) - ) - ) - ) (block (call $abort (i32.const 0) @@ -1700,10 +1681,13 @@ (if (i32.eqz (i32.eq - (call $~lib/internal/typedarray/TypedArray#get:length + (i32.load offset=8 (get_local $3) ) - (get_local $0) + (i32.mul + (get_local $0) + (i32.const 1) + ) ) ) (block @@ -1716,8 +1700,27 @@ (unreachable) ) ) + (if + (i32.eqz + (i32.eq + (call $~lib/internal/typedarray/TypedArray#get:length + (get_local $3) + ) + (get_local $0) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 30) + (i32.const 2) + ) + (unreachable) + ) + ) (set_local $4 - (call $~lib/internal/typedarray/TypedArray#constructor + (call $~lib/internal/typedarray/TypedArray#constructor (i32.const 0) (get_local $0) ) @@ -1735,7 +1738,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 32) + (i32.const 33) (i32.const 2) ) (unreachable) @@ -1757,7 +1760,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 33) + (i32.const 34) (i32.const 2) ) (unreachable) @@ -1766,7 +1769,7 @@ (if (i32.eqz (i32.eq - (call $~lib/internal/typedarray/TypedArray#get:length + (call $~lib/internal/typedarray/TypedArray#get:length (get_local $4) ) (get_local $0) @@ -1776,14 +1779,14 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 34) + (i32.const 35) (i32.const 2) ) (unreachable) ) ) (set_local $5 - (call $~lib/internal/typedarray/TypedArray#constructor + (call $~lib/internal/typedarray/TypedArray#constructor (i32.const 0) (get_local $0) ) @@ -1797,28 +1800,6 @@ (i32.const 0) ) ) - (block - (call $abort - (i32.const 0) - (i32.const 4) - (i32.const 37) - (i32.const 2) - ) - (unreachable) - ) - ) - (if - (i32.eqz - (i32.eq - (i32.load offset=8 - (get_local $5) - ) - (i32.mul - (get_local $0) - (i32.const 4) - ) - ) - ) (block (call $abort (i32.const 0) @@ -1832,10 +1813,13 @@ (if (i32.eqz (i32.eq - (call $~lib/internal/typedarray/TypedArray#get:length + (i32.load offset=8 (get_local $5) ) - (get_local $0) + (i32.mul + (get_local $0) + (i32.const 2) + ) ) ) (block @@ -1848,8 +1832,27 @@ (unreachable) ) ) + (if + (i32.eqz + (i32.eq + (call $~lib/internal/typedarray/TypedArray#get:length + (get_local $5) + ) + (get_local $0) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 40) + (i32.const 2) + ) + (unreachable) + ) + ) (set_local $6 - (call $~lib/internal/typedarray/TypedArray#constructor + (call $~lib/internal/typedarray/TypedArray#constructor (i32.const 0) (get_local $0) ) @@ -1863,28 +1866,6 @@ (i32.const 0) ) ) - (block - (call $abort - (i32.const 0) - (i32.const 4) - (i32.const 42) - (i32.const 2) - ) - (unreachable) - ) - ) - (if - (i32.eqz - (i32.eq - (i32.load offset=8 - (get_local $6) - ) - (i32.mul - (get_local $0) - (i32.const 4) - ) - ) - ) (block (call $abort (i32.const 0) @@ -1898,10 +1879,13 @@ (if (i32.eqz (i32.eq - (call $~lib/internal/typedarray/TypedArray#get:length + (i32.load offset=8 (get_local $6) ) - (get_local $0) + (i32.mul + (get_local $0) + (i32.const 4) + ) ) ) (block @@ -1914,8 +1898,27 @@ (unreachable) ) ) + (if + (i32.eqz + (i32.eq + (call $~lib/internal/typedarray/TypedArray#get:length + (get_local $6) + ) + (get_local $0) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 45) + (i32.const 2) + ) + (unreachable) + ) + ) (set_local $7 - (call $~lib/internal/typedarray/TypedArray#constructor + (call $~lib/internal/typedarray/TypedArray#constructor (i32.const 0) (get_local $0) ) @@ -1929,28 +1932,6 @@ (i32.const 0) ) ) - (block - (call $abort - (i32.const 0) - (i32.const 4) - (i32.const 47) - (i32.const 2) - ) - (unreachable) - ) - ) - (if - (i32.eqz - (i32.eq - (i32.load offset=8 - (get_local $7) - ) - (i32.mul - (get_local $0) - (i32.const 8) - ) - ) - ) (block (call $abort (i32.const 0) @@ -1964,10 +1945,13 @@ (if (i32.eqz (i32.eq - (call $~lib/internal/typedarray/TypedArray#get:length + (i32.load offset=8 (get_local $7) ) - (get_local $0) + (i32.mul + (get_local $0) + (i32.const 4) + ) ) ) (block @@ -1980,8 +1964,27 @@ (unreachable) ) ) + (if + (i32.eqz + (i32.eq + (call $~lib/internal/typedarray/TypedArray#get:length + (get_local $7) + ) + (get_local $0) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 50) + (i32.const 2) + ) + (unreachable) + ) + ) (set_local $8 - (call $~lib/internal/typedarray/TypedArray#constructor + (call $~lib/internal/typedarray/TypedArray#constructor (i32.const 0) (get_local $0) ) @@ -1995,28 +1998,6 @@ (i32.const 0) ) ) - (block - (call $abort - (i32.const 0) - (i32.const 4) - (i32.const 52) - (i32.const 2) - ) - (unreachable) - ) - ) - (if - (i32.eqz - (i32.eq - (i32.load offset=8 - (get_local $8) - ) - (i32.mul - (get_local $0) - (i32.const 8) - ) - ) - ) (block (call $abort (i32.const 0) @@ -2030,10 +2011,13 @@ (if (i32.eqz (i32.eq - (call $~lib/internal/typedarray/TypedArray#get:length + (i32.load offset=8 (get_local $8) ) - (get_local $0) + (i32.mul + (get_local $0) + (i32.const 8) + ) ) ) (block @@ -2046,8 +2030,27 @@ (unreachable) ) ) + (if + (i32.eqz + (i32.eq + (call $~lib/internal/typedarray/TypedArray#get:length + (get_local $8) + ) + (get_local $0) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 55) + (i32.const 2) + ) + (unreachable) + ) + ) (set_local $9 - (call $~lib/internal/typedarray/TypedArray#constructor + (call $~lib/internal/typedarray/TypedArray#constructor (i32.const 0) (get_local $0) ) @@ -2061,28 +2064,6 @@ (i32.const 0) ) ) - (block - (call $abort - (i32.const 0) - (i32.const 4) - (i32.const 57) - (i32.const 2) - ) - (unreachable) - ) - ) - (if - (i32.eqz - (i32.eq - (i32.load offset=8 - (get_local $9) - ) - (i32.mul - (get_local $0) - (i32.const 4) - ) - ) - ) (block (call $abort (i32.const 0) @@ -2096,10 +2077,13 @@ (if (i32.eqz (i32.eq - (call $~lib/internal/typedarray/TypedArray#get:length + (i32.load offset=8 (get_local $9) ) - (get_local $0) + (i32.mul + (get_local $0) + (i32.const 8) + ) ) ) (block @@ -2112,8 +2096,27 @@ (unreachable) ) ) + (if + (i32.eqz + (i32.eq + (call $~lib/internal/typedarray/TypedArray#get:length + (get_local $9) + ) + (get_local $0) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 60) + (i32.const 2) + ) + (unreachable) + ) + ) (set_local $10 - (call $~lib/internal/typedarray/TypedArray#constructor + (call $~lib/internal/typedarray/TypedArray#constructor (i32.const 0) (get_local $0) ) @@ -2131,7 +2134,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 62) + (i32.const 63) (i32.const 2) ) (unreachable) @@ -2145,7 +2148,7 @@ ) (i32.mul (get_local $0) - (i32.const 8) + (i32.const 4) ) ) ) @@ -2153,7 +2156,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 63) + (i32.const 64) (i32.const 2) ) (unreachable) @@ -2162,7 +2165,7 @@ (if (i32.eqz (i32.eq - (call $~lib/internal/typedarray/TypedArray#get:length + (call $~lib/internal/typedarray/TypedArray#get:length (get_local $10) ) (get_local $0) @@ -2172,7 +2175,73 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 64) + (i32.const 65) + (i32.const 2) + ) + (unreachable) + ) + ) + (set_local $11 + (call $~lib/internal/typedarray/TypedArray#constructor + (i32.const 0) + (get_local $0) + ) + ) + (if + (i32.eqz + (i32.eq + (i32.load offset=4 + (get_local $11) + ) + (i32.const 0) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 68) + (i32.const 2) + ) + (unreachable) + ) + ) + (if + (i32.eqz + (i32.eq + (i32.load offset=8 + (get_local $11) + ) + (i32.mul + (get_local $0) + (i32.const 8) + ) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 69) + (i32.const 2) + ) + (unreachable) + ) + ) + (if + (i32.eqz + (i32.eq + (call $~lib/internal/typedarray/TypedArray#get:length + (get_local $11) + ) + (get_local $0) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 70) (i32.const 2) ) (unreachable) @@ -2453,7 +2522,159 @@ ) ) ) - (func $start (; 29 ;) (type $v) + (func $~lib/typedarray/Uint8ClampedArray#__set (; 29 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (local $6 i32) + (local $7 i32) + (local $8 i32) + (local $9 i32) + (set_local $3 + (i32.load offset=4 + (get_local $0) + ) + ) + (set_local $4 + (i32.shr_u + (i32.sub + (i32.load offset=8 + (get_local $0) + ) + (get_local $3) + ) + (i32.const 0) + ) + ) + (if + (i32.ge_u + (get_local $1) + (get_local $4) + ) + (block + (call $abort + (i32.const 0) + (i32.const 164) + (i32.const 32) + (i32.const 42) + ) + (unreachable) + ) + ) + (set_local $5 + (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) + ) + ) + (block $~lib/internal/arraybuffer/storeUnsafeWithOffset|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#__get (; 30 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (local $6 i32) + (set_local $2 + (i32.load offset=4 + (get_local $0) + ) + ) + (set_local $3 + (i32.shr_u + (i32.sub + (i32.load offset=8 + (get_local $0) + ) + (get_local $2) + ) + (i32.const 0) + ) + ) + (if + (i32.ge_u + (get_local $1) + (get_local $3) + ) + (block + (call $abort + (i32.const 0) + (i32.const 44) + (i32.const 39) + (i32.const 42) + ) + (unreachable) + ) + ) + (return + (block $~lib/internal/arraybuffer/loadUnsafeWithOffset|inlined.0 (result i32) + (set_local $4 + (i32.load + (get_local $0) + ) + ) + (set_local $5 + (get_local $1) + ) + (set_local $6 + (get_local $2) + ) + (br $~lib/internal/arraybuffer/loadUnsafeWithOffset|inlined.0 + (i32.load8_u offset=8 + (i32.add + (i32.add + (get_local $4) + (get_local $6) + ) + (i32.shl + (get_local $5) + (i32.const 0) + ) + ) + ) + ) + ) + ) + ) + (func $start (; 31 ;) (type $v) (if (i32.eqz (i32.eq @@ -2491,8 +2712,8 @@ (if (i32.eqz (i32.eq - (i32.const 2) - (i32.const 2) + (i32.const 1) + (i32.const 1) ) ) (block @@ -2525,8 +2746,8 @@ (if (i32.eqz (i32.eq - (i32.const 4) - (i32.const 4) + (i32.const 2) + (i32.const 2) ) ) (block @@ -2559,8 +2780,8 @@ (if (i32.eqz (i32.eq - (i32.const 8) - (i32.const 8) + (i32.const 4) + (i32.const 4) ) ) (block @@ -2590,6 +2811,23 @@ (unreachable) ) ) + (if + (i32.eqz + (i32.eq + (i32.const 8) + (i32.const 8) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 9) + (i32.const 0) + ) + (unreachable) + ) + ) (if (i32.eqz (i32.eq @@ -2601,7 +2839,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 9) + (i32.const 10) (i32.const 0) ) (unreachable) @@ -2618,7 +2856,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 10) + (i32.const 11) (i32.const 0) ) (unreachable) @@ -2679,7 +2917,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 74) + (i32.const 80) (i32.const 0) ) (unreachable) @@ -2698,7 +2936,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 75) + (i32.const 81) (i32.const 0) ) (unreachable) @@ -2720,7 +2958,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 76) + (i32.const 82) (i32.const 0) ) (unreachable) @@ -2740,7 +2978,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 77) + (i32.const 83) (i32.const 0) ) (unreachable) @@ -2760,7 +2998,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 78) + (i32.const 84) (i32.const 0) ) (unreachable) @@ -2780,7 +3018,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 79) + (i32.const 85) (i32.const 0) ) (unreachable) @@ -2806,7 +3044,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 82) + (i32.const 88) (i32.const 0) ) (unreachable) @@ -2828,7 +3066,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 83) + (i32.const 89) (i32.const 0) ) (unreachable) @@ -2850,7 +3088,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 84) + (i32.const 90) (i32.const 0) ) (unreachable) @@ -2870,7 +3108,88 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 85) + (i32.const 91) + (i32.const 0) + ) + (unreachable) + ) + ) + (set_global $std/typedarray/clampedArr + (call $~lib/internal/typedarray/TypedArray#constructor + (i32.const 0) + (i32.const 3) + ) + ) + (call $~lib/typedarray/Uint8ClampedArray#__set + (get_global $std/typedarray/clampedArr) + (i32.const 0) + (i32.const -32) + ) + (call $~lib/typedarray/Uint8ClampedArray#__set + (get_global $std/typedarray/clampedArr) + (i32.const 1) + (i32.const 2) + ) + (call $~lib/typedarray/Uint8ClampedArray#__set + (get_global $std/typedarray/clampedArr) + (i32.const 2) + (i32.const 256) + ) + (if + (i32.eqz + (i32.eq + (call $~lib/internal/typedarray/TypedArray#__get + (get_global $std/typedarray/clampedArr) + (i32.const 0) + ) + (i32.const 0) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 98) + (i32.const 0) + ) + (unreachable) + ) + ) + (if + (i32.eqz + (i32.eq + (call $~lib/internal/typedarray/TypedArray#__get + (get_global $std/typedarray/clampedArr) + (i32.const 1) + ) + (i32.const 2) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 99) + (i32.const 0) + ) + (unreachable) + ) + ) + (if + (i32.eqz + (i32.eq + (call $~lib/internal/typedarray/TypedArray#__get + (get_global $std/typedarray/clampedArr) + (i32.const 2) + ) + (i32.const 255) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 100) (i32.const 0) ) (unreachable)