Chromium Code Reviews| Index: src/ast/ast-value-factory.h |
| diff --git a/src/ast/ast-value-factory.h b/src/ast/ast-value-factory.h |
| index 6f9091bd167d09ae09848101377ef729280f6f73..b471ad5daa58afbd6d4f41422adf5ca6331c54e4 100644 |
| --- a/src/ast/ast-value-factory.h |
| +++ b/src/ast/ast-value-factory.h |
| @@ -159,10 +159,7 @@ class AstValue : public ZoneObject { |
| return type_ == STRING; |
| } |
| - bool IsNumber() const { |
| - return type_ == NUMBER || type_ == NUMBER_WITH_DOT || type_ == SMI || |
| - type_ == SMI_WITH_DOT; |
| - } |
| + bool IsNumber() const { return IsSmi() || IsHeapNumber(); } |
| bool ContainsDot() const { |
| return type_ == NUMBER_WITH_DOT || type_ == SMI_WITH_DOT; |
| @@ -174,19 +171,36 @@ class AstValue : public ZoneObject { |
| } |
| double AsNumber() const { |
| - if (type_ == NUMBER || type_ == NUMBER_WITH_DOT) |
| - return number_; |
| - if (type_ == SMI || type_ == SMI_WITH_DOT) |
| - return smi_; |
| + if (IsHeapNumber()) return number_; |
| + if (IsSmi()) return smi_; |
| UNREACHABLE(); |
| return 0; |
| } |
| Smi* AsSmi() const { |
| - CHECK(type_ == SMI || type_ == SMI_WITH_DOT); |
| + CHECK(IsSmi()); |
| return Smi::FromInt(smi_); |
| } |
| + bool ToUint32(uint32_t* value) const { |
| + if (IsSmi()) { |
| + int num = smi_; |
| + if (num < 0) return false; |
| + *value = static_cast<uint32_t>(num); |
| + return true; |
| + } |
| + if (IsHeapNumber()) { |
| + double num = number_; |
| + if (num < 0) return false; |
| + uint32_t uint_value = FastD2UI(num); |
| + if (FastUI2D(uint_value) == num) { |
| + *value = uint_value; |
| + return true; |
| + } |
|
rmcilroy
2017/01/13 09:53:57
You need to be careful to check for minus 0.0 as w
Leszek Swirski
2017/01/13 10:58:10
Done, and amended the code in objects-inl.h that I
|
| + } |
| + return false; |
| + } |
| + |
| bool EqualsString(const AstRawString* string) const { |
| return type_ == STRING && string_ == string; |
| } |
| @@ -196,6 +210,9 @@ class AstValue : public ZoneObject { |
| bool BooleanValue() const; |
| bool IsSmi() const { return type_ == SMI || type_ == SMI_WITH_DOT; } |
| + bool IsHeapNumber() const { |
| + return type_ == NUMBER || type_ == NUMBER_WITH_DOT; |
| + } |
| bool IsFalse() const { return type_ == BOOLEAN && !bool_; } |
| bool IsTrue() const { return type_ == BOOLEAN && bool_; } |
| bool IsUndefined() const { return type_ == UNDEFINED; } |