Context (class)
A separate global context (or 'realm') within which code can be executed.
This is the same as import("quickjs:context"), but with a
yavascriptGlobals option added.
constructor(options?: {
date?: boolean;
stringNormalize?: boolean;
regExp?: boolean;
json?: boolean;
proxy?: boolean;
mapSet?: boolean;
typedArrays?: boolean;
promise?: boolean;
console?: boolean;
moduleGlobals?: boolean;
timers?: boolean;
yavascriptGlobals?: boolean;
modules?: {
};
});
}
Context (constructor)
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;
stringNormalize?: boolean;
regExp?: boolean;
json?: boolean;
proxy?: boolean;
mapSet?: boolean;
typedArrays?: boolean;
promise?: boolean;
console?: boolean;
moduleGlobals?: boolean;
timers?: boolean;
yavascriptGlobals?: boolean;
modules?: {
};
});
Context.prototype.globalThis (property)
The globalThis object used by this context.
You can add to or remove from it to change what is visible to the context.
Context.prototype.eval (method)
Runs code within the context and returns the result.
@paramcode — The code to run.
NOTE: This function will work even if you created the Context with option
eval: false(which only disables eval within the context).