Revision: 24796
Author:   [email protected]
Date:     Wed Oct 22 08:19:05 2014 UTC
Log:      Flatten the string in StringToDouble function.

[email protected]
BUG=chromium:425551
LOG=N

Review URL: https://codereview.chromium.org/654763003
https://code.google.com/p/v8/source/detail?r=24796

Added:
 /branches/bleeding_edge/test/mjsunit/regress/regress-425551.js
Modified:
 /branches/bleeding_edge/src/conversions.cc
 /branches/bleeding_edge/src/conversions.h
 /branches/bleeding_edge/src/lookup.cc
 /branches/bleeding_edge/src/runtime/runtime-numbers.cc

=======================================
--- /dev/null
+++ /branches/bleeding_edge/test/mjsunit/regress/regress-425551.js Wed Oct 22 08:19:05 2014 UTC
@@ -0,0 +1,7 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+var array = new Int8Array(10);
+array[/\u007d\u00fc\u0043/] = 1.499
+assertEquals(1.499, array[/\u007d\u00fc\u0043/]);
=======================================
--- /branches/bleeding_edge/src/conversions.cc  Wed Sep 10 12:38:12 2014 UTC
+++ /branches/bleeding_edge/src/conversions.cc  Wed Oct 22 08:19:05 2014 UTC
@@ -483,19 +483,21 @@
 }


-double StringToDouble(UnicodeCache* unicode_cache,
-                      String* string,
-                      int flags,
-                      double empty_string_val) {
-  DisallowHeapAllocation no_gc;
-  String::FlatContent flat = string->GetFlatContent();
-  // ECMA-262 section 15.1.2.3, empty string is NaN
-  if (flat.IsOneByte()) {
-    return StringToDouble(
-        unicode_cache, flat.ToOneByteVector(), flags, empty_string_val);
-  } else {
-    return StringToDouble(
-        unicode_cache, flat.ToUC16Vector(), flags, empty_string_val);
+double StringToDouble(UnicodeCache* unicode_cache, Handle<String> string,
+                      int flags, double empty_string_val) {
+  Handle<String> flattened = String::Flatten(string);
+  {
+    DisallowHeapAllocation no_gc;
+    String::FlatContent flat = flattened->GetFlatContent();
+    DCHECK(flat.IsFlat());
+    // ECMA-262 section 15.1.2.3, empty string is NaN
+    if (flat.IsOneByte()) {
+      return StringToDouble(unicode_cache, flat.ToOneByteVector(), flags,
+                            empty_string_val);
+    } else {
+      return StringToDouble(unicode_cache, flat.ToUC16Vector(), flags,
+                            empty_string_val);
+    }
   }
 }

=======================================
--- /branches/bleeding_edge/src/conversions.h   Mon Sep 22 11:42:10 2014 UTC
+++ /branches/bleeding_edge/src/conversions.h   Wed Oct 22 08:19:05 2014 UTC
@@ -198,10 +198,8 @@
 }


-double StringToDouble(UnicodeCache* unicode_cache,
-                      String* string,
-                      int flags,
-                      double empty_string_val = 0.0);
+double StringToDouble(UnicodeCache* unicode_cache, Handle<String> string,
+                      int flags, double empty_string_val = 0.0);


 inline bool TryNumberToSize(Isolate* isolate,
=======================================
--- /branches/bleeding_edge/src/lookup.cc       Tue Oct 21 11:54:10 2014 UTC
+++ /branches/bleeding_edge/src/lookup.cc       Wed Oct 22 08:19:05 2014 UTC
@@ -314,7 +314,7 @@
     Handle<String> name_string = Handle<String>::cast(name());
     if (name_string->length() > 0) {
       double d =
- StringToDouble(isolate()->unicode_cache(), *name_string, NO_FLAGS); + StringToDouble(isolate()->unicode_cache(), name_string, NO_FLAGS);
       if (!std::isnan(d)) {
         if (String::Equals(isolate()->factory()->minus_zero_string(),
                            name_string))
=======================================
--- /branches/bleeding_edge/src/runtime/runtime-numbers.cc Mon Oct 20 12:37:48 2014 UTC +++ /branches/bleeding_edge/src/runtime/runtime-numbers.cc Wed Oct 22 08:19:05 2014 UTC
@@ -193,7 +193,7 @@
   }

   return *isolate->factory()->NewNumber(
-      StringToDouble(isolate->unicode_cache(), *subject, flags));
+      StringToDouble(isolate->unicode_cache(), subject, flags));
 }


@@ -229,8 +229,7 @@
   DCHECK(args.length() == 1);
   CONVERT_ARG_HANDLE_CHECKED(String, subject, 0);

-  subject = String::Flatten(subject);
-  double value = StringToDouble(isolate->unicode_cache(), *subject,
+  double value = StringToDouble(isolate->unicode_cache(), subject,
ALLOW_TRAILING_JUNK, base::OS::nan_value());

   return *isolate->factory()->NewNumber(value);

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to