diff options
author | Allan Sandfeld Jensen <allan.jensen@digia.com> | 2013-09-13 12:51:20 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-19 20:50:05 +0200 |
commit | d441d6f39bb846989d95bcf5caf387b42414718d (patch) | |
tree | e367e64a75991c554930278175d403c072de6bb8 /Source/JavaScriptCore/runtime/JSStringJoiner.cpp | |
parent | 0060b2994c07842f4c59de64b5e3e430525c4b90 (diff) | |
download | qtwebkit-d441d6f39bb846989d95bcf5caf387b42414718d.tar.gz |
Import Qt5x2 branch of QtWebkit for Qt 5.2
Importing a new snapshot of webkit.
Change-Id: I2d01ad12cdc8af8cb015387641120a9d7ea5f10c
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@digia.com>
Diffstat (limited to 'Source/JavaScriptCore/runtime/JSStringJoiner.cpp')
-rw-r--r-- | Source/JavaScriptCore/runtime/JSStringJoiner.cpp | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/Source/JavaScriptCore/runtime/JSStringJoiner.cpp b/Source/JavaScriptCore/runtime/JSStringJoiner.cpp index cbf9ba48b..7e20d2195 100644 --- a/Source/JavaScriptCore/runtime/JSStringJoiner.cpp +++ b/Source/JavaScriptCore/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 @@ -29,9 +29,9 @@ #include "ExceptionHelpers.h" #include "JSScope.h" #include "JSString.h" +#include "Operations.h" #include <wtf/text/StringImpl.h> - namespace JSC { // The destination is 16bits, at least one string is 16 bits. @@ -94,7 +94,7 @@ static inline PassRefPtr<StringImpl> joinStrings(const Vector<String>& 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<size_t, RecordOverflow> 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<size_t, RecordOverflow> totalSeparactorsLength = separatorLength * (m_strings.size() - 1); + Checked<size_t, RecordOverflow> outputStringSize = totalSeparactorsLength + m_accumulatedStringsLength; + size_t finalSize; + if (outputStringSize.safeGet(finalSize) == CheckedState::DidOverflow) + return throwOutOfMemoryError(exec); + if (!outputStringSize) return jsEmptyString(exec); RefPtr<StringImpl> outputStringImpl; if (m_is8Bits) - outputStringImpl = joinStrings<LChar>(m_strings, m_separator, outputStringSize); + outputStringImpl = joinStrings<LChar>(m_strings, m_separator, finalSize); else - outputStringImpl = joinStrings<UChar>(m_strings, m_separator, outputStringSize); + outputStringImpl = joinStrings<UChar>(m_strings, m_separator, finalSize); if (!outputStringImpl) return throwOutOfMemoryError(exec); - return JSString::create(exec->globalData(), outputStringImpl.release()); + return JSString::create(exec->vm(), outputStringImpl.release()); } } |