make it 'runtime.instanceof'

This commit is contained in:
dcode
2019-04-03 00:26:41 +02:00
parent b58683aff4
commit 50c49e4275
62 changed files with 212 additions and 203 deletions

View File

@ -15,6 +15,22 @@ export declare function __runtime_id<T>(): u32;
@unsafe @builtin
export declare function __runtime_instanceof(id: u32, superId: u32): bool;
/** Runtime implementation. */
@unmanaged
export class runtime {
private constructor() { return unreachable(); }
@unsafe
static instanceof(ref: usize, id: u32): bool { // keyword
return ref
? __runtime_instanceof(
changetype<HEADER>(ref - HEADER_SIZE).classId,
id
)
: false;
}
}
/** Runtime implementation. */
export namespace runtime {
@ -128,15 +144,4 @@ export namespace runtime {
if (source) memory.copy(buffer, source, bufferSize);
return array;
}
// @ts-ignore: decorator
@unsafe
export function instanceOf(ref: usize, id: u32): bool {
return ref
? __runtime_instanceof(
changetype<HEADER>(ref - HEADER_SIZE).classId,
id
)
: false;
}
}