| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -136,6 +136,16 @@ Creates a code cache that can be used with the `Script` constructor's | |||
| 136 | 136 | `cachedData` option. Returns a `Buffer`. This method may be called at any | |
| 137 | 137 | time and any number of times. | |
| 138 | 138 | ||
| 139 | + The code cache of the `Script` doesn't contain any JavaScript observable | ||
| 140 | + states. The code cache is safe to be saved along side the script source and | ||
| 141 | + used to construct new `Script` instances multiple times. | ||
| 142 | + | ||
| 143 | + Functions in the `Script` source can be marked as lazily compiled and they are | ||
| 144 | + not compiled at construction of the `Script`. These functions are going to be | ||
| 145 | + compiled when they are invoked the first time. The code cache serializes the | ||
| 146 | + metadata that V8 currently knows about the `Script` that it can use to speed up | ||
| 147 | + future compilations. | ||
| 148 | + | ||
| 139 | 149 | ```js | |
| 140 | 150 | const script = new vm.Script(` | |
| 141 | 151 | function add(a, b) { | |
@@ -145,11 +155,14 @@ function add(a, b) { | |||
| 145 | 155 | const x = add(1, 2); | |
| 146 | 156 | `); | |
| 147 | 157 | ||
| 148 | - const cacheWithoutX = script.createCachedData(); | ||
| 158 | + const cacheWithoutAdd = script.createCachedData(); | ||
| 159 | + // In `cacheWithoutAdd` the function `add()` is marked for full compilation | ||
| 160 | + // upon invocation. | ||
| 149 | 161 | ||
| 150 | 162 | script.runInThisContext(); | |
| 151 | 163 | ||
| 152 | - const cacheWithX = script.createCachedData(); | ||
| 164 | + const cacheWithAdd = script.createCachedData(); | ||
| 165 | + // `cacheWithAdd` contains fully compiled function `add()`. | ||
| 153 | 166 | ``` | |
| 154 | 167 | ||
| 155 | 168 | ### `script.runInContext(contextifiedObject[, options])` | |
@@ -788,6 +801,16 @@ Creates a code cache that can be used with the `SourceTextModule` constructor's | |||
| 788 | 801 | `cachedData` option. Returns a `Buffer`. This method may be called any number | |
| 789 | 802 | of times before the module has been evaluated. | |
| 790 | 803 | ||
| 804 | + The code cache of the `SourceTextModule` doesn't contain any JavaScript | ||
| 805 | + observable states. The code cache is safe to be saved along side the script | ||
| 806 | + source and used to construct new `SourceTextModule` instances multiple times. | ||
| 807 | + | ||
| 808 | + Functions in the `SourceTextModule` source can be marked as lazily compiled | ||
| 809 | + and they are not compiled at construction of the `SourceTextModule`. These | ||
| 810 | + functions are going to be compiled when they are invoked the first time. The | ||
| 811 | + code cache serializes the metadata that V8 currently knows about the | ||
| 812 | + `SourceTextModule` that it can use to speed up future compilations. | ||
| 813 | + | ||
| 791 | 814 | ```js | |
| 792 | 815 | // Create an initial module | |
| 793 | 816 | const module = new vm.SourceTextModule('const a = 1;'); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments