X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/6fe7ccc865dc7d7541b93c5bcaf6368d2c98a174..4be4e30906bcb8ee30b4d189205cb70bad6707ce:/runtime/JSStringJoiner.cpp diff --git a/runtime/JSStringJoiner.cpp b/runtime/JSStringJoiner.cpp index ea26024..b6461c7 100644 --- a/runtime/JSStringJoiner.cpp +++ b/runtime/JSStringJoiner.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012 Apple Inc. All rights reserved. + * Copyright (C) 2012, 2013 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,15 +27,15 @@ #include "JSStringJoiner.h" #include "ExceptionHelpers.h" +#include "JSScope.h" #include "JSString.h" -#include "ScopeChain.h" +#include "Operations.h" #include - namespace JSC { // The destination is 16bits, at least one string is 16 bits. -static inline void appendStringToData(UChar*& data, const UString& string) +static inline void appendStringToData(UChar*& data, const String& string) { if (string.isNull()) return; @@ -57,7 +57,7 @@ static inline void appendStringToData(UChar*& data, const UString& string) } // If the destination is 8bits, we know every string has to be 8bit. -static inline void appendStringToData(LChar*& data, const UString& string) +static inline void appendStringToData(LChar*& data, const String& string) { if (string.isNull()) return; @@ -73,7 +73,7 @@ static inline void appendStringToData(LChar*& data, const UString& string) } template -static inline PassRefPtr joinStrings(const Vector& strings, const UString& separator, unsigned outputLength) +static inline PassRefPtr joinStrings(const Vector& strings, const String& separator, unsigned outputLength) { ASSERT(outputLength); @@ -82,7 +82,7 @@ static inline PassRefPtr joinStrings(const Vector& strings, if (!outputStringImpl) return PassRefPtr(); - const UString firstString = strings.first(); + const String firstString = strings.first(); appendStringToData(data, firstString); for (size_t i = 1; i < strings.size(); ++i) { @@ -94,7 +94,7 @@ static inline PassRefPtr joinStrings(const Vector& strings, return outputStringImpl.release(); } -JSValue JSStringJoiner::build(ExecState* exec) +JSValue JSStringJoiner::join(ExecState* exec) { if (!m_isValid) return throwOutOfMemoryError(exec); @@ -102,25 +102,29 @@ JSValue JSStringJoiner::build(ExecState* exec) if (!m_strings.size()) return jsEmptyString(exec); - size_t separatorLength = m_separator.length(); + Checked separatorLength = m_separator.length(); // FIXME: add special cases of joinStrings() for (separatorLength == 0) and (separatorLength == 1). ASSERT(m_strings.size() > 0); - size_t totalSeparactorsLength = separatorLength * (m_strings.size() - 1); - size_t outputStringSize = totalSeparactorsLength + m_cumulatedStringsLength; + Checked totalSeparactorsLength = separatorLength * (m_strings.size() - 1); + Checked outputStringSize = totalSeparactorsLength + m_accumulatedStringsLength; + unsigned finalSize; + if (outputStringSize.safeGet(finalSize) == CheckedState::DidOverflow) + return throwOutOfMemoryError(exec); + if (!outputStringSize) return jsEmptyString(exec); RefPtr outputStringImpl; if (m_is8Bits) - outputStringImpl = joinStrings(m_strings, m_separator, outputStringSize); + outputStringImpl = joinStrings(m_strings, m_separator, finalSize); else - outputStringImpl = joinStrings(m_strings, m_separator, outputStringSize); + outputStringImpl = joinStrings(m_strings, m_separator, finalSize); if (!outputStringImpl) return throwOutOfMemoryError(exec); - return JSString::create(exec->globalData(), outputStringImpl.release()); + return JSString::create(exec->vm(), outputStringImpl.release()); } }