| 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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 | 146 |
| 147 | 147 |
| 148 // Cast the given argument to PropertyDetails and store its value in a | 148 // Cast the given argument to PropertyDetails and store its value in a |
| 149 // variable with the given name. If the argument is not a Smi call | 149 // variable with the given name. If the argument is not a Smi call |
| 150 // IllegalOperation and return. | 150 // IllegalOperation and return. |
| 151 #define CONVERT_PROPERTY_DETAILS_CHECKED(name, index) \ | 151 #define CONVERT_PROPERTY_DETAILS_CHECKED(name, index) \ |
| 152 RUNTIME_ASSERT(args[index]->IsSmi()); \ | 152 RUNTIME_ASSERT(args[index]->IsSmi()); \ |
| 153 PropertyDetails name = PropertyDetails(Smi::cast(args[index])); | 153 PropertyDetails name = PropertyDetails(Smi::cast(args[index])); |
| 154 | 154 |
| 155 | 155 |
| 156 // Assert that the given argument has a valid value for a StrictModeFlag | 156 // Assert that the given argument has a valid value for a StrictMode |
| 157 // and store it in a StrictModeFlag variable with the given name. | 157 // and store it in a StrictMode variable with the given name. |
| 158 #define CONVERT_STRICT_MODE_ARG_CHECKED(name, index) \ | 158 #define CONVERT_STRICT_MODE_ARG_CHECKED(name, index) \ |
| 159 RUNTIME_ASSERT(args[index]->IsSmi()); \ | 159 RUNTIME_ASSERT(args[index]->IsSmi()); \ |
| 160 RUNTIME_ASSERT(args.smi_at(index) == kStrictMode || \ | 160 RUNTIME_ASSERT(args.smi_at(index) == STRICT || \ |
| 161 args.smi_at(index) == kNonStrictMode); \ | 161 args.smi_at(index) == SLOPPY); \ |
| 162 StrictModeFlag name = \ | 162 StrictMode name = static_cast<StrictMode>(args.smi_at(index)); |
| 163 static_cast<StrictModeFlag>(args.smi_at(index)); | |
| 164 | |
| 165 | |
| 166 // Assert that the given argument has a valid value for a LanguageMode | |
| 167 // and store it in a LanguageMode variable with the given name. | |
| 168 #define CONVERT_LANGUAGE_MODE_ARG(name, index) \ | |
| 169 ASSERT(args[index]->IsSmi()); \ | |
| 170 ASSERT(args.smi_at(index) == CLASSIC_MODE || \ | |
| 171 args.smi_at(index) == STRICT_MODE || \ | |
| 172 args.smi_at(index) == EXTENDED_MODE); \ | |
| 173 LanguageMode name = \ | |
| 174 static_cast<LanguageMode>(args.smi_at(index)); | |
| 175 | 163 |
| 176 | 164 |
| 177 static Handle<Map> ComputeObjectLiteralMap( | 165 static Handle<Map> ComputeObjectLiteralMap( |
| 178 Handle<Context> context, | 166 Handle<Context> context, |
| 179 Handle<FixedArray> constant_properties, | 167 Handle<FixedArray> constant_properties, |
| 180 bool* is_result_from_cache) { | 168 bool* is_result_from_cache) { |
| 181 Isolate* isolate = context->GetIsolate(); | 169 Isolate* isolate = context->GetIsolate(); |
| 182 int properties_length = constant_properties->length(); | 170 int properties_length = constant_properties->length(); |
| 183 int number_of_properties = properties_length / 2; | 171 int number_of_properties = properties_length / 2; |
| 184 // Check that there are only internal strings and array indices among keys. | 172 // Check that there are only internal strings and array indices among keys. |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 value = CreateLiteralBoilerplate(isolate, literals, array); | 279 value = CreateLiteralBoilerplate(isolate, literals, array); |
| 292 if (value.is_null()) return value; | 280 if (value.is_null()) return value; |
| 293 } | 281 } |
| 294 Handle<Object> result; | 282 Handle<Object> result; |
| 295 uint32_t element_index = 0; | 283 uint32_t element_index = 0; |
| 296 StoreMode mode = value->IsJSObject() ? FORCE_FIELD : ALLOW_AS_CONSTANT; | 284 StoreMode mode = value->IsJSObject() ? FORCE_FIELD : ALLOW_AS_CONSTANT; |
| 297 if (key->IsInternalizedString()) { | 285 if (key->IsInternalizedString()) { |
| 298 if (Handle<String>::cast(key)->AsArrayIndex(&element_index)) { | 286 if (Handle<String>::cast(key)->AsArrayIndex(&element_index)) { |
| 299 // Array index as string (uint32). | 287 // Array index as string (uint32). |
| 300 result = JSObject::SetOwnElement( | 288 result = JSObject::SetOwnElement( |
| 301 boilerplate, element_index, value, kNonStrictMode); | 289 boilerplate, element_index, value, SLOPPY); |
| 302 } else { | 290 } else { |
| 303 Handle<String> name(String::cast(*key)); | 291 Handle<String> name(String::cast(*key)); |
| 304 ASSERT(!name->AsArrayIndex(&element_index)); | 292 ASSERT(!name->AsArrayIndex(&element_index)); |
| 305 result = JSObject::SetLocalPropertyIgnoreAttributes( | 293 result = JSObject::SetLocalPropertyIgnoreAttributes( |
| 306 boilerplate, name, value, NONE, | 294 boilerplate, name, value, NONE, |
| 307 Object::OPTIMAL_REPRESENTATION, mode); | 295 Object::OPTIMAL_REPRESENTATION, mode); |
| 308 } | 296 } |
| 309 } else if (key->ToArrayIndex(&element_index)) { | 297 } else if (key->ToArrayIndex(&element_index)) { |
| 310 // Array index (uint32). | 298 // Array index (uint32). |
| 311 result = JSObject::SetOwnElement( | 299 result = JSObject::SetOwnElement( |
| 312 boilerplate, element_index, value, kNonStrictMode); | 300 boilerplate, element_index, value, SLOPPY); |
| 313 } else { | 301 } else { |
| 314 // Non-uint32 number. | 302 // Non-uint32 number. |
| 315 ASSERT(key->IsNumber()); | 303 ASSERT(key->IsNumber()); |
| 316 double num = key->Number(); | 304 double num = key->Number(); |
| 317 char arr[100]; | 305 char arr[100]; |
| 318 Vector<char> buffer(arr, ARRAY_SIZE(arr)); | 306 Vector<char> buffer(arr, ARRAY_SIZE(arr)); |
| 319 const char* str = DoubleToCString(num, buffer); | 307 const char* str = DoubleToCString(num, buffer); |
| 320 Handle<String> name = | 308 Handle<String> name = |
| 321 isolate->factory()->NewStringFromAscii(CStrVector(str)); | 309 isolate->factory()->NewStringFromAscii(CStrVector(str)); |
| 322 result = JSObject::SetLocalPropertyIgnoreAttributes( | 310 result = JSObject::SetLocalPropertyIgnoreAttributes( |
| (...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 957 v8::ArrayBufferView::kInternalFieldCount); | 945 v8::ArrayBufferView::kInternalFieldCount); |
| 958 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) { | 946 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) { |
| 959 holder->SetInternalField(i, Smi::FromInt(0)); | 947 holder->SetInternalField(i, Smi::FromInt(0)); |
| 960 } | 948 } |
| 961 | 949 |
| 962 ExternalArrayType array_type = kExternalInt8Array; // Bogus initialization. | 950 ExternalArrayType array_type = kExternalInt8Array; // Bogus initialization. |
| 963 size_t element_size = 1; // Bogus initialization. | 951 size_t element_size = 1; // Bogus initialization. |
| 964 Runtime::ArrayIdToTypeAndSize(arrayId, &array_type, &element_size); | 952 Runtime::ArrayIdToTypeAndSize(arrayId, &array_type, &element_size); |
| 965 | 953 |
| 966 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer(); | 954 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer(); |
| 955 if (source->IsJSTypedArray() && |
| 956 JSTypedArray::cast(*source)->type() == array_type) { |
| 957 length_obj = Handle<Object>(JSTypedArray::cast(*source)->length(), isolate); |
| 958 } |
| 967 size_t length = NumberToSize(isolate, *length_obj); | 959 size_t length = NumberToSize(isolate, *length_obj); |
| 968 | 960 |
| 969 if ((length > static_cast<unsigned>(Smi::kMaxValue)) || | 961 if ((length > static_cast<unsigned>(Smi::kMaxValue)) || |
| 970 (length > (kMaxInt / element_size))) { | 962 (length > (kMaxInt / element_size))) { |
| 971 return isolate->Throw(*isolate->factory()-> | 963 return isolate->Throw(*isolate->factory()-> |
| 972 NewRangeError("invalid_typed_array_length", | 964 NewRangeError("invalid_typed_array_length", |
| 973 HandleVector<Object>(NULL, 0))); | 965 HandleVector<Object>(NULL, 0))); |
| 974 } | 966 } |
| 975 size_t byte_length = length * element_size; | 967 size_t byte_length = length * element_size; |
| 976 | 968 |
| (...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1614 HandleScope scope(isolate); | 1606 HandleScope scope(isolate); |
| 1615 ASSERT(args.length() == 1); | 1607 ASSERT(args.length() == 1); |
| 1616 CONVERT_ARG_HANDLE_CHECKED(Object, obj, 0); | 1608 CONVERT_ARG_HANDLE_CHECKED(Object, obj, 0); |
| 1617 // We don't expect access checks to be needed on JSProxy objects. | 1609 // We don't expect access checks to be needed on JSProxy objects. |
| 1618 ASSERT(!obj->IsAccessCheckNeeded() || obj->IsJSObject()); | 1610 ASSERT(!obj->IsAccessCheckNeeded() || obj->IsJSObject()); |
| 1619 do { | 1611 do { |
| 1620 if (obj->IsAccessCheckNeeded() && | 1612 if (obj->IsAccessCheckNeeded() && |
| 1621 !isolate->MayNamedAccessWrapper(Handle<JSObject>::cast(obj), | 1613 !isolate->MayNamedAccessWrapper(Handle<JSObject>::cast(obj), |
| 1622 isolate->factory()->proto_string(), | 1614 isolate->factory()->proto_string(), |
| 1623 v8::ACCESS_GET)) { | 1615 v8::ACCESS_GET)) { |
| 1624 isolate->ReportFailedAccessCheck(JSObject::cast(*obj), v8::ACCESS_GET); | 1616 isolate->ReportFailedAccessCheckWrapper(Handle<JSObject>::cast(obj), |
| 1617 v8::ACCESS_GET); |
| 1625 RETURN_IF_SCHEDULED_EXCEPTION(isolate); | 1618 RETURN_IF_SCHEDULED_EXCEPTION(isolate); |
| 1626 return isolate->heap()->undefined_value(); | 1619 return isolate->heap()->undefined_value(); |
| 1627 } | 1620 } |
| 1628 obj = handle(obj->GetPrototype(isolate), isolate); | 1621 obj = handle(obj->GetPrototype(isolate), isolate); |
| 1629 } while (obj->IsJSObject() && | 1622 } while (obj->IsJSObject() && |
| 1630 JSObject::cast(*obj)->map()->is_hidden_prototype()); | 1623 JSObject::cast(*obj)->map()->is_hidden_prototype()); |
| 1631 return *obj; | 1624 return *obj; |
| 1632 } | 1625 } |
| 1633 | 1626 |
| 1634 | 1627 |
| 1635 static inline Object* GetPrototypeSkipHiddenPrototypes(Isolate* isolate, | 1628 static inline Object* GetPrototypeSkipHiddenPrototypes(Isolate* isolate, |
| 1636 Object* receiver) { | 1629 Object* receiver) { |
| 1637 Object* current = receiver->GetPrototype(isolate); | 1630 Object* current = receiver->GetPrototype(isolate); |
| 1638 while (current->IsJSObject() && | 1631 while (current->IsJSObject() && |
| 1639 JSObject::cast(current)->map()->is_hidden_prototype()) { | 1632 JSObject::cast(current)->map()->is_hidden_prototype()) { |
| 1640 current = current->GetPrototype(isolate); | 1633 current = current->GetPrototype(isolate); |
| 1641 } | 1634 } |
| 1642 return current; | 1635 return current; |
| 1643 } | 1636 } |
| 1644 | 1637 |
| 1645 | 1638 |
| 1646 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetPrototype) { | 1639 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetPrototype) { |
| 1647 HandleScope scope(isolate); | 1640 HandleScope scope(isolate); |
| 1648 ASSERT(args.length() == 2); | 1641 ASSERT(args.length() == 2); |
| 1649 CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0); | 1642 CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0); |
| 1650 CONVERT_ARG_HANDLE_CHECKED(Object, prototype, 1); | 1643 CONVERT_ARG_HANDLE_CHECKED(Object, prototype, 1); |
| 1651 if (FLAG_harmony_observation && obj->map()->is_observed()) { | 1644 if (obj->map()->is_observed()) { |
| 1652 Handle<Object> old_value( | 1645 Handle<Object> old_value( |
| 1653 GetPrototypeSkipHiddenPrototypes(isolate, *obj), isolate); | 1646 GetPrototypeSkipHiddenPrototypes(isolate, *obj), isolate); |
| 1654 | 1647 |
| 1655 Handle<Object> result = JSObject::SetPrototype(obj, prototype, true); | 1648 Handle<Object> result = JSObject::SetPrototype(obj, prototype, true); |
| 1656 RETURN_IF_EMPTY_HANDLE(isolate, result); | 1649 RETURN_IF_EMPTY_HANDLE(isolate, result); |
| 1657 | 1650 |
| 1658 Handle<Object> new_value( | 1651 Handle<Object> new_value( |
| 1659 GetPrototypeSkipHiddenPrototypes(isolate, *obj), isolate); | 1652 GetPrototypeSkipHiddenPrototypes(isolate, *obj), isolate); |
| 1660 if (!new_value->SameValue(*old_value)) { | 1653 if (!new_value->SameValue(*old_value)) { |
| 1661 JSObject::EnqueueChangeRecord(obj, "setPrototype", | 1654 JSObject::EnqueueChangeRecord(obj, "setPrototype", |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1740 Handle<Name> name, | 1733 Handle<Name> name, |
| 1741 v8::AccessType access_type) { | 1734 v8::AccessType access_type) { |
| 1742 uint32_t index; | 1735 uint32_t index; |
| 1743 if (name->AsArrayIndex(&index)) { | 1736 if (name->AsArrayIndex(&index)) { |
| 1744 // TODO(1095): we should traverse hidden prototype hierachy as well. | 1737 // TODO(1095): we should traverse hidden prototype hierachy as well. |
| 1745 if (CheckGenericAccess( | 1738 if (CheckGenericAccess( |
| 1746 obj, obj, index, access_type, &Isolate::MayIndexedAccessWrapper)) { | 1739 obj, obj, index, access_type, &Isolate::MayIndexedAccessWrapper)) { |
| 1747 return ACCESS_ALLOWED; | 1740 return ACCESS_ALLOWED; |
| 1748 } | 1741 } |
| 1749 | 1742 |
| 1750 obj->GetIsolate()->ReportFailedAccessCheck(*obj, access_type); | 1743 obj->GetIsolate()->ReportFailedAccessCheckWrapper(obj, access_type); |
| 1751 return ACCESS_FORBIDDEN; | 1744 return ACCESS_FORBIDDEN; |
| 1752 } | 1745 } |
| 1753 | 1746 |
| 1754 Isolate* isolate = obj->GetIsolate(); | 1747 Isolate* isolate = obj->GetIsolate(); |
| 1755 LookupResult lookup(isolate); | 1748 LookupResult lookup(isolate); |
| 1756 obj->LocalLookup(*name, &lookup, true); | 1749 obj->LocalLookup(*name, &lookup, true); |
| 1757 | 1750 |
| 1758 if (!lookup.IsProperty()) return ACCESS_ABSENT; | 1751 if (!lookup.IsProperty()) return ACCESS_ABSENT; |
| 1759 Handle<JSObject> holder(lookup.holder(), isolate); | 1752 Handle<JSObject> holder(lookup.holder(), isolate); |
| 1760 if (CheckGenericAccess<Handle<Object> >( | 1753 if (CheckGenericAccess<Handle<Object> >( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1779 if (lookup.IsProperty() && lookup.IsPropertyCallbacks()) { | 1772 if (lookup.IsProperty() && lookup.IsPropertyCallbacks()) { |
| 1780 if (CheckAccessException(lookup.GetCallbackObject(), access_type)) { | 1773 if (CheckAccessException(lookup.GetCallbackObject(), access_type)) { |
| 1781 return ACCESS_ALLOWED; | 1774 return ACCESS_ALLOWED; |
| 1782 } | 1775 } |
| 1783 } | 1776 } |
| 1784 break; | 1777 break; |
| 1785 default: | 1778 default: |
| 1786 break; | 1779 break; |
| 1787 } | 1780 } |
| 1788 | 1781 |
| 1789 isolate->ReportFailedAccessCheck(*obj, access_type); | 1782 isolate->ReportFailedAccessCheckWrapper(obj, access_type); |
| 1790 return ACCESS_FORBIDDEN; | 1783 return ACCESS_FORBIDDEN; |
| 1791 } | 1784 } |
| 1792 | 1785 |
| 1793 | 1786 |
| 1794 // Enumerator used as indices into the array returned from GetOwnProperty | 1787 // Enumerator used as indices into the array returned from GetOwnProperty |
| 1795 enum PropertyDescriptorIndices { | 1788 enum PropertyDescriptorIndices { |
| 1796 IS_ACCESSOR_INDEX, | 1789 IS_ACCESSOR_INDEX, |
| 1797 VALUE_INDEX, | 1790 VALUE_INDEX, |
| 1798 GETTER_INDEX, | 1791 GETTER_INDEX, |
| 1799 SETTER_INDEX, | 1792 SETTER_INDEX, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1813 // more than one access failure here. | 1806 // more than one access failure here. |
| 1814 AccessCheckResult access_check_result = | 1807 AccessCheckResult access_check_result = |
| 1815 CheckPropertyAccess(obj, name, v8::ACCESS_HAS); | 1808 CheckPropertyAccess(obj, name, v8::ACCESS_HAS); |
| 1816 RETURN_HANDLE_IF_SCHEDULED_EXCEPTION(isolate, Object); | 1809 RETURN_HANDLE_IF_SCHEDULED_EXCEPTION(isolate, Object); |
| 1817 switch (access_check_result) { | 1810 switch (access_check_result) { |
| 1818 case ACCESS_FORBIDDEN: return factory->false_value(); | 1811 case ACCESS_FORBIDDEN: return factory->false_value(); |
| 1819 case ACCESS_ALLOWED: break; | 1812 case ACCESS_ALLOWED: break; |
| 1820 case ACCESS_ABSENT: return factory->undefined_value(); | 1813 case ACCESS_ABSENT: return factory->undefined_value(); |
| 1821 } | 1814 } |
| 1822 | 1815 |
| 1823 PropertyAttributes attrs = obj->GetLocalPropertyAttribute(*name); | 1816 PropertyAttributes attrs = JSReceiver::GetLocalPropertyAttribute(obj, name); |
| 1824 if (attrs == ABSENT) { | 1817 if (attrs == ABSENT) { |
| 1825 RETURN_HANDLE_IF_SCHEDULED_EXCEPTION(isolate, Object); | 1818 RETURN_HANDLE_IF_SCHEDULED_EXCEPTION(isolate, Object); |
| 1826 return factory->undefined_value(); | 1819 return factory->undefined_value(); |
| 1827 } | 1820 } |
| 1828 ASSERT(!isolate->has_scheduled_exception()); | 1821 ASSERT(!isolate->has_scheduled_exception()); |
| 1829 AccessorPair* raw_accessors = obj->GetLocalPropertyAccessorPair(*name); | 1822 AccessorPair* raw_accessors = obj->GetLocalPropertyAccessorPair(*name); |
| 1830 Handle<AccessorPair> accessors(raw_accessors, isolate); | 1823 Handle<AccessorPair> accessors(raw_accessors, isolate); |
| 1831 Handle<FixedArray> elms = isolate->factory()->NewFixedArray(DESCRIPTOR_SIZE); | 1824 Handle<FixedArray> elms = isolate->factory()->NewFixedArray(DESCRIPTOR_SIZE); |
| 1832 elms->set(ENUMERABLE_INDEX, heap->ToBoolean((attrs & DONT_ENUM) == 0)); | 1825 elms->set(ENUMERABLE_INDEX, heap->ToBoolean((attrs & DONT_ENUM) == 0)); |
| 1833 elms->set(CONFIGURABLE_INDEX, heap->ToBoolean((attrs & DONT_DELETE) == 0)); | 1826 elms->set(CONFIGURABLE_INDEX, heap->ToBoolean((attrs & DONT_DELETE) == 0)); |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2056 bool is_var = value->IsUndefined(); | 2049 bool is_var = value->IsUndefined(); |
| 2057 bool is_const = value->IsTheHole(); | 2050 bool is_const = value->IsTheHole(); |
| 2058 bool is_function = value->IsSharedFunctionInfo(); | 2051 bool is_function = value->IsSharedFunctionInfo(); |
| 2059 ASSERT(is_var + is_const + is_function == 1); | 2052 ASSERT(is_var + is_const + is_function == 1); |
| 2060 | 2053 |
| 2061 if (is_var || is_const) { | 2054 if (is_var || is_const) { |
| 2062 // Lookup the property in the global object, and don't set the | 2055 // Lookup the property in the global object, and don't set the |
| 2063 // value of the variable if the property is already there. | 2056 // value of the variable if the property is already there. |
| 2064 // Do the lookup locally only, see ES5 erratum. | 2057 // Do the lookup locally only, see ES5 erratum. |
| 2065 LookupResult lookup(isolate); | 2058 LookupResult lookup(isolate); |
| 2066 if (FLAG_es52_globals) { | 2059 global->LocalLookup(*name, &lookup, true); |
| 2067 global->LocalLookup(*name, &lookup, true); | |
| 2068 } else { | |
| 2069 global->Lookup(*name, &lookup); | |
| 2070 } | |
| 2071 if (lookup.IsFound()) { | 2060 if (lookup.IsFound()) { |
| 2072 // We found an existing property. Unless it was an interceptor | 2061 // We found an existing property. Unless it was an interceptor |
| 2073 // that claims the property is absent, skip this declaration. | 2062 // that claims the property is absent, skip this declaration. |
| 2074 if (!lookup.IsInterceptor()) continue; | 2063 if (!lookup.IsInterceptor()) continue; |
| 2075 PropertyAttributes attributes = global->GetPropertyAttribute(*name); | 2064 if (JSReceiver::GetPropertyAttribute(global, name) != ABSENT) continue; |
| 2076 if (attributes != ABSENT) continue; | |
| 2077 // Fall-through and introduce the absent property by using | 2065 // Fall-through and introduce the absent property by using |
| 2078 // SetProperty. | 2066 // SetProperty. |
| 2079 } | 2067 } |
| 2080 } else if (is_function) { | 2068 } else if (is_function) { |
| 2081 // Copy the function and update its context. Use it as value. | 2069 // Copy the function and update its context. Use it as value. |
| 2082 Handle<SharedFunctionInfo> shared = | 2070 Handle<SharedFunctionInfo> shared = |
| 2083 Handle<SharedFunctionInfo>::cast(value); | 2071 Handle<SharedFunctionInfo>::cast(value); |
| 2084 Handle<JSFunction> function = | 2072 Handle<JSFunction> function = |
| 2085 isolate->factory()->NewFunctionFromSharedFunctionInfo( | 2073 isolate->factory()->NewFunctionFromSharedFunctionInfo( |
| 2086 shared, context, TENURED); | 2074 shared, context, TENURED); |
| 2087 value = function; | 2075 value = function; |
| 2088 } | 2076 } |
| 2089 | 2077 |
| 2090 LookupResult lookup(isolate); | 2078 LookupResult lookup(isolate); |
| 2091 global->LocalLookup(*name, &lookup, true); | 2079 global->LocalLookup(*name, &lookup, true); |
| 2092 | 2080 |
| 2093 // Compute the property attributes. According to ECMA-262, | 2081 // Compute the property attributes. According to ECMA-262, |
| 2094 // the property must be non-configurable except in eval. | 2082 // the property must be non-configurable except in eval. |
| 2095 int attr = NONE; | 2083 int attr = NONE; |
| 2096 bool is_eval = DeclareGlobalsEvalFlag::decode(flags); | 2084 bool is_eval = DeclareGlobalsEvalFlag::decode(flags); |
| 2097 if (!is_eval) { | 2085 if (!is_eval) { |
| 2098 attr |= DONT_DELETE; | 2086 attr |= DONT_DELETE; |
| 2099 } | 2087 } |
| 2100 bool is_native = DeclareGlobalsNativeFlag::decode(flags); | 2088 bool is_native = DeclareGlobalsNativeFlag::decode(flags); |
| 2101 if (is_const || (is_native && is_function)) { | 2089 if (is_const || (is_native && is_function)) { |
| 2102 attr |= READ_ONLY; | 2090 attr |= READ_ONLY; |
| 2103 } | 2091 } |
| 2104 | 2092 |
| 2105 LanguageMode language_mode = DeclareGlobalsLanguageMode::decode(flags); | 2093 StrictMode strict_mode = DeclareGlobalsStrictMode::decode(flags); |
| 2106 | 2094 |
| 2107 if (!lookup.IsFound() || is_function) { | 2095 if (!lookup.IsFound() || is_function) { |
| 2108 // If the local property exists, check that we can reconfigure it | 2096 // If the local property exists, check that we can reconfigure it |
| 2109 // as required for function declarations. | 2097 // as required for function declarations. |
| 2110 if (lookup.IsFound() && lookup.IsDontDelete()) { | 2098 if (lookup.IsFound() && lookup.IsDontDelete()) { |
| 2111 if (lookup.IsReadOnly() || lookup.IsDontEnum() || | 2099 if (lookup.IsReadOnly() || lookup.IsDontEnum() || |
| 2112 lookup.IsPropertyCallbacks()) { | 2100 lookup.IsPropertyCallbacks()) { |
| 2113 return ThrowRedeclarationError(isolate, "function", name); | 2101 return ThrowRedeclarationError(isolate, "function", name); |
| 2114 } | 2102 } |
| 2115 // If the existing property is not configurable, keep its attributes. | 2103 // If the existing property is not configurable, keep its attributes. |
| 2116 attr = lookup.GetAttributes(); | 2104 attr = lookup.GetAttributes(); |
| 2117 } | 2105 } |
| 2118 // Define or redefine own property. | 2106 // Define or redefine own property. |
| 2119 RETURN_IF_EMPTY_HANDLE(isolate, | 2107 RETURN_IF_EMPTY_HANDLE(isolate, |
| 2120 JSObject::SetLocalPropertyIgnoreAttributes( | 2108 JSObject::SetLocalPropertyIgnoreAttributes( |
| 2121 global, name, value, static_cast<PropertyAttributes>(attr))); | 2109 global, name, value, static_cast<PropertyAttributes>(attr))); |
| 2122 } else { | 2110 } else { |
| 2123 // Do a [[Put]] on the existing (own) property. | 2111 // Do a [[Put]] on the existing (own) property. |
| 2124 RETURN_IF_EMPTY_HANDLE(isolate, | 2112 RETURN_IF_EMPTY_HANDLE(isolate, |
| 2125 JSObject::SetProperty( | 2113 JSObject::SetProperty( |
| 2126 global, name, value, static_cast<PropertyAttributes>(attr), | 2114 global, name, value, static_cast<PropertyAttributes>(attr), |
| 2127 language_mode == CLASSIC_MODE ? kNonStrictMode : kStrictMode)); | 2115 strict_mode)); |
| 2128 } | 2116 } |
| 2129 } | 2117 } |
| 2130 | 2118 |
| 2131 ASSERT(!isolate->has_pending_exception()); | 2119 ASSERT(!isolate->has_pending_exception()); |
| 2132 return isolate->heap()->undefined_value(); | 2120 return isolate->heap()->undefined_value(); |
| 2133 } | 2121 } |
| 2134 | 2122 |
| 2135 | 2123 |
| 2136 RUNTIME_FUNCTION(MaybeObject*, Runtime_DeclareContextSlot) { | 2124 RUNTIME_FUNCTION(MaybeObject*, Runtime_DeclareContextSlot) { |
| 2137 HandleScope scope(isolate); | 2125 HandleScope scope(isolate); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2173 if (((attributes & READ_ONLY) == 0) || | 2161 if (((attributes & READ_ONLY) == 0) || |
| 2174 context->get(index)->IsTheHole()) { | 2162 context->get(index)->IsTheHole()) { |
| 2175 context->set(index, *initial_value); | 2163 context->set(index, *initial_value); |
| 2176 } | 2164 } |
| 2177 } else { | 2165 } else { |
| 2178 // Slow case: The property is in the context extension object of a | 2166 // Slow case: The property is in the context extension object of a |
| 2179 // function context or the global object of a native context. | 2167 // function context or the global object of a native context. |
| 2180 Handle<JSObject> object = Handle<JSObject>::cast(holder); | 2168 Handle<JSObject> object = Handle<JSObject>::cast(holder); |
| 2181 RETURN_IF_EMPTY_HANDLE( | 2169 RETURN_IF_EMPTY_HANDLE( |
| 2182 isolate, | 2170 isolate, |
| 2183 JSReceiver::SetProperty(object, name, initial_value, mode, | 2171 JSReceiver::SetProperty(object, name, initial_value, mode, SLOPPY)); |
| 2184 kNonStrictMode)); | |
| 2185 } | 2172 } |
| 2186 } | 2173 } |
| 2187 | 2174 |
| 2188 } else { | 2175 } else { |
| 2189 // The property is not in the function context. It needs to be | 2176 // The property is not in the function context. It needs to be |
| 2190 // "declared" in the function context's extension context or as a | 2177 // "declared" in the function context's extension context or as a |
| 2191 // property of the the global object. | 2178 // property of the the global object. |
| 2192 Handle<JSObject> object; | 2179 Handle<JSObject> object; |
| 2193 if (context->has_extension()) { | 2180 if (context->has_extension()) { |
| 2194 object = Handle<JSObject>(JSObject::cast(context->extension())); | 2181 object = Handle<JSObject>(JSObject::cast(context->extension())); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2220 if (lookup.IsPropertyCallbacks()) { | 2207 if (lookup.IsPropertyCallbacks()) { |
| 2221 return ThrowRedeclarationError(isolate, "const", name); | 2208 return ThrowRedeclarationError(isolate, "const", name); |
| 2222 } | 2209 } |
| 2223 } | 2210 } |
| 2224 if (object->IsJSGlobalObject()) { | 2211 if (object->IsJSGlobalObject()) { |
| 2225 // Define own property on the global object. | 2212 // Define own property on the global object. |
| 2226 RETURN_IF_EMPTY_HANDLE(isolate, | 2213 RETURN_IF_EMPTY_HANDLE(isolate, |
| 2227 JSObject::SetLocalPropertyIgnoreAttributes(object, name, value, mode)); | 2214 JSObject::SetLocalPropertyIgnoreAttributes(object, name, value, mode)); |
| 2228 } else { | 2215 } else { |
| 2229 RETURN_IF_EMPTY_HANDLE(isolate, | 2216 RETURN_IF_EMPTY_HANDLE(isolate, |
| 2230 JSReceiver::SetProperty(object, name, value, mode, kNonStrictMode)); | 2217 JSReceiver::SetProperty(object, name, value, mode, SLOPPY)); |
| 2231 } | 2218 } |
| 2232 } | 2219 } |
| 2233 | 2220 |
| 2234 return isolate->heap()->undefined_value(); | 2221 return isolate->heap()->undefined_value(); |
| 2235 } | 2222 } |
| 2236 | 2223 |
| 2237 | 2224 |
| 2238 RUNTIME_FUNCTION(MaybeObject*, Runtime_InitializeVarGlobal) { | 2225 RUNTIME_FUNCTION(MaybeObject*, Runtime_InitializeVarGlobal) { |
| 2239 HandleScope scope(isolate); | 2226 HandleScope scope(isolate); |
| 2240 // args[0] == name | 2227 // args[0] == name |
| 2241 // args[1] == language_mode | 2228 // args[1] == language_mode |
| 2242 // args[2] == value (optional) | 2229 // args[2] == value (optional) |
| 2243 | 2230 |
| 2244 // Determine if we need to assign to the variable if it already | 2231 // Determine if we need to assign to the variable if it already |
| 2245 // exists (based on the number of arguments). | 2232 // exists (based on the number of arguments). |
| 2246 RUNTIME_ASSERT(args.length() == 2 || args.length() == 3); | 2233 RUNTIME_ASSERT(args.length() == 2 || args.length() == 3); |
| 2247 bool assign = args.length() == 3; | 2234 bool assign = args.length() == 3; |
| 2248 | 2235 |
| 2249 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); | 2236 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); |
| 2250 RUNTIME_ASSERT(args[1]->IsSmi()); | 2237 RUNTIME_ASSERT(args[1]->IsSmi()); |
| 2251 CONVERT_LANGUAGE_MODE_ARG(language_mode, 1); | 2238 CONVERT_STRICT_MODE_ARG_CHECKED(strict_mode, 1); |
| 2252 StrictModeFlag strict_mode_flag = (language_mode == CLASSIC_MODE) | |
| 2253 ? kNonStrictMode : kStrictMode; | |
| 2254 | 2239 |
| 2255 // According to ECMA-262, section 12.2, page 62, the property must | 2240 // According to ECMA-262, section 12.2, page 62, the property must |
| 2256 // not be deletable. | 2241 // not be deletable. |
| 2257 PropertyAttributes attributes = DONT_DELETE; | 2242 PropertyAttributes attributes = DONT_DELETE; |
| 2258 | 2243 |
| 2259 // Lookup the property locally in the global object. If it isn't | 2244 // Lookup the property locally in the global object. If it isn't |
| 2260 // there, there is a property with this name in the prototype chain. | 2245 // there, there is a property with this name in the prototype chain. |
| 2261 // We follow Safari and Firefox behavior and only set the property | 2246 // We follow Safari and Firefox behavior and only set the property |
| 2262 // locally if there is an explicit initialization value that we have | 2247 // locally if there is an explicit initialization value that we have |
| 2263 // to assign to the property. | 2248 // to assign to the property. |
| 2264 // Note that objects can have hidden prototypes, so we need to traverse | 2249 // Note that objects can have hidden prototypes, so we need to traverse |
| 2265 // the whole chain of hidden prototypes to do a 'local' lookup. | 2250 // the whole chain of hidden prototypes to do a 'local' lookup. |
| 2266 LookupResult lookup(isolate); | 2251 LookupResult lookup(isolate); |
| 2267 isolate->context()->global_object()->LocalLookup(*name, &lookup, true); | 2252 isolate->context()->global_object()->LocalLookup(*name, &lookup, true); |
| 2268 if (lookup.IsInterceptor()) { | 2253 if (lookup.IsInterceptor()) { |
| 2254 Handle<JSObject> holder(lookup.holder()); |
| 2269 PropertyAttributes intercepted = | 2255 PropertyAttributes intercepted = |
| 2270 lookup.holder()->GetPropertyAttribute(*name); | 2256 JSReceiver::GetPropertyAttribute(holder, name); |
| 2271 if (intercepted != ABSENT && (intercepted & READ_ONLY) == 0) { | 2257 if (intercepted != ABSENT && (intercepted & READ_ONLY) == 0) { |
| 2272 // Found an interceptor that's not read only. | 2258 // Found an interceptor that's not read only. |
| 2273 if (assign) { | 2259 if (assign) { |
| 2274 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); | 2260 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); |
| 2275 Handle<Object> result = JSObject::SetPropertyForResult( | 2261 Handle<Object> result = JSObject::SetPropertyForResult( |
| 2276 handle(lookup.holder()), &lookup, name, value, attributes, | 2262 holder, &lookup, name, value, attributes, strict_mode); |
| 2277 strict_mode_flag); | |
| 2278 RETURN_IF_EMPTY_HANDLE(isolate, result); | 2263 RETURN_IF_EMPTY_HANDLE(isolate, result); |
| 2279 return *result; | 2264 return *result; |
| 2280 } else { | 2265 } else { |
| 2281 return isolate->heap()->undefined_value(); | 2266 return isolate->heap()->undefined_value(); |
| 2282 } | 2267 } |
| 2283 } | 2268 } |
| 2284 } | 2269 } |
| 2285 | 2270 |
| 2286 if (assign) { | 2271 if (assign) { |
| 2287 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); | 2272 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); |
| 2288 Handle<GlobalObject> global(isolate->context()->global_object()); | 2273 Handle<GlobalObject> global(isolate->context()->global_object()); |
| 2289 Handle<Object> result = JSReceiver::SetProperty( | 2274 Handle<Object> result = JSReceiver::SetProperty( |
| 2290 global, name, value, attributes, strict_mode_flag); | 2275 global, name, value, attributes, strict_mode); |
| 2291 RETURN_IF_EMPTY_HANDLE(isolate, result); | 2276 RETURN_IF_EMPTY_HANDLE(isolate, result); |
| 2292 return *result; | 2277 return *result; |
| 2293 } | 2278 } |
| 2294 return isolate->heap()->undefined_value(); | 2279 return isolate->heap()->undefined_value(); |
| 2295 } | 2280 } |
| 2296 | 2281 |
| 2297 | 2282 |
| 2298 RUNTIME_FUNCTION(MaybeObject*, Runtime_InitializeConstGlobal) { | 2283 RUNTIME_FUNCTION(MaybeObject*, Runtime_InitializeConstGlobal) { |
| 2299 SealHandleScope shs(isolate); | 2284 SealHandleScope shs(isolate); |
| 2300 // All constants are declared with an initial value. The name | 2285 // All constants are declared with an initial value. The name |
| (...skipping 30 matching lines...) Expand all Loading... |
| 2331 | 2316 |
| 2332 if (!lookup.IsReadOnly()) { | 2317 if (!lookup.IsReadOnly()) { |
| 2333 // Restore global object from context (in case of GC) and continue | 2318 // Restore global object from context (in case of GC) and continue |
| 2334 // with setting the value. | 2319 // with setting the value. |
| 2335 HandleScope handle_scope(isolate); | 2320 HandleScope handle_scope(isolate); |
| 2336 Handle<GlobalObject> global(isolate->context()->global_object()); | 2321 Handle<GlobalObject> global(isolate->context()->global_object()); |
| 2337 | 2322 |
| 2338 // BUG 1213575: Handle the case where we have to set a read-only | 2323 // BUG 1213575: Handle the case where we have to set a read-only |
| 2339 // property through an interceptor and only do it if it's | 2324 // property through an interceptor and only do it if it's |
| 2340 // uninitialized, e.g. the hole. Nirk... | 2325 // uninitialized, e.g. the hole. Nirk... |
| 2341 // Passing non-strict mode because the property is writable. | 2326 // Passing sloppy mode because the property is writable. |
| 2342 RETURN_IF_EMPTY_HANDLE( | 2327 RETURN_IF_EMPTY_HANDLE( |
| 2343 isolate, | 2328 isolate, |
| 2344 JSReceiver::SetProperty(global, name, value, attributes, | 2329 JSReceiver::SetProperty(global, name, value, attributes, SLOPPY)); |
| 2345 kNonStrictMode)); | |
| 2346 return *value; | 2330 return *value; |
| 2347 } | 2331 } |
| 2348 | 2332 |
| 2349 // Set the value, but only if we're assigning the initial value to a | 2333 // Set the value, but only if we're assigning the initial value to a |
| 2350 // constant. For now, we determine this by checking if the | 2334 // constant. For now, we determine this by checking if the |
| 2351 // current value is the hole. | 2335 // current value is the hole. |
| 2352 // Strict mode handling not needed (const is disallowed in strict mode). | 2336 // Strict mode handling not needed (const is disallowed in strict mode). |
| 2353 if (lookup.IsField()) { | 2337 if (lookup.IsField()) { |
| 2354 FixedArray* properties = global->properties(); | 2338 FixedArray* properties = global->properties(); |
| 2355 int index = lookup.GetFieldIndex().field_index(); | 2339 int index = lookup.GetFieldIndex().field_index(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2405 } | 2389 } |
| 2406 | 2390 |
| 2407 // The property could not be found, we introduce it as a property of the | 2391 // The property could not be found, we introduce it as a property of the |
| 2408 // global object. | 2392 // global object. |
| 2409 if (attributes == ABSENT) { | 2393 if (attributes == ABSENT) { |
| 2410 Handle<JSObject> global = Handle<JSObject>( | 2394 Handle<JSObject> global = Handle<JSObject>( |
| 2411 isolate->context()->global_object()); | 2395 isolate->context()->global_object()); |
| 2412 // Strict mode not needed (const disallowed in strict mode). | 2396 // Strict mode not needed (const disallowed in strict mode). |
| 2413 RETURN_IF_EMPTY_HANDLE( | 2397 RETURN_IF_EMPTY_HANDLE( |
| 2414 isolate, | 2398 isolate, |
| 2415 JSReceiver::SetProperty(global, name, value, NONE, kNonStrictMode)); | 2399 JSReceiver::SetProperty(global, name, value, NONE, SLOPPY)); |
| 2416 return *value; | 2400 return *value; |
| 2417 } | 2401 } |
| 2418 | 2402 |
| 2419 // The property was present in some function's context extension object, | 2403 // The property was present in some function's context extension object, |
| 2420 // as a property on the subject of a with, or as a property of the global | 2404 // as a property on the subject of a with, or as a property of the global |
| 2421 // object. | 2405 // object. |
| 2422 // | 2406 // |
| 2423 // In most situations, eval-introduced consts should still be present in | 2407 // In most situations, eval-introduced consts should still be present in |
| 2424 // the context extension object. However, because declaration and | 2408 // the context extension object. However, because declaration and |
| 2425 // initialization are separate, the property might have been deleted | 2409 // initialization are separate, the property might have been deleted |
| (...skipping 30 matching lines...) Expand all Loading... |
| 2456 // either a field or a dictionary slot. | 2440 // either a field or a dictionary slot. |
| 2457 UNREACHABLE(); | 2441 UNREACHABLE(); |
| 2458 } | 2442 } |
| 2459 } else { | 2443 } else { |
| 2460 // The property was found on some other object. Set it if it is not a | 2444 // The property was found on some other object. Set it if it is not a |
| 2461 // read-only property. | 2445 // read-only property. |
| 2462 if ((attributes & READ_ONLY) == 0) { | 2446 if ((attributes & READ_ONLY) == 0) { |
| 2463 // Strict mode not needed (const disallowed in strict mode). | 2447 // Strict mode not needed (const disallowed in strict mode). |
| 2464 RETURN_IF_EMPTY_HANDLE( | 2448 RETURN_IF_EMPTY_HANDLE( |
| 2465 isolate, | 2449 isolate, |
| 2466 JSReceiver::SetProperty(object, name, value, attributes, | 2450 JSReceiver::SetProperty(object, name, value, attributes, SLOPPY)); |
| 2467 kNonStrictMode)); | |
| 2468 } | 2451 } |
| 2469 } | 2452 } |
| 2470 | 2453 |
| 2471 return *value; | 2454 return *value; |
| 2472 } | 2455 } |
| 2473 | 2456 |
| 2474 | 2457 |
| 2475 RUNTIME_FUNCTION(MaybeObject*, | 2458 RUNTIME_FUNCTION(MaybeObject*, |
| 2476 Runtime_OptimizeObjectForAddingMultipleProperties) { | 2459 Runtime_OptimizeObjectForAddingMultipleProperties) { |
| 2477 HandleScope scope(isolate); | 2460 HandleScope scope(isolate); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2537 array->set_length(Smi::FromInt(elements_count)); | 2520 array->set_length(Smi::FromInt(elements_count)); |
| 2538 // Write in-object properties after the length of the array. | 2521 // Write in-object properties after the length of the array. |
| 2539 array->InObjectPropertyAtPut(JSRegExpResult::kIndexIndex, args[1]); | 2522 array->InObjectPropertyAtPut(JSRegExpResult::kIndexIndex, args[1]); |
| 2540 array->InObjectPropertyAtPut(JSRegExpResult::kInputIndex, args[2]); | 2523 array->InObjectPropertyAtPut(JSRegExpResult::kInputIndex, args[2]); |
| 2541 return array; | 2524 return array; |
| 2542 } | 2525 } |
| 2543 | 2526 |
| 2544 | 2527 |
| 2545 RUNTIME_FUNCTION(MaybeObject*, Runtime_RegExpInitializeObject) { | 2528 RUNTIME_FUNCTION(MaybeObject*, Runtime_RegExpInitializeObject) { |
| 2546 HandleScope scope(isolate); | 2529 HandleScope scope(isolate); |
| 2547 DisallowHeapAllocation no_allocation; | |
| 2548 ASSERT(args.length() == 5); | 2530 ASSERT(args.length() == 5); |
| 2549 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 0); | 2531 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 0); |
| 2550 CONVERT_ARG_HANDLE_CHECKED(String, source, 1); | 2532 CONVERT_ARG_HANDLE_CHECKED(String, source, 1); |
| 2551 // If source is the empty string we set it to "(?:)" instead as | 2533 // If source is the empty string we set it to "(?:)" instead as |
| 2552 // suggested by ECMA-262, 5th, section 15.10.4.1. | 2534 // suggested by ECMA-262, 5th, section 15.10.4.1. |
| 2553 if (source->length() == 0) source = isolate->factory()->query_colon_string(); | 2535 if (source->length() == 0) source = isolate->factory()->query_colon_string(); |
| 2554 | 2536 |
| 2555 CONVERT_ARG_HANDLE_CHECKED(Object, global, 2); | 2537 CONVERT_ARG_HANDLE_CHECKED(Object, global, 2); |
| 2556 if (!global->IsTrue()) global = isolate->factory()->false_value(); | 2538 if (!global->IsTrue()) global = isolate->factory()->false_value(); |
| 2557 | 2539 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2618 Builtins::Name builtin_name) { | 2600 Builtins::Name builtin_name) { |
| 2619 Handle<String> key = isolate->factory()->InternalizeUtf8String(name); | 2601 Handle<String> key = isolate->factory()->InternalizeUtf8String(name); |
| 2620 Handle<Code> code(isolate->builtins()->builtin(builtin_name)); | 2602 Handle<Code> code(isolate->builtins()->builtin(builtin_name)); |
| 2621 Handle<JSFunction> optimized = | 2603 Handle<JSFunction> optimized = |
| 2622 isolate->factory()->NewFunction(key, | 2604 isolate->factory()->NewFunction(key, |
| 2623 JS_OBJECT_TYPE, | 2605 JS_OBJECT_TYPE, |
| 2624 JSObject::kHeaderSize, | 2606 JSObject::kHeaderSize, |
| 2625 code, | 2607 code, |
| 2626 false); | 2608 false); |
| 2627 optimized->shared()->DontAdaptArguments(); | 2609 optimized->shared()->DontAdaptArguments(); |
| 2628 JSReceiver::SetProperty(holder, key, optimized, NONE, kStrictMode); | 2610 JSReceiver::SetProperty(holder, key, optimized, NONE, STRICT); |
| 2629 return optimized; | 2611 return optimized; |
| 2630 } | 2612 } |
| 2631 | 2613 |
| 2632 | 2614 |
| 2633 RUNTIME_FUNCTION(MaybeObject*, Runtime_SpecialArrayFunctions) { | 2615 RUNTIME_FUNCTION(MaybeObject*, Runtime_SpecialArrayFunctions) { |
| 2634 HandleScope scope(isolate); | 2616 HandleScope scope(isolate); |
| 2635 ASSERT(args.length() == 1); | 2617 ASSERT(args.length() == 1); |
| 2636 CONVERT_ARG_HANDLE_CHECKED(JSObject, holder, 0); | 2618 CONVERT_ARG_HANDLE_CHECKED(JSObject, holder, 0); |
| 2637 | 2619 |
| 2638 InstallBuiltin(isolate, holder, "pop", Builtins::kArrayPop); | 2620 InstallBuiltin(isolate, holder, "pop", Builtins::kArrayPop); |
| 2639 InstallBuiltin(isolate, holder, "push", Builtins::kArrayPush); | 2621 InstallBuiltin(isolate, holder, "push", Builtins::kArrayPush); |
| 2640 InstallBuiltin(isolate, holder, "shift", Builtins::kArrayShift); | 2622 InstallBuiltin(isolate, holder, "shift", Builtins::kArrayShift); |
| 2641 InstallBuiltin(isolate, holder, "unshift", Builtins::kArrayUnshift); | 2623 InstallBuiltin(isolate, holder, "unshift", Builtins::kArrayUnshift); |
| 2642 InstallBuiltin(isolate, holder, "slice", Builtins::kArraySlice); | 2624 InstallBuiltin(isolate, holder, "slice", Builtins::kArraySlice); |
| 2643 InstallBuiltin(isolate, holder, "splice", Builtins::kArraySplice); | 2625 InstallBuiltin(isolate, holder, "splice", Builtins::kArraySplice); |
| 2644 InstallBuiltin(isolate, holder, "concat", Builtins::kArrayConcat); | 2626 InstallBuiltin(isolate, holder, "concat", Builtins::kArrayConcat); |
| 2645 | 2627 |
| 2646 return *holder; | 2628 return *holder; |
| 2647 } | 2629 } |
| 2648 | 2630 |
| 2649 | 2631 |
| 2650 RUNTIME_FUNCTION(MaybeObject*, Runtime_IsClassicModeFunction) { | 2632 RUNTIME_FUNCTION(MaybeObject*, Runtime_IsSloppyModeFunction) { |
| 2651 SealHandleScope shs(isolate); | 2633 SealHandleScope shs(isolate); |
| 2652 ASSERT(args.length() == 1); | 2634 ASSERT(args.length() == 1); |
| 2653 CONVERT_ARG_CHECKED(JSReceiver, callable, 0); | 2635 CONVERT_ARG_CHECKED(JSReceiver, callable, 0); |
| 2654 if (!callable->IsJSFunction()) { | 2636 if (!callable->IsJSFunction()) { |
| 2655 HandleScope scope(isolate); | 2637 HandleScope scope(isolate); |
| 2656 bool threw = false; | 2638 bool threw = false; |
| 2657 Handle<Object> delegate = Execution::TryGetFunctionDelegate( | 2639 Handle<Object> delegate = Execution::TryGetFunctionDelegate( |
| 2658 isolate, Handle<JSReceiver>(callable), &threw); | 2640 isolate, Handle<JSReceiver>(callable), &threw); |
| 2659 if (threw) return Failure::Exception(); | 2641 if (threw) return Failure::Exception(); |
| 2660 callable = JSFunction::cast(*delegate); | 2642 callable = JSFunction::cast(*delegate); |
| 2661 } | 2643 } |
| 2662 JSFunction* function = JSFunction::cast(callable); | 2644 JSFunction* function = JSFunction::cast(callable); |
| 2663 SharedFunctionInfo* shared = function->shared(); | 2645 SharedFunctionInfo* shared = function->shared(); |
| 2664 return isolate->heap()->ToBoolean(shared->is_classic_mode()); | 2646 return isolate->heap()->ToBoolean(shared->strict_mode() == SLOPPY); |
| 2665 } | 2647 } |
| 2666 | 2648 |
| 2667 | 2649 |
| 2668 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetDefaultReceiver) { | 2650 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetDefaultReceiver) { |
| 2669 SealHandleScope shs(isolate); | 2651 SealHandleScope shs(isolate); |
| 2670 ASSERT(args.length() == 1); | 2652 ASSERT(args.length() == 1); |
| 2671 CONVERT_ARG_CHECKED(JSReceiver, callable, 0); | 2653 CONVERT_ARG_CHECKED(JSReceiver, callable, 0); |
| 2672 | 2654 |
| 2673 if (!callable->IsJSFunction()) { | 2655 if (!callable->IsJSFunction()) { |
| 2674 HandleScope scope(isolate); | 2656 HandleScope scope(isolate); |
| 2675 bool threw = false; | 2657 bool threw = false; |
| 2676 Handle<Object> delegate = Execution::TryGetFunctionDelegate( | 2658 Handle<Object> delegate = Execution::TryGetFunctionDelegate( |
| 2677 isolate, Handle<JSReceiver>(callable), &threw); | 2659 isolate, Handle<JSReceiver>(callable), &threw); |
| 2678 if (threw) return Failure::Exception(); | 2660 if (threw) return Failure::Exception(); |
| 2679 callable = JSFunction::cast(*delegate); | 2661 callable = JSFunction::cast(*delegate); |
| 2680 } | 2662 } |
| 2681 JSFunction* function = JSFunction::cast(callable); | 2663 JSFunction* function = JSFunction::cast(callable); |
| 2682 | 2664 |
| 2683 SharedFunctionInfo* shared = function->shared(); | 2665 SharedFunctionInfo* shared = function->shared(); |
| 2684 if (shared->native() || !shared->is_classic_mode()) { | 2666 if (shared->native() || shared->strict_mode() == STRICT) { |
| 2685 return isolate->heap()->undefined_value(); | 2667 return isolate->heap()->undefined_value(); |
| 2686 } | 2668 } |
| 2687 // Returns undefined for strict or native functions, or | 2669 // Returns undefined for strict or native functions, or |
| 2688 // the associated global receiver for "normal" functions. | 2670 // the associated global receiver for "normal" functions. |
| 2689 | 2671 |
| 2690 Context* native_context = | 2672 Context* native_context = |
| 2691 function->context()->global_object()->native_context(); | 2673 function->context()->global_object()->native_context(); |
| 2692 return native_context->global_object()->global_receiver(); | 2674 return native_context->global_object()->global_receiver(); |
| 2693 } | 2675 } |
| 2694 | 2676 |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2940 // Mark both, the source and the target, as un-flushable because the | 2922 // Mark both, the source and the target, as un-flushable because the |
| 2941 // shared unoptimized code makes them impossible to enqueue in a list. | 2923 // shared unoptimized code makes them impossible to enqueue in a list. |
| 2942 ASSERT(target_shared->code()->gc_metadata() == NULL); | 2924 ASSERT(target_shared->code()->gc_metadata() == NULL); |
| 2943 ASSERT(source_shared->code()->gc_metadata() == NULL); | 2925 ASSERT(source_shared->code()->gc_metadata() == NULL); |
| 2944 target_shared->set_dont_flush(true); | 2926 target_shared->set_dont_flush(true); |
| 2945 source_shared->set_dont_flush(true); | 2927 source_shared->set_dont_flush(true); |
| 2946 | 2928 |
| 2947 // Set the code, scope info, formal parameter count, and the length | 2929 // Set the code, scope info, formal parameter count, and the length |
| 2948 // of the target shared function info. | 2930 // of the target shared function info. |
| 2949 target_shared->ReplaceCode(source_shared->code()); | 2931 target_shared->ReplaceCode(source_shared->code()); |
| 2932 target_shared->set_feedback_vector(source_shared->feedback_vector()); |
| 2950 target_shared->set_scope_info(source_shared->scope_info()); | 2933 target_shared->set_scope_info(source_shared->scope_info()); |
| 2951 target_shared->set_length(source_shared->length()); | 2934 target_shared->set_length(source_shared->length()); |
| 2952 target_shared->set_formal_parameter_count( | 2935 target_shared->set_formal_parameter_count( |
| 2953 source_shared->formal_parameter_count()); | 2936 source_shared->formal_parameter_count()); |
| 2954 target_shared->set_script(source_shared->script()); | 2937 target_shared->set_script(source_shared->script()); |
| 2955 target_shared->set_start_position_and_type( | 2938 target_shared->set_start_position_and_type( |
| 2956 source_shared->start_position_and_type()); | 2939 source_shared->start_position_and_type()); |
| 2957 target_shared->set_end_position(source_shared->end_position()); | 2940 target_shared->set_end_position(source_shared->end_position()); |
| 2958 bool was_native = target_shared->native(); | 2941 bool was_native = target_shared->native(); |
| 2959 target_shared->set_compiler_hints(source_shared->compiler_hints()); | 2942 target_shared->set_compiler_hints(source_shared->compiler_hints()); |
| (...skipping 1983 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4943 : value; | 4926 : value; |
| 4944 } | 4927 } |
| 4945 // Lookup cache miss. Perform lookup and update the cache if | 4928 // Lookup cache miss. Perform lookup and update the cache if |
| 4946 // appropriate. | 4929 // appropriate. |
| 4947 LookupResult result(isolate); | 4930 LookupResult result(isolate); |
| 4948 receiver->LocalLookup(key, &result); | 4931 receiver->LocalLookup(key, &result); |
| 4949 if (result.IsField()) { | 4932 if (result.IsField()) { |
| 4950 int offset = result.GetFieldIndex().field_index(); | 4933 int offset = result.GetFieldIndex().field_index(); |
| 4951 // Do not track double fields in the keyed lookup cache. Reading | 4934 // Do not track double fields in the keyed lookup cache. Reading |
| 4952 // double values requires boxing. | 4935 // double values requires boxing. |
| 4953 if (!FLAG_track_double_fields || | 4936 if (!result.representation().IsDouble()) { |
| 4954 !result.representation().IsDouble()) { | |
| 4955 keyed_lookup_cache->Update(receiver_map, key, offset); | 4937 keyed_lookup_cache->Update(receiver_map, key, offset); |
| 4956 } | 4938 } |
| 4957 return receiver->FastPropertyAt(result.representation(), offset); | 4939 return receiver->FastPropertyAt(result.representation(), offset); |
| 4958 } | 4940 } |
| 4959 } else { | 4941 } else { |
| 4960 // Attempt dictionary lookup. | 4942 // Attempt dictionary lookup. |
| 4961 NameDictionary* dictionary = receiver->property_dictionary(); | 4943 NameDictionary* dictionary = receiver->property_dictionary(); |
| 4962 int entry = dictionary->FindEntry(key); | 4944 int entry = dictionary->FindEntry(key); |
| 4963 if ((entry != NameDictionary::kNotFound) && | 4945 if ((entry != NameDictionary::kNotFound) && |
| 4964 (dictionary->DetailsAt(entry).type() == NORMAL)) { | 4946 (dictionary->DetailsAt(entry).type() == NORMAL)) { |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5079 // setter to update the value instead. | 5061 // setter to update the value instead. |
| 5080 // TODO(mstarzinger): So far this only works if property attributes don't | 5062 // TODO(mstarzinger): So far this only works if property attributes don't |
| 5081 // change, this should be fixed once we cleanup the underlying code. | 5063 // change, this should be fixed once we cleanup the underlying code. |
| 5082 if (callback->IsForeign() && lookup.GetAttributes() == attr) { | 5064 if (callback->IsForeign() && lookup.GetAttributes() == attr) { |
| 5083 Handle<Object> result_object = | 5065 Handle<Object> result_object = |
| 5084 JSObject::SetPropertyWithCallback(js_object, | 5066 JSObject::SetPropertyWithCallback(js_object, |
| 5085 callback, | 5067 callback, |
| 5086 name, | 5068 name, |
| 5087 obj_value, | 5069 obj_value, |
| 5088 handle(lookup.holder()), | 5070 handle(lookup.holder()), |
| 5089 kStrictMode); | 5071 STRICT); |
| 5090 RETURN_IF_EMPTY_HANDLE(isolate, result_object); | 5072 RETURN_IF_EMPTY_HANDLE(isolate, result_object); |
| 5091 return *result_object; | 5073 return *result_object; |
| 5092 } | 5074 } |
| 5093 } | 5075 } |
| 5094 | 5076 |
| 5095 // Take special care when attributes are different and there is already | 5077 // Take special care when attributes are different and there is already |
| 5096 // a property. For simplicity we normalize the property which enables us | 5078 // a property. For simplicity we normalize the property which enables us |
| 5097 // to not worry about changing the instance_descriptor and creating a new | 5079 // to not worry about changing the instance_descriptor and creating a new |
| 5098 // map. The current version of SetObjectProperty does not handle attributes | 5080 // map. The current version of SetObjectProperty does not handle attributes |
| 5099 // correctly in the case where a property is a field and is reset with | 5081 // correctly in the case where a property is a field and is reset with |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5152 } | 5134 } |
| 5153 return isolate->heap()->undefined_value(); | 5135 return isolate->heap()->undefined_value(); |
| 5154 } | 5136 } |
| 5155 | 5137 |
| 5156 | 5138 |
| 5157 Handle<Object> Runtime::SetObjectProperty(Isolate* isolate, | 5139 Handle<Object> Runtime::SetObjectProperty(Isolate* isolate, |
| 5158 Handle<Object> object, | 5140 Handle<Object> object, |
| 5159 Handle<Object> key, | 5141 Handle<Object> key, |
| 5160 Handle<Object> value, | 5142 Handle<Object> value, |
| 5161 PropertyAttributes attr, | 5143 PropertyAttributes attr, |
| 5162 StrictModeFlag strict_mode) { | 5144 StrictMode strict_mode) { |
| 5163 SetPropertyMode set_mode = attr == NONE ? SET_PROPERTY : DEFINE_PROPERTY; | 5145 SetPropertyMode set_mode = attr == NONE ? SET_PROPERTY : DEFINE_PROPERTY; |
| 5164 | 5146 |
| 5165 if (object->IsUndefined() || object->IsNull()) { | 5147 if (object->IsUndefined() || object->IsNull()) { |
| 5166 Handle<Object> args[2] = { key, object }; | 5148 Handle<Object> args[2] = { key, object }; |
| 5167 Handle<Object> error = | 5149 Handle<Object> error = |
| 5168 isolate->factory()->NewTypeError("non_object_property_store", | 5150 isolate->factory()->NewTypeError("non_object_property_store", |
| 5169 HandleVector(args, 2)); | 5151 HandleVector(args, 2)); |
| 5170 isolate->Throw(*error); | 5152 isolate->Throw(*error); |
| 5171 return Handle<Object>(); | 5153 return Handle<Object>(); |
| 5172 } | 5154 } |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5270 // of a string using [] notation. We need to support this too in | 5252 // of a string using [] notation. We need to support this too in |
| 5271 // JavaScript. | 5253 // JavaScript. |
| 5272 // In the case of a String object we just need to redirect the assignment to | 5254 // In the case of a String object we just need to redirect the assignment to |
| 5273 // the underlying string if the index is in range. Since the underlying | 5255 // the underlying string if the index is in range. Since the underlying |
| 5274 // string does nothing with the assignment then we can ignore such | 5256 // string does nothing with the assignment then we can ignore such |
| 5275 // assignments. | 5257 // assignments. |
| 5276 if (js_object->IsStringObjectWithCharacterAt(index)) { | 5258 if (js_object->IsStringObjectWithCharacterAt(index)) { |
| 5277 return value; | 5259 return value; |
| 5278 } | 5260 } |
| 5279 | 5261 |
| 5280 return JSObject::SetElement(js_object, index, value, attr, kNonStrictMode, | 5262 return JSObject::SetElement(js_object, index, value, attr, SLOPPY, |
| 5281 false, | 5263 false, |
| 5282 DEFINE_PROPERTY); | 5264 DEFINE_PROPERTY); |
| 5283 } | 5265 } |
| 5284 | 5266 |
| 5285 if (key->IsName()) { | 5267 if (key->IsName()) { |
| 5286 Handle<Name> name = Handle<Name>::cast(key); | 5268 Handle<Name> name = Handle<Name>::cast(key); |
| 5287 if (name->AsArrayIndex(&index)) { | 5269 if (name->AsArrayIndex(&index)) { |
| 5288 return JSObject::SetElement(js_object, index, value, attr, kNonStrictMode, | 5270 return JSObject::SetElement(js_object, index, value, attr, SLOPPY, |
| 5289 false, | 5271 false, |
| 5290 DEFINE_PROPERTY); | 5272 DEFINE_PROPERTY); |
| 5291 } else { | 5273 } else { |
| 5292 if (name->IsString()) Handle<String>::cast(name)->TryFlatten(); | 5274 if (name->IsString()) Handle<String>::cast(name)->TryFlatten(); |
| 5293 return JSObject::SetLocalPropertyIgnoreAttributes(js_object, name, | 5275 return JSObject::SetLocalPropertyIgnoreAttributes(js_object, name, |
| 5294 value, attr); | 5276 value, attr); |
| 5295 } | 5277 } |
| 5296 } | 5278 } |
| 5297 | 5279 |
| 5298 // Call-back into JavaScript to convert the key to a string. | 5280 // Call-back into JavaScript to convert the key to a string. |
| 5299 bool has_pending_exception = false; | 5281 bool has_pending_exception = false; |
| 5300 Handle<Object> converted = | 5282 Handle<Object> converted = |
| 5301 Execution::ToString(isolate, key, &has_pending_exception); | 5283 Execution::ToString(isolate, key, &has_pending_exception); |
| 5302 if (has_pending_exception) return Handle<Object>(); // exception | 5284 if (has_pending_exception) return Handle<Object>(); // exception |
| 5303 Handle<String> name = Handle<String>::cast(converted); | 5285 Handle<String> name = Handle<String>::cast(converted); |
| 5304 | 5286 |
| 5305 if (name->AsArrayIndex(&index)) { | 5287 if (name->AsArrayIndex(&index)) { |
| 5306 return JSObject::SetElement(js_object, index, value, attr, kNonStrictMode, | 5288 return JSObject::SetElement(js_object, index, value, attr, SLOPPY, |
| 5307 false, | 5289 false, |
| 5308 DEFINE_PROPERTY); | 5290 DEFINE_PROPERTY); |
| 5309 } else { | 5291 } else { |
| 5310 return JSObject::SetLocalPropertyIgnoreAttributes(js_object, name, value, | 5292 return JSObject::SetLocalPropertyIgnoreAttributes(js_object, name, value, |
| 5311 attr); | 5293 attr); |
| 5312 } | 5294 } |
| 5313 } | 5295 } |
| 5314 | 5296 |
| 5315 | 5297 |
| 5316 MaybeObject* Runtime::DeleteObjectProperty(Isolate* isolate, | 5298 MaybeObject* Runtime::DeleteObjectProperty(Isolate* isolate, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5349 name = Handle<String>::cast(converted); | 5331 name = Handle<String>::cast(converted); |
| 5350 } | 5332 } |
| 5351 | 5333 |
| 5352 if (name->IsString()) Handle<String>::cast(name)->TryFlatten(); | 5334 if (name->IsString()) Handle<String>::cast(name)->TryFlatten(); |
| 5353 Handle<Object> result = JSReceiver::DeleteProperty(receiver, name, mode); | 5335 Handle<Object> result = JSReceiver::DeleteProperty(receiver, name, mode); |
| 5354 RETURN_IF_EMPTY_HANDLE(isolate, result); | 5336 RETURN_IF_EMPTY_HANDLE(isolate, result); |
| 5355 return *result; | 5337 return *result; |
| 5356 } | 5338 } |
| 5357 | 5339 |
| 5358 | 5340 |
| 5341 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetHiddenProperty) { |
| 5342 HandleScope scope(isolate); |
| 5343 RUNTIME_ASSERT(args.length() == 3); |
| 5344 |
| 5345 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); |
| 5346 CONVERT_ARG_HANDLE_CHECKED(String, key, 1); |
| 5347 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); |
| 5348 return *JSObject::SetHiddenProperty(object, key, value); |
| 5349 } |
| 5350 |
| 5351 |
| 5359 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetProperty) { | 5352 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetProperty) { |
| 5360 HandleScope scope(isolate); | 5353 HandleScope scope(isolate); |
| 5361 RUNTIME_ASSERT(args.length() == 4 || args.length() == 5); | 5354 RUNTIME_ASSERT(args.length() == 4 || args.length() == 5); |
| 5362 | 5355 |
| 5363 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); | 5356 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); |
| 5364 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); | 5357 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); |
| 5365 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); | 5358 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); |
| 5366 CONVERT_SMI_ARG_CHECKED(unchecked_attributes, 3); | 5359 CONVERT_SMI_ARG_CHECKED(unchecked_attributes, 3); |
| 5367 RUNTIME_ASSERT( | 5360 RUNTIME_ASSERT( |
| 5368 (unchecked_attributes & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); | 5361 (unchecked_attributes & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); |
| 5369 // Compute attributes. | 5362 // Compute attributes. |
| 5370 PropertyAttributes attributes = | 5363 PropertyAttributes attributes = |
| 5371 static_cast<PropertyAttributes>(unchecked_attributes); | 5364 static_cast<PropertyAttributes>(unchecked_attributes); |
| 5372 | 5365 |
| 5373 StrictModeFlag strict_mode = kNonStrictMode; | 5366 StrictMode strict_mode = SLOPPY; |
| 5374 if (args.length() == 5) { | 5367 if (args.length() == 5) { |
| 5375 CONVERT_STRICT_MODE_ARG_CHECKED(strict_mode_flag, 4); | 5368 CONVERT_STRICT_MODE_ARG_CHECKED(strict_mode_arg, 4); |
| 5376 strict_mode = strict_mode_flag; | 5369 strict_mode = strict_mode_arg; |
| 5377 } | 5370 } |
| 5378 | 5371 |
| 5379 Handle<Object> result = Runtime::SetObjectProperty(isolate, object, key, | 5372 Handle<Object> result = Runtime::SetObjectProperty(isolate, object, key, |
| 5380 value, | 5373 value, |
| 5381 attributes, | 5374 attributes, |
| 5382 strict_mode); | 5375 strict_mode); |
| 5383 RETURN_IF_EMPTY_HANDLE(isolate, result); | 5376 RETURN_IF_EMPTY_HANDLE(isolate, result); |
| 5384 return *result; | 5377 return *result; |
| 5385 } | 5378 } |
| 5386 | 5379 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5545 return *result; | 5538 return *result; |
| 5546 } | 5539 } |
| 5547 | 5540 |
| 5548 | 5541 |
| 5549 RUNTIME_FUNCTION(MaybeObject*, Runtime_DeleteProperty) { | 5542 RUNTIME_FUNCTION(MaybeObject*, Runtime_DeleteProperty) { |
| 5550 HandleScope scope(isolate); | 5543 HandleScope scope(isolate); |
| 5551 ASSERT(args.length() == 3); | 5544 ASSERT(args.length() == 3); |
| 5552 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, object, 0); | 5545 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, object, 0); |
| 5553 CONVERT_ARG_HANDLE_CHECKED(Name, key, 1); | 5546 CONVERT_ARG_HANDLE_CHECKED(Name, key, 1); |
| 5554 CONVERT_STRICT_MODE_ARG_CHECKED(strict_mode, 2); | 5547 CONVERT_STRICT_MODE_ARG_CHECKED(strict_mode, 2); |
| 5555 JSReceiver::DeleteMode delete_mode = (strict_mode == kStrictMode) | 5548 JSReceiver::DeleteMode delete_mode = strict_mode == STRICT |
| 5556 ? JSReceiver::STRICT_DELETION : JSReceiver::NORMAL_DELETION; | 5549 ? JSReceiver::STRICT_DELETION : JSReceiver::NORMAL_DELETION; |
| 5557 Handle<Object> result = JSReceiver::DeleteProperty(object, key, delete_mode); | 5550 Handle<Object> result = JSReceiver::DeleteProperty(object, key, delete_mode); |
| 5558 RETURN_IF_EMPTY_HANDLE(isolate, result); | 5551 RETURN_IF_EMPTY_HANDLE(isolate, result); |
| 5559 return *result; | 5552 return *result; |
| 5560 } | 5553 } |
| 5561 | 5554 |
| 5562 | 5555 |
| 5563 static MaybeObject* HasLocalPropertyImplementation(Isolate* isolate, | 5556 static MaybeObject* HasLocalPropertyImplementation(Isolate* isolate, |
| 5564 Handle<JSObject> object, | 5557 Handle<JSObject> object, |
| 5565 Handle<Name> key) { | 5558 Handle<Name> key) { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5643 CONVERT_SMI_ARG_CHECKED(index, 1); | 5636 CONVERT_SMI_ARG_CHECKED(index, 1); |
| 5644 | 5637 |
| 5645 bool result = JSReceiver::HasElement(receiver, index); | 5638 bool result = JSReceiver::HasElement(receiver, index); |
| 5646 RETURN_IF_SCHEDULED_EXCEPTION(isolate); | 5639 RETURN_IF_SCHEDULED_EXCEPTION(isolate); |
| 5647 if (isolate->has_pending_exception()) return Failure::Exception(); | 5640 if (isolate->has_pending_exception()) return Failure::Exception(); |
| 5648 return isolate->heap()->ToBoolean(result); | 5641 return isolate->heap()->ToBoolean(result); |
| 5649 } | 5642 } |
| 5650 | 5643 |
| 5651 | 5644 |
| 5652 RUNTIME_FUNCTION(MaybeObject*, Runtime_IsPropertyEnumerable) { | 5645 RUNTIME_FUNCTION(MaybeObject*, Runtime_IsPropertyEnumerable) { |
| 5653 SealHandleScope shs(isolate); | 5646 HandleScope scope(isolate); |
| 5654 ASSERT(args.length() == 2); | 5647 ASSERT(args.length() == 2); |
| 5655 | 5648 |
| 5656 CONVERT_ARG_CHECKED(JSObject, object, 0); | 5649 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); |
| 5657 CONVERT_ARG_CHECKED(Name, key, 1); | 5650 CONVERT_ARG_HANDLE_CHECKED(Name, key, 1); |
| 5658 | 5651 |
| 5659 PropertyAttributes att = object->GetLocalPropertyAttribute(key); | 5652 PropertyAttributes att = JSReceiver::GetLocalPropertyAttribute(object, key); |
| 5660 if (att == ABSENT || (att & DONT_ENUM) != 0) { | 5653 if (att == ABSENT || (att & DONT_ENUM) != 0) { |
| 5661 RETURN_IF_SCHEDULED_EXCEPTION(isolate); | 5654 RETURN_IF_SCHEDULED_EXCEPTION(isolate); |
| 5662 return isolate->heap()->false_value(); | 5655 return isolate->heap()->false_value(); |
| 5663 } | 5656 } |
| 5664 ASSERT(!isolate->has_scheduled_exception()); | 5657 ASSERT(!isolate->has_scheduled_exception()); |
| 5665 return isolate->heap()->true_value(); | 5658 return isolate->heap()->true_value(); |
| 5666 } | 5659 } |
| 5667 | 5660 |
| 5668 | 5661 |
| 5669 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetPropertyNames) { | 5662 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetPropertyNames) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5730 } | 5723 } |
| 5731 CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0); | 5724 CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0); |
| 5732 CONVERT_SMI_ARG_CHECKED(filter_value, 1); | 5725 CONVERT_SMI_ARG_CHECKED(filter_value, 1); |
| 5733 PropertyAttributes filter = static_cast<PropertyAttributes>(filter_value); | 5726 PropertyAttributes filter = static_cast<PropertyAttributes>(filter_value); |
| 5734 | 5727 |
| 5735 // Skip the global proxy as it has no properties and always delegates to the | 5728 // Skip the global proxy as it has no properties and always delegates to the |
| 5736 // real global object. | 5729 // real global object. |
| 5737 if (obj->IsJSGlobalProxy()) { | 5730 if (obj->IsJSGlobalProxy()) { |
| 5738 // Only collect names if access is permitted. | 5731 // Only collect names if access is permitted. |
| 5739 if (obj->IsAccessCheckNeeded() && | 5732 if (obj->IsAccessCheckNeeded() && |
| 5740 !isolate->MayNamedAccess(*obj, | 5733 !isolate->MayNamedAccessWrapper(obj, |
| 5741 isolate->heap()->undefined_value(), | 5734 isolate->factory()->undefined_value(), |
| 5742 v8::ACCESS_KEYS)) { | 5735 v8::ACCESS_KEYS)) { |
| 5743 isolate->ReportFailedAccessCheck(*obj, v8::ACCESS_KEYS); | 5736 isolate->ReportFailedAccessCheckWrapper(obj, v8::ACCESS_KEYS); |
| 5744 RETURN_IF_SCHEDULED_EXCEPTION(isolate); | 5737 RETURN_IF_SCHEDULED_EXCEPTION(isolate); |
| 5745 return *isolate->factory()->NewJSArray(0); | 5738 return *isolate->factory()->NewJSArray(0); |
| 5746 } | 5739 } |
| 5747 obj = Handle<JSObject>(JSObject::cast(obj->GetPrototype())); | 5740 obj = Handle<JSObject>(JSObject::cast(obj->GetPrototype())); |
| 5748 } | 5741 } |
| 5749 | 5742 |
| 5750 // Find the number of objects making up this. | 5743 // Find the number of objects making up this. |
| 5751 int length = LocalPrototypeChainLength(*obj); | 5744 int length = LocalPrototypeChainLength(*obj); |
| 5752 | 5745 |
| 5753 // Find the number of local properties for each of the objects. | 5746 // Find the number of local properties for each of the objects. |
| 5754 ScopedVector<int> local_property_count(length); | 5747 ScopedVector<int> local_property_count(length); |
| 5755 int total_property_count = 0; | 5748 int total_property_count = 0; |
| 5756 Handle<JSObject> jsproto = obj; | 5749 Handle<JSObject> jsproto = obj; |
| 5757 for (int i = 0; i < length; i++) { | 5750 for (int i = 0; i < length; i++) { |
| 5758 // Only collect names if access is permitted. | 5751 // Only collect names if access is permitted. |
| 5759 if (jsproto->IsAccessCheckNeeded() && | 5752 if (jsproto->IsAccessCheckNeeded() && |
| 5760 !isolate->MayNamedAccess(*jsproto, | 5753 !isolate->MayNamedAccessWrapper(jsproto, |
| 5761 isolate->heap()->undefined_value(), | 5754 isolate->factory()->undefined_value(), |
| 5762 v8::ACCESS_KEYS)) { | 5755 v8::ACCESS_KEYS)) { |
| 5763 isolate->ReportFailedAccessCheck(*jsproto, v8::ACCESS_KEYS); | 5756 isolate->ReportFailedAccessCheckWrapper(jsproto, v8::ACCESS_KEYS); |
| 5764 RETURN_IF_SCHEDULED_EXCEPTION(isolate); | 5757 RETURN_IF_SCHEDULED_EXCEPTION(isolate); |
| 5765 return *isolate->factory()->NewJSArray(0); | 5758 return *isolate->factory()->NewJSArray(0); |
| 5766 } | 5759 } |
| 5767 int n; | 5760 int n; |
| 5768 n = jsproto->NumberOfLocalProperties(filter); | 5761 n = jsproto->NumberOfLocalProperties(filter); |
| 5769 local_property_count[i] = n; | 5762 local_property_count[i] = n; |
| 5770 total_property_count += n; | 5763 total_property_count += n; |
| 5771 if (i < length - 1) { | 5764 if (i < length - 1) { |
| 5772 jsproto = Handle<JSObject>(JSObject::cast(jsproto->GetPrototype())); | 5765 jsproto = Handle<JSObject>(JSObject::cast(jsproto->GetPrototype())); |
| 5773 } | 5766 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 5797 if (name_from_hidden_proto == name) { | 5790 if (name_from_hidden_proto == name) { |
| 5798 names->set(j, isolate->heap()->hidden_string()); | 5791 names->set(j, isolate->heap()->hidden_string()); |
| 5799 hidden_strings++; | 5792 hidden_strings++; |
| 5800 break; | 5793 break; |
| 5801 } | 5794 } |
| 5802 } | 5795 } |
| 5803 } | 5796 } |
| 5804 } | 5797 } |
| 5805 } | 5798 } |
| 5806 next_copy_index += local_property_count[i]; | 5799 next_copy_index += local_property_count[i]; |
| 5807 if (jsproto->HasHiddenProperties()) { | 5800 |
| 5801 // Hidden properties only show up if the filter does not skip strings. |
| 5802 if ((filter & STRING) == 0 && JSObject::HasHiddenProperties(jsproto)) { |
| 5808 hidden_strings++; | 5803 hidden_strings++; |
| 5809 } | 5804 } |
| 5810 if (i < length - 1) { | 5805 if (i < length - 1) { |
| 5811 jsproto = Handle<JSObject>(JSObject::cast(jsproto->GetPrototype())); | 5806 jsproto = Handle<JSObject>(JSObject::cast(jsproto->GetPrototype())); |
| 5812 } | 5807 } |
| 5813 } | 5808 } |
| 5814 | 5809 |
| 5815 // Filter out name of hidden properties object and | 5810 // Filter out name of hidden properties object and |
| 5816 // hidden prototype duplicates. | 5811 // hidden prototype duplicates. |
| 5817 if (hidden_strings > 0) { | 5812 if (hidden_strings > 0) { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5901 | 5896 |
| 5902 RUNTIME_FUNCTION(MaybeObject*, Runtime_LocalKeys) { | 5897 RUNTIME_FUNCTION(MaybeObject*, Runtime_LocalKeys) { |
| 5903 HandleScope scope(isolate); | 5898 HandleScope scope(isolate); |
| 5904 ASSERT_EQ(args.length(), 1); | 5899 ASSERT_EQ(args.length(), 1); |
| 5905 CONVERT_ARG_CHECKED(JSObject, raw_object, 0); | 5900 CONVERT_ARG_CHECKED(JSObject, raw_object, 0); |
| 5906 Handle<JSObject> object(raw_object); | 5901 Handle<JSObject> object(raw_object); |
| 5907 | 5902 |
| 5908 if (object->IsJSGlobalProxy()) { | 5903 if (object->IsJSGlobalProxy()) { |
| 5909 // Do access checks before going to the global object. | 5904 // Do access checks before going to the global object. |
| 5910 if (object->IsAccessCheckNeeded() && | 5905 if (object->IsAccessCheckNeeded() && |
| 5911 !isolate->MayNamedAccess(*object, isolate->heap()->undefined_value(), | 5906 !isolate->MayNamedAccessWrapper(object, |
| 5912 v8::ACCESS_KEYS)) { | 5907 isolate->factory()->undefined_value(), |
| 5913 isolate->ReportFailedAccessCheck(*object, v8::ACCESS_KEYS); | 5908 v8::ACCESS_KEYS)) { |
| 5909 isolate->ReportFailedAccessCheckWrapper(object, v8::ACCESS_KEYS); |
| 5914 RETURN_IF_SCHEDULED_EXCEPTION(isolate); | 5910 RETURN_IF_SCHEDULED_EXCEPTION(isolate); |
| 5915 return *isolate->factory()->NewJSArray(0); | 5911 return *isolate->factory()->NewJSArray(0); |
| 5916 } | 5912 } |
| 5917 | 5913 |
| 5918 Handle<Object> proto(object->GetPrototype(), isolate); | 5914 Handle<Object> proto(object->GetPrototype(), isolate); |
| 5919 // If proxy is detached we simply return an empty array. | 5915 // If proxy is detached we simply return an empty array. |
| 5920 if (proto->IsNull()) return *isolate->factory()->NewJSArray(0); | 5916 if (proto->IsNull()) return *isolate->factory()->NewJSArray(0); |
| 5921 object = Handle<JSObject>::cast(proto); | 5917 object = Handle<JSObject>::cast(proto); |
| 5922 } | 5918 } |
| 5923 | 5919 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5987 return frame->GetParameter(index); | 5983 return frame->GetParameter(index); |
| 5988 } else { | 5984 } else { |
| 5989 return isolate->initial_object_prototype()->GetElement(isolate, index); | 5985 return isolate->initial_object_prototype()->GetElement(isolate, index); |
| 5990 } | 5986 } |
| 5991 } | 5987 } |
| 5992 | 5988 |
| 5993 // Handle special arguments properties. | 5989 // Handle special arguments properties. |
| 5994 if (key->Equals(isolate->heap()->length_string())) return Smi::FromInt(n); | 5990 if (key->Equals(isolate->heap()->length_string())) return Smi::FromInt(n); |
| 5995 if (key->Equals(isolate->heap()->callee_string())) { | 5991 if (key->Equals(isolate->heap()->callee_string())) { |
| 5996 JSFunction* function = frame->function(); | 5992 JSFunction* function = frame->function(); |
| 5997 if (!function->shared()->is_classic_mode()) { | 5993 if (function->shared()->strict_mode() == STRICT) { |
| 5998 return isolate->Throw(*isolate->factory()->NewTypeError( | 5994 return isolate->Throw(*isolate->factory()->NewTypeError( |
| 5999 "strict_arguments_callee", HandleVector<Object>(NULL, 0))); | 5995 "strict_arguments_callee", HandleVector<Object>(NULL, 0))); |
| 6000 } | 5996 } |
| 6001 return function; | 5997 return function; |
| 6002 } | 5998 } |
| 6003 | 5999 |
| 6004 // Lookup in the initial Object.prototype object. | 6000 // Lookup in the initial Object.prototype object. |
| 6005 return isolate->initial_object_prototype()->GetProperty(*key); | 6001 return isolate->initial_object_prototype()->GetProperty(*key); |
| 6006 } | 6002 } |
| 6007 | 6003 |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6238 str, ALLOW_TRAILING_JUNK, OS::nan_value()); | 6234 str, ALLOW_TRAILING_JUNK, OS::nan_value()); |
| 6239 | 6235 |
| 6240 // Create a number object from the value. | 6236 // Create a number object from the value. |
| 6241 return isolate->heap()->NumberFromDouble(value); | 6237 return isolate->heap()->NumberFromDouble(value); |
| 6242 } | 6238 } |
| 6243 | 6239 |
| 6244 | 6240 |
| 6245 template <class Converter> | 6241 template <class Converter> |
| 6246 MUST_USE_RESULT static MaybeObject* ConvertCaseHelper( | 6242 MUST_USE_RESULT static MaybeObject* ConvertCaseHelper( |
| 6247 Isolate* isolate, | 6243 Isolate* isolate, |
| 6248 String* s, | 6244 String* string, |
| 6249 String::Encoding result_encoding, | 6245 SeqString* result, |
| 6250 int length, | 6246 int result_length, |
| 6251 int input_string_length, | |
| 6252 unibrow::Mapping<Converter, 128>* mapping) { | 6247 unibrow::Mapping<Converter, 128>* mapping) { |
| 6248 DisallowHeapAllocation no_gc; |
| 6253 // We try this twice, once with the assumption that the result is no longer | 6249 // We try this twice, once with the assumption that the result is no longer |
| 6254 // than the input and, if that assumption breaks, again with the exact | 6250 // than the input and, if that assumption breaks, again with the exact |
| 6255 // length. This may not be pretty, but it is nicer than what was here before | 6251 // length. This may not be pretty, but it is nicer than what was here before |
| 6256 // and I hereby claim my vaffel-is. | 6252 // and I hereby claim my vaffel-is. |
| 6257 // | 6253 // |
| 6258 // Allocate the resulting string. | |
| 6259 // | |
| 6260 // NOTE: This assumes that the upper/lower case of an ASCII | 6254 // NOTE: This assumes that the upper/lower case of an ASCII |
| 6261 // character is also ASCII. This is currently the case, but it | 6255 // character is also ASCII. This is currently the case, but it |
| 6262 // might break in the future if we implement more context and locale | 6256 // might break in the future if we implement more context and locale |
| 6263 // dependent upper/lower conversions. | 6257 // dependent upper/lower conversions. |
| 6264 Object* o; | |
| 6265 { MaybeObject* maybe_o = result_encoding == String::ONE_BYTE_ENCODING | |
| 6266 ? isolate->heap()->AllocateRawOneByteString(length) | |
| 6267 : isolate->heap()->AllocateRawTwoByteString(length); | |
| 6268 if (!maybe_o->ToObject(&o)) return maybe_o; | |
| 6269 } | |
| 6270 String* result = String::cast(o); | |
| 6271 bool has_changed_character = false; | 6258 bool has_changed_character = false; |
| 6272 | 6259 |
| 6273 DisallowHeapAllocation no_gc; | |
| 6274 | |
| 6275 // Convert all characters to upper case, assuming that they will fit | 6260 // Convert all characters to upper case, assuming that they will fit |
| 6276 // in the buffer | 6261 // in the buffer |
| 6277 Access<ConsStringIteratorOp> op( | 6262 Access<ConsStringIteratorOp> op( |
| 6278 isolate->runtime_state()->string_iterator()); | 6263 isolate->runtime_state()->string_iterator()); |
| 6279 StringCharacterStream stream(s, op.value()); | 6264 StringCharacterStream stream(string, op.value()); |
| 6280 unibrow::uchar chars[Converter::kMaxWidth]; | 6265 unibrow::uchar chars[Converter::kMaxWidth]; |
| 6281 // We can assume that the string is not empty | 6266 // We can assume that the string is not empty |
| 6282 uc32 current = stream.GetNext(); | 6267 uc32 current = stream.GetNext(); |
| 6283 // y with umlauts is the only character that stops fitting into one-byte | 6268 // y with umlauts is the only character that stops fitting into one-byte |
| 6284 // when converting to uppercase. | 6269 // when converting to uppercase. |
| 6285 static const uc32 yuml_code = 0xff; | 6270 static const uc32 yuml_code = 0xff; |
| 6286 bool ignore_yuml = result->IsSeqTwoByteString() || Converter::kIsToLower; | 6271 bool ignore_yuml = result->IsSeqTwoByteString() || Converter::kIsToLower; |
| 6287 for (int i = 0; i < length;) { | 6272 for (int i = 0; i < result_length;) { |
| 6288 bool has_next = stream.HasMore(); | 6273 bool has_next = stream.HasMore(); |
| 6289 uc32 next = has_next ? stream.GetNext() : 0; | 6274 uc32 next = has_next ? stream.GetNext() : 0; |
| 6290 int char_length = mapping->get(current, next, chars); | 6275 int char_length = mapping->get(current, next, chars); |
| 6291 if (char_length == 0) { | 6276 if (char_length == 0) { |
| 6292 // The case conversion of this character is the character itself. | 6277 // The case conversion of this character is the character itself. |
| 6293 result->Set(i, current); | 6278 result->Set(i, current); |
| 6294 i++; | 6279 i++; |
| 6295 } else if (char_length == 1 && (ignore_yuml || current != yuml_code)) { | 6280 } else if (char_length == 1 && (ignore_yuml || current != yuml_code)) { |
| 6296 // Common case: converting the letter resulted in one character. | 6281 // Common case: converting the letter resulted in one character. |
| 6297 ASSERT(static_cast<uc32>(chars[0]) != current); | 6282 ASSERT(static_cast<uc32>(chars[0]) != current); |
| 6298 result->Set(i, chars[0]); | 6283 result->Set(i, chars[0]); |
| 6299 has_changed_character = true; | 6284 has_changed_character = true; |
| 6300 i++; | 6285 i++; |
| 6301 } else if (length == input_string_length) { | 6286 } else if (result_length == string->length()) { |
| 6302 bool found_yuml = (current == yuml_code); | 6287 bool found_yuml = (current == yuml_code); |
| 6303 // We've assumed that the result would be as long as the | 6288 // We've assumed that the result would be as long as the |
| 6304 // input but here is a character that converts to several | 6289 // input but here is a character that converts to several |
| 6305 // characters. No matter, we calculate the exact length | 6290 // characters. No matter, we calculate the exact length |
| 6306 // of the result and try the whole thing again. | 6291 // of the result and try the whole thing again. |
| 6307 // | 6292 // |
| 6308 // Note that this leaves room for optimization. We could just | 6293 // Note that this leaves room for optimization. We could just |
| 6309 // memcpy what we already have to the result string. Also, | 6294 // memcpy what we already have to the result string. Also, |
| 6310 // the result string is the last object allocated we could | 6295 // the result string is the last object allocated we could |
| 6311 // "realloc" it and probably, in the vast majority of cases, | 6296 // "realloc" it and probably, in the vast majority of cases, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6345 } | 6330 } |
| 6346 current = next; | 6331 current = next; |
| 6347 } | 6332 } |
| 6348 if (has_changed_character) { | 6333 if (has_changed_character) { |
| 6349 return result; | 6334 return result; |
| 6350 } else { | 6335 } else { |
| 6351 // If we didn't actually change anything in doing the conversion | 6336 // If we didn't actually change anything in doing the conversion |
| 6352 // we simple return the result and let the converted string | 6337 // we simple return the result and let the converted string |
| 6353 // become garbage; there is no reason to keep two identical strings | 6338 // become garbage; there is no reason to keep two identical strings |
| 6354 // alive. | 6339 // alive. |
| 6355 return s; | 6340 return string; |
| 6356 } | 6341 } |
| 6357 } | 6342 } |
| 6358 | 6343 |
| 6359 | 6344 |
| 6360 namespace { | 6345 namespace { |
| 6361 | 6346 |
| 6362 static const uintptr_t kOneInEveryByte = kUintptrAllBitsSet / 0xFF; | 6347 static const uintptr_t kOneInEveryByte = kUintptrAllBitsSet / 0xFF; |
| 6363 static const uintptr_t kAsciiMask = kOneInEveryByte << 7; | 6348 static const uintptr_t kAsciiMask = kOneInEveryByte << 7; |
| 6364 | 6349 |
| 6365 // Given a word and two range boundaries returns a word with high bit | 6350 // Given a word and two range boundaries returns a word with high bit |
| (...skipping 10 matching lines...) Expand all Loading... |
| 6376 // Has high bit set in every w byte less than n. | 6361 // Has high bit set in every w byte less than n. |
| 6377 uintptr_t tmp1 = kOneInEveryByte * (0x7F + n) - w; | 6362 uintptr_t tmp1 = kOneInEveryByte * (0x7F + n) - w; |
| 6378 // Has high bit set in every w byte greater than m. | 6363 // Has high bit set in every w byte greater than m. |
| 6379 uintptr_t tmp2 = w + kOneInEveryByte * (0x7F - m); | 6364 uintptr_t tmp2 = w + kOneInEveryByte * (0x7F - m); |
| 6380 return (tmp1 & tmp2 & (kOneInEveryByte * 0x80)); | 6365 return (tmp1 & tmp2 & (kOneInEveryByte * 0x80)); |
| 6381 } | 6366 } |
| 6382 | 6367 |
| 6383 | 6368 |
| 6384 #ifdef DEBUG | 6369 #ifdef DEBUG |
| 6385 static bool CheckFastAsciiConvert(char* dst, | 6370 static bool CheckFastAsciiConvert(char* dst, |
| 6386 char* src, | 6371 const char* src, |
| 6387 int length, | 6372 int length, |
| 6388 bool changed, | 6373 bool changed, |
| 6389 bool is_to_lower) { | 6374 bool is_to_lower) { |
| 6390 bool expected_changed = false; | 6375 bool expected_changed = false; |
| 6391 for (int i = 0; i < length; i++) { | 6376 for (int i = 0; i < length; i++) { |
| 6392 if (dst[i] == src[i]) continue; | 6377 if (dst[i] == src[i]) continue; |
| 6393 expected_changed = true; | 6378 expected_changed = true; |
| 6394 if (is_to_lower) { | 6379 if (is_to_lower) { |
| 6395 ASSERT('A' <= src[i] && src[i] <= 'Z'); | 6380 ASSERT('A' <= src[i] && src[i] <= 'Z'); |
| 6396 ASSERT(dst[i] == src[i] + ('a' - 'A')); | 6381 ASSERT(dst[i] == src[i] + ('a' - 'A')); |
| 6397 } else { | 6382 } else { |
| 6398 ASSERT('a' <= src[i] && src[i] <= 'z'); | 6383 ASSERT('a' <= src[i] && src[i] <= 'z'); |
| 6399 ASSERT(dst[i] == src[i] - ('a' - 'A')); | 6384 ASSERT(dst[i] == src[i] - ('a' - 'A')); |
| 6400 } | 6385 } |
| 6401 } | 6386 } |
| 6402 return (expected_changed == changed); | 6387 return (expected_changed == changed); |
| 6403 } | 6388 } |
| 6404 #endif | 6389 #endif |
| 6405 | 6390 |
| 6406 | 6391 |
| 6407 template<class Converter> | 6392 template<class Converter> |
| 6408 static bool FastAsciiConvert(char* dst, | 6393 static bool FastAsciiConvert(char* dst, |
| 6409 char* src, | 6394 const char* src, |
| 6410 int length, | 6395 int length, |
| 6411 bool* changed_out) { | 6396 bool* changed_out) { |
| 6412 #ifdef DEBUG | 6397 #ifdef DEBUG |
| 6413 char* saved_dst = dst; | 6398 char* saved_dst = dst; |
| 6414 char* saved_src = src; | 6399 const char* saved_src = src; |
| 6415 #endif | 6400 #endif |
| 6416 DisallowHeapAllocation no_gc; | 6401 DisallowHeapAllocation no_gc; |
| 6417 // We rely on the distance between upper and lower case letters | 6402 // We rely on the distance between upper and lower case letters |
| 6418 // being a known power of 2. | 6403 // being a known power of 2. |
| 6419 ASSERT('a' - 'A' == (1 << 5)); | 6404 ASSERT('a' - 'A' == (1 << 5)); |
| 6420 // Boundaries for the range of input characters than require conversion. | 6405 // Boundaries for the range of input characters than require conversion. |
| 6421 static const char lo = Converter::kIsToLower ? 'A' - 1 : 'a' - 1; | 6406 static const char lo = Converter::kIsToLower ? 'A' - 1 : 'a' - 1; |
| 6422 static const char hi = Converter::kIsToLower ? 'Z' + 1 : 'z' + 1; | 6407 static const char hi = Converter::kIsToLower ? 'Z' + 1 : 'z' + 1; |
| 6423 bool changed = false; | 6408 bool changed = false; |
| 6424 uintptr_t or_acc = 0; | 6409 uintptr_t or_acc = 0; |
| 6425 char* const limit = src + length; | 6410 const char* const limit = src + length; |
| 6426 #ifdef V8_HOST_CAN_READ_UNALIGNED | 6411 #ifdef V8_HOST_CAN_READ_UNALIGNED |
| 6427 // Process the prefix of the input that requires no conversion one | 6412 // Process the prefix of the input that requires no conversion one |
| 6428 // (machine) word at a time. | 6413 // (machine) word at a time. |
| 6429 while (src <= limit - sizeof(uintptr_t)) { | 6414 while (src <= limit - sizeof(uintptr_t)) { |
| 6430 uintptr_t w = *reinterpret_cast<uintptr_t*>(src); | 6415 const uintptr_t w = *reinterpret_cast<const uintptr_t*>(src); |
| 6431 or_acc |= w; | 6416 or_acc |= w; |
| 6432 if (AsciiRangeMask(w, lo, hi) != 0) { | 6417 if (AsciiRangeMask(w, lo, hi) != 0) { |
| 6433 changed = true; | 6418 changed = true; |
| 6434 break; | 6419 break; |
| 6435 } | 6420 } |
| 6436 *reinterpret_cast<uintptr_t*>(dst) = w; | 6421 *reinterpret_cast<uintptr_t*>(dst) = w; |
| 6437 src += sizeof(uintptr_t); | 6422 src += sizeof(uintptr_t); |
| 6438 dst += sizeof(uintptr_t); | 6423 dst += sizeof(uintptr_t); |
| 6439 } | 6424 } |
| 6440 // Process the remainder of the input performing conversion when | 6425 // Process the remainder of the input performing conversion when |
| 6441 // required one word at a time. | 6426 // required one word at a time. |
| 6442 while (src <= limit - sizeof(uintptr_t)) { | 6427 while (src <= limit - sizeof(uintptr_t)) { |
| 6443 uintptr_t w = *reinterpret_cast<uintptr_t*>(src); | 6428 const uintptr_t w = *reinterpret_cast<const uintptr_t*>(src); |
| 6444 or_acc |= w; | 6429 or_acc |= w; |
| 6445 uintptr_t m = AsciiRangeMask(w, lo, hi); | 6430 uintptr_t m = AsciiRangeMask(w, lo, hi); |
| 6446 // The mask has high (7th) bit set in every byte that needs | 6431 // The mask has high (7th) bit set in every byte that needs |
| 6447 // conversion and we know that the distance between cases is | 6432 // conversion and we know that the distance between cases is |
| 6448 // 1 << 5. | 6433 // 1 << 5. |
| 6449 *reinterpret_cast<uintptr_t*>(dst) = w ^ (m >> 2); | 6434 *reinterpret_cast<uintptr_t*>(dst) = w ^ (m >> 2); |
| 6450 src += sizeof(uintptr_t); | 6435 src += sizeof(uintptr_t); |
| 6451 dst += sizeof(uintptr_t); | 6436 dst += sizeof(uintptr_t); |
| 6452 } | 6437 } |
| 6453 #endif | 6438 #endif |
| (...skipping 22 matching lines...) Expand all Loading... |
| 6476 } | 6461 } |
| 6477 | 6462 |
| 6478 } // namespace | 6463 } // namespace |
| 6479 | 6464 |
| 6480 | 6465 |
| 6481 template <class Converter> | 6466 template <class Converter> |
| 6482 MUST_USE_RESULT static MaybeObject* ConvertCase( | 6467 MUST_USE_RESULT static MaybeObject* ConvertCase( |
| 6483 Arguments args, | 6468 Arguments args, |
| 6484 Isolate* isolate, | 6469 Isolate* isolate, |
| 6485 unibrow::Mapping<Converter, 128>* mapping) { | 6470 unibrow::Mapping<Converter, 128>* mapping) { |
| 6486 SealHandleScope shs(isolate); | 6471 HandleScope handle_scope(isolate); |
| 6487 CONVERT_ARG_CHECKED(String, s, 0); | 6472 CONVERT_ARG_HANDLE_CHECKED(String, s, 0); |
| 6488 s = s->TryFlattenGetString(); | 6473 s = FlattenGetString(s); |
| 6489 | 6474 int length = s->length(); |
| 6490 const int length = s->length(); | |
| 6491 // Assume that the string is not empty; we need this assumption later | 6475 // Assume that the string is not empty; we need this assumption later |
| 6492 if (length == 0) return s; | 6476 if (length == 0) return *s; |
| 6493 | 6477 |
| 6494 // Simpler handling of ASCII strings. | 6478 // Simpler handling of ASCII strings. |
| 6495 // | 6479 // |
| 6496 // NOTE: This assumes that the upper/lower case of an ASCII | 6480 // NOTE: This assumes that the upper/lower case of an ASCII |
| 6497 // character is also ASCII. This is currently the case, but it | 6481 // character is also ASCII. This is currently the case, but it |
| 6498 // might break in the future if we implement more context and locale | 6482 // might break in the future if we implement more context and locale |
| 6499 // dependent upper/lower conversions. | 6483 // dependent upper/lower conversions. |
| 6500 if (s->IsSeqOneByteString()) { | 6484 if (s->IsOneByteRepresentationUnderneath()) { |
| 6501 Object* o; | 6485 Handle<SeqOneByteString> result = |
| 6502 { MaybeObject* maybe_o = isolate->heap()->AllocateRawOneByteString(length); | 6486 isolate->factory()->NewRawOneByteString(length); |
| 6503 if (!maybe_o->ToObject(&o)) return maybe_o; | 6487 |
| 6504 } | 6488 DisallowHeapAllocation no_gc; |
| 6505 SeqOneByteString* result = SeqOneByteString::cast(o); | 6489 String::FlatContent flat_content = s->GetFlatContent(); |
| 6490 ASSERT(flat_content.IsFlat()); |
| 6506 bool has_changed_character = false; | 6491 bool has_changed_character = false; |
| 6507 bool is_ascii = FastAsciiConvert<Converter>( | 6492 bool is_ascii = FastAsciiConvert<Converter>( |
| 6508 reinterpret_cast<char*>(result->GetChars()), | 6493 reinterpret_cast<char*>(result->GetChars()), |
| 6509 reinterpret_cast<char*>(SeqOneByteString::cast(s)->GetChars()), | 6494 reinterpret_cast<const char*>(flat_content.ToOneByteVector().start()), |
| 6510 length, | 6495 length, |
| 6511 &has_changed_character); | 6496 &has_changed_character); |
| 6512 // If not ASCII, we discard the result and take the 2 byte path. | 6497 // If not ASCII, we discard the result and take the 2 byte path. |
| 6513 if (is_ascii) { | 6498 if (is_ascii) return has_changed_character ? *result : *s; |
| 6514 return has_changed_character ? result : s; | |
| 6515 } | |
| 6516 } | 6499 } |
| 6517 | 6500 |
| 6518 String::Encoding result_encoding = s->IsOneByteRepresentation() | 6501 Handle<SeqString> result; |
| 6519 ? String::ONE_BYTE_ENCODING : String::TWO_BYTE_ENCODING; | 6502 if (s->IsOneByteRepresentation()) { |
| 6503 result = isolate->factory()->NewRawOneByteString(length); |
| 6504 } else { |
| 6505 result = isolate->factory()->NewRawTwoByteString(length); |
| 6506 } |
| 6507 MaybeObject* maybe = ConvertCaseHelper(isolate, *s, *result, length, mapping); |
| 6520 Object* answer; | 6508 Object* answer; |
| 6521 { MaybeObject* maybe_answer = ConvertCaseHelper( | 6509 if (!maybe->ToObject(&answer)) return maybe; |
| 6522 isolate, s, result_encoding, length, length, mapping); | 6510 if (answer->IsString()) return answer; |
| 6523 if (!maybe_answer->ToObject(&answer)) return maybe_answer; | 6511 |
| 6512 ASSERT(answer->IsSmi()); |
| 6513 length = Smi::cast(answer)->value(); |
| 6514 if (s->IsOneByteRepresentation() && length > 0) { |
| 6515 result = isolate->factory()->NewRawOneByteString(length); |
| 6516 } else { |
| 6517 if (length < 0) length = -length; |
| 6518 result = isolate->factory()->NewRawTwoByteString(length); |
| 6524 } | 6519 } |
| 6525 if (answer->IsSmi()) { | 6520 return ConvertCaseHelper(isolate, *s, *result, length, mapping); |
| 6526 int new_length = Smi::cast(answer)->value(); | |
| 6527 if (new_length < 0) { | |
| 6528 result_encoding = String::TWO_BYTE_ENCODING; | |
| 6529 new_length = -new_length; | |
| 6530 } | |
| 6531 MaybeObject* maybe_answer = ConvertCaseHelper( | |
| 6532 isolate, s, result_encoding, new_length, length, mapping); | |
| 6533 if (!maybe_answer->ToObject(&answer)) return maybe_answer; | |
| 6534 } | |
| 6535 return answer; | |
| 6536 } | 6521 } |
| 6537 | 6522 |
| 6538 | 6523 |
| 6539 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringToLowerCase) { | 6524 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringToLowerCase) { |
| 6540 return ConvertCase( | 6525 return ConvertCase( |
| 6541 args, isolate, isolate->runtime_state()->to_lower_mapping()); | 6526 args, isolate, isolate->runtime_state()->to_lower_mapping()); |
| 6542 } | 6527 } |
| 6543 | 6528 |
| 6544 | 6529 |
| 6545 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringToUpperCase) { | 6530 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringToUpperCase) { |
| (...skipping 1117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7663 return isolate->heap()->AllocateHeapNumber(std::NAME(x)); \ | 7648 return isolate->heap()->AllocateHeapNumber(std::NAME(x)); \ |
| 7664 } | 7649 } |
| 7665 | 7650 |
| 7666 RUNTIME_UNARY_MATH(acos) | 7651 RUNTIME_UNARY_MATH(acos) |
| 7667 RUNTIME_UNARY_MATH(asin) | 7652 RUNTIME_UNARY_MATH(asin) |
| 7668 RUNTIME_UNARY_MATH(atan) | 7653 RUNTIME_UNARY_MATH(atan) |
| 7669 RUNTIME_UNARY_MATH(log) | 7654 RUNTIME_UNARY_MATH(log) |
| 7670 #undef RUNTIME_UNARY_MATH | 7655 #undef RUNTIME_UNARY_MATH |
| 7671 | 7656 |
| 7672 | 7657 |
| 7673 // Cube root approximation, refer to: http://metamerist.com/cbrt/cbrt.htm | 7658 RUNTIME_FUNCTION(MaybeObject*, Runtime_DoubleHi) { |
| 7674 // Using initial approximation adapted from Kahan's cbrt and 4 iterations | 7659 SealHandleScope shs(isolate); |
| 7675 // of Newton's method. | 7660 ASSERT(args.length() == 1); |
| 7676 inline double CubeRootNewtonIteration(double approx, double x) { | 7661 CONVERT_DOUBLE_ARG_CHECKED(x, 0); |
| 7677 return (1.0 / 3.0) * (x / (approx * approx) + 2 * approx); | 7662 uint64_t integer = double_to_uint64(x); |
| 7663 integer = (integer >> 32) & 0xFFFFFFFFu; |
| 7664 return isolate->heap()->NumberFromDouble(static_cast<int32_t>(integer)); |
| 7678 } | 7665 } |
| 7679 | 7666 |
| 7680 | 7667 |
| 7681 inline double CubeRoot(double x) { | 7668 RUNTIME_FUNCTION(MaybeObject*, Runtime_DoubleLo) { |
| 7682 static const uint64_t magic = V8_2PART_UINT64_C(0x2A9F7893, 00000000); | 7669 SealHandleScope shs(isolate); |
| 7683 uint64_t xhigh = double_to_uint64(x); | 7670 ASSERT(args.length() == 1); |
| 7684 double approx = uint64_to_double(xhigh / 3 + magic); | 7671 CONVERT_DOUBLE_ARG_CHECKED(x, 0); |
| 7685 | 7672 return isolate->heap()->NumberFromDouble( |
| 7686 approx = CubeRootNewtonIteration(approx, x); | 7673 static_cast<int32_t>(double_to_uint64(x) & 0xFFFFFFFFu)); |
| 7687 approx = CubeRootNewtonIteration(approx, x); | |
| 7688 approx = CubeRootNewtonIteration(approx, x); | |
| 7689 return CubeRootNewtonIteration(approx, x); | |
| 7690 } | 7674 } |
| 7691 | 7675 |
| 7692 | 7676 |
| 7693 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_cbrt) { | 7677 RUNTIME_FUNCTION(MaybeObject*, Runtime_ConstructDouble) { |
| 7694 SealHandleScope shs(isolate); | 7678 SealHandleScope shs(isolate); |
| 7695 ASSERT(args.length() == 1); | 7679 ASSERT(args.length() == 2); |
| 7696 CONVERT_DOUBLE_ARG_CHECKED(x, 0); | 7680 CONVERT_NUMBER_CHECKED(uint32_t, hi, Uint32, args[0]); |
| 7697 if (x == 0 || std::isinf(x)) return args[0]; | 7681 CONVERT_NUMBER_CHECKED(uint32_t, lo, Uint32, args[1]); |
| 7698 double result = (x > 0) ? CubeRoot(x) : -CubeRoot(-x); | 7682 uint64_t result = (static_cast<uint64_t>(hi) << 32) | lo; |
| 7699 return isolate->heap()->AllocateHeapNumber(result); | 7683 return isolate->heap()->AllocateHeapNumber(uint64_to_double(result)); |
| 7700 } | 7684 } |
| 7701 | 7685 |
| 7702 | 7686 |
| 7703 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_log1p) { | |
| 7704 SealHandleScope shs(isolate); | |
| 7705 ASSERT(args.length() == 1); | |
| 7706 CONVERT_DOUBLE_ARG_CHECKED(x, 0); | |
| 7707 | |
| 7708 double x_abs = std::fabs(x); | |
| 7709 // Use Taylor series to approximate. With y = x + 1; | |
| 7710 // log(y) at 1 == log(1) + log'(1)(y-1)/1! + log''(1)(y-1)^2/2! + ... | |
| 7711 // == 0 + x - x^2/2 + x^3/3 ... | |
| 7712 // The closer x is to 0, the fewer terms are required. | |
| 7713 static const double threshold_2 = 1.0 / 0x00800000; | |
| 7714 static const double threshold_3 = 1.0 / 0x00008000; | |
| 7715 static const double threshold_7 = 1.0 / 0x00000080; | |
| 7716 | |
| 7717 double result; | |
| 7718 if (x_abs < threshold_2) { | |
| 7719 result = x * (1.0/1.0 - x * 1.0/2.0); | |
| 7720 } else if (x_abs < threshold_3) { | |
| 7721 result = x * (1.0/1.0 - x * (1.0/2.0 - x * (1.0/3.0))); | |
| 7722 } else if (x_abs < threshold_7) { | |
| 7723 result = x * (1.0/1.0 - x * (1.0/2.0 - x * ( | |
| 7724 1.0/3.0 - x * (1.0/4.0 - x * ( | |
| 7725 1.0/5.0 - x * (1.0/6.0 - x * ( | |
| 7726 1.0/7.0))))))); | |
| 7727 } else { // Use regular log if not close enough to 0. | |
| 7728 result = std::log(1.0 + x); | |
| 7729 } | |
| 7730 return isolate->heap()->AllocateHeapNumber(result); | |
| 7731 } | |
| 7732 | |
| 7733 | |
| 7734 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_expm1) { | |
| 7735 SealHandleScope shs(isolate); | |
| 7736 ASSERT(args.length() == 1); | |
| 7737 CONVERT_DOUBLE_ARG_CHECKED(x, 0); | |
| 7738 | |
| 7739 double x_abs = std::fabs(x); | |
| 7740 // Use Taylor series to approximate. | |
| 7741 // exp(x) - 1 at 0 == -1 + exp(0) + exp'(0)*x/1! + exp''(0)*x^2/2! + ... | |
| 7742 // == x/1! + x^2/2! + x^3/3! + ... | |
| 7743 // The closer x is to 0, the fewer terms are required. | |
| 7744 static const double threshold_2 = 1.0 / 0x00400000; | |
| 7745 static const double threshold_3 = 1.0 / 0x00004000; | |
| 7746 static const double threshold_6 = 1.0 / 0x00000040; | |
| 7747 | |
| 7748 double result; | |
| 7749 if (x_abs < threshold_2) { | |
| 7750 result = x * (1.0/1.0 + x * (1.0/2.0)); | |
| 7751 } else if (x_abs < threshold_3) { | |
| 7752 result = x * (1.0/1.0 + x * (1.0/2.0 + x * (1.0/6.0))); | |
| 7753 } else if (x_abs < threshold_6) { | |
| 7754 result = x * (1.0/1.0 + x * (1.0/2.0 + x * ( | |
| 7755 1.0/6.0 + x * (1.0/24.0 + x * ( | |
| 7756 1.0/120.0 + x * (1.0/720.0)))))); | |
| 7757 } else { // Use regular exp if not close enough to 0. | |
| 7758 result = std::exp(x) - 1.0; | |
| 7759 } | |
| 7760 return isolate->heap()->AllocateHeapNumber(result); | |
| 7761 } | |
| 7762 | |
| 7763 | |
| 7764 static const double kPiDividedBy4 = 0.78539816339744830962; | 7687 static const double kPiDividedBy4 = 0.78539816339744830962; |
| 7765 | 7688 |
| 7766 | 7689 |
| 7767 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_atan2) { | 7690 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_atan2) { |
| 7768 SealHandleScope shs(isolate); | 7691 SealHandleScope shs(isolate); |
| 7769 ASSERT(args.length() == 2); | 7692 ASSERT(args.length() == 2); |
| 7770 isolate->counters()->math_atan2()->Increment(); | 7693 isolate->counters()->math_atan2()->Increment(); |
| 7771 | 7694 |
| 7772 CONVERT_DOUBLE_ARG_CHECKED(x, 0); | 7695 CONVERT_DOUBLE_ARG_CHECKED(x, 0); |
| 7773 CONVERT_DOUBLE_ARG_CHECKED(y, 1); | 7696 CONVERT_DOUBLE_ARG_CHECKED(y, 1); |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7972 Handle<JSObject> result = | 7895 Handle<JSObject> result = |
| 7973 isolate->factory()->NewArgumentsObject(callee, argument_count); | 7896 isolate->factory()->NewArgumentsObject(callee, argument_count); |
| 7974 // Allocate the elements if needed. | 7897 // Allocate the elements if needed. |
| 7975 int parameter_count = callee->shared()->formal_parameter_count(); | 7898 int parameter_count = callee->shared()->formal_parameter_count(); |
| 7976 if (argument_count > 0) { | 7899 if (argument_count > 0) { |
| 7977 if (parameter_count > 0) { | 7900 if (parameter_count > 0) { |
| 7978 int mapped_count = Min(argument_count, parameter_count); | 7901 int mapped_count = Min(argument_count, parameter_count); |
| 7979 Handle<FixedArray> parameter_map = | 7902 Handle<FixedArray> parameter_map = |
| 7980 isolate->factory()->NewFixedArray(mapped_count + 2, NOT_TENURED); | 7903 isolate->factory()->NewFixedArray(mapped_count + 2, NOT_TENURED); |
| 7981 parameter_map->set_map( | 7904 parameter_map->set_map( |
| 7982 isolate->heap()->non_strict_arguments_elements_map()); | 7905 isolate->heap()->sloppy_arguments_elements_map()); |
| 7983 | 7906 |
| 7984 Handle<Map> old_map(result->map()); | 7907 Handle<Map> old_map(result->map()); |
| 7985 Handle<Map> new_map = isolate->factory()->CopyMap(old_map); | 7908 Handle<Map> new_map = isolate->factory()->CopyMap(old_map); |
| 7986 new_map->set_elements_kind(NON_STRICT_ARGUMENTS_ELEMENTS); | 7909 new_map->set_elements_kind(SLOPPY_ARGUMENTS_ELEMENTS); |
| 7987 | 7910 |
| 7988 result->set_map(*new_map); | 7911 result->set_map(*new_map); |
| 7989 result->set_elements(*parameter_map); | 7912 result->set_elements(*parameter_map); |
| 7990 | 7913 |
| 7991 // Store the context and the arguments array at the beginning of the | 7914 // Store the context and the arguments array at the beginning of the |
| 7992 // parameter map. | 7915 // parameter map. |
| 7993 Handle<Context> context(isolate->context()); | 7916 Handle<Context> context(isolate->context()); |
| 7994 Handle<FixedArray> arguments = | 7917 Handle<FixedArray> arguments = |
| 7995 isolate->factory()->NewFixedArray(argument_count, NOT_TENURED); | 7918 isolate->factory()->NewFixedArray(argument_count, NOT_TENURED); |
| 7996 parameter_map->set(0, *context); | 7919 parameter_map->set(0, *context); |
| (...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8548 Deoptimizer::DeoptimizeFunction(*function); | 8471 Deoptimizer::DeoptimizeFunction(*function); |
| 8549 | 8472 |
| 8550 return isolate->heap()->undefined_value(); | 8473 return isolate->heap()->undefined_value(); |
| 8551 } | 8474 } |
| 8552 | 8475 |
| 8553 | 8476 |
| 8554 RUNTIME_FUNCTION(MaybeObject*, Runtime_ClearFunctionTypeFeedback) { | 8477 RUNTIME_FUNCTION(MaybeObject*, Runtime_ClearFunctionTypeFeedback) { |
| 8555 HandleScope scope(isolate); | 8478 HandleScope scope(isolate); |
| 8556 ASSERT(args.length() == 1); | 8479 ASSERT(args.length() == 1); |
| 8557 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); | 8480 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); |
| 8481 function->shared()->ClearTypeFeedbackInfo(isolate->heap()); |
| 8558 Code* unoptimized = function->shared()->code(); | 8482 Code* unoptimized = function->shared()->code(); |
| 8559 if (unoptimized->kind() == Code::FUNCTION) { | 8483 if (unoptimized->kind() == Code::FUNCTION) { |
| 8560 unoptimized->ClearInlineCaches(); | 8484 unoptimized->ClearInlineCaches(); |
| 8561 unoptimized->ClearTypeFeedbackInfo(isolate->heap()); | |
| 8562 } | 8485 } |
| 8563 return isolate->heap()->undefined_value(); | 8486 return isolate->heap()->undefined_value(); |
| 8564 } | 8487 } |
| 8565 | 8488 |
| 8566 | 8489 |
| 8567 RUNTIME_FUNCTION(MaybeObject*, Runtime_RunningInSimulator) { | 8490 RUNTIME_FUNCTION(MaybeObject*, Runtime_RunningInSimulator) { |
| 8568 SealHandleScope shs(isolate); | 8491 SealHandleScope shs(isolate); |
| 8569 #if defined(USE_SIMULATOR) | 8492 #if defined(USE_SIMULATOR) |
| 8570 return isolate->heap()->true_value(); | 8493 return isolate->heap()->true_value(); |
| 8571 #else | 8494 #else |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8793 } | 8716 } |
| 8794 } | 8717 } |
| 8795 | 8718 |
| 8796 // Failed. | 8719 // Failed. |
| 8797 if (FLAG_trace_osr) { | 8720 if (FLAG_trace_osr) { |
| 8798 PrintF("[OSR - Failed: "); | 8721 PrintF("[OSR - Failed: "); |
| 8799 function->PrintName(); | 8722 function->PrintName(); |
| 8800 PrintF(" at AST id %d]\n", ast_id.ToInt()); | 8723 PrintF(" at AST id %d]\n", ast_id.ToInt()); |
| 8801 } | 8724 } |
| 8802 | 8725 |
| 8803 function->ReplaceCode(function->shared()->code()); | 8726 if (!function->IsOptimized()) { |
| 8727 function->ReplaceCode(function->shared()->code()); |
| 8728 } |
| 8804 return NULL; | 8729 return NULL; |
| 8805 } | 8730 } |
| 8806 | 8731 |
| 8807 | 8732 |
| 8808 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetAllocationTimeout) { | 8733 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetAllocationTimeout) { |
| 8809 SealHandleScope shs(isolate); | 8734 SealHandleScope shs(isolate); |
| 8810 ASSERT(args.length() == 2 || args.length() == 3); | 8735 ASSERT(args.length() == 2 || args.length() == 3); |
| 8811 #ifdef DEBUG | 8736 #ifdef DEBUG |
| 8812 CONVERT_SMI_ARG_CHECKED(interval, 0); | 8737 CONVERT_SMI_ARG_CHECKED(interval, 0); |
| 8813 CONVERT_SMI_ARG_CHECKED(timeout, 1); | 8738 CONVERT_SMI_ARG_CHECKED(timeout, 1); |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9107 Handle<JSModule> module(context->module()); | 9032 Handle<JSModule> module(context->module()); |
| 9108 | 9033 |
| 9109 for (int j = 0; j < description->length(); ++j) { | 9034 for (int j = 0; j < description->length(); ++j) { |
| 9110 Handle<String> name(description->name(j)); | 9035 Handle<String> name(description->name(j)); |
| 9111 VariableMode mode = description->mode(j); | 9036 VariableMode mode = description->mode(j); |
| 9112 int index = description->index(j); | 9037 int index = description->index(j); |
| 9113 switch (mode) { | 9038 switch (mode) { |
| 9114 case VAR: | 9039 case VAR: |
| 9115 case LET: | 9040 case LET: |
| 9116 case CONST: | 9041 case CONST: |
| 9117 case CONST_HARMONY: { | 9042 case CONST_LEGACY: { |
| 9118 PropertyAttributes attr = | 9043 PropertyAttributes attr = |
| 9119 IsImmutableVariableMode(mode) ? FROZEN : SEALED; | 9044 IsImmutableVariableMode(mode) ? FROZEN : SEALED; |
| 9120 Handle<AccessorInfo> info = | 9045 Handle<AccessorInfo> info = |
| 9121 Accessors::MakeModuleExport(name, index, attr); | 9046 Accessors::MakeModuleExport(name, index, attr); |
| 9122 Handle<Object> result = JSObject::SetAccessor(module, info); | 9047 Handle<Object> result = JSObject::SetAccessor(module, info); |
| 9123 ASSERT(!(result.is_null() || result->IsUndefined())); | 9048 ASSERT(!(result.is_null() || result->IsUndefined())); |
| 9124 USE(result); | 9049 USE(result); |
| 9125 break; | 9050 break; |
| 9126 } | 9051 } |
| 9127 case MODULE: { | 9052 case MODULE: { |
| 9128 Object* referenced_context = Context::cast(host_context)->get(index); | 9053 Object* referenced_context = Context::cast(host_context)->get(index); |
| 9129 Handle<JSModule> value(Context::cast(referenced_context)->module()); | 9054 Handle<JSModule> value(Context::cast(referenced_context)->module()); |
| 9130 JSReceiver::SetProperty(module, name, value, FROZEN, kStrictMode); | 9055 JSReceiver::SetProperty(module, name, value, FROZEN, STRICT); |
| 9131 break; | 9056 break; |
| 9132 } | 9057 } |
| 9133 case INTERNAL: | 9058 case INTERNAL: |
| 9134 case TEMPORARY: | 9059 case TEMPORARY: |
| 9135 case DYNAMIC: | 9060 case DYNAMIC: |
| 9136 case DYNAMIC_GLOBAL: | 9061 case DYNAMIC_GLOBAL: |
| 9137 case DYNAMIC_LOCAL: | 9062 case DYNAMIC_LOCAL: |
| 9138 UNREACHABLE(); | 9063 UNREACHABLE(); |
| 9139 } | 9064 } |
| 9140 } | 9065 } |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9343 } | 9268 } |
| 9344 | 9269 |
| 9345 | 9270 |
| 9346 RUNTIME_FUNCTION(MaybeObject*, Runtime_StoreContextSlot) { | 9271 RUNTIME_FUNCTION(MaybeObject*, Runtime_StoreContextSlot) { |
| 9347 HandleScope scope(isolate); | 9272 HandleScope scope(isolate); |
| 9348 ASSERT(args.length() == 4); | 9273 ASSERT(args.length() == 4); |
| 9349 | 9274 |
| 9350 Handle<Object> value(args[0], isolate); | 9275 Handle<Object> value(args[0], isolate); |
| 9351 CONVERT_ARG_HANDLE_CHECKED(Context, context, 1); | 9276 CONVERT_ARG_HANDLE_CHECKED(Context, context, 1); |
| 9352 CONVERT_ARG_HANDLE_CHECKED(String, name, 2); | 9277 CONVERT_ARG_HANDLE_CHECKED(String, name, 2); |
| 9353 CONVERT_LANGUAGE_MODE_ARG(language_mode, 3); | 9278 CONVERT_STRICT_MODE_ARG_CHECKED(strict_mode, 3); |
| 9354 StrictModeFlag strict_mode = (language_mode == CLASSIC_MODE) | |
| 9355 ? kNonStrictMode : kStrictMode; | |
| 9356 | 9279 |
| 9357 int index; | 9280 int index; |
| 9358 PropertyAttributes attributes; | 9281 PropertyAttributes attributes; |
| 9359 ContextLookupFlags flags = FOLLOW_CHAINS; | 9282 ContextLookupFlags flags = FOLLOW_CHAINS; |
| 9360 BindingFlags binding_flags; | 9283 BindingFlags binding_flags; |
| 9361 Handle<Object> holder = context->Lookup(name, | 9284 Handle<Object> holder = context->Lookup(name, |
| 9362 flags, | 9285 flags, |
| 9363 &index, | 9286 &index, |
| 9364 &attributes, | 9287 &attributes, |
| 9365 &binding_flags); | 9288 &binding_flags); |
| 9366 if (isolate->has_pending_exception()) return Failure::Exception(); | 9289 if (isolate->has_pending_exception()) return Failure::Exception(); |
| 9367 | 9290 |
| 9368 if (index >= 0) { | 9291 if (index >= 0) { |
| 9369 // The property was found in a context slot. | 9292 // The property was found in a context slot. |
| 9370 Handle<Context> context = Handle<Context>::cast(holder); | 9293 Handle<Context> context = Handle<Context>::cast(holder); |
| 9371 if (binding_flags == MUTABLE_CHECK_INITIALIZED && | 9294 if (binding_flags == MUTABLE_CHECK_INITIALIZED && |
| 9372 context->get(index)->IsTheHole()) { | 9295 context->get(index)->IsTheHole()) { |
| 9373 Handle<Object> error = | 9296 Handle<Object> error = |
| 9374 isolate->factory()->NewReferenceError("not_defined", | 9297 isolate->factory()->NewReferenceError("not_defined", |
| 9375 HandleVector(&name, 1)); | 9298 HandleVector(&name, 1)); |
| 9376 return isolate->Throw(*error); | 9299 return isolate->Throw(*error); |
| 9377 } | 9300 } |
| 9378 // Ignore if read_only variable. | 9301 // Ignore if read_only variable. |
| 9379 if ((attributes & READ_ONLY) == 0) { | 9302 if ((attributes & READ_ONLY) == 0) { |
| 9380 // Context is a fixed array and set cannot fail. | 9303 // Context is a fixed array and set cannot fail. |
| 9381 context->set(index, *value); | 9304 context->set(index, *value); |
| 9382 } else if (strict_mode == kStrictMode) { | 9305 } else if (strict_mode == STRICT) { |
| 9383 // Setting read only property in strict mode. | 9306 // Setting read only property in strict mode. |
| 9384 Handle<Object> error = | 9307 Handle<Object> error = |
| 9385 isolate->factory()->NewTypeError("strict_cannot_assign", | 9308 isolate->factory()->NewTypeError("strict_cannot_assign", |
| 9386 HandleVector(&name, 1)); | 9309 HandleVector(&name, 1)); |
| 9387 return isolate->Throw(*error); | 9310 return isolate->Throw(*error); |
| 9388 } | 9311 } |
| 9389 return *value; | 9312 return *value; |
| 9390 } | 9313 } |
| 9391 | 9314 |
| 9392 // Slow case: The property is not in a context slot. It is either in a | 9315 // Slow case: The property is not in a context slot. It is either in a |
| 9393 // context extension object, a property of the subject of a with, or a | 9316 // context extension object, a property of the subject of a with, or a |
| 9394 // property of the global object. | 9317 // property of the global object. |
| 9395 Handle<JSReceiver> object; | 9318 Handle<JSReceiver> object; |
| 9396 | 9319 |
| 9397 if (!holder.is_null()) { | 9320 if (!holder.is_null()) { |
| 9398 // The property exists on the holder. | 9321 // The property exists on the holder. |
| 9399 object = Handle<JSReceiver>::cast(holder); | 9322 object = Handle<JSReceiver>::cast(holder); |
| 9400 } else { | 9323 } else { |
| 9401 // The property was not found. | 9324 // The property was not found. |
| 9402 ASSERT(attributes == ABSENT); | 9325 ASSERT(attributes == ABSENT); |
| 9403 | 9326 |
| 9404 if (strict_mode == kStrictMode) { | 9327 if (strict_mode == STRICT) { |
| 9405 // Throw in strict mode (assignment to undefined variable). | 9328 // Throw in strict mode (assignment to undefined variable). |
| 9406 Handle<Object> error = | 9329 Handle<Object> error = |
| 9407 isolate->factory()->NewReferenceError( | 9330 isolate->factory()->NewReferenceError( |
| 9408 "not_defined", HandleVector(&name, 1)); | 9331 "not_defined", HandleVector(&name, 1)); |
| 9409 return isolate->Throw(*error); | 9332 return isolate->Throw(*error); |
| 9410 } | 9333 } |
| 9411 // In non-strict mode, the property is added to the global object. | 9334 // In sloppy mode, the property is added to the global object. |
| 9412 attributes = NONE; | 9335 attributes = NONE; |
| 9413 object = Handle<JSReceiver>(isolate->context()->global_object()); | 9336 object = Handle<JSReceiver>(isolate->context()->global_object()); |
| 9414 } | 9337 } |
| 9415 | 9338 |
| 9416 // Set the property if it's not read only or doesn't yet exist. | 9339 // Set the property if it's not read only or doesn't yet exist. |
| 9417 if ((attributes & READ_ONLY) == 0 || | 9340 if ((attributes & READ_ONLY) == 0 || |
| 9418 (object->GetLocalPropertyAttribute(*name) == ABSENT)) { | 9341 (JSReceiver::GetLocalPropertyAttribute(object, name) == ABSENT)) { |
| 9419 RETURN_IF_EMPTY_HANDLE( | 9342 RETURN_IF_EMPTY_HANDLE( |
| 9420 isolate, | 9343 isolate, |
| 9421 JSReceiver::SetProperty(object, name, value, NONE, strict_mode)); | 9344 JSReceiver::SetProperty(object, name, value, NONE, strict_mode)); |
| 9422 } else if (strict_mode == kStrictMode && (attributes & READ_ONLY) != 0) { | 9345 } else if (strict_mode == STRICT && (attributes & READ_ONLY) != 0) { |
| 9423 // Setting read only property in strict mode. | 9346 // Setting read only property in strict mode. |
| 9424 Handle<Object> error = | 9347 Handle<Object> error = |
| 9425 isolate->factory()->NewTypeError( | 9348 isolate->factory()->NewTypeError( |
| 9426 "strict_cannot_assign", HandleVector(&name, 1)); | 9349 "strict_cannot_assign", HandleVector(&name, 1)); |
| 9427 return isolate->Throw(*error); | 9350 return isolate->Throw(*error); |
| 9428 } | 9351 } |
| 9429 return *value; | 9352 return *value; |
| 9430 } | 9353 } |
| 9431 | 9354 |
| 9432 | 9355 |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9653 return isolate->heap()->null_value(); | 9576 return isolate->heap()->null_value(); |
| 9654 } | 9577 } |
| 9655 } | 9578 } |
| 9656 | 9579 |
| 9657 | 9580 |
| 9658 RUNTIME_FUNCTION(MaybeObject*, Runtime_DateLocalTimezone) { | 9581 RUNTIME_FUNCTION(MaybeObject*, Runtime_DateLocalTimezone) { |
| 9659 SealHandleScope shs(isolate); | 9582 SealHandleScope shs(isolate); |
| 9660 ASSERT(args.length() == 1); | 9583 ASSERT(args.length() == 1); |
| 9661 | 9584 |
| 9662 CONVERT_DOUBLE_ARG_CHECKED(x, 0); | 9585 CONVERT_DOUBLE_ARG_CHECKED(x, 0); |
| 9663 int64_t time = isolate->date_cache()->EquivalentTime(static_cast<int64_t>(x)); | 9586 const char* zone = |
| 9664 const char* zone = OS::LocalTimezone(static_cast<double>(time)); | 9587 isolate->date_cache()->LocalTimezone(static_cast<int64_t>(x)); |
| 9665 return isolate->heap()->AllocateStringFromUtf8(CStrVector(zone)); | 9588 return isolate->heap()->AllocateStringFromUtf8(CStrVector(zone)); |
| 9666 } | 9589 } |
| 9667 | 9590 |
| 9668 | 9591 |
| 9669 RUNTIME_FUNCTION(MaybeObject*, Runtime_DateToUTC) { | 9592 RUNTIME_FUNCTION(MaybeObject*, Runtime_DateToUTC) { |
| 9670 SealHandleScope shs(isolate); | 9593 SealHandleScope shs(isolate); |
| 9671 ASSERT(args.length() == 1); | 9594 ASSERT(args.length() == 1); |
| 9672 | 9595 |
| 9673 CONVERT_DOUBLE_ARG_CHECKED(x, 0); | 9596 CONVERT_DOUBLE_ARG_CHECKED(x, 0); |
| 9674 int64_t time = isolate->date_cache()->ToUTC(static_cast<int64_t>(x)); | 9597 int64_t time = isolate->date_cache()->ToUTC(static_cast<int64_t>(x)); |
| 9675 | 9598 |
| 9676 return isolate->heap()->NumberFromDouble(static_cast<double>(time)); | 9599 return isolate->heap()->NumberFromDouble(static_cast<double>(time)); |
| 9677 } | 9600 } |
| 9678 | 9601 |
| 9679 | 9602 |
| 9603 RUNTIME_FUNCTION(MaybeObject*, Runtime_DateCacheVersion) { |
| 9604 HandleScope hs(isolate); |
| 9605 ASSERT(args.length() == 0); |
| 9606 if (!isolate->eternal_handles()->Exists(EternalHandles::DATE_CACHE_VERSION)) { |
| 9607 Handle<FixedArray> date_cache_version = |
| 9608 isolate->factory()->NewFixedArray(1, TENURED); |
| 9609 date_cache_version->set(0, Smi::FromInt(0)); |
| 9610 isolate->eternal_handles()->CreateSingleton( |
| 9611 isolate, *date_cache_version, EternalHandles::DATE_CACHE_VERSION); |
| 9612 } |
| 9613 Handle<FixedArray> date_cache_version = |
| 9614 Handle<FixedArray>::cast(isolate->eternal_handles()->GetSingleton( |
| 9615 EternalHandles::DATE_CACHE_VERSION)); |
| 9616 // Return result as a JS array. |
| 9617 Handle<JSObject> result = |
| 9618 isolate->factory()->NewJSObject(isolate->array_function()); |
| 9619 isolate->factory()->SetContent(Handle<JSArray>::cast(result), |
| 9620 date_cache_version); |
| 9621 return *result; |
| 9622 } |
| 9623 |
| 9624 |
| 9680 RUNTIME_FUNCTION(MaybeObject*, Runtime_GlobalReceiver) { | 9625 RUNTIME_FUNCTION(MaybeObject*, Runtime_GlobalReceiver) { |
| 9681 SealHandleScope shs(isolate); | 9626 SealHandleScope shs(isolate); |
| 9682 ASSERT(args.length() == 1); | 9627 ASSERT(args.length() == 1); |
| 9683 Object* global = args[0]; | 9628 Object* global = args[0]; |
| 9684 if (!global->IsJSGlobalObject()) return isolate->heap()->null_value(); | 9629 if (!global->IsJSGlobalObject()) return isolate->heap()->null_value(); |
| 9685 return JSGlobalObject::cast(global)->global_receiver(); | 9630 return JSGlobalObject::cast(global)->global_receiver(); |
| 9686 } | 9631 } |
| 9687 | 9632 |
| 9688 | 9633 |
| 9689 RUNTIME_FUNCTION(MaybeObject*, Runtime_IsAttachedGlobal) { | 9634 RUNTIME_FUNCTION(MaybeObject*, Runtime_IsAttachedGlobal) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9751 Handle<Object> error_message = | 9696 Handle<Object> error_message = |
| 9752 context->ErrorMessageForCodeGenerationFromStrings(); | 9697 context->ErrorMessageForCodeGenerationFromStrings(); |
| 9753 return isolate->Throw(*isolate->factory()->NewEvalError( | 9698 return isolate->Throw(*isolate->factory()->NewEvalError( |
| 9754 "code_gen_from_strings", HandleVector<Object>(&error_message, 1))); | 9699 "code_gen_from_strings", HandleVector<Object>(&error_message, 1))); |
| 9755 } | 9700 } |
| 9756 | 9701 |
| 9757 // Compile source string in the native context. | 9702 // Compile source string in the native context. |
| 9758 ParseRestriction restriction = function_literal_only | 9703 ParseRestriction restriction = function_literal_only |
| 9759 ? ONLY_SINGLE_FUNCTION_LITERAL : NO_PARSE_RESTRICTION; | 9704 ? ONLY_SINGLE_FUNCTION_LITERAL : NO_PARSE_RESTRICTION; |
| 9760 Handle<JSFunction> fun = Compiler::GetFunctionFromEval( | 9705 Handle<JSFunction> fun = Compiler::GetFunctionFromEval( |
| 9761 source, context, CLASSIC_MODE, restriction, RelocInfo::kNoPosition); | 9706 source, context, SLOPPY, restriction, RelocInfo::kNoPosition); |
| 9762 RETURN_IF_EMPTY_HANDLE(isolate, fun); | 9707 RETURN_IF_EMPTY_HANDLE(isolate, fun); |
| 9763 return *fun; | 9708 return *fun; |
| 9764 } | 9709 } |
| 9765 | 9710 |
| 9766 | 9711 |
| 9767 static ObjectPair CompileGlobalEval(Isolate* isolate, | 9712 static ObjectPair CompileGlobalEval(Isolate* isolate, |
| 9768 Handle<String> source, | 9713 Handle<String> source, |
| 9769 Handle<Object> receiver, | 9714 Handle<Object> receiver, |
| 9770 LanguageMode language_mode, | 9715 StrictMode strict_mode, |
| 9771 int scope_position) { | 9716 int scope_position) { |
| 9772 Handle<Context> context = Handle<Context>(isolate->context()); | 9717 Handle<Context> context = Handle<Context>(isolate->context()); |
| 9773 Handle<Context> native_context = Handle<Context>(context->native_context()); | 9718 Handle<Context> native_context = Handle<Context>(context->native_context()); |
| 9774 | 9719 |
| 9775 // Check if native context allows code generation from | 9720 // Check if native context allows code generation from |
| 9776 // strings. Throw an exception if it doesn't. | 9721 // strings. Throw an exception if it doesn't. |
| 9777 if (native_context->allow_code_gen_from_strings()->IsFalse() && | 9722 if (native_context->allow_code_gen_from_strings()->IsFalse() && |
| 9778 !CodeGenerationFromStringsAllowed(isolate, native_context)) { | 9723 !CodeGenerationFromStringsAllowed(isolate, native_context)) { |
| 9779 Handle<Object> error_message = | 9724 Handle<Object> error_message = |
| 9780 native_context->ErrorMessageForCodeGenerationFromStrings(); | 9725 native_context->ErrorMessageForCodeGenerationFromStrings(); |
| 9781 isolate->Throw(*isolate->factory()->NewEvalError( | 9726 isolate->Throw(*isolate->factory()->NewEvalError( |
| 9782 "code_gen_from_strings", HandleVector<Object>(&error_message, 1))); | 9727 "code_gen_from_strings", HandleVector<Object>(&error_message, 1))); |
| 9783 return MakePair(Failure::Exception(), NULL); | 9728 return MakePair(Failure::Exception(), NULL); |
| 9784 } | 9729 } |
| 9785 | 9730 |
| 9786 // Deal with a normal eval call with a string argument. Compile it | 9731 // Deal with a normal eval call with a string argument. Compile it |
| 9787 // and return the compiled function bound in the local context. | 9732 // and return the compiled function bound in the local context. |
| 9788 static const ParseRestriction restriction = NO_PARSE_RESTRICTION; | 9733 static const ParseRestriction restriction = NO_PARSE_RESTRICTION; |
| 9789 Handle<JSFunction> compiled = Compiler::GetFunctionFromEval( | 9734 Handle<JSFunction> compiled = Compiler::GetFunctionFromEval( |
| 9790 source, context, language_mode, restriction, scope_position); | 9735 source, context, strict_mode, restriction, scope_position); |
| 9791 RETURN_IF_EMPTY_HANDLE_VALUE(isolate, compiled, | 9736 RETURN_IF_EMPTY_HANDLE_VALUE(isolate, compiled, |
| 9792 MakePair(Failure::Exception(), NULL)); | 9737 MakePair(Failure::Exception(), NULL)); |
| 9793 return MakePair(*compiled, *receiver); | 9738 return MakePair(*compiled, *receiver); |
| 9794 } | 9739 } |
| 9795 | 9740 |
| 9796 | 9741 |
| 9797 RUNTIME_FUNCTION(ObjectPair, Runtime_ResolvePossiblyDirectEval) { | 9742 RUNTIME_FUNCTION(ObjectPair, Runtime_ResolvePossiblyDirectEval) { |
| 9798 HandleScope scope(isolate); | 9743 HandleScope scope(isolate); |
| 9799 ASSERT(args.length() == 5); | 9744 ASSERT(args.length() == 5); |
| 9800 | 9745 |
| 9801 Handle<Object> callee = args.at<Object>(0); | 9746 Handle<Object> callee = args.at<Object>(0); |
| 9802 | 9747 |
| 9803 // If "eval" didn't refer to the original GlobalEval, it's not a | 9748 // If "eval" didn't refer to the original GlobalEval, it's not a |
| 9804 // direct call to eval. | 9749 // direct call to eval. |
| 9805 // (And even if it is, but the first argument isn't a string, just let | 9750 // (And even if it is, but the first argument isn't a string, just let |
| 9806 // execution default to an indirect call to eval, which will also return | 9751 // execution default to an indirect call to eval, which will also return |
| 9807 // the first argument without doing anything). | 9752 // the first argument without doing anything). |
| 9808 if (*callee != isolate->native_context()->global_eval_fun() || | 9753 if (*callee != isolate->native_context()->global_eval_fun() || |
| 9809 !args[1]->IsString()) { | 9754 !args[1]->IsString()) { |
| 9810 return MakePair(*callee, isolate->heap()->undefined_value()); | 9755 return MakePair(*callee, isolate->heap()->undefined_value()); |
| 9811 } | 9756 } |
| 9812 | 9757 |
| 9813 CONVERT_LANGUAGE_MODE_ARG(language_mode, 3); | 9758 ASSERT(args[3]->IsSmi()); |
| 9759 ASSERT(args.smi_at(3) == SLOPPY || args.smi_at(3) == STRICT); |
| 9760 StrictMode strict_mode = static_cast<StrictMode>(args.smi_at(3)); |
| 9814 ASSERT(args[4]->IsSmi()); | 9761 ASSERT(args[4]->IsSmi()); |
| 9815 return CompileGlobalEval(isolate, | 9762 return CompileGlobalEval(isolate, |
| 9816 args.at<String>(1), | 9763 args.at<String>(1), |
| 9817 args.at<Object>(2), | 9764 args.at<Object>(2), |
| 9818 language_mode, | 9765 strict_mode, |
| 9819 args.smi_at(4)); | 9766 args.smi_at(4)); |
| 9820 } | 9767 } |
| 9821 | 9768 |
| 9822 | 9769 |
| 9823 // Allocate a block of memory in the given space (filled with a filler). | 9770 // Allocate a block of memory in the given space (filled with a filler). |
| 9824 // Used as a fall-back for generated code when the space is full. | 9771 // Used as a fall-back for generated code when the space is full. |
| 9825 static MaybeObject* Allocate(Isolate* isolate, | 9772 static MaybeObject* Allocate(Isolate* isolate, |
| 9826 int size, | 9773 int size, |
| 9827 bool double_align, | 9774 bool double_align, |
| 9828 AllocationSpace space) { | 9775 AllocationSpace space) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9873 RUNTIME_ASSERT(array->HasFastSmiOrObjectElements()); | 9820 RUNTIME_ASSERT(array->HasFastSmiOrObjectElements()); |
| 9874 int length = Smi::cast(array->length())->value(); | 9821 int length = Smi::cast(array->length())->value(); |
| 9875 FixedArray* elements = FixedArray::cast(array->elements()); | 9822 FixedArray* elements = FixedArray::cast(array->elements()); |
| 9876 for (int i = 0; i < length; i++) { | 9823 for (int i = 0; i < length; i++) { |
| 9877 if (elements->get(i) == *element) return isolate->heap()->false_value(); | 9824 if (elements->get(i) == *element) return isolate->heap()->false_value(); |
| 9878 } | 9825 } |
| 9879 | 9826 |
| 9880 // Strict not needed. Used for cycle detection in Array join implementation. | 9827 // Strict not needed. Used for cycle detection in Array join implementation. |
| 9881 RETURN_IF_EMPTY_HANDLE(isolate, JSObject::SetFastElement(array, length, | 9828 RETURN_IF_EMPTY_HANDLE(isolate, JSObject::SetFastElement(array, length, |
| 9882 element, | 9829 element, |
| 9883 kNonStrictMode, | 9830 SLOPPY, |
| 9884 true)); | 9831 true)); |
| 9885 return isolate->heap()->true_value(); | 9832 return isolate->heap()->true_value(); |
| 9886 } | 9833 } |
| 9887 | 9834 |
| 9888 | 9835 |
| 9889 /** | 9836 /** |
| 9890 * A simple visitor visits every element of Array's. | 9837 * A simple visitor visits every element of Array's. |
| 9891 * The backend storage can be a fixed array for fast elements case, | 9838 * The backend storage can be a fixed array for fast elements case, |
| 9892 * or a dictionary for sparse array. Since Dictionary is a subtype | 9839 * or a dictionary for sparse array. Since Dictionary is a subtype |
| 9893 * of FixedArray, the class can be used by both fast and slow cases. | 9840 * of FixedArray, the class can be used by both fast and slow cases. |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10058 SeededNumberDictionary::cast(array->elements())); | 10005 SeededNumberDictionary::cast(array->elements())); |
| 10059 int capacity = dictionary->Capacity(); | 10006 int capacity = dictionary->Capacity(); |
| 10060 for (int i = 0; i < capacity; i++) { | 10007 for (int i = 0; i < capacity; i++) { |
| 10061 Handle<Object> key(dictionary->KeyAt(i), array->GetIsolate()); | 10008 Handle<Object> key(dictionary->KeyAt(i), array->GetIsolate()); |
| 10062 if (dictionary->IsKey(*key)) { | 10009 if (dictionary->IsKey(*key)) { |
| 10063 element_count++; | 10010 element_count++; |
| 10064 } | 10011 } |
| 10065 } | 10012 } |
| 10066 break; | 10013 break; |
| 10067 } | 10014 } |
| 10068 case NON_STRICT_ARGUMENTS_ELEMENTS: | 10015 case SLOPPY_ARGUMENTS_ELEMENTS: |
| 10069 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ | 10016 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ |
| 10070 case EXTERNAL_##TYPE##_ELEMENTS: \ | 10017 case EXTERNAL_##TYPE##_ELEMENTS: \ |
| 10071 case TYPE##_ELEMENTS: \ | 10018 case TYPE##_ELEMENTS: \ |
| 10072 | 10019 |
| 10073 TYPED_ARRAYS(TYPED_ARRAY_CASE) | 10020 TYPED_ARRAYS(TYPED_ARRAY_CASE) |
| 10074 #undef TYPED_ARRAY_CASE | 10021 #undef TYPED_ARRAY_CASE |
| 10075 // External arrays are always dense. | 10022 // External arrays are always dense. |
| 10076 return length; | 10023 return length; |
| 10077 } | 10024 } |
| 10078 // As an estimate, we assume that the prototype doesn't contain any | 10025 // As an estimate, we assume that the prototype doesn't contain any |
| (...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10557 } | 10504 } |
| 10558 return string; | 10505 return string; |
| 10559 } | 10506 } |
| 10560 | 10507 |
| 10561 | 10508 |
| 10562 // Moves all own elements of an object, that are below a limit, to positions | 10509 // Moves all own elements of an object, that are below a limit, to positions |
| 10563 // starting at zero. All undefined values are placed after non-undefined values, | 10510 // starting at zero. All undefined values are placed after non-undefined values, |
| 10564 // and are followed by non-existing element. Does not change the length | 10511 // and are followed by non-existing element. Does not change the length |
| 10565 // property. | 10512 // property. |
| 10566 // Returns the number of non-undefined elements collected. | 10513 // Returns the number of non-undefined elements collected. |
| 10514 // Returns -1 if hole removal is not supported by this method. |
| 10567 RUNTIME_FUNCTION(MaybeObject*, Runtime_RemoveArrayHoles) { | 10515 RUNTIME_FUNCTION(MaybeObject*, Runtime_RemoveArrayHoles) { |
| 10568 HandleScope scope(isolate); | 10516 HandleScope scope(isolate); |
| 10569 ASSERT(args.length() == 2); | 10517 ASSERT(args.length() == 2); |
| 10570 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); | 10518 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); |
| 10571 CONVERT_NUMBER_CHECKED(uint32_t, limit, Uint32, args[1]); | 10519 CONVERT_NUMBER_CHECKED(uint32_t, limit, Uint32, args[1]); |
| 10572 return *JSObject::PrepareElementsForSort(object, limit); | 10520 return *JSObject::PrepareElementsForSort(object, limit); |
| 10573 } | 10521 } |
| 10574 | 10522 |
| 10575 | 10523 |
| 10576 // Move contents of argument 0 (an array) to argument 1 (an array) | 10524 // Move contents of argument 0 (an array) to argument 1 (an array) |
| (...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11345 // Add the value being returned. | 11293 // Add the value being returned. |
| 11346 if (at_return) { | 11294 if (at_return) { |
| 11347 details->set(details_index++, *return_value); | 11295 details->set(details_index++, *return_value); |
| 11348 } | 11296 } |
| 11349 | 11297 |
| 11350 // Add the receiver (same as in function frame). | 11298 // Add the receiver (same as in function frame). |
| 11351 // THIS MUST BE DONE LAST SINCE WE MIGHT ADVANCE | 11299 // THIS MUST BE DONE LAST SINCE WE MIGHT ADVANCE |
| 11352 // THE FRAME ITERATOR TO WRAP THE RECEIVER. | 11300 // THE FRAME ITERATOR TO WRAP THE RECEIVER. |
| 11353 Handle<Object> receiver(it.frame()->receiver(), isolate); | 11301 Handle<Object> receiver(it.frame()->receiver(), isolate); |
| 11354 if (!receiver->IsJSObject() && | 11302 if (!receiver->IsJSObject() && |
| 11355 shared->is_classic_mode() && | 11303 shared->strict_mode() == SLOPPY && |
| 11356 !function->IsBuiltin()) { | 11304 !function->IsBuiltin()) { |
| 11357 // If the receiver is not a JSObject and the function is not a | 11305 // If the receiver is not a JSObject and the function is not a |
| 11358 // builtin or strict-mode we have hit an optimization where a | 11306 // builtin or strict-mode we have hit an optimization where a |
| 11359 // value object is not converted into a wrapped JS objects. To | 11307 // value object is not converted into a wrapped JS objects. To |
| 11360 // hide this optimization from the debugger, we wrap the receiver | 11308 // hide this optimization from the debugger, we wrap the receiver |
| 11361 // by creating correct wrapper object based on the calling frame's | 11309 // by creating correct wrapper object based on the calling frame's |
| 11362 // native context. | 11310 // native context. |
| 11363 it.Advance(); | 11311 it.Advance(); |
| 11364 if (receiver->IsUndefined()) { | 11312 if (receiver->IsUndefined()) { |
| 11365 Context* context = function->context(); | 11313 Context* context = function->context(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11397 if (scope_info->ContextSlotIndex(*name, &mode, &init_flag) != -1) continue; | 11345 if (scope_info->ContextSlotIndex(*name, &mode, &init_flag) != -1) continue; |
| 11398 | 11346 |
| 11399 Handle<Object> value(i < frame_inspector->GetParametersCount() | 11347 Handle<Object> value(i < frame_inspector->GetParametersCount() |
| 11400 ? frame_inspector->GetParameter(i) | 11348 ? frame_inspector->GetParameter(i) |
| 11401 : isolate->heap()->undefined_value(), | 11349 : isolate->heap()->undefined_value(), |
| 11402 isolate); | 11350 isolate); |
| 11403 ASSERT(!value->IsTheHole()); | 11351 ASSERT(!value->IsTheHole()); |
| 11404 | 11352 |
| 11405 RETURN_IF_EMPTY_HANDLE_VALUE( | 11353 RETURN_IF_EMPTY_HANDLE_VALUE( |
| 11406 isolate, | 11354 isolate, |
| 11407 Runtime::SetObjectProperty( | 11355 Runtime::SetObjectProperty(isolate, target, name, value, NONE, SLOPPY), |
| 11408 isolate, target, name, value, NONE, kNonStrictMode), | |
| 11409 Handle<JSObject>()); | 11356 Handle<JSObject>()); |
| 11410 } | 11357 } |
| 11411 | 11358 |
| 11412 // Second fill all stack locals. | 11359 // Second fill all stack locals. |
| 11413 for (int i = 0; i < scope_info->StackLocalCount(); ++i) { | 11360 for (int i = 0; i < scope_info->StackLocalCount(); ++i) { |
| 11414 Handle<String> name(scope_info->StackLocalName(i)); | 11361 Handle<String> name(scope_info->StackLocalName(i)); |
| 11415 Handle<Object> value(frame_inspector->GetExpression(i), isolate); | 11362 Handle<Object> value(frame_inspector->GetExpression(i), isolate); |
| 11416 if (value->IsTheHole()) continue; | 11363 if (value->IsTheHole()) continue; |
| 11417 | 11364 |
| 11418 RETURN_IF_EMPTY_HANDLE_VALUE( | 11365 RETURN_IF_EMPTY_HANDLE_VALUE( |
| 11419 isolate, | 11366 isolate, |
| 11420 Runtime::SetObjectProperty( | 11367 Runtime::SetObjectProperty(isolate, target, name, value, NONE, SLOPPY), |
| 11421 isolate, target, name, value, NONE, kNonStrictMode), | |
| 11422 Handle<JSObject>()); | 11368 Handle<JSObject>()); |
| 11423 } | 11369 } |
| 11424 | 11370 |
| 11425 return target; | 11371 return target; |
| 11426 } | 11372 } |
| 11427 | 11373 |
| 11428 | 11374 |
| 11429 static void UpdateStackLocalsFromMaterializedObject(Isolate* isolate, | 11375 static void UpdateStackLocalsFromMaterializedObject(Isolate* isolate, |
| 11430 Handle<JSObject> target, | 11376 Handle<JSObject> target, |
| 11431 Handle<JSFunction> function, | 11377 Handle<JSFunction> function, |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11494 // Names of variables introduced by eval are strings. | 11440 // Names of variables introduced by eval are strings. |
| 11495 ASSERT(keys->get(i)->IsString()); | 11441 ASSERT(keys->get(i)->IsString()); |
| 11496 Handle<String> key(String::cast(keys->get(i))); | 11442 Handle<String> key(String::cast(keys->get(i))); |
| 11497 RETURN_IF_EMPTY_HANDLE_VALUE( | 11443 RETURN_IF_EMPTY_HANDLE_VALUE( |
| 11498 isolate, | 11444 isolate, |
| 11499 Runtime::SetObjectProperty(isolate, | 11445 Runtime::SetObjectProperty(isolate, |
| 11500 target, | 11446 target, |
| 11501 key, | 11447 key, |
| 11502 GetProperty(isolate, ext, key), | 11448 GetProperty(isolate, ext, key), |
| 11503 NONE, | 11449 NONE, |
| 11504 kNonStrictMode), | 11450 SLOPPY), |
| 11505 Handle<JSObject>()); | 11451 Handle<JSObject>()); |
| 11506 } | 11452 } |
| 11507 } | 11453 } |
| 11508 } | 11454 } |
| 11509 | 11455 |
| 11510 return target; | 11456 return target; |
| 11511 } | 11457 } |
| 11512 | 11458 |
| 11513 | 11459 |
| 11514 static Handle<JSObject> MaterializeLocalScope( | 11460 static Handle<JSObject> MaterializeLocalScope( |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11595 // Function context extension. These are variables introduced by eval. | 11541 // Function context extension. These are variables introduced by eval. |
| 11596 if (function_context->closure() == *function) { | 11542 if (function_context->closure() == *function) { |
| 11597 if (function_context->has_extension() && | 11543 if (function_context->has_extension() && |
| 11598 !function_context->IsNativeContext()) { | 11544 !function_context->IsNativeContext()) { |
| 11599 Handle<JSObject> ext(JSObject::cast(function_context->extension())); | 11545 Handle<JSObject> ext(JSObject::cast(function_context->extension())); |
| 11600 | 11546 |
| 11601 if (JSReceiver::HasProperty(ext, variable_name)) { | 11547 if (JSReceiver::HasProperty(ext, variable_name)) { |
| 11602 // We don't expect this to do anything except replacing | 11548 // We don't expect this to do anything except replacing |
| 11603 // property value. | 11549 // property value. |
| 11604 Runtime::SetObjectProperty(isolate, ext, variable_name, new_value, | 11550 Runtime::SetObjectProperty(isolate, ext, variable_name, new_value, |
| 11605 NONE, | 11551 NONE, SLOPPY); |
| 11606 kNonStrictMode); | |
| 11607 return true; | 11552 return true; |
| 11608 } | 11553 } |
| 11609 } | 11554 } |
| 11610 } | 11555 } |
| 11611 } | 11556 } |
| 11612 | 11557 |
| 11613 return default_result; | 11558 return default_result; |
| 11614 } | 11559 } |
| 11615 | 11560 |
| 11616 | 11561 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 11644 if (threw) return Handle<JSObject>(); | 11589 if (threw) return Handle<JSObject>(); |
| 11645 | 11590 |
| 11646 for (int i = 0; i < keys->length(); i++) { | 11591 for (int i = 0; i < keys->length(); i++) { |
| 11647 // Names of variables introduced by eval are strings. | 11592 // Names of variables introduced by eval are strings. |
| 11648 ASSERT(keys->get(i)->IsString()); | 11593 ASSERT(keys->get(i)->IsString()); |
| 11649 Handle<String> key(String::cast(keys->get(i))); | 11594 Handle<String> key(String::cast(keys->get(i))); |
| 11650 RETURN_IF_EMPTY_HANDLE_VALUE( | 11595 RETURN_IF_EMPTY_HANDLE_VALUE( |
| 11651 isolate, | 11596 isolate, |
| 11652 Runtime::SetObjectProperty(isolate, closure_scope, key, | 11597 Runtime::SetObjectProperty(isolate, closure_scope, key, |
| 11653 GetProperty(isolate, ext, key), | 11598 GetProperty(isolate, ext, key), |
| 11654 NONE, | 11599 NONE, SLOPPY), |
| 11655 kNonStrictMode), | |
| 11656 Handle<JSObject>()); | 11600 Handle<JSObject>()); |
| 11657 } | 11601 } |
| 11658 } | 11602 } |
| 11659 | 11603 |
| 11660 return closure_scope; | 11604 return closure_scope; |
| 11661 } | 11605 } |
| 11662 | 11606 |
| 11663 | 11607 |
| 11664 // This method copies structure of MaterializeClosure method above. | 11608 // This method copies structure of MaterializeClosure method above. |
| 11665 static bool SetClosureVariableValue(Isolate* isolate, | 11609 static bool SetClosureVariableValue(Isolate* isolate, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 11677 return true; | 11621 return true; |
| 11678 } | 11622 } |
| 11679 | 11623 |
| 11680 // Properties from the function context extension. This will | 11624 // Properties from the function context extension. This will |
| 11681 // be variables introduced by eval. | 11625 // be variables introduced by eval. |
| 11682 if (context->has_extension()) { | 11626 if (context->has_extension()) { |
| 11683 Handle<JSObject> ext(JSObject::cast(context->extension())); | 11627 Handle<JSObject> ext(JSObject::cast(context->extension())); |
| 11684 if (JSReceiver::HasProperty(ext, variable_name)) { | 11628 if (JSReceiver::HasProperty(ext, variable_name)) { |
| 11685 // We don't expect this to do anything except replacing property value. | 11629 // We don't expect this to do anything except replacing property value. |
| 11686 Runtime::SetObjectProperty(isolate, ext, variable_name, new_value, | 11630 Runtime::SetObjectProperty(isolate, ext, variable_name, new_value, |
| 11687 NONE, | 11631 NONE, SLOPPY); |
| 11688 kNonStrictMode); | |
| 11689 return true; | 11632 return true; |
| 11690 } | 11633 } |
| 11691 } | 11634 } |
| 11692 | 11635 |
| 11693 return false; | 11636 return false; |
| 11694 } | 11637 } |
| 11695 | 11638 |
| 11696 | 11639 |
| 11697 // Create a plain JSObject which materializes the scope for the specified | 11640 // Create a plain JSObject which materializes the scope for the specified |
| 11698 // catch context. | 11641 // catch context. |
| 11699 static Handle<JSObject> MaterializeCatchScope(Isolate* isolate, | 11642 static Handle<JSObject> MaterializeCatchScope(Isolate* isolate, |
| 11700 Handle<Context> context) { | 11643 Handle<Context> context) { |
| 11701 ASSERT(context->IsCatchContext()); | 11644 ASSERT(context->IsCatchContext()); |
| 11702 Handle<String> name(String::cast(context->extension())); | 11645 Handle<String> name(String::cast(context->extension())); |
| 11703 Handle<Object> thrown_object(context->get(Context::THROWN_OBJECT_INDEX), | 11646 Handle<Object> thrown_object(context->get(Context::THROWN_OBJECT_INDEX), |
| 11704 isolate); | 11647 isolate); |
| 11705 Handle<JSObject> catch_scope = | 11648 Handle<JSObject> catch_scope = |
| 11706 isolate->factory()->NewJSObject(isolate->object_function()); | 11649 isolate->factory()->NewJSObject(isolate->object_function()); |
| 11707 RETURN_IF_EMPTY_HANDLE_VALUE( | 11650 RETURN_IF_EMPTY_HANDLE_VALUE( |
| 11708 isolate, | 11651 isolate, |
| 11709 Runtime::SetObjectProperty(isolate, catch_scope, name, thrown_object, | 11652 Runtime::SetObjectProperty(isolate, catch_scope, name, thrown_object, |
| 11710 NONE, | 11653 NONE, SLOPPY), |
| 11711 kNonStrictMode), | |
| 11712 Handle<JSObject>()); | 11654 Handle<JSObject>()); |
| 11713 return catch_scope; | 11655 return catch_scope; |
| 11714 } | 11656 } |
| 11715 | 11657 |
| 11716 | 11658 |
| 11717 static bool SetCatchVariableValue(Isolate* isolate, | 11659 static bool SetCatchVariableValue(Isolate* isolate, |
| 11718 Handle<Context> context, | 11660 Handle<Context> context, |
| 11719 Handle<String> variable_name, | 11661 Handle<String> variable_name, |
| 11720 Handle<Object> new_value) { | 11662 Handle<Object> new_value) { |
| 11721 ASSERT(context->IsCatchContext()); | 11663 ASSERT(context->IsCatchContext()); |
| (...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12214 // If our frame is a top frame and we are stepping, we can do step-in | 12156 // If our frame is a top frame and we are stepping, we can do step-in |
| 12215 // at this place. | 12157 // at this place. |
| 12216 accept = additional_frame_it.frame()->id() == id; | 12158 accept = additional_frame_it.frame()->id() == id; |
| 12217 } | 12159 } |
| 12218 } | 12160 } |
| 12219 if (accept) { | 12161 if (accept) { |
| 12220 if (break_location_iterator.IsStepInLocation(isolate)) { | 12162 if (break_location_iterator.IsStepInLocation(isolate)) { |
| 12221 Smi* position_value = Smi::FromInt(break_location_iterator.position()); | 12163 Smi* position_value = Smi::FromInt(break_location_iterator.position()); |
| 12222 JSObject::SetElement(array, len, | 12164 JSObject::SetElement(array, len, |
| 12223 Handle<Object>(position_value, isolate), | 12165 Handle<Object>(position_value, isolate), |
| 12224 NONE, kNonStrictMode); | 12166 NONE, SLOPPY); |
| 12225 len++; | 12167 len++; |
| 12226 } | 12168 } |
| 12227 } | 12169 } |
| 12228 // Advance iterator. | 12170 // Advance iterator. |
| 12229 break_location_iterator.Next(); | 12171 break_location_iterator.Next(); |
| 12230 if (current_statement_pos != | 12172 if (current_statement_pos != |
| 12231 break_location_iterator.statement_position()) { | 12173 break_location_iterator.statement_position()) { |
| 12232 break; | 12174 break; |
| 12233 } | 12175 } |
| 12234 } | 12176 } |
| 12235 return *array; | 12177 return *array; |
| 12236 } | 12178 } |
| 12237 | 12179 |
| 12238 | 12180 |
| 12239 static const int kScopeDetailsTypeIndex = 0; | 12181 static const int kScopeDetailsTypeIndex = 0; |
| 12240 static const int kScopeDetailsObjectIndex = 1; | 12182 static const int kScopeDetailsObjectIndex = 1; |
| 12241 static const int kScopeDetailsSize = 2; | 12183 static const int kScopeDetailsSize = 2; |
| 12242 | 12184 |
| 12243 | 12185 |
| 12244 static MaybeObject* MaterializeScopeDetails(Isolate* isolate, | 12186 static Handle<JSObject> MaterializeScopeDetails(Isolate* isolate, |
| 12245 ScopeIterator* it) { | 12187 ScopeIterator* it) { |
| 12246 // Calculate the size of the result. | 12188 // Calculate the size of the result. |
| 12247 int details_size = kScopeDetailsSize; | 12189 int details_size = kScopeDetailsSize; |
| 12248 Handle<FixedArray> details = isolate->factory()->NewFixedArray(details_size); | 12190 Handle<FixedArray> details = isolate->factory()->NewFixedArray(details_size); |
| 12249 | 12191 |
| 12250 // Fill in scope details. | 12192 // Fill in scope details. |
| 12251 details->set(kScopeDetailsTypeIndex, Smi::FromInt(it->Type())); | 12193 details->set(kScopeDetailsTypeIndex, Smi::FromInt(it->Type())); |
| 12252 Handle<JSObject> scope_object = it->ScopeObject(); | 12194 Handle<JSObject> scope_object = it->ScopeObject(); |
| 12253 RETURN_IF_EMPTY_HANDLE(isolate, scope_object); | 12195 RETURN_IF_EMPTY_HANDLE_VALUE(isolate, scope_object, Handle<JSObject>()); |
| 12254 details->set(kScopeDetailsObjectIndex, *scope_object); | 12196 details->set(kScopeDetailsObjectIndex, *scope_object); |
| 12255 | 12197 |
| 12256 return *isolate->factory()->NewJSArrayWithElements(details); | 12198 return isolate->factory()->NewJSArrayWithElements(details); |
| 12257 } | 12199 } |
| 12258 | 12200 |
| 12259 | 12201 |
| 12260 // Return an array with scope details | 12202 // Return an array with scope details |
| 12261 // args[0]: number: break id | 12203 // args[0]: number: break id |
| 12262 // args[1]: number: frame index | 12204 // args[1]: number: frame index |
| 12263 // args[2]: number: inlined frame index | 12205 // args[2]: number: inlined frame index |
| 12264 // args[3]: number: scope index | 12206 // args[3]: number: scope index |
| 12265 // | 12207 // |
| 12266 // The array returned contains the following information: | 12208 // The array returned contains the following information: |
| (...skipping 20 matching lines...) Expand all Loading... |
| 12287 | 12229 |
| 12288 // Find the requested scope. | 12230 // Find the requested scope. |
| 12289 int n = 0; | 12231 int n = 0; |
| 12290 ScopeIterator it(isolate, frame, inlined_jsframe_index); | 12232 ScopeIterator it(isolate, frame, inlined_jsframe_index); |
| 12291 for (; !it.Done() && n < index; it.Next()) { | 12233 for (; !it.Done() && n < index; it.Next()) { |
| 12292 n++; | 12234 n++; |
| 12293 } | 12235 } |
| 12294 if (it.Done()) { | 12236 if (it.Done()) { |
| 12295 return isolate->heap()->undefined_value(); | 12237 return isolate->heap()->undefined_value(); |
| 12296 } | 12238 } |
| 12297 return MaterializeScopeDetails(isolate, &it); | 12239 Handle<JSObject> details = MaterializeScopeDetails(isolate, &it); |
| 12240 RETURN_IF_EMPTY_HANDLE(isolate, details); |
| 12241 return *details; |
| 12298 } | 12242 } |
| 12299 | 12243 |
| 12300 | 12244 |
| 12245 // Return an array of scope details |
| 12246 // args[0]: number: break id |
| 12247 // args[1]: number: frame index |
| 12248 // args[2]: number: inlined frame index |
| 12249 // |
| 12250 // The array returned contains arrays with the following information: |
| 12251 // 0: Scope type |
| 12252 // 1: Scope object |
| 12253 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetAllScopesDetails) { |
| 12254 HandleScope scope(isolate); |
| 12255 ASSERT(args.length() == 3); |
| 12256 |
| 12257 // Check arguments. |
| 12258 Object* check; |
| 12259 { MaybeObject* maybe_check = Runtime_CheckExecutionState( |
| 12260 RUNTIME_ARGUMENTS(isolate, args)); |
| 12261 if (!maybe_check->ToObject(&check)) return maybe_check; |
| 12262 } |
| 12263 CONVERT_SMI_ARG_CHECKED(wrapped_id, 1); |
| 12264 CONVERT_NUMBER_CHECKED(int, inlined_jsframe_index, Int32, args[2]); |
| 12265 |
| 12266 // Get the frame where the debugging is performed. |
| 12267 StackFrame::Id id = UnwrapFrameId(wrapped_id); |
| 12268 JavaScriptFrameIterator frame_it(isolate, id); |
| 12269 JavaScriptFrame* frame = frame_it.frame(); |
| 12270 |
| 12271 List<Handle<JSObject> > result(4); |
| 12272 ScopeIterator it(isolate, frame, inlined_jsframe_index); |
| 12273 for (; !it.Done(); it.Next()) { |
| 12274 Handle<JSObject> details = MaterializeScopeDetails(isolate, &it); |
| 12275 RETURN_IF_EMPTY_HANDLE(isolate, details); |
| 12276 result.Add(details); |
| 12277 } |
| 12278 |
| 12279 Handle<FixedArray> array = isolate->factory()->NewFixedArray(result.length()); |
| 12280 for (int i = 0; i < result.length(); ++i) { |
| 12281 array->set(i, *result[i]); |
| 12282 } |
| 12283 return *isolate->factory()->NewJSArrayWithElements(array); |
| 12284 } |
| 12285 |
| 12286 |
| 12301 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetFunctionScopeCount) { | 12287 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetFunctionScopeCount) { |
| 12302 HandleScope scope(isolate); | 12288 HandleScope scope(isolate); |
| 12303 ASSERT(args.length() == 1); | 12289 ASSERT(args.length() == 1); |
| 12304 | 12290 |
| 12305 // Check arguments. | 12291 // Check arguments. |
| 12306 CONVERT_ARG_HANDLE_CHECKED(JSFunction, fun, 0); | 12292 CONVERT_ARG_HANDLE_CHECKED(JSFunction, fun, 0); |
| 12307 | 12293 |
| 12308 // Count the visible scopes. | 12294 // Count the visible scopes. |
| 12309 int n = 0; | 12295 int n = 0; |
| 12310 for (ScopeIterator it(isolate, fun); !it.Done(); it.Next()) { | 12296 for (ScopeIterator it(isolate, fun); !it.Done(); it.Next()) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 12326 // Find the requested scope. | 12312 // Find the requested scope. |
| 12327 int n = 0; | 12313 int n = 0; |
| 12328 ScopeIterator it(isolate, fun); | 12314 ScopeIterator it(isolate, fun); |
| 12329 for (; !it.Done() && n < index; it.Next()) { | 12315 for (; !it.Done() && n < index; it.Next()) { |
| 12330 n++; | 12316 n++; |
| 12331 } | 12317 } |
| 12332 if (it.Done()) { | 12318 if (it.Done()) { |
| 12333 return isolate->heap()->undefined_value(); | 12319 return isolate->heap()->undefined_value(); |
| 12334 } | 12320 } |
| 12335 | 12321 |
| 12336 return MaterializeScopeDetails(isolate, &it); | 12322 Handle<JSObject> details = MaterializeScopeDetails(isolate, &it); |
| 12323 RETURN_IF_EMPTY_HANDLE(isolate, details); |
| 12324 return *details; |
| 12337 } | 12325 } |
| 12338 | 12326 |
| 12339 | 12327 |
| 12340 static bool SetScopeVariableValue(ScopeIterator* it, int index, | 12328 static bool SetScopeVariableValue(ScopeIterator* it, int index, |
| 12341 Handle<String> variable_name, | 12329 Handle<String> variable_name, |
| 12342 Handle<Object> new_value) { | 12330 Handle<Object> new_value) { |
| 12343 for (int n = 0; !it->Done() && n < index; it->Next()) { | 12331 for (int n = 0; !it->Done() && n < index; it->Next()) { |
| 12344 n++; | 12332 n++; |
| 12345 } | 12333 } |
| 12346 if (it->Done()) { | 12334 if (it->Done()) { |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12723 return target; | 12711 return target; |
| 12724 } | 12712 } |
| 12725 | 12713 |
| 12726 // FunctionGetArguments can't throw an exception. | 12714 // FunctionGetArguments can't throw an exception. |
| 12727 Handle<JSObject> arguments = Handle<JSObject>::cast( | 12715 Handle<JSObject> arguments = Handle<JSObject>::cast( |
| 12728 Accessors::FunctionGetArguments(function)); | 12716 Accessors::FunctionGetArguments(function)); |
| 12729 Runtime::SetObjectProperty(isolate, target, | 12717 Runtime::SetObjectProperty(isolate, target, |
| 12730 isolate->factory()->arguments_string(), | 12718 isolate->factory()->arguments_string(), |
| 12731 arguments, | 12719 arguments, |
| 12732 ::NONE, | 12720 ::NONE, |
| 12733 kNonStrictMode); | 12721 SLOPPY); |
| 12734 return target; | 12722 return target; |
| 12735 } | 12723 } |
| 12736 | 12724 |
| 12737 | 12725 |
| 12738 // Compile and evaluate source for the given context. | 12726 // Compile and evaluate source for the given context. |
| 12739 static MaybeObject* DebugEvaluate(Isolate* isolate, | 12727 static MaybeObject* DebugEvaluate(Isolate* isolate, |
| 12740 Handle<Context> context, | 12728 Handle<Context> context, |
| 12741 Handle<Object> context_extension, | 12729 Handle<Object> context_extension, |
| 12742 Handle<Object> receiver, | 12730 Handle<Object> receiver, |
| 12743 Handle<String> source) { | 12731 Handle<String> source) { |
| 12744 if (context_extension->IsJSObject()) { | 12732 if (context_extension->IsJSObject()) { |
| 12745 Handle<JSObject> extension = Handle<JSObject>::cast(context_extension); | 12733 Handle<JSObject> extension = Handle<JSObject>::cast(context_extension); |
| 12746 Handle<JSFunction> closure(context->closure(), isolate); | 12734 Handle<JSFunction> closure(context->closure(), isolate); |
| 12747 context = isolate->factory()->NewWithContext(closure, context, extension); | 12735 context = isolate->factory()->NewWithContext(closure, context, extension); |
| 12748 } | 12736 } |
| 12749 | 12737 |
| 12750 Handle<JSFunction> eval_fun = | 12738 Handle<JSFunction> eval_fun = |
| 12751 Compiler::GetFunctionFromEval(source, | 12739 Compiler::GetFunctionFromEval(source, |
| 12752 context, | 12740 context, |
| 12753 CLASSIC_MODE, | 12741 SLOPPY, |
| 12754 NO_PARSE_RESTRICTION, | 12742 NO_PARSE_RESTRICTION, |
| 12755 RelocInfo::kNoPosition); | 12743 RelocInfo::kNoPosition); |
| 12756 RETURN_IF_EMPTY_HANDLE(isolate, eval_fun); | 12744 RETURN_IF_EMPTY_HANDLE(isolate, eval_fun); |
| 12757 | 12745 |
| 12758 bool pending_exception; | 12746 bool pending_exception; |
| 12759 Handle<Object> result = Execution::Call( | 12747 Handle<Object> result = Execution::Call( |
| 12760 isolate, eval_fun, receiver, 0, NULL, &pending_exception); | 12748 isolate, eval_fun, receiver, 0, NULL, &pending_exception); |
| 12761 | 12749 |
| 12762 if (pending_exception) return Failure::Exception(); | 12750 if (pending_exception) return Failure::Exception(); |
| 12763 | 12751 |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13001 CONVERT_ARG_CHECKED(JSObject, target, 0); | 12989 CONVERT_ARG_CHECKED(JSObject, target, 0); |
| 13002 Object* instance_filter = args[1]; | 12990 Object* instance_filter = args[1]; |
| 13003 RUNTIME_ASSERT(instance_filter->IsUndefined() || | 12991 RUNTIME_ASSERT(instance_filter->IsUndefined() || |
| 13004 instance_filter->IsJSObject()); | 12992 instance_filter->IsJSObject()); |
| 13005 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[2]); | 12993 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[2]); |
| 13006 RUNTIME_ASSERT(max_references >= 0); | 12994 RUNTIME_ASSERT(max_references >= 0); |
| 13007 | 12995 |
| 13008 | 12996 |
| 13009 // Get the constructor function for context extension and arguments array. | 12997 // Get the constructor function for context extension and arguments array. |
| 13010 JSObject* arguments_boilerplate = | 12998 JSObject* arguments_boilerplate = |
| 13011 isolate->context()->native_context()->arguments_boilerplate(); | 12999 isolate->context()->native_context()->sloppy_arguments_boilerplate(); |
| 13012 JSFunction* arguments_function = | 13000 JSFunction* arguments_function = |
| 13013 JSFunction::cast(arguments_boilerplate->map()->constructor()); | 13001 JSFunction::cast(arguments_boilerplate->map()->constructor()); |
| 13014 | 13002 |
| 13015 // Get the number of referencing objects. | 13003 // Get the number of referencing objects. |
| 13016 int count; | 13004 int count; |
| 13017 Heap* heap = isolate->heap(); | 13005 Heap* heap = isolate->heap(); |
| 13018 HeapIterator heap_iterator(heap); | 13006 HeapIterator heap_iterator(heap); |
| 13019 count = DebugReferencedBy(&heap_iterator, | 13007 count = DebugReferencedBy(&heap_iterator, |
| 13020 target, instance_filter, max_references, | 13008 target, instance_filter, max_references, |
| 13021 NULL, 0, arguments_function); | 13009 NULL, 0, arguments_function); |
| (...skipping 1499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14521 | 14509 |
| 14522 #ifdef DEBUG | 14510 #ifdef DEBUG |
| 14523 // ListNatives is ONLY used by the fuzz-natives.js in debug mode | 14511 // ListNatives is ONLY used by the fuzz-natives.js in debug mode |
| 14524 // Exclude the code in release mode. | 14512 // Exclude the code in release mode. |
| 14525 RUNTIME_FUNCTION(MaybeObject*, Runtime_ListNatives) { | 14513 RUNTIME_FUNCTION(MaybeObject*, Runtime_ListNatives) { |
| 14526 HandleScope scope(isolate); | 14514 HandleScope scope(isolate); |
| 14527 ASSERT(args.length() == 0); | 14515 ASSERT(args.length() == 0); |
| 14528 #define COUNT_ENTRY(Name, argc, ressize) + 1 | 14516 #define COUNT_ENTRY(Name, argc, ressize) + 1 |
| 14529 int entry_count = 0 | 14517 int entry_count = 0 |
| 14530 RUNTIME_FUNCTION_LIST(COUNT_ENTRY) | 14518 RUNTIME_FUNCTION_LIST(COUNT_ENTRY) |
| 14531 INLINE_FUNCTION_LIST(COUNT_ENTRY) | 14519 INLINE_FUNCTION_LIST(COUNT_ENTRY); |
| 14532 INLINE_RUNTIME_FUNCTION_LIST(COUNT_ENTRY); | |
| 14533 #undef COUNT_ENTRY | 14520 #undef COUNT_ENTRY |
| 14534 Factory* factory = isolate->factory(); | 14521 Factory* factory = isolate->factory(); |
| 14535 Handle<FixedArray> elements = factory->NewFixedArray(entry_count); | 14522 Handle<FixedArray> elements = factory->NewFixedArray(entry_count); |
| 14536 int index = 0; | 14523 int index = 0; |
| 14537 bool inline_runtime_functions = false; | 14524 bool inline_runtime_functions = false; |
| 14538 #define ADD_ENTRY(Name, argc, ressize) \ | 14525 #define ADD_ENTRY(Name, argc, ressize) \ |
| 14539 { \ | 14526 { \ |
| 14540 HandleScope inner(isolate); \ | 14527 HandleScope inner(isolate); \ |
| 14541 Handle<String> name; \ | 14528 Handle<String> name; \ |
| 14542 /* Inline runtime functions have an underscore in front of the name. */ \ | 14529 /* Inline runtime functions have an underscore in front of the name. */ \ |
| 14543 if (inline_runtime_functions) { \ | 14530 if (inline_runtime_functions) { \ |
| 14544 name = factory->NewStringFromAscii( \ | 14531 name = factory->NewStringFromAscii( \ |
| 14545 Vector<const char>("_" #Name, StrLength("_" #Name))); \ | 14532 Vector<const char>("_" #Name, StrLength("_" #Name))); \ |
| 14546 } else { \ | 14533 } else { \ |
| 14547 name = factory->NewStringFromAscii( \ | 14534 name = factory->NewStringFromAscii( \ |
| 14548 Vector<const char>(#Name, StrLength(#Name))); \ | 14535 Vector<const char>(#Name, StrLength(#Name))); \ |
| 14549 } \ | 14536 } \ |
| 14550 Handle<FixedArray> pair_elements = factory->NewFixedArray(2); \ | 14537 Handle<FixedArray> pair_elements = factory->NewFixedArray(2); \ |
| 14551 pair_elements->set(0, *name); \ | 14538 pair_elements->set(0, *name); \ |
| 14552 pair_elements->set(1, Smi::FromInt(argc)); \ | 14539 pair_elements->set(1, Smi::FromInt(argc)); \ |
| 14553 Handle<JSArray> pair = factory->NewJSArrayWithElements(pair_elements); \ | 14540 Handle<JSArray> pair = factory->NewJSArrayWithElements(pair_elements); \ |
| 14554 elements->set(index++, *pair); \ | 14541 elements->set(index++, *pair); \ |
| 14555 } | 14542 } |
| 14556 inline_runtime_functions = false; | 14543 inline_runtime_functions = false; |
| 14557 RUNTIME_FUNCTION_LIST(ADD_ENTRY) | 14544 RUNTIME_FUNCTION_LIST(ADD_ENTRY) |
| 14558 inline_runtime_functions = true; | 14545 inline_runtime_functions = true; |
| 14559 INLINE_FUNCTION_LIST(ADD_ENTRY) | 14546 INLINE_FUNCTION_LIST(ADD_ENTRY) |
| 14560 INLINE_RUNTIME_FUNCTION_LIST(ADD_ENTRY) | |
| 14561 #undef ADD_ENTRY | 14547 #undef ADD_ENTRY |
| 14562 ASSERT_EQ(index, entry_count); | 14548 ASSERT_EQ(index, entry_count); |
| 14563 Handle<JSArray> result = factory->NewJSArrayWithElements(elements); | 14549 Handle<JSArray> result = factory->NewJSArrayWithElements(elements); |
| 14564 return *result; | 14550 return *result; |
| 14565 } | 14551 } |
| 14566 #endif | 14552 #endif |
| 14567 | 14553 |
| 14568 | 14554 |
| 14569 RUNTIME_FUNCTION(MaybeObject*, Runtime_Log) { | 14555 RUNTIME_FUNCTION(MaybeObject*, Runtime_Log) { |
| 14570 SealHandleScope shs(isolate); | 14556 SealHandleScope shs(isolate); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 14591 CONVERT_ARG_CHECKED(JSObject, obj, 0); \ | 14577 CONVERT_ARG_CHECKED(JSObject, obj, 0); \ |
| 14592 return isolate->heap()->ToBoolean(obj->Has##Name()); \ | 14578 return isolate->heap()->ToBoolean(obj->Has##Name()); \ |
| 14593 } | 14579 } |
| 14594 | 14580 |
| 14595 ELEMENTS_KIND_CHECK_RUNTIME_FUNCTION(FastSmiElements) | 14581 ELEMENTS_KIND_CHECK_RUNTIME_FUNCTION(FastSmiElements) |
| 14596 ELEMENTS_KIND_CHECK_RUNTIME_FUNCTION(FastObjectElements) | 14582 ELEMENTS_KIND_CHECK_RUNTIME_FUNCTION(FastObjectElements) |
| 14597 ELEMENTS_KIND_CHECK_RUNTIME_FUNCTION(FastSmiOrObjectElements) | 14583 ELEMENTS_KIND_CHECK_RUNTIME_FUNCTION(FastSmiOrObjectElements) |
| 14598 ELEMENTS_KIND_CHECK_RUNTIME_FUNCTION(FastDoubleElements) | 14584 ELEMENTS_KIND_CHECK_RUNTIME_FUNCTION(FastDoubleElements) |
| 14599 ELEMENTS_KIND_CHECK_RUNTIME_FUNCTION(FastHoleyElements) | 14585 ELEMENTS_KIND_CHECK_RUNTIME_FUNCTION(FastHoleyElements) |
| 14600 ELEMENTS_KIND_CHECK_RUNTIME_FUNCTION(DictionaryElements) | 14586 ELEMENTS_KIND_CHECK_RUNTIME_FUNCTION(DictionaryElements) |
| 14601 ELEMENTS_KIND_CHECK_RUNTIME_FUNCTION(NonStrictArgumentsElements) | 14587 ELEMENTS_KIND_CHECK_RUNTIME_FUNCTION(SloppyArgumentsElements) |
| 14602 ELEMENTS_KIND_CHECK_RUNTIME_FUNCTION(ExternalArrayElements) | 14588 ELEMENTS_KIND_CHECK_RUNTIME_FUNCTION(ExternalArrayElements) |
| 14603 // Properties test sitting with elements tests - not fooling anyone. | 14589 // Properties test sitting with elements tests - not fooling anyone. |
| 14604 ELEMENTS_KIND_CHECK_RUNTIME_FUNCTION(FastProperties) | 14590 ELEMENTS_KIND_CHECK_RUNTIME_FUNCTION(FastProperties) |
| 14605 | 14591 |
| 14606 #undef ELEMENTS_KIND_CHECK_RUNTIME_FUNCTION | 14592 #undef ELEMENTS_KIND_CHECK_RUNTIME_FUNCTION |
| 14607 | 14593 |
| 14608 | 14594 |
| 14609 #define TYPED_ARRAYS_CHECK_RUNTIME_FUNCTION(Type, type, TYPE, ctype, size) \ | 14595 #define TYPED_ARRAYS_CHECK_RUNTIME_FUNCTION(Type, type, TYPE, ctype, size) \ |
| 14610 RUNTIME_FUNCTION(MaybeObject*, Runtime_HasExternal##Type##Elements) { \ | 14596 RUNTIME_FUNCTION(MaybeObject*, Runtime_HasExternal##Type##Elements) { \ |
| 14611 CONVERT_ARG_CHECKED(JSObject, obj, 0); \ | 14597 CONVERT_ARG_CHECKED(JSObject, obj, 0); \ |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14728 } | 14714 } |
| 14729 return object; | 14715 return object; |
| 14730 } | 14716 } |
| 14731 | 14717 |
| 14732 | 14718 |
| 14733 RUNTIME_FUNCTION(MaybeObject*, Runtime_IsAccessAllowedForObserver) { | 14719 RUNTIME_FUNCTION(MaybeObject*, Runtime_IsAccessAllowedForObserver) { |
| 14734 HandleScope scope(isolate); | 14720 HandleScope scope(isolate); |
| 14735 ASSERT(args.length() == 3); | 14721 ASSERT(args.length() == 3); |
| 14736 CONVERT_ARG_HANDLE_CHECKED(JSFunction, observer, 0); | 14722 CONVERT_ARG_HANDLE_CHECKED(JSFunction, observer, 0); |
| 14737 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 1); | 14723 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 1); |
| 14738 ASSERT(object->IsAccessCheckNeeded()); | 14724 ASSERT(object->map()->is_access_check_needed()); |
| 14739 Handle<Object> key = args.at<Object>(2); | 14725 Handle<Object> key = args.at<Object>(2); |
| 14740 SaveContext save(isolate); | 14726 SaveContext save(isolate); |
| 14741 isolate->set_context(observer->context()); | 14727 isolate->set_context(observer->context()); |
| 14742 if (!isolate->MayNamedAccess(*object, isolate->heap()->undefined_value(), | 14728 if (!isolate->MayNamedAccessWrapper(object, |
| 14743 v8::ACCESS_KEYS)) { | 14729 isolate->factory()->undefined_value(), |
| 14730 v8::ACCESS_KEYS)) { |
| 14744 return isolate->heap()->false_value(); | 14731 return isolate->heap()->false_value(); |
| 14745 } | 14732 } |
| 14746 bool access_allowed = false; | 14733 bool access_allowed = false; |
| 14747 uint32_t index = 0; | 14734 uint32_t index = 0; |
| 14748 if (key->ToArrayIndex(&index) || | 14735 if (key->ToArrayIndex(&index) || |
| 14749 (key->IsString() && String::cast(*key)->AsArrayIndex(&index))) { | 14736 (key->IsString() && String::cast(*key)->AsArrayIndex(&index))) { |
| 14750 access_allowed = | 14737 access_allowed = |
| 14751 isolate->MayIndexedAccess(*object, index, v8::ACCESS_GET) && | 14738 isolate->MayIndexedAccessWrapper(object, index, v8::ACCESS_GET) && |
| 14752 isolate->MayIndexedAccess(*object, index, v8::ACCESS_HAS); | 14739 isolate->MayIndexedAccessWrapper(object, index, v8::ACCESS_HAS); |
| 14753 } else { | 14740 } else { |
| 14754 access_allowed = isolate->MayNamedAccess(*object, *key, v8::ACCESS_GET) && | 14741 access_allowed = |
| 14755 isolate->MayNamedAccess(*object, *key, v8::ACCESS_HAS); | 14742 isolate->MayNamedAccessWrapper(object, key, v8::ACCESS_GET) && |
| 14743 isolate->MayNamedAccessWrapper(object, key, v8::ACCESS_HAS); |
| 14756 } | 14744 } |
| 14757 return isolate->heap()->ToBoolean(access_allowed); | 14745 return isolate->heap()->ToBoolean(access_allowed); |
| 14758 } | 14746 } |
| 14759 | 14747 |
| 14760 | 14748 |
| 14761 static MaybeObject* ArrayConstructorCommon(Isolate* isolate, | 14749 static MaybeObject* ArrayConstructorCommon(Isolate* isolate, |
| 14762 Handle<JSFunction> constructor, | 14750 Handle<JSFunction> constructor, |
| 14763 Handle<AllocationSite> site, | 14751 Handle<AllocationSite> site, |
| 14764 Arguments* caller_args) { | 14752 Arguments* caller_args) { |
| 14765 bool holey = false; | 14753 bool holey = false; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 14783 JSArray* array; | 14771 JSArray* array; |
| 14784 MaybeObject* maybe_array; | 14772 MaybeObject* maybe_array; |
| 14785 if (!site.is_null() && can_use_type_feedback) { | 14773 if (!site.is_null() && can_use_type_feedback) { |
| 14786 ElementsKind to_kind = site->GetElementsKind(); | 14774 ElementsKind to_kind = site->GetElementsKind(); |
| 14787 if (holey && !IsFastHoleyElementsKind(to_kind)) { | 14775 if (holey && !IsFastHoleyElementsKind(to_kind)) { |
| 14788 to_kind = GetHoleyElementsKind(to_kind); | 14776 to_kind = GetHoleyElementsKind(to_kind); |
| 14789 // Update the allocation site info to reflect the advice alteration. | 14777 // Update the allocation site info to reflect the advice alteration. |
| 14790 site->SetElementsKind(to_kind); | 14778 site->SetElementsKind(to_kind); |
| 14791 } | 14779 } |
| 14792 | 14780 |
| 14793 maybe_array = isolate->heap()->AllocateJSObjectWithAllocationSite( | 14781 // We should allocate with an initial map that reflects the allocation site |
| 14794 *constructor, site); | 14782 // advice. Therefore we use AllocateJSObjectFromMap instead of passing |
| 14783 // the constructor. |
| 14784 Map* initial_map = constructor->initial_map(); |
| 14785 if (to_kind != initial_map->elements_kind()) { |
| 14786 MaybeObject* maybe_new_map = initial_map->AsElementsKind(to_kind); |
| 14787 if (!maybe_new_map->To(&initial_map)) return maybe_new_map; |
| 14788 } |
| 14789 |
| 14790 // If we don't care to track arrays of to_kind ElementsKind, then |
| 14791 // don't emit a memento for them. |
| 14792 AllocationSite* allocation_site = |
| 14793 (AllocationSite::GetMode(to_kind) == TRACK_ALLOCATION_SITE) |
| 14794 ? *site |
| 14795 : NULL; |
| 14796 |
| 14797 maybe_array = isolate->heap()->AllocateJSObjectFromMap(initial_map, |
| 14798 NOT_TENURED, |
| 14799 true, |
| 14800 allocation_site); |
| 14795 if (!maybe_array->To(&array)) return maybe_array; | 14801 if (!maybe_array->To(&array)) return maybe_array; |
| 14796 } else { | 14802 } else { |
| 14797 maybe_array = isolate->heap()->AllocateJSObject(*constructor); | 14803 maybe_array = isolate->heap()->AllocateJSObject(*constructor); |
| 14798 if (!maybe_array->To(&array)) return maybe_array; | 14804 if (!maybe_array->To(&array)) return maybe_array; |
| 14799 // We might need to transition to holey | 14805 // We might need to transition to holey |
| 14800 ElementsKind kind = constructor->initial_map()->elements_kind(); | 14806 ElementsKind kind = constructor->initial_map()->elements_kind(); |
| 14801 if (holey && !IsFastHoleyElementsKind(kind)) { | 14807 if (holey && !IsFastHoleyElementsKind(kind)) { |
| 14802 kind = GetHoleyElementsKind(kind); | 14808 kind = GetHoleyElementsKind(kind); |
| 14803 maybe_array = array->TransitionElementsKind(kind); | 14809 maybe_array = array->TransitionElementsKind(kind); |
| 14804 if (maybe_array->IsFailure()) return maybe_array; | 14810 if (maybe_array->IsFailure()) return maybe_array; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14841 CONVERT_ARG_HANDLE_CHECKED(Object, type_info, parameters_start + 1); | 14847 CONVERT_ARG_HANDLE_CHECKED(Object, type_info, parameters_start + 1); |
| 14842 #ifdef DEBUG | 14848 #ifdef DEBUG |
| 14843 if (!no_caller_args) { | 14849 if (!no_caller_args) { |
| 14844 CONVERT_SMI_ARG_CHECKED(arg_count, parameters_start + 2); | 14850 CONVERT_SMI_ARG_CHECKED(arg_count, parameters_start + 2); |
| 14845 ASSERT(arg_count == caller_args->length()); | 14851 ASSERT(arg_count == caller_args->length()); |
| 14846 } | 14852 } |
| 14847 #endif | 14853 #endif |
| 14848 | 14854 |
| 14849 Handle<AllocationSite> site; | 14855 Handle<AllocationSite> site; |
| 14850 if (!type_info.is_null() && | 14856 if (!type_info.is_null() && |
| 14851 *type_info != isolate->heap()->undefined_value()) { | 14857 !type_info.is_identical_to( |
| 14858 TypeFeedbackInfo::MegamorphicSentinel(isolate))) { |
| 14852 site = Handle<AllocationSite>::cast(type_info); | 14859 site = Handle<AllocationSite>::cast(type_info); |
| 14853 ASSERT(!site->SitePointsToLiteral()); | 14860 ASSERT(!site->SitePointsToLiteral()); |
| 14854 } | 14861 } |
| 14855 | 14862 |
| 14856 return ArrayConstructorCommon(isolate, | 14863 return ArrayConstructorCommon(isolate, |
| 14857 constructor, | 14864 constructor, |
| 14858 site, | 14865 site, |
| 14859 caller_args); | 14866 caller_args); |
| 14860 } | 14867 } |
| 14861 | 14868 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14896 FUNCTION_ADDR(Runtime_##name), number_of_args, result_size }, | 14903 FUNCTION_ADDR(Runtime_##name), number_of_args, result_size }, |
| 14897 | 14904 |
| 14898 | 14905 |
| 14899 #define I(name, number_of_args, result_size) \ | 14906 #define I(name, number_of_args, result_size) \ |
| 14900 { Runtime::kInline##name, Runtime::INLINE, \ | 14907 { Runtime::kInline##name, Runtime::INLINE, \ |
| 14901 "_" #name, NULL, number_of_args, result_size }, | 14908 "_" #name, NULL, number_of_args, result_size }, |
| 14902 | 14909 |
| 14903 static const Runtime::Function kIntrinsicFunctions[] = { | 14910 static const Runtime::Function kIntrinsicFunctions[] = { |
| 14904 RUNTIME_FUNCTION_LIST(F) | 14911 RUNTIME_FUNCTION_LIST(F) |
| 14905 INLINE_FUNCTION_LIST(I) | 14912 INLINE_FUNCTION_LIST(I) |
| 14906 INLINE_RUNTIME_FUNCTION_LIST(I) | |
| 14907 }; | 14913 }; |
| 14908 | 14914 |
| 14915 #undef I |
| 14916 #undef F |
| 14917 |
| 14909 | 14918 |
| 14910 MaybeObject* Runtime::InitializeIntrinsicFunctionNames(Heap* heap, | 14919 MaybeObject* Runtime::InitializeIntrinsicFunctionNames(Heap* heap, |
| 14911 Object* dictionary) { | 14920 Object* dictionary) { |
| 14912 ASSERT(dictionary != NULL); | 14921 ASSERT(dictionary != NULL); |
| 14913 ASSERT(NameDictionary::cast(dictionary)->NumberOfElements() == 0); | 14922 ASSERT(NameDictionary::cast(dictionary)->NumberOfElements() == 0); |
| 14914 for (int i = 0; i < kNumFunctions; ++i) { | 14923 for (int i = 0; i < kNumFunctions; ++i) { |
| 14915 Object* name_string; | 14924 Object* name_string; |
| 14916 { MaybeObject* maybe_name_string = | 14925 { MaybeObject* maybe_name_string = |
| 14917 heap->InternalizeUtf8String(kIntrinsicFunctions[i].name); | 14926 heap->InternalizeUtf8String(kIntrinsicFunctions[i].name); |
| 14918 if (!maybe_name_string->ToObject(&name_string)) return maybe_name_string; | 14927 if (!maybe_name_string->ToObject(&name_string)) return maybe_name_string; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14965 // Handle last resort GC and make sure to allow future allocations | 14974 // Handle last resort GC and make sure to allow future allocations |
| 14966 // to grow the heap without causing GCs (if possible). | 14975 // to grow the heap without causing GCs (if possible). |
| 14967 isolate->counters()->gc_last_resort_from_js()->Increment(); | 14976 isolate->counters()->gc_last_resort_from_js()->Increment(); |
| 14968 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 14977 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
| 14969 "Runtime::PerformGC"); | 14978 "Runtime::PerformGC"); |
| 14970 } | 14979 } |
| 14971 } | 14980 } |
| 14972 | 14981 |
| 14973 | 14982 |
| 14974 } } // namespace v8::internal | 14983 } } // namespace v8::internal |
| OLD | NEW |