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

Side by Side Diff: src/objects.cc

Issue 240113010: Tighten OpenHandle's extra checks. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebase Created 6 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') | 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 // 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 6404 matching lines...) Expand 10 before | Expand all | Expand 10 after
6415 ASSIGN_RETURN_ON_EXCEPTION( 6415 ASSIGN_RETURN_ON_EXCEPTION(
6416 isolate, names, 6416 isolate, names,
6417 Execution::Call(isolate, 6417 Execution::Call(isolate,
6418 isolate->proxy_enumerate(), 6418 isolate->proxy_enumerate(),
6419 object, 6419 object,
6420 ARRAY_SIZE(args), 6420 ARRAY_SIZE(args),
6421 args), 6421 args),
6422 FixedArray); 6422 FixedArray);
6423 ASSIGN_RETURN_ON_EXCEPTION( 6423 ASSIGN_RETURN_ON_EXCEPTION(
6424 isolate, content, 6424 isolate, content,
6425 FixedArray::AddKeysFromJSArray( 6425 FixedArray::AddKeysFromArrayLike(
6426 content, Handle<JSArray>::cast(names)), 6426 content, Handle<JSObject>::cast(names)),
6427 FixedArray); 6427 FixedArray);
6428 break; 6428 break;
6429 } 6429 }
6430 6430
6431 Handle<JSObject> current(JSObject::cast(*p), isolate); 6431 Handle<JSObject> current(JSObject::cast(*p), isolate);
6432 6432
6433 // Check access rights if required. 6433 // Check access rights if required.
6434 if (current->IsAccessCheckNeeded() && 6434 if (current->IsAccessCheckNeeded() &&
6435 !isolate->MayNamedAccess( 6435 !isolate->MayNamedAccess(
6436 current, isolate->factory()->undefined_value(), v8::ACCESS_KEYS)) { 6436 current, isolate->factory()->undefined_value(), v8::ACCESS_KEYS)) {
6437 isolate->ReportFailedAccessCheck(current, v8::ACCESS_KEYS); 6437 isolate->ReportFailedAccessCheck(current, v8::ACCESS_KEYS);
6438 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, FixedArray); 6438 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, FixedArray);
6439 break; 6439 break;
6440 } 6440 }
6441 6441
6442 // Compute the element keys. 6442 // Compute the element keys.
6443 Handle<FixedArray> element_keys = 6443 Handle<FixedArray> element_keys =
6444 isolate->factory()->NewFixedArray(current->NumberOfEnumElements()); 6444 isolate->factory()->NewFixedArray(current->NumberOfEnumElements());
6445 current->GetEnumElementKeys(*element_keys); 6445 current->GetEnumElementKeys(*element_keys);
6446 ASSIGN_RETURN_ON_EXCEPTION( 6446 ASSIGN_RETURN_ON_EXCEPTION(
6447 isolate, content, 6447 isolate, content,
6448 FixedArray::UnionOfKeys(content, element_keys), 6448 FixedArray::UnionOfKeys(content, element_keys),
6449 FixedArray); 6449 FixedArray);
6450 ASSERT(ContainsOnlyValidKeys(content)); 6450 ASSERT(ContainsOnlyValidKeys(content));
6451 6451
6452 // Add the element keys from the interceptor. 6452 // Add the element keys from the interceptor.
6453 if (current->HasIndexedInterceptor()) { 6453 if (current->HasIndexedInterceptor()) {
6454 Handle<JSArray> result; 6454 Handle<JSObject> result;
6455 if (JSObject::GetKeysForIndexedInterceptor( 6455 if (JSObject::GetKeysForIndexedInterceptor(
6456 current, object).ToHandle(&result)) { 6456 current, object).ToHandle(&result)) {
6457 ASSIGN_RETURN_ON_EXCEPTION( 6457 ASSIGN_RETURN_ON_EXCEPTION(
6458 isolate, content, 6458 isolate, content,
6459 FixedArray::AddKeysFromJSArray(content, result), 6459 FixedArray::AddKeysFromArrayLike(content, result),
6460 FixedArray); 6460 FixedArray);
6461 } 6461 }
6462 ASSERT(ContainsOnlyValidKeys(content)); 6462 ASSERT(ContainsOnlyValidKeys(content));
6463 } 6463 }
6464 6464
6465 // We can cache the computed property keys if access checks are 6465 // We can cache the computed property keys if access checks are
6466 // not needed and no interceptors are involved. 6466 // not needed and no interceptors are involved.
6467 // 6467 //
6468 // We do not use the cache if the object has elements and 6468 // We do not use the cache if the object has elements and
6469 // therefore it does not make sense to cache the property names 6469 // therefore it does not make sense to cache the property names
(...skipping 11 matching lines...) Expand all
6481 // Compute the property keys and cache them if possible. 6481 // Compute the property keys and cache them if possible.
6482 ASSIGN_RETURN_ON_EXCEPTION( 6482 ASSIGN_RETURN_ON_EXCEPTION(
6483 isolate, content, 6483 isolate, content,
6484 FixedArray::UnionOfKeys( 6484 FixedArray::UnionOfKeys(
6485 content, GetEnumPropertyKeys(current, cache_enum_keys)), 6485 content, GetEnumPropertyKeys(current, cache_enum_keys)),
6486 FixedArray); 6486 FixedArray);
6487 ASSERT(ContainsOnlyValidKeys(content)); 6487 ASSERT(ContainsOnlyValidKeys(content));
6488 6488
6489 // Add the property keys from the interceptor. 6489 // Add the property keys from the interceptor.
6490 if (current->HasNamedInterceptor()) { 6490 if (current->HasNamedInterceptor()) {
6491 Handle<JSArray> result; 6491 Handle<JSObject> result;
6492 if (JSObject::GetKeysForNamedInterceptor( 6492 if (JSObject::GetKeysForNamedInterceptor(
6493 current, object).ToHandle(&result)) { 6493 current, object).ToHandle(&result)) {
6494 ASSIGN_RETURN_ON_EXCEPTION( 6494 ASSIGN_RETURN_ON_EXCEPTION(
6495 isolate, content, 6495 isolate, content,
6496 FixedArray::AddKeysFromJSArray(content, result), 6496 FixedArray::AddKeysFromArrayLike(content, result),
6497 FixedArray); 6497 FixedArray);
6498 } 6498 }
6499 ASSERT(ContainsOnlyValidKeys(content)); 6499 ASSERT(ContainsOnlyValidKeys(content));
6500 } 6500 }
6501 6501
6502 // If we only want local properties we bail out after the first 6502 // If we only want local properties we bail out after the first
6503 // iteration. 6503 // iteration.
6504 if (type == LOCAL_ONLY) break; 6504 if (type == LOCAL_ONLY) break;
6505 } 6505 }
6506 return content; 6506 return content;
(...skipping 1717 matching lines...) Expand 10 before | Expand all | Expand 10 after
8224 8224
8225 void FixedArray::Shrink(int new_length) { 8225 void FixedArray::Shrink(int new_length) {
8226 ASSERT(0 <= new_length && new_length <= length()); 8226 ASSERT(0 <= new_length && new_length <= length());
8227 if (new_length < length()) { 8227 if (new_length < length()) {
8228 RightTrimFixedArray<Heap::FROM_MUTATOR>( 8228 RightTrimFixedArray<Heap::FROM_MUTATOR>(
8229 GetHeap(), this, length() - new_length); 8229 GetHeap(), this, length() - new_length);
8230 } 8230 }
8231 } 8231 }
8232 8232
8233 8233
8234 MaybeHandle<FixedArray> FixedArray::AddKeysFromJSArray( 8234 MaybeHandle<FixedArray> FixedArray::AddKeysFromArrayLike(
8235 Handle<FixedArray> content, 8235 Handle<FixedArray> content,
8236 Handle<JSArray> array) { 8236 Handle<JSObject> array) {
8237 ASSERT(array->IsJSArray() || array->HasSloppyArgumentsElements());
8237 ElementsAccessor* accessor = array->GetElementsAccessor(); 8238 ElementsAccessor* accessor = array->GetElementsAccessor();
8238 Handle<FixedArray> result; 8239 Handle<FixedArray> result;
8239 ASSIGN_RETURN_ON_EXCEPTION( 8240 ASSIGN_RETURN_ON_EXCEPTION(
8240 array->GetIsolate(), result, 8241 array->GetIsolate(), result,
8241 accessor->AddElementsToFixedArray(array, array, content), 8242 accessor->AddElementsToFixedArray(array, array, content),
8242 FixedArray); 8243 FixedArray);
8243 8244
8244 #ifdef ENABLE_SLOW_ASSERTS 8245 #ifdef ENABLE_SLOW_ASSERTS
8245 if (FLAG_enable_slow_asserts) { 8246 if (FLAG_enable_slow_asserts) {
8246 DisallowHeapAllocation no_allocation; 8247 DisallowHeapAllocation no_allocation;
(...skipping 5651 matching lines...) Expand 10 before | Expand all | Expand 10 after
13898 return handle(*result_internal, isolate); 13899 return handle(*result_internal, isolate);
13899 } 13900 }
13900 } 13901 }
13901 13902
13902 return GetPropertyPostInterceptor(object, receiver, name, attributes); 13903 return GetPropertyPostInterceptor(object, receiver, name, attributes);
13903 } 13904 }
13904 13905
13905 13906
13906 // Compute the property keys from the interceptor. 13907 // Compute the property keys from the interceptor.
13907 // TODO(rossberg): support symbols in API, and filter here if needed. 13908 // TODO(rossberg): support symbols in API, and filter here if needed.
13908 MaybeHandle<JSArray> JSObject::GetKeysForNamedInterceptor( 13909 MaybeHandle<JSObject> JSObject::GetKeysForNamedInterceptor(
13909 Handle<JSObject> object, Handle<JSReceiver> receiver) { 13910 Handle<JSObject> object, Handle<JSReceiver> receiver) {
13910 Isolate* isolate = receiver->GetIsolate(); 13911 Isolate* isolate = receiver->GetIsolate();
13911 Handle<InterceptorInfo> interceptor(object->GetNamedInterceptor()); 13912 Handle<InterceptorInfo> interceptor(object->GetNamedInterceptor());
13912 PropertyCallbackArguments 13913 PropertyCallbackArguments
13913 args(isolate, interceptor->data(), *receiver, *object); 13914 args(isolate, interceptor->data(), *receiver, *object);
13914 v8::Handle<v8::Array> result; 13915 v8::Handle<v8::Object> result;
13915 if (!interceptor->enumerator()->IsUndefined()) { 13916 if (!interceptor->enumerator()->IsUndefined()) {
13916 v8::NamedPropertyEnumeratorCallback enum_fun = 13917 v8::NamedPropertyEnumeratorCallback enum_fun =
13917 v8::ToCData<v8::NamedPropertyEnumeratorCallback>( 13918 v8::ToCData<v8::NamedPropertyEnumeratorCallback>(
13918 interceptor->enumerator()); 13919 interceptor->enumerator());
13919 LOG(isolate, ApiObjectAccess("interceptor-named-enum", *object)); 13920 LOG(isolate, ApiObjectAccess("interceptor-named-enum", *object));
13920 result = args.Call(enum_fun); 13921 result = args.Call(enum_fun);
13921 } 13922 }
13922 if (result.IsEmpty()) return MaybeHandle<JSArray>(); 13923 if (result.IsEmpty()) return MaybeHandle<JSObject>();
13923 #if ENABLE_EXTRA_CHECKS 13924 #if ENABLE_EXTRA_CHECKS
13924 CHECK(v8::Utils::OpenHandle(*result)->IsJSObject()); 13925 CHECK(v8::Utils::OpenHandle(*result)->IsJSArray() ||
13926 v8::Utils::OpenHandle(*result)->HasSloppyArgumentsElements());
13925 #endif 13927 #endif
13926 // Rebox before returning. 13928 // Rebox before returning.
13927 return handle(*v8::Utils::OpenHandle(*result), isolate); 13929 return handle(*v8::Utils::OpenHandle(*result), isolate);
13928 } 13930 }
13929 13931
13930 13932
13931 // Compute the element keys from the interceptor. 13933 // Compute the element keys from the interceptor.
13932 MaybeHandle<JSArray> JSObject::GetKeysForIndexedInterceptor( 13934 MaybeHandle<JSObject> JSObject::GetKeysForIndexedInterceptor(
13933 Handle<JSObject> object, Handle<JSReceiver> receiver) { 13935 Handle<JSObject> object, Handle<JSReceiver> receiver) {
13934 Isolate* isolate = receiver->GetIsolate(); 13936 Isolate* isolate = receiver->GetIsolate();
13935 Handle<InterceptorInfo> interceptor(object->GetIndexedInterceptor()); 13937 Handle<InterceptorInfo> interceptor(object->GetIndexedInterceptor());
13936 PropertyCallbackArguments 13938 PropertyCallbackArguments
13937 args(isolate, interceptor->data(), *receiver, *object); 13939 args(isolate, interceptor->data(), *receiver, *object);
13938 v8::Handle<v8::Array> result; 13940 v8::Handle<v8::Object> result;
13939 if (!interceptor->enumerator()->IsUndefined()) { 13941 if (!interceptor->enumerator()->IsUndefined()) {
13940 v8::IndexedPropertyEnumeratorCallback enum_fun = 13942 v8::IndexedPropertyEnumeratorCallback enum_fun =
13941 v8::ToCData<v8::IndexedPropertyEnumeratorCallback>( 13943 v8::ToCData<v8::IndexedPropertyEnumeratorCallback>(
13942 interceptor->enumerator()); 13944 interceptor->enumerator());
13943 LOG(isolate, ApiObjectAccess("interceptor-indexed-enum", *object)); 13945 LOG(isolate, ApiObjectAccess("interceptor-indexed-enum", *object));
13944 result = args.Call(enum_fun); 13946 result = args.Call(enum_fun);
13945 } 13947 }
13946 if (result.IsEmpty()) return MaybeHandle<JSArray>(); 13948 if (result.IsEmpty()) return MaybeHandle<JSObject>();
13947 #if ENABLE_EXTRA_CHECKS 13949 #if ENABLE_EXTRA_CHECKS
13948 CHECK(v8::Utils::OpenHandle(*result)->IsJSObject()); 13950 CHECK(v8::Utils::OpenHandle(*result)->IsJSArray() ||
13951 v8::Utils::OpenHandle(*result)->HasSloppyArgumentsElements());
13949 #endif 13952 #endif
13950 // Rebox before returning. 13953 // Rebox before returning.
13951 return handle(*v8::Utils::OpenHandle(*result), isolate); 13954 return handle(*v8::Utils::OpenHandle(*result), isolate);
13952 } 13955 }
13953 13956
13954 13957
13955 bool JSObject::HasRealNamedProperty(Handle<JSObject> object, 13958 bool JSObject::HasRealNamedProperty(Handle<JSObject> object,
13956 Handle<Name> key) { 13959 Handle<Name> key) {
13957 Isolate* isolate = object->GetIsolate(); 13960 Isolate* isolate = object->GetIsolate();
13958 SealHandleScope shs(isolate); 13961 SealHandleScope shs(isolate);
(...skipping 3396 matching lines...) Expand 10 before | Expand all | Expand 10 after
17355 #define ERROR_MESSAGES_TEXTS(C, T) T, 17358 #define ERROR_MESSAGES_TEXTS(C, T) T,
17356 static const char* error_messages_[] = { 17359 static const char* error_messages_[] = {
17357 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) 17360 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS)
17358 }; 17361 };
17359 #undef ERROR_MESSAGES_TEXTS 17362 #undef ERROR_MESSAGES_TEXTS
17360 return error_messages_[reason]; 17363 return error_messages_[reason];
17361 } 17364 }
17362 17365
17363 17366
17364 } } // namespace v8::internal 17367 } } // namespace v8::internal
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