Skip to content

Commit

Permalink
deps: cherry-pick 0bcb1d6f from upstream V8
Browse files Browse the repository at this point in the history
Original commit message:

    Introduce --disallow-code-generation-from-strings

    Exposing the existing Context::AllowCodeGenerationFromStrings(false) API
    to the command line.

    Bug: v8:7134
    Change-Id: I062ccff0b03c5bcf6878c41c455c0ded37a1d743
    Reviewed-on: https://chromium-review.googlesource.com/809631
    Reviewed-by: Michael Starzinger <mstarzinger@chromium.org>
    Commit-Queue: Jakob Kummerow <jkummerow@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#49911}

PR-URL: #18212
Refs: v8/v8@0bcb1d6
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Gus Caplan <me@gus.host>
  • Loading branch information
jakobkummerow authored and MylesBorins committed Mar 7, 2018
1 parent ae2dabb commit 056001d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

# Reset this number to 0 on major V8 upgrades.
# Increment by one for each non-official patch applied to deps/v8.
'v8_embedder_string': '-node.20',
'v8_embedder_string': '-node.21',

# Enable disassembler for `--print-code` v8 options
'v8_enable_disassembler': 1,
Expand Down
5 changes: 5 additions & 0 deletions deps/v8/src/bootstrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5299,6 +5299,11 @@ Genesis::Genesis(
if (!InstallDebuggerNatives()) return;
}

if (FLAG_disallow_code_generation_from_strings) {
native_context()->set_allow_code_gen_from_strings(
isolate->heap()->false_value());
}

ConfigureUtilsObject(context_type);

// Check that the script context table is empty except for the 'this' binding.
Expand Down
2 changes: 2 additions & 0 deletions deps/v8/src/flag-definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,8 @@ DEFINE_BOOL(expose_trigger_failure, false, "expose trigger-failure extension")
DEFINE_INT(stack_trace_limit, 10, "number of stack frames to capture")
DEFINE_BOOL(builtins_in_stack_traces, false,
"show built-in functions in stack traces")
DEFINE_BOOL(disallow_code_generation_from_strings, false,
"disallow eval and friends")

// builtins.cc
DEFINE_BOOL(allow_unsafe_function_constructor, false,
Expand Down
9 changes: 9 additions & 0 deletions deps/v8/test/mjsunit/disallow-codegen-from-strings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Flags: --disallow-code-generation-from-strings

assertThrows("1 + 1", EvalError);
assertThrows(() => eval("1 + 1"), EvalError);
assertThrows(() => Function("x", "return x + 1"), EvalError);

0 comments on commit 056001d

Please sign in to comment.