Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(628)

Side by Side Diff: src/ast.cc

Issue 4004006: Fix a bug that prevents constants from overwriting function values in object ... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 return Token::ILLEGAL; 133 return Token::ILLEGAL;
134 } 134 }
135 135
136 136
137 bool FunctionLiteral::AllowsLazyCompilation() { 137 bool FunctionLiteral::AllowsLazyCompilation() {
138 return scope()->AllowsLazyCompilation(); 138 return scope()->AllowsLazyCompilation();
139 } 139 }
140 140
141 141
142 ObjectLiteral::Property::Property(Literal* key, Expression* value) { 142 ObjectLiteral::Property::Property(Literal* key, Expression* value) {
143 emit_store_ = true;
143 key_ = key; 144 key_ = key;
144 value_ = value; 145 value_ = value;
145 Object* k = *key->handle(); 146 Object* k = *key->handle();
146 if (k->IsSymbol() && Heap::Proto_symbol()->Equals(String::cast(k))) { 147 if (k->IsSymbol() && Heap::Proto_symbol()->Equals(String::cast(k))) {
147 kind_ = PROTOTYPE; 148 kind_ = PROTOTYPE;
148 } else if (value_->AsMaterializedLiteral() != NULL) { 149 } else if (value_->AsMaterializedLiteral() != NULL) {
149 kind_ = MATERIALIZED_LITERAL; 150 kind_ = MATERIALIZED_LITERAL;
150 } else if (value_->AsLiteral() != NULL) { 151 } else if (value_->AsLiteral() != NULL) {
151 kind_ = CONSTANT; 152 kind_ = CONSTANT;
152 } else { 153 } else {
153 kind_ = COMPUTED; 154 kind_ = COMPUTED;
154 } 155 }
155 } 156 }
156 157
157 158
158 ObjectLiteral::Property::Property(bool is_getter, FunctionLiteral* value) { 159 ObjectLiteral::Property::Property(bool is_getter, FunctionLiteral* value) {
160 emit_store_ = true;
159 key_ = new Literal(value->name()); 161 key_ = new Literal(value->name());
160 value_ = value; 162 value_ = value;
161 kind_ = is_getter ? GETTER : SETTER; 163 kind_ = is_getter ? GETTER : SETTER;
162 } 164 }
163 165
164 166
165 bool ObjectLiteral::Property::IsCompileTimeValue() { 167 bool ObjectLiteral::Property::IsCompileTimeValue() {
166 return kind_ == CONSTANT || 168 return kind_ == CONSTANT ||
167 (kind_ == MATERIALIZED_LITERAL && 169 (kind_ == MATERIALIZED_LITERAL &&
168 CompileTimeValue::IsCompileTimeValue(value_)); 170 CompileTimeValue::IsCompileTimeValue(value_));
169 } 171 }
170 172
171 173
174 void ObjectLiteral::Property::set_emit_store(bool emit_store) {
175 emit_store_ = emit_store;
176 }
177
178
179 bool ObjectLiteral::Property::emit_store() {
180 return emit_store_;
181 }
182
183
184 bool IsEqualString(void* first, void* second) {
185 Handle<String> h1(reinterpret_cast<String**>(first));
186 Handle<String> h2(reinterpret_cast<String**>(second));
187 return (*h1)->Equals(*h2);
188 }
189
190 bool IsEqualSmi(void* first, void* second) {
191 Handle<Smi> h1(reinterpret_cast<Smi**>(first));
192 Handle<Smi> h2(reinterpret_cast<Smi**>(second));
193 return (*h1)->value() == (*h2)->value();
194 }
195
196 void ObjectLiteral::CalculateEmitStore() {
197 HashMap properties(&IsEqualString);
198 HashMap elements(&IsEqualSmi);
199 for (int i = this->properties()->length() - 1; i >= 0; i--) {
200 ObjectLiteral::Property* property = this->properties()->at(i);
201 Literal* literal = property->key();
202 Handle<Object> handle = literal->handle();
203
204 if (handle->IsNull()) {
205 continue;
206 }
207
208 uint32_t hash;
209 HashMap* table;
210 void* key;
211 uint32_t index;
212 if (handle->IsSymbol()) {
213 Handle<String> name(String::cast(*handle));
214 ASSERT(!name->AsArrayIndex(&index));
215 key = name.location();
216 hash = name->Hash();
217 table = &properties;
218 } else if (handle->ToArrayIndex(&index)) {
219 key = handle.location();
220 hash = index;
221 table = &elements;
222 } else {
223 ASSERT(handle->IsNumber());
224 double num = handle->Number();
225 char arr[100];
226 Vector<char> buffer(arr, ARRAY_SIZE(arr));
227 const char* str = DoubleToCString(num, buffer);
228 Handle<String> name = Factory::NewStringFromAscii(CStrVector(str));
229 key = name.location();
230 hash = name->Hash();
231 table = &properties;
232 }
233 // If the key of a computed property is in the table, do not emit
234 // a store for the property later.
235 if (property->kind() == ObjectLiteral::Property::COMPUTED) {
236 if (table->Lookup(literal, hash, false) != NULL) {
237 property->set_emit_store(false);
238 }
239 }
240 // Add key to the table.
241 table->Lookup(literal, hash, true);
242 }
243 }
244
245
172 void TargetCollector::AddTarget(BreakTarget* target) { 246 void TargetCollector::AddTarget(BreakTarget* target) {
173 // Add the label to the collector, but discard duplicates. 247 // Add the label to the collector, but discard duplicates.
174 int length = targets_->length(); 248 int length = targets_->length();
175 for (int i = 0; i < length; i++) { 249 for (int i = 0; i < length; i++) {
176 if (targets_->at(i) == target) return; 250 if (targets_->at(i) == target) return;
177 } 251 }
178 targets_->Add(target); 252 targets_->Add(target);
179 } 253 }
180 254
181 255
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 cond_(NULL), 747 cond_(NULL),
674 may_have_function_literal_(true) { 748 may_have_function_literal_(true) {
675 } 749 }
676 750
677 751
678 CaseClause::CaseClause(Expression* label, ZoneList<Statement*>* statements) 752 CaseClause::CaseClause(Expression* label, ZoneList<Statement*>* statements)
679 : label_(label), statements_(statements) { 753 : label_(label), statements_(statements) {
680 } 754 }
681 755
682 } } // namespace v8::internal 756 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/ast.h ('k') | src/ia32/codegen-ia32.cc » ('j') | src/ia32/full-codegen-ia32.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698