declare module "quickjs:context" {
export class Context {
constructor(options?: {
date?: boolean;
eval?: boolean;
stringNormalize?: boolean;
regExp?: boolean;
json?: boolean;
proxy?: boolean;
mapSet?: boolean;
typedArrays?: boolean;
promise?: boolean;
inspect?: boolean;
console?: boolean;
print?: boolean;
moduleGlobals?: boolean;
timers?: boolean;
modules?: {
"quickjs:bytecode"?: boolean;
"quickjs:cmdline"?: boolean;
"quickjs:context"?: boolean;
"quickjs:encoding"?: boolean;
"quickjs:engine"?: boolean;
"quickjs:os"?: boolean;
"quickjs:std"?: boolean;
"quickjs:timers"?: boolean;
};
});
globalThis: typeof globalThis;
eval(code: string): any;
}
}A separate global context (or 'realm') within which code can be executed.
class Context {
constructor(options?: {
date?: boolean;
eval?: boolean;
stringNormalize?: boolean;
regExp?: boolean;
json?: boolean;
proxy?: boolean;
mapSet?: boolean;
typedArrays?: boolean;
promise?: boolean;
inspect?: boolean;
console?: boolean;
print?: boolean;
moduleGlobals?: boolean;
timers?: boolean;
modules?: {
"quickjs:bytecode"?: boolean;
"quickjs:cmdline"?: boolean;
"quickjs:context"?: boolean;
"quickjs:encoding"?: boolean;
"quickjs:engine"?: boolean;
"quickjs:os"?: boolean;
"quickjs:std"?: boolean;
"quickjs:timers"?: boolean;
};
});
globalThis: typeof globalThis;
eval(code: string): any;
}Create a new global context (or 'realm') within code can be executed.
@paramoptions — Options for what globals/modules/etc to make available within the context.
The following globals are always present, regardless of options:
- Object
- Function
- Error
- EvalError
- RangeError
- ReferenceError
- SyntaxError
- TypeError
- URIError
- InternalError
- AggregateError
- Array
- parseInt
- parseFloat
- isNaN
- isFinite
- decodeURI
- decodeURIComponent
- encodeURI
- encodeURIComponent
- escape
- unescape
- Infinity
- NaN
- undefined
- Number
- Boolean
- String
- Math
- Reflect
- Symbol
- eval (but it doesn't work unless the
evaloption is enabled) - globalThis
Note that new contexts don't have a scriptArgs global. If you need one
to be present in the new context, you can add one onto the Context's
globalThis property.
constructor(options?: {
date?: boolean;
eval?: boolean;
stringNormalize?: boolean;
regExp?: boolean;
json?: boolean;
proxy?: boolean;
mapSet?: boolean;
typedArrays?: boolean;
promise?: boolean;
inspect?: boolean;
console?: boolean;
print?: boolean;
moduleGlobals?: boolean;
timers?: boolean;
modules?: {
"quickjs:bytecode"?: boolean;
"quickjs:cmdline"?: boolean;
"quickjs:context"?: boolean;
"quickjs:encoding"?: boolean;
"quickjs:engine"?: boolean;
"quickjs:os"?: boolean;
"quickjs:std"?: boolean;
"quickjs:timers"?: boolean;
};
});The globalThis object used by this context.
You can add to or remove from it to change what is visible to the context.
globalThis: typeof globalThis;Runs code within the context and returns the result.
@paramcode — The code to run.
eval(code: string): any;