From be577615c8542bc8e294ce83167de259ea7eff34 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Thu, 28 Mar 2019 22:42:06 +0100 Subject: [PATCH] module: inline try catch Moving `try / catch` into separate functions is not necessary anymore due to V8 optimizations. PR-URL: https://github.com/nodejs/node/pull/26970 Refs: https://github.com/nodejs/node/pull/25362 Reviewed-By: Guy Bedford Reviewed-By: Matteo Collina --- lib/internal/modules/cjs/loader.js | 12 ++++-------- test/message/assert_throws_stack.out | 1 - test/message/console.out | 1 - test/message/core_line_numbers.out | 1 - test/message/error_exit.out | 1 - test/message/events_unhandled_error_common_trace.out | 1 - test/message/events_unhandled_error_nexttick.out | 1 - test/message/events_unhandled_error_sameline.out | 1 - test/message/if-error-has-good-stack.out | 2 +- test/message/undefined_reference_in_new_context.out | 2 +- test/message/unhandled_promise_trace_warnings.out | 2 -- test/message/util_inspect_error.out | 5 ----- test/message/vm_display_runtime_error.out | 4 ++-- test/message/vm_display_syntax_error.out | 4 ++-- test/message/vm_dont_display_runtime_error.out | 2 +- test/message/vm_dont_display_syntax_error.out | 2 +- 16 files changed, 12 insertions(+), 30 deletions(-) diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index c2d57f0be6499e..cb80330947d495 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -595,13 +595,7 @@ Module._load = function(request, parent, isMain) { Module._cache[filename] = module; - tryModuleLoad(module, filename); - - return module.exports; -}; - -function tryModuleLoad(module, filename) { - var threw = true; + let threw = true; try { module.load(filename); threw = false; @@ -610,7 +604,9 @@ function tryModuleLoad(module, filename) { delete Module._cache[filename]; } } -} + + return module.exports; +}; Module._resolveFilename = function(request, parent, isMain, options) { if (NativeModule.canBeRequiredByUsers(request)) { diff --git a/test/message/assert_throws_stack.out b/test/message/assert_throws_stack.out index 0457670d6a317c..7d4a7aecbcd410 100644 --- a/test/message/assert_throws_stack.out +++ b/test/message/assert_throws_stack.out @@ -16,4 +16,3 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: at * at * at * - at * diff --git a/test/message/console.out b/test/message/console.out index 0a19ff8be321ff..6d6e2bd1abb5b7 100644 --- a/test/message/console.out +++ b/test/message/console.out @@ -7,4 +7,3 @@ Trace: foo at * at * at * - at * diff --git a/test/message/core_line_numbers.out b/test/message/core_line_numbers.out index 0336e5b451651e..53d3894825b4a4 100644 --- a/test/message/core_line_numbers.out +++ b/test/message/core_line_numbers.out @@ -9,7 +9,6 @@ RangeError: Invalid input at Module._compile (internal/modules/cjs/loader.js:*:*) at Object.Module._extensions..js (internal/modules/cjs/loader.js:*:*) at Module.load (internal/modules/cjs/loader.js:*:*) - at tryModuleLoad (internal/modules/cjs/loader.js:*:*) at Function.Module._load (internal/modules/cjs/loader.js:*:*) at Function.Module.runMain (internal/modules/cjs/loader.js:*:*) at internal/main/run_main_module.js:*:* diff --git a/test/message/error_exit.out b/test/message/error_exit.out index 3364210099ca75..b975d41a55d929 100644 --- a/test/message/error_exit.out +++ b/test/message/error_exit.out @@ -11,7 +11,6 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: at Module._compile (internal/modules/cjs/loader.js:*:*) at Object.Module._extensions..js (internal/modules/cjs/loader.js:*:*) at Module.load (internal/modules/cjs/loader.js:*:*) - at tryModuleLoad (internal/modules/cjs/loader.js:*:*) at Function.Module._load (internal/modules/cjs/loader.js:*:*) at Function.Module.runMain (internal/modules/cjs/loader.js:*:*) at internal/main/run_main_module.js:*:* diff --git a/test/message/events_unhandled_error_common_trace.out b/test/message/events_unhandled_error_common_trace.out index 0d64143c67f865..610ea6064ddc00 100644 --- a/test/message/events_unhandled_error_common_trace.out +++ b/test/message/events_unhandled_error_common_trace.out @@ -9,7 +9,6 @@ Error: foo:bar at Module._compile (internal/modules/cjs/loader.js:*:*) at Object.Module._extensions..js (internal/modules/cjs/loader.js:*:*) at Module.load (internal/modules/cjs/loader.js:*:*) - at tryModuleLoad (internal/modules/cjs/loader.js:*:*) at Function.Module._load (internal/modules/cjs/loader.js:*:*) at Function.Module.runMain (internal/modules/cjs/loader.js:*:*) at internal/main/run_main_module.js:*:* diff --git a/test/message/events_unhandled_error_nexttick.out b/test/message/events_unhandled_error_nexttick.out index d53e96ee21a628..ddb13807eea5b5 100644 --- a/test/message/events_unhandled_error_nexttick.out +++ b/test/message/events_unhandled_error_nexttick.out @@ -7,7 +7,6 @@ Error at Module._compile (internal/modules/cjs/loader.js:*:*) at Object.Module._extensions..js (internal/modules/cjs/loader.js:*:*) at Module.load (internal/modules/cjs/loader.js:*:*) - at tryModuleLoad (internal/modules/cjs/loader.js:*:*) at Function.Module._load (internal/modules/cjs/loader.js:*:*) at Function.Module.runMain (internal/modules/cjs/loader.js:*:*) at internal/main/run_main_module.js:*:* diff --git a/test/message/events_unhandled_error_sameline.out b/test/message/events_unhandled_error_sameline.out index f877b254aafe97..798061a39bac8b 100644 --- a/test/message/events_unhandled_error_sameline.out +++ b/test/message/events_unhandled_error_sameline.out @@ -7,7 +7,6 @@ Error at Module._compile (internal/modules/cjs/loader.js:*:*) at Object.Module._extensions..js (internal/modules/cjs/loader.js:*:*) at Module.load (internal/modules/cjs/loader.js:*:*) - at tryModuleLoad (internal/modules/cjs/loader.js:*:*) at Function.Module._load (internal/modules/cjs/loader.js:*:*) at Function.Module.runMain (internal/modules/cjs/loader.js:*:*) at internal/main/run_main_module.js:*:* diff --git a/test/message/if-error-has-good-stack.out b/test/message/if-error-has-good-stack.out index 2a4dfe8fb26630..c762d74aedbca2 100644 --- a/test/message/if-error-has-good-stack.out +++ b/test/message/if-error-has-good-stack.out @@ -14,6 +14,6 @@ AssertionError [ERR_ASSERTION]: ifError got unwanted exception: test error at Module._compile (internal/modules/cjs/loader.js:*:*) at Object.Module._extensions..js (internal/modules/cjs/loader.js:*:*) at Module.load (internal/modules/cjs/loader.js:*:*) - at tryModuleLoad (internal/modules/cjs/loader.js:*:*) at Function.Module._load (internal/modules/cjs/loader.js:*:*) at Function.Module.runMain (internal/modules/cjs/loader.js:*:*) + at internal/main/run_main_module.js:*:* diff --git a/test/message/undefined_reference_in_new_context.out b/test/message/undefined_reference_in_new_context.out index 6b5fedfa993701..9cc5eced7ceaa2 100644 --- a/test/message/undefined_reference_in_new_context.out +++ b/test/message/undefined_reference_in_new_context.out @@ -12,5 +12,5 @@ ReferenceError: foo is not defined at Module._compile (internal/modules/cjs/loader.js:*) at *..js (internal/modules/cjs/loader.js:*) at Module.load (internal/modules/cjs/loader.js:*) - at tryModuleLoad (internal/modules/cjs/loader.js:*:*) at Function.Module._load (internal/modules/cjs/loader.js:*:*) + at Function.Module.runMain (internal/modules/cjs/loader.js:*:*) diff --git a/test/message/unhandled_promise_trace_warnings.out b/test/message/unhandled_promise_trace_warnings.out index 2d3646b51a203d..13778fb798aa6c 100644 --- a/test/message/unhandled_promise_trace_warnings.out +++ b/test/message/unhandled_promise_trace_warnings.out @@ -12,7 +12,6 @@ at * at * at * - at * (node:*) Error: This was rejected at * (*test*message*unhandled_promise_trace_warnings.js:*) at * @@ -21,7 +20,6 @@ at * at * at * - at * (node:*) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. at * at * diff --git a/test/message/util_inspect_error.out b/test/message/util_inspect_error.out index 31b65eb2e2bf3c..644ccd58831ef7 100644 --- a/test/message/util_inspect_error.out +++ b/test/message/util_inspect_error.out @@ -8,7 +8,6 @@ at * at * at * - at * nested: { err: Error: foo @@ -20,7 +19,6 @@ at * at * at * - at * { err: Error: foo bar @@ -31,7 +29,6 @@ at * at * at * - at * nested: { err: Error: foo bar @@ -42,7 +39,6 @@ at * at * at * - at * } } { Error: foo @@ -54,5 +50,4 @@ bar at * at * at * - at * foo: 'bar' } diff --git a/test/message/vm_display_runtime_error.out b/test/message/vm_display_runtime_error.out index bc95b2a7b092f5..7927510c4152ee 100644 --- a/test/message/vm_display_runtime_error.out +++ b/test/message/vm_display_runtime_error.out @@ -11,9 +11,9 @@ Error: boo! at Module._compile (internal/modules/cjs/loader.js:*) at Object.Module._extensions..js (internal/modules/cjs/loader.js:*) at Module.load (internal/modules/cjs/loader.js:*) - at tryModuleLoad (internal/modules/cjs/loader.js:*:*) at Function.Module._load (internal/modules/cjs/loader.js:*) at Function.Module.runMain (internal/modules/cjs/loader.js:*) + at internal/main/run_main_module.js:*:* test.vm:1 throw new Error("spooky!") ^ @@ -26,6 +26,6 @@ Error: spooky! at Module._compile (internal/modules/cjs/loader.js:*) at Object.Module._extensions..js (internal/modules/cjs/loader.js:*) at Module.load (internal/modules/cjs/loader.js:*) - at tryModuleLoad (internal/modules/cjs/loader.js:*:*) at Function.Module._load (internal/modules/cjs/loader.js:*) at Function.Module.runMain (internal/modules/cjs/loader.js:*) + at internal/main/run_main_module.js:*:* diff --git a/test/message/vm_display_syntax_error.out b/test/message/vm_display_syntax_error.out index f0692723e81257..71d4a0ea1311f9 100644 --- a/test/message/vm_display_syntax_error.out +++ b/test/message/vm_display_syntax_error.out @@ -10,9 +10,9 @@ SyntaxError: Unexpected number at Module._compile (internal/modules/cjs/loader.js:*) at Object.Module._extensions..js (internal/modules/cjs/loader.js:*) at Module.load (internal/modules/cjs/loader.js:*) - at tryModuleLoad (internal/modules/cjs/loader.js:*:*) at Function.Module._load (internal/modules/cjs/loader.js:*) at Function.Module.runMain (internal/modules/cjs/loader.js:*) + at internal/main/run_main_module.js:*:* test.vm:1 var 5; ^ @@ -24,6 +24,6 @@ SyntaxError: Unexpected number at Module._compile (internal/modules/cjs/loader.js:*) at Object.Module._extensions..js (internal/modules/cjs/loader.js:*) at Module.load (internal/modules/cjs/loader.js:*) - at tryModuleLoad (internal/modules/cjs/loader.js:*:*) at Function.Module._load (internal/modules/cjs/loader.js:*) at Function.Module.runMain (internal/modules/cjs/loader.js:*) + at internal/main/run_main_module.js:*:* diff --git a/test/message/vm_dont_display_runtime_error.out b/test/message/vm_dont_display_runtime_error.out index 532cfbf4dd8125..831ec8b6be4eab 100644 --- a/test/message/vm_dont_display_runtime_error.out +++ b/test/message/vm_dont_display_runtime_error.out @@ -12,6 +12,6 @@ Error: boo! at Module._compile (internal/modules/cjs/loader.js:*) at Object.Module._extensions..js (internal/modules/cjs/loader.js:*) at Module.load (internal/modules/cjs/loader.js:*) - at tryModuleLoad (internal/modules/cjs/loader.js:*:*) at Function.Module._load (internal/modules/cjs/loader.js:*) at Function.Module.runMain (internal/modules/cjs/loader.js:*) + at internal/main/run_main_module.js:*:* diff --git a/test/message/vm_dont_display_syntax_error.out b/test/message/vm_dont_display_syntax_error.out index f27cb1a0859d8c..22924e7a6e72e1 100644 --- a/test/message/vm_dont_display_syntax_error.out +++ b/test/message/vm_dont_display_syntax_error.out @@ -12,6 +12,6 @@ SyntaxError: Unexpected number at Module._compile (internal/modules/cjs/loader.js:*) at Object.Module._extensions..js (internal/modules/cjs/loader.js:*) at Module.load (internal/modules/cjs/loader.js:*) - at tryModuleLoad (internal/modules/cjs/loader.js:*:*) at Function.Module._load (internal/modules/cjs/loader.js:*) at Function.Module.runMain (internal/modules/cjs/loader.js:*) + at internal/main/run_main_module.js:*:*