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

Side by Side Diff: src/handles.cc

Issue 8404030: Version 3.7.1 (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
Patch Set: Created 9 years, 1 month 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/handles.h ('k') | src/heap.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 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 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 369
370 370
371 Handle<Object> GetProperty(Handle<Object> obj, 371 Handle<Object> GetProperty(Handle<Object> obj,
372 Handle<Object> key) { 372 Handle<Object> key) {
373 Isolate* isolate = Isolate::Current(); 373 Isolate* isolate = Isolate::Current();
374 CALL_HEAP_FUNCTION(isolate, 374 CALL_HEAP_FUNCTION(isolate,
375 Runtime::GetObjectProperty(isolate, obj, key), Object); 375 Runtime::GetObjectProperty(isolate, obj, key), Object);
376 } 376 }
377 377
378 378
379 Handle<Object> GetProperty(Handle<JSReceiver> obj,
380 Handle<String> name,
381 LookupResult* result) {
382 PropertyAttributes attributes;
383 Isolate* isolate = Isolate::Current();
384 CALL_HEAP_FUNCTION(isolate,
385 obj->GetProperty(*obj, result, *name, &attributes),
386 Object);
387 }
388
389
390 Handle<Object> GetElement(Handle<Object> obj,
391 uint32_t index) {
392 Isolate* isolate = Isolate::Current();
393 CALL_HEAP_FUNCTION(isolate, Runtime::GetElement(obj, index), Object);
394 }
395
396
397 Handle<Object> GetPropertyWithInterceptor(Handle<JSObject> receiver, 379 Handle<Object> GetPropertyWithInterceptor(Handle<JSObject> receiver,
398 Handle<JSObject> holder, 380 Handle<JSObject> holder,
399 Handle<String> name, 381 Handle<String> name,
400 PropertyAttributes* attributes) { 382 PropertyAttributes* attributes) {
401 Isolate* isolate = receiver->GetIsolate(); 383 Isolate* isolate = receiver->GetIsolate();
402 CALL_HEAP_FUNCTION(isolate, 384 CALL_HEAP_FUNCTION(isolate,
403 holder->GetPropertyWithInterceptor(*receiver, 385 holder->GetPropertyWithInterceptor(*receiver,
404 *name, 386 *name,
405 attributes), 387 attributes),
406 Object); 388 Object);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 uint32_t index, 479 uint32_t index,
498 Handle<Object> value, 480 Handle<Object> value,
499 StrictModeFlag strict_mode) { 481 StrictModeFlag strict_mode) {
500 ASSERT(!object->HasExternalArrayElements()); 482 ASSERT(!object->HasExternalArrayElements());
501 CALL_HEAP_FUNCTION(object->GetIsolate(), 483 CALL_HEAP_FUNCTION(object->GetIsolate(),
502 object->SetElement(index, *value, strict_mode, false), 484 object->SetElement(index, *value, strict_mode, false),
503 Object); 485 Object);
504 } 486 }
505 487
506 488
489 Handle<Object> TransitionElementsKind(Handle<JSObject> object,
490 ElementsKind to_kind) {
491 CALL_HEAP_FUNCTION(object->GetIsolate(),
492 object->TransitionElementsKind(to_kind),
493 Object);
494 }
495
496
507 Handle<JSObject> Copy(Handle<JSObject> obj) { 497 Handle<JSObject> Copy(Handle<JSObject> obj) {
508 Isolate* isolate = obj->GetIsolate(); 498 Isolate* isolate = obj->GetIsolate();
509 CALL_HEAP_FUNCTION(isolate, 499 CALL_HEAP_FUNCTION(isolate,
510 isolate->heap()->CopyJSObject(*obj), JSObject); 500 isolate->heap()->CopyJSObject(*obj), JSObject);
511 } 501 }
512 502
513 503
514 Handle<Object> SetAccessor(Handle<JSObject> obj, Handle<AccessorInfo> info) { 504 Handle<Object> SetAccessor(Handle<JSObject> obj, Handle<AccessorInfo> info) {
515 CALL_HEAP_FUNCTION(obj->GetIsolate(), obj->DefineAccessor(*info), Object); 505 CALL_HEAP_FUNCTION(obj->GetIsolate(), obj->DefineAccessor(*info), Object);
516 } 506 }
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 return line; 684 return line;
695 } 685 }
696 686
697 687
698 void CustomArguments::IterateInstance(ObjectVisitor* v) { 688 void CustomArguments::IterateInstance(ObjectVisitor* v) {
699 v->VisitPointers(values_, values_ + ARRAY_SIZE(values_)); 689 v->VisitPointers(values_, values_ + ARRAY_SIZE(values_));
700 } 690 }
701 691
702 692
703 // Compute the property keys from the interceptor. 693 // Compute the property keys from the interceptor.
704 v8::Handle<v8::Array> GetKeysForNamedInterceptor(Handle<JSObject> receiver, 694 v8::Handle<v8::Array> GetKeysForNamedInterceptor(Handle<JSReceiver> receiver,
705 Handle<JSObject> object) { 695 Handle<JSObject> object) {
706 Isolate* isolate = receiver->GetIsolate(); 696 Isolate* isolate = receiver->GetIsolate();
707 Handle<InterceptorInfo> interceptor(object->GetNamedInterceptor()); 697 Handle<InterceptorInfo> interceptor(object->GetNamedInterceptor());
708 CustomArguments args(isolate, interceptor->data(), *receiver, *object); 698 CustomArguments args(isolate, interceptor->data(), *receiver, *object);
709 v8::AccessorInfo info(args.end()); 699 v8::AccessorInfo info(args.end());
710 v8::Handle<v8::Array> result; 700 v8::Handle<v8::Array> result;
711 if (!interceptor->enumerator()->IsUndefined()) { 701 if (!interceptor->enumerator()->IsUndefined()) {
712 v8::NamedPropertyEnumerator enum_fun = 702 v8::NamedPropertyEnumerator enum_fun =
713 v8::ToCData<v8::NamedPropertyEnumerator>(interceptor->enumerator()); 703 v8::ToCData<v8::NamedPropertyEnumerator>(interceptor->enumerator());
714 LOG(isolate, ApiObjectAccess("interceptor-named-enum", *object)); 704 LOG(isolate, ApiObjectAccess("interceptor-named-enum", *object));
715 { 705 {
716 // Leaving JavaScript. 706 // Leaving JavaScript.
717 VMState state(isolate, EXTERNAL); 707 VMState state(isolate, EXTERNAL);
718 result = enum_fun(info); 708 result = enum_fun(info);
719 } 709 }
720 } 710 }
721 return result; 711 return result;
722 } 712 }
723 713
724 714
725 // Compute the element keys from the interceptor. 715 // Compute the element keys from the interceptor.
726 v8::Handle<v8::Array> GetKeysForIndexedInterceptor(Handle<JSObject> receiver, 716 v8::Handle<v8::Array> GetKeysForIndexedInterceptor(Handle<JSReceiver> receiver,
727 Handle<JSObject> object) { 717 Handle<JSObject> object) {
728 Isolate* isolate = receiver->GetIsolate(); 718 Isolate* isolate = receiver->GetIsolate();
729 Handle<InterceptorInfo> interceptor(object->GetIndexedInterceptor()); 719 Handle<InterceptorInfo> interceptor(object->GetIndexedInterceptor());
730 CustomArguments args(isolate, interceptor->data(), *receiver, *object); 720 CustomArguments args(isolate, interceptor->data(), *receiver, *object);
731 v8::AccessorInfo info(args.end()); 721 v8::AccessorInfo info(args.end());
732 v8::Handle<v8::Array> result; 722 v8::Handle<v8::Array> result;
733 if (!interceptor->enumerator()->IsUndefined()) { 723 if (!interceptor->enumerator()->IsUndefined()) {
734 v8::IndexedPropertyEnumerator enum_fun = 724 v8::IndexedPropertyEnumerator enum_fun =
735 v8::ToCData<v8::IndexedPropertyEnumerator>(interceptor->enumerator()); 725 v8::ToCData<v8::IndexedPropertyEnumerator>(interceptor->enumerator());
736 LOG(isolate, ApiObjectAccess("interceptor-indexed-enum", *object)); 726 LOG(isolate, ApiObjectAccess("interceptor-indexed-enum", *object));
(...skipping 10 matching lines...) Expand all
747 static bool ContainsOnlyValidKeys(Handle<FixedArray> array) { 737 static bool ContainsOnlyValidKeys(Handle<FixedArray> array) {
748 int len = array->length(); 738 int len = array->length();
749 for (int i = 0; i < len; i++) { 739 for (int i = 0; i < len; i++) {
750 Object* e = array->get(i); 740 Object* e = array->get(i);
751 if (!(e->IsString() || e->IsNumber())) return false; 741 if (!(e->IsString() || e->IsNumber())) return false;
752 } 742 }
753 return true; 743 return true;
754 } 744 }
755 745
756 746
757 Handle<FixedArray> GetKeysInFixedArrayFor(Handle<JSObject> object, 747 Handle<FixedArray> GetKeysInFixedArrayFor(Handle<JSReceiver> object,
758 KeyCollectionType type) { 748 KeyCollectionType type,
749 bool* threw) {
759 USE(ContainsOnlyValidKeys); 750 USE(ContainsOnlyValidKeys);
760 Isolate* isolate = object->GetIsolate(); 751 Isolate* isolate = object->GetIsolate();
761 Handle<FixedArray> content = isolate->factory()->empty_fixed_array(); 752 Handle<FixedArray> content = isolate->factory()->empty_fixed_array();
762 Handle<JSObject> arguments_boilerplate = Handle<JSObject>( 753 Handle<JSObject> arguments_boilerplate = Handle<JSObject>(
763 isolate->context()->global_context()->arguments_boilerplate(), 754 isolate->context()->global_context()->arguments_boilerplate(),
764 isolate); 755 isolate);
765 Handle<JSFunction> arguments_function = Handle<JSFunction>( 756 Handle<JSFunction> arguments_function = Handle<JSFunction>(
766 JSFunction::cast(arguments_boilerplate->map()->constructor()), 757 JSFunction::cast(arguments_boilerplate->map()->constructor()),
767 isolate); 758 isolate);
768 759
769 // Only collect keys if access is permitted. 760 // Only collect keys if access is permitted.
770 for (Handle<Object> p = object; 761 for (Handle<Object> p = object;
771 *p != isolate->heap()->null_value(); 762 *p != isolate->heap()->null_value();
772 p = Handle<Object>(p->GetPrototype(), isolate)) { 763 p = Handle<Object>(p->GetPrototype(), isolate)) {
764 if (p->IsJSProxy()) {
765 Handle<JSProxy> proxy(JSProxy::cast(*p), isolate);
766 Handle<Object> args[] = { proxy };
767 Handle<Object> names = Execution::Call(
768 isolate->proxy_enumerate(), object, ARRAY_SIZE(args), args, threw);
769 if (*threw) return content;
770 content = AddKeysFromJSArray(content, Handle<JSArray>::cast(names));
771 break;
772 }
773
773 Handle<JSObject> current(JSObject::cast(*p), isolate); 774 Handle<JSObject> current(JSObject::cast(*p), isolate);
774 775
775 // Check access rights if required. 776 // Check access rights if required.
776 if (current->IsAccessCheckNeeded() && 777 if (current->IsAccessCheckNeeded() &&
777 !isolate->MayNamedAccess(*current, 778 !isolate->MayNamedAccess(*current,
778 isolate->heap()->undefined_value(), 779 isolate->heap()->undefined_value(),
779 v8::ACCESS_KEYS)) { 780 v8::ACCESS_KEYS)) {
780 isolate->ReportFailedAccessCheck(*current, v8::ACCESS_KEYS); 781 isolate->ReportFailedAccessCheck(*current, v8::ACCESS_KEYS);
781 break; 782 break;
782 } 783 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 830
830 // If we only want local properties we bail out after the first 831 // If we only want local properties we bail out after the first
831 // iteration. 832 // iteration.
832 if (type == LOCAL_ONLY) 833 if (type == LOCAL_ONLY)
833 break; 834 break;
834 } 835 }
835 return content; 836 return content;
836 } 837 }
837 838
838 839
839 Handle<JSArray> GetKeysFor(Handle<JSObject> object) { 840 Handle<JSArray> GetKeysFor(Handle<JSReceiver> object, bool* threw) {
840 Isolate* isolate = object->GetIsolate(); 841 Isolate* isolate = object->GetIsolate();
841 isolate->counters()->for_in()->Increment(); 842 isolate->counters()->for_in()->Increment();
842 Handle<FixedArray> elements = GetKeysInFixedArrayFor(object, 843 Handle<FixedArray> elements =
843 INCLUDE_PROTOS); 844 GetKeysInFixedArrayFor(object, INCLUDE_PROTOS, threw);
844 return isolate->factory()->NewJSArrayWithElements(elements); 845 return isolate->factory()->NewJSArrayWithElements(elements);
845 } 846 }
846 847
847 848
848 Handle<FixedArray> GetEnumPropertyKeys(Handle<JSObject> object, 849 Handle<FixedArray> GetEnumPropertyKeys(Handle<JSObject> object,
849 bool cache_result) { 850 bool cache_result) {
850 int index = 0; 851 int index = 0;
851 Isolate* isolate = object->GetIsolate(); 852 Isolate* isolate = object->GetIsolate();
852 if (object->HasFastProperties()) { 853 if (object->HasFastProperties()) {
853 if (object->map()->instance_descriptors()->HasEnumCache()) { 854 if (object->map()->instance_descriptors()->HasEnumCache()) {
(...skipping 29 matching lines...) Expand all
883 } else { 884 } else {
884 int num_enum = object->NumberOfEnumProperties(); 885 int num_enum = object->NumberOfEnumProperties();
885 Handle<FixedArray> storage = isolate->factory()->NewFixedArray(num_enum); 886 Handle<FixedArray> storage = isolate->factory()->NewFixedArray(num_enum);
886 Handle<FixedArray> sort_array = isolate->factory()->NewFixedArray(num_enum); 887 Handle<FixedArray> sort_array = isolate->factory()->NewFixedArray(num_enum);
887 object->property_dictionary()->CopyEnumKeysTo(*storage, *sort_array); 888 object->property_dictionary()->CopyEnumKeysTo(*storage, *sort_array);
888 return storage; 889 return storage;
889 } 890 }
890 } 891 }
891 892
892 893
894 Handle<ObjectHashSet> ObjectHashSetAdd(Handle<ObjectHashSet> table,
895 Handle<Object> key) {
896 CALL_HEAP_FUNCTION(table->GetIsolate(),
897 table->Add(*key),
898 ObjectHashSet);
899 }
900
901
902 Handle<ObjectHashSet> ObjectHashSetRemove(Handle<ObjectHashSet> table,
903 Handle<Object> key) {
904 CALL_HEAP_FUNCTION(table->GetIsolate(),
905 table->Remove(*key),
906 ObjectHashSet);
907 }
908
909
893 Handle<ObjectHashTable> PutIntoObjectHashTable(Handle<ObjectHashTable> table, 910 Handle<ObjectHashTable> PutIntoObjectHashTable(Handle<ObjectHashTable> table,
894 Handle<JSReceiver> key, 911 Handle<Object> key,
895 Handle<Object> value) { 912 Handle<Object> value) {
896 CALL_HEAP_FUNCTION(table->GetIsolate(), 913 CALL_HEAP_FUNCTION(table->GetIsolate(),
897 table->Put(*key, *value), 914 table->Put(*key, *value),
898 ObjectHashTable); 915 ObjectHashTable);
899 } 916 }
900 917
901 918
902 bool EnsureCompiled(Handle<SharedFunctionInfo> shared,
903 ClearExceptionFlag flag) {
904 return shared->is_compiled() || CompileLazyShared(shared, flag);
905 }
906
907
908 static bool CompileLazyHelper(CompilationInfo* info,
909 ClearExceptionFlag flag) {
910 // Compile the source information to a code object.
911 ASSERT(info->IsOptimizing() || !info->shared_info()->is_compiled());
912 ASSERT(!info->isolate()->has_pending_exception());
913 bool result = Compiler::CompileLazy(info);
914 ASSERT(result != Isolate::Current()->has_pending_exception());
915 if (!result && flag == CLEAR_EXCEPTION) {
916 info->isolate()->clear_pending_exception();
917 }
918 return result;
919 }
920
921
922 bool CompileLazyShared(Handle<SharedFunctionInfo> shared,
923 ClearExceptionFlag flag) {
924 CompilationInfo info(shared);
925 return CompileLazyHelper(&info, flag);
926 }
927
928
929 bool CompileLazy(Handle<JSFunction> function, ClearExceptionFlag flag) {
930 bool result = true;
931 if (function->shared()->is_compiled()) {
932 function->ReplaceCode(function->shared()->code());
933 function->shared()->set_code_age(0);
934 } else {
935 CompilationInfo info(function);
936 result = CompileLazyHelper(&info, flag);
937 ASSERT(!result || function->is_compiled());
938 }
939 return result;
940 }
941
942
943 bool CompileOptimized(Handle<JSFunction> function,
944 int osr_ast_id,
945 ClearExceptionFlag flag) {
946 CompilationInfo info(function);
947 info.SetOptimizing(osr_ast_id);
948 return CompileLazyHelper(&info, flag);
949 }
950
951 } } // namespace v8::internal 919 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/handles.h ('k') | src/heap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698