| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 <ctype.h> // isspace. | 5 #include <ctype.h> // isspace. |
| 6 | 6 |
| 7 #include "vm/bootstrap_natives.h" | 7 #include "vm/bootstrap_natives.h" |
| 8 | 8 |
| 9 #include "vm/bigint_operations.h" | 9 #include "vm/bigint_operations.h" |
| 10 #include "vm/exceptions.h" | 10 #include "vm/exceptions.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 *is_positive = tokens[0].kind == Token::kTIGHTADD; | 97 *is_positive = tokens[0].kind == Token::kTIGHTADD; |
| 98 *value = tokens[1].literal; | 98 *value = tokens[1].literal; |
| 99 return true; | 99 return true; |
| 100 } | 100 } |
| 101 return false; | 101 return false; |
| 102 } | 102 } |
| 103 | 103 |
| 104 | 104 |
| 105 DEFINE_NATIVE_ENTRY(MathNatives_parseInt, 1) { | 105 DEFINE_NATIVE_ENTRY(MathNatives_parseInt, 1) { |
| 106 GET_NATIVE_ARGUMENT(String, value, arguments->At(0)); | 106 GET_NATIVE_ARGUMENT(String, value, arguments->At(0)); |
| 107 Scanner scanner(value, String::Handle()); | 107 const String& dummy_key = String::Handle(Symbols::Empty()); |
| 108 Scanner scanner(value, dummy_key); |
| 108 const Scanner::GrowableTokenStream& tokens = scanner.GetStream(); | 109 const Scanner::GrowableTokenStream& tokens = scanner.GetStream(); |
| 109 String* int_string; | 110 String* int_string; |
| 110 bool is_positive; | 111 bool is_positive; |
| 111 if (IsValidLiteral(tokens, Token::kINTEGER, &is_positive, &int_string)) { | 112 if (IsValidLiteral(tokens, Token::kINTEGER, &is_positive, &int_string)) { |
| 112 if (is_positive) { | 113 if (is_positive) { |
| 113 return Integer::New(*int_string); | 114 return Integer::New(*int_string); |
| 114 } else { | 115 } else { |
| 115 String& temp = String::Handle(); | 116 String& temp = String::Handle(); |
| 116 temp = String::Concat(String::Handle(Symbols::New("-")), | 117 temp = String::Concat(String::Handle(Symbols::New("-")), |
| 117 *int_string); | 118 *int_string); |
| 118 return Integer::New(temp); | 119 return Integer::New(temp); |
| 119 } | 120 } |
| 120 } else { | 121 } else { |
| 121 GrowableArray<const Object*> args; | 122 GrowableArray<const Object*> args; |
| 122 args.Add(&value); | 123 args.Add(&value); |
| 123 Exceptions::ThrowByType(Exceptions::kFormat, args); | 124 Exceptions::ThrowByType(Exceptions::kFormat, args); |
| 124 return Object::null(); | 125 return Object::null(); |
| 125 } | 126 } |
| 126 } | 127 } |
| 127 | 128 |
| 128 | 129 |
| 129 DEFINE_NATIVE_ENTRY(MathNatives_parseDouble, 1) { | 130 DEFINE_NATIVE_ENTRY(MathNatives_parseDouble, 1) { |
| 130 GET_NATIVE_ARGUMENT(String, value, arguments->At(0)); | 131 GET_NATIVE_ARGUMENT(String, value, arguments->At(0)); |
| 131 Scanner scanner(value, String::Handle()); | 132 const String& dummy_key = String::Handle(Symbols::Empty()); |
| 133 Scanner scanner(value, dummy_key); |
| 132 const Scanner::GrowableTokenStream& tokens = scanner.GetStream(); | 134 const Scanner::GrowableTokenStream& tokens = scanner.GetStream(); |
| 133 String* number_string; | 135 String* number_string; |
| 134 bool is_positive; | 136 bool is_positive; |
| 135 if (IsValidLiteral(tokens, Token::kDOUBLE, &is_positive, &number_string)) { | 137 if (IsValidLiteral(tokens, Token::kDOUBLE, &is_positive, &number_string)) { |
| 136 const char* cstr = number_string->ToCString(); | 138 const char* cstr = number_string->ToCString(); |
| 137 char* p_end = NULL; | 139 char* p_end = NULL; |
| 138 double double_value = strtod(cstr, &p_end); | 140 double double_value = strtod(cstr, &p_end); |
| 139 ASSERT(p_end != cstr); | 141 ASSERT(p_end != cstr); |
| 140 if (!is_positive) { | 142 if (!is_positive) { |
| 141 double_value = -double_value; | 143 double_value = -double_value; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 166 } | 168 } |
| 167 } | 169 } |
| 168 | 170 |
| 169 GrowableArray<const Object*> args; | 171 GrowableArray<const Object*> args; |
| 170 args.Add(&value); | 172 args.Add(&value); |
| 171 Exceptions::ThrowByType(Exceptions::kFormat, args); | 173 Exceptions::ThrowByType(Exceptions::kFormat, args); |
| 172 return Object::null(); | 174 return Object::null(); |
| 173 } | 175 } |
| 174 | 176 |
| 175 } // namespace dart | 177 } // namespace dart |
| OLD | NEW |