Reviewers: rossberg,

Message:
PTAL

Description:
harmony-scoping: Disallow cross-script assignment to const

[email protected]
BUG=v8:2198
LOG=N

Please review this at https://codereview.chromium.org/745963002/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+26, -0 lines):
  M src/hydrogen.cc
  M test/cctest/test-decls.cc


Index: src/hydrogen.cc
diff --git a/src/hydrogen.cc b/src/hydrogen.cc
index 46a3810c75e840f16b9039d86ab9219962e761df..3044622fa35a18265fb9dd696df6a13f7ab64fbf 100644
--- a/src/hydrogen.cc
+++ b/src/hydrogen.cc
@@ -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>(
Index: test/cctest/test-decls.cc
diff --git a/test/cctest/test-decls.cc b/test/cctest/test-decls.cc
index 05f8671f6328f4314c058e481078eb120bda3312..54f0429a5f587893059b52e3e756c7dd2a5bf85b 100644
--- a/test/cctest/test-decls.cc
+++ b/test/cctest/test-decls.cc
@@ -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));
+  }
+}


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to