Skip to content

Commit

Permalink
module: inline try catch
Browse files Browse the repository at this point in the history
Moving `try / catch` into separate functions is not necessary
anymore due to V8 optimizations.

PR-URL: nodejs#26970
Refs: nodejs#25362
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
  • Loading branch information
BridgeAR committed Apr 4, 2019
1 parent ae9fae8 commit be57761
Show file tree
Hide file tree
Showing 16 changed files with 12 additions and 30 deletions.
12 changes: 4 additions & 8 deletions lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)) {
Expand Down
1 change: 0 additions & 1 deletion test/message/assert_throws_stack.out
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
at *
at *
at *
at *
1 change: 0 additions & 1 deletion test/message/console.out
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ Trace: foo
at *
at *
at *
at *
1 change: 0 additions & 1 deletion test/message/core_line_numbers.out
Original file line number Diff line number Diff line change
Expand Up @@ -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:*:*
1 change: 0 additions & 1 deletion test/message/error_exit.out
Original file line number Diff line number Diff line change
Expand Up @@ -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:*:*
1 change: 0 additions & 1 deletion test/message/events_unhandled_error_common_trace.out
Original file line number Diff line number Diff line change
Expand Up @@ -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:*:*
Expand Down
1 change: 0 additions & 1 deletion test/message/events_unhandled_error_nexttick.out
Original file line number Diff line number Diff line change
Expand Up @@ -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:*:*
Expand Down
1 change: 0 additions & 1 deletion test/message/events_unhandled_error_sameline.out
Original file line number Diff line number Diff line change
Expand Up @@ -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:*:*
Expand Down
2 changes: 1 addition & 1 deletion test/message/if-error-has-good-stack.out
Original file line number Diff line number Diff line change
Expand Up @@ -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:*:*
2 changes: 1 addition & 1 deletion test/message/undefined_reference_in_new_context.out
Original file line number Diff line number Diff line change
Expand Up @@ -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:*:*)
2 changes: 0 additions & 2 deletions test/message/unhandled_promise_trace_warnings.out
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
at *
at *
at *
at *
(node:*) Error: This was rejected
at * (*test*message*unhandled_promise_trace_warnings.js:*)
at *
Expand All @@ -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 *
Expand Down
5 changes: 0 additions & 5 deletions test/message/util_inspect_error.out
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
at *
at *
at *
at *
nested:
{ err:
Error: foo
Expand All @@ -20,7 +19,6 @@
at *
at *
at *
at *
{
err: Error: foo
bar
Expand All @@ -31,7 +29,6 @@
at *
at *
at *
at *
nested: {
err: Error: foo
bar
Expand All @@ -42,7 +39,6 @@
at *
at *
at *
at *
}
}
{ Error: foo
Expand All @@ -54,5 +50,4 @@ bar
at *
at *
at *
at *
foo: 'bar' }
4 changes: 2 additions & 2 deletions test/message/vm_display_runtime_error.out
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
^
Expand All @@ -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:*:*
4 changes: 2 additions & 2 deletions test/message/vm_display_syntax_error.out
Original file line number Diff line number Diff line change
Expand Up @@ -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;
^
Expand All @@ -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:*:*
2 changes: 1 addition & 1 deletion test/message/vm_dont_display_runtime_error.out
Original file line number Diff line number Diff line change
Expand Up @@ -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:*:*
2 changes: 1 addition & 1 deletion test/message/vm_dont_display_syntax_error.out
Original file line number Diff line number Diff line change
Expand Up @@ -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:*:*

0 comments on commit be57761

Please sign in to comment.