You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

vm.d.ts 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. declare module "vm" {
  2. interface Context {
  3. [key: string]: any;
  4. }
  5. interface BaseOptions {
  6. /**
  7. * Specifies the filename used in stack traces produced by this script.
  8. * Default: `''`.
  9. */
  10. filename?: string;
  11. /**
  12. * Specifies the line number offset that is displayed in stack traces produced by this script.
  13. * Default: `0`.
  14. */
  15. lineOffset?: number;
  16. /**
  17. * Specifies the column number offset that is displayed in stack traces produced by this script.
  18. * Default: `0`
  19. */
  20. columnOffset?: number;
  21. }
  22. interface ScriptOptions extends BaseOptions {
  23. displayErrors?: boolean;
  24. timeout?: number;
  25. cachedData?: Buffer;
  26. produceCachedData?: boolean;
  27. }
  28. interface RunningScriptOptions extends BaseOptions {
  29. displayErrors?: boolean;
  30. timeout?: number;
  31. }
  32. interface CompileFunctionOptions extends BaseOptions {
  33. /**
  34. * Provides an optional data with V8's code cache data for the supplied source.
  35. */
  36. cachedData?: Buffer;
  37. /**
  38. * Specifies whether to produce new cache data.
  39. * Default: `false`,
  40. */
  41. produceCachedData?: boolean;
  42. /**
  43. * The sandbox/context in which the said function should be compiled in.
  44. */
  45. parsingContext?: Context;
  46. /**
  47. * An array containing a collection of context extensions (objects wrapping the current scope) to be applied while compiling
  48. */
  49. contextExtensions?: Object[];
  50. }
  51. class Script {
  52. constructor(code: string, options?: ScriptOptions);
  53. runInContext(contextifiedSandbox: Context, options?: RunningScriptOptions): any;
  54. runInNewContext(sandbox?: Context, options?: RunningScriptOptions): any;
  55. runInThisContext(options?: RunningScriptOptions): any;
  56. }
  57. function createContext(sandbox?: Context): Context;
  58. function isContext(sandbox: Context): boolean;
  59. function runInContext(code: string, contextifiedSandbox: Context, options?: RunningScriptOptions | string): any;
  60. function runInNewContext(code: string, sandbox?: Context, options?: RunningScriptOptions | string): any;
  61. function runInThisContext(code: string, options?: RunningScriptOptions | string): any;
  62. function compileFunction(code: string, params: string[], options: CompileFunctionOptions): Function;
  63. }