1
1
package io .scalajs .nodejs .vm
2
2
3
+ import com .thoughtworks .enableIf
4
+
3
5
import scala .scalajs .js
4
6
import scala .scalajs .js .annotation .JSImport
7
+ import scala .scalajs .js .typedarray .{DataView , Uint8Array }
8
+ import scala .scalajs .js .|
5
9
6
10
/**
7
11
* The vm module provides APIs for compiling and running code within V8 Virtual Machine contexts.
@@ -10,9 +14,13 @@ import scala.scalajs.js.annotation.JSImport
10
14
@ js.native
11
15
trait VM extends js.Object {
12
16
13
- // ///////////////////////////////////////////////////////////////////////////////
14
- // Methods
15
- // ///////////////////////////////////////////////////////////////////////////////
17
+ @ enableIf(io.scalajs.nodejs.CompilerSwitches .gteNodeJs10)
18
+ def compileFunction (code : String ,
19
+ params : js.Array [String ],
20
+ options : CompileFunctionOptions = js.native): js.Function = js.native
21
+
22
+ @ enableIf(io.scalajs.nodejs.CompilerSwitches .gteNodeJs10)
23
+ def compileFunction (code : String ): js.Function = js.native
16
24
17
25
/**
18
26
* If given a sandbox object, the vm.createContext() method will
@@ -30,22 +38,15 @@ trait VM extends js.Object {
30
38
* @example vm.createContext([sandbox])
31
39
* @since 0.11.7
32
40
*/
33
- def createContext (sandbox : js.Any ): ScriptContext = js.native
34
-
35
- /**
36
- * Creates a new script
37
- * @param code The JavaScript code to compile.
38
- * @param options the optional options
39
- * @example vm.createScript(code[, options])
40
- */
41
- def createScript (code : String , options : ScriptOptions = js.native): ContextifyScript = js.native
41
+ def createContext (sandbox : js.Object , options : CreateContextOptions = js.native): ScriptContext = js.native
42
+ def createContext (): ScriptContext = js.native
42
43
43
44
/**
44
- * The vm.runInDebugContext() method compiles and executes code inside the V8 debug context .
45
- * @param code The JavaScript code to compile and run.
46
- * @example vm.runInDebugContext(code)
45
+ * Returns true if the given sandbox object has been contextified using vm.createContext() .
46
+ * @param sandbox the sandbox
47
+ * @return true if the given sandbox object has been contextified using vm.createContext().
47
48
*/
48
- def runInDebugContext ( code : String ): js. Any = js.native
49
+ def isContext ( sandbox : js. Object ): Boolean = js.native
49
50
50
51
/**
51
52
* Runs the compiled code contained by the vm.Script object within the given contextifiedSandbox and returns the
@@ -55,8 +56,9 @@ trait VM extends js.Object {
55
56
* @param options the optional options
56
57
* @example script.runInContext(contextifiedSandbox[, options])
57
58
*/
58
- def runInContext (code : String , contextifiedSandbox : ScriptContext , options : ContextOptions = js.native): js.Any =
59
- js.native
59
+ def runInContext (code : String ,
60
+ contextifiedSandbox : ScriptContext ,
61
+ options : VMRunInContextOptions = js.native): js.Any = js.native
60
62
61
63
/**
62
64
* First contextifies the given sandbox, runs the compiled code contained by the vm.Script object within the created
@@ -66,7 +68,7 @@ trait VM extends js.Object {
66
68
* @param options the optional options
67
69
* @example vm.runInNewContext(code[, sandbox][, options])
68
70
*/
69
- def runInNewContext (code : String , sandbox : js.Any , options : ContextOptions = js.native): js.Any =
71
+ def runInNewContext (code : String , sandbox : js.Any , options : VMRunInNewContextOptions = js.native): js.Any =
70
72
js.native
71
73
72
74
/**
@@ -76,14 +78,7 @@ trait VM extends js.Object {
76
78
* @param options the optional options
77
79
* @example script.runInThisContext([options])
78
80
*/
79
- def runInThisContext (code : String , options : ContextOptions = js.native): ContextifyScript = js.native
80
-
81
- /**
82
- * Returns true if the given sandbox object has been contextified using vm.createContext().
83
- * @param sandbox the sandbox
84
- * @return true if the given sandbox object has been contextified using vm.createContext().
85
- */
86
- def isContext (sandbox : js.Any ): Boolean = js.native
81
+ def runInThisContext (code : String , options : VMRunInContextOptions = js.native): Script = js.native
87
82
88
83
}
89
84
@@ -93,3 +88,46 @@ trait VM extends js.Object {
93
88
@ js.native
94
89
@ JSImport (" vm" , JSImport .Namespace )
95
90
object VM extends VM
91
+
92
+ class CompileFunctionOptions (
93
+ var filename : js.UndefOr [String ] = js.undefined,
94
+ var lineOffset : js.UndefOr [Int ] = js.undefined,
95
+ var columnOffset : js.UndefOr [Int ] = js.undefined,
96
+ var cachedData : js.UndefOr [Uint8Array | DataView ] = js.undefined,
97
+ @ deprecated(" Use script.createCachedData" , " Node.js v10" )
98
+ var produceCachedData : js.UndefOr [Boolean ] = js.undefined,
99
+ var parsingContext : js.UndefOr [js.Object ] = js.undefined,
100
+ var contextExtensions : js.UndefOr [js.Array [js.Object ]] = js.undefined
101
+ ) extends js.Object
102
+
103
+ class CreateContextOptions (
104
+ var name : js.UndefOr [String ] = js.undefined,
105
+ var origin : js.UndefOr [String ] = js.undefined,
106
+ var codeGeneration : js.UndefOr [CodeGeneration ] = js.undefined
107
+ ) extends js.Object
108
+
109
+ class VMRunInNewContextOptions (
110
+ var filename : js.UndefOr [String ] = js.undefined,
111
+ var lineOffset : js.UndefOr [Int ] = js.undefined,
112
+ var columnOffset : js.UndefOr [Int ] = js.undefined,
113
+ var displayErrors : js.UndefOr [Boolean ] = js.undefined,
114
+ var timeout : js.UndefOr [Int ] = js.undefined,
115
+ var breakOnSigint : js.UndefOr [Boolean ] = js.undefined,
116
+ var contextName : js.UndefOr [String ] = js.undefined,
117
+ var contextOrigin : js.UndefOr [String ] = js.undefined,
118
+ var contextCodeGeneration : js.UndefOr [CodeGeneration ] = js.undefined,
119
+ var cachedData : js.UndefOr [Uint8Array | DataView ] = js.undefined,
120
+ var produceCachedData : js.UndefOr [Boolean ] = js.undefined,
121
+ var importModuleDynamically : js.UndefOr [js.Function ] = js.undefined
122
+ ) extends js.Object
123
+
124
+ class VMRunInContextOptions (var filename : js.UndefOr [String ] = js.undefined,
125
+ var lineOffset : js.UndefOr [Int ] = js.undefined,
126
+ var columnOffset : js.UndefOr [Int ] = js.undefined,
127
+ var displayErrors : js.UndefOr [Boolean ] = js.undefined,
128
+ var timeout : js.UndefOr [Int ] = js.undefined,
129
+ var breakOnSigint : js.UndefOr [Boolean ] = js.undefined,
130
+ var cachedData : js.UndefOr [Uint8Array | DataView ] = js.undefined,
131
+ var produceCachedData : js.UndefOr [Boolean ] = js.undefined,
132
+ var importModuleDynamically : js.UndefOr [js.Function ] = js.undefined)
133
+ extends js.Object
0 commit comments