Reviewers: rossberg,
Message:
PTAL
Description:
Implement TDZ in StoreIC for top-level lexicals.
StoreIC::Store was missing a check present in LoadIC::Load.
[email protected]
BUG=v8:3941
LOG=Y
Please review this at https://codereview.chromium.org/1001323002/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+51, -0 lines):
M src/ic/ic.cc
M test/cctest/test-decls.cc
Index: src/ic/ic.cc
diff --git a/src/ic/ic.cc b/src/ic/ic.cc
index
f8c3b0669f09272ee32f029a5dc4c1fb08448b81..92b44217caf3bf796f133fe73e6d41bbc19e2308
100644
--- a/src/ic/ic.cc
+++ b/src/ic/ic.cc
@@ -1558,6 +1558,15 @@ MaybeHandle<Object> StoreIC::Store(Handle<Object>
object, Handle<Name> name,
return TypeError("const_assign", object, name);
}
+ Handle<Object> value =
+ FixedArray::get(script_context, lookup_result.slot_index);
+
+ if (*value == *isolate()->factory()->the_hole_value()) {
+ // Do not install stubs and stay pre-monomorphic for
+ // uninitialized accesses.
+ return ReferenceError("not_defined", name);
+ }
+
if (FLAG_use_ic &&
StoreScriptContextFieldStub::Accepted(&lookup_result)) {
StoreScriptContextFieldStub stub(isolate(), &lookup_result);
Index: test/cctest/test-decls.cc
diff --git a/test/cctest/test-decls.cc b/test/cctest/test-decls.cc
index
f4fa8289e45d0f7aa4d7960ae663c503b2bb24d1..e1450ad297eb5c85e67e33c9aef06c03edbb71c3
100644
--- a/test/cctest/test-decls.cc
+++ b/test/cctest/test-decls.cc
@@ -1183,3 +1183,45 @@ TEST(Regress425510) {
}
}
}
+
+
+TEST(Regress3941) {
+ i::FLAG_harmony_scoping = true;
+ i::FLAG_allow_natives_syntax = true;
+
+ HandleScope handle_scope(CcTest::isolate());
+
+ {
+ SimpleContext context;
+ context.Check("function f() { x = 1; }", EXPECT_RESULT,
+ Undefined(CcTest::isolate()));
+ context.Check("'use strict'; f(); let x = 2; x", EXPECT_EXCEPTION);
+ }
+
+
+ {
+ // Train ICs.
+ SimpleContext context;
+ context.Check("function f() { x = 1; }", EXPECT_RESULT,
+ Undefined(CcTest::isolate()));
+ for (int i = 0; i < 4; i++) {
+ context.Check("f(); x", EXPECT_RESULT,
Number::New(CcTest::isolate(), 1));
+ }
+ context.Check("'use strict'; f(); let x = 2; x", EXPECT_EXCEPTION);
+ }
+
+
+ {
+ // Optimize.
+ SimpleContext context;
+ context.Check("function f() { x = 1; }", EXPECT_RESULT,
+ Undefined(CcTest::isolate()));
+ for (int i = 0; i < 4; i++) {
+ context.Check("f(); x", EXPECT_RESULT,
Number::New(CcTest::isolate(), 1));
+ }
+ context.Check("%OptimizeFunctionOnNextCall(f); f(); x", EXPECT_RESULT,
+ Number::New(CcTest::isolate(), 1));
+
+ context.Check("'use strict'; f(); let x = 2; x", EXPECT_EXCEPTION);
+ }
+}
--
--
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.