From: jochen@chromium.org Date: Mon, 28 Apr 2014 09:14:24 +0000 (+0000) Subject: Merge v8converions with conversions X-Git-Tag: upstream/4.7.83~9394 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=629725d4fbf41d36c66829ddfa4c764a7f6acadf;p=platform%2Fupstream%2Fv8.git Merge v8converions with conversions BUG=none R=mstarzinger@chromium.org LOG=n Review URL: https://codereview.chromium.org/250793009 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@21005 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/conversions.cc b/src/conversions.cc index 1d5ed35..0b83a83 100644 --- a/src/conversions.cc +++ b/src/conversions.cc @@ -29,8 +29,13 @@ #include #include +#include "v8.h" + +#include "assert-scope.h" +#include "conversions.h" #include "conversions-inl.h" #include "dtoa.h" +#include "factory.h" #include "list-inl.h" #include "strtod.h" #include "utils.h" @@ -44,6 +49,47 @@ namespace v8 { namespace internal { +namespace { + +// C++-style iterator adaptor for StringCharacterStream +// (unlike C++ iterators the end-marker has different type). +class StringCharacterStreamIterator { + public: + class EndMarker {}; + + explicit StringCharacterStreamIterator(StringCharacterStream* stream); + + uint16_t operator*() const; + void operator++(); + bool operator==(EndMarker const&) const { return end_; } + bool operator!=(EndMarker const& m) const { return !end_; } + + private: + StringCharacterStream* const stream_; + uint16_t current_; + bool end_; +}; + + +StringCharacterStreamIterator::StringCharacterStreamIterator( + StringCharacterStream* stream) : stream_(stream) { + ++(*this); +} + +uint16_t StringCharacterStreamIterator::operator*() const { + return current_; +} + + +void StringCharacterStreamIterator::operator++() { + end_ = !stream_->HasMore(); + if (!end_) { + current_ = stream_->GetNext(); + } +} +} // End anonymous namespace. + + double StringToDouble(UnicodeCache* unicode_cache, const char* str, int flags, double empty_string_val) { // We cast to const uint8_t* here to avoid instantiating the @@ -273,7 +319,6 @@ static char* CreateExponentialRepresentation(char* decimal_rep, } - char* DoubleToExponentialCString(double value, int f) { const int kMaxDigitsAfterPoint = 20; // f might be -1 to signal that f was undefined in JavaScript. @@ -460,4 +505,22 @@ char* DoubleToRadixCString(double value, int radix) { return builder.Finalize(); } + +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.IsAscii()) { + return StringToDouble( + unicode_cache, flat.ToOneByteVector(), flags, empty_string_val); + } else { + return StringToDouble( + unicode_cache, flat.ToUC16Vector(), flags, empty_string_val); + } +} + + } } // namespace v8::internal diff --git a/src/conversions.h b/src/conversions.h index c8484e4..12f895d 100644 --- a/src/conversions.h +++ b/src/conversions.h @@ -28,6 +28,11 @@ #ifndef V8_CONVERSIONS_H_ #define V8_CONVERSIONS_H_ +#include + +#include "checks.h" +#include "handles.h" +#include "objects.h" #include "utils.h" namespace v8 { @@ -163,6 +168,77 @@ char* DoubleToExponentialCString(double value, int f); char* DoubleToPrecisionCString(double value, int f); char* DoubleToRadixCString(double value, int radix); + +static inline bool IsMinusZero(double value) { + static const DoubleRepresentation minus_zero(-0.0); + return DoubleRepresentation(value) == minus_zero; +} + + +// Integer32 is an integer that can be represented as a signed 32-bit +// integer. It has to be in the range [-2^31, 2^31 - 1]. +// We also have to check for negative 0 as it is not an Integer32. +static inline bool IsInt32Double(double value) { + return !IsMinusZero(value) && + value >= kMinInt && + value <= kMaxInt && + value == FastI2D(FastD2I(value)); +} + + +// Convert from Number object to C integer. +inline int32_t NumberToInt32(Object* number) { + if (number->IsSmi()) return Smi::cast(number)->value(); + return DoubleToInt32(number->Number()); +} + + +inline uint32_t NumberToUint32(Object* number) { + if (number->IsSmi()) return Smi::cast(number)->value(); + return DoubleToUint32(number->Number()); +} + + +double StringToDouble(UnicodeCache* unicode_cache, + String* string, + int flags, + double empty_string_val = 0.0); + + +inline bool TryNumberToSize(Isolate* isolate, + Object* number, size_t* result) { + SealHandleScope shs(isolate); + if (number->IsSmi()) { + int value = Smi::cast(number)->value(); + ASSERT(static_cast(Smi::kMaxValue) + <= std::numeric_limits::max()); + if (value >= 0) { + *result = static_cast(value); + return true; + } + return false; + } else { + ASSERT(number->IsHeapNumber()); + double value = HeapNumber::cast(number)->value(); + if (value >= 0 && + value <= std::numeric_limits::max()) { + *result = static_cast(value); + return true; + } else { + return false; + } + } +} + +// Converts a number into size_t. +inline size_t NumberToSize(Isolate* isolate, + Object* number) { + size_t result = 0; + bool is_valid = TryNumberToSize(isolate, number, &result); + CHECK(is_valid); + return result; +} + } } // namespace v8::internal #endif // V8_CONVERSIONS_H_ diff --git a/src/elements.cc b/src/elements.cc index 79dc722..281d8b0 100644 --- a/src/elements.cc +++ b/src/elements.cc @@ -28,10 +28,10 @@ #include "v8.h" #include "arguments.h" -#include "objects.h" +#include "conversions.h" #include "elements.h" +#include "objects.h" #include "utils.h" -#include "v8conversions.h" // Each concrete ElementsAccessor can handle exactly one ElementsKind, // several abstract ElementsAccessor classes are used to allow sharing diff --git a/src/factory.cc b/src/factory.cc index 47a2d81..3c3b187 100644 --- a/src/factory.cc +++ b/src/factory.cc @@ -4,9 +4,9 @@ #include "factory.h" -#include "macro-assembler.h" +#include "conversions.h" #include "isolate-inl.h" -#include "v8conversions.h" +#include "macro-assembler.h" namespace v8 { namespace internal { diff --git a/src/heap-snapshot-generator.cc b/src/heap-snapshot-generator.cc index 08c0f49..cb04f62 100644 --- a/src/heap-snapshot-generator.cc +++ b/src/heap-snapshot-generator.cc @@ -31,10 +31,10 @@ #include "allocation-tracker.h" #include "code-stubs.h" -#include "heap-profiler.h" +#include "conversions.h" #include "debug.h" +#include "heap-profiler.h" #include "types.h" -#include "v8conversions.h" namespace v8 { namespace internal { diff --git a/src/heap.cc b/src/heap.cc index 0876783..ebf9f8f 100644 --- a/src/heap.cc +++ b/src/heap.cc @@ -32,6 +32,7 @@ #include "bootstrapper.h" #include "codegen.h" #include "compilation-cache.h" +#include "conversions.h" #include "cpu-profiler.h" #include "debug.h" #include "deoptimizer.h" @@ -50,7 +51,6 @@ #include "store-buffer.h" #include "utils/random-number-generator.h" #include "utils.h" -#include "v8conversions.h" #include "v8threads.h" #include "vm-state-inl.h" #if V8_TARGET_ARCH_ARM && !V8_INTERPRETED_REGEXP diff --git a/src/hydrogen-instructions.h b/src/hydrogen-instructions.h index d1684d7..55a5735 100644 --- a/src/hydrogen-instructions.h +++ b/src/hydrogen-instructions.h @@ -32,13 +32,13 @@ #include "allocation.h" #include "code-stubs.h" +#include "conversions.h" #include "data-flow.h" #include "deoptimizer.h" #include "small-pointer-list.h" #include "string-stream.h" #include "unique.h" #include "utils.h" -#include "v8conversions.h" #include "zone.h" namespace v8 { diff --git a/src/ic.cc b/src/ic.cc index 6480da1..09444b3 100644 --- a/src/ic.cc +++ b/src/ic.cc @@ -31,11 +31,11 @@ #include "api.h" #include "arguments.h" #include "codegen.h" +#include "conversions.h" #include "execution.h" #include "ic-inl.h" #include "runtime.h" #include "stub-cache.h" -#include "v8conversions.h" namespace v8 { namespace internal { diff --git a/src/incremental-marking.cc b/src/incremental-marking.cc index b8dab32..c533ce3 100644 --- a/src/incremental-marking.cc +++ b/src/incremental-marking.cc @@ -31,9 +31,9 @@ #include "code-stubs.h" #include "compilation-cache.h" +#include "conversions.h" #include "objects-visiting.h" #include "objects-visiting-inl.h" -#include "v8conversions.h" namespace v8 { namespace internal { diff --git a/src/json-parser.h b/src/json-parser.h index 8c19bc8..732e7ea 100644 --- a/src/json-parser.h +++ b/src/json-parser.h @@ -31,7 +31,7 @@ #include "v8.h" #include "char-predicates-inl.h" -#include "v8conversions.h" +#include "conversions.h" #include "messages.h" #include "spaces-inl.h" #include "token.h" diff --git a/src/json-stringifier.h b/src/json-stringifier.h index e6957eb..7c4a9b4 100644 --- a/src/json-stringifier.h +++ b/src/json-stringifier.h @@ -29,8 +29,8 @@ #define V8_JSON_STRINGIFIER_H_ #include "v8.h" +#include "conversions.h" #include "utils.h" -#include "v8conversions.h" namespace v8 { namespace internal { diff --git a/src/property-details-inl.h b/src/property-details-inl.h index 98eb1cf..8350452 100644 --- a/src/property-details-inl.h +++ b/src/property-details-inl.h @@ -28,9 +28,9 @@ #ifndef V8_PROPERTY_DETAILS_INL_H_ #define V8_PROPERTY_DETAILS_INL_H_ +#include "conversions.h" #include "objects.h" #include "property-details.h" -#include "v8conversions.h" namespace v8 { namespace internal { diff --git a/src/runtime.cc b/src/runtime.cc index f3946d3..c91c3f9 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -38,6 +38,7 @@ #include "codegen.h" #include "compilation-cache.h" #include "compiler.h" +#include "conversions.h" #include "cpu.h" #include "cpu-profiler.h" #include "dateparser-inl.h" @@ -63,7 +64,6 @@ #include "string-search.h" #include "stub-cache.h" #include "uri.h" -#include "v8conversions.h" #include "v8threads.h" #include "vm-state-inl.h" diff --git a/src/uri.h b/src/uri.h index 1b52a50..a8791bc 100644 --- a/src/uri.h +++ b/src/uri.h @@ -30,9 +30,9 @@ #include "v8.h" +#include "conversions.h" #include "string-search.h" #include "utils.h" -#include "v8conversions.h" namespace v8 { namespace internal { diff --git a/src/v8conversions.cc b/src/v8conversions.cc deleted file mode 100644 index b891a3e..0000000 --- a/src/v8conversions.cc +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright 2011 the V8 project authors. All rights reserved. -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following -// disclaimer in the documentation and/or other materials provided -// with the distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived -// from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#include -#include - -#include "v8.h" - -#include "assert-scope.h" -#include "conversions-inl.h" -#include "v8conversions.h" -#include "dtoa.h" -#include "factory.h" -#include "strtod.h" - -namespace v8 { -namespace internal { - -namespace { - -// C++-style iterator adaptor for StringCharacterStream -// (unlike C++ iterators the end-marker has different type). -class StringCharacterStreamIterator { - public: - class EndMarker {}; - - explicit StringCharacterStreamIterator(StringCharacterStream* stream); - - uint16_t operator*() const; - void operator++(); - bool operator==(EndMarker const&) const { return end_; } - bool operator!=(EndMarker const& m) const { return !end_; } - - private: - StringCharacterStream* const stream_; - uint16_t current_; - bool end_; -}; - - -StringCharacterStreamIterator::StringCharacterStreamIterator( - StringCharacterStream* stream) : stream_(stream) { - ++(*this); -} - -uint16_t StringCharacterStreamIterator::operator*() const { - return current_; -} - - -void StringCharacterStreamIterator::operator++() { - end_ = !stream_->HasMore(); - if (!end_) { - current_ = stream_->GetNext(); - } -} -} // End anonymous namespace. - - -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.IsAscii()) { - return StringToDouble( - unicode_cache, flat.ToOneByteVector(), flags, empty_string_val); - } else { - return StringToDouble( - unicode_cache, flat.ToUC16Vector(), flags, empty_string_val); - } -} - -} } // namespace v8::internal diff --git a/src/v8conversions.h b/src/v8conversions.h deleted file mode 100644 index eb315b1..0000000 --- a/src/v8conversions.h +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright 2011 the V8 project authors. All rights reserved. -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following -// disclaimer in the documentation and/or other materials provided -// with the distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived -// from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#ifndef V8_V8CONVERSIONS_H_ -#define V8_V8CONVERSIONS_H_ - -#include "conversions.h" - -namespace v8 { -namespace internal { - - -static inline bool IsMinusZero(double value) { - static const DoubleRepresentation minus_zero(-0.0); - return DoubleRepresentation(value) == minus_zero; -} - - -// Integer32 is an integer that can be represented as a signed 32-bit -// integer. It has to be in the range [-2^31, 2^31 - 1]. -// We also have to check for negative 0 as it is not an Integer32. -static inline bool IsInt32Double(double value) { - return !IsMinusZero(value) && - value >= kMinInt && - value <= kMaxInt && - value == FastI2D(FastD2I(value)); -} - - -// Convert from Number object to C integer. -inline int32_t NumberToInt32(Object* number) { - if (number->IsSmi()) return Smi::cast(number)->value(); - return DoubleToInt32(number->Number()); -} - - -inline uint32_t NumberToUint32(Object* number) { - if (number->IsSmi()) return Smi::cast(number)->value(); - return DoubleToUint32(number->Number()); -} - - -double StringToDouble(UnicodeCache* unicode_cache, - String* string, - int flags, - double empty_string_val = 0.0); - - -inline bool TryNumberToSize(Isolate* isolate, - Object* number, size_t* result) { - SealHandleScope shs(isolate); - if (number->IsSmi()) { - int value = Smi::cast(number)->value(); - ASSERT(static_cast(Smi::kMaxValue) - <= std::numeric_limits::max()); - if (value >= 0) { - *result = static_cast(value); - return true; - } - return false; - } else { - ASSERT(number->IsHeapNumber()); - double value = HeapNumber::cast(number)->value(); - if (value >= 0 && - value <= std::numeric_limits::max()) { - *result = static_cast(value); - return true; - } else { - return false; - } - } -} - -// Converts a number into size_t. -inline size_t NumberToSize(Isolate* isolate, - Object* number) { - size_t result = 0; - bool is_valid = TryNumberToSize(isolate, number, &result); - CHECK(is_valid); - return result; -} - -} } // namespace v8::internal - -#endif // V8_V8CONVERSIONS_H_ diff --git a/tools/gyp/v8.gyp b/tools/gyp/v8.gyp index bf345cc..9f3003b 100644 --- a/tools/gyp/v8.gyp +++ b/tools/gyp/v8.gyp @@ -595,8 +595,6 @@ '../../src/v8.cc', '../../src/v8.h', '../../src/v8checks.h', - '../../src/v8conversions.cc', - '../../src/v8conversions.h', '../../src/v8globals.h', '../../src/v8memory.h', '../../src/v8threads.cc',