summaryrefslogtreecommitdiff
path: root/src/node_contextify.cc
diff options
context:
space:
mode:
authorGus Caplan <me@gus.host>2018-02-26 14:29:41 -0600
committerGus Caplan <me@gus.host>2018-03-12 14:39:21 -0500
commitcb5f358ee7461f191db8c88e0af26023558f5232 (patch)
treef23e34d68a09fb05d044f00bd795575db63a9370 /src/node_contextify.cc
parenta03c90b661f69200f124718b56b55b0cb3506c71 (diff)
downloadnode-new-cb5f358ee7461f191db8c88e0af26023558f5232.tar.gz
vm: add code generation options
Adds options to a VM Context to disable code generation from strings (such as eval or new Function) and WASM code generation (WebAssembly.compile). PR-URL: https://github.com/nodejs/node/pull/19016 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Diffstat (limited to 'src/node_contextify.cc')
-rw-r--r--src/node_contextify.cc24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/node_contextify.cc b/src/node_contextify.cc
index d267a5180f..a7f46f6126 100644
--- a/src/node_contextify.cc
+++ b/src/node_contextify.cc
@@ -185,6 +185,30 @@ Local<Context> ContextifyContext::CreateV8Context(
CHECK(name->IsString());
Utf8Value name_val(env->isolate(), name);
+ Local<Value> codegen = options_obj->Get(env->context(),
+ FIXED_ONE_BYTE_STRING(env->isolate(), "codeGeneration"))
+ .ToLocalChecked();
+
+ if (!codegen->IsUndefined()) {
+ CHECK(codegen->IsObject());
+ Local<Object> codegen_obj = codegen.As<Object>();
+
+ Local<Value> allow_code_gen_from_strings =
+ codegen_obj->Get(env->context(),
+ FIXED_ONE_BYTE_STRING(env->isolate(), "strings"))
+ .ToLocalChecked();
+ ctx->AllowCodeGenerationFromStrings(
+ allow_code_gen_from_strings->IsUndefined() ||
+ allow_code_gen_from_strings->IsTrue());
+
+ Local<Value> allow_wasm_code_gen = codegen_obj->Get(env->context(),
+ FIXED_ONE_BYTE_STRING(env->isolate(), "wasm"))
+ .ToLocalChecked();
+ ctx->SetEmbedderData(ContextEmbedderIndex::kAllowWasmCodeGeneration,
+ Boolean::New(env->isolate(), allow_wasm_code_gen->IsUndefined() ||
+ allow_wasm_code_gen->IsTrue()));
+ }
+
ContextInfo info(*name_val);
Local<Value> origin =