mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-18 01:11:32 +00:00
symbols
This commit is contained in:
2
std/assembly/index.d.ts
vendored
2
std/assembly/index.d.ts
vendored
@ -1023,7 +1023,7 @@ declare class ArrayBuffer {
|
||||
/** Returns true if value is one of the ArrayBuffer views, such as typed array or a DataView **/
|
||||
static isView<T>(value: T): bool;
|
||||
/** Constructs a new array buffer of the given length in bytes. */
|
||||
constructor(length: i32, unsafe?: bool);
|
||||
constructor(length: i32);
|
||||
/** Returns a copy of this array buffer's bytes from begin, inclusive, up to end, exclusive. */
|
||||
slice(begin?: i32, end?: i32): ArrayBuffer;
|
||||
/** Returns a string representation of ArrayBuffer. */
|
||||
|
@ -72,7 +72,7 @@ export class Map<K,V> {
|
||||
this.buckets = new ArrayBuffer(bucketsSize);
|
||||
this.bucketsMask = INITIAL_CAPACITY - 1;
|
||||
const entriesSize = INITIAL_CAPACITY * <i32>ENTRY_SIZE<K,V>();
|
||||
this.entries = new ArrayBuffer(entriesSize, true);
|
||||
this.entries = new ArrayBuffer(entriesSize);
|
||||
this.entriesCapacity = INITIAL_CAPACITY;
|
||||
this.entriesOffset = 0;
|
||||
this.entriesCount = 0;
|
||||
@ -147,7 +147,7 @@ export class Map<K,V> {
|
||||
var newBucketsCapacity = <i32>(newBucketsMask + 1);
|
||||
var newBuckets = new ArrayBuffer(newBucketsCapacity * <i32>BUCKET_SIZE);
|
||||
var newEntriesCapacity = <i32>(newBucketsCapacity * FILL_FACTOR);
|
||||
var newEntries = new ArrayBuffer(newEntriesCapacity * <i32>ENTRY_SIZE<K,V>(), true);
|
||||
var newEntries = new ArrayBuffer(newEntriesCapacity * <i32>ENTRY_SIZE<K,V>());
|
||||
|
||||
// copy old entries to new entries
|
||||
var oldPtr = changetype<usize>(this.entries);
|
||||
|
@ -12,8 +12,8 @@ export namespace runtime {
|
||||
// @ts-ignore: decorator
|
||||
@lazy @inline
|
||||
static readonly SIZE: usize = gc.implemented
|
||||
? (offsetof<Header>( ) + AL_MASK) & ~AL_MASK // full header if GC is present
|
||||
: (offsetof<Header>("gc1") + AL_MASK) & ~AL_MASK; // half header if GC is absent
|
||||
? (offsetof<runtime.Header>( ) + AL_MASK) & ~AL_MASK // full header if GC is present
|
||||
: (offsetof<runtime.Header>("gc1") + AL_MASK) & ~AL_MASK; // half header if GC is absent
|
||||
|
||||
/** Magic value used to validate runtime headers. */
|
||||
// @ts-ignore: decorator
|
||||
|
@ -1,12 +1,83 @@
|
||||
import { Map } from "./map";
|
||||
|
||||
@lazy var stringToId: Map<string, usize>;
|
||||
@lazy var idToString: Map<usize, string>;
|
||||
@lazy var nextId: usize = 12; // Symbol.unscopables + 1
|
||||
// @ts-ignore: decorator
|
||||
@lazy
|
||||
var stringToId: Map<string, usize>;
|
||||
|
||||
// @ts-ignore: decorator
|
||||
@lazy
|
||||
var idToString: Map<usize, string>;
|
||||
|
||||
// @ts-ignore: decorator
|
||||
@lazy
|
||||
var nextId: usize = 12; // Symbol.unscopables + 1
|
||||
|
||||
@unmanaged abstract class _Symbol {
|
||||
|
||||
// @ts-ignore: decorator
|
||||
@lazy
|
||||
static readonly hasInstance: symbol = changetype<symbol>(1);
|
||||
|
||||
// @ts-ignore: decorator
|
||||
@lazy
|
||||
static readonly isConcatSpreadable: symbol = changetype<symbol>(2);
|
||||
|
||||
// @ts-ignore: decorator
|
||||
@lazy
|
||||
static readonly isRegExp: symbol = changetype<symbol>(3);
|
||||
|
||||
// @ts-ignore: decorator
|
||||
@lazy
|
||||
static readonly iterator: symbol = changetype<symbol>(3);
|
||||
|
||||
// @ts-ignore: decorator
|
||||
@lazy
|
||||
static readonly match: symbol = changetype<symbol>(4);
|
||||
|
||||
// @ts-ignore: decorator
|
||||
@lazy
|
||||
static readonly replace: symbol = changetype<symbol>(5);
|
||||
|
||||
// @ts-ignore: decorator
|
||||
@lazy
|
||||
static readonly search: symbol = changetype<symbol>(6);
|
||||
|
||||
// @ts-ignore: decorator
|
||||
@lazy
|
||||
static readonly species: symbol = changetype<symbol>(7);
|
||||
|
||||
// @ts-ignore: decorator
|
||||
@lazy
|
||||
static readonly split: symbol = changetype<symbol>(8);
|
||||
|
||||
// @ts-ignore: decorator
|
||||
@lazy
|
||||
static readonly toPrimitive: symbol = changetype<symbol>(9);
|
||||
|
||||
// @ts-ignore: decorator
|
||||
@lazy
|
||||
static readonly toStringTag: symbol = changetype<symbol>(10);
|
||||
|
||||
// @ts-ignore: decorator
|
||||
@lazy
|
||||
static readonly unscopables: symbol = changetype<symbol>(11);
|
||||
|
||||
static for(key: string): symbol {
|
||||
if (!stringToId) { stringToId = new Map(); idToString = new Map(); }
|
||||
else if (stringToId.has(key)) return changetype<symbol>(stringToId.get(key));
|
||||
var id = nextId++;
|
||||
if (!id) unreachable(); // out of ids
|
||||
stringToId.set(key, id);
|
||||
idToString.set(id, key);
|
||||
return changetype<symbol>(id);
|
||||
}
|
||||
|
||||
static keyFor(sym: symbol): string | null {
|
||||
return idToString !== null && idToString.has(changetype<usize>(sym))
|
||||
? idToString.get(changetype<usize>(sym))
|
||||
: null;
|
||||
}
|
||||
|
||||
@unmanaged
|
||||
// @ts-ignore: nolib
|
||||
export class symbol {
|
||||
toString(): string {
|
||||
var id = changetype<usize>(this);
|
||||
var str = "";
|
||||
@ -37,40 +108,7 @@ export function Symbol(description: string | null = null): symbol {
|
||||
return changetype<symbol>(id);
|
||||
}
|
||||
|
||||
export namespace Symbol {
|
||||
export type Symbol = _Symbol;
|
||||
|
||||
// well-known symbols
|
||||
@lazy export const hasInstance = changetype<symbol>(1);
|
||||
@lazy export const isConcatSpreadable = changetype<symbol>(2);
|
||||
@lazy export const isRegExp = changetype<symbol>(3);
|
||||
@lazy export const iterator = changetype<symbol>(3);
|
||||
@lazy export const match = changetype<symbol>(4);
|
||||
@lazy export const replace = changetype<symbol>(5);
|
||||
@lazy export const search = changetype<symbol>(6);
|
||||
@lazy export const species = changetype<symbol>(7);
|
||||
@lazy export const split = changetype<symbol>(8);
|
||||
@lazy export const toPrimitive = changetype<symbol>(9);
|
||||
@lazy export const toStringTag = changetype<symbol>(10);
|
||||
@lazy export const unscopables = changetype<symbol>(11);
|
||||
|
||||
// FIXME
|
||||
|
||||
/* tslint:disable */// not valid TS
|
||||
// @ts-ignore: identifier
|
||||
export function for(key: string): symbol {
|
||||
if (!stringToId) { stringToId = new Map(); idToString = new Map(); }
|
||||
else if (stringToId.has(key)) return changetype<symbol>(stringToId.get(key));
|
||||
var id = nextId++;
|
||||
if (!id) unreachable(); // out of ids
|
||||
stringToId.set(key, id);
|
||||
idToString.set(id, key);
|
||||
return changetype<symbol>(id);
|
||||
}
|
||||
/* tslint:enable */
|
||||
|
||||
export function keyFor(sym: symbol): string | null {
|
||||
return idToString !== null && idToString.has(changetype<usize>(sym))
|
||||
? idToString.get(changetype<usize>(sym))
|
||||
: null;
|
||||
}
|
||||
}
|
||||
// @ts-ignore: nolib
|
||||
export type symbol = _Symbol;
|
||||
|
Reference in New Issue
Block a user