Add ArrayBuffer/DataView/Symbol#toString and improve Errors (#332)

This commit is contained in:
Max Graey
2018-11-18 12:43:44 +02:00
committed by Daniel Wirtz
parent a79db87af9
commit 1928404f3b
13 changed files with 3479 additions and 118 deletions

View File

@ -4,7 +4,30 @@ var stringToId: Map<string, usize>;
var idToString: Map<usize, string>;
var nextId: usize = 12; // Symbol.unscopables + 1
@unmanaged export class symbol {}
@unmanaged export class symbol {
toString(): string {
var id = changetype<usize>(this);
var str = "";
switch (id) {
case 1: { str = "hasInstance"; break; }
case 2: { str = "isConcatSpreadable"; break; }
case 3: { str = "isRegExp"; break; }
case 4: { str = "match"; break; }
case 5: { str = "replace"; break; }
case 6: { str = "search"; break; }
case 7: { str = "species"; break; }
case 8: { str = "split"; break; }
case 9: { str = "toPrimitive"; break; }
case 10: { str = "toStringTag"; break; }
case 11: { str = "unscopables"; break; }
default: {
if (idToString !== null && idToString.has(id)) str = idToString.get(id);
break;
}
}
return "Symbol(" + str + ")";
}
}
type Symbol = symbol;
@ -17,18 +40,18 @@ export function Symbol(description: string | null = null): symbol {
export namespace Symbol {
// well-known symbols
export const hasInstance = changetype<symbol>(1);
export const concatSpreadable = changetype<symbol>(2);
export const isRegExp = changetype<symbol>(3);
export const iterator = changetype<symbol>(3);
export const match = changetype<symbol>(4);
export const replace = changetype<symbol>(5);
export const search = changetype<symbol>(6);
export const species = changetype<symbol>(7);
export const split = changetype<symbol>(8);
export const toPrimitive = changetype<symbol>(9);
export const toStringTag = changetype<symbol>(10);
export const unscopables = changetype<symbol>(11);
export const hasInstance = changetype<symbol>(1);
export const isConcatSpreadable = changetype<symbol>(2);
export const isRegExp = changetype<symbol>(3);
export const iterator = changetype<symbol>(3);
export const match = changetype<symbol>(4);
export const replace = changetype<symbol>(5);
export const search = changetype<symbol>(6);
export const species = changetype<symbol>(7);
export const split = changetype<symbol>(8);
export const toPrimitive = changetype<symbol>(9);
export const toStringTag = changetype<symbol>(10);
export const unscopables = changetype<symbol>(11);
/* tslint:disable */// not valid TS
export function for(key: string): symbol {