Add ArrayBuffer.isView and rework Array.isArray (#431)

This commit is contained in:
Max Graey
2019-02-03 11:41:04 +02:00
committed by Daniel Wirtz
parent 1867416236
commit 4829f3a3e4
18 changed files with 3530 additions and 2567 deletions

View File

@ -113,7 +113,6 @@ export function compileCall(
let type = evaluateConstantType(compiler, typeArguments, operands, reportNode);
compiler.currentType = Type.bool;
if (!type) return module.createUnreachable();
compiler.currentType = Type.bool;
return type.is(TypeFlags.REFERENCE)
? module.createI32(1)
: module.createI32(0);
@ -134,9 +133,9 @@ export function compileCall(
compiler.currentType = Type.bool;
if (!type) return module.createUnreachable();
let classType = type.classReference;
return classType !== null && classType.lookupOverload(OperatorKind.INDEXED_GET) !== null
? module.createI32(1)
: module.createI32(0);
return (
classType !== null && classType.prototype.extends(compiler.program.arrayPrototype)
) ? module.createI32(1) : module.createI32(0);
}
case "isDefined": { // isDefined(expression) -> bool
compiler.currentType = Type.bool;

View File

@ -2856,6 +2856,14 @@ export class ClassPrototype extends Element {
this.decoratorFlags = decoratorFlags;
}
extends(basePtototype: ClassPrototype | null): bool {
var current: ClassPrototype | null = this;
do {
if (current === basePtototype) return true;
} while (current = current.basePrototype);
return false;
}
toString(): string {
return this.simpleName;
}
@ -2969,6 +2977,16 @@ export class Class extends Element {
return null;
}
lookupField(name: string, shouldReadonly: boolean = false): Element | null {
if (this.members == null) return null;
var member = this.members.get(name);
if (
member == null || member.kind != ElementKind.FIELD ||
(shouldReadonly && !member.is(CommonFlags.READONLY))
) return null;
return member;
}
offsetof(fieldName: string): u32 {
var members = assert(this.members);
assert(members.has(fieldName));