| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3c53548 commit 0f4e98b
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -549,6 +549,19 @@ Maybe<bool> InitializeContextRuntime(Local<Context> context) { | |||
| 549 | 549 | Isolate* isolate = context->GetIsolate(); | |
| 550 | 550 | HandleScope handle_scope(isolate); | |
| 551 | 551 | ||
| 552 | + // When `IsCodeGenerationFromStringsAllowed` is true, V8 takes the fast path | ||
| 553 | + // and ignores the ModifyCodeGenerationFromStrings callback. Set it to false | ||
| 554 | + // to delegate the code generation validation to | ||
| 555 | + // node::ModifyCodeGenerationFromStrings. | ||
| 556 | + // The `IsCodeGenerationFromStringsAllowed` can be refreshed by V8 according | ||
| 557 | + // to the runtime flags, propagate the value to the embedder data. | ||
| 558 | + bool is_code_generation_from_strings_allowed = | ||
| 559 | + context->IsCodeGenerationFromStringsAllowed(); | ||
| 560 | + context->AllowCodeGenerationFromStrings(false); | ||
| 561 | + context->SetEmbedderData( | ||
| 562 | + ContextEmbedderIndex::kAllowCodeGenerationFromStrings, | ||
| 563 | + is_code_generation_from_strings_allowed ? True(isolate) : False(isolate)); | ||
| 564 | + | ||
| 552 | 565 | if (per_process::cli_options->disable_proto == "") { | |
| 553 | 566 | return Just(true); | |
| 554 | 567 | } | |
@@ -641,11 +654,11 @@ Maybe<bool> InitializeMainContextForSnapshot(Local<Context> context) { | |||
| 641 | 654 | Isolate* isolate = context->GetIsolate(); | |
| 642 | 655 | HandleScope handle_scope(isolate); | |
| 643 | 656 | ||
| 644 | - context->AllowCodeGenerationFromStrings(false); | ||
| 645 | - context->SetEmbedderData( | ||
| 646 | - ContextEmbedderIndex::kAllowCodeGenerationFromStrings, True(isolate)); | ||
| 657 | + // Initialize the default values. | ||
| 647 | 658 | context->SetEmbedderData(ContextEmbedderIndex::kAllowWasmCodeGeneration, | |
| 648 | 659 | True(isolate)); | |
| 660 | + context->SetEmbedderData( | ||
| 661 | + ContextEmbedderIndex::kAllowCodeGenerationFromStrings, True(isolate)); | ||
| 649 | 662 | ||
| 650 | 663 | if (InitializeBaseContextForSnapshot(context).IsNothing()) { | |
| 651 | 664 | return Nothing<bool>(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -855,6 +855,16 @@ const SnapshotData* SnapshotBuilder::GetEmbeddedSnapshotData() { | |||
| 855 | 855 | )"; | |
| 856 | 856 | } | |
| 857 | 857 | ||
| 858 | + // Reset context settings that need to be initialized again after | ||
| 859 | + // deserialization. | ||
| 860 | + static void ResetContextSettingsBeforeSnapshot(Local<Context> context) { | ||
| 861 | + // Reset the AllowCodeGenerationFromStrings flag to true (default value) so | ||
| 862 | + // that it can be re-initialized with v8 flag | ||
| 863 | + // --disallow-code-generation-from-strings and recognized in | ||
| 864 | + // node::InitializeContextRuntime. | ||
| 865 | + context->AllowCodeGenerationFromStrings(true); | ||
| 866 | + } | ||
| 867 | + | ||
| 858 | 868 | Mutex SnapshotBuilder::snapshot_data_mutex_; | |
| 859 | 869 | ||
| 860 | 870 | const std::vector<intptr_t>& SnapshotBuilder::CollectExternalReferences() { | |
@@ -944,6 +954,7 @@ int SnapshotBuilder::Generate(SnapshotData* out, | |||
| 944 | 954 | if (base_context.IsEmpty()) { | |
| 945 | 955 | return BOOTSTRAP_ERROR; | |
| 946 | 956 | } | |
| 957 | + ResetContextSettingsBeforeSnapshot(base_context); | ||
| 947 | 958 | ||
| 948 | 959 | Local<Context> main_context = NewContext(isolate); | |
| 949 | 960 | if (main_context.IsEmpty()) { | |
@@ -1012,6 +1023,8 @@ int SnapshotBuilder::Generate(SnapshotData* out, | |||
| 1012 | 1023 | size_str.c_str()); | |
| 1013 | 1024 | } | |
| 1014 | 1025 | #endif | |
| 1026 | + | ||
| 1027 | + ResetContextSettingsBeforeSnapshot(main_context); | ||
| 1015 | 1028 | } | |
| 1016 | 1029 | ||
| 1017 | 1030 | // Global handles to the contexts can't be disposed before the | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,9 @@ | |||
| 1 | + // Flags: --disallow-code-generation-from-strings | ||
| 2 | + 'use strict'; | ||
| 3 | + | ||
| 4 | + require('../common'); | ||
| 5 | + const assert = require('assert'); | ||
| 6 | + | ||
| 7 | + // Verify that v8 option --disallow-code-generation-from-strings is still | ||
| 8 | + // respected | ||
| 9 | + assert.throws(() => eval('"eval"'), EvalError); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,7 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + require('../common'); | ||
| 4 | + const assert = require('assert'); | ||
| 5 | + | ||
| 6 | + // Verify that eval is allowed by default. | ||
| 7 | + assert.strictEqual(eval('"eval"'), 'eval'); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments