2024-12-13 00:29:41 +00:00
|
|
|
import { object, setGlobalPrototypes, target } from "./primordials.ts";
|
2024-12-11 09:53:02 +00:00
|
|
|
import { Error, RangeError, SyntaxError, TypeError } from "./errors.ts";
|
2024-12-13 00:29:41 +00:00
|
|
|
import { Boolean } from "./boolean.ts";
|
2024-12-11 09:53:02 +00:00
|
|
|
import { Function } from "./function.ts";
|
|
|
|
import { Number } from "./number.ts";
|
|
|
|
import { Object } from "./object.ts";
|
|
|
|
import { String } from "./string.ts";
|
|
|
|
import { Symbol } from "./symbol.ts";
|
|
|
|
import { Array } from "./array.ts";
|
2024-12-13 00:29:41 +00:00
|
|
|
import { Map, WeakMap } from "./map.ts";
|
2024-12-11 09:53:02 +00:00
|
|
|
import { RegExp } from "./regex.ts";
|
2024-12-13 00:29:41 +00:00
|
|
|
import { Date } from "./date.ts";
|
|
|
|
import { Math as _Math } from "./math.ts";
|
|
|
|
import { Set, WeakSet } from "./set.ts";
|
2024-12-25 00:48:04 +00:00
|
|
|
import { JSON } from "./json.ts";
|
|
|
|
import { encodeURI, encodeURIComponent } from "./url.ts";
|
2024-12-27 17:17:07 +00:00
|
|
|
import { Promise } from "./promise.ts";
|
2024-12-11 09:53:02 +00:00
|
|
|
|
|
|
|
declare global {
|
|
|
|
function print(...args: any[]): void;
|
2024-12-13 00:29:41 +00:00
|
|
|
function measure(func: Function): void;
|
2024-12-11 09:53:02 +00:00
|
|
|
}
|
|
|
|
|
2024-12-13 00:29:41 +00:00
|
|
|
function fixup<T extends Function>(clazz: T) {
|
|
|
|
object.setPrototype(clazz, Function.prototype);
|
2024-12-27 17:17:07 +00:00
|
|
|
object.setPrototype(clazz.prototype as any, Object.prototype);
|
2024-12-13 00:29:41 +00:00
|
|
|
return clazz;
|
|
|
|
}
|
|
|
|
|
|
|
|
object.defineField(target, "undefined", { e: false, c: false, w: false, v: void 0 });
|
2024-12-11 09:53:02 +00:00
|
|
|
|
2024-12-13 00:29:41 +00:00
|
|
|
target.Symbol = fixup(Symbol);
|
|
|
|
target.Number = fixup(Number);
|
|
|
|
target.String = fixup(String);
|
|
|
|
target.Boolean = fixup(Boolean);
|
2024-12-11 09:53:02 +00:00
|
|
|
|
|
|
|
target.Object = Object;
|
2024-12-13 00:29:41 +00:00
|
|
|
target.Function = fixup(Function);
|
|
|
|
target.Array = fixup(Array);
|
2024-12-11 09:53:02 +00:00
|
|
|
|
2024-12-13 00:29:41 +00:00
|
|
|
target.Error = fixup(Error);
|
2024-12-11 09:53:02 +00:00
|
|
|
target.RangeError = RangeError;
|
|
|
|
target.SyntaxError = SyntaxError;
|
|
|
|
target.TypeError = TypeError;
|
|
|
|
|
2024-12-13 00:29:41 +00:00
|
|
|
target.Map = fixup(Map);
|
|
|
|
target.WeakMap = fixup(WeakMap);
|
|
|
|
target.Set = fixup(Set);
|
|
|
|
target.WeakSet = fixup(WeakSet);
|
|
|
|
target.RegExp = fixup(RegExp);
|
|
|
|
target.Date = fixup(Date);
|
2024-12-27 17:17:07 +00:00
|
|
|
target.Promise = fixup(Promise);
|
2024-12-13 00:29:41 +00:00
|
|
|
target.Math = object.setPrototype(_Math, Object.prototype);
|
2024-12-25 00:48:04 +00:00
|
|
|
target.JSON = object.setPrototype(JSON, Object.prototype);
|
2024-12-11 09:53:02 +00:00
|
|
|
|
|
|
|
target.parseInt = Number.parseInt;
|
|
|
|
target.parseFloat = Number.parseFloat;
|
|
|
|
target.NaN = Number.NaN;
|
|
|
|
target.Infinity = Number.POSITIVE_INFINITY;
|
2024-12-25 00:48:04 +00:00
|
|
|
target.encodeURI = encodeURI;
|
|
|
|
target.encodeURIComponent = encodeURIComponent;
|
2024-12-11 09:53:02 +00:00
|
|
|
|
|
|
|
setGlobalPrototypes({
|
|
|
|
string: String.prototype,
|
|
|
|
number: Number.prototype,
|
|
|
|
boolean: Boolean.prototype,
|
|
|
|
symbol: Symbol.prototype,
|
|
|
|
object: Object.prototype,
|
|
|
|
array: Array.prototype,
|
|
|
|
function: Function.prototype,
|
|
|
|
error: Error.prototype,
|
|
|
|
syntax: SyntaxError.prototype,
|
|
|
|
range: RangeError.prototype,
|
|
|
|
type: TypeError.prototype,
|
|
|
|
regex: RegExp,
|
|
|
|
});
|