From b7aded3300269bc36d1a14b474c4a85e185189d4 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Sat, 3 Nov 2018 14:26:32 +0800 Subject: [PATCH] src: compile native modules and their code cache in C++ This patch refactors out a part of NativeModule.prototype.compile (in JS land) into a C++ NativeModule class, this enables a couple of possibilities: 1. By moving the code to the C++ land, we have more opportunity to specialize the compilation process of the native modules (e.g. compilation options, code cache) that is orthogonal to how user land modules are compiled 2. We can reuse the code to compile bootstrappers and context fixers and enable them to be compiled with the code cache later, since they are not loaded by NativeModule in the JS land their caching must be done in C++. 3. Since there is no need to pass the static data to JS for compilation anymore, this enables us to use (std::map) in the generated node_code_cache.cc and node_javascript.cc later, and scope every actual access to the source of native modules to a std::map lookup instead of a lookup on a v8::Object in dictionary mode. This patch also refactor the code cache generator and tests a bit and trace the `withCodeCache` and `withoutCodeCache` in a Set instead of an Array, and makes sure that all the cachable builtins are tested. PR-URL: https://github.com/nodejs/node/pull/24221 Reviewed-By: Refael Ackermann Reviewed-By: Anna Henningsen --- lib/internal/bootstrap/cache.js | 30 +- lib/internal/bootstrap/loaders.js | 63 +--- node.gyp | 2 + src/env.h | 490 +++++++++++++++-------------- src/node.cc | 27 +- src/node_code_cache.h | 2 + src/node_code_cache_stub.cc | 3 + src/node_internals.h | 1 + src/node_native_module.cc | 326 +++++++++++++++++++ src/node_native_module.h | 41 +++ test/code-cache/test-code-cache.js | 55 ++-- tools/generate_code_cache.js | 4 +- 12 files changed, 680 insertions(+), 364 deletions(-) create mode 100644 src/node_native_module.cc create mode 100644 src/node_native_module.h diff --git a/lib/internal/bootstrap/cache.js b/lib/internal/bootstrap/cache.js index 41159d650bc375..ff6c4422c1148c 100644 --- a/lib/internal/bootstrap/cache.js +++ b/lib/internal/bootstrap/cache.js @@ -8,20 +8,13 @@ const { NativeModule } = require('internal/bootstrap/loaders'); +const { + source, + compileCodeCache +} = internalBinding('native_module'); const { hasTracing } = process.binding('config'); -function getCodeCache(id) { - const cached = NativeModule.getCached(id); - if (cached && (cached.loaded || cached.loading)) { - return cached.script.createCachedData(); - } - - // The script has not been compiled and run - NativeModule.require(id); - return getCodeCache(id); -} - -const depsModule = Object.keys(NativeModule._source).filter( +const depsModule = Object.keys(source).filter( (key) => NativeModule.isDepsModule(key) || key.startsWith('internal/deps') ); @@ -75,17 +68,10 @@ if (!process.versions.openssl) { } module.exports = { - cachableBuiltins: Object.keys(NativeModule._source).filter( + cachableBuiltins: Object.keys(source).filter( (key) => !cannotUseCache.includes(key) ), - builtinSource: Object.assign({}, NativeModule._source), - getCodeCache, - getSource: NativeModule.getSource, - codeCache: internalBinding('code_cache'), - compiledWithoutCache: NativeModule.compiledWithoutCache, - compiledWithCache: NativeModule.compiledWithCache, - nativeModuleWrap(script) { - return NativeModule.wrap(script); - }, + getSource(id) { return source[id]; }, + getCodeCache: compileCodeCache, cannotUseCache }; diff --git a/lib/internal/bootstrap/loaders.js b/lib/internal/bootstrap/loaders.js index 1879c0154c3179..78e1180dde2af2 100644 --- a/lib/internal/bootstrap/loaders.js +++ b/lib/internal/bootstrap/loaders.js @@ -149,7 +149,6 @@ // Create this WeakMap in js-land because V8 has no C++ API for WeakMap internalBinding('module_wrap').callbackMap = new WeakMap(); - const { ContextifyScript } = internalBinding('contextify'); // Set up NativeModule function NativeModule(id) { @@ -160,7 +159,6 @@ this.exportKeys = undefined; this.loaded = false; this.loading = false; - this.script = null; // The ContextifyScript of the module } NativeModule._source = getInternalBinding('natives'); @@ -168,12 +166,6 @@ const config = getBinding('config'); - const codeCache = getInternalBinding('code_cache'); - const codeCacheHash = getInternalBinding('code_cache_hash'); - const sourceHash = getInternalBinding('natives_hash'); - const compiledWithoutCache = NativeModule.compiledWithoutCache = []; - const compiledWithCache = NativeModule.compiledWithCache = []; - // Think of this as module.exports in this file even though it is not // written in CommonJS style. const loaderExports = { internalBinding, NativeModule }; @@ -332,67 +324,18 @@ this.exports = new Proxy(this.exports, handler); }; + const { compileFunction } = getInternalBinding('native_module'); NativeModule.prototype.compile = function() { const id = this.id; - let source = NativeModule.getSource(id); - source = NativeModule.wrap(source); this.loading = true; try { - // Currently V8 only checks that the length of the source code is the - // same as the code used to generate the hash, so we add an additional - // check here: - // 1. During compile time, when generating node_javascript.cc and - // node_code_cache.cc, we compute and include the hash of the - // (unwrapped) JavaScript source in both. - // 2. At runtime, we check that the hash of the code being compiled - // and the hash of the code used to generate the cache - // (inside the wrapper) is the same. - // This is based on the assumptions: - // 1. `internalBinding('code_cache_hash')` must be in sync with - // `internalBinding('code_cache')` (same C++ file) - // 2. `internalBinding('natives_hash')` must be in sync with - // `internalBinding('natives')` (same C++ file) - // 3. If `internalBinding('natives_hash')` is in sync with - // `internalBinding('natives_hash')`, then the (unwrapped) - // code used to generate `internalBinding('code_cache')` - // should be in sync with the (unwrapped) code in - // `internalBinding('natives')` - // There will be, however, false positives if the wrapper used - // to generate the cache is different from the one used at run time, - // and the length of the wrapper somehow stays the same. - // But that should be rare and can be eased once we make the - // two bootstrappers cached and checked as well. - const cache = codeCacheHash[id] && - (codeCacheHash[id] === sourceHash[id]) ? codeCache[id] : undefined; - - // (code, filename, lineOffset, columnOffset - // cachedData, produceCachedData, parsingContext) - const script = new ContextifyScript( - source, this.filename, 0, 0, - cache, false, undefined - ); - - // This will be used to create code cache in tools/generate_code_cache.js - this.script = script; - - // One of these conditions may be false when any of the inputs - // of the `node_js2c` target in node.gyp is modified. - // FIXME(joyeecheung): Figure out how to resolve the dependency issue. - // When the code cache was introduced we were at a point where refactoring - // node.gyp may not be worth the effort. - if (!cache || script.cachedDataRejected) { - compiledWithoutCache.push(this.id); - } else { - compiledWithCache.push(this.id); - } - - // Arguments: timeout, displayErrors, breakOnSigint - const fn = script.runInThisContext(-1, true, false); const requireFn = this.id.startsWith('internal/deps/') ? NativeModule.requireForDeps : NativeModule.require; + + const fn = compileFunction(id); fn(this.exports, requireFn, this, process, internalBinding); if (config.experimentalModules && !NativeModule.isInternal(this.id)) { diff --git a/node.gyp b/node.gyp index 83bd412dea6c9d..5b68281de45790 100644 --- a/node.gyp +++ b/node.gyp @@ -416,6 +416,8 @@ 'src/node_javascript.h', 'src/node_messaging.h', 'src/node_mutex.h', + 'src/node_native_module.h', + 'src/node_native_module.cc', 'src/node_options.h', 'src/node_options-inl.h', 'src/node_perf.h', diff --git a/src/env.h b/src/env.h index 791eda4fd9dc53..d58990567b0b0d 100644 --- a/src/env.h +++ b/src/env.h @@ -115,248 +115,258 @@ struct PackageConfig { // Strings are per-isolate primitives but Environment proxies them // for the sake of convenience. Strings should be ASCII-only. -#define PER_ISOLATE_STRING_PROPERTIES(V) \ - V(address_string, "address") \ - V(aliases_string, "aliases") \ - V(args_string, "args") \ - V(async_ids_stack_string, "async_ids_stack") \ - V(buffer_string, "buffer") \ - V(bytes_parsed_string, "bytesParsed") \ - V(bytes_read_string, "bytesRead") \ - V(bytes_written_string, "bytesWritten") \ - V(cached_data_string, "cachedData") \ - V(cached_data_produced_string, "cachedDataProduced") \ - V(cached_data_rejected_string, "cachedDataRejected") \ - V(change_string, "change") \ - V(channel_string, "channel") \ - V(chunks_sent_since_last_write_string, "chunksSentSinceLastWrite") \ - V(constants_string, "constants") \ - V(oncertcb_string, "oncertcb") \ - V(code_string, "code") \ - V(cwd_string, "cwd") \ - V(dest_string, "dest") \ - V(destroyed_string, "destroyed") \ - V(detached_string, "detached") \ - V(dns_a_string, "A") \ - V(dns_aaaa_string, "AAAA") \ - V(dns_cname_string, "CNAME") \ - V(dns_mx_string, "MX") \ - V(dns_naptr_string, "NAPTR") \ - V(dns_ns_string, "NS") \ - V(dns_ptr_string, "PTR") \ - V(dns_soa_string, "SOA") \ - V(dns_srv_string, "SRV") \ - V(dns_txt_string, "TXT") \ - V(duration_string, "duration") \ - V(emit_warning_string, "emitWarning") \ - V(exchange_string, "exchange") \ - V(encoding_string, "encoding") \ - V(entries_string, "entries") \ - V(entry_type_string, "entryType") \ - V(env_pairs_string, "envPairs") \ - V(env_var_settings_string, "envVarSettings") \ - V(errno_string, "errno") \ - V(error_string, "error") \ - V(exit_code_string, "exitCode") \ - V(expire_string, "expire") \ - V(exponent_string, "exponent") \ - V(exports_string, "exports") \ - V(ext_key_usage_string, "ext_key_usage") \ - V(external_stream_string, "_externalStream") \ - V(family_string, "family") \ - V(fatal_exception_string, "_fatalException") \ - V(fd_string, "fd") \ - V(file_string, "file") \ - V(fingerprint_string, "fingerprint") \ - V(fingerprint256_string, "fingerprint256") \ - V(flags_string, "flags") \ - V(fragment_string, "fragment") \ - V(get_data_clone_error_string, "_getDataCloneError") \ - V(get_shared_array_buffer_id_string, "_getSharedArrayBufferId") \ - V(gid_string, "gid") \ - V(handle_string, "handle") \ - V(help_text_string, "helpText") \ - V(homedir_string, "homedir") \ - V(host_string, "host") \ - V(hostmaster_string, "hostmaster") \ - V(ignore_string, "ignore") \ - V(infoaccess_string, "infoAccess") \ - V(inherit_string, "inherit") \ - V(input_string, "input") \ - V(internal_string, "internal") \ - V(ipv4_string, "IPv4") \ - V(ipv6_string, "IPv6") \ - V(isclosing_string, "isClosing") \ - V(issuer_string, "issuer") \ - V(issuercert_string, "issuerCertificate") \ - V(kill_signal_string, "killSignal") \ - V(kind_string, "kind") \ - V(mac_string, "mac") \ - V(main_string, "main") \ - V(max_buffer_string, "maxBuffer") \ - V(message_string, "message") \ - V(message_port_string, "messagePort") \ - V(message_port_constructor_string, "MessagePort") \ - V(minttl_string, "minttl") \ - V(modulus_string, "modulus") \ - V(name_string, "name") \ - V(netmask_string, "netmask") \ - V(nsname_string, "nsname") \ - V(ocsp_request_string, "OCSPRequest") \ - V(onaltsvc_string, "onaltsvc") \ - V(onchange_string, "onchange") \ - V(onclienthello_string, "onclienthello") \ - V(oncomplete_string, "oncomplete") \ - V(onconnection_string, "onconnection") \ - V(ondone_string, "ondone") \ - V(onerror_string, "onerror") \ - V(onexit_string, "onexit") \ - V(onframeerror_string, "onframeerror") \ - V(ongetpadding_string, "ongetpadding") \ - V(onhandshakedone_string, "onhandshakedone") \ - V(onhandshakestart_string, "onhandshakestart") \ - V(onheaders_string, "onheaders") \ - V(onmessage_string, "onmessage") \ - V(onnewsession_string, "onnewsession") \ - V(onocspresponse_string, "onocspresponse") \ - V(ongoawaydata_string, "ongoawaydata") \ - V(onorigin_string, "onorigin") \ - V(onpriority_string, "onpriority") \ - V(onread_string, "onread") \ - V(onreadstart_string, "onreadstart") \ - V(onreadstop_string, "onreadstop") \ - V(onping_string, "onping") \ - V(onsettings_string, "onsettings") \ - V(onshutdown_string, "onshutdown") \ - V(onsignal_string, "onsignal") \ - V(onstreamclose_string, "onstreamclose") \ - V(ontrailers_string, "ontrailers") \ - V(onunpipe_string, "onunpipe") \ - V(onwrite_string, "onwrite") \ - V(openssl_error_stack, "opensslErrorStack") \ - V(options_string, "options") \ - V(output_string, "output") \ - V(order_string, "order") \ - V(parse_error_string, "Parse Error") \ - V(password_string, "password") \ - V(path_string, "path") \ - V(pending_handle_string, "pendingHandle") \ - V(pid_string, "pid") \ - V(pipe_string, "pipe") \ - V(pipe_target_string, "pipeTarget") \ - V(pipe_source_string, "pipeSource") \ - V(port_string, "port") \ - V(port1_string, "port1") \ - V(port2_string, "port2") \ - V(preference_string, "preference") \ - V(priority_string, "priority") \ - V(promise_string, "promise") \ - V(pubkey_string, "pubkey") \ - V(query_string, "query") \ - V(raw_string, "raw") \ - V(read_host_object_string, "_readHostObject") \ - V(readable_string, "readable") \ - V(reason_string, "reason") \ - V(refresh_string, "refresh") \ - V(regexp_string, "regexp") \ - V(rename_string, "rename") \ - V(replacement_string, "replacement") \ - V(retry_string, "retry") \ - V(scheme_string, "scheme") \ - V(serial_string, "serial") \ - V(scopeid_string, "scopeid") \ - V(serial_number_string, "serialNumber") \ - V(service_string, "service") \ - V(servername_string, "servername") \ - V(session_id_string, "sessionId") \ - V(shell_string, "shell") \ - V(signal_string, "signal") \ - V(sink_string, "sink") \ - V(size_string, "size") \ - V(sni_context_err_string, "Invalid SNI context") \ - V(sni_context_string, "sni_context") \ - V(source_string, "source") \ - V(stack_string, "stack") \ - V(start_time_string, "startTime") \ - V(status_string, "status") \ - V(stdio_string, "stdio") \ - V(subject_string, "subject") \ - V(subjectaltname_string, "subjectaltname") \ - V(syscall_string, "syscall") \ - V(thread_id_string, "threadId") \ - V(ticketkeycallback_string, "onticketkeycallback") \ - V(timeout_string, "timeout") \ - V(tls_ticket_string, "tlsTicket") \ - V(ttl_string, "ttl") \ - V(type_string, "type") \ - V(uid_string, "uid") \ - V(unknown_string, "") \ - V(url_string, "url") \ - V(username_string, "username") \ - V(valid_from_string, "valid_from") \ - V(valid_to_string, "valid_to") \ - V(value_string, "value") \ - V(verify_error_string, "verifyError") \ - V(version_string, "version") \ - V(weight_string, "weight") \ - V(windows_hide_string, "windowsHide") \ - V(windows_verbatim_arguments_string, "windowsVerbatimArguments") \ - V(wrap_string, "wrap") \ - V(writable_string, "writable") \ - V(write_host_object_string, "_writeHostObject") \ - V(write_queue_size_string, "writeQueueSize") \ - V(x_forwarded_string, "x-forwarded-for") \ +#define PER_ISOLATE_STRING_PROPERTIES(V) \ + V(address_string, "address") \ + V(aliases_string, "aliases") \ + V(args_string, "args") \ + V(async_ids_stack_string, "async_ids_stack") \ + V(buffer_string, "buffer") \ + V(bytes_parsed_string, "bytesParsed") \ + V(bytes_read_string, "bytesRead") \ + V(bytes_written_string, "bytesWritten") \ + V(cached_data_string, "cachedData") \ + V(cached_data_produced_string, "cachedDataProduced") \ + V(cached_data_rejected_string, "cachedDataRejected") \ + V(change_string, "change") \ + V(channel_string, "channel") \ + V(chunks_sent_since_last_write_string, "chunksSentSinceLastWrite") \ + V(constants_string, "constants") \ + V(oncertcb_string, "oncertcb") \ + V(code_string, "code") \ + V(cwd_string, "cwd") \ + V(dest_string, "dest") \ + V(destroyed_string, "destroyed") \ + V(detached_string, "detached") \ + V(dns_a_string, "A") \ + V(dns_aaaa_string, "AAAA") \ + V(dns_cname_string, "CNAME") \ + V(dns_mx_string, "MX") \ + V(dns_naptr_string, "NAPTR") \ + V(dns_ns_string, "NS") \ + V(dns_ptr_string, "PTR") \ + V(dns_soa_string, "SOA") \ + V(dns_srv_string, "SRV") \ + V(dns_txt_string, "TXT") \ + V(duration_string, "duration") \ + V(emit_warning_string, "emitWarning") \ + V(exchange_string, "exchange") \ + V(encoding_string, "encoding") \ + V(entries_string, "entries") \ + V(entry_type_string, "entryType") \ + V(env_pairs_string, "envPairs") \ + V(env_var_settings_string, "envVarSettings") \ + V(errno_string, "errno") \ + V(error_string, "error") \ + V(exit_code_string, "exitCode") \ + V(expire_string, "expire") \ + V(exponent_string, "exponent") \ + V(exports_string, "exports") \ + V(ext_key_usage_string, "ext_key_usage") \ + V(external_stream_string, "_externalStream") \ + V(family_string, "family") \ + V(fatal_exception_string, "_fatalException") \ + V(fd_string, "fd") \ + V(file_string, "file") \ + V(fingerprint_string, "fingerprint") \ + V(fingerprint256_string, "fingerprint256") \ + V(flags_string, "flags") \ + V(fragment_string, "fragment") \ + V(get_data_clone_error_string, "_getDataCloneError") \ + V(get_shared_array_buffer_id_string, "_getSharedArrayBufferId") \ + V(gid_string, "gid") \ + V(handle_string, "handle") \ + V(help_text_string, "helpText") \ + V(homedir_string, "homedir") \ + V(host_string, "host") \ + V(hostmaster_string, "hostmaster") \ + V(ignore_string, "ignore") \ + V(infoaccess_string, "infoAccess") \ + V(inherit_string, "inherit") \ + V(input_string, "input") \ + V(internal_string, "internal") \ + V(internal_binding_string, "internalBinding") \ + V(ipv4_string, "IPv4") \ + V(ipv6_string, "IPv6") \ + V(isclosing_string, "isClosing") \ + V(issuer_string, "issuer") \ + V(issuercert_string, "issuerCertificate") \ + V(kill_signal_string, "killSignal") \ + V(kind_string, "kind") \ + V(mac_string, "mac") \ + V(main_string, "main") \ + V(max_buffer_string, "maxBuffer") \ + V(message_string, "message") \ + V(message_port_string, "messagePort") \ + V(message_port_constructor_string, "MessagePort") \ + V(minttl_string, "minttl") \ + V(module_string, "module") \ + V(modulus_string, "modulus") \ + V(name_string, "name") \ + V(netmask_string, "netmask") \ + V(nsname_string, "nsname") \ + V(ocsp_request_string, "OCSPRequest") \ + V(onaltsvc_string, "onaltsvc") \ + V(onchange_string, "onchange") \ + V(onclienthello_string, "onclienthello") \ + V(oncomplete_string, "oncomplete") \ + V(onconnection_string, "onconnection") \ + V(ondone_string, "ondone") \ + V(onerror_string, "onerror") \ + V(onexit_string, "onexit") \ + V(onframeerror_string, "onframeerror") \ + V(ongetpadding_string, "ongetpadding") \ + V(onhandshakedone_string, "onhandshakedone") \ + V(onhandshakestart_string, "onhandshakestart") \ + V(onheaders_string, "onheaders") \ + V(onmessage_string, "onmessage") \ + V(onnewsession_string, "onnewsession") \ + V(onocspresponse_string, "onocspresponse") \ + V(ongoawaydata_string, "ongoawaydata") \ + V(onorigin_string, "onorigin") \ + V(onpriority_string, "onpriority") \ + V(onread_string, "onread") \ + V(onreadstart_string, "onreadstart") \ + V(onreadstop_string, "onreadstop") \ + V(onping_string, "onping") \ + V(onsettings_string, "onsettings") \ + V(onshutdown_string, "onshutdown") \ + V(onsignal_string, "onsignal") \ + V(onstreamclose_string, "onstreamclose") \ + V(ontrailers_string, "ontrailers") \ + V(onunpipe_string, "onunpipe") \ + V(onwrite_string, "onwrite") \ + V(openssl_error_stack, "opensslErrorStack") \ + V(options_string, "options") \ + V(output_string, "output") \ + V(order_string, "order") \ + V(parse_error_string, "Parse Error") \ + V(password_string, "password") \ + V(path_string, "path") \ + V(pending_handle_string, "pendingHandle") \ + V(pid_string, "pid") \ + V(pipe_string, "pipe") \ + V(pipe_target_string, "pipeTarget") \ + V(pipe_source_string, "pipeSource") \ + V(port_string, "port") \ + V(port1_string, "port1") \ + V(port2_string, "port2") \ + V(preference_string, "preference") \ + V(priority_string, "priority") \ + V(process_string, "process") \ + V(promise_string, "promise") \ + V(pubkey_string, "pubkey") \ + V(query_string, "query") \ + V(raw_string, "raw") \ + V(read_host_object_string, "_readHostObject") \ + V(readable_string, "readable") \ + V(reason_string, "reason") \ + V(refresh_string, "refresh") \ + V(regexp_string, "regexp") \ + V(rename_string, "rename") \ + V(replacement_string, "replacement") \ + V(require_string, "require") \ + V(retry_string, "retry") \ + V(scheme_string, "scheme") \ + V(serial_string, "serial") \ + V(scopeid_string, "scopeid") \ + V(serial_number_string, "serialNumber") \ + V(service_string, "service") \ + V(servername_string, "servername") \ + V(session_id_string, "sessionId") \ + V(shell_string, "shell") \ + V(signal_string, "signal") \ + V(sink_string, "sink") \ + V(size_string, "size") \ + V(sni_context_err_string, "Invalid SNI context") \ + V(sni_context_string, "sni_context") \ + V(source_string, "source") \ + V(stack_string, "stack") \ + V(start_time_string, "startTime") \ + V(status_string, "status") \ + V(stdio_string, "stdio") \ + V(subject_string, "subject") \ + V(subjectaltname_string, "subjectaltname") \ + V(syscall_string, "syscall") \ + V(thread_id_string, "threadId") \ + V(ticketkeycallback_string, "onticketkeycallback") \ + V(timeout_string, "timeout") \ + V(tls_ticket_string, "tlsTicket") \ + V(ttl_string, "ttl") \ + V(type_string, "type") \ + V(uid_string, "uid") \ + V(unknown_string, "") \ + V(url_string, "url") \ + V(username_string, "username") \ + V(valid_from_string, "valid_from") \ + V(valid_to_string, "valid_to") \ + V(value_string, "value") \ + V(verify_error_string, "verifyError") \ + V(version_string, "version") \ + V(weight_string, "weight") \ + V(windows_hide_string, "windowsHide") \ + V(windows_verbatim_arguments_string, "windowsVerbatimArguments") \ + V(wrap_string, "wrap") \ + V(writable_string, "writable") \ + V(write_host_object_string, "_writeHostObject") \ + V(write_queue_size_string, "writeQueueSize") \ + V(x_forwarded_string, "x-forwarded-for") \ V(zero_return_string, "ZERO_RETURN") -#define ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES(V) \ - V(as_external, v8::External) \ - V(async_hooks_after_function, v8::Function) \ - V(async_hooks_before_function, v8::Function) \ - V(async_hooks_binding, v8::Object) \ - V(async_hooks_destroy_function, v8::Function) \ - V(async_hooks_init_function, v8::Function) \ - V(async_hooks_promise_resolve_function, v8::Function) \ - V(async_wrap_object_ctor_template, v8::FunctionTemplate) \ - V(async_wrap_ctor_template, v8::FunctionTemplate) \ - V(buffer_prototype_object, v8::Object) \ - V(context, v8::Context) \ - V(domain_callback, v8::Function) \ - V(domexception_function, v8::Function) \ - V(fdclose_constructor_template, v8::ObjectTemplate) \ - V(fd_constructor_template, v8::ObjectTemplate) \ - V(filehandlereadwrap_template, v8::ObjectTemplate) \ - V(fsreqpromise_constructor_template, v8::ObjectTemplate) \ - V(fs_use_promises_symbol, v8::Symbol) \ - V(handle_wrap_ctor_template, v8::FunctionTemplate) \ - V(host_import_module_dynamically_callback, v8::Function) \ - V(host_initialize_import_meta_object_callback, v8::Function) \ - V(http2ping_constructor_template, v8::ObjectTemplate) \ - V(http2settings_constructor_template, v8::ObjectTemplate) \ - V(http2stream_constructor_template, v8::ObjectTemplate) \ - V(immediate_callback_function, v8::Function) \ - V(inspector_console_api_object, v8::Object) \ - V(libuv_stream_wrap_ctor_template, v8::FunctionTemplate) \ - V(message_port, v8::Object) \ - V(message_port_constructor_template, v8::FunctionTemplate) \ - V(pipe_constructor_template, v8::FunctionTemplate) \ - V(performance_entry_callback, v8::Function) \ - V(performance_entry_template, v8::Function) \ - V(process_object, v8::Object) \ - V(promise_handler_function, v8::Function) \ - V(promise_wrap_template, v8::ObjectTemplate) \ - V(sab_lifetimepartner_constructor_template, v8::FunctionTemplate) \ - V(script_context_constructor_template, v8::FunctionTemplate) \ - V(script_data_constructor_function, v8::Function) \ - V(secure_context_constructor_template, v8::FunctionTemplate) \ - V(shutdown_wrap_template, v8::ObjectTemplate) \ - V(tcp_constructor_template, v8::FunctionTemplate) \ - V(tick_callback_function, v8::Function) \ - V(timers_callback_function, v8::Function) \ - V(tls_wrap_constructor_function, v8::Function) \ - V(trace_category_state_function, v8::Function) \ - V(tty_constructor_template, v8::FunctionTemplate) \ - V(udp_constructor_function, v8::Function) \ - V(url_constructor_function, v8::Function) \ +#define ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES(V) \ + V(as_external, v8::External) \ + V(async_hooks_after_function, v8::Function) \ + V(async_hooks_before_function, v8::Function) \ + V(async_hooks_binding, v8::Object) \ + V(async_hooks_destroy_function, v8::Function) \ + V(async_hooks_init_function, v8::Function) \ + V(async_hooks_promise_resolve_function, v8::Function) \ + V(async_wrap_object_ctor_template, v8::FunctionTemplate) \ + V(async_wrap_ctor_template, v8::FunctionTemplate) \ + V(buffer_prototype_object, v8::Object) \ + V(context, v8::Context) \ + V(domain_callback, v8::Function) \ + V(domexception_function, v8::Function) \ + V(fdclose_constructor_template, v8::ObjectTemplate) \ + V(fd_constructor_template, v8::ObjectTemplate) \ + V(filehandlereadwrap_template, v8::ObjectTemplate) \ + V(fsreqpromise_constructor_template, v8::ObjectTemplate) \ + V(fs_use_promises_symbol, v8::Symbol) \ + V(handle_wrap_ctor_template, v8::FunctionTemplate) \ + V(host_import_module_dynamically_callback, v8::Function) \ + V(host_initialize_import_meta_object_callback, v8::Function) \ + V(http2ping_constructor_template, v8::ObjectTemplate) \ + V(http2settings_constructor_template, v8::ObjectTemplate) \ + V(http2stream_constructor_template, v8::ObjectTemplate) \ + V(immediate_callback_function, v8::Function) \ + V(inspector_console_api_object, v8::Object) \ + V(libuv_stream_wrap_ctor_template, v8::FunctionTemplate) \ + V(message_port, v8::Object) \ + V(message_port_constructor_template, v8::FunctionTemplate) \ + V(native_modules_code_cache, v8::Object) \ + V(native_modules_code_cache_hash, v8::Object) \ + V(native_modules_source, v8::Object) \ + V(native_modules_source_hash, v8::Object) \ + V(native_modules_with_cache, v8::Set) \ + V(native_modules_without_cache, v8::Set) \ + V(pipe_constructor_template, v8::FunctionTemplate) \ + V(performance_entry_callback, v8::Function) \ + V(performance_entry_template, v8::Function) \ + V(process_object, v8::Object) \ + V(promise_handler_function, v8::Function) \ + V(promise_wrap_template, v8::ObjectTemplate) \ + V(sab_lifetimepartner_constructor_template, v8::FunctionTemplate) \ + V(script_context_constructor_template, v8::FunctionTemplate) \ + V(script_data_constructor_function, v8::Function) \ + V(secure_context_constructor_template, v8::FunctionTemplate) \ + V(shutdown_wrap_template, v8::ObjectTemplate) \ + V(tcp_constructor_template, v8::FunctionTemplate) \ + V(tick_callback_function, v8::Function) \ + V(timers_callback_function, v8::Function) \ + V(tls_wrap_constructor_function, v8::Function) \ + V(trace_category_state_function, v8::Function) \ + V(tty_constructor_template, v8::FunctionTemplate) \ + V(udp_constructor_function, v8::Function) \ + V(url_constructor_function, v8::Function) \ V(write_wrap_template, v8::ObjectTemplate) class Environment; diff --git a/src/node.cc b/src/node.cc index ca7dd53c19a0c4..4c84f781707b01 100644 --- a/src/node.cc +++ b/src/node.cc @@ -25,10 +25,9 @@ #include "node_errors.h" #include "node_internals.h" #include "node_javascript.h" -#include "node_code_cache.h" +#include "node_native_module.h" +#include "node_perf.h" #include "node_platform.h" -#include "node_version.h" -#include "node_internals.h" #include "node_revert.h" #include "node_version.h" #include "tracing/traced_value.h" @@ -131,6 +130,7 @@ typedef int mode_t; namespace node { +using native_module::NativeModule; using options_parser::kAllowedInEnvironment; using options_parser::kDisallowedInEnvironment; using v8::Array; @@ -771,6 +771,7 @@ static MaybeLocal ExecuteString(Environment* env, try_catch.SetVerbose(false); ScriptOrigin origin(filename); + MaybeLocal