| OLD | NEW |
| 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 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 | 341 |
| 342 | 342 |
| 343 MaybeObject* TransitionElements(Handle<Object> object, | 343 MaybeObject* TransitionElements(Handle<Object> object, |
| 344 ElementsKind to_kind, | 344 ElementsKind to_kind, |
| 345 Isolate* isolate) { | 345 Isolate* isolate) { |
| 346 HandleScope scope(isolate); | 346 HandleScope scope(isolate); |
| 347 if (!object->IsJSObject()) return isolate->ThrowIllegalOperation(); | 347 if (!object->IsJSObject()) return isolate->ThrowIllegalOperation(); |
| 348 ElementsKind from_kind = | 348 ElementsKind from_kind = |
| 349 Handle<JSObject>::cast(object)->map()->elements_kind(); | 349 Handle<JSObject>::cast(object)->map()->elements_kind(); |
| 350 if (Map::IsValidElementsTransition(from_kind, to_kind)) { | 350 if (Map::IsValidElementsTransition(from_kind, to_kind)) { |
| 351 Handle<Object> result = JSObject::TransitionElementsKind( | 351 JSObject::TransitionElementsKind(Handle<JSObject>::cast(object), to_kind); |
| 352 Handle<JSObject>::cast(object), to_kind); | 352 return *object; |
| 353 if (result.is_null()) return isolate->ThrowIllegalOperation(); | |
| 354 return *result; | |
| 355 } | 353 } |
| 356 return isolate->ThrowIllegalOperation(); | 354 return isolate->ThrowIllegalOperation(); |
| 357 } | 355 } |
| 358 | 356 |
| 359 | 357 |
| 360 static const int kSmiLiteralMinimumLength = 1024; | 358 static const int kSmiLiteralMinimumLength = 1024; |
| 361 | 359 |
| 362 | 360 |
| 363 Handle<Object> Runtime::CreateArrayLiteralBoilerplate( | 361 Handle<Object> Runtime::CreateArrayLiteralBoilerplate( |
| 364 Isolate* isolate, | 362 Isolate* isolate, |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 Handle<FixedArray> literals, | 509 Handle<FixedArray> literals, |
| 512 int literals_index, | 510 int literals_index, |
| 513 Handle<FixedArray> elements) { | 511 Handle<FixedArray> elements) { |
| 514 // Check if boilerplate exists. If not, create it first. | 512 // Check if boilerplate exists. If not, create it first. |
| 515 Handle<Object> literal_site(literals->get(literals_index), isolate); | 513 Handle<Object> literal_site(literals->get(literals_index), isolate); |
| 516 Handle<AllocationSite> site; | 514 Handle<AllocationSite> site; |
| 517 if (*literal_site == isolate->heap()->undefined_value()) { | 515 if (*literal_site == isolate->heap()->undefined_value()) { |
| 518 ASSERT(*elements != isolate->heap()->empty_fixed_array()); | 516 ASSERT(*elements != isolate->heap()->empty_fixed_array()); |
| 519 Handle<Object> boilerplate = | 517 Handle<Object> boilerplate = |
| 520 Runtime::CreateArrayLiteralBoilerplate(isolate, literals, elements); | 518 Runtime::CreateArrayLiteralBoilerplate(isolate, literals, elements); |
| 521 if (boilerplate.is_null()) return site; | 519 if (boilerplate.is_null()) { |
| 520 ASSERT(site.is_null()); |
| 521 return site; |
| 522 } |
| 522 site = isolate->factory()->NewAllocationSite(); | 523 site = isolate->factory()->NewAllocationSite(); |
| 523 site->set_transition_info(*boilerplate); | 524 site->set_transition_info(*boilerplate); |
| 524 literals->set(literals_index, *site); | 525 literals->set(literals_index, *site); |
| 525 } else { | 526 } else { |
| 526 site = Handle<AllocationSite>::cast(literal_site); | 527 site = Handle<AllocationSite>::cast(literal_site); |
| 527 } | 528 } |
| 528 | 529 |
| 529 return site; | 530 return site; |
| 530 } | 531 } |
| 531 | 532 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 561 | 562 |
| 562 JSObject* boilerplate = JSObject::cast(site->transition_info()); | 563 JSObject* boilerplate = JSObject::cast(site->transition_info()); |
| 563 if (boilerplate->elements()->map() == | 564 if (boilerplate->elements()->map() == |
| 564 isolate->heap()->fixed_cow_array_map()) { | 565 isolate->heap()->fixed_cow_array_map()) { |
| 565 isolate->counters()->cow_arrays_created_runtime()->Increment(); | 566 isolate->counters()->cow_arrays_created_runtime()->Increment(); |
| 566 } | 567 } |
| 567 | 568 |
| 568 AllocationSiteMode mode = AllocationSite::GetMode( | 569 AllocationSiteMode mode = AllocationSite::GetMode( |
| 569 boilerplate->GetElementsKind()); | 570 boilerplate->GetElementsKind()); |
| 570 if (mode == TRACK_ALLOCATION_SITE) { | 571 if (mode == TRACK_ALLOCATION_SITE) { |
| 571 return isolate->heap()->CopyJSObjectWithAllocationSite( | 572 return isolate->heap()->CopyJSObject(boilerplate, *site); |
| 572 boilerplate, *site); | |
| 573 } | 573 } |
| 574 | 574 |
| 575 return isolate->heap()->CopyJSObject(boilerplate); | 575 return isolate->heap()->CopyJSObject(boilerplate); |
| 576 } | 576 } |
| 577 | 577 |
| 578 | 578 |
| 579 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateSymbol) { | 579 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateSymbol) { |
| 580 HandleScope scope(isolate); | 580 HandleScope scope(isolate); |
| 581 ASSERT(args.length() == 1); | 581 ASSERT(args.length() == 1); |
| 582 Handle<Object> name(args[0], isolate); | 582 Handle<Object> name(args[0], isolate); |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 926 | 926 |
| 927 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer(); | 927 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer(); |
| 928 size_t length = NumberToSize(isolate, *length_obj); | 928 size_t length = NumberToSize(isolate, *length_obj); |
| 929 size_t byte_length = length * element_size; | 929 size_t byte_length = length * element_size; |
| 930 if (byte_length < length) { // Overflow | 930 if (byte_length < length) { // Overflow |
| 931 return isolate->Throw(*isolate->factory()-> | 931 return isolate->Throw(*isolate->factory()-> |
| 932 NewRangeError("invalid_array_buffer_length", | 932 NewRangeError("invalid_array_buffer_length", |
| 933 HandleVector<Object>(NULL, 0))); | 933 HandleVector<Object>(NULL, 0))); |
| 934 } | 934 } |
| 935 | 935 |
| 936 // NOTE: not initializing backing store. |
| 936 // We assume that the caller of this function will initialize holder | 937 // We assume that the caller of this function will initialize holder |
| 937 // with the loop | 938 // with the loop |
| 938 // for(i = 0; i < length; i++) { holder[i] = source[i]; } | 939 // for(i = 0; i < length; i++) { holder[i] = source[i]; } |
| 940 // We assume that the caller of this function is always a typed array |
| 941 // constructor. |
| 939 // If source is a typed array, this loop will always run to completion, | 942 // If source is a typed array, this loop will always run to completion, |
| 940 // so we are sure that the backing store will be initialized. | 943 // so we are sure that the backing store will be initialized. |
| 941 // Otherwise, we do not know (the indexing operation might throw). | 944 // Otherwise, the indexing operation might throw, so the loop will not |
| 942 // Hence we require zero initialization unless our source is a typed array. | 945 // run to completion and the typed array might remain partly initialized. |
| 943 bool should_zero_initialize = !source->IsJSTypedArray(); | 946 // However we further assume that the caller of this function is a typed array |
| 947 // constructor, and the exception will propagate out of the constructor, |
| 948 // therefore uninitialized memory will not be accessible by a user program. |
| 949 // |
| 950 // TODO(dslomov): revise this once we support subclassing. |
| 944 | 951 |
| 945 if (!Runtime::SetupArrayBufferAllocatingData( | 952 if (!Runtime::SetupArrayBufferAllocatingData( |
| 946 isolate, buffer, byte_length, should_zero_initialize)) { | 953 isolate, buffer, byte_length, false)) { |
| 947 return isolate->Throw(*isolate->factory()-> | 954 return isolate->Throw(*isolate->factory()-> |
| 948 NewRangeError("invalid_array_buffer_length", | 955 NewRangeError("invalid_array_buffer_length", |
| 949 HandleVector<Object>(NULL, 0))); | 956 HandleVector<Object>(NULL, 0))); |
| 950 } | 957 } |
| 951 | 958 |
| 952 holder->set_buffer(*buffer); | 959 holder->set_buffer(*buffer); |
| 953 holder->set_byte_offset(Smi::FromInt(0)); | 960 holder->set_byte_offset(Smi::FromInt(0)); |
| 954 Handle<Object> byte_length_obj( | 961 Handle<Object> byte_length_obj( |
| 955 isolate->factory()->NewNumberFromSize(byte_length)); | 962 isolate->factory()->NewNumberFromSize(byte_length)); |
| 956 holder->set_byte_length(*byte_length_obj); | 963 holder->set_byte_length(*byte_length_obj); |
| (...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1816 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetOwnProperty) { | 1823 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetOwnProperty) { |
| 1817 HandleScope scope(isolate); | 1824 HandleScope scope(isolate); |
| 1818 ASSERT(args.length() == 2); | 1825 ASSERT(args.length() == 2); |
| 1819 CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0); | 1826 CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0); |
| 1820 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); | 1827 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); |
| 1821 return GetOwnProperty(isolate, obj, name); | 1828 return GetOwnProperty(isolate, obj, name); |
| 1822 } | 1829 } |
| 1823 | 1830 |
| 1824 | 1831 |
| 1825 RUNTIME_FUNCTION(MaybeObject*, Runtime_PreventExtensions) { | 1832 RUNTIME_FUNCTION(MaybeObject*, Runtime_PreventExtensions) { |
| 1826 SealHandleScope shs(isolate); | 1833 HandleScope scope(isolate); |
| 1827 ASSERT(args.length() == 1); | 1834 ASSERT(args.length() == 1); |
| 1828 CONVERT_ARG_CHECKED(JSObject, obj, 0); | 1835 CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0); |
| 1829 return obj->PreventExtensions(); | 1836 Handle<Object> result = JSObject::PreventExtensions(obj); |
| 1837 RETURN_IF_EMPTY_HANDLE(isolate, result); |
| 1838 return *result; |
| 1830 } | 1839 } |
| 1831 | 1840 |
| 1832 | 1841 |
| 1833 RUNTIME_FUNCTION(MaybeObject*, Runtime_IsExtensible) { | 1842 RUNTIME_FUNCTION(MaybeObject*, Runtime_IsExtensible) { |
| 1834 SealHandleScope shs(isolate); | 1843 SealHandleScope shs(isolate); |
| 1835 ASSERT(args.length() == 1); | 1844 ASSERT(args.length() == 1); |
| 1836 CONVERT_ARG_CHECKED(JSObject, obj, 0); | 1845 CONVERT_ARG_CHECKED(JSObject, obj, 0); |
| 1837 if (obj->IsJSGlobalProxy()) { | 1846 if (obj->IsJSGlobalProxy()) { |
| 1838 Object* proto = obj->GetPrototype(); | 1847 Object* proto = obj->GetPrototype(); |
| 1839 if (proto->IsNull()) return isolate->heap()->false_value(); | 1848 if (proto->IsNull()) return isolate->heap()->false_value(); |
| 1840 ASSERT(proto->IsJSGlobalObject()); | 1849 ASSERT(proto->IsJSGlobalObject()); |
| 1841 obj = JSObject::cast(proto); | 1850 obj = JSObject::cast(proto); |
| 1842 } | 1851 } |
| 1843 return isolate->heap()->ToBoolean(obj->map()->is_extensible()); | 1852 return isolate->heap()->ToBoolean(obj->map()->is_extensible()); |
| 1844 } | 1853 } |
| 1845 | 1854 |
| 1846 | 1855 |
| 1847 RUNTIME_FUNCTION(MaybeObject*, Runtime_RegExpCompile) { | 1856 RUNTIME_FUNCTION(MaybeObject*, Runtime_RegExpCompile) { |
| 1848 HandleScope scope(isolate); | 1857 HandleScope scope(isolate); |
| 1849 ASSERT(args.length() == 3); | 1858 ASSERT(args.length() == 3); |
| 1850 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, re, 0); | 1859 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, re, 0); |
| 1851 CONVERT_ARG_HANDLE_CHECKED(String, pattern, 1); | 1860 CONVERT_ARG_HANDLE_CHECKED(String, pattern, 1); |
| 1852 CONVERT_ARG_HANDLE_CHECKED(String, flags, 2); | 1861 CONVERT_ARG_HANDLE_CHECKED(String, flags, 2); |
| 1853 Handle<Object> result = | 1862 Handle<Object> result = RegExpImpl::Compile(re, pattern, flags); |
| 1854 RegExpImpl::Compile(re, pattern, flags); | |
| 1855 RETURN_IF_EMPTY_HANDLE(isolate, result); | 1863 RETURN_IF_EMPTY_HANDLE(isolate, result); |
| 1856 return *result; | 1864 return *result; |
| 1857 } | 1865 } |
| 1858 | 1866 |
| 1859 | 1867 |
| 1860 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateApiFunction) { | 1868 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateApiFunction) { |
| 1861 HandleScope scope(isolate); | 1869 HandleScope scope(isolate); |
| 1862 ASSERT(args.length() == 1); | 1870 ASSERT(args.length() == 1); |
| 1863 CONVERT_ARG_HANDLE_CHECKED(FunctionTemplateInfo, data, 0); | 1871 CONVERT_ARG_HANDLE_CHECKED(FunctionTemplateInfo, data, 0); |
| 1864 return *isolate->factory()->CreateApiFunction(data); | 1872 return *isolate->factory()->CreateApiFunction(data); |
| (...skipping 4049 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5914 } | 5922 } |
| 5915 return function; | 5923 return function; |
| 5916 } | 5924 } |
| 5917 | 5925 |
| 5918 // Lookup in the initial Object.prototype object. | 5926 // Lookup in the initial Object.prototype object. |
| 5919 return isolate->initial_object_prototype()->GetProperty(*key); | 5927 return isolate->initial_object_prototype()->GetProperty(*key); |
| 5920 } | 5928 } |
| 5921 | 5929 |
| 5922 | 5930 |
| 5923 RUNTIME_FUNCTION(MaybeObject*, Runtime_ToFastProperties) { | 5931 RUNTIME_FUNCTION(MaybeObject*, Runtime_ToFastProperties) { |
| 5924 SealHandleScope shs(isolate); | 5932 HandleScope scope(isolate); |
| 5925 ASSERT(args.length() == 1); | 5933 ASSERT(args.length() == 1); |
| 5926 Object* object = args[0]; | 5934 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); |
| 5927 return (object->IsJSObject() && !object->IsGlobalObject()) | 5935 if (object->IsJSObject() && !object->IsGlobalObject()) { |
| 5928 ? JSObject::cast(object)->TransformToFastProperties(0) | 5936 JSObject::TransformToFastProperties(Handle<JSObject>::cast(object), 0); |
| 5929 : object; | 5937 } |
| 5938 return *object; |
| 5930 } | 5939 } |
| 5931 | 5940 |
| 5932 | 5941 |
| 5933 RUNTIME_FUNCTION(MaybeObject*, Runtime_ToBool) { | 5942 RUNTIME_FUNCTION(MaybeObject*, Runtime_ToBool) { |
| 5934 SealHandleScope shs(isolate); | 5943 SealHandleScope shs(isolate); |
| 5935 ASSERT(args.length() == 1); | 5944 ASSERT(args.length() == 1); |
| 5936 | 5945 |
| 5937 return isolate->heap()->ToBoolean(args[0]->BooleanValue()); | 5946 return isolate->heap()->ToBoolean(args[0]->BooleanValue()); |
| 5938 } | 5947 } |
| 5939 | 5948 |
| (...skipping 8859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14799 // Handle last resort GC and make sure to allow future allocations | 14808 // Handle last resort GC and make sure to allow future allocations |
| 14800 // to grow the heap without causing GCs (if possible). | 14809 // to grow the heap without causing GCs (if possible). |
| 14801 isolate->counters()->gc_last_resort_from_js()->Increment(); | 14810 isolate->counters()->gc_last_resort_from_js()->Increment(); |
| 14802 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 14811 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
| 14803 "Runtime::PerformGC"); | 14812 "Runtime::PerformGC"); |
| 14804 } | 14813 } |
| 14805 } | 14814 } |
| 14806 | 14815 |
| 14807 | 14816 |
| 14808 } } // namespace v8::internal | 14817 } } // namespace v8::internal |
| OLD | NEW |