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

Side by Side Diff: src/handles.cc

Issue 196133017: Experimental parser: merge r19949 (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 6 years, 9 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/globals.h ('k') | src/handles-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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 } 502 }
503 503
504 504
505 Handle<FixedArray> GetKeysInFixedArrayFor(Handle<JSReceiver> object, 505 Handle<FixedArray> GetKeysInFixedArrayFor(Handle<JSReceiver> object,
506 KeyCollectionType type, 506 KeyCollectionType type,
507 bool* threw) { 507 bool* threw) {
508 USE(ContainsOnlyValidKeys); 508 USE(ContainsOnlyValidKeys);
509 Isolate* isolate = object->GetIsolate(); 509 Isolate* isolate = object->GetIsolate();
510 Handle<FixedArray> content = isolate->factory()->empty_fixed_array(); 510 Handle<FixedArray> content = isolate->factory()->empty_fixed_array();
511 Handle<JSObject> arguments_boilerplate = Handle<JSObject>( 511 Handle<JSObject> arguments_boilerplate = Handle<JSObject>(
512 isolate->context()->native_context()->arguments_boilerplate(), 512 isolate->context()->native_context()->sloppy_arguments_boilerplate(),
513 isolate); 513 isolate);
514 Handle<JSFunction> arguments_function = Handle<JSFunction>( 514 Handle<JSFunction> arguments_function = Handle<JSFunction>(
515 JSFunction::cast(arguments_boilerplate->map()->constructor()), 515 JSFunction::cast(arguments_boilerplate->map()->constructor()),
516 isolate); 516 isolate);
517 517
518 // Only collect keys if access is permitted. 518 // Only collect keys if access is permitted.
519 for (Handle<Object> p = object; 519 for (Handle<Object> p = object;
520 *p != isolate->heap()->null_value(); 520 *p != isolate->heap()->null_value();
521 p = Handle<Object>(p->GetPrototype(isolate), isolate)) { 521 p = Handle<Object>(p->GetPrototype(isolate), isolate)) {
522 if (p->IsJSProxy()) { 522 if (p->IsJSProxy()) {
523 Handle<JSProxy> proxy(JSProxy::cast(*p), isolate); 523 Handle<JSProxy> proxy(JSProxy::cast(*p), isolate);
524 Handle<Object> args[] = { proxy }; 524 Handle<Object> args[] = { proxy };
525 Handle<Object> names = Execution::Call(isolate, 525 Handle<Object> names = Execution::Call(isolate,
526 isolate->proxy_enumerate(), 526 isolate->proxy_enumerate(),
527 object, 527 object,
528 ARRAY_SIZE(args), 528 ARRAY_SIZE(args),
529 args, 529 args,
530 threw); 530 threw);
531 if (*threw) return content; 531 if (*threw) return content;
532 content = AddKeysFromJSArray(content, Handle<JSArray>::cast(names)); 532 content = AddKeysFromJSArray(content, Handle<JSArray>::cast(names));
533 break; 533 break;
534 } 534 }
535 535
536 Handle<JSObject> current(JSObject::cast(*p), isolate); 536 Handle<JSObject> current(JSObject::cast(*p), isolate);
537 537
538 // Check access rights if required. 538 // Check access rights if required.
539 if (current->IsAccessCheckNeeded() && 539 if (current->IsAccessCheckNeeded() &&
540 !isolate->MayNamedAccess(*current, 540 !isolate->MayNamedAccessWrapper(current,
541 isolate->heap()->undefined_value(), 541 isolate->factory()->undefined_value(),
542 v8::ACCESS_KEYS)) { 542 v8::ACCESS_KEYS)) {
543 isolate->ReportFailedAccessCheck(*current, v8::ACCESS_KEYS); 543 isolate->ReportFailedAccessCheckWrapper(current, v8::ACCESS_KEYS);
544 if (isolate->has_scheduled_exception()) { 544 if (isolate->has_scheduled_exception()) {
545 isolate->PromoteScheduledException(); 545 isolate->PromoteScheduledException();
546 *threw = true; 546 *threw = true;
547 } 547 }
548 break; 548 break;
549 } 549 }
550 550
551 // Compute the element keys. 551 // Compute the element keys.
552 Handle<FixedArray> element_keys = 552 Handle<FixedArray> element_keys =
553 isolate->factory()->NewFixedArray(current->NumberOfEnumElements()); 553 isolate->factory()->NewFixedArray(current->NumberOfEnumElements());
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 *storage, 705 *storage,
706 indices.is_null() ? Object::cast(Smi::FromInt(0)) 706 indices.is_null() ? Object::cast(Smi::FromInt(0))
707 : Object::cast(*indices)); 707 : Object::cast(*indices));
708 if (cache_result) { 708 if (cache_result) {
709 object->map()->SetEnumLength(enum_size); 709 object->map()->SetEnumLength(enum_size);
710 } 710 }
711 711
712 return ReduceFixedArrayTo(storage, enum_size); 712 return ReduceFixedArrayTo(storage, enum_size);
713 } else { 713 } else {
714 Handle<NameDictionary> dictionary(object->property_dictionary()); 714 Handle<NameDictionary> dictionary(object->property_dictionary());
715 715 int length = dictionary->NumberOfEnumElements();
716 int length = dictionary->NumberOfElements();
717 if (length == 0) { 716 if (length == 0) {
718 return Handle<FixedArray>(isolate->heap()->empty_fixed_array()); 717 return Handle<FixedArray>(isolate->heap()->empty_fixed_array());
719 } 718 }
720 719 Handle<FixedArray> storage = isolate->factory()->NewFixedArray(length);
721 // The enumeration array is generated by allocating an array big enough to 720 dictionary->CopyEnumKeysTo(*storage);
722 // hold all properties that have been seen, whether they are are deleted or
723 // not. Subsequently all visible properties are added to the array. If some
724 // properties were not visible, the array is trimmed so it only contains
725 // visible properties. This improves over adding elements and sorting by
726 // index by having linear complexity rather than n*log(n).
727
728 // By comparing the monotonous NextEnumerationIndex to the NumberOfElements,
729 // we can predict the number of holes in the final array. If there will be
730 // more than 50% holes, regenerate the enumeration indices to reduce the
731 // number of holes to a minimum. This avoids allocating a large array if
732 // many properties were added but subsequently deleted.
733 int next_enumeration = dictionary->NextEnumerationIndex();
734 if (!object->IsGlobalObject() && next_enumeration > (length * 3) / 2) {
735 NameDictionary::DoGenerateNewEnumerationIndices(dictionary);
736 next_enumeration = dictionary->NextEnumerationIndex();
737 }
738
739 Handle<FixedArray> storage =
740 isolate->factory()->NewFixedArray(next_enumeration);
741
742 storage = Handle<FixedArray>(dictionary->CopyEnumKeysTo(*storage));
743 ASSERT(storage->length() == object->NumberOfLocalProperties(DONT_SHOW));
744 return storage; 721 return storage;
745 } 722 }
746 } 723 }
747 724
748 725
749 DeferredHandleScope::DeferredHandleScope(Isolate* isolate) 726 DeferredHandleScope::DeferredHandleScope(Isolate* isolate)
750 : impl_(isolate->handle_scope_implementer()) { 727 : impl_(isolate->handle_scope_implementer()) {
751 impl_->BeginDeferredScope(); 728 impl_->BeginDeferredScope();
752 HandleScopeData* data = impl_->isolate()->handle_scope_data(); 729 HandleScopeData* data = impl_->isolate()->handle_scope_data();
753 Object** new_next = impl_->GetSpareOrNewBlock(); 730 Object** new_next = impl_->GetSpareOrNewBlock();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 Handle<Code> code) { 767 Handle<Code> code) {
791 heap->EnsureWeakObjectToCodeTable(); 768 heap->EnsureWeakObjectToCodeTable();
792 Handle<DependentCode> dep(heap->LookupWeakObjectToCodeDependency(*object)); 769 Handle<DependentCode> dep(heap->LookupWeakObjectToCodeDependency(*object));
793 dep = DependentCode::Insert(dep, DependentCode::kWeaklyEmbeddedGroup, code); 770 dep = DependentCode::Insert(dep, DependentCode::kWeaklyEmbeddedGroup, code);
794 CALL_HEAP_FUNCTION_VOID(heap->isolate(), 771 CALL_HEAP_FUNCTION_VOID(heap->isolate(),
795 heap->AddWeakObjectToCodeDependency(*object, *dep)); 772 heap->AddWeakObjectToCodeDependency(*object, *dep));
796 } 773 }
797 774
798 775
799 } } // namespace v8::internal 776 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/globals.h ('k') | src/handles-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698