Commit 4d4ed236 authored by dslomov's avatar dslomov Committed by Commit bot

harmony-scoping: Disallow cross-script assignment to const

R=rossberg@chromium.org
BUG=v8:2198
LOG=N

Review URL: https://codereview.chromium.org/745963002

Cr-Commit-Position: refs/heads/master@{#25468}
parent 7aad1d2e
......@@ -6556,6 +6556,9 @@ void HOptimizedGraphBuilder::HandleGlobalVariableAssignment(
global->native_context()->script_context_table());
ScriptContextTable::LookupResult lookup;
if (ScriptContextTable::Lookup(script_contexts, var->name(), &lookup)) {
if (lookup.mode == CONST) {
return Bailout(kNonInitializerAssignmentToConst);
}
Handle<Context> script_context =
ScriptContextTable::GetContext(script_contexts, lookup.context_index);
HStoreNamedField* instr = Add<HStoreNamedField>(
......
......@@ -1136,3 +1136,26 @@ TEST(CrossScriptStoreICs) {
Number::New(CcTest::isolate(), 20));
}
}
TEST(CrossScriptAssignmentToConst) {
i::FLAG_harmony_scoping = true;
i::FLAG_allow_natives_syntax = true;
HandleScope handle_scope(CcTest::isolate());
{
SimpleContext context;
context.Check("function f() { x = 27; }", EXPECT_RESULT,
Undefined(CcTest::isolate()));
context.Check("'use strict';const x = 1; x", EXPECT_RESULT,
Number::New(CcTest::isolate(), 1));
context.Check("f();", EXPECT_EXCEPTION);
context.Check("x", EXPECT_RESULT, Number::New(CcTest::isolate(), 1));
context.Check("f();", EXPECT_EXCEPTION);
context.Check("x", EXPECT_RESULT, Number::New(CcTest::isolate(), 1));
context.Check("%OptimizeFunctionOnNextCall(f);f();", EXPECT_EXCEPTION);
context.Check("x", EXPECT_RESULT, Number::New(CcTest::isolate(), 1));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment