From d8071af48083f67f84235163e1ed25baa666ecf6 Mon Sep 17 00:00:00 2001 From: TopchetoEU <36534413+TopchetoEU@users.noreply.github.com> Date: Thu, 21 Sep 2023 10:50:48 +0300 Subject: [PATCH] refactor: remove dead .ts code --- lib/core.ts | 13 ++- lib/promise.ts | 208 ----------------------------------------- lib/tsconfig.json | 3 - lib/values/function.ts | 5 - lib/values/object.ts | 5 - 5 files changed, 10 insertions(+), 224 deletions(-) delete mode 100644 lib/promise.ts delete mode 100644 lib/values/function.ts delete mode 100644 lib/values/object.ts diff --git a/lib/core.ts b/lib/core.ts index 7a0c5b4..addd0b7 100644 --- a/lib/core.ts +++ b/lib/core.ts @@ -45,15 +45,22 @@ globalThis.log = internals.constructor.log; var i = 0.0; try { - run('values/object'); + var Object = env.global.Object = internals.object; + var Function = env.global.Function = internals.function; + var Promise = env.global.Promise = internals.promise; + + env.setProto('object', Object.prototype); + env.setProto('function', Function.prototype); + + (Object.prototype as any).__proto__ = null; + run('values/symbol'); - run('values/function'); + run('values/errors'); run('values/string'); run('values/number'); run('values/boolean'); run('values/array'); - run('promise'); run('map'); run('set'); run('regex'); diff --git a/lib/promise.ts b/lib/promise.ts deleted file mode 100644 index 1f7e8b7..0000000 --- a/lib/promise.ts +++ /dev/null @@ -1,208 +0,0 @@ -define("promise", () => { - var Promise = env.global.Promise = internals.promise - return; - - // const syms = { - // callbacks: internals.symbol('Promise.callbacks'), - // state: internals.symbol('Promise.state'), - // value: internals.symbol('Promise.value'), - // handled: internals.symbol('Promise.handled'), - // } as { - // readonly callbacks: unique symbol, - // readonly state: unique symbol, - // readonly value: unique symbol, - // readonly handled: unique symbol, - // } - - // type Callback = [ PromiseFulfillFunc, PromiseRejectFunc ]; - // enum State { - // Pending, - // Fulfilled, - // Rejected, - // } - - // function isAwaitable(val: unknown): val is Thenable { - // return ( - // typeof val === 'object' && - // val !== null && - // 'then' in val && - // typeof val.then === 'function' - // ); - // } - // function resolve(promise: Promise, v: any, state: State) { - // if (promise[syms.state] === State.Pending) { - // if (typeof v === 'object' && v !== null && 'then' in v && typeof v.then === 'function') { - // v.then( - // (res: any) => resolve(promise, res, state), - // (res: any) => resolve(promise, res, State.Rejected) - // ); - // return; - // } - // promise[syms.value] = v; - // promise[syms.state] = state; - - // for (let i = 0; i < promise[syms.callbacks]!.length; i++) { - // promise[syms.handled] = true; - // promise[syms.callbacks]![i][state - 1](v); - // } - - // promise[syms.callbacks] = undefined; - - // internals.pushMessage(true, internals.setEnv(() => { - // if (!promise[syms.handled] && state === State.Rejected) { - // log('Uncaught (in promise) ' + promise[syms.value]); - // } - // }, env), undefined, []); - // } - // } - - // class _Promise { - // public static isAwaitable(val: unknown): val is Thenable { - // return isAwaitable(val); - // } - - // public static resolve(val: T): Promise> { - // return new Promise(res => res(val as any)); - // } - // public static reject(val: T): Promise> { - // return new Promise((_, rej) => rej(val as any)); - // } - - // public static race(vals: T[]): Promise> { - // if (typeof vals.length !== 'number') throw new env.global.TypeError('vals must be an array. Note that Promise.race is not variadic.'); - // return new Promise((res, rej) => { - // for (let i = 0; i < vals.length; i++) { - // const val = vals[i]; - // if (this.isAwaitable(val)) val.then(res, rej); - // else res(val as any); - // } - // }); - // } - // public static any(vals: T[]): Promise> { - // if (typeof vals.length !== 'number') throw new env.global.TypeError('vals must be an array. Note that Promise.any is not variadic.'); - // return new Promise((res, rej) => { - // let n = 0; - - // for (let i = 0; i < vals.length; i++) { - // const val = vals[i]; - // if (this.isAwaitable(val)) val.then(res, (err) => { - // n++; - // if (n === vals.length) throw Error('No promise resolved.'); - // }); - // else res(val as any); - // } - - // if (vals.length === 0) throw Error('No promise resolved.'); - // }); - // } - // public static all(vals: any[]): Promise { - // if (typeof vals.length !== 'number') throw new env.global.TypeError('vals must be an array. Note that Promise.all is not variadic.'); - // return new Promise((res, rej) => { - // const result: any[] = []; - // let n = 0; - - // for (let i = 0; i < vals.length; i++) { - // const val = vals[i]; - // if (this.isAwaitable(val)) val.then( - // val => { - // n++; - // result[i] = val; - // if (n === vals.length) res(result); - // }, - // rej - // ); - // else { - // n++; - // result[i] = val; - // } - // } - - // if (vals.length === n) res(result); - // }); - // } - // public static allSettled(vals: any[]): Promise { - // if (typeof vals.length !== 'number') throw new env.global.TypeError('vals must be an array. Note that Promise.allSettled is not variadic.'); - // return new Promise((res, rej) => { - // const result: any[] = []; - // let n = 0; - - // for (let i = 0; i < vals.length; i++) { - // const value = vals[i]; - // if (this.isAwaitable(value)) value.then( - // value => { - // n++; - // result[i] = { status: 'fulfilled', value }; - // if (n === vals.length) res(result); - // }, - // reason => { - // n++; - // result[i] = { status: 'rejected', reason }; - // if (n === vals.length) res(result); - // }, - // ); - // else { - // n++; - // result[i] = { status: 'fulfilled', value }; - // } - // } - - // if (vals.length === n) res(result); - // }); - // } - - // [syms.callbacks]?: Callback[] = []; - // [syms.handled] = false; - // [syms.state] = State.Pending; - // [syms.value]?: T | unknown; - - // public then(onFulfil?: PromiseFulfillFunc, onReject?: PromiseRejectFunc) { - // return new Promise((resolve, reject) => { - // onFulfil ??= v => v; - // onReject ??= v => v; - - // const callback = (func: (val: any) => any) => (v: any) => { - // try { - // resolve(func(v)); - // } - // catch (e) { reject(e); } - // } - // switch (this[syms.state]) { - // case State.Pending: - // this[syms.callbacks]![this[syms.callbacks]!.length] = [callback(onFulfil), callback(onReject)]; - // break; - // case State.Fulfilled: - // this[syms.handled] = true; - // callback(onFulfil)(this[syms.value]); - // break; - // case State.Rejected: - // this[syms.handled] = true; - // callback(onReject)(this[syms.value]); - // break; - // } - // }) - // } - // public catch(func: PromiseRejectFunc) { - // return this.then(undefined, func); - // } - // public finally(func: () => void) { - // return this.then( - // v => { - // func(); - // return v; - // }, - // v => { - // func(); - // throw v; - // } - // ); - // } - - // public constructor(func: PromiseFunc) { - // internals.pushMessage(true, func, undefined, [ - // ((v) => resolve(this, v, State.Fulfilled)) as PromiseFulfillFunc, - // ((err) => resolve(this, err, State.Rejected)) as PromiseRejectFunc - // ]); - // } - // } - // env.global.Promise = Promise as any; -}); diff --git a/lib/tsconfig.json b/lib/tsconfig.json index 8c3e2af..e802b34 100644 --- a/lib/tsconfig.json +++ b/lib/tsconfig.json @@ -3,15 +3,12 @@ "lib.d.ts", "modules.ts", "utils.ts", - "values/object.ts", "values/symbol.ts", - "values/function.ts", "values/errors.ts", "values/string.ts", "values/number.ts", "values/boolean.ts", "values/array.ts", - "promise.ts", "map.ts", "set.ts", "regex.ts", diff --git a/lib/values/function.ts b/lib/values/function.ts deleted file mode 100644 index 4636d5d..0000000 --- a/lib/values/function.ts +++ /dev/null @@ -1,5 +0,0 @@ -define("values/function", () => { - var Function = env.global.Function = internals.function; - env.setProto('function', Function.prototype); - setConstr(Function.prototype, Function); -}); \ No newline at end of file diff --git a/lib/values/object.ts b/lib/values/object.ts deleted file mode 100644 index 0473a1e..0000000 --- a/lib/values/object.ts +++ /dev/null @@ -1,5 +0,0 @@ -define("values/object", () => { - var Object = env.global.Object = internals.object; - (Object.prototype as any).__proto__ = null; - env.setProto('object', Object.prototype); -}); \ No newline at end of file