Reviewers: danno,
Message:
Test for http://code.google.com/p/v8/source/detail?r=11212
Description:
Regression test for large string joins.
BUG=none
TEST=New test for join.
Please review this at http://codereview.chromium.org/9963104/
SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/
Affected files:
M test/cctest/SConscript
A test/cctest/test-ascii-array-join.cc
Index: test/cctest/SConscript
===================================================================
--- test/cctest/SConscript (revision 11218)
+++ test/cctest/SConscript (working copy)
@@ -54,6 +54,7 @@
'test-accessors.cc',
'test-alloc.cc',
'test-api.cc',
+ 'test-ascii-array-join.cc',
'test-ast.cc',
'test-bignum-dtoa.cc',
'test-bignum.cc',
Index: test/cctest/test-ascii-array-join.cc
===================================================================
--- test/cctest/test-ascii-array-join.cc (revision 0)
+++ test/cctest/test-ascii-array-join.cc (revision 0)
@@ -0,0 +1,85 @@
+// Copyright 2012 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 <limits.h>
+
+#include "v8.h"
+
+#include "api.h"
+#include "isolate.h"
+#include "compilation-cache.h"
+#include "execution.h"
+#include "snapshot.h"
+#include "platform.h"
+#include "utils.h"
+#include "cctest.h"
+#include "parser.h"
+#include "unicode-inl.h"
+
+static const bool kLogThreading = false;
+
+using ::v8::Local;
+using ::v8::Script;
+using ::v8::String;
+using ::v8::Value;
+
+
+// string s is made of 2^17 = 131072 'c' characters.
+// a is an array starting with 'bad', followed by 2^14 times the string s.
+// That means the total length of the concatenated strings is 2^31 + 3.
+// So on 32bits systems summing the lengths of the strings (as smis)
overflows
+// and wraps.
+static const char* join_causing_out_of_memory =
+ "var two_14 = Math.pow(2, 14);"
+ "var two_17 = Math.pow(2, 17);"
+ "var s = Array(two_17 + 1).join('c');"
+ "var a = ['bad'];"
+ "for (var i = 1; i <= two_14; i++) a.push(s);"
+ "a.join("");";
+
+
+TEST(AsciiArrayJoin) {
+ // Set heap limits.
+ static const int K = 1024;
+ v8::ResourceConstraints constraints;
+ constraints.set_max_young_space_size(256 * K);
+ constraints.set_max_old_space_size(4 * K * K);
+ v8::SetResourceConstraints(&constraints);
+
+ v8::HandleScope scope;
+ LocalContext context;
+ v8::V8::IgnoreOutOfMemoryException();
+ Local<Script> script =
+ Script::Compile(String::New(join_causing_out_of_memory));
+ Local<Value> result = script->Run();
+
+ // Check for out of memory state.
+ CHECK(result.IsEmpty());
+ CHECK(context->HasOutOfMemoryException());
+}
+
+
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev