mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-04-25 07:02:13 +00:00
Add a .data pointer on ArrayBuffers for convenience, see #291
This commit is contained in:
parent
b7e7be20cf
commit
db0e82fbc3
2
dist/asc.js
vendored
2
dist/asc.js
vendored
File diff suppressed because one or more lines are too long
2
dist/asc.js.map
vendored
2
dist/asc.js.map
vendored
File diff suppressed because one or more lines are too long
@ -9,6 +9,9 @@ export class ArrayBuffer {
|
||||
|
||||
readonly byteLength: i32; // capped to [0, MAX_LENGTH]
|
||||
|
||||
// @unsafe
|
||||
get data(): usize { return changetype<usize>(this) + HEADER_SIZE; }
|
||||
|
||||
constructor(length: i32, unsafe: bool = false) {
|
||||
if (<u32>length > <u32>MAX_BLENGTH) throw new RangeError("Invalid array buffer length");
|
||||
var buffer = allocateUnsafe(length);
|
||||
|
2
std/assembly/index.d.ts
vendored
2
std/assembly/index.d.ts
vendored
@ -372,6 +372,8 @@ declare namespace table {
|
||||
declare class ArrayBuffer {
|
||||
/** The size, in bytes, of the array. */
|
||||
readonly byteLength: i32;
|
||||
/** Unsafe pointer to the start of the data in memory. */
|
||||
readonly data: usize;
|
||||
/** Constructs a new array buffer of the given length in bytes. */
|
||||
constructor(length: i32, unsafe?: bool);
|
||||
/** Returns a copy of this array buffer's bytes from begin, inclusive, up to end, exclusive. */
|
||||
|
@ -2276,7 +2276,13 @@
|
||||
(get_local $2)
|
||||
)
|
||||
)
|
||||
(func $start (; 10 ;) (; has Stack IR ;) (type $v)
|
||||
(func $~lib/arraybuffer/ArrayBuffer#get:data (; 10 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
|
||||
(i32.add
|
||||
(get_local $0)
|
||||
(i32.const 8)
|
||||
)
|
||||
)
|
||||
(func $start (; 11 ;) (; has Stack IR ;) (type $v)
|
||||
(set_global $~lib/allocator/arena/startOffset
|
||||
(i32.const 160)
|
||||
)
|
||||
@ -2329,6 +2335,25 @@
|
||||
(unreachable)
|
||||
)
|
||||
)
|
||||
(if
|
||||
(i32.eq
|
||||
(call $~lib/arraybuffer/ArrayBuffer#get:data
|
||||
(get_global $std/arraybuffer/sliced)
|
||||
)
|
||||
(call $~lib/arraybuffer/ArrayBuffer#get:data
|
||||
(get_global $std/arraybuffer/buffer)
|
||||
)
|
||||
)
|
||||
(block
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 120)
|
||||
(i32.const 10)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
)
|
||||
(if
|
||||
(i32.eq
|
||||
(get_global $std/arraybuffer/sliced)
|
||||
@ -2338,7 +2363,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 120)
|
||||
(i32.const 10)
|
||||
(i32.const 11)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -2364,7 +2389,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 120)
|
||||
(i32.const 14)
|
||||
(i32.const 15)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -2390,7 +2415,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 120)
|
||||
(i32.const 18)
|
||||
(i32.const 19)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -2414,7 +2439,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 120)
|
||||
(i32.const 22)
|
||||
(i32.const 23)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -2438,7 +2463,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 120)
|
||||
(i32.const 26)
|
||||
(i32.const 27)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -2462,7 +2487,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 120)
|
||||
(i32.const 30)
|
||||
(i32.const 31)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -2486,7 +2511,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 120)
|
||||
(i32.const 34)
|
||||
(i32.const 35)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -2509,7 +2534,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 120)
|
||||
(i32.const 38)
|
||||
(i32.const 39)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -2523,14 +2548,14 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 120)
|
||||
(i32.const 39)
|
||||
(i32.const 40)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
)
|
||||
)
|
||||
(func $null (; 11 ;) (; has Stack IR ;) (type $v)
|
||||
(func $null (; 12 ;) (; has Stack IR ;) (type $v)
|
||||
(nop)
|
||||
)
|
||||
)
|
||||
|
@ -7,6 +7,7 @@ assert(buffer.byteLength == 8);
|
||||
var sliced = buffer.slice();
|
||||
|
||||
assert(sliced.byteLength == 8);
|
||||
assert(sliced.data != buffer.data);
|
||||
assert(sliced !== buffer);
|
||||
|
||||
sliced = buffer.slice(1);
|
||||
|
@ -558,7 +558,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 13)
|
||||
(i32.const 16)
|
||||
(i32.const 40)
|
||||
)
|
||||
(unreachable)
|
||||
@ -2871,7 +2871,13 @@
|
||||
(get_local $2)
|
||||
)
|
||||
)
|
||||
(func $start (; 10 ;) (type $v)
|
||||
(func $~lib/arraybuffer/ArrayBuffer#get:data (; 10 ;) (type $ii) (param $0 i32) (result i32)
|
||||
(i32.add
|
||||
(get_local $0)
|
||||
(get_global $~lib/internal/arraybuffer/HEADER_SIZE)
|
||||
)
|
||||
)
|
||||
(func $start (; 11 ;) (type $v)
|
||||
(set_global $~lib/allocator/arena/startOffset
|
||||
(i32.and
|
||||
(i32.add
|
||||
@ -2944,6 +2950,27 @@
|
||||
(unreachable)
|
||||
)
|
||||
)
|
||||
(if
|
||||
(i32.eqz
|
||||
(i32.ne
|
||||
(call $~lib/arraybuffer/ArrayBuffer#get:data
|
||||
(get_global $std/arraybuffer/sliced)
|
||||
)
|
||||
(call $~lib/arraybuffer/ArrayBuffer#get:data
|
||||
(get_global $std/arraybuffer/buffer)
|
||||
)
|
||||
)
|
||||
)
|
||||
(block
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 120)
|
||||
(i32.const 10)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
)
|
||||
(if
|
||||
(i32.eqz
|
||||
(i32.ne
|
||||
@ -2955,7 +2982,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 120)
|
||||
(i32.const 10)
|
||||
(i32.const 11)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -2986,7 +3013,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 120)
|
||||
(i32.const 14)
|
||||
(i32.const 15)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -3017,7 +3044,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 120)
|
||||
(i32.const 18)
|
||||
(i32.const 19)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -3043,7 +3070,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 120)
|
||||
(i32.const 22)
|
||||
(i32.const 23)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -3069,7 +3096,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 120)
|
||||
(i32.const 26)
|
||||
(i32.const 27)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -3095,7 +3122,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 120)
|
||||
(i32.const 30)
|
||||
(i32.const 31)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -3121,7 +3148,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 120)
|
||||
(i32.const 34)
|
||||
(i32.const 35)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -3152,7 +3179,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 120)
|
||||
(i32.const 38)
|
||||
(i32.const 39)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -3169,13 +3196,13 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 120)
|
||||
(i32.const 39)
|
||||
(i32.const 40)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
)
|
||||
)
|
||||
(func $null (; 11 ;) (type $v)
|
||||
(func $null (; 12 ;) (type $v)
|
||||
)
|
||||
)
|
||||
|
@ -478,7 +478,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 13)
|
||||
(i32.const 16)
|
||||
(i32.const 40)
|
||||
)
|
||||
(unreachable)
|
||||
|
@ -582,7 +582,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 13)
|
||||
(i32.const 16)
|
||||
(i32.const 40)
|
||||
)
|
||||
(unreachable)
|
||||
|
@ -479,7 +479,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 13)
|
||||
(i32.const 16)
|
||||
(i32.const 40)
|
||||
)
|
||||
(unreachable)
|
||||
|
@ -584,7 +584,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 13)
|
||||
(i32.const 16)
|
||||
(i32.const 40)
|
||||
)
|
||||
(unreachable)
|
||||
|
@ -499,7 +499,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 56)
|
||||
(i32.const 13)
|
||||
(i32.const 16)
|
||||
(i32.const 40)
|
||||
)
|
||||
(unreachable)
|
||||
|
@ -613,7 +613,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 56)
|
||||
(i32.const 13)
|
||||
(i32.const 16)
|
||||
(i32.const 40)
|
||||
)
|
||||
(unreachable)
|
||||
|
Loading…
x
Reference in New Issue
Block a user