mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-17 08:51:34 +00:00
Initial ArrayBuffer implementation; Conditional allocation within constructors; Explicit constructor return values
This commit is contained in:
86
tests/compiler/std/constructor.ts
Normal file
86
tests/compiler/std/constructor.ts
Normal file
@ -0,0 +1,86 @@
|
||||
import "allocator/arena";
|
||||
|
||||
// trailing conditional allocate
|
||||
class EmptyCtor {
|
||||
constructor() {}
|
||||
}
|
||||
|
||||
var emptyCtor = new EmptyCtor();
|
||||
|
||||
// trailing conditional allocate with field initializer
|
||||
class EmptyCtorWithFieldInit {
|
||||
a: i32 = 1;
|
||||
constructor() {}
|
||||
}
|
||||
|
||||
var emptyCtorWithFieldInit = new EmptyCtorWithFieldInit();
|
||||
|
||||
// trailing conditional allocate with field initialized to zero
|
||||
class EmptyCtorWithFieldNoInit {
|
||||
a: i32;
|
||||
constructor() {}
|
||||
}
|
||||
|
||||
var emptyCtorWithFieldNoInit = new EmptyCtorWithFieldNoInit();
|
||||
|
||||
// direct allocate
|
||||
class None {
|
||||
}
|
||||
|
||||
var none = new None();
|
||||
|
||||
// direct allocate with field initializer
|
||||
class JustFieldInit {
|
||||
a: i32 = 1;
|
||||
}
|
||||
|
||||
var justFieldInit = new JustFieldInit();
|
||||
|
||||
// direct allocate with field initialized to zero
|
||||
class JustFieldNoInit {
|
||||
a: i32;
|
||||
}
|
||||
|
||||
var justFieldNoInit = new JustFieldNoInit();
|
||||
|
||||
// explicit allocation with no extra checks
|
||||
class CtorReturns {
|
||||
constructor() {
|
||||
return changetype<CtorReturns>(allocate_memory(0));
|
||||
}
|
||||
}
|
||||
|
||||
var ctorReturns = new CtorReturns();
|
||||
|
||||
var b: bool = true;
|
||||
|
||||
// explicit allocation with a trailing conditional fallback
|
||||
class CtorConditionallyReturns {
|
||||
constructor() {
|
||||
if (b) {
|
||||
return changetype<CtorConditionallyReturns>(allocate_memory(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var ctorConditionallyReturns = new CtorConditionallyReturns();
|
||||
|
||||
// implicit allocation with no extra checks
|
||||
class CtorAllocates {
|
||||
constructor() {
|
||||
this;
|
||||
}
|
||||
}
|
||||
|
||||
var ctorAllocates = new CtorAllocates();
|
||||
|
||||
// implicit allocation with a trailing conditional fallback
|
||||
class CtorConditionallyAllocates {
|
||||
constructor() {
|
||||
if (b) {
|
||||
this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var ctorConditionallyAllocates = new CtorConditionallyAllocates();
|
Reference in New Issue
Block a user