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

Side by Side Diff: src/objects.h

Issue 2579023002: [runtime] Improve Object::ToNumber, ToInteger, ToInt32, ToUint32, ToString (Closed)
Patch Set: fix Uint32 conversion Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/objects.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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 #ifndef V8_OBJECTS_H_ 5 #ifndef V8_OBJECTS_H_
6 #define V8_OBJECTS_H_ 6 #define V8_OBJECTS_H_
7 7
8 #include <iosfwd> 8 #include <iosfwd>
9 #include <memory> 9 #include <memory>
10 10
(...skipping 1281 matching lines...) Expand 10 before | Expand all | Expand 10 after
1292 1292
1293 // ES6 section 7.1.14 ToPropertyKey 1293 // ES6 section 7.1.14 ToPropertyKey
1294 MUST_USE_RESULT static inline MaybeHandle<Name> ToName(Isolate* isolate, 1294 MUST_USE_RESULT static inline MaybeHandle<Name> ToName(Isolate* isolate,
1295 Handle<Object> input); 1295 Handle<Object> input);
1296 1296
1297 // ES6 section 7.1.1 ToPrimitive 1297 // ES6 section 7.1.1 ToPrimitive
1298 MUST_USE_RESULT static inline MaybeHandle<Object> ToPrimitive( 1298 MUST_USE_RESULT static inline MaybeHandle<Object> ToPrimitive(
1299 Handle<Object> input, ToPrimitiveHint hint = ToPrimitiveHint::kDefault); 1299 Handle<Object> input, ToPrimitiveHint hint = ToPrimitiveHint::kDefault);
1300 1300
1301 // ES6 section 7.1.3 ToNumber 1301 // ES6 section 7.1.3 ToNumber
1302 MUST_USE_RESULT static MaybeHandle<Object> ToNumber(Handle<Object> input); 1302 MUST_USE_RESULT static inline MaybeHandle<Object> ToNumber(
1303 Handle<Object> input);
1303 1304
1304 // ES6 section 7.1.4 ToInteger 1305 // ES6 section 7.1.4 ToInteger
1305 MUST_USE_RESULT static MaybeHandle<Object> ToInteger(Isolate* isolate, 1306 MUST_USE_RESULT static inline MaybeHandle<Object> ToInteger(
1306 Handle<Object> input); 1307 Isolate* isolate, Handle<Object> input);
1307 1308
1308 // ES6 section 7.1.5 ToInt32 1309 // ES6 section 7.1.5 ToInt32
1309 MUST_USE_RESULT static MaybeHandle<Object> ToInt32(Isolate* isolate, 1310 MUST_USE_RESULT static inline MaybeHandle<Object> ToInt32(
1310 Handle<Object> input); 1311 Isolate* isolate, Handle<Object> input);
1311 1312
1312 // ES6 section 7.1.6 ToUint32 1313 // ES6 section 7.1.6 ToUint32
1313 MUST_USE_RESULT static MaybeHandle<Object> ToUint32(Isolate* isolate, 1314 MUST_USE_RESULT inline static MaybeHandle<Object> ToUint32(
1314 Handle<Object> input); 1315 Isolate* isolate, Handle<Object> input);
1315 1316
1316 // ES6 section 7.1.12 ToString 1317 // ES6 section 7.1.12 ToString
1317 MUST_USE_RESULT static MaybeHandle<String> ToString(Isolate* isolate, 1318 MUST_USE_RESULT static inline MaybeHandle<String> ToString(
1318 Handle<Object> input); 1319 Isolate* isolate, Handle<Object> input);
1319 1320
1320 static Handle<String> NoSideEffectsToString(Isolate* isolate, 1321 static Handle<String> NoSideEffectsToString(Isolate* isolate,
1321 Handle<Object> input); 1322 Handle<Object> input);
1322 1323
1323 // ES6 section 7.1.14 ToPropertyKey 1324 // ES6 section 7.1.14 ToPropertyKey
1324 MUST_USE_RESULT static MaybeHandle<Object> ToPropertyKey( 1325 MUST_USE_RESULT static MaybeHandle<Object> ToPropertyKey(
1325 Isolate* isolate, Handle<Object> value); 1326 Isolate* isolate, Handle<Object> value);
1326 1327
1327 // ES6 section 7.1.15 ToLength 1328 // ES6 section 7.1.15 ToLength
1328 MUST_USE_RESULT static MaybeHandle<Object> ToLength(Isolate* isolate, 1329 MUST_USE_RESULT static MaybeHandle<Object> ToLength(Isolate* isolate,
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
1557 Map* GetPrototypeChainRootMap(Isolate* isolate); 1558 Map* GetPrototypeChainRootMap(Isolate* isolate);
1558 1559
1559 // Helper for SetProperty and SetSuperProperty. 1560 // Helper for SetProperty and SetSuperProperty.
1560 // Return value is only meaningful if [found] is set to true on return. 1561 // Return value is only meaningful if [found] is set to true on return.
1561 MUST_USE_RESULT static Maybe<bool> SetPropertyInternal( 1562 MUST_USE_RESULT static Maybe<bool> SetPropertyInternal(
1562 LookupIterator* it, Handle<Object> value, LanguageMode language_mode, 1563 LookupIterator* it, Handle<Object> value, LanguageMode language_mode,
1563 StoreFromKeyed store_mode, bool* found); 1564 StoreFromKeyed store_mode, bool* found);
1564 1565
1565 MUST_USE_RESULT static MaybeHandle<Name> ConvertToName(Isolate* isolate, 1566 MUST_USE_RESULT static MaybeHandle<Name> ConvertToName(Isolate* isolate,
1566 Handle<Object> input); 1567 Handle<Object> input);
1567 1568 MUST_USE_RESULT static MaybeHandle<String> ConvertToString(
1569 Isolate* isolate, Handle<Object> input);
1570 MUST_USE_RESULT static MaybeHandle<Object> ConvertToNumber(
1571 Isolate* isolate, Handle<Object> input);
1572 MUST_USE_RESULT static MaybeHandle<Object> ConvertToInteger(
1573 Isolate* isolate, Handle<Object> input);
1574 MUST_USE_RESULT static MaybeHandle<Object> ConvertToInt32(
1575 Isolate* isolate, Handle<Object> input);
1576 MUST_USE_RESULT static MaybeHandle<Object> ConvertToUint32(
1577 Isolate* isolate, Handle<Object> input);
1568 DISALLOW_IMPLICIT_CONSTRUCTORS(Object); 1578 DISALLOW_IMPLICIT_CONSTRUCTORS(Object);
1569 }; 1579 };
1570 1580
1571 1581
1572 // In objects.h to be usable without objects-inl.h inclusion. 1582 // In objects.h to be usable without objects-inl.h inclusion.
1573 bool Object::IsSmi() const { return HAS_SMI_TAG(this); } 1583 bool Object::IsSmi() const { return HAS_SMI_TAG(this); }
1574 bool Object::IsHeapObject() const { return Internals::HasHeapObjectTag(this); } 1584 bool Object::IsHeapObject() const { return Internals::HasHeapObjectTag(this); }
1575 1585
1576 1586
1577 struct Brief { 1587 struct Brief {
1578 explicit Brief(const Object* const v) : value(v) {} 1588 explicit Brief(const Object* const v) : value(v) {}
1579 const Object* value; 1589 const Object* value;
1580 }; 1590 };
1581 1591
1582 V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os, const Brief& v); 1592 V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os, const Brief& v);
1583 1593
1584 // Smi represents integer Numbers that can be stored in 31 bits. 1594 // Smi represents integer Numbers that can be stored in 31 bits.
1585 // Smis are immediate which means they are NOT allocated in the heap. 1595 // Smis are immediate which means they are NOT allocated in the heap.
1586 // The this pointer has the following format: [31 bit signed int] 0 1596 // The this pointer has the following format: [31 bit signed int] 0
1587 // For long smis it has the following format: 1597 // For long smis it has the following format:
1588 // [32 bit signed int] [31 bits zero padding] 0 1598 // [32 bit signed int] [31 bits zero padding] 0
1589 // Smi stands for small integer. 1599 // Smi stands for small integer.
1590 class Smi: public Object { 1600 class Smi: public Object {
1591 public: 1601 public:
1592 // Returns the integer value. 1602 // Returns the integer value.
1593 inline int value() const { return Internals::SmiValue(this); } 1603 inline int value() const { return Internals::SmiValue(this); }
1604 inline Smi* ToUint32Smi() {
1605 if (value() <= 0) return Smi::kZero;
1606 return Smi::FromInt(static_cast<uint32_t>(value()));
1607 }
1594 1608
1595 // Convert a value to a Smi object. 1609 // Convert a value to a Smi object.
1596 static inline Smi* FromInt(int value) { 1610 static inline Smi* FromInt(int value) {
1597 DCHECK(Smi::IsValid(value)); 1611 DCHECK(Smi::IsValid(value));
1598 return reinterpret_cast<Smi*>(Internals::IntToSmi(value)); 1612 return reinterpret_cast<Smi*>(Internals::IntToSmi(value));
1599 } 1613 }
1600 1614
1601 static inline Smi* FromIntptr(intptr_t value) { 1615 static inline Smi* FromIntptr(intptr_t value) {
1602 DCHECK(Smi::IsValid(value)); 1616 DCHECK(Smi::IsValid(value));
1603 int smi_shift_bits = kSmiTagSize + kSmiShiftSize; 1617 int smi_shift_bits = kSmiTagSize + kSmiShiftSize;
(...skipping 10404 matching lines...) Expand 10 before | Expand all | Expand 10 after
12008 } 12022 }
12009 return value; 12023 return value;
12010 } 12024 }
12011 }; 12025 };
12012 12026
12013 12027
12014 } // NOLINT, false-positive due to second-order macros. 12028 } // NOLINT, false-positive due to second-order macros.
12015 } // NOLINT, false-positive due to second-order macros. 12029 } // NOLINT, false-positive due to second-order macros.
12016 12030
12017 #endif // V8_OBJECTS_H_ 12031 #endif // V8_OBJECTS_H_
OLDNEW
« no previous file with comments | « no previous file | src/objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698