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

Side by Side Diff: src/objects.cc

Issue 10071009: Prepare DefinePropertyAccessor for callback transitions. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 8 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 | « src/objects.h ('k') | no next file » | 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 4392 matching lines...) Expand 10 before | Expand all | Expand 10 after
4403 AccessorPair* accessors; 4403 AccessorPair* accessors;
4404 { MaybeObject* maybe_accessors = GetHeap()->AllocateAccessorPair(); 4404 { MaybeObject* maybe_accessors = GetHeap()->AllocateAccessorPair();
4405 if (!maybe_accessors->To(&accessors)) return maybe_accessors; 4405 if (!maybe_accessors->To(&accessors)) return maybe_accessors;
4406 } 4406 }
4407 accessors->SetComponents(getter, setter); 4407 accessors->SetComponents(getter, setter);
4408 4408
4409 return SetElementCallback(index, accessors, attributes); 4409 return SetElementCallback(index, accessors, attributes);
4410 } 4410 }
4411 4411
4412 4412
4413 MaybeObject* JSObject::CreateAccessorPairFor(String* name) {
4414 LookupResult result(GetHeap()->isolate());
4415 LocalLookupRealNamedProperty(name, &result);
4416 if (result.IsProperty() && result.type() == CALLBACKS) {
4417 ASSERT(!result.IsDontDelete());
4418 Object* obj = result.GetCallbackObject();
4419 if (obj->IsAccessorPair()) {
4420 return AccessorPair::cast(obj)->CopyWithoutTransitions();
4421 }
4422 }
4423 return GetHeap()->AllocateAccessorPair();
4424 }
4425
4426
4413 MaybeObject* JSObject::DefinePropertyAccessor(String* name, 4427 MaybeObject* JSObject::DefinePropertyAccessor(String* name,
4414 Object* getter, 4428 Object* getter,
4415 Object* setter, 4429 Object* setter,
4416 PropertyAttributes attributes) { 4430 PropertyAttributes attributes) {
4417 // Lookup the name.
4418 LookupResult result(GetHeap()->isolate());
4419 LocalLookupRealNamedProperty(name, &result);
4420 if (result.IsFound()) {
4421 if (result.type() == CALLBACKS) {
4422 ASSERT(!result.IsDontDelete());
4423 Object* obj = result.GetCallbackObject();
4424 // Need to preserve old getters/setters.
4425 if (obj->IsAccessorPair()) {
4426 AccessorPair* copy;
4427 { MaybeObject* maybe_copy =
4428 AccessorPair::cast(obj)->CopyWithoutTransitions();
4429 if (!maybe_copy->To(&copy)) return maybe_copy;
4430 }
4431 copy->SetComponents(getter, setter);
4432 // Use set to update attributes.
4433 return SetPropertyCallback(name, copy, attributes);
4434 }
4435 }
4436 }
4437
4438 AccessorPair* accessors; 4431 AccessorPair* accessors;
4439 { MaybeObject* maybe_accessors = GetHeap()->AllocateAccessorPair(); 4432 { MaybeObject* maybe_accessors = CreateAccessorPairFor(name);
4440 if (!maybe_accessors->To(&accessors)) return maybe_accessors; 4433 if (!maybe_accessors->To(&accessors)) return maybe_accessors;
4441 } 4434 }
4442 accessors->SetComponents(getter, setter); 4435 accessors->SetComponents(getter, setter);
4443
4444 return SetPropertyCallback(name, accessors, attributes); 4436 return SetPropertyCallback(name, accessors, attributes);
4445 } 4437 }
4446 4438
4447 4439
4448 bool JSObject::CanSetCallback(String* name) { 4440 bool JSObject::CanSetCallback(String* name) {
4449 ASSERT(!IsAccessCheckNeeded() || 4441 ASSERT(!IsAccessCheckNeeded() ||
4450 GetIsolate()->MayNamedAccess(this, name, v8::ACCESS_SET)); 4442 GetIsolate()->MayNamedAccess(this, name, v8::ACCESS_SET));
4451 4443
4452 // Check if there is an API defined callback object which prohibits 4444 // Check if there is an API defined callback object which prohibits
4453 // callback overwriting in this object or it's prototype chain. 4445 // callback overwriting in this object or it's prototype chain.
(...skipping 8519 matching lines...) Expand 10 before | Expand all | Expand 10 after
12973 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); 12965 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER);
12974 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); 12966 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER);
12975 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); 12967 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER);
12976 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); 12968 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER);
12977 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); 12969 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER);
12978 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); 12970 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER);
12979 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); 12971 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER);
12980 } 12972 }
12981 12973
12982 } } // namespace v8::internal 12974 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698