@@ -647,7 +647,28 @@ static MaybeLocal<Value> ExecuteBootstrapper( |
647 | 647 |
|
648 | 648 | void LoadEnvironment(Environment* env) { |
649 | 649 | RunBootstrapping(env); |
650 | | - StartExecution(env); |
| 650 | + |
| 651 | + // To allow people to extend Node in different ways, this hook allows |
| 652 | + // one to drop a file lib/_third_party_main.js into the build |
| 653 | + // directory which will be executed instead of Node's normal loading. |
| 654 | + if (per_process::native_module_loader.Exists("_third_party_main")) { |
| 655 | + StartExecution(env, "_third_party_main"); |
| 656 | + } else { |
| 657 | + // TODO(joyeecheung): create different scripts for different |
| 658 | + // execution modes: |
| 659 | + // - `main_thread_main.js` when env->is_main_thread() |
| 660 | + // - `worker_thread_main.js` when !env->is_main_thread() |
| 661 | + // - `run_third_party_main.js` for `_third_party_main` |
| 662 | + // - `inspect_main.js` for `node inspect` |
| 663 | + // - `mkcodecache_main.js` for the code cache generator |
| 664 | + // - `print_help_main.js` for --help |
| 665 | + // - `bash_completion_main.js` for --completion-bash |
| 666 | + // - `internal/v8_prof_processor` for --prof-process |
| 667 | + // And leave bootstrap/node.js dedicated to the setup of the environment. |
| 668 | + // We may want to move this switch out of LoadEnvironment, especially for |
| 669 | + // the per-process options. |
| 670 | + StartExecution(env, nullptr); |
| 671 | + } |
651 | 672 | } |
652 | 673 |
|
653 | 674 | void RunBootstrapping(Environment* env) { |
@@ -724,7 +745,7 @@ void RunBootstrapping(Environment* env) { |
724 | 745 | env->set_start_execution_function(start_execution.As<Function>()); |
725 | 746 | } |
726 | 747 |
|
727 | | -void StartExecution(Environment* env) { |
| 748 | +void StartExecution(Environment* env, const char* main_script_id) { |
728 | 749 | HandleScope handle_scope(env->isolate()); |
729 | 750 | // We have to use Local<>::New because of the optimized way in which we access |
730 | 751 | // the object in the env->...() getters, which does not play well with |
@@ -734,8 +755,19 @@ void StartExecution(Environment* env) { |
734 | 755 | env->set_start_execution_function(Local<Function>()); |
735 | 756 |
|
736 | 757 | if (start_execution.IsEmpty()) return; |
| 758 | + |
| 759 | + Local<Value> main_script_v; |
| 760 | + if (main_script_id == nullptr) { |
| 761 | + // TODO(joyeecheung): make this mandatory - we may also create an overload |
| 762 | + // for main_script that is a Local<Function>. |
| 763 | + main_script_v = Undefined(env->isolate()); |
| 764 | + } else { |
| 765 | + main_script_v = OneByteString(env->isolate(), main_script_id); |
| 766 | + } |
| 767 | + |
| 768 | + Local<Value> argv[] = {main_script_v}; |
737 | 769 | USE(start_execution->Call( |
738 | | - env->context(), Undefined(env->isolate()), 0, nullptr)); |
| 770 | + env->context(), Undefined(env->isolate()), arraysize(argv), argv)); |
739 | 771 | } |
740 | 772 |
|
741 | 773 | static void StartInspector(Environment* env, const char* path) { |
|