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

Side by Side Diff: src/ast.cc

Issue 6410028: Fix bug in object literals with large array indexes as strings. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge/build-ia32
Patch Set: Created 9 years, 10 months 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
« no previous file with comments | « no previous file | src/hashmap.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 208
209 209
210 bool IsEqualString(void* first, void* second) { 210 bool IsEqualString(void* first, void* second) {
211 ASSERT((*reinterpret_cast<String**>(first))->IsString()); 211 ASSERT((*reinterpret_cast<String**>(first))->IsString());
212 ASSERT((*reinterpret_cast<String**>(second))->IsString()); 212 ASSERT((*reinterpret_cast<String**>(second))->IsString());
213 Handle<String> h1(reinterpret_cast<String**>(first)); 213 Handle<String> h1(reinterpret_cast<String**>(first));
214 Handle<String> h2(reinterpret_cast<String**>(second)); 214 Handle<String> h2(reinterpret_cast<String**>(second));
215 return (*h1)->Equals(*h2); 215 return (*h1)->Equals(*h2);
216 } 216 }
217 217
218 bool IsEqualSmi(void* first, void* second) { 218
219 ASSERT((*reinterpret_cast<Smi**>(first))->IsSmi()); 219 bool IsEqualNumber(void* first, void* second) {
220 ASSERT((*reinterpret_cast<Smi**>(second))->IsSmi()); 220 ASSERT((*reinterpret_cast<Object**>(first))->IsNumber());
221 Handle<Smi> h1(reinterpret_cast<Smi**>(first)); 221 ASSERT((*reinterpret_cast<Object**>(second))->IsNumber());
222 Handle<Smi> h2(reinterpret_cast<Smi**>(second)); 222
223 return (*h1)->value() == (*h2)->value(); 223 Handle<Object> h1(reinterpret_cast<Object**>(first));
224 Handle<Object> h2(reinterpret_cast<Object**>(second));
225 if (h1->IsSmi()) {
226 return h2->IsSmi() && *h1 == *h2;
227 }
228 if (h2->IsSmi()) return false;
229 Handle<HeapNumber> n1 = Handle<HeapNumber>::cast(h1);
230 Handle<HeapNumber> n2 = Handle<HeapNumber>::cast(h2);
231 ASSERT(isfinite(n1->value()));
232 ASSERT(isfinite(n2->value()));
233 return n1->value() == n2->value();
224 } 234 }
225 235
236
226 void ObjectLiteral::CalculateEmitStore() { 237 void ObjectLiteral::CalculateEmitStore() {
227 HashMap properties(&IsEqualString); 238 HashMap properties(&IsEqualString);
228 HashMap elements(&IsEqualSmi); 239 HashMap elements(&IsEqualNumber);
229 for (int i = this->properties()->length() - 1; i >= 0; i--) { 240 for (int i = this->properties()->length() - 1; i >= 0; i--) {
230 ObjectLiteral::Property* property = this->properties()->at(i); 241 ObjectLiteral::Property* property = this->properties()->at(i);
231 Literal* literal = property->key(); 242 Literal* literal = property->key();
232 Handle<Object> handle = literal->handle(); 243 Handle<Object> handle = literal->handle();
233 244
234 if (handle->IsNull()) { 245 if (handle->IsNull()) {
235 continue; 246 continue;
236 } 247 }
237 248
238 uint32_t hash; 249 uint32_t hash;
239 HashMap* table; 250 HashMap* table;
240 void* key; 251 void* key;
241 uint32_t index;
242 Smi* smi_key_location;
243 if (handle->IsSymbol()) { 252 if (handle->IsSymbol()) {
244 Handle<String> name(String::cast(*handle)); 253 Handle<String> name(String::cast(*handle));
245 if (name->AsArrayIndex(&index)) { 254 if (name->AsArrayIndex(&hash)) {
246 smi_key_location = Smi::FromInt(index); 255 Handle<Object> key_handle = Factory::NewNumberFromUint(hash);
247 key = &smi_key_location; 256 key = key_handle.location();
248 hash = index;
249 table = &elements; 257 table = &elements;
250 } else { 258 } else {
251 key = name.location(); 259 key = name.location();
252 hash = name->Hash(); 260 hash = name->Hash();
253 table = &properties; 261 table = &properties;
254 } 262 }
255 } else if (handle->ToArrayIndex(&index)) { 263 } else if (handle->ToArrayIndex(&hash)) {
256 key = handle.location(); 264 key = handle.location();
257 hash = index;
258 table = &elements; 265 table = &elements;
259 } else { 266 } else {
260 ASSERT(handle->IsNumber()); 267 ASSERT(handle->IsNumber());
261 double num = handle->Number(); 268 double num = handle->Number();
262 char arr[100]; 269 char arr[100];
263 Vector<char> buffer(arr, ARRAY_SIZE(arr)); 270 Vector<char> buffer(arr, ARRAY_SIZE(arr));
264 const char* str = DoubleToCString(num, buffer); 271 const char* str = DoubleToCString(num, buffer);
265 Handle<String> name = Factory::NewStringFromAscii(CStrVector(str)); 272 Handle<String> name = Factory::NewStringFromAscii(CStrVector(str));
266 key = name.location(); 273 key = name.location();
267 hash = name->Hash(); 274 hash = name->Hash();
(...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 1056
1050 CaseClause::CaseClause(Expression* label, 1057 CaseClause::CaseClause(Expression* label,
1051 ZoneList<Statement*>* statements, 1058 ZoneList<Statement*>* statements,
1052 int pos) 1059 int pos)
1053 : label_(label), 1060 : label_(label),
1054 statements_(statements), 1061 statements_(statements),
1055 position_(pos), 1062 position_(pos),
1056 compare_type_(NONE) {} 1063 compare_type_(NONE) {}
1057 1064
1058 } } // namespace v8::internal 1065 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/hashmap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698