OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // Review notes: | 5 // Review notes: |
6 // | 6 // |
7 // - The use of macros in these inline functions may seem superfluous | 7 // - The use of macros in these inline functions may seem superfluous |
8 // but it is absolutely needed to make sure gcc generates optimal | 8 // but it is absolutely needed to make sure gcc generates optimal |
9 // code. gcc is not happy when attempting to inline too deep. | 9 // code. gcc is not happy when attempting to inline too deep. |
10 // | 10 // |
(...skipping 1153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1164 MaybeHandle<Object> Object::GetProperty(Handle<Object> object, | 1164 MaybeHandle<Object> Object::GetProperty(Handle<Object> object, |
1165 Handle<Name> name) { | 1165 Handle<Name> name) { |
1166 LookupIterator it(object, name); | 1166 LookupIterator it(object, name); |
1167 return GetProperty(&it); | 1167 return GetProperty(&it); |
1168 } | 1168 } |
1169 | 1169 |
1170 | 1170 |
1171 MaybeHandle<Object> Object::GetElement(Isolate* isolate, | 1171 MaybeHandle<Object> Object::GetElement(Isolate* isolate, |
1172 Handle<Object> object, | 1172 Handle<Object> object, |
1173 uint32_t index) { | 1173 uint32_t index) { |
1174 // GetElement can trigger a getter which can cause allocation. | 1174 LookupIterator it(isolate, object, index); |
1175 // This was not always the case. This DCHECK is here to catch | 1175 return GetProperty(&it); |
1176 // leftover incorrect uses. | |
1177 DCHECK(AllowHeapAllocation::IsAllowed()); | |
1178 return Object::GetElementWithReceiver(isolate, object, object, index); | |
1179 } | 1176 } |
1180 | 1177 |
1181 | 1178 |
1182 Handle<Object> Object::GetPrototypeSkipHiddenPrototypes( | 1179 Handle<Object> Object::GetPrototypeSkipHiddenPrototypes( |
1183 Isolate* isolate, Handle<Object> receiver) { | 1180 Isolate* isolate, Handle<Object> receiver) { |
1184 PrototypeIterator iter(isolate, receiver); | 1181 PrototypeIterator iter(isolate, receiver); |
1185 while (!iter.IsAtEnd(PrototypeIterator::END_AT_NON_HIDDEN)) { | 1182 while (!iter.IsAtEnd(PrototypeIterator::END_AT_NON_HIDDEN)) { |
1186 if (PrototypeIterator::GetCurrent(iter)->IsJSProxy()) { | 1183 if (PrototypeIterator::GetCurrent(iter)->IsJSProxy()) { |
1187 return PrototypeIterator::GetCurrent(iter); | 1184 return PrototypeIterator::GetCurrent(iter); |
1188 } | 1185 } |
(...skipping 18 matching lines...) Expand all Loading... |
1207 Handle<String> str = isolate->factory()->InternalizeUtf8String(name); | 1204 Handle<String> str = isolate->factory()->InternalizeUtf8String(name); |
1208 DCHECK(!str.is_null()); | 1205 DCHECK(!str.is_null()); |
1209 #ifdef DEBUG | 1206 #ifdef DEBUG |
1210 uint32_t index; // Assert that the name is not an array index. | 1207 uint32_t index; // Assert that the name is not an array index. |
1211 DCHECK(!str->AsArrayIndex(&index)); | 1208 DCHECK(!str->AsArrayIndex(&index)); |
1212 #endif // DEBUG | 1209 #endif // DEBUG |
1213 return GetProperty(object, str); | 1210 return GetProperty(object, str); |
1214 } | 1211 } |
1215 | 1212 |
1216 | 1213 |
1217 MaybeHandle<Object> JSProxy::GetElementWithHandler(Handle<JSProxy> proxy, | |
1218 Handle<Object> receiver, | |
1219 uint32_t index) { | |
1220 return GetPropertyWithHandler( | |
1221 proxy, receiver, proxy->GetIsolate()->factory()->Uint32ToString(index)); | |
1222 } | |
1223 | |
1224 | |
1225 MaybeHandle<Object> JSProxy::SetElementWithHandler(Handle<JSProxy> proxy, | 1214 MaybeHandle<Object> JSProxy::SetElementWithHandler(Handle<JSProxy> proxy, |
1226 Handle<JSReceiver> receiver, | 1215 Handle<JSReceiver> receiver, |
1227 uint32_t index, | 1216 uint32_t index, |
1228 Handle<Object> value, | 1217 Handle<Object> value, |
1229 LanguageMode language_mode) { | 1218 LanguageMode language_mode) { |
1230 Isolate* isolate = proxy->GetIsolate(); | 1219 Isolate* isolate = proxy->GetIsolate(); |
1231 Handle<String> name = isolate->factory()->Uint32ToString(index); | 1220 Handle<String> name = isolate->factory()->Uint32ToString(index); |
1232 return SetPropertyWithHandler(proxy, receiver, name, value, language_mode); | 1221 return SetPropertyWithHandler(proxy, receiver, name, value, language_mode); |
1233 } | 1222 } |
1234 | 1223 |
(...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2223 | 2212 |
2224 | 2213 |
2225 void Struct::InitializeBody(int object_size) { | 2214 void Struct::InitializeBody(int object_size) { |
2226 Object* value = GetHeap()->undefined_value(); | 2215 Object* value = GetHeap()->undefined_value(); |
2227 for (int offset = kHeaderSize; offset < object_size; offset += kPointerSize) { | 2216 for (int offset = kHeaderSize; offset < object_size; offset += kPointerSize) { |
2228 WRITE_FIELD(this, offset, value); | 2217 WRITE_FIELD(this, offset, value); |
2229 } | 2218 } |
2230 } | 2219 } |
2231 | 2220 |
2232 | 2221 |
2233 bool Object::ToArrayIndex(uint32_t* index) { | 2222 bool Object::ToArrayLength(uint32_t* index) { |
2234 if (IsSmi()) { | 2223 if (IsSmi()) { |
2235 int value = Smi::cast(this)->value(); | 2224 int value = Smi::cast(this)->value(); |
2236 if (value < 0) return false; | 2225 if (value < 0) return false; |
2237 *index = value; | 2226 *index = value; |
2238 return true; | 2227 return true; |
2239 } | 2228 } |
2240 if (IsHeapNumber()) { | 2229 if (IsHeapNumber()) { |
2241 double value = HeapNumber::cast(this)->value(); | 2230 double value = HeapNumber::cast(this)->value(); |
2242 uint32_t uint_value = static_cast<uint32_t>(value); | 2231 uint32_t uint_value = static_cast<uint32_t>(value); |
2243 if (value == static_cast<double>(uint_value)) { | 2232 if (value == static_cast<double>(uint_value)) { |
2244 *index = uint_value; | 2233 *index = uint_value; |
2245 return true; | 2234 return true; |
2246 } | 2235 } |
2247 } | 2236 } |
2248 return false; | 2237 return false; |
2249 } | 2238 } |
2250 | 2239 |
2251 | 2240 |
| 2241 bool Object::ToArrayIndex(uint32_t* index) { |
| 2242 return ToArrayLength(index) && *index != kMaxUInt32; |
| 2243 } |
| 2244 |
| 2245 |
2252 bool Object::IsStringObjectWithCharacterAt(uint32_t index) { | 2246 bool Object::IsStringObjectWithCharacterAt(uint32_t index) { |
2253 if (!this->IsJSValue()) return false; | 2247 if (!this->IsJSValue()) return false; |
2254 | 2248 |
2255 JSValue* js_value = JSValue::cast(this); | 2249 JSValue* js_value = JSValue::cast(this); |
2256 if (!js_value->value()->IsString()) return false; | 2250 if (!js_value->value()->IsString()) return false; |
2257 | 2251 |
2258 String* str = String::cast(js_value->value()); | 2252 String* str = String::cast(js_value->value()); |
2259 if (index >= static_cast<uint32_t>(str->length())) return false; | 2253 if (index >= static_cast<uint32_t>(str->length())) return false; |
2260 | 2254 |
2261 return true; | 2255 return true; |
(...skipping 4277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6539 return JSArrayBuffer::cast(buffer())->was_neutered(); | 6533 return JSArrayBuffer::cast(buffer())->was_neutered(); |
6540 } | 6534 } |
6541 | 6535 |
6542 | 6536 |
6543 Object* JSTypedArray::length() const { | 6537 Object* JSTypedArray::length() const { |
6544 if (WasNeutered()) return Smi::FromInt(0); | 6538 if (WasNeutered()) return Smi::FromInt(0); |
6545 return Object::cast(READ_FIELD(this, kLengthOffset)); | 6539 return Object::cast(READ_FIELD(this, kLengthOffset)); |
6546 } | 6540 } |
6547 | 6541 |
6548 | 6542 |
| 6543 uint32_t JSTypedArray::length_value() const { |
| 6544 if (WasNeutered()) return 0; |
| 6545 uint32_t index = 0; |
| 6546 CHECK(Object::cast(READ_FIELD(this, kLengthOffset))->ToArrayLength(&index)); |
| 6547 return index; |
| 6548 } |
| 6549 |
| 6550 |
6549 void JSTypedArray::set_length(Object* value, WriteBarrierMode mode) { | 6551 void JSTypedArray::set_length(Object* value, WriteBarrierMode mode) { |
6550 WRITE_FIELD(this, kLengthOffset, value); | 6552 WRITE_FIELD(this, kLengthOffset, value); |
6551 CONDITIONAL_WRITE_BARRIER(GetHeap(), this, kLengthOffset, value, mode); | 6553 CONDITIONAL_WRITE_BARRIER(GetHeap(), this, kLengthOffset, value, mode); |
6552 } | 6554 } |
6553 | 6555 |
6554 | 6556 |
6555 #ifdef VERIFY_HEAP | 6557 #ifdef VERIFY_HEAP |
6556 ACCESSORS(JSTypedArray, raw_length, Object, kLengthOffset) | 6558 ACCESSORS(JSTypedArray, raw_length, Object, kLengthOffset) |
6557 #endif | 6559 #endif |
6558 | 6560 |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6850 return false; | 6852 return false; |
6851 } | 6853 } |
6852 int d = c - '0'; | 6854 int d = c - '0'; |
6853 if (is_first_char_) { | 6855 if (is_first_char_) { |
6854 is_first_char_ = false; | 6856 is_first_char_ = false; |
6855 if (c == '0' && length_ > 1) { | 6857 if (c == '0' && length_ > 1) { |
6856 is_array_index_ = false; | 6858 is_array_index_ = false; |
6857 return false; | 6859 return false; |
6858 } | 6860 } |
6859 } | 6861 } |
6860 if (array_index_ > 429496729U - ((d + 2) >> 3)) { | 6862 if (array_index_ > 429496729U - ((d + 3) >> 3)) { |
6861 is_array_index_ = false; | 6863 is_array_index_ = false; |
6862 return false; | 6864 return false; |
6863 } | 6865 } |
6864 array_index_ = array_index_ * 10 + d; | 6866 array_index_ = array_index_ * 10 + d; |
6865 return true; | 6867 return true; |
6866 } | 6868 } |
6867 | 6869 |
6868 | 6870 |
6869 template<typename Char> | 6871 template<typename Char> |
6870 inline void StringHasher::AddCharacters(const Char* chars, int length) { | 6872 inline void StringHasher::AddCharacters(const Char* chars, int length) { |
(...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7662 #undef READ_SHORT_FIELD | 7664 #undef READ_SHORT_FIELD |
7663 #undef WRITE_SHORT_FIELD | 7665 #undef WRITE_SHORT_FIELD |
7664 #undef READ_BYTE_FIELD | 7666 #undef READ_BYTE_FIELD |
7665 #undef WRITE_BYTE_FIELD | 7667 #undef WRITE_BYTE_FIELD |
7666 #undef NOBARRIER_READ_BYTE_FIELD | 7668 #undef NOBARRIER_READ_BYTE_FIELD |
7667 #undef NOBARRIER_WRITE_BYTE_FIELD | 7669 #undef NOBARRIER_WRITE_BYTE_FIELD |
7668 | 7670 |
7669 } } // namespace v8::internal | 7671 } } // namespace v8::internal |
7670 | 7672 |
7671 #endif // V8_OBJECTS_INL_H_ | 7673 #endif // V8_OBJECTS_INL_H_ |
OLD | NEW |