Commit b664c122 authored by dslomov@chromium.org's avatar dslomov@chromium.org

Flatten the string in StringToDouble function.

R=yangguo@chromium.org
BUG=chromium:425551
LOG=N

Review URL: https://codereview.chromium.org/654763003

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24796 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 4669a5cf
......@@ -483,19 +483,21 @@ char* DoubleToRadixCString(double value, int radix) {
}
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);
}
}
}
......
......@@ -198,10 +198,8 @@ inline uint32_t NumberToUint32(Object* number) {
}
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,
......
......@@ -314,7 +314,7 @@ bool LookupIterator::IsSpecialNumericIndex() const {
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))
......
......@@ -193,7 +193,7 @@ RUNTIME_FUNCTION(Runtime_StringToNumber) {
}
return *isolate->factory()->NewNumber(
StringToDouble(isolate->unicode_cache(), *subject, flags));
StringToDouble(isolate->unicode_cache(), subject, flags));
}
......@@ -229,8 +229,7 @@ RUNTIME_FUNCTION(Runtime_StringParseFloat) {
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);
......
// 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/]);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment