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

Side by Side Diff: src/objects.cc

Issue 24200005: Hanldify JSObject::PreventExtensions method. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 3 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') | src/runtime.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 5304 matching lines...) Expand 10 before | Expand all | Expand 10 after
5315 return JSObject::cast(context->extension())->ReferencesObject(obj); 5315 return JSObject::cast(context->extension())->ReferencesObject(obj);
5316 } 5316 }
5317 } 5317 }
5318 5318
5319 // No references to object. 5319 // No references to object.
5320 return false; 5320 return false;
5321 } 5321 }
5322 5322
5323 5323
5324 Handle<Object> JSObject::PreventExtensions(Handle<JSObject> object) { 5324 Handle<Object> JSObject::PreventExtensions(Handle<JSObject> object) {
5325 CALL_HEAP_FUNCTION(object->GetIsolate(), object->PreventExtensions(), Object); 5325 Isolate* isolate = object->GetIsolate();
5326 } 5326 if (object->IsAccessCheckNeeded() &&
5327 5327 !isolate->MayNamedAccess(*object,
5328
5329 MaybeObject* JSObject::PreventExtensions() {
5330 Isolate* isolate = GetIsolate();
5331 if (IsAccessCheckNeeded() &&
5332 !isolate->MayNamedAccess(this,
5333 isolate->heap()->undefined_value(), 5328 isolate->heap()->undefined_value(),
5334 v8::ACCESS_KEYS)) { 5329 v8::ACCESS_KEYS)) {
5335 isolate->ReportFailedAccessCheck(this, v8::ACCESS_KEYS); 5330 isolate->ReportFailedAccessCheck(*object, v8::ACCESS_KEYS);
5336 RETURN_IF_SCHEDULED_EXCEPTION(isolate); 5331 RETURN_HANDLE_IF_SCHEDULED_EXCEPTION(isolate, Object);
5337 return isolate->heap()->false_value(); 5332 return isolate->factory()->false_value();
5338 } 5333 }
5339 5334
5340 if (IsJSGlobalProxy()) { 5335 if (object->IsJSGlobalProxy()) {
5341 Object* proto = GetPrototype(); 5336 Handle<Object> proto(object->GetPrototype(), isolate);
5342 if (proto->IsNull()) return this; 5337 if (proto->IsNull()) return object;
5343 ASSERT(proto->IsJSGlobalObject()); 5338 ASSERT(proto->IsJSGlobalObject());
5344 return JSObject::cast(proto)->PreventExtensions(); 5339 return PreventExtensions(Handle<JSObject>::cast(proto));
5345 } 5340 }
5346 5341
5347 // It's not possible to seal objects with external array elements 5342 // It's not possible to seal objects with external array elements
5348 if (HasExternalArrayElements()) { 5343 if (object->HasExternalArrayElements()) {
5349 HandleScope scope(isolate);
5350 Handle<Object> object(this, isolate);
5351 Handle<Object> error = 5344 Handle<Object> error =
5352 isolate->factory()->NewTypeError( 5345 isolate->factory()->NewTypeError(
5353 "cant_prevent_ext_external_array_elements", 5346 "cant_prevent_ext_external_array_elements",
5354 HandleVector(&object, 1)); 5347 HandleVector(&object, 1));
5355 return isolate->Throw(*error); 5348 isolate->Throw(*error);
5349 return Handle<Object>();
5356 } 5350 }
5357 5351
5358 // If there are fast elements we normalize. 5352 // If there are fast elements we normalize.
5359 SeededNumberDictionary* dictionary = NULL; 5353 Handle<SeededNumberDictionary> dictionary = NormalizeElements(object);
5360 { MaybeObject* maybe = NormalizeElements(); 5354 ASSERT(object->HasDictionaryElements() ||
5361 if (!maybe->To<SeededNumberDictionary>(&dictionary)) return maybe; 5355 object->HasDictionaryArgumentsElements());
5362 } 5356
5363 ASSERT(HasDictionaryElements() || HasDictionaryArgumentsElements());
5364 // Make sure that we never go back to fast case. 5357 // Make sure that we never go back to fast case.
5365 dictionary->set_requires_slow_elements(); 5358 dictionary->set_requires_slow_elements();
5366 5359
5367 // Do a map transition, other objects with this map may still 5360 // Do a map transition, other objects with this map may still
5368 // be extensible. 5361 // be extensible.
5369 // TODO(adamk): Extend the NormalizedMapCache to handle non-extensible maps. 5362 // TODO(adamk): Extend the NormalizedMapCache to handle non-extensible maps.
5370 Map* new_map; 5363 Handle<Map> new_map = Map::Copy(handle(object->map()));
5371 MaybeObject* maybe = map()->Copy();
5372 if (!maybe->To(&new_map)) return maybe;
5373 5364
5374 new_map->set_is_extensible(false); 5365 new_map->set_is_extensible(false);
5375 set_map(new_map); 5366 object->set_map(*new_map);
5376 ASSERT(!map()->is_extensible()); 5367 ASSERT(!object->map()->is_extensible());
5377 return new_map; 5368 return object;
5378 } 5369 }
5379 5370
5380 5371
5381 template<typename Dictionary> 5372 template<typename Dictionary>
5382 static void FreezeDictionary(Dictionary* dictionary) { 5373 static void FreezeDictionary(Dictionary* dictionary) {
5383 int capacity = dictionary->Capacity(); 5374 int capacity = dictionary->Capacity();
5384 for (int i = 0; i < capacity; i++) { 5375 for (int i = 0; i < capacity; i++) {
5385 Object* k = dictionary->KeyAt(i); 5376 Object* k = dictionary->KeyAt(i);
5386 if (dictionary->IsKey(k)) { 5377 if (dictionary->IsKey(k)) {
5387 PropertyDetails details = dictionary->DetailsAt(i); 5378 PropertyDetails details = dictionary->DetailsAt(i);
(...skipping 10699 matching lines...) Expand 10 before | Expand all | Expand 10 after
16087 #define ERROR_MESSAGES_TEXTS(C, T) T, 16078 #define ERROR_MESSAGES_TEXTS(C, T) T,
16088 static const char* error_messages_[] = { 16079 static const char* error_messages_[] = {
16089 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) 16080 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS)
16090 }; 16081 };
16091 #undef ERROR_MESSAGES_TEXTS 16082 #undef ERROR_MESSAGES_TEXTS
16092 return error_messages_[reason]; 16083 return error_messages_[reason];
16093 } 16084 }
16094 16085
16095 16086
16096 } } // namespace v8::internal 16087 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/runtime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698