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

Side by Side Diff: src/objects.cc

Issue 11275292: Object.observe: Move notification of JSArray length changes to JSArray::SetElementsLength (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add test Created 8 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
« no previous file with comments | « src/objects.h ('k') | test/mjsunit/harmony/object-observe.js » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 9360 matching lines...) Expand 10 before | Expand all | Expand 10 after
9371 9371
9372 void JSArray::Expand(int required_size) { 9372 void JSArray::Expand(int required_size) {
9373 GetIsolate()->factory()->SetElementsCapacityAndLength( 9373 GetIsolate()->factory()->SetElementsCapacityAndLength(
9374 Handle<JSArray>(this), required_size, required_size); 9374 Handle<JSArray>(this), required_size, required_size);
9375 } 9375 }
9376 9376
9377 9377
9378 MaybeObject* JSArray::SetElementsLength(Object* len) { 9378 MaybeObject* JSArray::SetElementsLength(Object* len) {
9379 // We should never end in here with a pixel or external array. 9379 // We should never end in here with a pixel or external array.
9380 ASSERT(AllowsSetElementsLength()); 9380 ASSERT(AllowsSetElementsLength());
9381 return GetElementsAccessor()->SetLength(this, len); 9381 if (!(FLAG_harmony_observation && map()->is_observed()))
9382 return GetElementsAccessor()->SetLength(this, len);
9383
9384 Isolate* isolate = GetIsolate();
9385 HandleScope scope(isolate);
9386 Handle<JSArray> self(this);
9387 List<Handle<String> > indices;
9388 List<Handle<Object> > old_values;
9389 Handle<Object> old_length_handle(self->length());
9390 Handle<Object> new_length_handle(len);
9391 uint32_t old_length = 0;
9392 CHECK(old_length_handle->ToArrayIndex(&old_length));
9393 uint32_t new_length = 0;
9394 if (!new_length_handle->ToArrayIndex(&new_length))
9395 return Failure::InternalError();
9396
9397 // TODO(adamk): This loop can be very slow for arrays in dictionary mode.
9398 // Find another way to iterate over arrays with dictionary elements.
9399 for (uint32_t i = old_length - 1; i + 1 > new_length; --i) {
9400 PropertyAttributes attributes = self->GetLocalElementAttribute(i);
9401 if (attributes == ABSENT) continue;
9402 // A non-configurable property will cause the truncation operation to
9403 // stop at this index.
9404 if (attributes == DONT_DELETE) break;
9405 // TODO(adamk): Don't fetch the old value if it's an accessor.
9406 old_values.Add(Object::GetElement(self, i));
9407 indices.Add(isolate->factory()->Uint32ToString(i));
9408 }
9409
9410 MaybeObject* result =
9411 self->GetElementsAccessor()->SetLength(*self, *new_length_handle);
9412 Handle<Object> hresult;
9413 if (!result->ToHandle(&hresult)) return result;
9414
9415 CHECK(self->length()->ToArrayIndex(&new_length));
9416 if (old_length != new_length) {
9417 for (int i = 0; i < indices.length(); ++i) {
9418 JSObject::EnqueueChangeRecord(
9419 self, "deleted", indices[i], old_values[i]);
9420 }
9421 JSObject::EnqueueChangeRecord(
9422 self, "updated", isolate->factory()->length_symbol(),
9423 old_length_handle);
9424 }
9425 return *hresult;
9382 } 9426 }
9383 9427
9384 9428
9385 Map* Map::GetPrototypeTransition(Object* prototype) { 9429 Map* Map::GetPrototypeTransition(Object* prototype) {
9386 FixedArray* cache = GetPrototypeTransitions(); 9430 FixedArray* cache = GetPrototypeTransitions();
9387 int number_of_transitions = NumberOfProtoTransitions(); 9431 int number_of_transitions = NumberOfProtoTransitions();
9388 const int proto_offset = 9432 const int proto_offset =
9389 kProtoTransitionHeaderSize + kProtoTransitionPrototypeOffset; 9433 kProtoTransitionHeaderSize + kProtoTransitionPrototypeOffset;
9390 const int map_offset = kProtoTransitionHeaderSize + kProtoTransitionMapOffset; 9434 const int map_offset = kProtoTransitionHeaderSize + kProtoTransitionMapOffset;
9391 const int step = kProtoTransitionElementsPerEntry; 9435 const int step = kProtoTransitionElementsPerEntry;
(...skipping 4467 matching lines...) Expand 10 before | Expand all | Expand 10 after
13859 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); 13903 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER);
13860 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); 13904 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER);
13861 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); 13905 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER);
13862 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); 13906 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER);
13863 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); 13907 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER);
13864 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); 13908 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER);
13865 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); 13909 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER);
13866 } 13910 }
13867 13911
13868 } } // namespace v8::internal 13912 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | test/mjsunit/harmony/object-observe.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698