Chromium Code Reviews| 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 1150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1161 MaybeHandle<Object> Object::GetProperty(Handle<Object> object, | 1161 MaybeHandle<Object> Object::GetProperty(Handle<Object> object, |
| 1162 Handle<Name> name) { | 1162 Handle<Name> name) { |
| 1163 LookupIterator it(object, name); | 1163 LookupIterator it(object, name); |
| 1164 return GetProperty(&it); | 1164 return GetProperty(&it); |
| 1165 } | 1165 } |
| 1166 | 1166 |
| 1167 | 1167 |
| 1168 MaybeHandle<Object> Object::GetElement(Isolate* isolate, | 1168 MaybeHandle<Object> Object::GetElement(Isolate* isolate, |
| 1169 Handle<Object> object, | 1169 Handle<Object> object, |
| 1170 uint32_t index) { | 1170 uint32_t index) { |
| 1171 // GetElement can trigger a getter which can cause allocation. | 1171 LookupIterator it(isolate, object, index); |
| 1172 // This was not always the case. This DCHECK is here to catch | 1172 return GetProperty(&it); |
| 1173 // leftover incorrect uses. | |
| 1174 DCHECK(AllowHeapAllocation::IsAllowed()); | |
| 1175 return Object::GetElementWithReceiver(isolate, object, object, index); | |
| 1176 } | 1173 } |
| 1177 | 1174 |
| 1178 | 1175 |
| 1179 Handle<Object> Object::GetPrototypeSkipHiddenPrototypes( | 1176 Handle<Object> Object::GetPrototypeSkipHiddenPrototypes( |
| 1180 Isolate* isolate, Handle<Object> receiver) { | 1177 Isolate* isolate, Handle<Object> receiver) { |
| 1181 PrototypeIterator iter(isolate, receiver); | 1178 PrototypeIterator iter(isolate, receiver); |
| 1182 while (!iter.IsAtEnd(PrototypeIterator::END_AT_NON_HIDDEN)) { | 1179 while (!iter.IsAtEnd(PrototypeIterator::END_AT_NON_HIDDEN)) { |
| 1183 if (PrototypeIterator::GetCurrent(iter)->IsJSProxy()) { | 1180 if (PrototypeIterator::GetCurrent(iter)->IsJSProxy()) { |
| 1184 return PrototypeIterator::GetCurrent(iter); | 1181 return PrototypeIterator::GetCurrent(iter); |
| 1185 } | 1182 } |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 1204 Handle<String> str = isolate->factory()->InternalizeUtf8String(name); | 1201 Handle<String> str = isolate->factory()->InternalizeUtf8String(name); |
| 1205 DCHECK(!str.is_null()); | 1202 DCHECK(!str.is_null()); |
| 1206 #ifdef DEBUG | 1203 #ifdef DEBUG |
| 1207 uint32_t index; // Assert that the name is not an array index. | 1204 uint32_t index; // Assert that the name is not an array index. |
| 1208 DCHECK(!str->AsArrayIndex(&index)); | 1205 DCHECK(!str->AsArrayIndex(&index)); |
| 1209 #endif // DEBUG | 1206 #endif // DEBUG |
| 1210 return GetProperty(object, str); | 1207 return GetProperty(object, str); |
| 1211 } | 1208 } |
| 1212 | 1209 |
| 1213 | 1210 |
| 1214 MaybeHandle<Object> JSProxy::GetElementWithHandler(Handle<JSProxy> proxy, | |
| 1215 Handle<Object> receiver, | |
| 1216 uint32_t index) { | |
| 1217 return GetPropertyWithHandler( | |
| 1218 proxy, receiver, proxy->GetIsolate()->factory()->Uint32ToString(index)); | |
| 1219 } | |
| 1220 | |
| 1221 | |
| 1222 MaybeHandle<Object> JSProxy::SetElementWithHandler(Handle<JSProxy> proxy, | 1211 MaybeHandle<Object> JSProxy::SetElementWithHandler(Handle<JSProxy> proxy, |
| 1223 Handle<JSReceiver> receiver, | 1212 Handle<JSReceiver> receiver, |
| 1224 uint32_t index, | 1213 uint32_t index, |
| 1225 Handle<Object> value, | 1214 Handle<Object> value, |
| 1226 LanguageMode language_mode) { | 1215 LanguageMode language_mode) { |
| 1227 Isolate* isolate = proxy->GetIsolate(); | 1216 Isolate* isolate = proxy->GetIsolate(); |
| 1228 Handle<String> name = isolate->factory()->Uint32ToString(index); | 1217 Handle<String> name = isolate->factory()->Uint32ToString(index); |
| 1229 return SetPropertyWithHandler(proxy, receiver, name, value, language_mode); | 1218 return SetPropertyWithHandler(proxy, receiver, name, value, language_mode); |
| 1230 } | 1219 } |
| 1231 | 1220 |
| (...skipping 986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2218 | 2207 |
| 2219 | 2208 |
| 2220 void Struct::InitializeBody(int object_size) { | 2209 void Struct::InitializeBody(int object_size) { |
| 2221 Object* value = GetHeap()->undefined_value(); | 2210 Object* value = GetHeap()->undefined_value(); |
| 2222 for (int offset = kHeaderSize; offset < object_size; offset += kPointerSize) { | 2211 for (int offset = kHeaderSize; offset < object_size; offset += kPointerSize) { |
| 2223 WRITE_FIELD(this, offset, value); | 2212 WRITE_FIELD(this, offset, value); |
| 2224 } | 2213 } |
| 2225 } | 2214 } |
| 2226 | 2215 |
| 2227 | 2216 |
| 2228 bool Object::ToArrayIndex(uint32_t* index) { | 2217 bool Object::ToArrayLength(uint32_t* index) { |
| 2229 if (IsSmi()) { | 2218 if (IsSmi()) { |
| 2230 int value = Smi::cast(this)->value(); | 2219 int value = Smi::cast(this)->value(); |
| 2231 if (value < 0) return false; | 2220 if (value < 0) return false; |
| 2232 *index = value; | 2221 *index = value; |
| 2233 return true; | 2222 return true; |
| 2234 } | 2223 } |
| 2235 if (IsHeapNumber()) { | 2224 if (IsHeapNumber()) { |
| 2236 double value = HeapNumber::cast(this)->value(); | 2225 double value = HeapNumber::cast(this)->value(); |
| 2237 uint32_t uint_value = static_cast<uint32_t>(value); | 2226 uint32_t uint_value = static_cast<uint32_t>(value); |
| 2238 if (value == static_cast<double>(uint_value)) { | 2227 if (value == static_cast<double>(uint_value)) { |
| 2239 *index = uint_value; | 2228 *index = uint_value; |
| 2240 return true; | 2229 return true; |
| 2241 } | 2230 } |
| 2242 } | 2231 } |
| 2243 return false; | 2232 return false; |
| 2244 } | 2233 } |
| 2245 | 2234 |
| 2246 | 2235 |
| 2236 bool Object::ToArrayIndex(uint32_t* index) { | |
| 2237 return ToArrayLength(index) && *index != kMaxUInt32; | |
| 2238 } | |
| 2239 | |
| 2240 | |
| 2247 bool Object::IsStringObjectWithCharacterAt(uint32_t index) { | 2241 bool Object::IsStringObjectWithCharacterAt(uint32_t index) { |
| 2248 if (!this->IsJSValue()) return false; | 2242 if (!this->IsJSValue()) return false; |
| 2249 | 2243 |
| 2250 JSValue* js_value = JSValue::cast(this); | 2244 JSValue* js_value = JSValue::cast(this); |
| 2251 if (!js_value->value()->IsString()) return false; | 2245 if (!js_value->value()->IsString()) return false; |
| 2252 | 2246 |
| 2253 String* str = String::cast(js_value->value()); | 2247 String* str = String::cast(js_value->value()); |
| 2254 if (index >= static_cast<uint32_t>(str->length())) return false; | 2248 if (index >= static_cast<uint32_t>(str->length())) return false; |
| 2255 | 2249 |
| 2256 return true; | 2250 return true; |
| (...skipping 4261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6518 return JSArrayBuffer::cast(buffer())->was_neutered(); | 6512 return JSArrayBuffer::cast(buffer())->was_neutered(); |
| 6519 } | 6513 } |
| 6520 | 6514 |
| 6521 | 6515 |
| 6522 Object* JSTypedArray::length() const { | 6516 Object* JSTypedArray::length() const { |
| 6523 if (WasNeutered()) return Smi::FromInt(0); | 6517 if (WasNeutered()) return Smi::FromInt(0); |
| 6524 return Object::cast(READ_FIELD(this, kLengthOffset)); | 6518 return Object::cast(READ_FIELD(this, kLengthOffset)); |
| 6525 } | 6519 } |
| 6526 | 6520 |
| 6527 | 6521 |
| 6522 uint32_t JSTypedArray::length_value() const { | |
| 6523 if (WasNeutered()) return 0; | |
| 6524 uint32_t index; | |
| 6525 CHECK(Object::cast(READ_FIELD(this, kLengthOffset))->ToArrayIndex(&index)); | |
|
Igor Sheludko
2015/05/26 17:11:56
ToArrayLength()?
| |
| 6526 return index; | |
| 6527 } | |
| 6528 | |
| 6529 | |
| 6528 void JSTypedArray::set_length(Object* value, WriteBarrierMode mode) { | 6530 void JSTypedArray::set_length(Object* value, WriteBarrierMode mode) { |
| 6529 WRITE_FIELD(this, kLengthOffset, value); | 6531 WRITE_FIELD(this, kLengthOffset, value); |
| 6530 CONDITIONAL_WRITE_BARRIER(GetHeap(), this, kLengthOffset, value, mode); | 6532 CONDITIONAL_WRITE_BARRIER(GetHeap(), this, kLengthOffset, value, mode); |
| 6531 } | 6533 } |
| 6532 | 6534 |
| 6533 | 6535 |
| 6534 #ifdef VERIFY_HEAP | 6536 #ifdef VERIFY_HEAP |
| 6535 ACCESSORS(JSTypedArray, raw_length, Object, kLengthOffset) | 6537 ACCESSORS(JSTypedArray, raw_length, Object, kLengthOffset) |
| 6536 #endif | 6538 #endif |
| 6537 | 6539 |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6821 return false; | 6823 return false; |
| 6822 } | 6824 } |
| 6823 int d = c - '0'; | 6825 int d = c - '0'; |
| 6824 if (is_first_char_) { | 6826 if (is_first_char_) { |
| 6825 is_first_char_ = false; | 6827 is_first_char_ = false; |
| 6826 if (c == '0' && length_ > 1) { | 6828 if (c == '0' && length_ > 1) { |
| 6827 is_array_index_ = false; | 6829 is_array_index_ = false; |
| 6828 return false; | 6830 return false; |
| 6829 } | 6831 } |
| 6830 } | 6832 } |
| 6831 if (array_index_ > 429496729U - ((d + 2) >> 3)) { | 6833 if (array_index_ > 429496729U - ((d + 3) >> 3)) { |
| 6832 is_array_index_ = false; | 6834 is_array_index_ = false; |
| 6833 return false; | 6835 return false; |
| 6834 } | 6836 } |
| 6835 array_index_ = array_index_ * 10 + d; | 6837 array_index_ = array_index_ * 10 + d; |
| 6836 return true; | 6838 return true; |
| 6837 } | 6839 } |
| 6838 | 6840 |
| 6839 | 6841 |
| 6840 template<typename Char> | 6842 template<typename Char> |
| 6841 inline void StringHasher::AddCharacters(const Char* chars, int length) { | 6843 inline void StringHasher::AddCharacters(const Char* chars, int length) { |
| (...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7626 #undef READ_SHORT_FIELD | 7628 #undef READ_SHORT_FIELD |
| 7627 #undef WRITE_SHORT_FIELD | 7629 #undef WRITE_SHORT_FIELD |
| 7628 #undef READ_BYTE_FIELD | 7630 #undef READ_BYTE_FIELD |
| 7629 #undef WRITE_BYTE_FIELD | 7631 #undef WRITE_BYTE_FIELD |
| 7630 #undef NOBARRIER_READ_BYTE_FIELD | 7632 #undef NOBARRIER_READ_BYTE_FIELD |
| 7631 #undef NOBARRIER_WRITE_BYTE_FIELD | 7633 #undef NOBARRIER_WRITE_BYTE_FIELD |
| 7632 | 7634 |
| 7633 } } // namespace v8::internal | 7635 } } // namespace v8::internal |
| 7634 | 7636 |
| 7635 #endif // V8_OBJECTS_INL_H_ | 7637 #endif // V8_OBJECTS_INL_H_ |
| OLD | NEW |