Chromium Code Reviews| Index: src/runtime.cc |
| diff --git a/src/runtime.cc b/src/runtime.cc |
| index 213166a92d48f212d89ad23589505efd7e6a1eea..7a70e825a97e494d0f7bde5297c362ca285ff543 100644 |
| --- a/src/runtime.cc |
| +++ b/src/runtime.cc |
| @@ -6874,6 +6874,31 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_AllocateHeapNumber) { |
| } |
| +static int HexToInt(uint16_t c) { |
| + if (c >= '0' && c <= '9') return c - '0'; |
| + ASSERT(c >= 'a' && c <= 'f'); |
| + return c - 'a' + 10; |
| +} |
| + |
| + |
| +RUNTIME_FUNCTION(MaybeObject*, Runtime_HeapNumberFromHex) { |
| + SealHandleScope shs(isolate); |
| + ASSERT(args.length() == 1); |
| + CONVERT_ARG_CHECKED(String, input, 0); |
| + RUNTIME_ASSERT(input->length() == 16); |
| + // Only used during bootstrapping. |
| + RUNTIME_ASSERT(isolate->bootstrapper()->IsActive()); |
| + double result = 0; |
| + uint8_t* bytes = reinterpret_cast<uint8_t*>(&result); |
|
Jakob Kummerow
2013/11/19 17:49:54
Are you sure this compiles? AFAIK this is what we
|
| + // Input string is a little-endian hex representation of the double value. |
| + for (int i = 0; i < 8; i++) { |
| + bytes[i] = HexToInt(input->Get(2 * i)) * 16 + |
| + HexToInt(input->Get(2 * i + 1)); |
| + } |
| + return isolate->heap()->AllocateHeapNumber(result); |
| +} |
| + |
| + |
| RUNTIME_FUNCTION(MaybeObject*, Runtime_NumberAdd) { |
| SealHandleScope shs(isolate); |
| ASSERT(args.length() == 2); |