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

Side by Side Diff: src/objects.cc

Issue 1178503004: Replace SetObjectProperty / DefineObjectProperty with less powerful alternatives where relevant. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase Created 5 years, 6 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
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.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 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <iomanip> 5 #include <iomanip>
6 #include <sstream> 6 #include <sstream>
7 7
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/accessors.h" 10 #include "src/accessors.h"
(...skipping 3205 matching lines...) Expand 10 before | Expand all | Expand 10 after
3216 Isolate* isolate, Handle<Object> receiver, Handle<Object> name, 3216 Isolate* isolate, Handle<Object> receiver, Handle<Object> name,
3217 Handle<Object> value, LanguageMode language_mode) { 3217 Handle<Object> value, LanguageMode language_mode) {
3218 if (is_sloppy(language_mode)) return value; 3218 if (is_sloppy(language_mode)) return value;
3219 THROW_NEW_ERROR( 3219 THROW_NEW_ERROR(
3220 isolate, 3220 isolate,
3221 NewTypeError(MessageTemplate::kStrictReadOnlyProperty, name, receiver), 3221 NewTypeError(MessageTemplate::kStrictReadOnlyProperty, name, receiver),
3222 Object); 3222 Object);
3223 } 3223 }
3224 3224
3225 3225
3226 MaybeHandle<Object> Object::WriteToReadOnlyElement(Isolate* isolate,
3227 Handle<Object> receiver,
3228 uint32_t index,
3229 Handle<Object> value,
3230 LanguageMode language_mode) {
3231 return WriteToReadOnlyProperty(isolate, receiver,
3232 isolate->factory()->NewNumberFromUint(index),
3233 value, language_mode);
3234 }
3235
3236
3237 MaybeHandle<Object> Object::RedefineNonconfigurableProperty( 3226 MaybeHandle<Object> Object::RedefineNonconfigurableProperty(
3238 Isolate* isolate, Handle<Object> name, Handle<Object> value, 3227 Isolate* isolate, Handle<Object> name, Handle<Object> value,
3239 LanguageMode language_mode) { 3228 LanguageMode language_mode) {
3240 if (is_sloppy(language_mode)) return value; 3229 if (is_sloppy(language_mode)) return value;
3241 THROW_NEW_ERROR(isolate, 3230 THROW_NEW_ERROR(isolate,
3242 NewTypeError(MessageTemplate::kRedefineDisallowed, name), 3231 NewTypeError(MessageTemplate::kRedefineDisallowed, name),
3243 Object); 3232 Object);
3244 } 3233 }
3245 3234
3246 3235
3247 MaybeHandle<Object> Object::SetDataProperty(LookupIterator* it, 3236 MaybeHandle<Object> Object::SetDataProperty(LookupIterator* it,
3248 Handle<Object> value) { 3237 Handle<Object> value) {
3249 // Proxies are handled on the WithHandler path. Other non-JSObjects cannot 3238 // Proxies are handled on the WithHandler path. Other non-JSObjects cannot
3250 // have own properties. 3239 // have own properties.
3251 Handle<JSObject> receiver = Handle<JSObject>::cast(it->GetReceiver()); 3240 Handle<JSObject> receiver = Handle<JSObject>::cast(it->GetReceiver());
3252 3241
3253 // Store on the holder which may be hidden behind the receiver. 3242 // Store on the holder which may be hidden behind the receiver.
3254 DCHECK(it->HolderIsReceiverOrHiddenPrototype()); 3243 DCHECK(it->HolderIsReceiverOrHiddenPrototype());
3255 3244
3256 // Old value for the observation change record. 3245 // Old value for the observation change record.
3257 // Fetch before transforming the object since the encoding may become 3246 // Fetch before transforming the object since the encoding may become
3258 // incompatible with what's cached in |it|. 3247 // incompatible with what's cached in |it|.
3259 bool is_observed = receiver->map()->is_observed() && 3248 bool is_observed = receiver->map()->is_observed() &&
3260 (it->IsElement() || 3249 (it->IsElement() ||
3261 !it->isolate()->IsInternallyUsedPropertyName(it->name())); 3250 !it->isolate()->IsInternallyUsedPropertyName(it->name()));
3262 MaybeHandle<Object> maybe_old; 3251 MaybeHandle<Object> maybe_old;
3263 if (is_observed) maybe_old = it->GetDataValue(); 3252 if (is_observed) maybe_old = it->GetDataValue();
3264 3253
3254 Handle<Object> to_assign = value;
3265 // Convert the incoming value to a number for storing into typed arrays. 3255 // Convert the incoming value to a number for storing into typed arrays.
3266 if (it->IsElement() && (receiver->HasExternalArrayElements() || 3256 if (it->IsElement() && (receiver->HasExternalArrayElements() ||
3267 receiver->HasFixedTypedArrayElements())) { 3257 receiver->HasFixedTypedArrayElements())) {
3268 if (!value->IsNumber() && !value->IsUndefined()) { 3258 if (!value->IsNumber() && !value->IsUndefined()) {
3269 ASSIGN_RETURN_ON_EXCEPTION(it->isolate(), value, 3259 ASSIGN_RETURN_ON_EXCEPTION(it->isolate(), to_assign,
3270 Execution::ToNumber(it->isolate(), value), 3260 Execution::ToNumber(it->isolate(), value),
3271 Object); 3261 Object);
3272 } 3262 }
3273 } 3263 }
3274 3264
3275 // Possibly migrate to the most up-to-date map that will be able to store 3265 // Possibly migrate to the most up-to-date map that will be able to store
3276 // |value| under it->name(). 3266 // |value| under it->name().
3277 it->PrepareForDataProperty(value); 3267 it->PrepareForDataProperty(to_assign);
3278 3268
3279 // Write the property value. 3269 // Write the property value.
3280 value = it->WriteDataValue(value); 3270 it->WriteDataValue(to_assign);
3281 3271
3282 // Send the change record if there are observers. 3272 // Send the change record if there are observers.
3283 if (is_observed && !value->SameValue(*maybe_old.ToHandleChecked())) { 3273 if (is_observed && !value->SameValue(*maybe_old.ToHandleChecked())) {
3284 RETURN_ON_EXCEPTION(it->isolate(), JSObject::EnqueueChangeRecord( 3274 RETURN_ON_EXCEPTION(it->isolate(), JSObject::EnqueueChangeRecord(
3285 receiver, "update", it->GetName(), 3275 receiver, "update", it->GetName(),
3286 maybe_old.ToHandleChecked()), 3276 maybe_old.ToHandleChecked()),
3287 Object); 3277 Object);
3288 } 3278 }
3289 3279
3290 return value; 3280 return value;
(...skipping 956 matching lines...) Expand 10 before | Expand all | Expand 10 after
4247 4237
4248 4238
4249 // Reconfigures a property to a data property with attributes, even if it is not 4239 // Reconfigures a property to a data property with attributes, even if it is not
4250 // reconfigurable. 4240 // reconfigurable.
4251 MaybeHandle<Object> JSObject::SetOwnPropertyIgnoreAttributes( 4241 MaybeHandle<Object> JSObject::SetOwnPropertyIgnoreAttributes(
4252 Handle<JSObject> object, Handle<Name> name, Handle<Object> value, 4242 Handle<JSObject> object, Handle<Name> name, Handle<Object> value,
4253 PropertyAttributes attributes) { 4243 PropertyAttributes attributes) {
4254 DCHECK(!value->IsTheHole()); 4244 DCHECK(!value->IsTheHole());
4255 LookupIterator it(object, name, LookupIterator::OWN_SKIP_INTERCEPTOR); 4245 LookupIterator it(object, name, LookupIterator::OWN_SKIP_INTERCEPTOR);
4256 if (it.state() == LookupIterator::ACCESS_CHECK) { 4246 if (it.state() == LookupIterator::ACCESS_CHECK) {
4257 if (!it.isolate()->MayAccess(object)) { 4247 if (!it.HasAccess()) {
4258 return SetPropertyWithFailedAccessCheck(&it, value, SLOPPY); 4248 return SetPropertyWithFailedAccessCheck(&it, value, SLOPPY);
4259 } 4249 }
4260 it.Next(); 4250 it.Next();
4261 } 4251 }
4262 4252
4263 if (it.IsFound()) { 4253 if (it.IsFound()) {
4264 return ReconfigureAsDataProperty(&it, value, attributes); 4254 return ReconfigureAsDataProperty(&it, value, attributes);
4265 } 4255 }
4266 4256
4267 return AddDataProperty(&it, value, attributes, STRICT, 4257 return AddDataProperty(&it, value, attributes, STRICT,
4268 CERTAINLY_NOT_STORE_FROM_KEYED); 4258 CERTAINLY_NOT_STORE_FROM_KEYED);
4269 } 4259 }
4270 4260
4271 4261
4272 MaybeHandle<Object> JSObject::SetOwnElementIgnoreAttributes( 4262 MaybeHandle<Object> JSObject::SetOwnElementIgnoreAttributes(
4273 Handle<JSObject> object, uint32_t index, Handle<Object> value, 4263 Handle<JSObject> object, uint32_t index, Handle<Object> value,
4274 PropertyAttributes attributes) { 4264 PropertyAttributes attributes) {
4275 DCHECK(!object->HasExternalArrayElements()); 4265 DCHECK(!object->HasExternalArrayElements());
4276 Isolate* isolate = object->GetIsolate(); 4266 Isolate* isolate = object->GetIsolate();
4277 LookupIterator it(isolate, object, index, 4267 LookupIterator it(isolate, object, index,
4278 LookupIterator::OWN_SKIP_INTERCEPTOR); 4268 LookupIterator::OWN_SKIP_INTERCEPTOR);
4279 if (it.state() == LookupIterator::ACCESS_CHECK) { 4269 if (it.state() == LookupIterator::ACCESS_CHECK) {
4280 if (!isolate->MayAccess(object)) { 4270 if (!it.HasAccess()) {
4281 return SetPropertyWithFailedAccessCheck(&it, value, STRICT); 4271 return SetPropertyWithFailedAccessCheck(&it, value, STRICT);
4282 } 4272 }
4283 it.Next(); 4273 it.Next();
4284 } 4274 }
4285 4275
4286 if (it.IsFound()) { 4276 if (it.IsFound()) {
4287 return ReconfigureAsDataProperty(&it, value, attributes); 4277 return ReconfigureAsDataProperty(&it, value, attributes);
4288 } 4278 }
4289 4279
4290 return AddDataProperty(&it, value, attributes, STRICT, 4280 return AddDataProperty(&it, value, attributes, STRICT,
(...skipping 12435 matching lines...) Expand 10 before | Expand all | Expand 10 after
16726 Handle<Object> new_value) { 16716 Handle<Object> new_value) {
16727 if (cell->value() != *new_value) { 16717 if (cell->value() != *new_value) {
16728 cell->set_value(*new_value); 16718 cell->set_value(*new_value);
16729 Isolate* isolate = cell->GetIsolate(); 16719 Isolate* isolate = cell->GetIsolate();
16730 cell->dependent_code()->DeoptimizeDependentCodeGroup( 16720 cell->dependent_code()->DeoptimizeDependentCodeGroup(
16731 isolate, DependentCode::kPropertyCellChangedGroup); 16721 isolate, DependentCode::kPropertyCellChangedGroup);
16732 } 16722 }
16733 } 16723 }
16734 } // namespace internal 16724 } // namespace internal
16735 } // namespace v8 16725 } // namespace v8
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698