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

Side by Side Diff: src/runtime.cc

Issue 8352046: Refactor how elements are redefined by the runtime. Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 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
« src/elements.cc ('K') | « src/elements.cc ('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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 4214 matching lines...) Expand 10 before | Expand all | Expand 10 after
4225 4225
4226 // Check if this is an element. 4226 // Check if this is an element.
4227 uint32_t index; 4227 uint32_t index;
4228 bool is_element = name->AsArrayIndex(&index); 4228 bool is_element = name->AsArrayIndex(&index);
4229 4229
4230 // Special case for elements if any of the flags might be involved. 4230 // Special case for elements if any of the flags might be involved.
4231 // If elements are in fast case we always implicitly assume that: 4231 // If elements are in fast case we always implicitly assume that:
4232 // DONT_DELETE: false, DONT_ENUM: false, READ_ONLY: false. 4232 // DONT_DELETE: false, DONT_ENUM: false, READ_ONLY: false.
4233 if (is_element && (attr != NONE || 4233 if (is_element && (attr != NONE ||
4234 js_object->HasLocalElement(index) == JSObject::DICTIONARY_ELEMENT)) { 4234 js_object->HasLocalElement(index) == JSObject::DICTIONARY_ELEMENT)) {
4235 // Normalize the elements to enable attributes on the property.
4236 if (js_object->IsJSGlobalProxy()) { 4235 if (js_object->IsJSGlobalProxy()) {
4237 // We do not need to do access checks here since these has already 4236 // We do not need to do access checks here since these has already
4238 // been performed by the call to GetOwnProperty. 4237 // been performed by the call to GetOwnProperty.
4239 Handle<Object> proto(js_object->GetPrototype()); 4238 Handle<Object> proto(js_object->GetPrototype());
4240 // If proxy is detached, ignore the assignment. Alternatively, 4239 // If proxy is detached, ignore the assignment. Alternatively,
4241 // we could throw an exception. 4240 // we could throw an exception.
4242 if (proto->IsNull()) return *obj_value; 4241 if (proto->IsNull()) return *obj_value;
4243 js_object = Handle<JSObject>::cast(proto); 4242 js_object = Handle<JSObject>::cast(proto);
4244 } 4243 }
4245 4244
4246 // Don't allow element properties to be redefined on objects with external 4245 // Don't allow element properties to be redefined on objects with external
4247 // array elements. 4246 // array elements.
4248 if (js_object->HasExternalArrayElements()) { 4247 if (js_object->HasExternalArrayElements()) {
4249 Handle<Object> args[2] = { js_object, name }; 4248 Handle<Object> args[2] = { js_object, name };
4250 Handle<Object> error = 4249 Handle<Object> error =
4251 isolate->factory()->NewTypeError("redef_external_array_element", 4250 isolate->factory()->NewTypeError("redef_external_array_element",
4252 HandleVector(args, 2)); 4251 HandleVector(args, 2));
4253 return isolate->Throw(*error); 4252 return isolate->Throw(*error);
4254 } 4253 }
4255 4254
4256 Handle<NumberDictionary> dictionary = NormalizeElements(js_object); 4255 js_object->GetElementsAccessor()->Set(*js_object,
4257 // Make sure that we never go back to fast case. 4256 index,
4258 dictionary->set_requires_slow_elements(); 4257 *obj_value,
4259 PropertyDetails details = PropertyDetails(attr, NORMAL); 4258 attr);
4260 Handle<NumberDictionary> extended_dictionary =
4261 NumberDictionarySet(dictionary, index, obj_value, details);
4262 if (*extended_dictionary != *dictionary) {
4263 if (js_object->GetElementsKind() == NON_STRICT_ARGUMENTS_ELEMENTS) {
4264 FixedArray::cast(js_object->elements())->set(1, *extended_dictionary);
4265 } else {
4266 js_object->set_elements(*extended_dictionary);
4267 }
4268 }
4269 return *obj_value; 4259 return *obj_value;
4270 } 4260 }
4271 4261
4272 LookupResult result(isolate); 4262 LookupResult result(isolate);
4273 js_object->LocalLookupRealNamedProperty(*name, &result); 4263 js_object->LocalLookupRealNamedProperty(*name, &result);
4274 4264
4275 // To be compatible with safari we do not change the value on API objects 4265 // To be compatible with safari we do not change the value on API objects
4276 // in defineProperty. Firefox disagrees here, and actually changes the value. 4266 // in defineProperty. Firefox disagrees here, and actually changes the value.
4277 if (result.IsProperty() && 4267 if (result.IsProperty() &&
4278 (result.type() == CALLBACKS) && 4268 (result.type() == CALLBACKS) &&
(...skipping 9107 matching lines...) Expand 10 before | Expand all | Expand 10 after
13386 } else { 13376 } else {
13387 // Handle last resort GC and make sure to allow future allocations 13377 // Handle last resort GC and make sure to allow future allocations
13388 // to grow the heap without causing GCs (if possible). 13378 // to grow the heap without causing GCs (if possible).
13389 isolate->counters()->gc_last_resort_from_js()->Increment(); 13379 isolate->counters()->gc_last_resort_from_js()->Increment();
13390 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags); 13380 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags);
13391 } 13381 }
13392 } 13382 }
13393 13383
13394 13384
13395 } } // namespace v8::internal 13385 } } // namespace v8::internal
OLDNEW
« src/elements.cc ('K') | « src/elements.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698