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

Side by Side Diff: src/objects.cc

Issue 26592012: Prevent changes to hidden properties from being observable via Object.observe (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: moar Created 7 years, 2 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 | test/cctest/test-object-observe.cc » ('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 // 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 2119 matching lines...) Expand 10 before | Expand all | Expand 10 after
2130 } else { 2130 } else {
2131 // Normalize the object to prevent very large instance descriptors. 2131 // Normalize the object to prevent very large instance descriptors.
2132 // This eliminates unwanted N^2 allocation and lookup behavior. 2132 // This eliminates unwanted N^2 allocation and lookup behavior.
2133 NormalizeProperties(object, CLEAR_INOBJECT_PROPERTIES, 0); 2133 NormalizeProperties(object, CLEAR_INOBJECT_PROPERTIES, 0);
2134 AddSlowProperty(object, name, value, attributes); 2134 AddSlowProperty(object, name, value, attributes);
2135 } 2135 }
2136 } else { 2136 } else {
2137 AddSlowProperty(object, name, value, attributes); 2137 AddSlowProperty(object, name, value, attributes);
2138 } 2138 }
2139 2139
2140 if (FLAG_harmony_observation && object->map()->is_observed()) { 2140 if (FLAG_harmony_observation &&
2141 object->map()->is_observed() &&
2142 *name != isolate->heap()->hidden_string()) {
2141 Handle<Object> old_value = isolate->factory()->the_hole_value(); 2143 Handle<Object> old_value = isolate->factory()->the_hole_value();
2142 EnqueueChangeRecord(object, "new", name, old_value); 2144 EnqueueChangeRecord(object, "new", name, old_value);
2143 } 2145 }
2144 2146
2145 return value; 2147 return value;
2146 } 2148 }
2147 2149
2148 2150
2149 void JSObject::EnqueueChangeRecord(Handle<JSObject> object, 2151 void JSObject::EnqueueChangeRecord(Handle<JSObject> object,
2150 const char* type_str, 2152 const char* type_str,
(...skipping 1857 matching lines...) Expand 10 before | Expand all | Expand 10 after
4008 Handle<Object> error = isolate->factory()->NewTypeError( 4010 Handle<Object> error = isolate->factory()->NewTypeError(
4009 "strict_read_only_property", HandleVector(args, ARRAY_SIZE(args))); 4011 "strict_read_only_property", HandleVector(args, ARRAY_SIZE(args)));
4010 isolate->Throw(*error); 4012 isolate->Throw(*error);
4011 return Handle<Object>(); 4013 return Handle<Object>();
4012 } else { 4014 } else {
4013 return value; 4015 return value;
4014 } 4016 }
4015 } 4017 }
4016 4018
4017 Handle<Object> old_value = isolate->factory()->the_hole_value(); 4019 Handle<Object> old_value = isolate->factory()->the_hole_value();
4018 if (FLAG_harmony_observation && 4020 bool is_observed = FLAG_harmony_observation &&
4019 object->map()->is_observed() && lookup->IsDataProperty()) { 4021 object->map()->is_observed() &&
4022 *name != isolate->heap()->hidden_string();
4023 if (is_observed && lookup->IsDataProperty()) {
4020 old_value = Object::GetProperty(object, name); 4024 old_value = Object::GetProperty(object, name);
4021 } 4025 }
4022 4026
4023 // This is a real property that is not read-only, or it is a 4027 // This is a real property that is not read-only, or it is a
4024 // transition or null descriptor and there are no setters in the prototypes. 4028 // transition or null descriptor and there are no setters in the prototypes.
4025 Handle<Object> result = value; 4029 Handle<Object> result = value;
4026 switch (lookup->type()) { 4030 switch (lookup->type()) {
4027 case NORMAL: 4031 case NORMAL:
4028 SetNormalizedProperty(handle(lookup->holder()), lookup, value); 4032 SetNormalizedProperty(handle(lookup->holder()), lookup, value);
4029 break; 4033 break;
(...skipping 18 matching lines...) Expand all
4048 result = SetPropertyUsingTransition(handle(lookup->holder()), lookup, 4052 result = SetPropertyUsingTransition(handle(lookup->holder()), lookup,
4049 name, value, attributes); 4053 name, value, attributes);
4050 break; 4054 break;
4051 case HANDLER: 4055 case HANDLER:
4052 case NONEXISTENT: 4056 case NONEXISTENT:
4053 UNREACHABLE(); 4057 UNREACHABLE();
4054 } 4058 }
4055 4059
4056 RETURN_IF_EMPTY_HANDLE_VALUE(isolate, result, Handle<Object>()); 4060 RETURN_IF_EMPTY_HANDLE_VALUE(isolate, result, Handle<Object>());
4057 4061
4058 if (FLAG_harmony_observation && object->map()->is_observed()) { 4062 if (is_observed) {
4059 if (lookup->IsTransition()) { 4063 if (lookup->IsTransition()) {
4060 EnqueueChangeRecord(object, "new", name, old_value); 4064 EnqueueChangeRecord(object, "new", name, old_value);
4061 } else { 4065 } else {
4062 LookupResult new_lookup(isolate); 4066 LookupResult new_lookup(isolate);
4063 object->LocalLookup(*name, &new_lookup, true); 4067 object->LocalLookup(*name, &new_lookup, true);
4064 if (new_lookup.IsDataProperty()) { 4068 if (new_lookup.IsDataProperty()) {
4065 Handle<Object> new_value = Object::GetProperty(object, name); 4069 Handle<Object> new_value = Object::GetProperty(object, name);
4066 if (!new_value->SameValue(*old_value)) { 4070 if (!new_value->SameValue(*old_value)) {
4067 EnqueueChangeRecord(object, "updated", name, old_value); 4071 EnqueueChangeRecord(object, "updated", name, old_value);
4068 } 4072 }
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
4149 4153
4150 // Check for accessor in prototype chain removed here in clone. 4154 // Check for accessor in prototype chain removed here in clone.
4151 if (!lookup.IsFound()) { 4155 if (!lookup.IsFound()) {
4152 // Neither properties nor transitions found. 4156 // Neither properties nor transitions found.
4153 return AddProperty(object, name, value, attributes, kNonStrictMode, 4157 return AddProperty(object, name, value, attributes, kNonStrictMode,
4154 MAY_BE_STORE_FROM_KEYED, extensibility_check, value_type, mode); 4158 MAY_BE_STORE_FROM_KEYED, extensibility_check, value_type, mode);
4155 } 4159 }
4156 4160
4157 Handle<Object> old_value = isolate->factory()->the_hole_value(); 4161 Handle<Object> old_value = isolate->factory()->the_hole_value();
4158 PropertyAttributes old_attributes = ABSENT; 4162 PropertyAttributes old_attributes = ABSENT;
4159 bool is_observed = FLAG_harmony_observation && object->map()->is_observed(); 4163 bool is_observed = FLAG_harmony_observation &&
4164 object->map()->is_observed() &&
4165 *name != isolate->heap()->hidden_string();
4160 if (is_observed && lookup.IsProperty()) { 4166 if (is_observed && lookup.IsProperty()) {
4161 if (lookup.IsDataProperty()) old_value = 4167 if (lookup.IsDataProperty()) old_value =
4162 Object::GetProperty(object, name); 4168 Object::GetProperty(object, name);
4163 old_attributes = lookup.GetAttributes(); 4169 old_attributes = lookup.GetAttributes();
4164 } 4170 }
4165 4171
4166 // Check of IsReadOnly removed from here in clone. 4172 // Check of IsReadOnly removed from here in clone.
4167 switch (lookup.type()) { 4173 switch (lookup.type()) {
4168 case NORMAL: 4174 case NORMAL:
4169 ReplaceSlowProperty(object, name, value, attributes); 4175 ReplaceSlowProperty(object, name, value, attributes);
(...skipping 1043 matching lines...) Expand 10 before | Expand all | Expand 10 after
5213 Handle<Object> args[2] = { name, object }; 5219 Handle<Object> args[2] = { name, object };
5214 Handle<Object> error = isolate->factory()->NewTypeError( 5220 Handle<Object> error = isolate->factory()->NewTypeError(
5215 "strict_delete_property", HandleVector(args, ARRAY_SIZE(args))); 5221 "strict_delete_property", HandleVector(args, ARRAY_SIZE(args)));
5216 isolate->Throw(*error); 5222 isolate->Throw(*error);
5217 return Handle<Object>(); 5223 return Handle<Object>();
5218 } 5224 }
5219 return isolate->factory()->false_value(); 5225 return isolate->factory()->false_value();
5220 } 5226 }
5221 5227
5222 Handle<Object> old_value = isolate->factory()->the_hole_value(); 5228 Handle<Object> old_value = isolate->factory()->the_hole_value();
5223 bool is_observed = FLAG_harmony_observation && object->map()->is_observed(); 5229 bool is_observed = FLAG_harmony_observation &&
5230 object->map()->is_observed() &&
5231 *name != isolate->heap()->hidden_string();
5224 if (is_observed && lookup.IsDataProperty()) { 5232 if (is_observed && lookup.IsDataProperty()) {
5225 old_value = Object::GetProperty(object, name); 5233 old_value = Object::GetProperty(object, name);
5226 } 5234 }
5227 Handle<Object> result; 5235 Handle<Object> result;
5228 5236
5229 // Check for interceptor. 5237 // Check for interceptor.
5230 if (lookup.IsInterceptor()) { 5238 if (lookup.IsInterceptor()) {
5231 // Skip interceptor if forcing a deletion. 5239 // Skip interceptor if forcing a deletion.
5232 if (mode == FORCE_DELETION) { 5240 if (mode == FORCE_DELETION) {
5233 result = DeletePropertyPostInterceptor(object, name, mode); 5241 result = DeletePropertyPostInterceptor(object, name, mode);
(...skipping 1051 matching lines...) Expand 10 before | Expand all | Expand 10 after
6285 6293
6286 // Try to flatten before operating on the string. 6294 // Try to flatten before operating on the string.
6287 if (name->IsString()) String::cast(*name)->TryFlatten(); 6295 if (name->IsString()) String::cast(*name)->TryFlatten();
6288 6296
6289 if (!object->CanSetCallback(*name)) return; 6297 if (!object->CanSetCallback(*name)) return;
6290 6298
6291 uint32_t index = 0; 6299 uint32_t index = 0;
6292 bool is_element = name->AsArrayIndex(&index); 6300 bool is_element = name->AsArrayIndex(&index);
6293 6301
6294 Handle<Object> old_value = isolate->factory()->the_hole_value(); 6302 Handle<Object> old_value = isolate->factory()->the_hole_value();
6295 bool is_observed = FLAG_harmony_observation && object->map()->is_observed(); 6303 bool is_observed = FLAG_harmony_observation &&
6304 object->map()->is_observed() &&
6305 *name != isolate->heap()->hidden_string();
6296 bool preexists = false; 6306 bool preexists = false;
6297 if (is_observed) { 6307 if (is_observed) {
6298 if (is_element) { 6308 if (is_element) {
6299 preexists = HasLocalElement(object, index); 6309 preexists = HasLocalElement(object, index);
6300 if (preexists && object->GetLocalElementAccessorPair(index) == NULL) { 6310 if (preexists && object->GetLocalElementAccessorPair(index) == NULL) {
6301 old_value = Object::GetElement(isolate, object, index); 6311 old_value = Object::GetElement(isolate, object, index);
6302 } 6312 }
6303 } else { 6313 } else {
6304 LookupResult lookup(isolate); 6314 LookupResult lookup(isolate);
6305 object->LocalLookup(*name, &lookup, true); 6315 object->LocalLookup(*name, &lookup, true);
(...skipping 10058 matching lines...) Expand 10 before | Expand all | Expand 10 after
16364 #define ERROR_MESSAGES_TEXTS(C, T) T, 16374 #define ERROR_MESSAGES_TEXTS(C, T) T,
16365 static const char* error_messages_[] = { 16375 static const char* error_messages_[] = {
16366 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) 16376 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS)
16367 }; 16377 };
16368 #undef ERROR_MESSAGES_TEXTS 16378 #undef ERROR_MESSAGES_TEXTS
16369 return error_messages_[reason]; 16379 return error_messages_[reason];
16370 } 16380 }
16371 16381
16372 16382
16373 } } // namespace v8::internal 16383 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | test/cctest/test-object-observe.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698