Author: [email protected]
Date: Wed Jul 1 23:28:37 2009
New Revision: 2326
Modified:
branches/bleeding_edge/src/runtime.cc
branches/bleeding_edge/test/cctest/test-api.cc
branches/bleeding_edge/test/cctest/test-decls.cc
Log:
Make global variable initialization consistent with Firefox and Safari
behavior. Only force the introduction of a variable directly on the
global object if there is an explicit initial value in a variable
declaration.
BUG=http://crbug.com/12548
Review URL: http://codereview.chromium.org/151191
Modified: branches/bleeding_edge/src/runtime.cc
==============================================================================
--- branches/bleeding_edge/src/runtime.cc (original)
+++ branches/bleeding_edge/src/runtime.cc Wed Jul 1 23:28:37 2009
@@ -769,17 +769,23 @@
PropertyAttributes attributes = DONT_DELETE;
// Lookup the property locally in the global object. If it isn't
- // there, we add the property and take special precautions to always
- // add it as a local property even in case of callbacks in the
- // prototype chain (this rules out using SetProperty).
- // We have IgnoreAttributesAndSetLocalProperty for this.
+ // there, there is a property with this name in the prototype chain.
+ // We follow Safari and Firefox behavior and only set the property
+ // locally if there is an explicit initialization value that we have
+ // to assign to the property. When adding the property we take
+ // special precautions to always add it as a local property even in
+ // case of callbacks in the prototype chain (this rules out using
+ // SetProperty). We have IgnoreAttributesAndSetLocalProperty for
+ // this.
LookupResult lookup;
global->LocalLookup(*name, &lookup);
if (!lookup.IsProperty()) {
- Object* value = (assign) ? args[1] : Heap::undefined_value();
- return global->IgnoreAttributesAndSetLocalProperty(*name,
- value,
- attributes);
+ if (assign) {
+ return global->IgnoreAttributesAndSetLocalProperty(*name,
+ args[1],
+ attributes);
+ }
+ return Heap::undefined_value();
}
// Determine if this is a redeclaration of something read-only.
Modified: branches/bleeding_edge/test/cctest/test-api.cc
==============================================================================
--- branches/bleeding_edge/test/cctest/test-api.cc (original)
+++ branches/bleeding_edge/test/cctest/test-api.cc Wed Jul 1 23:28:37 2009
@@ -7024,3 +7024,20 @@
calling_context1.Clear();
calling_context2.Clear();
}
+
+
+// Check that a variable declaration with no explicit initialization
+// value does not shadow an existing property in the prototype chain.
+//
+// This is consistent with Firefox and Safari.
+//
+// See http://crbug.com/12548.
+THREADED_TEST(InitGlobalVarInProtoChain) {
+ v8::HandleScope scope;
+ LocalContext context;
+ // Introduce a variable in the prototype chain.
+ CompileRun("__proto__.x = 42");
+ v8::Handle<v8::Value> result = CompileRun("var x; x");
+ CHECK(!result->IsUndefined());
+ CHECK_EQ(42, result->Int32Value());
+}
Modified: branches/bleeding_edge/test/cctest/test-decls.cc
==============================================================================
--- branches/bleeding_edge/test/cctest/test-decls.cc (original)
+++ branches/bleeding_edge/test/cctest/test-decls.cc Wed Jul 1 23:28:37
2009
@@ -534,10 +534,10 @@
{ ExistsInPrototypeContext context;
context.Check("var x; x",
- 0,
+ 1, // get
0,
1, // declaration
- EXPECT_RESULT, Undefined());
+ EXPECT_EXCEPTION);
}
{ ExistsInPrototypeContext context;
--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---