| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/object.h" | 5 #include "vm/object.h" |
| 6 | 6 |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
| 10 #include "vm/bigint_operations.h" | 10 #include "vm/bigint_operations.h" |
| (...skipping 10568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10579 Double::InstanceSize(), | 10579 Double::InstanceSize(), |
| 10580 space); | 10580 space); |
| 10581 NoGCScope no_gc; | 10581 NoGCScope no_gc; |
| 10582 result ^= raw; | 10582 result ^= raw; |
| 10583 } | 10583 } |
| 10584 result.set_value(d); | 10584 result.set_value(d); |
| 10585 return result.raw(); | 10585 return result.raw(); |
| 10586 } | 10586 } |
| 10587 | 10587 |
| 10588 | 10588 |
| 10589 static bool IsWhiteSpace(char ch) { | |
| 10590 return ch == '\0' || ch == '\n' || ch == '\r' || ch == ' ' || ch == '\t'; | |
| 10591 } | |
| 10592 | |
| 10593 | |
| 10594 static bool StringToDouble(const String& str, double* double_value) { | |
| 10595 ASSERT(double_value != NULL); | |
| 10596 // TODO(regis): For now, we use strtod to convert a string to double. | |
| 10597 const char* nptr = str.ToCString(); | |
| 10598 char* endptr = NULL; | |
| 10599 *double_value = strtod(nptr, &endptr); | |
| 10600 // We do not treat overflow or underflow as an error and therefore do not | |
| 10601 // check errno for ERANGE. | |
| 10602 if (!IsWhiteSpace(*endptr)) { | |
| 10603 return false; | |
| 10604 } | |
| 10605 return true; | |
| 10606 } | |
| 10607 | |
| 10608 | |
| 10609 RawDouble* Double::New(const String& str, Heap::Space space) { | 10589 RawDouble* Double::New(const String& str, Heap::Space space) { |
| 10610 double double_value; | 10590 double double_value; |
| 10611 if (!StringToDouble(str, &double_value)) { | 10591 if (!CStringToDouble(str.ToCString(), str.Length(), &double_value)) { |
| 10612 return Double::Handle().raw(); | 10592 return Double::Handle().raw(); |
| 10613 } | 10593 } |
| 10614 return New(double_value, space); | 10594 return New(double_value, space); |
| 10615 } | 10595 } |
| 10616 | 10596 |
| 10617 | 10597 |
| 10618 RawDouble* Double::NewCanonical(double value) { | 10598 RawDouble* Double::NewCanonical(double value) { |
| 10619 const Class& cls = | 10599 const Class& cls = |
| 10620 Class::Handle(Isolate::Current()->object_store()->double_class()); | 10600 Class::Handle(Isolate::Current()->object_store()->double_class()); |
| 10621 const Array& constants = Array::Handle(cls.constants()); | 10601 const Array& constants = Array::Handle(cls.constants()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 10638 // it is full. | 10618 // it is full. |
| 10639 canonical_value = Double::New(value, Heap::kOld); | 10619 canonical_value = Double::New(value, Heap::kOld); |
| 10640 cls.InsertCanonicalConstant(index, canonical_value); | 10620 cls.InsertCanonicalConstant(index, canonical_value); |
| 10641 canonical_value.SetCanonical(); | 10621 canonical_value.SetCanonical(); |
| 10642 return canonical_value.raw(); | 10622 return canonical_value.raw(); |
| 10643 } | 10623 } |
| 10644 | 10624 |
| 10645 | 10625 |
| 10646 RawDouble* Double::NewCanonical(const String& str) { | 10626 RawDouble* Double::NewCanonical(const String& str) { |
| 10647 double double_value; | 10627 double double_value; |
| 10648 if (!StringToDouble(str, &double_value)) { | 10628 if (!CStringToDouble(str.ToCString(), str.Length(), &double_value)) { |
| 10649 return Double::Handle().raw(); | 10629 return Double::Handle().raw(); |
| 10650 } | 10630 } |
| 10651 return NewCanonical(double_value); | 10631 return NewCanonical(double_value); |
| 10652 } | 10632 } |
| 10653 | 10633 |
| 10654 | 10634 |
| 10655 const char* Double::ToCString() const { | 10635 const char* Double::ToCString() const { |
| 10656 if (isnan(value())) { | 10636 if (isnan(value())) { |
| 10657 return "NaN"; | 10637 return "NaN"; |
| 10658 } | 10638 } |
| (...skipping 2390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13049 } | 13029 } |
| 13050 return result.raw(); | 13030 return result.raw(); |
| 13051 } | 13031 } |
| 13052 | 13032 |
| 13053 | 13033 |
| 13054 const char* WeakProperty::ToCString() const { | 13034 const char* WeakProperty::ToCString() const { |
| 13055 return "_WeakProperty"; | 13035 return "_WeakProperty"; |
| 13056 } | 13036 } |
| 13057 | 13037 |
| 13058 } // namespace dart | 13038 } // namespace dart |
| OLD | NEW |