|
149 | 149 |
|
150 | 150 | // Create this WeakMap in js-land because V8 has no C++ API for WeakMap
|
151 | 151 | internalBinding('module_wrap').callbackMap = new WeakMap();
|
152 |
| - const { ContextifyScript } = internalBinding('contextify'); |
153 | 152 |
|
154 | 153 | // Set up NativeModule
|
155 | 154 | function NativeModule(id) {
|
|
160 | 159 | this.exportKeys = undefined;
|
161 | 160 | this.loaded = false;
|
162 | 161 | this.loading = false;
|
163 |
| - this.script = null; // The ContextifyScript of the module |
164 | 162 | }
|
165 | 163 |
|
166 | 164 | NativeModule._source = getInternalBinding('natives');
|
167 | 165 | NativeModule._cache = {};
|
168 | 166 |
|
169 | 167 | const config = getBinding('config');
|
170 | 168 |
|
171 |
| - const codeCache = getInternalBinding('code_cache'); |
172 |
| - const codeCacheHash = getInternalBinding('code_cache_hash'); |
173 |
| - const sourceHash = getInternalBinding('natives_hash'); |
174 |
| - const compiledWithoutCache = NativeModule.compiledWithoutCache = []; |
175 |
| - const compiledWithCache = NativeModule.compiledWithCache = []; |
176 |
| - |
177 | 169 | // Think of this as module.exports in this file even though it is not
|
178 | 170 | // written in CommonJS style.
|
179 | 171 | const loaderExports = { internalBinding, NativeModule };
|
|
332 | 324 | this.exports = new Proxy(this.exports, handler);
|
333 | 325 | };
|
334 | 326 |
|
| 327 | + const { compileFunction } = getInternalBinding('native_module'); |
335 | 328 | NativeModule.prototype.compile = function() {
|
336 | 329 | const id = this.id;
|
337 |
| - let source = NativeModule.getSource(id); |
338 |
| - source = NativeModule.wrap(source); |
339 | 330 |
|
340 | 331 | this.loading = true;
|
341 | 332 |
|
342 | 333 | try {
|
343 |
| - // Currently V8 only checks that the length of the source code is the |
344 |
| - // same as the code used to generate the hash, so we add an additional |
345 |
| - // check here: |
346 |
| - // 1. During compile time, when generating node_javascript.cc and |
347 |
| - // node_code_cache.cc, we compute and include the hash of the |
348 |
| - // (unwrapped) JavaScript source in both. |
349 |
| - // 2. At runtime, we check that the hash of the code being compiled |
350 |
| - // and the hash of the code used to generate the cache |
351 |
| - // (inside the wrapper) is the same. |
352 |
| - // This is based on the assumptions: |
353 |
| - // 1. `internalBinding('code_cache_hash')` must be in sync with |
354 |
| - // `internalBinding('code_cache')` (same C++ file) |
355 |
| - // 2. `internalBinding('natives_hash')` must be in sync with |
356 |
| - // `internalBinding('natives')` (same C++ file) |
357 |
| - // 3. If `internalBinding('natives_hash')` is in sync with |
358 |
| - // `internalBinding('natives_hash')`, then the (unwrapped) |
359 |
| - // code used to generate `internalBinding('code_cache')` |
360 |
| - // should be in sync with the (unwrapped) code in |
361 |
| - // `internalBinding('natives')` |
362 |
| - // There will be, however, false positives if the wrapper used |
363 |
| - // to generate the cache is different from the one used at run time, |
364 |
| - // and the length of the wrapper somehow stays the same. |
365 |
| - // But that should be rare and can be eased once we make the |
366 |
| - // two bootstrappers cached and checked as well. |
367 |
| - const cache = codeCacheHash[id] && |
368 |
| - (codeCacheHash[id] === sourceHash[id]) ? codeCache[id] : undefined; |
369 |
| - |
370 |
| - // (code, filename, lineOffset, columnOffset |
371 |
| - // cachedData, produceCachedData, parsingContext) |
372 |
| - const script = new ContextifyScript( |
373 |
| - source, this.filename, 0, 0, |
374 |
| - cache, false, undefined |
375 |
| - ); |
376 |
| - |
377 |
| - // This will be used to create code cache in tools/generate_code_cache.js |
378 |
| - this.script = script; |
379 |
| - |
380 |
| - // One of these conditions may be false when any of the inputs |
381 |
| - // of the `node_js2c` target in node.gyp is modified. |
382 |
| - // FIXME(joyeecheung): Figure out how to resolve the dependency issue. |
383 |
| - // When the code cache was introduced we were at a point where refactoring |
384 |
| - // node.gyp may not be worth the effort. |
385 |
| - if (!cache || script.cachedDataRejected) { |
386 |
| - compiledWithoutCache.push(this.id); |
387 |
| - } else { |
388 |
| - compiledWithCache.push(this.id); |
389 |
| - } |
390 |
| - |
391 |
| - // Arguments: timeout, displayErrors, breakOnSigint |
392 |
| - const fn = script.runInThisContext(-1, true, false); |
393 | 334 | const requireFn = this.id.startsWith('internal/deps/') ?
|
394 | 335 | NativeModule.requireForDeps :
|
395 | 336 | NativeModule.require;
|
| 337 | + |
| 338 | + const fn = compileFunction(id); |
396 | 339 | fn(this.exports, requireFn, this, process, internalBinding);
|
397 | 340 |
|
398 | 341 | if (config.experimentalModules && !NativeModule.isInternal(this.id)) {
|
|
0 commit comments