assemblyscript/tests/compiler/std/gc-integration.ts
2019-03-09 01:06:45 +01:00

22 lines
637 B
TypeScript

// declare classes to test with
class A {}
class B {
static readonly c: B = changetype<B>(8); // static root, readonly
static d: A = changetype<A>(16); // static root, writable
}
// make sure static properties are compiled
B.c;
B.d;
// declare roots
var no_ref: usize = 64; // NOT a root, basic value
var a_ref: A | null = changetype<A>(24); // global root, nullable
var b_ref: B = changetype<B>(32); // global root, non-nullable
var i: i32 = 0;
__rt_iterateroots((ref: usize): void => { assert(<u32>ref == ++i << 3); });
assert(i == 4);
assert(__rt_classid<A>() != __rt_classid<B>());