Skip to content

Commit 3263264

Browse files
BridgeARBethGriggs
authored andcommitted
module: inline try catch
Moving `try / catch` into separate functions is not necessary anymore due to V8 optimizations. PR-URL: #26970 Refs: #25362 Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Signed-off-by: Beth Griggs <Bethany.Griggs@uk.ibm.com>
1 parent e9bffa8 commit 3263264

16 files changed

+12
-30
lines changed

lib/internal/modules/cjs/loader.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -595,13 +595,7 @@ Module._load = function(request, parent, isMain) {
595595

596596
Module._cache[filename] = module;
597597

598-
tryModuleLoad(module, filename);
599-
600-
return module.exports;
601-
};
602-
603-
function tryModuleLoad(module, filename) {
604-
var threw = true;
598+
let threw = true;
605599
try {
606600
module.load(filename);
607601
threw = false;
@@ -610,7 +604,9 @@ function tryModuleLoad(module, filename) {
610604
delete Module._cache[filename];
611605
}
612606
}
613-
}
607+
608+
return module.exports;
609+
};
614610

615611
Module._resolveFilename = function(request, parent, isMain, options) {
616612
if (NativeModule.canBeRequiredByUsers(request)) {

test/message/assert_throws_stack.out

-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,3 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
1616
at *
1717
at *
1818
at *
19-
at *

test/message/console.out

-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@ Trace: foo
77
at *
88
at *
99
at *
10-
at *

test/message/core_line_numbers.out

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ RangeError: Invalid input
99
at Module._compile (internal/modules/cjs/loader.js:*:*)
1010
at Object.Module._extensions..js (internal/modules/cjs/loader.js:*:*)
1111
at Module.load (internal/modules/cjs/loader.js:*:*)
12-
at tryModuleLoad (internal/modules/cjs/loader.js:*:*)
1312
at Function.Module._load (internal/modules/cjs/loader.js:*:*)
1413
at Function.Module.runMain (internal/modules/cjs/loader.js:*:*)
1514
at internal/main/run_main_module.js:*:*

test/message/error_exit.out

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
1111
at Module._compile (internal/modules/cjs/loader.js:*:*)
1212
at Object.Module._extensions..js (internal/modules/cjs/loader.js:*:*)
1313
at Module.load (internal/modules/cjs/loader.js:*:*)
14-
at tryModuleLoad (internal/modules/cjs/loader.js:*:*)
1514
at Function.Module._load (internal/modules/cjs/loader.js:*:*)
1615
at Function.Module.runMain (internal/modules/cjs/loader.js:*:*)
1716
at internal/main/run_main_module.js:*:*

test/message/events_unhandled_error_common_trace.out

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ Error: foo:bar
99
at Module._compile (internal/modules/cjs/loader.js:*:*)
1010
at Object.Module._extensions..js (internal/modules/cjs/loader.js:*:*)
1111
at Module.load (internal/modules/cjs/loader.js:*:*)
12-
at tryModuleLoad (internal/modules/cjs/loader.js:*:*)
1312
at Function.Module._load (internal/modules/cjs/loader.js:*:*)
1413
at Function.Module.runMain (internal/modules/cjs/loader.js:*:*)
1514
at internal/main/run_main_module.js:*:*

test/message/events_unhandled_error_nexttick.out

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ Error
77
at Module._compile (internal/modules/cjs/loader.js:*:*)
88
at Object.Module._extensions..js (internal/modules/cjs/loader.js:*:*)
99
at Module.load (internal/modules/cjs/loader.js:*:*)
10-
at tryModuleLoad (internal/modules/cjs/loader.js:*:*)
1110
at Function.Module._load (internal/modules/cjs/loader.js:*:*)
1211
at Function.Module.runMain (internal/modules/cjs/loader.js:*:*)
1312
at internal/main/run_main_module.js:*:*

test/message/events_unhandled_error_sameline.out

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ Error
77
at Module._compile (internal/modules/cjs/loader.js:*:*)
88
at Object.Module._extensions..js (internal/modules/cjs/loader.js:*:*)
99
at Module.load (internal/modules/cjs/loader.js:*:*)
10-
at tryModuleLoad (internal/modules/cjs/loader.js:*:*)
1110
at Function.Module._load (internal/modules/cjs/loader.js:*:*)
1211
at Function.Module.runMain (internal/modules/cjs/loader.js:*:*)
1312
at internal/main/run_main_module.js:*:*

test/message/if-error-has-good-stack.out

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ AssertionError [ERR_ASSERTION]: ifError got unwanted exception: test error
1414
at Module._compile (internal/modules/cjs/loader.js:*:*)
1515
at Object.Module._extensions..js (internal/modules/cjs/loader.js:*:*)
1616
at Module.load (internal/modules/cjs/loader.js:*:*)
17-
at tryModuleLoad (internal/modules/cjs/loader.js:*:*)
1817
at Function.Module._load (internal/modules/cjs/loader.js:*:*)
1918
at Function.Module.runMain (internal/modules/cjs/loader.js:*:*)
19+
at internal/main/run_main_module.js:*:*

test/message/undefined_reference_in_new_context.out

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ ReferenceError: foo is not defined
1212
at Module._compile (internal/modules/cjs/loader.js:*)
1313
at *..js (internal/modules/cjs/loader.js:*)
1414
at Module.load (internal/modules/cjs/loader.js:*)
15-
at tryModuleLoad (internal/modules/cjs/loader.js:*:*)
1615
at Function.Module._load (internal/modules/cjs/loader.js:*:*)
16+
at Function.Module.runMain (internal/modules/cjs/loader.js:*:*)

test/message/unhandled_promise_trace_warnings.out

-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
at *
1313
at *
1414
at *
15-
at *
1615
(node:*) Error: This was rejected
1716
at * (*test*message*unhandled_promise_trace_warnings.js:*)
1817
at *
@@ -21,7 +20,6 @@
2120
at *
2221
at *
2322
at *
24-
at *
2523
(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.
2624
at *
2725
at *

test/message/util_inspect_error.out

-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
at *
99
at *
1010
at *
11-
at *
1211
nested:
1312
{ err:
1413
Error: foo
@@ -20,7 +19,6 @@
2019
at *
2120
at *
2221
at *
23-
at *
2422
{
2523
err: Error: foo
2624
bar
@@ -31,7 +29,6 @@
3129
at *
3230
at *
3331
at *
34-
at *
3532
nested: {
3633
err: Error: foo
3734
bar
@@ -42,7 +39,6 @@
4239
at *
4340
at *
4441
at *
45-
at *
4642
}
4743
}
4844
{ Error: foo
@@ -54,5 +50,4 @@ bar
5450
at *
5551
at *
5652
at *
57-
at *
5853
foo: 'bar' }

test/message/vm_display_runtime_error.out

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ Error: boo!
1111
at Module._compile (internal/modules/cjs/loader.js:*)
1212
at Object.Module._extensions..js (internal/modules/cjs/loader.js:*)
1313
at Module.load (internal/modules/cjs/loader.js:*)
14-
at tryModuleLoad (internal/modules/cjs/loader.js:*:*)
1514
at Function.Module._load (internal/modules/cjs/loader.js:*)
1615
at Function.Module.runMain (internal/modules/cjs/loader.js:*)
16+
at internal/main/run_main_module.js:*:*
1717
test.vm:1
1818
throw new Error("spooky!")
1919
^
@@ -26,6 +26,6 @@ Error: spooky!
2626
at Module._compile (internal/modules/cjs/loader.js:*)
2727
at Object.Module._extensions..js (internal/modules/cjs/loader.js:*)
2828
at Module.load (internal/modules/cjs/loader.js:*)
29-
at tryModuleLoad (internal/modules/cjs/loader.js:*:*)
3029
at Function.Module._load (internal/modules/cjs/loader.js:*)
3130
at Function.Module.runMain (internal/modules/cjs/loader.js:*)
31+
at internal/main/run_main_module.js:*:*

test/message/vm_display_syntax_error.out

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ SyntaxError: Unexpected number
1010
at Module._compile (internal/modules/cjs/loader.js:*)
1111
at Object.Module._extensions..js (internal/modules/cjs/loader.js:*)
1212
at Module.load (internal/modules/cjs/loader.js:*)
13-
at tryModuleLoad (internal/modules/cjs/loader.js:*:*)
1413
at Function.Module._load (internal/modules/cjs/loader.js:*)
1514
at Function.Module.runMain (internal/modules/cjs/loader.js:*)
15+
at internal/main/run_main_module.js:*:*
1616
test.vm:1
1717
var 5;
1818
^
@@ -24,6 +24,6 @@ SyntaxError: Unexpected number
2424
at Module._compile (internal/modules/cjs/loader.js:*)
2525
at Object.Module._extensions..js (internal/modules/cjs/loader.js:*)
2626
at Module.load (internal/modules/cjs/loader.js:*)
27-
at tryModuleLoad (internal/modules/cjs/loader.js:*:*)
2827
at Function.Module._load (internal/modules/cjs/loader.js:*)
2928
at Function.Module.runMain (internal/modules/cjs/loader.js:*)
29+
at internal/main/run_main_module.js:*:*

test/message/vm_dont_display_runtime_error.out

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ Error: boo!
1212
at Module._compile (internal/modules/cjs/loader.js:*)
1313
at Object.Module._extensions..js (internal/modules/cjs/loader.js:*)
1414
at Module.load (internal/modules/cjs/loader.js:*)
15-
at tryModuleLoad (internal/modules/cjs/loader.js:*:*)
1615
at Function.Module._load (internal/modules/cjs/loader.js:*)
1716
at Function.Module.runMain (internal/modules/cjs/loader.js:*)
17+
at internal/main/run_main_module.js:*:*

test/message/vm_dont_display_syntax_error.out

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ SyntaxError: Unexpected number
1212
at Module._compile (internal/modules/cjs/loader.js:*)
1313
at Object.Module._extensions..js (internal/modules/cjs/loader.js:*)
1414
at Module.load (internal/modules/cjs/loader.js:*)
15-
at tryModuleLoad (internal/modules/cjs/loader.js:*:*)
1615
at Function.Module._load (internal/modules/cjs/loader.js:*)
1716
at Function.Module.runMain (internal/modules/cjs/loader.js:*)
17+
at internal/main/run_main_module.js:*:*

0 commit comments

Comments
 (0)