Update V8 to r6101 as required by WebKit r74534
Change-Id: I7f84af8dd732f11898fd644b2c2b1538914cb78d
diff --git a/test/cctest/SConscript b/test/cctest/SConscript
index ba3466d..7038137 100644
--- a/test/cctest/SConscript
+++ b/test/cctest/SConscript
@@ -50,6 +50,7 @@
'test-dataflow.cc',
'test-debug.cc',
'test-decls.cc',
+ 'test-deoptimization.cc',
'test-diy-fp.cc',
'test-double.cc',
'test-dtoa.cc',
@@ -69,6 +70,7 @@
'test-parsing.cc',
'test-profile-generator.cc',
'test-regexp.cc',
+ 'test-reloc-info.cc',
'test-serialize.cc',
'test-sockets.cc',
'test-spaces.cc',
diff --git a/test/cctest/cctest.gyp b/test/cctest/cctest.gyp
new file mode 100644
index 0000000..aa2b355
--- /dev/null
+++ b/test/cctest/cctest.gyp
@@ -0,0 +1,160 @@
+# Copyright 2010 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.
+
+{
+ 'target_defaults': {
+ 'conditions': [
+ ['OS!="mac"', {
+ # TODO(sgjesse): This is currently copied from v8.gyp, should probably
+ # be refactored.
+ 'conditions': [
+ ['v8_target_arch=="arm"', {
+ 'defines': [
+ 'V8_TARGET_ARCH_ARM',
+ ],
+ }],
+ ['v8_target_arch=="ia32"', {
+ 'defines': [
+ 'V8_TARGET_ARCH_IA32',
+ ],
+ }],
+ ['v8_target_arch=="x64"', {
+ 'defines': [
+ 'V8_TARGET_ARCH_X64',
+ ],
+ }],
+ ],
+ }],
+ ],
+ },
+ 'targets': [
+ {
+ 'target_name': 'cctest',
+ 'type': 'executable',
+ 'dependencies': [
+ '../../tools/gyp/v8.gyp:v8',
+ ],
+ 'include_dirs': [
+ '../../src',
+ ],
+ 'sources': [
+ 'cctest.cc',
+ 'gay-fixed.cc',
+ 'gay-precision.cc',
+ 'gay-shortest.cc',
+ 'test-accessors.cc',
+ 'test-alloc.cc',
+ 'test-api.cc',
+ 'test-ast.cc',
+ 'test-bignum.cc',
+ 'test-bignum-dtoa.cc',
+ 'test-circular-queue.cc',
+ 'test-compiler.cc',
+ 'test-conversions.cc',
+ 'test-cpu-profiler.cc',
+ 'test-dataflow.cc',
+ 'test-debug.cc',
+ 'test-decls.cc',
+ 'test-deoptimization.cc',
+ 'test-diy-fp.cc',
+ 'test-double.cc',
+ 'test-dtoa.cc',
+ 'test-fast-dtoa.cc',
+ 'test-fixed-dtoa.cc',
+ 'test-flags.cc',
+ 'test-func-name-inference.cc',
+ 'test-hashmap.cc',
+ 'test-heap.cc',
+ 'test-heap-profiler.cc',
+ 'test-list.cc',
+ 'test-liveedit.cc',
+ 'test-lock.cc',
+ 'test-log.cc',
+ 'test-log-utils.cc',
+ 'test-mark-compact.cc',
+ 'test-parsing.cc',
+ 'test-profile-generator.cc',
+ 'test-regexp.cc',
+ 'test-reloc-info.cc',
+ 'test-serialize.cc',
+ 'test-sockets.cc',
+ 'test-spaces.cc',
+ 'test-strings.cc',
+ 'test-strtod.cc',
+ 'test-thread-termination.cc',
+ 'test-threads.cc',
+ 'test-type-info.cc',
+ 'test-unbound-queue.cc',
+ 'test-utils.cc',
+ 'test-version.cc'
+ ],
+ 'conditions': [
+ ['v8_target_arch=="ia32"', {
+ 'sources': [
+ 'test-assembler-ia32.cc',
+ 'test-disasm-ia32.cc',
+ 'test-log-stack-tracer.cc'
+ ],
+ }],
+ ['v8_target_arch=="x64"', {
+ 'sources': [
+ 'test-assembler-x64.cc',
+ 'test-macro-assembler-x64.cc',
+ 'test-log-stack-tracer.cc'
+ ],
+ }],
+ ['v8_target_arch=="arm"', {
+ 'sources': [
+ 'test-assembler-arm.cc',
+ 'test-disasm-arm.cc'
+ ],
+ }],
+ ['v8_target_arch=="mips"', {
+ 'sources': [
+ 'test-assembler-mips.cc',
+ 'test-mips.cc',
+ ],
+ }],
+ [ 'OS=="linux"', {
+ 'sources': [
+ 'test-platform-linux.cc',
+ ],
+ }],
+ [ 'OS=="mac"', {
+ 'sources': [
+ 'test-platform-macos.cc',
+ ],
+ }],
+ [ 'OS=="win"', {
+ 'sources': [
+ 'test-platform-win32.cc',
+ ],
+ }],
+ ],
+ },
+ ],
+}
diff --git a/test/cctest/cctest.status b/test/cctest/cctest.status
index 895e245..4dfe51a 100644
--- a/test/cctest/cctest.status
+++ b/test/cctest/cctest.status
@@ -29,19 +29,40 @@
test-api/Bug*: FAIL
+
+##############################################################################
# BUG(281): This test fails on some Linuxes.
test-debug/DebuggerAgent: PASS, (PASS || FAIL) if $system == linux
# BUG(382): Weird test. Can't guarantee that it never times out.
test-api/ApplyInterruption: PASS || TIMEOUT
+# BUG(484): This test which we thought was originally corrected in r5236
+# is re-appearing. Disabled until bug in test is fixed. This only fails
+# when snapshot is on, so I am marking it PASS || FAIL
+test-heap-profiler/HeapSnapshotsDiff: PASS || FAIL
+
# These tests always fail. They are here to test test.py. If
# they don't fail then test.py has failed.
test-serialize/TestThatAlwaysFails: FAIL
test-serialize/DependentTestThatAlwaysFails: FAIL
+
+##############################################################################
+[ $arch == x64 ]
+
+# Optimization is currently not working on crankshaft x64 and ARM.
+test-heap/TestInternalWeakLists: PASS || FAIL
+test-heap/TestInternalWeakListsTraverseWithGC: PASS || FAIL
+
+
+##############################################################################
[ $arch == arm ]
+# Optimization is currently not working on crankshaft x64 and ARM.
+test-heap/TestInternalWeakLists: PASS || FAIL
+test-heap/TestInternalWeakListsTraverseWithGC: PASS || FAIL
+
# We cannot assume that we can throw OutOfMemory exceptions in all situations.
# Apparently our ARM box is in such a state. Skip the test as it also runs for
# a long time.
@@ -51,6 +72,23 @@
# BUG(355): Test crashes on ARM.
test-log/ProfLazyMode: SKIP
+# BUG(945): Socket connect fails on ARM
+test-debug/DebuggerAgentProtocolOverflowHeader: SKIP
+test-sockets/Socket: SKIP
+
+
+##############################################################################
+[ $arch == arm && $crankshaft ]
+
+# Tests that fail with crankshaft.
+test-deoptimization/DeoptimizeBinaryOperationMOD: FAIL
+
+# Tests that time out with crankshaft.
+test-debug/ThreadedDebugging: SKIP
+test-debug/DebugBreakLoop: SKIP
+
+
+##############################################################################
[ $arch == mips ]
test-accessors: SKIP
test-alloc: SKIP
diff --git a/test/cctest/test-alloc.cc b/test/cctest/test-alloc.cc
index fcf2ce4..d2a28d7 100644
--- a/test/cctest/test-alloc.cc
+++ b/test/cctest/test-alloc.cc
@@ -133,7 +133,7 @@
// Force the creation of an initial map and set the code to
// something empty.
Factory::NewJSObject(function);
- function->set_code(Builtins::builtin(Builtins::EmptyFunction));
+ function->ReplaceCode(Builtins::builtin(Builtins::EmptyFunction));
// Patch the map to have an accessor for "get".
Handle<Map> map(function->initial_map());
Handle<DescriptorArray> instance_descriptors(map->instance_descriptors());
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index 4af0c52..9539973 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -814,79 +814,6 @@
}
-static void* expected_ptr;
-static v8::Handle<v8::Value> callback(const v8::Arguments& args) {
- void* ptr = v8::External::Unwrap(args.Data());
- CHECK_EQ(expected_ptr, ptr);
- return v8::Boolean::New(true);
-}
-
-
-static void TestExternalPointerWrapping() {
- v8::HandleScope scope;
- LocalContext env;
-
- v8::Handle<v8::Value> data = v8::External::Wrap(expected_ptr);
-
- v8::Handle<v8::Object> obj = v8::Object::New();
- obj->Set(v8_str("func"),
- v8::FunctionTemplate::New(callback, data)->GetFunction());
- env->Global()->Set(v8_str("obj"), obj);
-
- CHECK(CompileRun(
- "function foo() {\n"
- " for (var i = 0; i < 13; i++) obj.func();\n"
- "}\n"
- "foo(), true")->BooleanValue());
-}
-
-
-THREADED_TEST(ExternalWrap) {
- // Check heap allocated object.
- int* ptr = new int;
- expected_ptr = ptr;
- TestExternalPointerWrapping();
- delete ptr;
-
- // Check stack allocated object.
- int foo;
- expected_ptr = &foo;
- TestExternalPointerWrapping();
-
- // Check not aligned addresses.
- const int n = 100;
- char* s = new char[n];
- for (int i = 0; i < n; i++) {
- expected_ptr = s + i;
- TestExternalPointerWrapping();
- }
-
- delete[] s;
-
- // Check several invalid addresses.
- expected_ptr = reinterpret_cast<void*>(1);
- TestExternalPointerWrapping();
-
- expected_ptr = reinterpret_cast<void*>(0xdeadbeef);
- TestExternalPointerWrapping();
-
- expected_ptr = reinterpret_cast<void*>(0xdeadbeef + 1);
- TestExternalPointerWrapping();
-
-#if defined(V8_HOST_ARCH_X64)
- // Check a value with a leading 1 bit in x64 Smi encoding.
- expected_ptr = reinterpret_cast<void*>(0x400000000);
- TestExternalPointerWrapping();
-
- expected_ptr = reinterpret_cast<void*>(0xdeadbeefdeadbeef);
- TestExternalPointerWrapping();
-
- expected_ptr = reinterpret_cast<void*>(0xdeadbeefdeadbeef + 1);
- TestExternalPointerWrapping();
-#endif
-}
-
-
THREADED_TEST(FindInstanceInPrototypeChain) {
v8::HandleScope scope;
LocalContext env;
@@ -4417,47 +4344,167 @@
}
+static int StrCmp16(uint16_t* a, uint16_t* b) {
+ while (true) {
+ if (*a == 0 && *b == 0) return 0;
+ if (*a != *b) return 0 + *a - *b;
+ a++;
+ b++;
+ }
+}
+
+
+static int StrNCmp16(uint16_t* a, uint16_t* b, int n) {
+ while (true) {
+ if (n-- == 0) return 0;
+ if (*a == 0 && *b == 0) return 0;
+ if (*a != *b) return 0 + *a - *b;
+ a++;
+ b++;
+ }
+}
+
+
THREADED_TEST(StringWrite) {
v8::HandleScope scope;
v8::Handle<String> str = v8_str("abcde");
+ // abc<Icelandic eth><Unicode snowman>.
+ v8::Handle<String> str2 = v8_str("abc\303\260\342\230\203");
+
+ CHECK_EQ(5, str2->Length());
char buf[100];
+ char utf8buf[100];
+ uint16_t wbuf[100];
int len;
+ int charlen;
+
+ memset(utf8buf, 0x1, sizeof(utf8buf));
+ len = str2->WriteUtf8(utf8buf, sizeof(utf8buf), &charlen);
+ CHECK_EQ(len, 9);
+ CHECK_EQ(charlen, 5);
+ CHECK_EQ(strcmp(utf8buf, "abc\303\260\342\230\203"), 0);
+
+ memset(utf8buf, 0x1, sizeof(utf8buf));
+ len = str2->WriteUtf8(utf8buf, 8, &charlen);
+ CHECK_EQ(len, 8);
+ CHECK_EQ(charlen, 5);
+ CHECK_EQ(strncmp(utf8buf, "abc\303\260\342\230\203\1", 9), 0);
+
+ memset(utf8buf, 0x1, sizeof(utf8buf));
+ len = str2->WriteUtf8(utf8buf, 7, &charlen);
+ CHECK_EQ(len, 5);
+ CHECK_EQ(charlen, 4);
+ CHECK_EQ(strncmp(utf8buf, "abc\303\260\1", 5), 0);
+
+ memset(utf8buf, 0x1, sizeof(utf8buf));
+ len = str2->WriteUtf8(utf8buf, 6, &charlen);
+ CHECK_EQ(len, 5);
+ CHECK_EQ(charlen, 4);
+ CHECK_EQ(strncmp(utf8buf, "abc\303\260\1", 5), 0);
+
+ memset(utf8buf, 0x1, sizeof(utf8buf));
+ len = str2->WriteUtf8(utf8buf, 5, &charlen);
+ CHECK_EQ(len, 5);
+ CHECK_EQ(charlen, 4);
+ CHECK_EQ(strncmp(utf8buf, "abc\303\260\1", 5), 0);
+
+ memset(utf8buf, 0x1, sizeof(utf8buf));
+ len = str2->WriteUtf8(utf8buf, 4, &charlen);
+ CHECK_EQ(len, 3);
+ CHECK_EQ(charlen, 3);
+ CHECK_EQ(strncmp(utf8buf, "abc\1", 4), 0);
+
+ memset(utf8buf, 0x1, sizeof(utf8buf));
+ len = str2->WriteUtf8(utf8buf, 3, &charlen);
+ CHECK_EQ(len, 3);
+ CHECK_EQ(charlen, 3);
+ CHECK_EQ(strncmp(utf8buf, "abc\1", 4), 0);
+
+ memset(utf8buf, 0x1, sizeof(utf8buf));
+ len = str2->WriteUtf8(utf8buf, 2, &charlen);
+ CHECK_EQ(len, 2);
+ CHECK_EQ(charlen, 2);
+ CHECK_EQ(strncmp(utf8buf, "ab\1", 3), 0);
memset(buf, 0x1, sizeof(buf));
+ memset(wbuf, 0x1, sizeof(wbuf));
len = str->WriteAscii(buf);
CHECK_EQ(len, 5);
- CHECK_EQ(strncmp("abcde\0", buf, 6), 0);
+ len = str->Write(wbuf);
+ CHECK_EQ(len, 5);
+ CHECK_EQ(strcmp("abcde", buf), 0);
+ uint16_t answer1[] = {'a', 'b', 'c', 'd', 'e', '\0'};
+ CHECK_EQ(StrCmp16(answer1, wbuf), 0);
memset(buf, 0x1, sizeof(buf));
+ memset(wbuf, 0x1, sizeof(wbuf));
len = str->WriteAscii(buf, 0, 4);
CHECK_EQ(len, 4);
+ len = str->Write(wbuf, 0, 4);
+ CHECK_EQ(len, 4);
CHECK_EQ(strncmp("abcd\1", buf, 5), 0);
+ uint16_t answer2[] = {'a', 'b', 'c', 'd', 0x101};
+ CHECK_EQ(StrNCmp16(answer2, wbuf, 5), 0);
memset(buf, 0x1, sizeof(buf));
+ memset(wbuf, 0x1, sizeof(wbuf));
len = str->WriteAscii(buf, 0, 5);
CHECK_EQ(len, 5);
+ len = str->Write(wbuf, 0, 5);
+ CHECK_EQ(len, 5);
CHECK_EQ(strncmp("abcde\1", buf, 6), 0);
+ uint16_t answer3[] = {'a', 'b', 'c', 'd', 'e', 0x101};
+ CHECK_EQ(StrNCmp16(answer3, wbuf, 6), 0);
memset(buf, 0x1, sizeof(buf));
+ memset(wbuf, 0x1, sizeof(wbuf));
len = str->WriteAscii(buf, 0, 6);
CHECK_EQ(len, 5);
- CHECK_EQ(strncmp("abcde\0", buf, 6), 0);
+ len = str->Write(wbuf, 0, 6);
+ CHECK_EQ(len, 5);
+ CHECK_EQ(strcmp("abcde", buf), 0);
+ uint16_t answer4[] = {'a', 'b', 'c', 'd', 'e', '\0'};
+ CHECK_EQ(StrCmp16(answer4, wbuf), 0);
memset(buf, 0x1, sizeof(buf));
+ memset(wbuf, 0x1, sizeof(wbuf));
len = str->WriteAscii(buf, 4, -1);
CHECK_EQ(len, 1);
- CHECK_EQ(strncmp("e\0", buf, 2), 0);
+ len = str->Write(wbuf, 4, -1);
+ CHECK_EQ(len, 1);
+ CHECK_EQ(strcmp("e", buf), 0);
+ uint16_t answer5[] = {'e', '\0'};
+ CHECK_EQ(StrCmp16(answer5, wbuf), 0);
memset(buf, 0x1, sizeof(buf));
+ memset(wbuf, 0x1, sizeof(wbuf));
len = str->WriteAscii(buf, 4, 6);
CHECK_EQ(len, 1);
- CHECK_EQ(strncmp("e\0", buf, 2), 0);
+ len = str->Write(wbuf, 4, 6);
+ CHECK_EQ(len, 1);
+ CHECK_EQ(strcmp("e", buf), 0);
+ CHECK_EQ(StrCmp16(answer5, wbuf), 0);
memset(buf, 0x1, sizeof(buf));
+ memset(wbuf, 0x1, sizeof(wbuf));
len = str->WriteAscii(buf, 4, 1);
CHECK_EQ(len, 1);
+ len = str->Write(wbuf, 4, 1);
+ CHECK_EQ(len, 1);
CHECK_EQ(strncmp("e\1", buf, 2), 0);
+ uint16_t answer6[] = {'e', 0x101};
+ CHECK_EQ(StrNCmp16(answer6, wbuf, 2), 0);
+
+ memset(buf, 0x1, sizeof(buf));
+ memset(wbuf, 0x1, sizeof(wbuf));
+ len = str->WriteAscii(buf, 3, 1);
+ CHECK_EQ(len, 1);
+ len = str->Write(wbuf, 3, 1);
+ CHECK_EQ(len, 1);
+ CHECK_EQ(strncmp("d\1", buf, 2), 0);
+ uint16_t answer7[] = {'d', 0x101};
+ CHECK_EQ(StrNCmp16(answer7, wbuf, 2), 0);
}
@@ -5133,13 +5180,11 @@
}
-static bool allowed_access_type[v8::ACCESS_KEYS + 1] = { false };
static bool NamedAccessBlocker(Local<v8::Object> global,
Local<Value> name,
v8::AccessType type,
Local<Value> data) {
- return Context::GetCurrent()->Global()->Equals(global) ||
- allowed_access_type[type];
+ return Context::GetCurrent()->Global()->Equals(global);
}
@@ -5147,8 +5192,7 @@
uint32_t key,
v8::AccessType type,
Local<Value> data) {
- return Context::GetCurrent()->Global()->Equals(global) ||
- allowed_access_type[type];
+ return Context::GetCurrent()->Global()->Equals(global);
}
@@ -5180,7 +5224,7 @@
}
-TEST(AccessControl) {
+THREADED_TEST(AccessControl) {
v8::HandleScope handle_scope;
v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
@@ -5206,27 +5250,6 @@
v8::Handle<v8::Object> global0 = context0->Global();
- // Define a property with JS getter and setter.
- CompileRun(
- "function getter() { return 'getter'; };\n"
- "function setter() { return 'setter'; }\n"
- "Object.defineProperty(this, 'js_accessor_p', {get:getter, set:setter})");
-
- Local<Value> getter = global0->Get(v8_str("getter"));
- Local<Value> setter = global0->Get(v8_str("setter"));
-
- // And define normal element.
- global0->Set(239, v8_str("239"));
-
- // Define an element with JS getter and setter.
- CompileRun(
- "function el_getter() { return 'el_getter'; };\n"
- "function el_setter() { return 'el_setter'; };\n"
- "Object.defineProperty(this, '42', {get: el_getter, set: el_setter});");
-
- Local<Value> el_getter = global0->Get(v8_str("el_getter"));
- Local<Value> el_setter = global0->Get(v8_str("el_setter"));
-
v8::HandleScope scope1;
v8::Persistent<Context> context1 = Context::New();
@@ -5235,187 +5258,40 @@
v8::Handle<v8::Object> global1 = context1->Global();
global1->Set(v8_str("other"), global0);
- // Access blocked property.
- CompileRun("other.blocked_prop = 1");
-
- ExpectUndefined("other.blocked_prop");
- ExpectUndefined(
- "Object.getOwnPropertyDescriptor(other, 'blocked_prop')");
- ExpectFalse("propertyIsEnumerable.call(other, 'blocked_prop')");
-
- // Enable ACCESS_HAS
- allowed_access_type[v8::ACCESS_HAS] = true;
- ExpectUndefined("other.blocked_prop");
- // ... and now we can get the descriptor...
- ExpectUndefined(
- "Object.getOwnPropertyDescriptor(other, 'blocked_prop').value");
- // ... and enumerate the property.
- ExpectTrue("propertyIsEnumerable.call(other, 'blocked_prop')");
- allowed_access_type[v8::ACCESS_HAS] = false;
-
- // Access blocked element.
- CompileRun("other[239] = 1");
-
- ExpectUndefined("other[239]");
- ExpectUndefined("Object.getOwnPropertyDescriptor(other, '239')");
- ExpectFalse("propertyIsEnumerable.call(other, '239')");
-
- // Enable ACCESS_HAS
- allowed_access_type[v8::ACCESS_HAS] = true;
- ExpectUndefined("other[239]");
- // ... and now we can get the descriptor...
- ExpectUndefined("Object.getOwnPropertyDescriptor(other, '239').value");
- // ... and enumerate the property.
- ExpectTrue("propertyIsEnumerable.call(other, '239')");
- allowed_access_type[v8::ACCESS_HAS] = false;
-
- // Access a property with JS accessor.
- CompileRun("other.js_accessor_p = 2");
-
- ExpectUndefined("other.js_accessor_p");
- ExpectUndefined(
- "Object.getOwnPropertyDescriptor(other, 'js_accessor_p')");
-
- // Enable ACCESS_HAS.
- allowed_access_type[v8::ACCESS_HAS] = true;
- ExpectUndefined("other.js_accessor_p");
- ExpectUndefined(
- "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').get");
- ExpectUndefined(
- "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').set");
- ExpectUndefined(
- "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').value");
- allowed_access_type[v8::ACCESS_HAS] = false;
-
- // Enable both ACCESS_HAS and ACCESS_GET.
- allowed_access_type[v8::ACCESS_HAS] = true;
- allowed_access_type[v8::ACCESS_GET] = true;
-
- ExpectString("other.js_accessor_p", "getter");
- ExpectObject(
- "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').get", getter);
- ExpectUndefined(
- "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').set");
- ExpectUndefined(
- "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').value");
-
- allowed_access_type[v8::ACCESS_GET] = false;
- allowed_access_type[v8::ACCESS_HAS] = false;
-
- // Enable both ACCESS_HAS and ACCESS_SET.
- allowed_access_type[v8::ACCESS_HAS] = true;
- allowed_access_type[v8::ACCESS_SET] = true;
-
- ExpectUndefined("other.js_accessor_p");
- ExpectUndefined(
- "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').get");
- ExpectObject(
- "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').set", setter);
- ExpectUndefined(
- "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').value");
-
- allowed_access_type[v8::ACCESS_SET] = false;
- allowed_access_type[v8::ACCESS_HAS] = false;
-
- // Enable both ACCESS_HAS, ACCESS_GET and ACCESS_SET.
- allowed_access_type[v8::ACCESS_HAS] = true;
- allowed_access_type[v8::ACCESS_GET] = true;
- allowed_access_type[v8::ACCESS_SET] = true;
-
- ExpectString("other.js_accessor_p", "getter");
- ExpectObject(
- "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').get", getter);
- ExpectObject(
- "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').set", setter);
- ExpectUndefined(
- "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').value");
-
- allowed_access_type[v8::ACCESS_SET] = false;
- allowed_access_type[v8::ACCESS_GET] = false;
- allowed_access_type[v8::ACCESS_HAS] = false;
-
- // Access an element with JS accessor.
- CompileRun("other[42] = 2");
-
- ExpectUndefined("other[42]");
- ExpectUndefined("Object.getOwnPropertyDescriptor(other, '42')");
-
- // Enable ACCESS_HAS.
- allowed_access_type[v8::ACCESS_HAS] = true;
- ExpectUndefined("other[42]");
- ExpectUndefined("Object.getOwnPropertyDescriptor(other, '42').get");
- ExpectUndefined("Object.getOwnPropertyDescriptor(other, '42').set");
- ExpectUndefined("Object.getOwnPropertyDescriptor(other, '42').value");
- allowed_access_type[v8::ACCESS_HAS] = false;
-
- // Enable both ACCESS_HAS and ACCESS_GET.
- allowed_access_type[v8::ACCESS_HAS] = true;
- allowed_access_type[v8::ACCESS_GET] = true;
-
- ExpectString("other[42]", "el_getter");
- ExpectObject("Object.getOwnPropertyDescriptor(other, '42').get", el_getter);
- ExpectUndefined("Object.getOwnPropertyDescriptor(other, '42').set");
- ExpectUndefined("Object.getOwnPropertyDescriptor(other, '42').value");
-
- allowed_access_type[v8::ACCESS_GET] = false;
- allowed_access_type[v8::ACCESS_HAS] = false;
-
- // Enable both ACCESS_HAS and ACCESS_SET.
- allowed_access_type[v8::ACCESS_HAS] = true;
- allowed_access_type[v8::ACCESS_SET] = true;
-
- ExpectUndefined("other[42]");
- ExpectUndefined("Object.getOwnPropertyDescriptor(other, '42').get");
- ExpectObject("Object.getOwnPropertyDescriptor(other, '42').set", el_setter);
- ExpectUndefined("Object.getOwnPropertyDescriptor(other, '42').value");
-
- allowed_access_type[v8::ACCESS_SET] = false;
- allowed_access_type[v8::ACCESS_HAS] = false;
-
- // Enable both ACCESS_HAS, ACCESS_GET and ACCESS_SET.
- allowed_access_type[v8::ACCESS_HAS] = true;
- allowed_access_type[v8::ACCESS_GET] = true;
- allowed_access_type[v8::ACCESS_SET] = true;
-
- ExpectString("other[42]", "el_getter");
- ExpectObject("Object.getOwnPropertyDescriptor(other, '42').get", el_getter);
- ExpectObject("Object.getOwnPropertyDescriptor(other, '42').set", el_setter);
- ExpectUndefined("Object.getOwnPropertyDescriptor(other, '42').value");
-
- allowed_access_type[v8::ACCESS_SET] = false;
- allowed_access_type[v8::ACCESS_GET] = false;
- allowed_access_type[v8::ACCESS_HAS] = false;
-
v8::Handle<Value> value;
+ // Access blocked property
+ value = v8_compile("other.blocked_prop = 1")->Run();
+ value = v8_compile("other.blocked_prop")->Run();
+ CHECK(value->IsUndefined());
+
+ value = v8_compile("propertyIsEnumerable.call(other, 'blocked_prop')")->Run();
+ CHECK(value->IsFalse());
+
// Access accessible property
- value = CompileRun("other.accessible_prop = 3");
+ value = v8_compile("other.accessible_prop = 3")->Run();
CHECK(value->IsNumber());
CHECK_EQ(3, value->Int32Value());
CHECK_EQ(3, g_echo_value);
- value = CompileRun("other.accessible_prop");
+ value = v8_compile("other.accessible_prop")->Run();
CHECK(value->IsNumber());
CHECK_EQ(3, value->Int32Value());
- value = CompileRun(
- "Object.getOwnPropertyDescriptor(other, 'accessible_prop').value");
- CHECK(value->IsNumber());
- CHECK_EQ(3, value->Int32Value());
-
- value = CompileRun("propertyIsEnumerable.call(other, 'accessible_prop')");
+ value =
+ v8_compile("propertyIsEnumerable.call(other, 'accessible_prop')")->Run();
CHECK(value->IsTrue());
// Enumeration doesn't enumerate accessors from inaccessible objects in
// the prototype chain even if the accessors are in themselves accessible.
- value =
+ Local<Value> result =
CompileRun("(function(){var obj = {'__proto__':other};"
"for (var p in obj)"
" if (p == 'accessible_prop' || p == 'blocked_prop') {"
" return false;"
" }"
"return true;})()");
- CHECK(value->IsTrue());
+ CHECK(result->IsTrue());
context1->Exit();
context0->Exit();
@@ -5922,6 +5798,22 @@
instance_template->Set(v8_str("f"),
v8::FunctionTemplate::New(InstanceFunctionCallback));
+ // The script to check how Crankshaft compiles missing global function
+ // invocations. function g is not defined and should throw on call.
+ const char* script =
+ "function wrapper(call) {"
+ " var x = 0, y = 1;"
+ " for (var i = 0; i < 1000; i++) {"
+ " x += i * 100;"
+ " y += i * 100;"
+ " }"
+ " if (call) g();"
+ "}"
+ "for (var i = 0; i < 17; i++) wrapper(false);"
+ "var thrown = 0;"
+ "try { wrapper(true); } catch (e) { thrown = 1; };"
+ "thrown";
+
{
LocalContext env(NULL, instance_template);
// Hold on to the global object so it can be used again in another
@@ -5932,6 +5824,8 @@
CHECK_EQ(42, value->Int32Value());
value = Script::Compile(v8_str("f()"))->Run();
CHECK_EQ(12, value->Int32Value());
+ value = Script::Compile(v8_str(script))->Run();
+ CHECK_EQ(1, value->Int32Value());
}
{
@@ -5941,6 +5835,48 @@
CHECK_EQ(42, value->Int32Value());
value = Script::Compile(v8_str("f()"))->Run();
CHECK_EQ(12, value->Int32Value());
+ value = Script::Compile(v8_str(script))->Run();
+ CHECK_EQ(1, value->Int32Value());
+ }
+}
+
+
+THREADED_TEST(CallKnownGlobalReceiver) {
+ v8::HandleScope handle_scope;
+
+ Local<Value> global_object;
+
+ Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New();
+ Local<ObjectTemplate> instance_template = t->InstanceTemplate();
+
+ // The script to check that we leave global object not
+ // global object proxy on stack when we deoptimize from inside
+ // arguments evaluation.
+ // To provoke error we need to both force deoptimization
+ // from arguments evaluation and to force CallIC to take
+ // CallIC_Miss code path that can't cope with global proxy.
+ const char* script =
+ "function bar(x, y) { try { } finally { } }"
+ "function baz(x) { try { } finally { } }"
+ "function bom(x) { try { } finally { } }"
+ "function foo(x) { bar([x], bom(2)); }"
+ "for (var i = 0; i < 10000; i++) foo(1);"
+ "foo";
+
+ Local<Value> foo;
+ {
+ LocalContext env(NULL, instance_template);
+ // Hold on to the global object so it can be used again in another
+ // environment initialization.
+ global_object = env->Global();
+ foo = Script::Compile(v8_str(script))->Run();
+ }
+
+ {
+ // Create new environment reusing the global object.
+ LocalContext env(NULL, instance_template, global_object);
+ env->Global()->Set(v8_str("foo"), foo);
+ Local<Value> value = Script::Compile(v8_str("foo()"))->Run();
}
}
@@ -8915,6 +8851,105 @@
}
+v8::Handle<v8::String> a;
+v8::Handle<v8::String> h;
+
+static bool NamedGetAccessBlockAandH(Local<v8::Object> obj,
+ Local<Value> name,
+ v8::AccessType type,
+ Local<Value> data) {
+ return !(name->Equals(a) || name->Equals(h));
+}
+
+
+THREADED_TEST(TurnOnAccessCheckAndRecompile) {
+ v8::HandleScope handle_scope;
+
+ // Create an environment with access check to the global object disabled by
+ // default. When the registered access checker will block access to properties
+ // a and h
+ a = v8_str("a");
+ h = v8_str("h");
+ v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
+ global_template->SetAccessCheckCallbacks(NamedGetAccessBlockAandH,
+ IndexedGetAccessBlocker,
+ v8::Handle<v8::Value>(),
+ false);
+ v8::Persistent<Context> context = Context::New(NULL, global_template);
+ Context::Scope context_scope(context);
+
+ // Set up a property and a number of functions.
+ context->Global()->Set(v8_str("a"), v8_num(1));
+ static const char* source = "function f1() {return a;}"
+ "function f2() {return a;}"
+ "function g1() {return h();}"
+ "function g2() {return h();}"
+ "function h() {return 1;}";
+
+ CompileRun(source);
+ Local<Function> f1;
+ Local<Function> f2;
+ Local<Function> g1;
+ Local<Function> g2;
+ Local<Function> h;
+ f1 = Local<Function>::Cast(context->Global()->Get(v8_str("f1")));
+ f2 = Local<Function>::Cast(context->Global()->Get(v8_str("f2")));
+ g1 = Local<Function>::Cast(context->Global()->Get(v8_str("g1")));
+ g2 = Local<Function>::Cast(context->Global()->Get(v8_str("g2")));
+ h = Local<Function>::Cast(context->Global()->Get(v8_str("h")));
+
+ // Get the global object.
+ v8::Handle<v8::Object> global = context->Global();
+
+ // Call f1 one time and f2 a number of times. This will ensure that f1 still
+ // uses the runtime system to retreive property a whereas f2 uses global load
+ // inline cache.
+ CHECK(f1->Call(global, 0, NULL)->Equals(v8_num(1)));
+ for (int i = 0; i < 4; i++) {
+ CHECK(f2->Call(global, 0, NULL)->Equals(v8_num(1)));
+ }
+
+ // Same for g1 and g2.
+ CHECK(g1->Call(global, 0, NULL)->Equals(v8_num(1)));
+ for (int i = 0; i < 4; i++) {
+ CHECK(g2->Call(global, 0, NULL)->Equals(v8_num(1)));
+ }
+
+ // Detach the global and turn on access check now blocking access to property
+ // a and function h.
+ context->DetachGlobal();
+ context->Global()->TurnOnAccessCheck();
+
+ // Failing access check to property get results in undefined.
+ CHECK(f1->Call(global, 0, NULL)->IsUndefined());
+ CHECK(f2->Call(global, 0, NULL)->IsUndefined());
+
+ // Failing access check to function call results in exception.
+ CHECK(g1->Call(global, 0, NULL).IsEmpty());
+ CHECK(g2->Call(global, 0, NULL).IsEmpty());
+
+ // No failing access check when just returning a constant.
+ CHECK(h->Call(global, 0, NULL)->Equals(v8_num(1)));
+
+ // Now compile the source again. And get the newly compiled functions, except
+ // for h for which access is blocked.
+ CompileRun(source);
+ f1 = Local<Function>::Cast(context->Global()->Get(v8_str("f1")));
+ f2 = Local<Function>::Cast(context->Global()->Get(v8_str("f2")));
+ g1 = Local<Function>::Cast(context->Global()->Get(v8_str("g1")));
+ g2 = Local<Function>::Cast(context->Global()->Get(v8_str("g2")));
+ CHECK(context->Global()->Get(v8_str("h"))->IsUndefined());
+
+ // Failing access check to property get results in undefined.
+ CHECK(f1->Call(global, 0, NULL)->IsUndefined());
+ CHECK(f2->Call(global, 0, NULL)->IsUndefined());
+
+ // Failing access check to function call results in exception.
+ CHECK(g1->Call(global, 0, NULL).IsEmpty());
+ CHECK(g2->Call(global, 0, NULL).IsEmpty());
+}
+
+
// This test verifies that pre-compilation (aka preparsing) can be called
// without initializing the whole VM. Thus we cannot run this test in a
// multi-threaded setup.
@@ -10766,7 +10801,9 @@
// Tests the C++ StackTrace API.
-THREADED_TEST(CaptureStackTrace) {
+// TODO(3074796): Reenable this as a THREADED_TEST once it passes.
+// THREADED_TEST(CaptureStackTrace) {
+TEST(CaptureStackTrace) {
v8::HandleScope scope;
v8::Handle<v8::String> origin = v8::String::New("capture-stack-trace-test");
Local<ObjectTemplate> templ = ObjectTemplate::New();
diff --git a/test/cctest/test-dataflow.cc b/test/cctest/test-dataflow.cc
index 003ac66..5894de2 100644
--- a/test/cctest/test-dataflow.cc
+++ b/test/cctest/test-dataflow.cc
@@ -52,6 +52,24 @@
}
{
+ BitVector v(64);
+ v.Add(27);
+ v.Add(30);
+ v.Add(31);
+ v.Add(33);
+ BitVector::Iterator iter(&v);
+ CHECK_EQ(27, iter.Current());
+ iter.Advance();
+ CHECK_EQ(30, iter.Current());
+ iter.Advance();
+ CHECK_EQ(31, iter.Current());
+ iter.Advance();
+ CHECK_EQ(33, iter.Current());
+ iter.Advance();
+ CHECK(iter.Done());
+ }
+
+ {
BitVector v(15);
v.Add(0);
BitVector w(15);
diff --git a/test/cctest/test-debug.cc b/test/cctest/test-debug.cc
index 7791185..87f9cab 100644
--- a/test/cctest/test-debug.cc
+++ b/test/cctest/test-debug.cc
@@ -1,4 +1,4 @@
-// Copyright 2007-2008 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -32,11 +32,13 @@
#include "v8.h"
#include "api.h"
+#include "cctest.h"
#include "compilation-cache.h"
#include "debug.h"
+#include "deoptimizer.h"
#include "platform.h"
#include "stub-cache.h"
-#include "cctest.h"
+#include "utils.h"
using ::v8::internal::EmbeddedVector;
@@ -515,16 +517,52 @@
// ---
-// Source for The JavaScript function which picks out the function name of the
-// top frame.
+// Source for the JavaScript function which picks out the function
+// name of a frame.
const char* frame_function_name_source =
- "function frame_function_name(exec_state) {"
- " return exec_state.frame(0).func().name();"
+ "function frame_function_name(exec_state, frame_number) {"
+ " return exec_state.frame(frame_number).func().name();"
"}";
v8::Local<v8::Function> frame_function_name;
-// Source for The JavaScript function which picks out the source line for the
+// Source for the JavaScript function which pick out the name of the
+// first argument of a frame.
+const char* frame_argument_name_source =
+ "function frame_argument_name(exec_state, frame_number) {"
+ " return exec_state.frame(frame_number).argumentName(0);"
+ "}";
+v8::Local<v8::Function> frame_argument_name;
+
+
+// Source for the JavaScript function which pick out the value of the
+// first argument of a frame.
+const char* frame_argument_value_source =
+ "function frame_argument_value(exec_state, frame_number) {"
+ " return exec_state.frame(frame_number).argumentValue(0).value_;"
+ "}";
+v8::Local<v8::Function> frame_argument_value;
+
+
+// Source for the JavaScript function which pick out the name of the
+// first argument of a frame.
+const char* frame_local_name_source =
+ "function frame_local_name(exec_state, frame_number) {"
+ " return exec_state.frame(frame_number).localName(0);"
+ "}";
+v8::Local<v8::Function> frame_local_name;
+
+
+// Source for the JavaScript function which pick out the value of the
+// first argument of a frame.
+const char* frame_local_value_source =
+ "function frame_local_value(exec_state, frame_number) {"
+ " return exec_state.frame(frame_number).localValue(0).value_;"
+ "}";
+v8::Local<v8::Function> frame_local_value;
+
+
+// Source for the JavaScript function which picks out the source line for the
// top frame.
const char* frame_source_line_source =
"function frame_source_line(exec_state) {"
@@ -533,7 +571,7 @@
v8::Local<v8::Function> frame_source_line;
-// Source for The JavaScript function which picks out the source column for the
+// Source for the JavaScript function which picks out the source column for the
// top frame.
const char* frame_source_column_source =
"function frame_source_column(exec_state) {"
@@ -542,7 +580,7 @@
v8::Local<v8::Function> frame_source_column;
-// Source for The JavaScript function which picks out the script name for the
+// Source for the JavaScript function which picks out the script name for the
// top frame.
const char* frame_script_name_source =
"function frame_script_name(exec_state) {"
@@ -551,7 +589,7 @@
v8::Local<v8::Function> frame_script_name;
-// Source for The JavaScript function which picks out the script data for the
+// Source for the JavaScript function which picks out the script data for the
// top frame.
const char* frame_script_data_source =
"function frame_script_data(exec_state) {"
@@ -560,7 +598,7 @@
v8::Local<v8::Function> frame_script_data;
-// Source for The JavaScript function which picks out the script data from
+// Source for the JavaScript function which picks out the script data from
// AfterCompile event
const char* compiled_script_data_source =
"function compiled_script_data(event_data) {"
@@ -569,7 +607,7 @@
v8::Local<v8::Function> compiled_script_data;
-// Source for The JavaScript function which returns the number of frames.
+// Source for the JavaScript function which returns the number of frames.
static const char* frame_count_source =
"function frame_count(exec_state) {"
" return exec_state.frameCount();"
@@ -603,8 +641,8 @@
break_point_hit_count++;
if (!frame_function_name.IsEmpty()) {
// Get the name of the function.
- const int argc = 1;
- v8::Handle<v8::Value> argv[argc] = { exec_state };
+ const int argc = 2;
+ v8::Handle<v8::Value> argv[argc] = { exec_state, v8::Integer::New(0) };
v8::Handle<v8::Value> result = frame_function_name->Call(exec_state,
argc, argv);
if (result->IsUndefined()) {
@@ -834,8 +872,8 @@
// Check that the current function is the expected.
CHECK(break_point_hit_count <
StrLength(expected_step_sequence));
- const int argc = 1;
- v8::Handle<v8::Value> argv[argc] = { exec_state };
+ const int argc = 2;
+ v8::Handle<v8::Value> argv[argc] = { exec_state, v8::Integer::New(0) };
v8::Handle<v8::Value> result = frame_function_name->Call(exec_state,
argc, argv);
CHECK(result->IsString());
@@ -2586,6 +2624,10 @@
v8::Local<v8::Function> foo = CompileFunction(&env,
"function foo(){a=1;b=1;c=1;}",
"foo");
+
+ // Run foo to allow it to get optimized.
+ CompileRun("a=0; b=0; c=0; foo();");
+
SetBreakPoint(foo, 3);
// Register a debug event listener which steps and counts.
@@ -2635,7 +2677,8 @@
" y = 1;\n"
" x = a[i];\n"
" }\n"
- "}\n",
+ "}\n"
+ "y=0\n",
"foo");
// Create array [0,1,2,3,4,5,6,7,8,9]
@@ -2681,7 +2724,8 @@
" y = 1;\n"
" a[i] = 42;\n"
" }\n"
- "}\n",
+ "}\n"
+ "y=0\n",
"foo");
// Create array [0,1,2,3,4,5,6,7,8,9]
@@ -2753,15 +2797,12 @@
}
-static void DoDebugStepNamedStoreLoop(int expected, bool full_compiler = true) {
+static void DoDebugStepNamedStoreLoop(int expected) {
v8::HandleScope scope;
DebugLocalContext env;
- // Register a debug event listener which steps and counts before compiling the
- // function to ensure the full compiler is used.
- if (full_compiler) {
- v8::Debug::SetDebugEventListener(DebugEventStep);
- }
+ // Register a debug event listener which steps and counts.
+ v8::Debug::SetDebugEventListener(DebugEventStep);
// Create a function for testing stepping of named store.
v8::Local<v8::Function> foo = CompileFunction(
@@ -2777,12 +2818,6 @@
// Call function without any break points to ensure inlining is in place.
foo->Call(env->Global(), 0, NULL);
- // Register a debug event listener which steps and counts after compiling the
- // function to ensure the optimizing compiler is used.
- if (!full_compiler) {
- v8::Debug::SetDebugEventListener(DebugEventStep);
- }
-
// Setup break point and step through the function.
SetBreakPoint(foo, 3);
step_action = StepNext;
@@ -2798,20 +2833,11 @@
// Test of the stepping mechanism for named load in a loop.
-TEST(DebugStepNamedStoreLoopFull) {
- // With the full compiler it is possible to break on the for statement.
+TEST(DebugStepNamedStoreLoop) {
DoDebugStepNamedStoreLoop(22);
}
-// Test of the stepping mechanism for named load in a loop.
-TEST(DebugStepNamedStoreLoopOptimizing) {
- // With the optimizing compiler it is not possible to break on the for
- // statement as it uses a local variable thus no IC's.
- DoDebugStepNamedStoreLoop(11, false);
-}
-
-
// Test the stepping mechanism with different ICs.
TEST(DebugStepLinearMixedICs) {
v8::HandleScope scope;
@@ -2828,6 +2854,10 @@
" var index='name';"
" var y = {};"
" a=1;b=2;x=a;y[index]=3;x=y[index];bar();}", "foo");
+
+ // Run functions to allow them to get optimized.
+ CompileRun("a=0; b=0; bar(); foo();");
+
SetBreakPoint(foo, 0);
step_action = StepIn;
@@ -2862,15 +2892,18 @@
// Register a debug event listener which steps and counts.
v8::Debug::SetDebugEventListener(DebugEventStep);
- // Create a function for testing stepping.
+ // Create a function for testing stepping. Run it to allow it to get
+ // optimized.
const char* src = "function foo() { "
" var a;"
" var b = 1;"
" var c = foo;"
" var d = Math.floor;"
" var e = b + d(1.2);"
- "}";
+ "}"
+ "foo()";
v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo");
+
SetBreakPoint(foo, 0);
// Stepping through the declarations.
@@ -2892,15 +2925,18 @@
// Register a debug event listener which steps and counts.
v8::Debug::SetDebugEventListener(DebugEventStep);
- // Create a function for testing stepping.
+ // Create a function for testing stepping. Run it to allow it to get
+ // optimized.
const char* src = "function foo() { "
" var a,b;"
" a = 1;"
" b = a + 2;"
" b = 1 + 2 + 3;"
" a = Math.floor(b);"
- "}";
+ "}"
+ "foo()";
v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo");
+
SetBreakPoint(foo, 0);
// Stepping through the declarations.
@@ -2922,7 +2958,8 @@
// Register a debug event listener which steps and counts.
v8::Debug::SetDebugEventListener(DebugEventStep);
- // Create a function for testing stepping.
+ // Create a function for testing stepping. Run it to allow it to get
+ // optimized.
const int argc = 1;
const char* src = "function foo(x) { "
" a = 1;"
@@ -2932,7 +2969,8 @@
" c = 1;"
" d = 1;"
" }"
- "}";
+ "}"
+ "a=0; b=0; c=0; d=0; foo()";
v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo");
SetBreakPoint(foo, 0);
@@ -2963,7 +3001,8 @@
// Register a debug event listener which steps and counts.
v8::Debug::SetDebugEventListener(DebugEventStep);
- // Create a function for testing stepping.
+ // Create a function for testing stepping. Run it to allow it to get
+ // optimized.
const int argc = 1;
const char* src = "function foo(x) { "
" a = 1;"
@@ -2979,7 +3018,8 @@
" f = 1;"
" break;"
" }"
- "}";
+ "}"
+ "a=0; b=0; c=0; d=0; e=0; f=0; foo()";
v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo");
SetBreakPoint(foo, 0);
@@ -3017,14 +3057,16 @@
// Register a debug event listener which steps and counts.
v8::Debug::SetDebugEventListener(DebugEventStep);
- // Create a function for testing stepping.
+ // Create a function for testing stepping. Run it to allow it to get
+ // optimized.
const int argc = 1;
const char* src = "function foo(x) { "
" var a = 0;"
" while (a < x) {"
" a++;"
" }"
- "}";
+ "}"
+ "foo()";
v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo");
SetBreakPoint(foo, 8); // "var a = 0;"
@@ -3033,14 +3075,14 @@
break_point_hit_count = 0;
v8::Handle<v8::Value> argv_10[argc] = { v8::Number::New(10) };
foo->Call(env->Global(), argc, argv_10);
- CHECK_EQ(23, break_point_hit_count);
+ CHECK_EQ(22, break_point_hit_count);
// Looping 100 times.
step_action = StepIn;
break_point_hit_count = 0;
v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(100) };
foo->Call(env->Global(), argc, argv_100);
- CHECK_EQ(203, break_point_hit_count);
+ CHECK_EQ(202, break_point_hit_count);
// Get rid of the debug event listener.
v8::Debug::SetDebugEventListener(NULL);
@@ -3055,14 +3097,16 @@
// Register a debug event listener which steps and counts.
v8::Debug::SetDebugEventListener(DebugEventStep);
- // Create a function for testing stepping.
+ // Create a function for testing stepping. Run it to allow it to get
+ // optimized.
const int argc = 1;
const char* src = "function foo(x) { "
" var a = 0;"
" do {"
" a++;"
" } while (a < x)"
- "}";
+ "}"
+ "foo()";
v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo");
SetBreakPoint(foo, 8); // "var a = 0;"
@@ -3093,15 +3137,18 @@
// Register a debug event listener which steps and counts.
v8::Debug::SetDebugEventListener(DebugEventStep);
- // Create a function for testing stepping.
+ // Create a function for testing stepping. Run it to allow it to get
+ // optimized.
const int argc = 1;
const char* src = "function foo(x) { "
" a = 1;"
" for (i = 0; i < x; i++) {"
" b = 1;"
" }"
- "}";
+ "}"
+ "a=0; b=0; i=0; foo()";
v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo");
+
SetBreakPoint(foo, 8); // "a = 1;"
// Looping 10 times.
@@ -3131,7 +3178,8 @@
// Register a debug event listener which steps and counts.
v8::Debug::SetDebugEventListener(DebugEventStep);
- // Create a function for testing stepping.
+ // Create a function for testing stepping. Run it to allow it to get
+ // optimized.
const int argc = 1;
const char* src = "function foo(x) { "
" var a = 0;"
@@ -3144,7 +3192,8 @@
" c++;"
" }"
" return b;"
- "}";
+ "}"
+ "foo()";
v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo");
v8::Handle<v8::Value> result;
SetBreakPoint(foo, 8); // "var a = 0;"
@@ -3180,7 +3229,8 @@
// Register a debug event listener which steps and counts.
v8::Debug::SetDebugEventListener(DebugEventStep);
- // Create a function for testing stepping.
+ // Create a function for testing stepping. Run it to allow it to get
+ // optimized.
const int argc = 1;
const char* src = "function foo(x) { "
" var a = 0;"
@@ -3193,7 +3243,8 @@
" c++;"
" }"
" return b;"
- "}";
+ "}"
+ "foo()";
v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo");
v8::Handle<v8::Value> result;
SetBreakPoint(foo, 8); // "var a = 0;"
@@ -3230,13 +3281,16 @@
// Register a debug event listener which steps and counts.
v8::Debug::SetDebugEventListener(DebugEventStep);
+ // Create a function for testing stepping. Run it to allow it to get
+ // optimized.
v8::Local<v8::Function> foo;
const char* src_1 = "function foo() { "
" var a = [1, 2];"
" for (x in a) {"
" b = 0;"
" }"
- "}";
+ "}"
+ "foo()";
foo = CompileFunction(&env, src_1, "foo");
SetBreakPoint(foo, 0); // "var a = ..."
@@ -3245,12 +3299,15 @@
foo->Call(env->Global(), 0, NULL);
CHECK_EQ(6, break_point_hit_count);
+ // Create a function for testing stepping. Run it to allow it to get
+ // optimized.
const char* src_2 = "function foo() { "
" var a = {a:[1, 2, 3]};"
" for (x in a.a) {"
" b = 0;"
" }"
- "}";
+ "}"
+ "foo()";
foo = CompileFunction(&env, src_2, "foo");
SetBreakPoint(foo, 0); // "var a = ..."
@@ -3272,12 +3329,14 @@
// Register a debug event listener which steps and counts.
v8::Debug::SetDebugEventListener(DebugEventStep);
- // Create a function for testing stepping.
+ // Create a function for testing stepping. Run it to allow it to get
+ // optimized.
const char* src = "function foo(x) { "
" var a = {};"
" with (a) {}"
" with (b) {}"
- "}";
+ "}"
+ "foo()";
env->Global()->Set(v8::String::New("b"), v8::Object::New());
v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo");
v8::Handle<v8::Value> result;
@@ -3301,12 +3360,14 @@
// Register a debug event listener which steps and counts.
v8::Debug::SetDebugEventListener(DebugEventStep);
- // Create a function for testing stepping.
+ // Create a function for testing stepping. Run it to allow it to get
+ // optimized.
const char* src = "function foo(x) { "
" var a;"
" a = x ? 1 : 2;"
" return a;"
- "}";
+ "}"
+ "foo()";
v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo");
SetBreakPoint(foo, 0); // "var a;"
@@ -3340,10 +3401,12 @@
// Register a debug event listener which steps and counts.
v8::Debug::SetDebugEventListener(DebugEventStepSequence);
- // Create functions for testing stepping.
+ // Create a function for testing stepping. Run it to allow it to get
+ // optimized.
const char* src = "function a() {b();c();}; "
"function b() {c();}; "
- "function c() {}; ";
+ "function c() {}; "
+ "a(); b(); c()";
v8::Local<v8::Function> a = CompileFunction(&env, src, "a");
SetBreakPoint(a, 0);
@@ -3389,11 +3452,13 @@
// Register a debug event listener which steps and counts.
v8::Debug::SetDebugEventListener(DebugEventStepSequence);
- // Create functions for testing stepping.
+ // Create a function for testing stepping. Run it to allow it to get
+ // optimized.
const char* src = "function a() {b(c(d()),d());c(d());d()}; "
"function b(x,y) {c();}; "
"function c(x) {}; "
- "function d() {}; ";
+ "function d() {}; "
+ "a(); b(); c(); d()";
v8::Local<v8::Function> a = CompileFunction(&env, src, "a");
SetBreakPoint(a, 0);
@@ -3439,10 +3504,12 @@
// Register a debug event listener which steps and counts.
v8::Debug::SetDebugEventListener(DebugEventStepSequence);
- // Create functions for testing stepping.
+ // Create a function for testing stepping. Run it to allow it to get
+ // optimized.
const char* src = "function a() {b(false);c();}; "
"function b(x) {if(x){c();};}; "
- "function c() {}; ";
+ "function c() {}; "
+ "a(); b(); c()";
v8::Local<v8::Function> a = CompileFunction(&env, src, "a");
SetBreakPoint(a, 0);
@@ -6116,8 +6183,8 @@
// Get the name of the top frame function.
if (!frame_function_name.IsEmpty()) {
// Get the name of the function.
- const int argc = 1;
- v8::Handle<v8::Value> argv[argc] = { exec_state };
+ const int argc = 2;
+ v8::Handle<v8::Value> argv[argc] = { exec_state, v8::Integer::New(0) };
v8::Handle<v8::Value> result = frame_function_name->Call(exec_state,
argc, argv);
if (result->IsUndefined()) {
@@ -6846,6 +6913,7 @@
}
}
+
// Check that event details contain context where debug event occured.
TEST(DebugEventBreakData) {
v8::HandleScope scope;
@@ -6898,6 +6966,156 @@
CheckDebuggerUnloaded();
}
+static bool debug_event_break_deoptimize_done = false;
+
+static void DebugEventBreakDeoptimize(v8::DebugEvent event,
+ v8::Handle<v8::Object> exec_state,
+ v8::Handle<v8::Object> event_data,
+ v8::Handle<v8::Value> data) {
+ if (event == v8::Break) {
+ if (!frame_function_name.IsEmpty()) {
+ // Get the name of the function.
+ const int argc = 2;
+ v8::Handle<v8::Value> argv[argc] = { exec_state, v8::Integer::New(0) };
+ v8::Handle<v8::Value> result =
+ frame_function_name->Call(exec_state, argc, argv);
+ if (!result->IsUndefined()) {
+ char fn[80];
+ CHECK(result->IsString());
+ v8::Handle<v8::String> function_name(result->ToString());
+ function_name->WriteAscii(fn);
+ if (strcmp(fn, "bar") == 0) {
+ i::Deoptimizer::DeoptimizeAll();
+ debug_event_break_deoptimize_done = true;
+ }
+ }
+ }
+
+ v8::Debug::DebugBreak();
+ }
+}
+
+
+// Test deoptimization when execution is broken using the debug break stack
+// check interrupt.
+TEST(DeoptimizeDuringDebugBreak) {
+ v8::HandleScope scope;
+ DebugLocalContext env;
+ env.ExposeDebug();
+
+ // Create a function for checking the function when hitting a break point.
+ frame_function_name = CompileFunction(&env,
+ frame_function_name_source,
+ "frame_function_name");
+
+
+ // Set a debug event listener which will keep interrupting execution until
+ // debug break. When inside function bar it will deoptimize all functions.
+ // This tests lazy deoptimization bailout for the stack check, as the first
+ // time in function bar when using debug break and no break points will be at
+ // the initial stack check.
+ v8::Debug::SetDebugEventListener(DebugEventBreakDeoptimize,
+ v8::Undefined());
+
+ // Compile and run function bar which will optimize it for some flag settings.
+ v8::Script::Compile(v8::String::New("function bar(){}; bar()"))->Run();
+
+ // Set debug break and call bar again.
+ v8::Debug::DebugBreak();
+ v8::Script::Compile(v8::String::New("bar()"))->Run();
+
+ CHECK(debug_event_break_deoptimize_done);
+
+ v8::Debug::SetDebugEventListener(NULL);
+}
+
+
+static void DebugEventBreakWithOptimizedStack(v8::DebugEvent event,
+ v8::Handle<v8::Object> exec_state,
+ v8::Handle<v8::Object> event_data,
+ v8::Handle<v8::Value> data) {
+ if (event == v8::Break) {
+ if (!frame_function_name.IsEmpty()) {
+ for (int i = 0; i < 2; i++) {
+ const int argc = 2;
+ v8::Handle<v8::Value> argv[argc] = { exec_state, v8::Integer::New(i) };
+ // Get the name of the function in frame i.
+ v8::Handle<v8::Value> result =
+ frame_function_name->Call(exec_state, argc, argv);
+ CHECK(result->IsString());
+ v8::Handle<v8::String> function_name(result->ToString());
+ CHECK(function_name->Equals(v8::String::New("loop")));
+ // Get the name of the first argument in frame i.
+ result = frame_argument_name->Call(exec_state, argc, argv);
+ CHECK(result->IsString());
+ v8::Handle<v8::String> argument_name(result->ToString());
+ CHECK(argument_name->Equals(v8::String::New("count")));
+ // Get the value of the first argument in frame i. If the
+ // funtion is optimized the value will be undefined, otherwise
+ // the value will be '1 - i'.
+ //
+ // TODO(3141533): We should be able to get the real value for
+ // optimized frames.
+ result = frame_argument_value->Call(exec_state, argc, argv);
+ CHECK(result->IsUndefined() || (result->Int32Value() == 1 - i));
+ // Get the name of the first local variable.
+ result = frame_local_name->Call(exec_state, argc, argv);
+ CHECK(result->IsString());
+ v8::Handle<v8::String> local_name(result->ToString());
+ CHECK(local_name->Equals(v8::String::New("local")));
+ // Get the value of the first local variable. If the function
+ // is optimized the value will be undefined, otherwise it will
+ // be 42.
+ //
+ // TODO(3141533): We should be able to get the real value for
+ // optimized frames.
+ result = frame_local_value->Call(exec_state, argc, argv);
+ CHECK(result->IsUndefined() || (result->Int32Value() == 42));
+ }
+ }
+ }
+}
+
+
+static v8::Handle<v8::Value> ScheduleBreak(const v8::Arguments& args) {
+ v8::Debug::SetDebugEventListener(DebugEventBreakWithOptimizedStack,
+ v8::Undefined());
+ v8::Debug::DebugBreak();
+ return v8::Undefined();
+}
+
+
+TEST(DebugBreakStackInspection) {
+ v8::HandleScope scope;
+ DebugLocalContext env;
+
+ frame_function_name =
+ CompileFunction(&env, frame_function_name_source, "frame_function_name");
+ frame_argument_name =
+ CompileFunction(&env, frame_argument_name_source, "frame_argument_name");
+ frame_argument_value = CompileFunction(&env,
+ frame_argument_value_source,
+ "frame_argument_value");
+ frame_local_name =
+ CompileFunction(&env, frame_local_name_source, "frame_local_name");
+ frame_local_value =
+ CompileFunction(&env, frame_local_value_source, "frame_local_value");
+
+ v8::Handle<v8::FunctionTemplate> schedule_break_template =
+ v8::FunctionTemplate::New(ScheduleBreak);
+ v8::Handle<v8::Function> schedule_break =
+ schedule_break_template->GetFunction();
+ env->Global()->Set(v8_str("scheduleBreak"), schedule_break);
+
+ const char* src =
+ "function loop(count) {"
+ " var local = 42;"
+ " if (count < 1) { scheduleBreak(); loop(count + 1); }"
+ "}"
+ "loop(0);";
+ v8::Script::Compile(v8::String::New(src))->Run();
+}
+
// Test that setting the terminate execution flag during debug break processing.
static void TestDebugBreakInLoop(const char* loop_head,
diff --git a/test/cctest/test-deoptimization.cc b/test/cctest/test-deoptimization.cc
new file mode 100644
index 0000000..1745355
--- /dev/null
+++ b/test/cctest/test-deoptimization.cc
@@ -0,0 +1,714 @@
+// Copyright 2007-2010 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 <stdlib.h>
+
+#include "v8.h"
+
+#include "api.h"
+#include "compilation-cache.h"
+#include "debug.h"
+#include "deoptimizer.h"
+#include "platform.h"
+#include "stub-cache.h"
+#include "cctest.h"
+
+
+using ::v8::internal::Handle;
+using ::v8::internal::Object;
+using ::v8::internal::JSFunction;
+using ::v8::internal::Deoptimizer;
+using ::v8::internal::EmbeddedVector;
+using ::v8::internal::OS;
+
+// Size of temp buffer for formatting small strings.
+#define SMALL_STRING_BUFFER_SIZE 80
+
+// Utility class to set --allow-natives-syntax --always-opt and --nouse-inlining
+// when constructed and return to their default state when destroyed.
+class AlwaysOptimizeAllowNativesSyntaxNoInlining {
+ public:
+ AlwaysOptimizeAllowNativesSyntaxNoInlining()
+ : always_opt_(i::FLAG_always_opt),
+ allow_natives_syntax_(i::FLAG_allow_natives_syntax),
+ use_inlining_(i::FLAG_use_inlining) {
+ i::FLAG_always_opt = true;
+ i::FLAG_allow_natives_syntax = true;
+ i::FLAG_use_inlining = false;
+ }
+
+ ~AlwaysOptimizeAllowNativesSyntaxNoInlining() {
+ i::FLAG_allow_natives_syntax = allow_natives_syntax_;
+ i::FLAG_always_opt = always_opt_;
+ i::FLAG_use_inlining = use_inlining_;
+ }
+
+ private:
+ bool always_opt_;
+ bool allow_natives_syntax_;
+ bool use_inlining_;
+};
+
+
+// Utility class to set --allow-natives-syntax and --nouse-inlining when
+// constructed and return to their default state when destroyed.
+class AllowNativesSyntaxNoInlining {
+ public:
+ AllowNativesSyntaxNoInlining()
+ : allow_natives_syntax_(i::FLAG_allow_natives_syntax),
+ use_inlining_(i::FLAG_use_inlining) {
+ i::FLAG_allow_natives_syntax = true;
+ i::FLAG_use_inlining = false;
+ }
+
+ ~AllowNativesSyntaxNoInlining() {
+ i::FLAG_allow_natives_syntax = allow_natives_syntax_;
+ i::FLAG_use_inlining = use_inlining_;
+ }
+
+ private:
+ bool allow_natives_syntax_;
+ bool use_inlining_;
+};
+
+
+Handle<JSFunction> GetJSFunction(v8::Handle<v8::Object> obj,
+ const char* property_name) {
+ v8::Local<v8::Function> fun =
+ v8::Local<v8::Function>::Cast(obj->Get(v8_str(property_name)));
+ return v8::Utils::OpenHandle(*fun);
+}
+
+
+TEST(DeoptimizeSimple) {
+ v8::HandleScope scope;
+ const char* extension_list[] = { "v8/gc" };
+ v8::ExtensionConfiguration extensions(1, extension_list);
+ LocalContext env(&extensions);
+
+ // Test lazy deoptimization of a simple function.
+ {
+ AlwaysOptimizeAllowNativesSyntaxNoInlining options;
+ CompileRun(
+ "var count = 0;"
+ "function h() { %DeoptimizeFunction(f); }"
+ "function g() { count++; h(); }"
+ "function f() { g(); };"
+ "f();"
+ "gc(); gc()");
+ }
+
+ CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
+ CHECK(!GetJSFunction(env->Global(), "f")->IsOptimized());
+ CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount());
+
+ // Test lazy deoptimization of a simple function. Call the function after the
+ // deoptimization while it is still activated further down the stack.
+ {
+ AlwaysOptimizeAllowNativesSyntaxNoInlining options;
+ CompileRun(
+ "var count = 0;"
+ "function g() { count++; %DeoptimizeFunction(f); f(false); }"
+ "function f(x) { if (x) { g(); } else { return } };"
+ "f(true);"
+ "gc(); gc()");
+ }
+
+ CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
+ CHECK(!GetJSFunction(env->Global(), "f")->IsOptimized());
+ CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount());
+}
+
+
+TEST(DeoptimizeSimpleWithArguments) {
+ v8::HandleScope scope;
+ const char* extension_list[] = { "v8/gc" };
+ v8::ExtensionConfiguration extensions(1, extension_list);
+ LocalContext env(&extensions);
+
+ // Test lazy deoptimization of a simple function with some arguments.
+ {
+ AlwaysOptimizeAllowNativesSyntaxNoInlining options;
+ CompileRun(
+ "var count = 0;"
+ "function h(x) { %DeoptimizeFunction(f); }"
+ "function g(x, y) { count++; h(x); }"
+ "function f(x, y, z) { g(1,x); y+z; };"
+ "f(1, \"2\", false);"
+ "gc(); gc()");
+ }
+
+ CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
+ CHECK(!GetJSFunction(env->Global(), "f")->IsOptimized());
+ CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount());
+
+ // Test lazy deoptimization of a simple function with some arguments. Call the
+ // function after the deoptimization while it is still activated further down
+ // the stack.
+ {
+ AlwaysOptimizeAllowNativesSyntaxNoInlining options;
+ CompileRun(
+ "var count = 0;"
+ "function g(x, y) { count++; %DeoptimizeFunction(f); f(false, 1, y); }"
+ "function f(x, y, z) { if (x) { g(x, y); } else { return y + z; } };"
+ "f(true, 1, \"2\");"
+ "gc(); gc()");
+ }
+
+ CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
+ CHECK(!GetJSFunction(env->Global(), "f")->IsOptimized());
+ CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount());
+}
+
+
+TEST(DeoptimizeSimpleNested) {
+ v8::HandleScope scope;
+ const char* extension_list[] = { "v8/gc" };
+ v8::ExtensionConfiguration extensions(1, extension_list);
+ LocalContext env(&extensions);
+
+ // Test lazy deoptimization of a simple function. Have a nested function call
+ // do the deoptimization.
+ {
+ AlwaysOptimizeAllowNativesSyntaxNoInlining options;
+ CompileRun(
+ "var count = 0;"
+ "var result = 0;"
+ "function h(x, y, z) { return x + y + z; }"
+ "function g(z) { count++; %DeoptimizeFunction(f); return z;}"
+ "function f(x,y,z) { return h(x, y, g(z)); };"
+ "result = f(1, 2, 3);"
+ "gc(); gc()");
+
+ CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
+ CHECK_EQ(6, env->Global()->Get(v8_str("result"))->Int32Value());
+ CHECK(!GetJSFunction(env->Global(), "f")->IsOptimized());
+ CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount());
+ }
+}
+
+
+TEST(DeoptimizeRecursive) {
+ v8::HandleScope scope;
+ const char* extension_list[] = { "v8/gc" };
+ v8::ExtensionConfiguration extensions(1, extension_list);
+ LocalContext env(&extensions);
+
+ {
+ // Test lazy deoptimization of a simple function called recursively. Call
+ // the function recursively a number of times before deoptimizing it.
+ AlwaysOptimizeAllowNativesSyntaxNoInlining options;
+ CompileRun(
+ "var count = 0;"
+ "var calls = 0;"
+ "function g() { count++; %DeoptimizeFunction(f); }"
+ "function f(x) { calls++; if (x > 0) { f(x - 1); } else { g(); } };"
+ "f(10); gc(); gc()");
+ }
+
+ CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
+ CHECK_EQ(11, env->Global()->Get(v8_str("calls"))->Int32Value());
+ CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount());
+
+ v8::Local<v8::Function> fun =
+ v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
+ Handle<v8::internal::JSFunction> f = v8::Utils::OpenHandle(*fun);
+}
+
+
+TEST(DeoptimizeMultiple) {
+ v8::HandleScope scope;
+ const char* extension_list[] = { "v8/gc" };
+ v8::ExtensionConfiguration extensions(1, extension_list);
+ LocalContext env(&extensions);
+
+ {
+ AlwaysOptimizeAllowNativesSyntaxNoInlining options;
+ CompileRun(
+ "var count = 0;"
+ "var result = 0;"
+ "function g() { count++;"
+ " %DeoptimizeFunction(f1);"
+ " %DeoptimizeFunction(f2);"
+ " %DeoptimizeFunction(f3);"
+ " %DeoptimizeFunction(f4);}"
+ "function f4(x) { g(); };"
+ "function f3(x, y, z) { f4(); return x + y + z; };"
+ "function f2(x, y) { return x + f3(y + 1, y + 1, y + 1) + y; };"
+ "function f1(x) { return f2(x + 1, x + 1) + x; };"
+ "result = f1(1);"
+ "gc(); gc()");
+ }
+
+ CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
+ CHECK_EQ(14, env->Global()->Get(v8_str("result"))->Int32Value());
+ CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount());
+}
+
+
+TEST(DeoptimizeConstructor) {
+ v8::HandleScope scope;
+ const char* extension_list[] = { "v8/gc" };
+ v8::ExtensionConfiguration extensions(1, extension_list);
+ LocalContext env(&extensions);
+
+ {
+ AlwaysOptimizeAllowNativesSyntaxNoInlining options;
+ CompileRun(
+ "var count = 0;"
+ "function g() { count++;"
+ " %DeoptimizeFunction(f); }"
+ "function f() { g(); };"
+ "result = new f() instanceof f;"
+ "gc(); gc()");
+ }
+
+ CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
+ CHECK(env->Global()->Get(v8_str("result"))->IsTrue());
+ CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount());
+
+ {
+ AlwaysOptimizeAllowNativesSyntaxNoInlining options;
+ CompileRun(
+ "var count = 0;"
+ "var result = 0;"
+ "function g() { count++;"
+ " %DeoptimizeFunction(f); }"
+ "function f(x, y) { this.x = x; g(); this.y = y; };"
+ "result = new f(1, 2);"
+ "result = result.x + result.y;"
+ "gc(); gc()");
+ }
+
+ CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
+ CHECK_EQ(3, env->Global()->Get(v8_str("result"))->Int32Value());
+ CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount());
+}
+
+
+TEST(DeoptimizeConstructorMultiple) {
+ v8::HandleScope scope;
+ const char* extension_list[] = { "v8/gc" };
+ v8::ExtensionConfiguration extensions(1, extension_list);
+ LocalContext env(&extensions);
+
+ {
+ AlwaysOptimizeAllowNativesSyntaxNoInlining options;
+ CompileRun(
+ "var count = 0;"
+ "var result = 0;"
+ "function g() { count++;"
+ " %DeoptimizeFunction(f1);"
+ " %DeoptimizeFunction(f2);"
+ " %DeoptimizeFunction(f3);"
+ " %DeoptimizeFunction(f4);}"
+ "function f4(x) { this.result = x; g(); };"
+ "function f3(x, y, z) { this.result = new f4(x + y + z).result; };"
+ "function f2(x, y) {"
+ " this.result = x + new f3(y + 1, y + 1, y + 1).result + y; };"
+ "function f1(x) { this.result = new f2(x + 1, x + 1).result + x; };"
+ "result = new f1(1).result;"
+ "gc(); gc()");
+ }
+
+ CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
+ CHECK_EQ(14, env->Global()->Get(v8_str("result"))->Int32Value());
+ CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount());
+}
+
+
+TEST(DeoptimizeBinaryOperationADDString) {
+ v8::HandleScope scope;
+ const char* extension_list[] = { "v8/gc" };
+ v8::ExtensionConfiguration extensions(1, extension_list);
+ LocalContext env(&extensions);
+
+ const char* f_source = "function f(x, y) { return x + y; };";
+
+ {
+ AllowNativesSyntaxNoInlining options;
+ // Compile function f and collect to type feedback to insert binary op stub
+ // call in the optimized code.
+ i::FLAG_prepare_always_opt = true;
+ CompileRun("var count = 0;"
+ "var result = 0;"
+ "var deopt = false;"
+ "function X() { };"
+ "X.prototype.toString = function () {"
+ " if (deopt) { count++; %DeoptimizeFunction(f); } return 'an X'"
+ "};");
+ CompileRun(f_source);
+ CompileRun("for (var i = 0; i < 5; i++) {"
+ " f('a+', new X());"
+ "};");
+
+ // Compile an optimized version of f.
+ i::FLAG_always_opt = true;
+ CompileRun(f_source);
+ CompileRun("f('a+', new X());");
+ CHECK(!i::V8::UseCrankshaft() ||
+ GetJSFunction(env->Global(), "f")->IsOptimized());
+
+ // Call f and force deoptimization while processing the binary operation.
+ CompileRun("deopt = true;"
+ "var result = f('a+', new X());"
+ "gc(); gc();");
+ }
+
+ CHECK(!GetJSFunction(env->Global(), "f")->IsOptimized());
+ CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
+ v8::Handle<v8::Value> result = env->Global()->Get(v8_str("result"));
+ CHECK(result->IsString());
+ v8::String::AsciiValue ascii(result);
+ CHECK_EQ("a+an X", *ascii);
+ CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount());
+}
+
+
+static void CompileConstructorWithDeoptimizingValueOf() {
+ CompileRun("var count = 0;"
+ "var result = 0;"
+ "var deopt = false;"
+ "function X() { };"
+ "X.prototype.valueOf = function () {"
+ " if (deopt) { count++; %DeoptimizeFunction(f); } return 8"
+ "};");
+}
+
+
+static void TestDeoptimizeBinaryOpHelper(LocalContext* env,
+ const char* binary_op) {
+ EmbeddedVector<char, SMALL_STRING_BUFFER_SIZE> f_source_buffer;
+ OS::SNPrintF(f_source_buffer,
+ "function f(x, y) { return x %s y; };",
+ binary_op);
+ char* f_source = f_source_buffer.start();
+
+ AllowNativesSyntaxNoInlining options;
+ // Compile function f and collect to type feedback to insert binary op stub
+ // call in the optimized code.
+ i::FLAG_prepare_always_opt = true;
+ CompileConstructorWithDeoptimizingValueOf();
+ CompileRun(f_source);
+ CompileRun("for (var i = 0; i < 5; i++) {"
+ " f(8, new X());"
+ "};");
+
+ // Compile an optimized version of f.
+ i::FLAG_always_opt = true;
+ CompileRun(f_source);
+ CompileRun("f(7, new X());");
+ CHECK(!i::V8::UseCrankshaft() ||
+ GetJSFunction((*env)->Global(), "f")->IsOptimized());
+
+ // Call f and force deoptimization while processing the binary operation.
+ CompileRun("deopt = true;"
+ "var result = f(7, new X());"
+ "gc(); gc();");
+
+ CHECK(!GetJSFunction((*env)->Global(), "f")->IsOptimized());
+}
+
+
+TEST(DeoptimizeBinaryOperationADD) {
+ v8::HandleScope scope;
+ const char* extension_list[] = { "v8/gc" };
+ v8::ExtensionConfiguration extensions(1, extension_list);
+ LocalContext env(&extensions);
+
+ TestDeoptimizeBinaryOpHelper(&env, "+");
+
+ CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
+ CHECK_EQ(15, env->Global()->Get(v8_str("result"))->Int32Value());
+ CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount());
+}
+
+
+TEST(DeoptimizeBinaryOperationSUB) {
+ v8::HandleScope scope;
+ const char* extension_list[] = { "v8/gc" };
+ v8::ExtensionConfiguration extensions(1, extension_list);
+ LocalContext env(&extensions);
+
+ TestDeoptimizeBinaryOpHelper(&env, "-");
+
+ CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
+ CHECK_EQ(-1, env->Global()->Get(v8_str("result"))->Int32Value());
+ CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount());
+}
+
+
+TEST(DeoptimizeBinaryOperationMUL) {
+ v8::HandleScope scope;
+ const char* extension_list[] = { "v8/gc" };
+ v8::ExtensionConfiguration extensions(1, extension_list);
+ LocalContext env(&extensions);
+
+ TestDeoptimizeBinaryOpHelper(&env, "*");
+
+ CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
+ CHECK_EQ(56, env->Global()->Get(v8_str("result"))->Int32Value());
+ CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount());
+}
+
+
+TEST(DeoptimizeBinaryOperationDIV) {
+ v8::HandleScope scope;
+ const char* extension_list[] = { "v8/gc" };
+ v8::ExtensionConfiguration extensions(1, extension_list);
+ LocalContext env(&extensions);
+
+ TestDeoptimizeBinaryOpHelper(&env, "/");
+
+ CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
+ CHECK_EQ(0, env->Global()->Get(v8_str("result"))->Int32Value());
+ CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount());
+}
+
+
+TEST(DeoptimizeBinaryOperationMOD) {
+ v8::HandleScope scope;
+ const char* extension_list[] = { "v8/gc" };
+ v8::ExtensionConfiguration extensions(1, extension_list);
+ LocalContext env(&extensions);
+
+ TestDeoptimizeBinaryOpHelper(&env, "%");
+
+ CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
+ CHECK_EQ(7, env->Global()->Get(v8_str("result"))->Int32Value());
+ CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount());
+}
+
+
+TEST(DeoptimizeCompare) {
+ v8::HandleScope scope;
+ const char* extension_list[] = { "v8/gc" };
+ v8::ExtensionConfiguration extensions(1, extension_list);
+ LocalContext env(&extensions);
+
+ const char* f_source = "function f(x, y) { return x < y; };";
+
+ {
+ AllowNativesSyntaxNoInlining options;
+ // Compile function f and collect to type feedback to insert compare ic
+ // call in the optimized code.
+ i::FLAG_prepare_always_opt = true;
+ CompileRun("var count = 0;"
+ "var result = 0;"
+ "var deopt = false;"
+ "function X() { };"
+ "X.prototype.toString = function () {"
+ " if (deopt) { count++; %DeoptimizeFunction(f); } return 'b'"
+ "};");
+ CompileRun(f_source);
+ CompileRun("for (var i = 0; i < 5; i++) {"
+ " f('a', new X());"
+ "};");
+
+ // Compile an optimized version of f.
+ i::FLAG_always_opt = true;
+ CompileRun(f_source);
+ CompileRun("f('a', new X());");
+ CHECK(!i::V8::UseCrankshaft() ||
+ GetJSFunction(env->Global(), "f")->IsOptimized());
+
+ // Call f and force deoptimization while processing the comparison.
+ CompileRun("deopt = true;"
+ "var result = f('a', new X());"
+ "gc(); gc();");
+ }
+
+ CHECK(!GetJSFunction(env->Global(), "f")->IsOptimized());
+ CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
+ CHECK_EQ(true, env->Global()->Get(v8_str("result"))->BooleanValue());
+ CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount());
+}
+
+
+TEST(DeoptimizeLoadICStoreIC) {
+ v8::HandleScope scope;
+ const char* extension_list[] = { "v8/gc" };
+ v8::ExtensionConfiguration extensions(1, extension_list);
+ LocalContext env(&extensions);
+
+ // Functions to generate load/store/keyed load/keyed store IC calls.
+ const char* f1_source = "function f1(x) { return x.y; };";
+ const char* g1_source = "function g1(x) { x.y = 1; };";
+ const char* f2_source = "function f2(x, y) { return x[y]; };";
+ const char* g2_source = "function g2(x, y) { x[y] = 1; };";
+
+ {
+ AllowNativesSyntaxNoInlining options;
+ // Compile functions and collect to type feedback to insert ic
+ // calls in the optimized code.
+ i::FLAG_prepare_always_opt = true;
+ CompileRun("var count = 0;"
+ "var result = 0;"
+ "var deopt = false;"
+ "function X() { };"
+ "X.prototype.__defineGetter__('y', function () {"
+ " if (deopt) { count++; %DeoptimizeFunction(f1); };"
+ " return 13;"
+ "});"
+ "X.prototype.__defineSetter__('y', function () {"
+ " if (deopt) { count++; %DeoptimizeFunction(g1); };"
+ "});"
+ "X.prototype.__defineGetter__('z', function () {"
+ " if (deopt) { count++; %DeoptimizeFunction(f2); };"
+ " return 13;"
+ "});"
+ "X.prototype.__defineSetter__('z', function () {"
+ " if (deopt) { count++; %DeoptimizeFunction(g2); };"
+ "});");
+ CompileRun(f1_source);
+ CompileRun(g1_source);
+ CompileRun(f2_source);
+ CompileRun(g2_source);
+ CompileRun("for (var i = 0; i < 5; i++) {"
+ " f1(new X());"
+ " g1(new X());"
+ " f2(new X(), 'z');"
+ " g2(new X(), 'z');"
+ "};");
+
+ // Compile an optimized version of the functions.
+ i::FLAG_always_opt = true;
+ CompileRun(f1_source);
+ CompileRun(g1_source);
+ CompileRun(f2_source);
+ CompileRun(g2_source);
+ CompileRun("f1(new X());");
+ CompileRun("g1(new X());");
+ CompileRun("f2(new X(), 'z');");
+ CompileRun("g2(new X(), 'z');");
+ if (i::V8::UseCrankshaft()) {
+ CHECK(GetJSFunction(env->Global(), "f1")->IsOptimized());
+ CHECK(GetJSFunction(env->Global(), "g1")->IsOptimized());
+ CHECK(GetJSFunction(env->Global(), "f2")->IsOptimized());
+ CHECK(GetJSFunction(env->Global(), "g2")->IsOptimized());
+ }
+
+ // Call functions and force deoptimization while processing the ics.
+ CompileRun("deopt = true;"
+ "var result = f1(new X());"
+ "g1(new X());"
+ "f2(new X(), 'z');"
+ "g2(new X(), 'z');"
+ "gc(); gc();");
+ }
+
+ CHECK(!GetJSFunction(env->Global(), "f1")->IsOptimized());
+ CHECK(!GetJSFunction(env->Global(), "g1")->IsOptimized());
+ CHECK(!GetJSFunction(env->Global(), "f2")->IsOptimized());
+ CHECK(!GetJSFunction(env->Global(), "g2")->IsOptimized());
+ CHECK_EQ(4, env->Global()->Get(v8_str("count"))->Int32Value());
+ CHECK_EQ(13, env->Global()->Get(v8_str("result"))->Int32Value());
+ CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount());
+}
+
+
+TEST(DeoptimizeLoadICStoreICNested) {
+ v8::HandleScope scope;
+ const char* extension_list[] = { "v8/gc" };
+ v8::ExtensionConfiguration extensions(1, extension_list);
+ LocalContext env(&extensions);
+
+ // Functions to generate load/store/keyed load/keyed store IC calls.
+ const char* f1_source = "function f1(x) { return x.y; };";
+ const char* g1_source = "function g1(x) { x.y = 1; };";
+ const char* f2_source = "function f2(x, y) { return x[y]; };";
+ const char* g2_source = "function g2(x, y) { x[y] = 1; };";
+
+ {
+ AllowNativesSyntaxNoInlining options;
+ // Compile functions and collect to type feedback to insert ic
+ // calls in the optimized code.
+ i::FLAG_prepare_always_opt = true;
+ CompileRun("var count = 0;"
+ "var result = 0;"
+ "var deopt = false;"
+ "function X() { };"
+ "X.prototype.__defineGetter__('y', function () {"
+ " g1(this);"
+ " return 13;"
+ "});"
+ "X.prototype.__defineSetter__('y', function () {"
+ " f2(this, 'z');"
+ "});"
+ "X.prototype.__defineGetter__('z', function () {"
+ " g2(this, 'z');"
+ "});"
+ "X.prototype.__defineSetter__('z', function () {"
+ " if (deopt) {"
+ " count++;"
+ " %DeoptimizeFunction(f1);"
+ " %DeoptimizeFunction(g1);"
+ " %DeoptimizeFunction(f2);"
+ " %DeoptimizeFunction(g2); };"
+ "});");
+ CompileRun(f1_source);
+ CompileRun(g1_source);
+ CompileRun(f2_source);
+ CompileRun(g2_source);
+ CompileRun("for (var i = 0; i < 5; i++) {"
+ " f1(new X());"
+ " g1(new X());"
+ " f2(new X(), 'z');"
+ " g2(new X(), 'z');"
+ "};");
+
+ // Compile an optimized version of the functions.
+ i::FLAG_always_opt = true;
+ CompileRun(f1_source);
+ CompileRun(g1_source);
+ CompileRun(f2_source);
+ CompileRun(g2_source);
+ CompileRun("f1(new X());");
+ CompileRun("g1(new X());");
+ CompileRun("f2(new X(), 'z');");
+ CompileRun("g2(new X(), 'z');");
+ if (i::V8::UseCrankshaft()) {
+ CHECK(GetJSFunction(env->Global(), "f1")->IsOptimized());
+ CHECK(GetJSFunction(env->Global(), "g1")->IsOptimized());
+ CHECK(GetJSFunction(env->Global(), "f2")->IsOptimized());
+ CHECK(GetJSFunction(env->Global(), "g2")->IsOptimized());
+ }
+
+ // Call functions and force deoptimization while processing the ics.
+ CompileRun("deopt = true;"
+ "var result = f1(new X());"
+ "gc(); gc();");
+ }
+
+ CHECK(!GetJSFunction(env->Global(), "f1")->IsOptimized());
+ CHECK(!GetJSFunction(env->Global(), "g1")->IsOptimized());
+ CHECK(!GetJSFunction(env->Global(), "f2")->IsOptimized());
+ CHECK(!GetJSFunction(env->Global(), "g2")->IsOptimized());
+ CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
+ CHECK_EQ(13, env->Global()->Get(v8_str("result"))->Int32Value());
+ CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount());
+}
diff --git a/test/cctest/test-heap-profiler.cc b/test/cctest/test-heap-profiler.cc
index 95314d7..ad242fe 100644
--- a/test/cctest/test-heap-profiler.cc
+++ b/test/cctest/test-heap-profiler.cc
@@ -1193,4 +1193,69 @@
CHECK_EQ(1, stream.eos_signaled());
}
+
+TEST(HeapSnapshotGetNodeById) {
+ v8::HandleScope scope;
+ LocalContext env;
+
+ const v8::HeapSnapshot* snapshot =
+ v8::HeapProfiler::TakeSnapshot(v8::String::New("id"));
+ const v8::HeapGraphNode* root = snapshot->GetRoot();
+ CHECK_EQ(root, snapshot->GetNodeById(root->GetId()));
+ for (int i = 0, count = root->GetChildrenCount(); i < count; ++i) {
+ const v8::HeapGraphEdge* prop = root->GetChild(i);
+ CHECK_EQ(
+ prop->GetToNode(), snapshot->GetNodeById(prop->GetToNode()->GetId()));
+ }
+ // Check a big id, which should not exist yet.
+ CHECK_EQ(NULL, snapshot->GetNodeById(0x1000000UL));
+}
+
+
+namespace {
+
+class TestActivityControl : public v8::ActivityControl {
+ public:
+ explicit TestActivityControl(int abort_count)
+ : done_(0), total_(0), abort_count_(abort_count) {}
+ ControlOption ReportProgressValue(int done, int total) {
+ done_ = done;
+ total_ = total;
+ return --abort_count_ != 0 ? kContinue : kAbort;
+ }
+ int done() { return done_; }
+ int total() { return total_; }
+
+ private:
+ int done_;
+ int total_;
+ int abort_count_;
+};
+}
+
+TEST(TakeHeapSnapshotAborting) {
+ v8::HandleScope scope;
+ LocalContext env;
+
+ const int snapshots_count = v8::HeapProfiler::GetSnapshotsCount();
+ TestActivityControl aborting_control(3);
+ const v8::HeapSnapshot* no_snapshot =
+ v8::HeapProfiler::TakeSnapshot(v8::String::New("abort"),
+ v8::HeapSnapshot::kFull,
+ &aborting_control);
+ CHECK_EQ(NULL, no_snapshot);
+ CHECK_EQ(snapshots_count, v8::HeapProfiler::GetSnapshotsCount());
+ CHECK_GT(aborting_control.total(), aborting_control.done());
+
+ TestActivityControl control(-1); // Don't abort.
+ const v8::HeapSnapshot* snapshot =
+ v8::HeapProfiler::TakeSnapshot(v8::String::New("full"),
+ v8::HeapSnapshot::kFull,
+ &control);
+ CHECK_NE(NULL, snapshot);
+ CHECK_EQ(snapshots_count + 1, v8::HeapProfiler::GetSnapshotsCount());
+ CHECK_EQ(control.total(), control.done());
+ CHECK_GT(control.total(), 0);
+}
+
#endif // ENABLE_LOGGING_AND_PROFILING
diff --git a/test/cctest/test-heap.cc b/test/cctest/test-heap.cc
index fbe66ec..a23ee17 100644
--- a/test/cctest/test-heap.cc
+++ b/test/cctest/test-heap.cc
@@ -511,7 +511,7 @@
if (!maybe_a->ToObject(&a)) continue;
CHECK(a->IsSymbol());
Object* b;
- MaybeObject* maybe_b = Heap::LookupAsciiSymbol(string);
+ MaybeObject *maybe_b = Heap::LookupAsciiSymbol(string);
if (!maybe_b->ToObject(&b)) continue;
CHECK_EQ(b, a);
CHECK(String::cast(b)->IsEqualTo(CStrVector(string)));
@@ -978,7 +978,9 @@
Handle<String> foo_name = Factory::LookupAsciiSymbol("foo");
// This compile will add the code to the compilation cache.
- CompileRun(source);
+ { v8::HandleScope scope;
+ CompileRun(source);
+ }
// Check function is compiled.
Object* func_value =
@@ -1000,8 +1002,8 @@
Heap::CollectAllGarbage(true);
// foo should no longer be in the compilation cache
- CHECK(!function->shared()->is_compiled());
- CHECK(!function->is_compiled());
+ CHECK(!function->shared()->is_compiled() || function->IsOptimized());
+ CHECK(!function->is_compiled() || function->IsOptimized());
// Call foo to get it recompiled.
CompileRun("foo()");
CHECK(function->shared()->is_compiled());
@@ -1021,6 +1023,20 @@
}
+// Count the number of user functions in the weak list of optimized
+// functions attached to a global context.
+static int CountOptimizedUserFunctions(v8::Handle<v8::Context> context) {
+ int count = 0;
+ Handle<Context> icontext = v8::Utils::OpenHandle(*context);
+ Object* object = icontext->get(Context::OPTIMIZED_FUNCTIONS_LIST);
+ while (object->IsJSFunction() && !JSFunction::cast(object)->IsBuiltin()) {
+ count++;
+ object = JSFunction::cast(object)->next_function_link();
+ }
+ return count;
+}
+
+
TEST(TestInternalWeakLists) {
static const int kNumTestContexts = 10;
@@ -1032,9 +1048,63 @@
// Create a number of global contests which gets linked together.
for (int i = 0; i < kNumTestContexts; i++) {
ctx[i] = v8::Context::New();
+
+ bool opt = (FLAG_always_opt && i::V8::UseCrankshaft());
+
CHECK_EQ(i + 1, CountGlobalContexts());
ctx[i]->Enter();
+
+ // Create a handle scope so no function objects get stuch in the outer
+ // handle scope
+ v8::HandleScope scope;
+ const char* source = "function f1() { };"
+ "function f2() { };"
+ "function f3() { };"
+ "function f4() { };"
+ "function f5() { };";
+ CompileRun(source);
+ CHECK_EQ(0, CountOptimizedUserFunctions(ctx[i]));
+ CompileRun("f1()");
+ CHECK_EQ(opt ? 1 : 0, CountOptimizedUserFunctions(ctx[i]));
+ CompileRun("f2()");
+ CHECK_EQ(opt ? 2 : 0, CountOptimizedUserFunctions(ctx[i]));
+ CompileRun("f3()");
+ CHECK_EQ(opt ? 3 : 0, CountOptimizedUserFunctions(ctx[i]));
+ CompileRun("f4()");
+ CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctions(ctx[i]));
+ CompileRun("f5()");
+ CHECK_EQ(opt ? 5 : 0, CountOptimizedUserFunctions(ctx[i]));
+
+ // Remove function f1, and
+ CompileRun("f1=null");
+
+ // Scavenge treats these references as strong.
+ for (int j = 0; j < 10; j++) {
+ Heap::PerformScavenge();
+ CHECK_EQ(opt ? 5 : 0, CountOptimizedUserFunctions(ctx[i]));
+ }
+
+ // Mark compact handles the weak references.
+ Heap::CollectAllGarbage(true);
+ CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctions(ctx[i]));
+
+ // Get rid of f3 and f5 in the same way.
+ CompileRun("f3=null");
+ for (int j = 0; j < 10; j++) {
+ Heap::PerformScavenge();
+ CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctions(ctx[i]));
+ }
+ Heap::CollectAllGarbage(true);
+ CHECK_EQ(opt ? 3 : 0, CountOptimizedUserFunctions(ctx[i]));
+ CompileRun("f5=null");
+ for (int j = 0; j < 10; j++) {
+ Heap::PerformScavenge();
+ CHECK_EQ(opt ? 3 : 0, CountOptimizedUserFunctions(ctx[i]));
+ }
+ Heap::CollectAllGarbage(true);
+ CHECK_EQ(opt ? 2 : 0, CountOptimizedUserFunctions(ctx[i]));
+
ctx[i]->Exit();
}
@@ -1076,6 +1146,25 @@
}
+// Count the number of user functions in the weak list of optimized
+// functions attached to a global context causing a GC after the
+// specified number of elements.
+static int CountOptimizedUserFunctionsWithGC(v8::Handle<v8::Context> context,
+ int n) {
+ int count = 0;
+ Handle<Context> icontext = v8::Utils::OpenHandle(*context);
+ Handle<Object> object(icontext->get(Context::OPTIMIZED_FUNCTIONS_LIST));
+ while (object->IsJSFunction() &&
+ !Handle<JSFunction>::cast(object)->IsBuiltin()) {
+ count++;
+ if (count == n) Heap::CollectAllGarbage(true);
+ object = Handle<Object>(
+ Object::cast(JSFunction::cast(*object)->next_function_link()));
+ }
+ return count;
+}
+
+
TEST(TestInternalWeakListsTraverseWithGC) {
static const int kNumTestContexts = 10;
@@ -1090,17 +1179,44 @@
ctx[i] = v8::Context::New();
CHECK_EQ(i + 1, CountGlobalContexts());
CHECK_EQ(i + 1, CountGlobalContextsWithGC(i / 2 + 1));
-
- ctx[i]->Enter();
- ctx[i]->Exit();
}
+
+ bool opt = (FLAG_always_opt && i::V8::UseCrankshaft());
+
+ // Compile a number of functions the length of the weak list of optimized
+ // functions both with and without GCs while iterating the list.
+ ctx[0]->Enter();
+ const char* source = "function f1() { };"
+ "function f2() { };"
+ "function f3() { };"
+ "function f4() { };"
+ "function f5() { };";
+ CompileRun(source);
+ CHECK_EQ(0, CountOptimizedUserFunctions(ctx[0]));
+ CompileRun("f1()");
+ CHECK_EQ(opt ? 1 : 0, CountOptimizedUserFunctions(ctx[0]));
+ CHECK_EQ(opt ? 1 : 0, CountOptimizedUserFunctionsWithGC(ctx[0], 1));
+ CompileRun("f2()");
+ CHECK_EQ(opt ? 2 : 0, CountOptimizedUserFunctions(ctx[0]));
+ CHECK_EQ(opt ? 2 : 0, CountOptimizedUserFunctionsWithGC(ctx[0], 1));
+ CompileRun("f3()");
+ CHECK_EQ(opt ? 3 : 0, CountOptimizedUserFunctions(ctx[0]));
+ CHECK_EQ(opt ? 3 : 0, CountOptimizedUserFunctionsWithGC(ctx[0], 1));
+ CompileRun("f4()");
+ CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctions(ctx[0]));
+ CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctionsWithGC(ctx[0], 2));
+ CompileRun("f5()");
+ CHECK_EQ(opt ? 5 : 0, CountOptimizedUserFunctions(ctx[0]));
+ CHECK_EQ(opt ? 5 : 0, CountOptimizedUserFunctionsWithGC(ctx[0], 4));
+
+ ctx[0]->Exit();
}
TEST(TestSizeOfObjectsVsHeapIteratorPrecision) {
InitializeVM();
intptr_t size_of_objects_1 = Heap::SizeOfObjects();
- HeapIterator iterator(HeapIterator::kPreciseFiltering);
+ HeapIterator iterator(HeapIterator::kFilterFreeListNodes);
intptr_t size_of_objects_2 = 0;
for (HeapObject* obj = iterator.next();
obj != NULL;
@@ -1124,3 +1240,65 @@
CHECK_GT(size_of_objects_2 / 100, delta);
}
}
+
+
+class HeapIteratorTestHelper {
+ public:
+ HeapIteratorTestHelper(Object* a, Object* b)
+ : a_(a), b_(b), a_found_(false), b_found_(false) {}
+ bool a_found() { return a_found_; }
+ bool b_found() { return b_found_; }
+ void IterateHeap(HeapIterator::HeapObjectsFiltering mode) {
+ HeapIterator iterator(mode);
+ for (HeapObject* obj = iterator.next();
+ obj != NULL;
+ obj = iterator.next()) {
+ if (obj == a_)
+ a_found_ = true;
+ else if (obj == b_)
+ b_found_ = true;
+ }
+ }
+ private:
+ Object* a_;
+ Object* b_;
+ bool a_found_;
+ bool b_found_;
+};
+
+TEST(HeapIteratorFilterUnreachable) {
+ InitializeVM();
+ v8::HandleScope scope;
+ CompileRun("a = {}; b = {};");
+ v8::Handle<Object> a(Top::context()->global()->GetProperty(
+ *Factory::LookupAsciiSymbol("a"))->ToObjectChecked());
+ v8::Handle<Object> b(Top::context()->global()->GetProperty(
+ *Factory::LookupAsciiSymbol("b"))->ToObjectChecked());
+ CHECK_NE(*a, *b);
+ {
+ HeapIteratorTestHelper helper(*a, *b);
+ helper.IterateHeap(HeapIterator::kFilterUnreachable);
+ CHECK(helper.a_found());
+ CHECK(helper.b_found());
+ }
+ CHECK(Top::context()->global()->DeleteProperty(
+ *Factory::LookupAsciiSymbol("a"), JSObject::FORCE_DELETION));
+ // We ensure that GC will not happen, so our raw pointer stays valid.
+ AssertNoAllocation no_alloc;
+ Object* a_saved = *a;
+ a.Clear();
+ // Verify that "a" object still resides in the heap...
+ {
+ HeapIteratorTestHelper helper(a_saved, *b);
+ helper.IterateHeap(HeapIterator::kNoFiltering);
+ CHECK(helper.a_found());
+ CHECK(helper.b_found());
+ }
+ // ...but is now unreachable.
+ {
+ HeapIteratorTestHelper helper(a_saved, *b);
+ helper.IterateHeap(HeapIterator::kFilterUnreachable);
+ CHECK(!helper.a_found());
+ CHECK(helper.b_found());
+ }
+}
diff --git a/test/cctest/test-log-stack-tracer.cc b/test/cctest/test-log-stack-tracer.cc
index 65be6bd..c85f6c0 100644
--- a/test/cctest/test-log-stack-tracer.cc
+++ b/test/cctest/test-log-stack-tracer.cc
@@ -39,6 +39,7 @@
#include "cctest.h"
#include "disassembler.h"
#include "register-allocator-inl.h"
+#include "vm-state-inl.h"
using v8::Function;
using v8::Local;
@@ -200,6 +201,7 @@
static void CheckJSFunctionAtAddress(const char* func_name, Address addr) {
+ CHECK(i::Heap::Contains(addr));
i::Object* obj = i::HeapObject::FromAddress(addr);
CHECK(obj->IsJSFunction());
CHECK(JSFunction::cast(obj)->shared()->name()->IsString());
@@ -298,10 +300,17 @@
// trace(EBP) [native (extension)]
// DoTrace(EBP) [native]
// StackTracer::Trace
- CHECK_GT(sample.frames_count, 1);
+
+ // The VM state tracking keeps track of external callbacks and puts
+ // them at the top of the sample stack.
+ int base = 0;
+ CHECK(sample.stack[0] == FUNCTION_ADDR(TraceExtension::Trace));
+ base++;
+
// Stack tracing will start from the first JS function, i.e. "JSFuncDoTrace"
- CheckJSFunctionAtAddress("JSFuncDoTrace", sample.stack[0]);
- CheckJSFunctionAtAddress("JSTrace", sample.stack[1]);
+ CHECK_GT(sample.frames_count, base + 1);
+ CheckJSFunctionAtAddress("JSFuncDoTrace", sample.stack[base + 0]);
+ CheckJSFunctionAtAddress("JSTrace", sample.stack[base + 1]);
}
@@ -311,6 +320,10 @@
// Top::c_entry_fp value. In this case, StackTracer uses passed frame
// pointer value as a starting point for stack walking.
TEST(PureJSStackTrace) {
+ // This test does not pass with inlining enabled since inlined functions
+ // don't appear in the stack trace.
+ i::FLAG_use_inlining = false;
+
TickSample sample;
InitTraceEnv(&sample);
@@ -341,10 +354,17 @@
// The last JS function called. It is only visible through
// sample.function, as its return address is above captured EBP value.
CheckJSFunctionAtAddress("JSFuncDoTrace", sample.function);
- CHECK_GT(sample.frames_count, 1);
+
+ // The VM state tracking keeps track of external callbacks and puts
+ // them at the top of the sample stack.
+ int base = 0;
+ CHECK(sample.stack[0] == FUNCTION_ADDR(TraceExtension::JSTrace));
+ base++;
+
// Stack sampling will start from the caller of JSFuncDoTrace, i.e. "JSTrace"
- CheckJSFunctionAtAddress("JSTrace", sample.stack[0]);
- CheckJSFunctionAtAddress("OuterJSTrace", sample.stack[1]);
+ CHECK_GT(sample.frames_count, base + 1);
+ CheckJSFunctionAtAddress("JSTrace", sample.stack[base + 0]);
+ CheckJSFunctionAtAddress("OuterJSTrace", sample.stack[base + 1]);
}
diff --git a/test/cctest/test-log-utils.cc b/test/cctest/test-log-utils.cc
index c99d770..861be12 100644
--- a/test/cctest/test-log-utils.cc
+++ b/test/cctest/test-log-utils.cc
@@ -12,7 +12,6 @@
using v8::internal::CStrVector;
using v8::internal::EmbeddedVector;
using v8::internal::LogDynamicBuffer;
-using v8::internal::LogRecordCompressor;
using v8::internal::MutableCStrVector;
using v8::internal::ScopedVector;
using v8::internal::Vector;
@@ -138,173 +137,4 @@
CHECK_EQ(0, ReadData(&dynabuf, 100 + seal_size, &buf));
}
-
-TEST(CompressorStore) {
- LogRecordCompressor comp(2);
- const Vector<const char> empty = CStrVector("");
- CHECK(comp.Store(empty));
- CHECK(!comp.Store(empty));
- CHECK(!comp.Store(empty));
- const Vector<const char> aaa = CStrVector("aaa");
- CHECK(comp.Store(aaa));
- CHECK(!comp.Store(aaa));
- CHECK(!comp.Store(aaa));
- CHECK(comp.Store(empty));
- CHECK(!comp.Store(empty));
- CHECK(!comp.Store(empty));
-}
-
-
-void CheckCompression(LogRecordCompressor* comp,
- const Vector<const char>& after) {
- EmbeddedVector<char, 100> result;
- CHECK(comp->RetrievePreviousCompressed(&result));
- CHECK_EQ(after, result);
-}
-
-
-void CheckCompression(LogRecordCompressor* comp,
- const char* after) {
- CheckCompression(comp, CStrVector(after));
-}
-
-
-TEST(CompressorNonCompressed) {
- LogRecordCompressor comp(0);
- CHECK(!comp.RetrievePreviousCompressed(NULL));
- const Vector<const char> empty = CStrVector("");
- CHECK(comp.Store(empty));
- CHECK(!comp.RetrievePreviousCompressed(NULL));
- const Vector<const char> a_x_20 = CStrVector("aaaaaaaaaaaaaaaaaaaa");
- CHECK(comp.Store(a_x_20));
- CheckCompression(&comp, empty);
- CheckCompression(&comp, empty);
- CHECK(comp.Store(empty));
- CheckCompression(&comp, a_x_20);
- CheckCompression(&comp, a_x_20);
-}
-
-
-TEST(CompressorSingleLine) {
- LogRecordCompressor comp(1);
- const Vector<const char> string_1 = CStrVector("eee,ddd,ccc,bbb,aaa");
- CHECK(comp.Store(string_1));
- const Vector<const char> string_2 = CStrVector("fff,ddd,ccc,bbb,aaa");
- CHECK(comp.Store(string_2));
- // string_1 hasn't been compressed.
- CheckCompression(&comp, string_1);
- CheckCompression(&comp, string_1);
- const Vector<const char> string_3 = CStrVector("hhh,ggg,ccc,bbb,aaa");
- CHECK(comp.Store(string_3));
- // string_2 compressed using string_1.
- CheckCompression(&comp, "fff#1:3");
- CheckCompression(&comp, "fff#1:3");
- CHECK(!comp.Store(string_3));
- // Expecting no changes.
- CheckCompression(&comp, "fff#1:3");
- CHECK(!comp.Store(string_3));
- // Expecting no changes.
- CheckCompression(&comp, "fff#1:3");
- const Vector<const char> string_4 = CStrVector("iii,hhh,ggg,ccc,bbb,aaa");
- CHECK(comp.Store(string_4));
- // string_3 compressed using string_2.
- CheckCompression(&comp, "hhh,ggg#1:7");
- const Vector<const char> string_5 = CStrVector("nnn,mmm,lll,kkk,jjj");
- CHECK(comp.Store(string_5));
- // string_4 compressed using string_3.
- CheckCompression(&comp, "iii,#1");
- const Vector<const char> string_6 = CStrVector("nnn,mmmmmm,lll,kkk,jjj");
- CHECK(comp.Store(string_6));
- // string_5 hasn't been compressed.
- CheckCompression(&comp, string_5);
- CHECK(comp.Store(string_5));
- // string_6 compressed using string_5.
- CheckCompression(&comp, "nnn,mmm#1:4");
- const Vector<const char> string_7 = CStrVector("nnnnnn,mmm,lll,kkk,jjj");
- CHECK(comp.Store(string_7));
- // string_5 compressed using string_6.
- CheckCompression(&comp, "nnn,#1:7");
- const Vector<const char> string_8 = CStrVector("xxn,mmm,lll,kkk,jjj");
- CHECK(comp.Store(string_8));
- // string_7 compressed using string_5.
- CheckCompression(&comp, "nnn#1");
- const Vector<const char> string_9 =
- CStrVector("aaaaaaaaaaaaa,bbbbbbbbbbbbbbbbb");
- CHECK(comp.Store(string_9));
- // string_8 compressed using string_7.
- CheckCompression(&comp, "xx#1:5");
- const Vector<const char> string_10 =
- CStrVector("aaaaaaaaaaaaa,cccccccbbbbbbbbbb");
- CHECK(comp.Store(string_10));
- // string_9 hasn't been compressed.
- CheckCompression(&comp, string_9);
- CHECK(comp.Store(string_1));
- // string_10 compressed using string_9.
- CheckCompression(&comp, "aaaaaaaaaaaaa,ccccccc#1:21");
-}
-
-
-
-TEST(CompressorMultiLines) {
- const int kWindowSize = 3;
- LogRecordCompressor comp(kWindowSize);
- const Vector<const char> string_1 = CStrVector("eee,ddd,ccc,bbb,aaa");
- CHECK(comp.Store(string_1));
- const Vector<const char> string_2 = CStrVector("iii,hhh,ggg,fff,aaa");
- CHECK(comp.Store(string_2));
- const Vector<const char> string_3 = CStrVector("mmm,lll,kkk,jjj,aaa");
- CHECK(comp.Store(string_3));
- const Vector<const char> string_4 = CStrVector("nnn,hhh,ggg,fff,aaa");
- CHECK(comp.Store(string_4));
- const Vector<const char> string_5 = CStrVector("ooo,lll,kkk,jjj,aaa");
- CHECK(comp.Store(string_5));
- // string_4 compressed using string_2.
- CheckCompression(&comp, "nnn#2:3");
- CHECK(comp.Store(string_1));
- // string_5 compressed using string_3.
- CheckCompression(&comp, "ooo#2:3");
- CHECK(comp.Store(string_4));
- // string_1 is out of buffer by now, so it shouldn't be compressed.
- CHECK_GE(3, kWindowSize);
- CheckCompression(&comp, string_1);
- CHECK(comp.Store(string_2));
- // string_4 compressed using itself.
- CheckCompression(&comp, "#3");
-}
-
-
-TEST(CompressorBestSelection) {
- LogRecordCompressor comp(3);
- const Vector<const char> string_1 = CStrVector("eee,ddd,ccc,bbb,aaa");
- CHECK(comp.Store(string_1));
- const Vector<const char> string_2 = CStrVector("ddd,ccc,bbb,aaa");
- CHECK(comp.Store(string_2));
- const Vector<const char> string_3 = CStrVector("fff,eee,ddd,ccc,bbb,aaa");
- CHECK(comp.Store(string_3));
- // string_2 compressed using string_1.
- CheckCompression(&comp, "#1:4");
- const Vector<const char> string_4 = CStrVector("nnn,hhh,ggg,fff,aaa");
- CHECK(comp.Store(string_4));
- // Compressing string_3 using string_1 gives a better compression than
- // using string_2.
- CheckCompression(&comp, "fff,#2");
-}
-
-
-TEST(CompressorCompressibility) {
- LogRecordCompressor comp(2);
- const Vector<const char> string_1 = CStrVector("eee,ddd,ccc,bbb,aaa");
- CHECK(comp.Store(string_1));
- const Vector<const char> string_2 = CStrVector("ccc,bbb,aaa");
- CHECK(comp.Store(string_2));
- const Vector<const char> string_3 = CStrVector("aaa");
- CHECK(comp.Store(string_3));
- // string_2 compressed using string_1.
- CheckCompression(&comp, "#1:8");
- const Vector<const char> string_4 = CStrVector("xxx");
- CHECK(comp.Store(string_4));
- // string_3 can't be compressed using string_2 --- too short.
- CheckCompression(&comp, string_3);
-}
-
#endif // ENABLE_LOGGING_AND_PROFILING
diff --git a/test/cctest/test-log.cc b/test/cctest/test-log.cc
index 710c10e..503e0cf 100644
--- a/test/cctest/test-log.cc
+++ b/test/cctest/test-log.cc
@@ -16,6 +16,7 @@
#include "cpu-profiler.h"
#include "v8threads.h"
#include "cctest.h"
+#include "vm-state-inl.h"
using v8::internal::Address;
using v8::internal::EmbeddedVector;
@@ -246,7 +247,8 @@
static void CheckThatProfilerWorks(LogBufferMatcher* matcher) {
- CHECK(!LoggerTestHelper::IsSamplerActive());
+ CHECK(i::RuntimeProfiler::IsEnabled() ||
+ !LoggerTestHelper::IsSamplerActive());
LoggerTestHelper::ResetSamplesTaken();
Logger::ResumeProfiler(v8::PROFILER_MODULE_CPU, 0);
@@ -272,7 +274,8 @@
}
Logger::PauseProfiler(v8::PROFILER_MODULE_CPU, 0);
- CHECK(!LoggerTestHelper::IsSamplerActive());
+ CHECK(i::RuntimeProfiler::IsEnabled() ||
+ !LoggerTestHelper::IsSamplerActive());
// Wait 50 msecs to allow Profiler thread to process the last
// tick sample it has got.
@@ -291,8 +294,12 @@
TEST(ProfLazyMode) {
ScopedLoggerInitializer initialize_logger(true);
- // No sampling should happen prior to resuming profiler.
- CHECK(!LoggerTestHelper::IsSamplerActive());
+ if (!i::V8::UseCrankshaft()) return;
+
+ // No sampling should happen prior to resuming profiler unless we
+ // are runtime profiling.
+ CHECK(i::RuntimeProfiler::IsEnabled() ||
+ !LoggerTestHelper::IsSamplerActive());
LogBufferMatcher matcher;
// Nothing must be logged until profiling is resumed.
@@ -403,7 +410,7 @@
class TestSampler : public v8::internal::Sampler {
public:
TestSampler()
- : Sampler(0, true),
+ : Sampler(0, true, true),
semaphore_(v8::internal::OS::CreateSemaphore(0)),
was_sample_stack_called_(false) {
}
@@ -431,30 +438,38 @@
} // namespace
TEST(ProfMultipleThreads) {
+ TestSampler* sampler = NULL;
+ {
+ v8::Locker locker;
+ sampler = new TestSampler();
+ sampler->Start();
+ CHECK(sampler->IsActive());
+ }
+
LoopingJsThread jsThread;
jsThread.Start();
LoopingNonJsThread nonJsThread;
nonJsThread.Start();
- TestSampler sampler;
- sampler.Start();
- CHECK(!sampler.WasSampleStackCalled());
+ CHECK(!sampler->WasSampleStackCalled());
jsThread.WaitForRunning();
jsThread.SendSigProf();
- CHECK(sampler.WaitForTick());
- CHECK(sampler.WasSampleStackCalled());
- sampler.Reset();
- CHECK(!sampler.WasSampleStackCalled());
+ CHECK(sampler->WaitForTick());
+ CHECK(sampler->WasSampleStackCalled());
+ sampler->Reset();
+ CHECK(!sampler->WasSampleStackCalled());
nonJsThread.WaitForRunning();
nonJsThread.SendSigProf();
- CHECK(!sampler.WaitForTick());
- CHECK(!sampler.WasSampleStackCalled());
- sampler.Stop();
+ CHECK(!sampler->WaitForTick());
+ CHECK(!sampler->WasSampleStackCalled());
+ sampler->Stop();
jsThread.Stop();
nonJsThread.Stop();
jsThread.Join();
nonJsThread.Join();
+
+ delete sampler;
}
#endif // __linux__
diff --git a/test/cctest/test-mark-compact.cc b/test/cctest/test-mark-compact.cc
index 9942567..86f105f 100644
--- a/test/cctest/test-mark-compact.cc
+++ b/test/cctest/test-mark-compact.cc
@@ -71,6 +71,10 @@
TEST(Promotion) {
+ // This test requires compaction. If compaction is turned off, we
+ // skip the entire test.
+ if (FLAG_never_compact) return;
+
// Ensure that we get a compacting collection so that objects are promoted
// from new space.
FLAG_gc_global = true;
diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc
index a93fc27..e642d1b 100755
--- a/test/cctest/test-parsing.cc
+++ b/test/cctest/test-parsing.cc
@@ -257,15 +257,22 @@
NULL
};
+ uintptr_t stack_limit = i::StackGuard::real_climit();
for (int i = 0; programs[i]; i++) {
const char* program = programs[i];
- unibrow::Utf8InputBuffer<256> stream(program, strlen(program));
+ i::Utf8ToUC16CharacterStream stream(
+ reinterpret_cast<const i::byte*>(program),
+ static_cast<unsigned>(strlen(program)));
i::CompleteParserRecorder log;
i::V8JavaScriptScanner scanner;
- scanner.Initialize(i::Handle<i::String>::null(), &stream);
- v8::preparser::PreParser preparser;
- bool result = preparser.PreParseProgram(&scanner, &log, true);
- CHECK(result);
+ scanner.Initialize(&stream);
+
+ v8::preparser::PreParser::PreParseResult result =
+ v8::preparser::PreParser::PreParseProgram(&scanner,
+ &log,
+ true,
+ stack_limit);
+ CHECK_EQ(v8::preparser::PreParser::kPreParseSuccess, result);
i::ScriptDataImpl data(log.ExtractData());
CHECK(!data.has_error());
}
@@ -284,9 +291,10 @@
// and then used the invalid currently scanned literal. This always
// failed in debug mode, and sometimes crashed in release mode.
- unibrow::Utf8InputBuffer<256> stream(program, strlen(program));
+ i::Utf8ToUC16CharacterStream stream(reinterpret_cast<const i::byte*>(program),
+ static_cast<unsigned>(strlen(program)));
i::ScriptDataImpl* data =
- i::ParserApi::PreParse(i::Handle<i::String>::null(), &stream, NULL);
+ i::ParserApi::PreParse(&stream, NULL);
CHECK(data->HasError());
delete data;
}
@@ -305,10 +313,10 @@
"try { } catch (e) { var foo = function () { /* first */ } }"
"var bar = function () { /* second */ }";
- unibrow::Utf8InputBuffer<256> stream(program, strlen(program));
+ i::Utf8ToUC16CharacterStream stream(reinterpret_cast<const i::byte*>(program),
+ static_cast<unsigned>(strlen(program)));
i::ScriptDataImpl* data =
- i::ParserApi::PartialPreParse(i::Handle<i::String>::null(),
- &stream, NULL);
+ i::ParserApi::PartialPreParse(&stream, NULL);
CHECK(!data->HasError());
data->Initialize();
@@ -327,3 +335,313 @@
CHECK_EQ('}', program[entry2.end_pos() - 1]);
delete data;
}
+
+
+TEST(PreParseOverflow) {
+ int marker;
+ i::StackGuard::SetStackLimit(
+ reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
+
+ size_t kProgramSize = 1024 * 1024;
+ i::SmartPointer<char> program(
+ reinterpret_cast<char*>(malloc(kProgramSize + 1)));
+ memset(*program, '(', kProgramSize);
+ program[kProgramSize] = '\0';
+
+ uintptr_t stack_limit = i::StackGuard::real_climit();
+
+ i::Utf8ToUC16CharacterStream stream(
+ reinterpret_cast<const i::byte*>(*program),
+ static_cast<unsigned>(kProgramSize));
+ i::CompleteParserRecorder log;
+ i::V8JavaScriptScanner scanner;
+ scanner.Initialize(&stream);
+
+
+ v8::preparser::PreParser::PreParseResult result =
+ v8::preparser::PreParser::PreParseProgram(&scanner,
+ &log,
+ true,
+ stack_limit);
+ CHECK_EQ(v8::preparser::PreParser::kPreParseStackOverflow, result);
+}
+
+
+class TestExternalResource: public v8::String::ExternalStringResource {
+ public:
+ explicit TestExternalResource(uint16_t* data, int length)
+ : data_(data), length_(static_cast<size_t>(length)) { }
+
+ ~TestExternalResource() { }
+
+ const uint16_t* data() const {
+ return data_;
+ }
+
+ size_t length() const {
+ return length_;
+ }
+ private:
+ uint16_t* data_;
+ size_t length_;
+};
+
+
+#define CHECK_EQU(v1, v2) CHECK_EQ(static_cast<int>(v1), static_cast<int>(v2))
+
+void TestCharacterStream(const char* ascii_source,
+ unsigned length,
+ unsigned start = 0,
+ unsigned end = 0) {
+ if (end == 0) end = length;
+ unsigned sub_length = end - start;
+ i::HandleScope test_scope;
+ i::SmartPointer<i::uc16> uc16_buffer(new i::uc16[length]);
+ for (unsigned i = 0; i < length; i++) {
+ uc16_buffer[i] = static_cast<i::uc16>(ascii_source[i]);
+ }
+ i::Vector<const char> ascii_vector(ascii_source, static_cast<int>(length));
+ i::Handle<i::String> ascii_string(
+ i::Factory::NewStringFromAscii(ascii_vector));
+ TestExternalResource resource(*uc16_buffer, length);
+ i::Handle<i::String> uc16_string(
+ i::Factory::NewExternalStringFromTwoByte(&resource));
+
+ i::ExternalTwoByteStringUC16CharacterStream uc16_stream(
+ i::Handle<i::ExternalTwoByteString>::cast(uc16_string), start, end);
+ i::GenericStringUC16CharacterStream string_stream(ascii_string, start, end);
+ i::Utf8ToUC16CharacterStream utf8_stream(
+ reinterpret_cast<const i::byte*>(ascii_source), end);
+ utf8_stream.SeekForward(start);
+
+ unsigned i = start;
+ while (i < end) {
+ // Read streams one char at a time
+ CHECK_EQU(i, uc16_stream.pos());
+ CHECK_EQU(i, string_stream.pos());
+ CHECK_EQU(i, utf8_stream.pos());
+ int32_t c0 = ascii_source[i];
+ int32_t c1 = uc16_stream.Advance();
+ int32_t c2 = string_stream.Advance();
+ int32_t c3 = utf8_stream.Advance();
+ i++;
+ CHECK_EQ(c0, c1);
+ CHECK_EQ(c0, c2);
+ CHECK_EQ(c0, c3);
+ CHECK_EQU(i, uc16_stream.pos());
+ CHECK_EQU(i, string_stream.pos());
+ CHECK_EQU(i, utf8_stream.pos());
+ }
+ while (i > start + sub_length / 4) {
+ // Pushback, re-read, pushback again.
+ int32_t c0 = ascii_source[i - 1];
+ CHECK_EQU(i, uc16_stream.pos());
+ CHECK_EQU(i, string_stream.pos());
+ CHECK_EQU(i, utf8_stream.pos());
+ uc16_stream.PushBack(c0);
+ string_stream.PushBack(c0);
+ utf8_stream.PushBack(c0);
+ i--;
+ CHECK_EQU(i, uc16_stream.pos());
+ CHECK_EQU(i, string_stream.pos());
+ CHECK_EQU(i, utf8_stream.pos());
+ int32_t c1 = uc16_stream.Advance();
+ int32_t c2 = string_stream.Advance();
+ int32_t c3 = utf8_stream.Advance();
+ i++;
+ CHECK_EQU(i, uc16_stream.pos());
+ CHECK_EQU(i, string_stream.pos());
+ CHECK_EQU(i, utf8_stream.pos());
+ CHECK_EQ(c0, c1);
+ CHECK_EQ(c0, c2);
+ CHECK_EQ(c0, c3);
+ uc16_stream.PushBack(c0);
+ string_stream.PushBack(c0);
+ utf8_stream.PushBack(c0);
+ i--;
+ CHECK_EQU(i, uc16_stream.pos());
+ CHECK_EQU(i, string_stream.pos());
+ CHECK_EQU(i, utf8_stream.pos());
+ }
+ unsigned halfway = start + sub_length / 2;
+ uc16_stream.SeekForward(halfway - i);
+ string_stream.SeekForward(halfway - i);
+ utf8_stream.SeekForward(halfway - i);
+ i = halfway;
+ CHECK_EQU(i, uc16_stream.pos());
+ CHECK_EQU(i, string_stream.pos());
+ CHECK_EQU(i, utf8_stream.pos());
+
+ while (i < end) {
+ // Read streams one char at a time
+ CHECK_EQU(i, uc16_stream.pos());
+ CHECK_EQU(i, string_stream.pos());
+ CHECK_EQU(i, utf8_stream.pos());
+ int32_t c0 = ascii_source[i];
+ int32_t c1 = uc16_stream.Advance();
+ int32_t c2 = string_stream.Advance();
+ int32_t c3 = utf8_stream.Advance();
+ i++;
+ CHECK_EQ(c0, c1);
+ CHECK_EQ(c0, c2);
+ CHECK_EQ(c0, c3);
+ CHECK_EQU(i, uc16_stream.pos());
+ CHECK_EQU(i, string_stream.pos());
+ CHECK_EQU(i, utf8_stream.pos());
+ }
+
+ int32_t c1 = uc16_stream.Advance();
+ int32_t c2 = string_stream.Advance();
+ int32_t c3 = utf8_stream.Advance();
+ CHECK_LT(c1, 0);
+ CHECK_LT(c2, 0);
+ CHECK_LT(c3, 0);
+}
+
+
+TEST(CharacterStreams) {
+ v8::HandleScope handles;
+ v8::Persistent<v8::Context> context = v8::Context::New();
+ v8::Context::Scope context_scope(context);
+
+ TestCharacterStream("abc\0\n\r\x7f", 7);
+ static const unsigned kBigStringSize = 4096;
+ char buffer[kBigStringSize + 1];
+ for (unsigned i = 0; i < kBigStringSize; i++) {
+ buffer[i] = static_cast<char>(i & 0x7f);
+ }
+ TestCharacterStream(buffer, kBigStringSize);
+
+ TestCharacterStream(buffer, kBigStringSize, 576, 3298);
+
+ TestCharacterStream("\0", 1);
+ TestCharacterStream("", 0);
+}
+
+
+TEST(Utf8CharacterStream) {
+ static const unsigned kMaxUC16CharU = unibrow::Utf8::kMaxThreeByteChar;
+ static const int kMaxUC16Char = static_cast<int>(kMaxUC16CharU);
+
+ static const int kAllUtf8CharsSize =
+ (unibrow::Utf8::kMaxOneByteChar + 1) +
+ (unibrow::Utf8::kMaxTwoByteChar - unibrow::Utf8::kMaxOneByteChar) * 2 +
+ (unibrow::Utf8::kMaxThreeByteChar - unibrow::Utf8::kMaxTwoByteChar) * 3;
+ static const unsigned kAllUtf8CharsSizeU =
+ static_cast<unsigned>(kAllUtf8CharsSize);
+
+ char buffer[kAllUtf8CharsSizeU];
+ unsigned cursor = 0;
+ for (int i = 0; i <= kMaxUC16Char; i++) {
+ cursor += unibrow::Utf8::Encode(buffer + cursor, i);
+ }
+ ASSERT(cursor == kAllUtf8CharsSizeU);
+
+ i::Utf8ToUC16CharacterStream stream(reinterpret_cast<const i::byte*>(buffer),
+ kAllUtf8CharsSizeU);
+ for (int i = 0; i <= kMaxUC16Char; i++) {
+ CHECK_EQU(i, stream.pos());
+ int32_t c = stream.Advance();
+ CHECK_EQ(i, c);
+ CHECK_EQU(i + 1, stream.pos());
+ }
+ for (int i = kMaxUC16Char; i >= 0; i--) {
+ CHECK_EQU(i + 1, stream.pos());
+ stream.PushBack(i);
+ CHECK_EQU(i, stream.pos());
+ }
+ int i = 0;
+ while (stream.pos() < kMaxUC16CharU) {
+ CHECK_EQU(i, stream.pos());
+ unsigned progress = stream.SeekForward(12);
+ i += progress;
+ int32_t c = stream.Advance();
+ if (i <= kMaxUC16Char) {
+ CHECK_EQ(i, c);
+ } else {
+ CHECK_EQ(-1, c);
+ }
+ i += 1;
+ CHECK_EQU(i, stream.pos());
+ }
+}
+
+#undef CHECK_EQU
+
+void TestStreamScanner(i::UC16CharacterStream* stream,
+ i::Token::Value* expected_tokens,
+ int skip_pos = 0, // Zero means not skipping.
+ int skip_to = 0) {
+ i::V8JavaScriptScanner scanner;
+ scanner.Initialize(stream, i::JavaScriptScanner::kAllLiterals);
+
+ int i = 0;
+ do {
+ i::Token::Value expected = expected_tokens[i];
+ i::Token::Value actual = scanner.Next();
+ CHECK_EQ(i::Token::String(expected), i::Token::String(actual));
+ if (scanner.location().end_pos == skip_pos) {
+ scanner.SeekForward(skip_to);
+ }
+ i++;
+ } while (expected_tokens[i] != i::Token::ILLEGAL);
+}
+
+TEST(StreamScanner) {
+ const char* str1 = "{ foo get for : */ <- \n\n /*foo*/ bib";
+ i::Utf8ToUC16CharacterStream stream1(reinterpret_cast<const i::byte*>(str1),
+ static_cast<unsigned>(strlen(str1)));
+ i::Token::Value expectations1[] = {
+ i::Token::LBRACE,
+ i::Token::IDENTIFIER,
+ i::Token::IDENTIFIER,
+ i::Token::FOR,
+ i::Token::COLON,
+ i::Token::MUL,
+ i::Token::DIV,
+ i::Token::LT,
+ i::Token::SUB,
+ i::Token::IDENTIFIER,
+ i::Token::EOS,
+ i::Token::ILLEGAL
+ };
+ TestStreamScanner(&stream1, expectations1, 0, 0);
+
+ const char* str2 = "case default const {THIS\nPART\nSKIPPED} do";
+ i::Utf8ToUC16CharacterStream stream2(reinterpret_cast<const i::byte*>(str2),
+ static_cast<unsigned>(strlen(str2)));
+ i::Token::Value expectations2[] = {
+ i::Token::CASE,
+ i::Token::DEFAULT,
+ i::Token::CONST,
+ i::Token::LBRACE,
+ // Skipped part here
+ i::Token::RBRACE,
+ i::Token::DO,
+ i::Token::EOS,
+ i::Token::ILLEGAL
+ };
+ ASSERT_EQ('{', str2[19]);
+ ASSERT_EQ('}', str2[37]);
+ TestStreamScanner(&stream2, expectations2, 20, 37);
+
+ const char* str3 = "{}}}}";
+ i::Token::Value expectations3[] = {
+ i::Token::LBRACE,
+ i::Token::RBRACE,
+ i::Token::RBRACE,
+ i::Token::RBRACE,
+ i::Token::RBRACE,
+ i::Token::EOS,
+ i::Token::ILLEGAL
+ };
+ // Skip zero-four RBRACEs.
+ for (int i = 0; i <= 4; i++) {
+ expectations3[6 - i] = i::Token::ILLEGAL;
+ expectations3[5 - i] = i::Token::EOS;
+ i::Utf8ToUC16CharacterStream stream3(
+ reinterpret_cast<const i::byte*>(str3),
+ static_cast<unsigned>(strlen(str3)));
+ TestStreamScanner(&stream3, expectations3, 1, 1 + i);
+ }
+}
diff --git a/test/cctest/test-profile-generator.cc b/test/cctest/test-profile-generator.cc
index f46191a..f849d40 100644
--- a/test/cctest/test-profile-generator.cc
+++ b/test/cctest/test-profile-generator.cc
@@ -757,6 +757,10 @@
TEST(RecordStackTraceAtStartProfiling) {
+ // This test does not pass with inlining enabled since inlined functions
+ // don't appear in the stack trace.
+ i::FLAG_use_inlining = false;
+
if (env.IsEmpty()) {
v8::HandleScope scope;
const char* extensions[] = { "v8/profiler" };
@@ -778,12 +782,16 @@
CpuProfiler::GetProfile(NULL, 0);
const ProfileTree* topDown = profile->top_down();
const ProfileNode* current = topDown->root();
+ const_cast<ProfileNode*>(current)->Print(0);
// The tree should look like this:
// (root)
// (anonymous function)
// a
// b
// c
+ // There can also be:
+ // startProfiling
+ // if the sampler managed to get a tick.
current = PickChild(current, "(anonymous function)");
CHECK_NE(NULL, const_cast<ProfileNode*>(current));
current = PickChild(current, "a");
@@ -792,7 +800,12 @@
CHECK_NE(NULL, const_cast<ProfileNode*>(current));
current = PickChild(current, "c");
CHECK_NE(NULL, const_cast<ProfileNode*>(current));
- CHECK_EQ(0, current->children()->length());
+ CHECK(current->children()->length() == 0 ||
+ current->children()->length() == 1);
+ if (current->children()->length() == 1) {
+ current = PickChild(current, "startProfiling");
+ CHECK_EQ(0, current->children()->length());
+ }
}
diff --git a/test/cctest/test-reloc-info.cc b/test/cctest/test-reloc-info.cc
new file mode 100644
index 0000000..2b9beac
--- /dev/null
+++ b/test/cctest/test-reloc-info.cc
@@ -0,0 +1,109 @@
+// Copyright 2010 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 "cctest.h"
+#include "assembler.h"
+
+namespace v8 {
+namespace internal {
+
+static void WriteRinfo(RelocInfoWriter* writer,
+ byte* pc, RelocInfo::Mode mode, intptr_t data) {
+ RelocInfo rinfo(pc, mode, data);
+ writer->Write(&rinfo);
+}
+
+
+// Tests that writing both types of positions and then reading either
+// or both works as expected.
+TEST(Positions) {
+ const int instr_size = 10 << 10;
+ const int reloc_size = 10 << 10;
+ const int buf_size = instr_size + reloc_size;
+ SmartPointer<byte> buf(new byte[buf_size]);
+ byte* pc = *buf;
+ CodeDesc desc = { *buf, buf_size, instr_size, reloc_size, NULL };
+
+ RelocInfoWriter writer(*buf + buf_size, pc);
+ for (int i = 0, pos = 0; i < 100; i++, pc += i, pos += i) {
+ RelocInfo::Mode mode = (i % 2 == 0) ?
+ RelocInfo::STATEMENT_POSITION : RelocInfo::POSITION;
+ WriteRinfo(&writer, pc, mode, pos);
+ }
+
+ // Read only (non-statement) positions.
+ {
+ RelocIterator it(desc, RelocInfo::ModeMask(RelocInfo::POSITION));
+ pc = *buf;
+ for (int i = 0, pos = 0; i < 100; i++, pc += i, pos += i) {
+ RelocInfo::Mode mode = (i % 2 == 0) ?
+ RelocInfo::STATEMENT_POSITION : RelocInfo::POSITION;
+ if (mode == RelocInfo::POSITION) {
+ CHECK_EQ(pc, it.rinfo()->pc());
+ CHECK_EQ(mode, it.rinfo()->rmode());
+ CHECK_EQ(pos, static_cast<int>(it.rinfo()->data()));
+ it.next();
+ }
+ }
+ CHECK(it.done());
+ }
+
+ // Read only statement positions.
+ {
+ RelocIterator it(desc, RelocInfo::ModeMask(RelocInfo::STATEMENT_POSITION));
+ pc = *buf;
+ for (int i = 0, pos = 0; i < 100; i++, pc += i, pos += i) {
+ RelocInfo::Mode mode = (i % 2 == 0) ?
+ RelocInfo::STATEMENT_POSITION : RelocInfo::POSITION;
+ if (mode == RelocInfo::STATEMENT_POSITION) {
+ CHECK_EQ(pc, it.rinfo()->pc());
+ CHECK_EQ(mode, it.rinfo()->rmode());
+ CHECK_EQ(pos, static_cast<int>(it.rinfo()->data()));
+ it.next();
+ }
+ }
+ CHECK(it.done());
+ }
+
+ // Read both types of positions.
+ {
+ RelocIterator it(desc, RelocInfo::kPositionMask);
+ pc = *buf;
+ for (int i = 0, pos = 0; i < 100; i++, pc += i, pos += i) {
+ RelocInfo::Mode mode = (i % 2 == 0) ?
+ RelocInfo::STATEMENT_POSITION : RelocInfo::POSITION;
+ CHECK_EQ(pc, it.rinfo()->pc());
+ CHECK_EQ(mode, it.rinfo()->rmode());
+ CHECK_EQ(pos, static_cast<int>(it.rinfo()->data()));
+ it.next();
+ }
+ CHECK(it.done());
+ }
+}
+
+} } // namespace v8::internal
diff --git a/test/cctest/test-spaces.cc b/test/cctest/test-spaces.cc
index b399a4e..706c6bf 100644
--- a/test/cctest/test-spaces.cc
+++ b/test/cctest/test-spaces.cc
@@ -95,13 +95,13 @@
OldSpace faked_space(Heap::MaxReserved(), OLD_POINTER_SPACE, NOT_EXECUTABLE);
int total_pages = 0;
- int requested = 2;
+ int requested = MemoryAllocator::kPagesPerChunk;
int allocated;
- // If we request two pages, we should get one or two.
+ // If we request n pages, we should get n or n - 1.
Page* first_page =
MemoryAllocator::AllocatePages(requested, &allocated, &faked_space);
CHECK(first_page->is_valid());
- CHECK(allocated > 0 && allocated <= 2);
+ CHECK(allocated == requested || allocated == requested - 1);
total_pages += allocated;
Page* last_page = first_page;
@@ -110,11 +110,11 @@
last_page = p;
}
- // Again, we should get one or two pages.
+ // Again, we should get n or n - 1 pages.
Page* others =
MemoryAllocator::AllocatePages(requested, &allocated, &faked_space);
CHECK(others->is_valid());
- CHECK(allocated > 0 && allocated <= 2);
+ CHECK(allocated == requested || allocated == requested - 1);
total_pages += allocated;
MemoryAllocator::SetNextPage(last_page, others);
@@ -129,11 +129,10 @@
CHECK(second_page->is_valid());
// Freeing pages at the first chunk starting at or after the second page
- // should free the entire second chunk. It will return the last page in the
- // first chunk (if the second page was in the first chunk) or else an
- // invalid page (if the second page was the start of the second chunk).
+ // should free the entire second chunk. It will return the page it was passed
+ // (since the second page was in the first chunk).
Page* free_return = MemoryAllocator::FreePages(second_page);
- CHECK(free_return == last_page || !free_return->is_valid());
+ CHECK(free_return == second_page);
MemoryAllocator::SetNextPage(first_page, free_return);
// Freeing pages in the first chunk starting at the first page should free
diff --git a/test/cctest/test-utils.cc b/test/cctest/test-utils.cc
index 88ef0a2..b48dcb8 100644
--- a/test/cctest/test-utils.cc
+++ b/test/cctest/test-utils.cc
@@ -103,6 +103,7 @@
TEST(MemCopy) {
+ V8::Initialize(NULL);
const int N = kMinComplexMemCopy + 128;
Vector<byte> buffer1 = Vector<byte>::New(N);
Vector<byte> buffer2 = Vector<byte>::New(N);
diff --git a/test/cctest/test-version.cc b/test/cctest/test-version.cc
index 6d26855..6bec4b7 100644
--- a/test/cctest/test-version.cc
+++ b/test/cctest/test-version.cc
@@ -74,6 +74,20 @@
TEST(VersionString) {
+#ifdef USE_SIMULATOR
+ CheckVersion(0, 0, 0, 0, false, "0.0.0 SIMULATOR", "libv8-0.0.0.so");
+ CheckVersion(0, 0, 0, 0, true,
+ "0.0.0 (candidate) SIMULATOR", "libv8-0.0.0-candidate.so");
+ CheckVersion(1, 0, 0, 0, false, "1.0.0 SIMULATOR", "libv8-1.0.0.so");
+ CheckVersion(1, 0, 0, 0, true,
+ "1.0.0 (candidate) SIMULATOR", "libv8-1.0.0-candidate.so");
+ CheckVersion(1, 0, 0, 1, false, "1.0.0.1 SIMULATOR", "libv8-1.0.0.1.so");
+ CheckVersion(1, 0, 0, 1, true,
+ "1.0.0.1 (candidate) SIMULATOR", "libv8-1.0.0.1-candidate.so");
+ CheckVersion(2, 5, 10, 7, false, "2.5.10.7 SIMULATOR", "libv8-2.5.10.7.so");
+ CheckVersion(2, 5, 10, 7, true,
+ "2.5.10.7 (candidate) SIMULATOR", "libv8-2.5.10.7-candidate.so");
+#else
CheckVersion(0, 0, 0, 0, false, "0.0.0", "libv8-0.0.0.so");
CheckVersion(0, 0, 0, 0, true,
"0.0.0 (candidate)", "libv8-0.0.0-candidate.so");
@@ -86,4 +100,5 @@
CheckVersion(2, 5, 10, 7, false, "2.5.10.7", "libv8-2.5.10.7.so");
CheckVersion(2, 5, 10, 7, true,
"2.5.10.7 (candidate)", "libv8-2.5.10.7-candidate.so");
+#endif
}
diff --git a/test/es5conform/es5conform.status b/test/es5conform/es5conform.status
index 5add082..a51bd30 100644
--- a/test/es5conform/es5conform.status
+++ b/test/es5conform/es5conform.status
@@ -29,6 +29,8 @@
def UNIMPLEMENTED = PASS || FAIL
def FAIL_OK = FAIL, OKAY
+
+##############################################################################
# Non UTF8 characters in test files.
chapter10/10.4/10.4.2/10.4.2-3-c-2-s: FAIL_OK
chapter10/10.4/10.4.2/10.4.2-3-c-1-s: FAIL_OK
@@ -86,7 +88,7 @@
# than those described in the spec - but according to spec they can
# have additional properties.
# All compareArray calls in these tests could be exchanged with a
-# isSubsetOfArray call (I will upload a path to the es5conform site).
+# isSubsetOfArray call (I will upload a patch to the es5conform site).
# SUBSETFAIL
chapter15/15.2/15.2.3/15.2.3.4/15.2.3.4-4-1: FAIL_OK
@@ -110,12 +112,6 @@
chapter15/15.2/15.2.3/15.2.3.4/15.2.3.4-4-7: FAIL_OK
# SUBSETFAIL
-chapter15/15.2/15.2.3/15.2.3.4/15.2.3.4-4-8: FAIL_OK
-
-# SUBSETFAIL
-chapter15/15.2/15.2.3/15.2.3.4/15.2.3.4-4-9: FAIL_OK
-
-# SUBSETFAIL
chapter15/15.2/15.2.3/15.2.3.4/15.2.3.4-4-11: FAIL_OK
# We do not implement all methods on RegExp.
diff --git a/test/message/message.status b/test/message/message.status
index c4a3842..70354ce 100644
--- a/test/message/message.status
+++ b/test/message/message.status
@@ -30,6 +30,8 @@
# All tests in the bug directory are expected to fail.
bugs: FAIL
+
+##############################################################################
[ $arch == mips ]
# Skip all tests on MIPS.
diff --git a/test/message/try-catch-finally-return-in-finally.js b/test/message/try-catch-finally-return-in-finally.js
index d23fe35..58a62a8 100644
--- a/test/message/try-catch-finally-return-in-finally.js
+++ b/test/message/try-catch-finally-return-in-finally.js
@@ -36,4 +36,5 @@
}
}
-print(f());
+var result = f();
+if (result != 42) print("Wrong result: " + result);
diff --git a/test/message/try-catch-finally-return-in-finally.out b/test/message/try-catch-finally-return-in-finally.out
index 1c42ee0..f59f5c6 100644
--- a/test/message/try-catch-finally-return-in-finally.out
+++ b/test/message/try-catch-finally-return-in-finally.out
@@ -24,5 +24,3 @@
# 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.
-
-42
diff --git a/test/message/try-finally-return-in-finally.js b/test/message/try-finally-return-in-finally.js
index 6ec8970..0e46193 100644
--- a/test/message/try-finally-return-in-finally.js
+++ b/test/message/try-finally-return-in-finally.js
@@ -34,4 +34,5 @@
}
}
-print(f());
+var result = f();
+if (result != 42) print("Wrong result: " + result);
diff --git a/test/message/try-finally-return-in-finally.out b/test/message/try-finally-return-in-finally.out
index 1c42ee0..f59f5c6 100644
--- a/test/message/try-finally-return-in-finally.out
+++ b/test/message/try-finally-return-in-finally.out
@@ -24,5 +24,3 @@
# 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.
-
-42
diff --git a/test/mjsunit/regress/regress-3408144.js b/test/mjsunit/accessors-on-global-object.js
similarity index 60%
copy from test/mjsunit/regress/regress-3408144.js
copy to test/mjsunit/accessors-on-global-object.js
index 6e292d6..8d95692 100644
--- a/test/mjsunit/regress/regress-3408144.js
+++ b/test/mjsunit/accessors-on-global-object.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,13 +25,48 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test incorrect code generation for alternations on ARM.
+// Test that installing a getter on the global object instead of a
+// normal property works.
+var x = 0;
-// Flags: --nofull-compiler
+function getX() { return x; }
-function foo() {
- return (0 > ("10"||10) - 1);
+for (var i = 0; i < 10; i++) {
+ assertEquals(i < 5 ? 0 : 42, getX());
+ if (i == 4) __defineGetter__("x", function() { return 42; });
}
-assertFalse(foo());
+
+// Test that installing a setter on the global object instead of a
+// normal property works.
+
+var y = 0;
+var setter_y;
+
+function setY(value) { y = value; }
+
+for (var i = 0; i < 10; i++) {
+ setY(i);
+ assertEquals(i < 5 ? i : 2 * i, y);
+ if (i == 4) {
+ __defineSetter__("y", function(value) { setter_y = 2 * value; });
+ __defineGetter__("y", function() { return setter_y; });
+ }
+}
+
+
+// Test that replacing a getter with a normal property works as
+// expected.
+
+__defineGetter__("z", function() { return 42; });
+
+function getZ() { return z; }
+
+for (var i = 0; i < 10; i++) {
+ assertEquals(i < 5 ? 42 : 0, getZ());
+ if (i == 4) {
+ delete z;
+ var z = 0;
+ }
+}
diff --git a/test/mjsunit/regress/regress-3408144.js b/test/mjsunit/apply-arguments-gc-safepoint.js
similarity index 80%
copy from test/mjsunit/regress/regress-3408144.js
copy to test/mjsunit/apply-arguments-gc-safepoint.js
index 6e292d6..57ed8cc 100644
--- a/test/mjsunit/regress/regress-3408144.js
+++ b/test/mjsunit/apply-arguments-gc-safepoint.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,13 +25,20 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test incorrect code generation for alternations on ARM.
+// Flags: --expose-gc
+// Test that safepoint tables are correctly generated for apply with
+// arguments in the case where arguments adaption is needed.
-// Flags: --nofull-compiler
-
-function foo() {
- return (0 > ("10"||10) - 1);
+function f(x, y) {
+ if (x == 149999) gc();
+ return x + y;
}
-assertFalse(foo());
+function g() {
+ f.apply(this, arguments);
+}
+
+for (var i = 0; i < 150000; i++) {
+ g(i);
+}
diff --git a/test/mjsunit/array-functions-prototype.js b/test/mjsunit/array-functions-prototype.js
index ea0dc61..b68ee73 100644
--- a/test/mjsunit/array-functions-prototype.js
+++ b/test/mjsunit/array-functions-prototype.js
@@ -55,7 +55,7 @@
// shift.
// ----------------------------------------------------------------------
-function runTest() {
+function runTest1() {
var nonArray = new constructor();
var array = ['zero', , 'two'];
// Shift away the zero.
@@ -80,13 +80,13 @@
assertEquals('two', nonArray[2]);
}
-runTest();
+runTest1();
// ----------------------------------------------------------------------
// unshift.
// ----------------------------------------------------------------------
-runTest = function() {
+runTest2 = function() {
var nonArray = new constructor();
var array = ['zero', , 'two'];
// Unshift a new 'zero'.
@@ -110,14 +110,14 @@
assertEquals('two', nonArray[3]);
}
-runTest();
+runTest2();
// ----------------------------------------------------------------------
// splice
// ----------------------------------------------------------------------
-runTest = function() {
+runTest3 = function() {
var nonArray = new constructor();
var array = ['zero', , 'two'];
// Delete the first element by splicing in nothing.
@@ -140,14 +140,14 @@
assertEquals('two', nonArray[2]);
};
-runTest();
+runTest3();
// ----------------------------------------------------------------------
// slice
// ----------------------------------------------------------------------
-runTest = function() {
+runTest4 = function() {
var nonArray = new constructor();
var array = ['zero', , 'two'];
// Again Spidermonkey is inconsistent. (array.slice(0, 3))[1] is
@@ -156,4 +156,4 @@
assertArrayEquals(['zero', 'one', 'two'], Array.prototype.slice.call(nonArray, 0, 3));
};
-runTest();
+runTest4();
diff --git a/test/mjsunit/array-slice.js b/test/mjsunit/array-slice.js
index 8f9ce53..50b5b27 100644
--- a/test/mjsunit/array-slice.js
+++ b/test/mjsunit/array-slice.js
@@ -218,3 +218,16 @@
assertTrue(delete Array.prototype[5]);
}
})();
+
+// Check slicing on arguments object.
+(function() {
+ function func(expected, a0, a1, a2) {
+ assertEquals(expected, Array.prototype.slice.call(arguments, 1));
+ }
+
+ func([]);
+ func(['a'], 'a');
+ func(['a', 1], 'a', 1);
+ func(['a', 1, undefined], 'a', 1, undefined);
+ func(['a', 1, undefined, void(0)], 'a', 1, undefined, void(0));
+})();
diff --git a/test/mjsunit/array-sort.js b/test/mjsunit/array-sort.js
index a082abc..7060c5f 100644
--- a/test/mjsunit/array-sort.js
+++ b/test/mjsunit/array-sort.js
@@ -1,4 +1,4 @@
-// Copyright 2008 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -360,3 +360,18 @@
}
TestSpecialCasesInheritedElementSort();
+
+// Test that sort calls compare function with global object as receiver,
+// and with only elements of the array as arguments.
+function o(v) {
+ return {__proto__: o.prototype, val: v};
+}
+var arr = [o(1), o(2), o(4), o(8), o(16), o(32), o(64), o(128), o(256), o(-0)];
+var global = this;
+function cmpTest(a, b) {
+ assertEquals(global, this);
+ assertTrue(a instanceof o);
+ assertTrue(b instanceof o);
+ return a.val - b.val;
+}
+arr.sort(cmpTest);
\ No newline at end of file
diff --git a/test/mjsunit/bitops-info.js b/test/mjsunit/bitops-info.js
index 4b114c5..4660fdf 100644
--- a/test/mjsunit/bitops-info.js
+++ b/test/mjsunit/bitops-info.js
@@ -37,6 +37,7 @@
return 1600822924; // It's a signed Int32.
}
+
function f() {
var x = non_int32(); // Not a constant.
var y = hidden_smi(); // Not a constant.
@@ -65,13 +66,6 @@
assertEquals(46512102 & 2600822924, x & y, "10rev");
assertEquals(1600822924 & 2600822924, x & z, "11rev");
- assertEquals((46512102 & -0x20123456) | 1, (y & -0x20123456) | 1, "12");
- assertEquals((1600822924 & -0x20123456) | 1, (z & -0x20123456) | 1, "13");
- assertEquals((2600822924 & -0x20123456) | 1, (x & -0x20123456) | 1, "14");
- assertEquals((46512102 & -0x20123456) | 1, (-0x20123456 & y) | 1, "12rev");
- assertEquals((1600822924 & -0x20123456) | 1, (-0x20123456 & z) | 1, "13rev");
- assertEquals((2600822924 & -0x20123456) | 1, (-0x20123456 & x) | 1, "14rev");
-
assertEquals(2600822924 & 2600822924, x & x, "xx");
assertEquals(y, y & y, "yy");
assertEquals(z, z & z, "zz");
diff --git a/test/mjsunit/codegen-coverage.js b/test/mjsunit/codegen-coverage.js
index 8e7f189..cd53863 100644
--- a/test/mjsunit/codegen-coverage.js
+++ b/test/mjsunit/codegen-coverage.js
@@ -25,8 +25,6 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Flags: --nofull-compiler --nofast-compiler
-
// Test paths in the code generator where values in specific registers
// get moved around.
function identity(x) {
diff --git a/test/mjsunit/regress/regress-3408144.js b/test/mjsunit/compiler/alloc-number.js
similarity index 81%
copy from test/mjsunit/regress/regress-3408144.js
copy to test/mjsunit/compiler/alloc-number.js
index 6e292d6..85c39de 100644
--- a/test/mjsunit/regress/regress-3408144.js
+++ b/test/mjsunit/compiler/alloc-number.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,13 +25,15 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test incorrect code generation for alternations on ARM.
-
-// Flags: --nofull-compiler
-
-function foo() {
- return (0 > ("10"||10) - 1);
+// Try to get a GC because of a heap number allocation while we
+// have live values (o) in a register.
+function f(o) {
+ var x = 1.5;
+ var y = 2.5;
+ for (var i = 1; i < 100000; i+=2) o.val = x + y + i;
+ return o;
}
-assertFalse(foo());
+var o = { val: 0 };
+for (var i = 0; i < 100; i++) f(o);
diff --git a/test/mjsunit/compiler/array-access.js b/test/mjsunit/compiler/array-access.js
new file mode 100644
index 0000000..65b3c99
--- /dev/null
+++ b/test/mjsunit/compiler/array-access.js
@@ -0,0 +1,132 @@
+// Copyright 2010 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.
+
+function Get0(a) {
+ return a[0];
+}
+
+function GetN(a,n) {
+ return a[n];
+}
+
+function GetA0(a) {
+ return a[a[0]];
+}
+
+function GetAN(a,n) {
+ return a[a[n]];
+}
+
+function GetAAN(a,n) {
+ return a[a[a[n]]];
+}
+
+function RunGetTests() {
+ var a = [2,0,1];
+ assertEquals(2, Get0(a));
+
+ assertEquals(2, GetN(a, 0));
+ assertEquals(0, GetN(a, 1));
+ assertEquals(1, GetN(a, 2));
+
+ assertEquals(1, GetA0(a));
+
+ assertEquals(1, GetAN(a,0));
+ assertEquals(2, GetAN(a,1));
+ assertEquals(0, GetAN(a,2));
+
+ assertEquals(0, GetAAN(a,0));
+ assertEquals(1, GetAAN(a,1));
+ assertEquals(2, GetAAN(a,2));
+}
+
+
+function Set07(a) {
+ a[0] = 7;
+}
+
+function Set0V(a, v) {
+ a[0] = v;
+}
+
+function SetN7(a, n) {
+ a[n] = 7;
+}
+
+function SetNX(a, n, x) {
+ a[n] = x;
+}
+
+function RunSetTests(a) {
+ Set07(a);
+ assertEquals(7, a[0]);
+ assertEquals(0, a[1]);
+ assertEquals(0, a[2]);
+
+ Set0V(a, 1);
+ assertEquals(1, a[0]);
+ assertEquals(0, a[1]);
+ assertEquals(0, a[2]);
+
+ SetN7(a, 2);
+ assertEquals(1, a[0]);
+ assertEquals(0, a[1]);
+ assertEquals(7, a[2]);
+
+ SetNX(a, 1, 5);
+ assertEquals(1, a[0]);
+ assertEquals(5, a[1]);
+ assertEquals(7, a[2]);
+
+ for (var i = 0; i < 3; i++) SetNX(a, i, 0);
+ assertEquals(0, a[0]);
+ assertEquals(0, a[1]);
+ assertEquals(0, a[2]);
+}
+
+function RunArrayBoundsCheckTest() {
+ var g = [1,2,3];
+
+ function f(a, i) { a[i] = 42; }
+
+ for (var i = 0; i < 100000; i++) { f(g, 0); }
+
+ f(g, 4);
+
+ assertEquals(42, g[0]);
+ assertEquals(42, g[4]);
+}
+
+var a = [0,0,0];
+var o = {0: 0, 1: 0, 2: 0};
+for (var i = 0; i < 1000; i++) {
+ RunGetTests();
+ RunSetTests(a);
+ RunSetTests(o);
+}
+
+RunArrayBoundsCheckTest();
diff --git a/test/mjsunit/regress/regress-1146.js b/test/mjsunit/compiler/array-length.js
similarity index 75%
rename from test/mjsunit/regress/regress-1146.js
rename to test/mjsunit/compiler/array-length.js
index e8028ce..7adb9ab 100644
--- a/test/mjsunit/regress/regress-1146.js
+++ b/test/mjsunit/compiler/array-length.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,24 +25,18 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test keyed calls with different key types.
-function F() {}
-var a = new F();
-function f(i) { return a[i](); }
+function ArrayLength(a) { return a.length; }
-a.first = function() { return 11; }
-a[0] = function() { return 22; }
-var obj = {};
-a[obj] = function() { return 33; }
+function Test(a0, a2, a5) {
+ assertEquals(0, ArrayLength(a0));
+ assertEquals(2, ArrayLength(a2));
+ assertEquals(5, ArrayLength(a5));
+}
-// Make object slow-case.
-a.foo = 0;
-delete a.foo;
-// Do multiple calls for IC transitions.
-var b = "first";
-f(b);
-f(b);
-
-assertEquals(11, f(b));
-assertEquals(22, f(0));
-assertEquals(33, f(obj));
+var a0 = [];
+var a2 = [1,2];
+var a5 = [1,2,3,4,5];
+for (var i = 0; i < 10000000; i++) Test(a0, a2, a5);
+assertEquals("undefined", typeof(ArrayLength(0)));
+for (var i = 0; i < 10000000; i++) Test(a0, a2, a5);
+assertEquals(4, ArrayLength("hest"));
diff --git a/test/mjsunit/compiler/assignment-deopt.js b/test/mjsunit/compiler/assignment-deopt.js
new file mode 100644
index 0000000..74f185b
--- /dev/null
+++ b/test/mjsunit/compiler/assignment-deopt.js
@@ -0,0 +1,146 @@
+// Copyright 2010 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.
+
+// Test deopt with count operation on parameter.
+var max_smi = 1073741823;
+var o = {x:0};
+
+function assign1(x) { x += 1; o.x = x; }
+assign1(max_smi);
+assertEquals(max_smi + 1, o.x);
+
+assign1(1.1);
+assertEquals(2.1, o.x);
+
+
+// Test deopt with count operation on named property.
+function assign2(p) { p.x += 1 }
+
+o.x = "42";
+assign2(o);
+assertEquals("421", o.x);
+
+var s = max_smi - 10000;
+o.x = s;
+for(var i = 0; i < 20000; i++) {
+ assign2(o);
+}
+assertEquals(max_smi + 10000, o.x);
+
+
+// Test deopt with count operation on keyed property.
+function assign3(a, b) { a[b] += 1; }
+
+o = ["42"];
+assign3(o, 0);
+assertEquals("421", o[0]);
+
+var s = max_smi - 10000;
+o[0] = s;
+for(var i = 0; i < 20000; i++) {
+ assign3(o, 0);
+}
+assertEquals(max_smi + 10000, o[0]);
+
+assign3(o,"0");
+
+assertEquals(max_smi + 10001, o[0]);
+
+// Test bailout when accessing a non-existing array element.
+o[0] = 0;
+for(var i = 0; i < 10000; i++) {
+ assign3(o, 0);
+}
+assign3(o,1);
+
+// Test bailout with count operation in a value context.
+function assign5(x,y) { return (x += 1) + y; }
+for (var i = 0; i < 10000; ++i) assertEquals(4, assign5(2, 1));
+assertEquals(4.1, assign5(2, 1.1));
+assertEquals(4.1, assign5(2.1, 1));
+
+function assign7(o,y) { return (o.x += 1) + y; }
+o = {x:0};
+for (var i = 0; i < 10000; ++i) {
+ o.x = 42;
+ assertEquals(44, assign7(o, 1));
+}
+o.x = 42;
+assertEquals(44.1, assign7(o, 1.1));
+o.x = 42.1;
+assertEquals(44.1, assign7(o, 1));
+
+function assign9(o,y) { return (o[0] += 1) + y; }
+q = [0];
+for (var i = 0; i < 10000; ++i) {
+ q[0] = 42;
+ assertEquals(44, assign9(q, 1));
+}
+q[0] = 42;
+assertEquals(44.1, assign9(q, 1.1));
+q[0] = 42.1;
+assertEquals(44.1, assign9(q, 1));
+
+// Test deopt because of a failed map check on the load.
+function assign10(p) { return p.x += 1 }
+var g1 = {x:0};
+var g2 = {y:0, x:42};
+for (var i = 0; i < 10000; ++i) {
+ g1.x = 42;
+ assertEquals(43, assign10(g1));
+ assertEquals(43, g1.x);
+}
+assertEquals(43, assign10(g2));
+assertEquals(43, g2.x);
+
+// Test deopt because of a failed map check on the store.
+// The binary operation changes the map as a side effect.
+o = {x:0};
+var g3 = { valueOf: function() { o.y = "bar"; return 42; }};
+function assign11(p) { return p.x += 1; }
+
+for (var i = 0; i < 10000; i++) {
+ o.x = "a";
+ assign11(o);
+}
+assertEquals("a11", assign11(o));
+o.x = g3;
+assertEquals(43, assign11(o));
+assertEquals("bar", o.y);
+
+o = [0];
+var g4 = { valueOf: function() { o.y = "bar"; return 42; }};
+function assign12(p) { return p[0] += 1; }
+
+for (var i = 0; i < 1000000; i++) {
+ o[0] = "a";
+ assign12(o);
+}
+assertEquals("a11", assign12(o));
+o[0] = g4;
+assertEquals(43, assign12(o));
+assertEquals("bar", o.y);
diff --git a/test/mjsunit/compiler/assignment.js b/test/mjsunit/compiler/assignment.js
index 6aded4e..1f3f282 100644
--- a/test/mjsunit/compiler/assignment.js
+++ b/test/mjsunit/compiler/assignment.js
@@ -264,6 +264,13 @@
bar_loop();
+// Test assignment in test context.
+function test_assign(x, y) { if (x = y) return x; }
+
+assertEquals(42, test_assign(0, 42));
+
+assertEquals("undefined", typeof test_assign(42, 0));
+
// Test for assignment using a keyed store ic:
function store_i_in_element_i_of_object_i() {
var i = new Object();
diff --git a/test/mjsunit/regress/regress-1146.js b/test/mjsunit/compiler/binary-ops.js
similarity index 61%
copy from test/mjsunit/regress/regress-1146.js
copy to test/mjsunit/compiler/binary-ops.js
index e8028ce..27745c1 100644
--- a/test/mjsunit/regress/regress-1146.js
+++ b/test/mjsunit/compiler/binary-ops.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,24 +25,31 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test keyed calls with different key types.
-function F() {}
-var a = new F();
-function f(i) { return a[i](); }
+// Values in distinct spans.
+function or_test0(x, y) { return x | y; }
+function and_test0(x, y) { return x & y; }
+function add_test0(x, y) { return x + y; }
-a.first = function() { return 11; }
-a[0] = function() { return 22; }
-var obj = {};
-a[obj] = function() { return 33; }
+assertEquals(3, or_test0(1, 2)); // 1 | 2
+assertEquals(2, and_test0(3, 6)); // 3 & 6
+assertEquals(5, add_test0(2, 3)); // 2 + 3
-// Make object slow-case.
-a.foo = 0;
-delete a.foo;
-// Do multiple calls for IC transitions.
-var b = "first";
-f(b);
-f(b);
-assertEquals(11, f(b));
-assertEquals(22, f(0));
-assertEquals(33, f(obj));
+// Values in the same span.
+function or_test1(x, y) { return x | x; }
+function and_test1(x, y) { return x & x; }
+function add_test1(x, y) { return x + x; }
+
+assertEquals(1, or_test1(1, 2)); // 1 | 1
+assertEquals(3, and_test1(3, 6)); // 3 & 3
+assertEquals(4, add_test1(2, 3)); // 2 + 2
+
+
+// Values in distinct spans that alias.
+function or_test2(x, y) { x = y; return x | y; }
+function and_test2(x, y) { x = y; return x & y; }
+function add_test2(x, y) { x = y; return x + y; }
+
+assertEquals(2, or_test2(1, 2)); // 2 | 2
+assertEquals(6, and_test2(3, 6)); // 6 & 6
+assertEquals(6, add_test2(2, 3)); // 3 + 3
diff --git a/test/mjsunit/regress/regress-3408144.js b/test/mjsunit/compiler/call-keyed.js
similarity index 86%
copy from test/mjsunit/regress/regress-3408144.js
copy to test/mjsunit/compiler/call-keyed.js
index 6e292d6..d442212 100644
--- a/test/mjsunit/regress/regress-3408144.js
+++ b/test/mjsunit/compiler/call-keyed.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,13 +25,14 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test incorrect code generation for alternations on ARM.
+A = {}
+A.i = [];
+A.i.push(function () { });
+A.i.push(function () { });
-
-// Flags: --nofull-compiler
-
-function foo() {
- return (0 > ("10"||10) - 1);
+function f (event) {
+ for(var i = 0, j = A.i.length; i < j; ++i)
+ A.i[i]();
}
-assertFalse(foo());
+f(null);
diff --git a/test/mjsunit/compiler/compare.js b/test/mjsunit/compiler/compare.js
new file mode 100644
index 0000000..3f96087
--- /dev/null
+++ b/test/mjsunit/compiler/compare.js
@@ -0,0 +1,108 @@
+// Copyright 2010 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.
+
+function MaxLT(x, y) {
+ if (x < y) return y;
+ return x;
+}
+
+function MaxLE(x, y) {
+ if (x <= y) return y;
+ return x;
+}
+
+function MaxGE(x, y) {
+ if (x >= y) return x;
+ return y;
+}
+
+function MaxGT(x, y) {
+ if (x > y) return x;
+ return y;
+}
+
+
+// First test primitive values.
+function TestPrimitive(max, x, y) {
+ assertEquals(max, MaxLT(x, y), "MaxLT - primitive");
+ assertEquals(max, MaxLE(x, y), "MaxLE - primitive");
+ assertEquals(max, MaxGE(x, y), "MaxGE - primitive");
+ assertEquals(max, MaxGT(x, y), "MaxGT - primitive");
+}
+
+TestPrimitive(1, 0, 1);
+TestPrimitive(1, 1, 0);
+TestPrimitive(4, 3, 4);
+TestPrimitive(4, 4, 3);
+TestPrimitive(0, -1, 0);
+TestPrimitive(0, 0, -1)
+TestPrimitive(-2, -2, -3);
+TestPrimitive(-2, -3, -2);
+
+TestPrimitive(1, 0.1, 1);
+TestPrimitive(1, 1, 0.1);
+TestPrimitive(4, 3.1, 4);
+TestPrimitive(4, 4, 3.1);
+TestPrimitive(0, -1.1, 0);
+TestPrimitive(0, 0, -1.1)
+TestPrimitive(-2, -2, -3.1);
+TestPrimitive(-2, -3.1, -2);
+
+
+// Test non-primitive values and watch for valueOf call order.
+function TestNonPrimitive(order, f) {
+ var result = "";
+ var x = { valueOf: function() { result += "x"; } };
+ var y = { valueOf: function() { result += "y"; } };
+ f(x, y);
+ assertEquals(order, result);
+}
+
+TestNonPrimitive("xy", MaxLT);
+TestNonPrimitive("yx", MaxLE);
+TestNonPrimitive("xy", MaxGE);
+TestNonPrimitive("yx", MaxGT);
+
+// Test compare in case of aliased registers.
+function CmpX(x) { if (x == x) return 42; }
+assertEquals(42, CmpX(0));
+
+function CmpXY(x) { var y = x; if (x == y) return 42; }
+assertEquals(42, CmpXY(0));
+
+
+// Test compare against null.
+function CmpNullValue(x) { return x == null; }
+assertEquals(false, CmpNullValue(42));
+
+function CmpNullTest(x) { if (x == null) return 42; return 0; }
+assertEquals(42, CmpNullTest(null));
+
+var g1 = 0;
+function CmpNullEffect() { (g1 = 42) == null; }
+CmpNullEffect();
+assertEquals(42, g1);
diff --git a/test/mjsunit/regress/regress-1146.js b/test/mjsunit/compiler/complex-for-in.js
similarity index 73%
copy from test/mjsunit/regress/regress-1146.js
copy to test/mjsunit/compiler/complex-for-in.js
index e8028ce..883f20a 100644
--- a/test/mjsunit/regress/regress-1146.js
+++ b/test/mjsunit/compiler/complex-for-in.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,24 +25,26 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test keyed calls with different key types.
-function F() {}
-var a = new F();
-function f(i) { return a[i](); }
+function TestNamed(m) {
+ var o = {};
+ var result = [];
+ for (o.p in m) result.push(o.p);
+ return result;
+}
-a.first = function() { return 11; }
-a[0] = function() { return 22; }
-var obj = {};
-a[obj] = function() { return 33; }
+assertArrayEquals(['x','y'], TestNamed({x:0, y:1}));
+assertArrayEquals(['0','1'], TestNamed([1,2]));
-// Make object slow-case.
-a.foo = 0;
-delete a.foo;
-// Do multiple calls for IC transitions.
-var b = "first";
-f(b);
-f(b);
-assertEquals(11, f(b));
-assertEquals(22, f(0));
-assertEquals(33, f(obj));
+function TestKeyed(m) {
+ var a = [];
+ var result = [];
+ var i = 0;
+ for (a[i++] in m) result.push(a[i - 1]);
+ assertEquals(i, a.length);
+ return result;
+}
+
+
+assertArrayEquals(['x','y'], TestKeyed({x:0, y:1}));
+assertArrayEquals(['0','1'], TestKeyed([1,2]));
diff --git a/test/mjsunit/regress/regress-3408144.js b/test/mjsunit/compiler/control-flow-0.js
similarity index 83%
copy from test/mjsunit/regress/regress-3408144.js
copy to test/mjsunit/compiler/control-flow-0.js
index 6e292d6..bcf4f2d 100644
--- a/test/mjsunit/regress/regress-3408144.js
+++ b/test/mjsunit/compiler/control-flow-0.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,13 +25,20 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test incorrect code generation for alternations on ARM.
-
-
-// Flags: --nofull-compiler
-
-function foo() {
- return (0 > ("10"||10) - 1);
+function f() {
+ return (42 + (0 == 1 ? 1 : 2));
}
-assertFalse(foo());
+
+function g(x) {
+ return (x + (0 == 1 ? 1 : 2));
+}
+
+
+function h(x) {
+ return ((x + 1) + (0 == 1 ? 1 : 2));
+}
+
+assertEquals(44, f());
+assertEquals(45, g(43));
+assertEquals(47, h(44));
diff --git a/test/mjsunit/regress/regress-3408144.js b/test/mjsunit/compiler/control-flow-1.js
similarity index 78%
copy from test/mjsunit/regress/regress-3408144.js
copy to test/mjsunit/compiler/control-flow-1.js
index 6e292d6..973d9b6 100644
--- a/test/mjsunit/regress/regress-3408144.js
+++ b/test/mjsunit/compiler/control-flow-1.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,13 +25,31 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test incorrect code generation for alternations on ARM.
+var global = this;
-
-// Flags: --nofull-compiler
-
-function foo() {
- return (0 > ("10"||10) - 1);
+function f0(x) {
+ assertTrue(this === global);
+ return x;
}
-assertFalse(foo());
+function g0(x, y) {
+ return f0(x == y);
+}
+
+assertTrue(g0(0, 0));
+assertFalse(g0(0, 1));
+
+
+var o = {};
+o.f1 = f1;
+function f1(x) {
+ assertTrue(this === o);
+ return x;
+}
+
+function g1(x, y) {
+ return o.f1(x == y);
+}
+
+assertTrue(g1(0, 0));
+assertFalse(g1(0, 1));
\ No newline at end of file
diff --git a/test/mjsunit/regress/regress-3408144.js b/test/mjsunit/compiler/control-flow-2.js
similarity index 86%
copy from test/mjsunit/regress/regress-3408144.js
copy to test/mjsunit/compiler/control-flow-2.js
index 6e292d6..26ed564 100644
--- a/test/mjsunit/regress/regress-3408144.js
+++ b/test/mjsunit/compiler/control-flow-2.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,13 +25,10 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test incorrect code generation for alternations on ARM.
-
-
-// Flags: --nofull-compiler
-
-function foo() {
- return (0 > ("10"||10) - 1);
+function f(a,b) {
+ return (b < a) - (a < b);
}
-assertFalse(foo());
+assertEquals(0, f(0,0));
+assertEquals(1, f(1,0));
+assertEquals(-1, f(0,1));
diff --git a/test/mjsunit/compiler/count-deopt.js b/test/mjsunit/compiler/count-deopt.js
new file mode 100644
index 0000000..dcd82f8
--- /dev/null
+++ b/test/mjsunit/compiler/count-deopt.js
@@ -0,0 +1,150 @@
+// Copyright 2010 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.
+
+// Test deopt with count operation on parameter.
+var max_smi = 1073741823;
+var o = {x:0};
+
+function inc1(x) { x++; o.x = x; }
+inc1(max_smi);
+assertEquals(max_smi + 1, o.x);
+
+inc1(1.1);
+assertEquals(2.1, o.x);
+
+
+// Test deopt with count operation on named property.
+function inc2(p) { p.x++ }
+
+o.x = "42";
+inc2(o);
+assertEquals(43, o.x);
+
+var s = max_smi - 10000;
+o.x = s;
+for(var i = 0; i < 20000; i++) {
+ inc2(o);
+}
+assertEquals(max_smi + 10000, o.x);
+
+
+// Test deopt with count operation on keyed property.
+function inc3(a, b) { a[b]++; }
+
+o = ["42"];
+inc3(o, 0);
+assertEquals(43, o[0]);
+
+var s = max_smi - 10000;
+o[0] = s;
+for(var i = 0; i < 20000; i++) {
+ inc3(o, 0);
+}
+assertEquals(max_smi + 10000, o[0]);
+
+inc3(o,"0");
+
+assertEquals(max_smi + 10001, o[0]);
+
+// Test bailout when accessing a non-existing array element.
+o[0] = 0;
+for(var i = 0; i < 10000; i++) {
+ inc3(o, 0);
+}
+inc3(o,1);
+
+// Test bailout with count operation in a value context.
+function inc4(x,y) { return (x++) + y; }
+for (var i = 0; i < 100000; ++i) assertEquals(3, inc4(2, 1));
+assertEquals(3.1, inc4(2, 1.1));
+
+function inc5(x,y) { return (++x) + y; }
+for (var i = 0; i < 100000; ++i) assertEquals(4, inc5(2, 1));
+assertEquals(4.1, inc5(2, 1.1));
+assertEquals(4.1, inc5(2.1, 1));
+
+function inc6(o,y) { return (o.x++) + y; }
+o = {x:0};
+for (var i = 0; i < 10000; ++i) {
+ o.x = 42;
+ assertEquals(43, inc6(o, 1));
+}
+o.x = 42;
+assertEquals(43.1, inc6(o, 1.1));
+o.x = 42.1;
+assertEquals(43.1, inc6(o, 1));
+
+function inc7(o,y) { return (++o.x) + y; }
+o = {x:0};
+for (var i = 0; i < 10000; ++i) {
+ o.x = 42;
+ assertEquals(44, inc7(o, 1));
+}
+o.x = 42;
+assertEquals(44.1, inc7(o, 1.1));
+o.x = 42.1;
+assertEquals(44.1, inc7(o, 1));
+
+function inc8(o,y) { return (o[0]++) + y; }
+var q = [0];
+for (var i = 0; i < 100000; ++i) {
+ q[0] = 42;
+ assertEquals(43, inc8(q, 1));
+}
+q[0] = 42;
+assertEquals(43.1, inc8(q, 1.1));
+q[0] = 42.1;
+assertEquals(43.1, inc8(q, 1));
+
+function inc9(o,y) { return (++o[0]) + y; }
+q = [0];
+for (var i = 0; i < 100000; ++i) {
+ q[0] = 42;
+ assertEquals(44, inc9(q, 1));
+}
+q[0] = 42;
+assertEquals(44.1, inc9(q, 1.1));
+q[0] = 42.1;
+assertEquals(44.1, inc9(q, 1));
+
+// Test deopt because of a failed map check.
+function inc10(p) { return p.x++ }
+var g1 = {x:0};
+var g2 = {y:0, x:42}
+for (var i = 0; i < 10000; ++i) {
+ g1.x = 42;
+ assertEquals(42, inc10(g1));
+ assertEquals(43, g1.x);
+}
+assertEquals(42, inc10(g2));
+assertEquals(43, g2.x);
+
+// Test deoptimization with postfix operation in a value context.
+function inc11(a) { return a[this.x++]; }
+var g3 = {x:null, f:inc11};
+var g4 = [42];
+assertEquals(42, g3.f(g4));
diff --git a/test/mjsunit/compiler/countoperation.js b/test/mjsunit/compiler/countoperation.js
index 5660cee..dca4c11 100644
--- a/test/mjsunit/compiler/countoperation.js
+++ b/test/mjsunit/compiler/countoperation.js
@@ -109,3 +109,23 @@
assertEquals(45, b[c]);
assertEquals(1, b[c]++ && 1);
assertEquals(46, b[c]);
+
+// Test count operations with parameters.
+function f(x) { x++; return x; }
+assertEquals(43, f(42));
+
+function g(x) { ++x; return x; }
+assertEquals(43, g(42));
+
+function h(x) { var y = x++; return y; }
+assertEquals(42, h(42));
+
+function k(x) { var y = ++x; return y; }
+assertEquals(43, k(42));
+
+// Test count operation in a test context.
+function countTestPost(i) { var k = 0; while (i--) { k++; } return k; }
+assertEquals(10, countTestPost(10));
+
+function countTestPre(i) { var k = 0; while (--i) { k++; } return k; }
+assertEquals(9, countTestPre(10));
diff --git a/test/mjsunit/compiler/delete.js b/test/mjsunit/compiler/delete.js
new file mode 100644
index 0000000..373a1cb
--- /dev/null
+++ b/test/mjsunit/compiler/delete.js
@@ -0,0 +1,71 @@
+// Copyright 2010 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.
+
+// Tests of unary delete in cases where it is always true or always false.
+
+// In an effect context, expression is always true.
+assertEquals(undefined, void (delete 0));
+// In an effect context, expression is always false.
+assertEquals(undefined, (function (x) { delete x; })(0));
+
+// In a pure test context, expression is always true.
+assertEquals(1, (delete 0) ? 1 : 2);
+// In a pure test context, expression is always false.
+assertEquals(2, (function (x) { return (delete x) ? 1 : 2; })(0));
+// In a negated test context, expression is always false.
+assertEquals(1, (function (x) { return !(delete x) ? 1 : 2; })(0));
+
+// In a hybrid test/value context, expression is always true, value
+// expected in accumulator.
+assertEquals(3, 1 + ((delete 0) && 2));
+// In a hybrid test/value context, expression is always false, value
+// expected in accumulator.
+assertEquals(false, (function (x) { return (delete x) && 2; })(0));
+// In a hybrid test/value context, expression is always true, value
+// expected on stack.
+assertEquals(3, ((delete 0) && 2) + 1);
+// In a hybrid test/value context, expression is always false, value
+// expected on stack.
+assertEquals(1, (function (x) { return ((delete x) && 2) + 1; })(0));
+
+// In a hybrid value/test context, expression is always true, value
+// expected in accumulator.
+assertEquals(2, 1 + ((delete 0) || 2));
+// In a hybrid value/test context, expression is always false, value
+// expected in accumulator.
+assertEquals(2, (function (x) { return (delete x) || 2; })(0));
+// In a hybrid value/test context, expression is always true, value
+// expected on stack.
+assertEquals(2, ((delete 0) || 2) + 1);
+// In a hybrid value/test context, expression is always false, value
+// expected on stack.
+assertEquals(3, (function (x) { return ((delete x) || 2) + 1; })(0));
+
+
+// 'this' at toplevel is different from all other global variables---not
+// deletable.
+assertEquals(true, delete this);
diff --git a/test/mjsunit/regress/regress-3408144.js b/test/mjsunit/compiler/deopt-args.js
similarity index 82%
copy from test/mjsunit/regress/regress-3408144.js
copy to test/mjsunit/compiler/deopt-args.js
index 6e292d6..780e2a2 100644
--- a/test/mjsunit/regress/regress-3408144.js
+++ b/test/mjsunit/compiler/deopt-args.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,13 +25,19 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test incorrect code generation for alternations on ARM.
-
-
-// Flags: --nofull-compiler
-
-function foo() {
- return (0 > ("10"||10) - 1);
+function g(x) {
+ return x.f(0,1,2);
}
-assertFalse(foo());
+function f(a,b,c) {
+ return 42;
+}
+
+var object = { };
+object.f = f;
+for (var i = 0; i < 10000000; i++) {
+ assertEquals(42, g(object));
+}
+
+object.f = function(a,b,c) { return 87; };
+assertEquals(87, g(object));
diff --git a/test/mjsunit/regress/regress-1146.js b/test/mjsunit/compiler/deopt-inlined-smi.js
similarity index 74%
copy from test/mjsunit/regress/regress-1146.js
copy to test/mjsunit/compiler/deopt-inlined-smi.js
index e8028ce..dda083e 100644
--- a/test/mjsunit/regress/regress-1146.js
+++ b/test/mjsunit/compiler/deopt-inlined-smi.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,24 +25,40 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test keyed calls with different key types.
-function F() {}
-var a = new F();
-function f(i) { return a[i](); }
+// Flags: --always-opt --always-inline-smi-code
-a.first = function() { return 11; }
-a[0] = function() { return 22; }
-var obj = {};
-a[obj] = function() { return 33; }
+// Test deoptimization into inlined smi code.
-// Make object slow-case.
-a.foo = 0;
-delete a.foo;
-// Do multiple calls for IC transitions.
-var b = "first";
-f(b);
-f(b);
+function f(x) {
+ return ~x;
+}
-assertEquals(11, f(b));
-assertEquals(22, f(0));
-assertEquals(33, f(obj));
+f(42);
+assertEquals(~12, f(12.45));
+assertEquals(~42, f(42.87));
+
+
+var a = 1, b = 2, c = 4, d = 8;
+function g() {
+ return a | (b | (c | d));
+}
+
+g();
+c = "16";
+assertEquals(1 | 2 | 16 | 8, g());
+
+
+function h() {
+ return 1 | a;
+}
+a = "2";
+h();
+assertEquals(3, h());
+
+
+function k() {
+ return a | 1;
+}
+a = "4";
+k();
+assertEquals(5, k());
diff --git a/test/mjsunit/compiler/expression-trees.js b/test/mjsunit/compiler/expression-trees.js
new file mode 100644
index 0000000..fac6b4c
--- /dev/null
+++ b/test/mjsunit/compiler/expression-trees.js
@@ -0,0 +1,107 @@
+// Copyright 2010 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.
+
+// Flags: --always-opt --nocompilation-cache
+
+// Given a binary operation string and an ordered array of leaf
+// strings, return an array of all binary tree strings with the leaves
+// (in order) as the fringe.
+function makeTrees(op, leaves) {
+ var len = leaves.length;
+ if (len == 1) {
+ // One leaf is a leaf.
+ return leaves;
+ } else {
+ // More than one leaf requires an interior node.
+ var result = [];
+ // Split the leaves into left and right subtrees in all possible
+ // ways. For each split recursively compute all possible subtrees.
+ for (var i = 1; i < len; ++i) {
+ var leftTrees = makeTrees(op, leaves.slice(0, i));
+ var rightTrees = makeTrees(op, leaves.slice(i, len));
+ // Adjoin every possible left and right subtree.
+ for (var j = 0; j < leftTrees.length; ++j) {
+ for (var k = 0; k < rightTrees.length; ++k) {
+ var string = "(" + leftTrees[j] + op + rightTrees[k] + ")";
+ result.push(string);
+ }
+ }
+ }
+ return result;
+ }
+}
+
+// All 429 possible bitwise OR trees with eight leaves.
+var identifiers = ['a','b','c','d','e','f','g','h'];
+var or_trees = makeTrees("|", identifiers);
+var and_trees = makeTrees("&", identifiers);
+
+// Set up leaf masks to set 8 least-significant bits.
+var a = 1 << 0;
+var b = 1 << 1;
+var c = 1 << 2;
+var d = 1 << 3;
+var e = 1 << 4;
+var f = 1 << 5;
+var g = 1 << 6;
+var h = 1 << 7;
+
+for (var i = 0; i < or_trees.length; ++i) {
+ for (var j = 0; j < 8; ++j) {
+ var or_fun = new Function("return " + or_trees[i]);
+ if (j == 0) assertEquals(255, or_fun());
+
+ // Set the j'th variable to a string to force a bailout.
+ eval(identifiers[j] + "+= ''");
+ assertEquals(255, or_fun());
+ // Set it back to a number for the next iteration.
+ eval(identifiers[j] + "= +" + identifiers[j]);
+ }
+}
+
+// Set up leaf masks to clear 8 least-significant bits.
+a ^= 255;
+b ^= 255;
+c ^= 255;
+d ^= 255;
+e ^= 255;
+f ^= 255;
+g ^= 255;
+h ^= 255;
+
+for (i = 0; i < and_trees.length; ++i) {
+ for (var j = 0; j < 8; ++j) {
+ var and_fun = new Function("return " + and_trees[i]);
+ if (j == 0) assertEquals(0, and_fun());
+
+ // Set the j'th variable to a string to force a bailout.
+ eval(identifiers[j] + "+= ''");
+ assertEquals(0, and_fun());
+ // Set it back to a number for the next iteration.
+ eval(identifiers[j] + "= +" + identifiers[j]);
+ }
+}
diff --git a/test/mjsunit/regress/regress-3408144.js b/test/mjsunit/compiler/for-stmt.js
similarity index 76%
copy from test/mjsunit/regress/regress-3408144.js
copy to test/mjsunit/compiler/for-stmt.js
index 6e292d6..c8af01c 100644
--- a/test/mjsunit/regress/regress-3408144.js
+++ b/test/mjsunit/compiler/for-stmt.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,13 +25,35 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test incorrect code generation for alternations on ARM.
+
+// Test variants of for loops.
+function f(i, p) {
+ for(; i < 10; ) {
+ p.x = p.x + 1;
+ i = i+1;
+ }
+}
+var o = {x:42};
+f(1, o);
+assertEquals(51, o.x);
-// Flags: --nofull-compiler
+function g(i, p) {
+ for(; ; ) {
+ if (i == 10) return;
+ p.x = p.x + 1;
+ i = i+1;
+ }
+}
+o = {x:42};
+g(1, o);
+assertEquals(51, o.x);
-function foo() {
- return (0 > ("10"||10) - 1);
+
+function h(p) {
+ for(; p.x < 10; p.x++) {}
}
-assertFalse(foo());
+var o = {x:0};
+h(o);
+assertEquals(10, o.x);
diff --git a/test/mjsunit/compiler/globals.js b/test/mjsunit/compiler/globals.js
index 0abd5dd..3b778da 100644
--- a/test/mjsunit/compiler/globals.js
+++ b/test/mjsunit/compiler/globals.js
@@ -63,3 +63,14 @@
code = "g--; 1";
assertEquals(1, eval(code));
assertEquals(3, g);
+
+// Test simple assignment to non-deletable and deletable globals.
+var glo1 = 0;
+function f1(x) { glo1 = x; }
+f1(42);
+assertEquals(glo1, 42);
+
+glo2 = 0;
+function f2(x) { glo2 = x; }
+f2(42);
+assertEquals(42, glo2);
diff --git a/test/mjsunit/regress/regress-1146.js b/test/mjsunit/compiler/inline-compare.js
similarity index 74%
copy from test/mjsunit/regress/regress-1146.js
copy to test/mjsunit/compiler/inline-compare.js
index e8028ce..6efe154 100644
--- a/test/mjsunit/regress/regress-1146.js
+++ b/test/mjsunit/compiler/inline-compare.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,24 +25,22 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test keyed calls with different key types.
-function F() {}
-var a = new F();
-function f(i) { return a[i](); }
+// Test that we can inline a function that returns the result of
+// a compare operation.
+function TestInlineCompare(o) {
+ // Effect context.
+ o.f();
+ // Value context.
+ var x = o.f();
+ assertFalse(x);
+ assertFalse(o.f());
+ // Test context.
+ if (o.f()) {
+ assertTrue(false); // Should not happen.
+ }
+}
-a.first = function() { return 11; }
-a[0] = function() { return 22; }
-var obj = {};
-a[obj] = function() { return 33; }
-
-// Make object slow-case.
-a.foo = 0;
-delete a.foo;
-// Do multiple calls for IC transitions.
-var b = "first";
-f(b);
-f(b);
-
-assertEquals(11, f(b));
-assertEquals(22, f(0));
-assertEquals(33, f(obj));
+var o = {};
+o.f = function() { return 0 === 1; };
+for (var i = 0; i < 10000000; i++) TestInlineCompare(o);
+TestInlineCompare({f: o.f});
diff --git a/test/mjsunit/regress/regress-1146.js b/test/mjsunit/compiler/inline-conditional.js
similarity index 71%
copy from test/mjsunit/regress/regress-1146.js
copy to test/mjsunit/compiler/inline-conditional.js
index e8028ce..941f74a 100644
--- a/test/mjsunit/regress/regress-1146.js
+++ b/test/mjsunit/compiler/inline-conditional.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,24 +25,22 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test keyed calls with different key types.
-function F() {}
-var a = new F();
-function f(i) { return a[i](); }
+// Test that we can inline a function that returns the result of
+// a conditional operation.
+function TestInlineConditional(o) {
+ // Effect context.
+ o.f();
+ // Value context.
+ var x = o.f();
+ assertEquals(87, x);
+ assertEquals(87, o.f());
+ // Test context.
+ if (!o.f()) {
+ assertTrue(false); // Should not happen.
+ }
+}
-a.first = function() { return 11; }
-a[0] = function() { return 22; }
-var obj = {};
-a[obj] = function() { return 33; }
-
-// Make object slow-case.
-a.foo = 0;
-delete a.foo;
-// Do multiple calls for IC transitions.
-var b = "first";
-f(b);
-f(b);
-
-assertEquals(11, f(b));
-assertEquals(22, f(0));
-assertEquals(33, f(obj));
+var o = {x:false,y:42,z:87};
+o.f = function() { return this.x ? this.y : this.z; };
+for (var i = 0; i < 10000; i++) TestInlineConditional(o);
+TestInlineConditional({x:true,y:87,z:42,f: o.f});
diff --git a/test/mjsunit/regress/regress-1146.js b/test/mjsunit/compiler/inline-global-access.js
similarity index 72%
copy from test/mjsunit/regress/regress-1146.js
copy to test/mjsunit/compiler/inline-global-access.js
index e8028ce..3795173 100644
--- a/test/mjsunit/regress/regress-1146.js
+++ b/test/mjsunit/compiler/inline-global-access.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,24 +25,25 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test keyed calls with different key types.
-function F() {}
-var a = new F();
-function f(i) { return a[i](); }
+// Test that we can inline a function that returns the result of a
+// global variable load.
+var GLOBAL;
+function TestInlineGlobalLoad(o) {
+ // Effect context.
+ GLOBAL = 42;
+ o.f();
+ // Value context.
+ var x = o.f();
+ assertEquals(42, x);
+ GLOBAL = 87;
+ assertEquals(87, o.f());
+ // Test context.
+ if (!o.f()) {
+ assertTrue(false); // Should not happen.
+ }
+}
-a.first = function() { return 11; }
-a[0] = function() { return 22; }
-var obj = {};
-a[obj] = function() { return 33; }
-
-// Make object slow-case.
-a.foo = 0;
-delete a.foo;
-// Do multiple calls for IC transitions.
-var b = "first";
-f(b);
-f(b);
-
-assertEquals(11, f(b));
-assertEquals(22, f(0));
-assertEquals(33, f(obj));
+var o = {};
+o.f = function() { return GLOBAL; };
+for (var i = 0; i < 10000000; i++) TestInlineGlobalLoad(o);
+TestInlineGlobalLoad({f: o.f});
diff --git a/test/mjsunit/compiler/inline-param.js b/test/mjsunit/compiler/inline-param.js
new file mode 100644
index 0000000..8e0933a
--- /dev/null
+++ b/test/mjsunit/compiler/inline-param.js
@@ -0,0 +1,80 @@
+// Copyright 2010 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.
+
+// Test that we can inline a call with a parameter.
+function TestInlineOneParam(o, p) {
+ // Effect context.
+ o.f(p);
+ // Value context.
+ var x = o.f(p);
+ assertEquals(42, x);
+ assertEquals(42, o.f(p));
+ // Test context.
+ if (!o.f(p)) {
+ assertTrue(false); // Should not happen.
+ }
+}
+
+var obj = {x:42};
+var o1 = {};
+o1.f = function(o) { return o.x; };
+for (var i = 0; i < 10000; i++) TestInlineOneParam(o1, obj);
+TestInlineOneParam({f: o1.f}, {x:42});
+
+
+function TestInlineTwoParams(o, p) {
+ var y = 43;
+ // Effect context.
+ o.h(y, y);
+ // Value context.
+ var x = o.h(p, y);
+ assertEquals(true, x);
+ assertEquals(false, o.h(y, p));
+ // Test context.
+ if (!o.h(p, y)) {
+ assertTrue(false); // Should not happen.
+ }
+
+ // Perform the same tests again, but this time with non-trivial
+ // expressions as the parameters.
+
+ // Effect context.
+ o.h(y + 1, y + 1);
+ // Value context.
+ var x = o.h(p + 1, y + 1);
+ assertEquals(true, x);
+ assertEquals(false, o.h(y + 1, p + 1));
+ // Test context.
+ if (!o.h(p + 1, y + 1)) {
+ assertTrue(false); // Should not happen.
+ }
+}
+
+var o2 = {};
+o2.h = function(i, j) { return i < j; };
+for (var i = 0; i < 10000; i++) TestInlineTwoParams(o2, 42);
+TestInlineTwoParams({h: o2.h}, 42);
diff --git a/test/mjsunit/compiler/inline-two.js b/test/mjsunit/compiler/inline-two.js
new file mode 100644
index 0000000..30f579d
--- /dev/null
+++ b/test/mjsunit/compiler/inline-two.js
@@ -0,0 +1,93 @@
+// Copyright 2010 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.
+
+// Test that we can inline a function that calls another function.
+function TestInlineX(o) {
+ // Effect context.
+ o.g();
+ // Value context.
+ var x = o.g();
+ assertEquals(42, x);
+ assertEquals(42, o.g());
+ // Test context.
+ if (!o.g()) {
+ assertTrue(false); // Should not happen.
+ }
+}
+
+var o2 = {};
+o2.size = function() { return 42; }
+o2.g = function() { return this.size(); };
+for (var i = 0; i < 10000; i++) TestInlineX(o2);
+TestInlineX({g: o2.g, size:o2.size});
+
+
+// Test that we can inline a call on a non-variable receiver.
+function TestInlineX2(o) {
+ // Effect context.
+ o.h();
+ // Value context.
+ var x = o.h();
+ assertEquals(42, x);
+ assertEquals(42, o.h());
+ // Test context.
+ if (!o.h()) {
+ assertTrue(false); // Should not happen.
+ }
+}
+
+var obj = {}
+obj.foo = function() { return 42; }
+var o3 = {};
+o3.v = obj;
+o3.h = function() { return this.v.foo(); };
+for (var i = 0; i < 10000; i++) TestInlineX2(o3);
+TestInlineX2({h: o3.h, v:obj});
+
+
+// Test that we can inline a call on a non-variable receiver.
+function TestInlineFG(o) {
+ // Effect context.
+ o.h();
+ // Value context.
+ var x = o.h();
+ assertEquals(42, x);
+ assertEquals(42, o.h());
+ // Test context.
+ if (!o.h()) {
+ assertTrue(false); // Should not happen.
+ }
+}
+
+var obj = {}
+obj.g = function() { return 42; }
+var o3 = {};
+o3.v = obj;
+o3.f = function() { return this.v; }
+o3.h = function() { return this.f().g(); };
+for (var i = 0; i < 10000; i++) TestInlineFG(o3);
+TestInlineFG({h: o3.h, f: o3.f, v:obj});
diff --git a/test/mjsunit/regress/regress-3408144.js b/test/mjsunit/compiler/logical-and.js
similarity index 62%
copy from test/mjsunit/regress/regress-3408144.js
copy to test/mjsunit/compiler/logical-and.js
index 6e292d6..1d31a0a 100644
--- a/test/mjsunit/regress/regress-3408144.js
+++ b/test/mjsunit/compiler/logical-and.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,13 +25,46 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test incorrect code generation for alternations on ARM.
-
-
-// Flags: --nofull-compiler
-
-function foo() {
- return (0 > ("10"||10) - 1);
+function AndBB(x,y) {
+ return (x == 0) && (y == 0);
}
-assertFalse(foo());
+function AndBN(x,y) {
+ return (x == 0) && y;
+}
+
+function AndNB(x,y) {
+ return x && (y == 0);
+}
+
+function AndNN(x,y) {
+ return x && y;
+}
+
+assertTrue(AndBB(0, 0));
+assertFalse(AndBB(1, 0));
+assertFalse(AndBB(0, 1));
+assertFalse(AndBB(1, 1));
+
+assertFalse(AndBN(0, 0));
+assertTrue(AndBN(0, 1));
+assertFalse(AndBN(1, 0));
+assertEquals(1, AndBN(0, 1));
+assertEquals(2, AndBN(0, 2));
+assertFalse(AndBN(1, 1));
+assertFalse(AndBN(1, 2));
+
+assertEquals(0, AndNB(0, 0));
+assertTrue(AndNB(1, 0));
+assertEquals(0, AndNB(0, 1));
+assertEquals("", AndNB("", 1));
+assertFalse(AndNB(1, 1));
+assertTrue(AndNB(2, 0));
+
+assertEquals(0, AndNN(0, 0));
+assertEquals(0, AndNN(1, 0));
+assertEquals(0, AndNN(2, 0));
+assertEquals(0, AndNN(0, 1));
+assertEquals(0, AndNN(0, 2));
+assertEquals(1, AndNN(1, 1));
+assertEquals(2, AndNN(3, 2));
diff --git a/test/mjsunit/regress/regress-1146.js b/test/mjsunit/compiler/logical-or.js
similarity index 65%
copy from test/mjsunit/regress/regress-1146.js
copy to test/mjsunit/compiler/logical-or.js
index e8028ce..87c630d 100644
--- a/test/mjsunit/regress/regress-1146.js
+++ b/test/mjsunit/compiler/logical-or.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,24 +25,42 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test keyed calls with different key types.
-function F() {}
-var a = new F();
-function f(i) { return a[i](); }
+function OrBB(x,y) {
+ return (x == 0) || (y == 0);
+}
-a.first = function() { return 11; }
-a[0] = function() { return 22; }
-var obj = {};
-a[obj] = function() { return 33; }
+function OrBN(x,y) {
+ return (x == 0) || y;
+}
-// Make object slow-case.
-a.foo = 0;
-delete a.foo;
-// Do multiple calls for IC transitions.
-var b = "first";
-f(b);
-f(b);
+function OrNB(x,y) {
+ return x || (y == 0);
+}
-assertEquals(11, f(b));
-assertEquals(22, f(0));
-assertEquals(33, f(obj));
+function OrNN(x,y) {
+ return x || y;
+}
+
+assertTrue(OrBB(0, 0));
+assertTrue(OrBB(1, 0));
+assertTrue(OrBB(0, 1));
+assertFalse(OrBB(1, 1));
+
+assertTrue(OrBN(0, 0));
+assertEquals(0, OrBN(1, 0));
+assertTrue(OrBN(0, 1));
+assertEquals(1, OrBN(1, 1));
+assertEquals(2, OrBN(1, 2));
+
+assertTrue(OrNB(0, 0));
+assertEquals(1, OrNB(1, 0));
+assertFalse(OrNB(0, 1));
+assertEquals(1, OrNB(1, 1));
+assertEquals(2, OrNB(2, 1));
+
+assertEquals(0, OrNN(0, 0));
+assertEquals(1, OrNN(1, 0));
+assertEquals(2, OrNN(2, 0));
+assertEquals(1, OrNN(0, 1));
+assertEquals(2, OrNN(0, 2));
+assertEquals(1, OrNN(1, 2));
diff --git a/test/mjsunit/compiler/loops.js b/test/mjsunit/compiler/loops.js
index 4de45e7..2195c6c 100644
--- a/test/mjsunit/compiler/loops.js
+++ b/test/mjsunit/compiler/loops.js
@@ -33,3 +33,29 @@
n = n * i;
}
assertEquals(120, n);
+
+// Test assignments in the loop condition.
+function f(i, n) {
+ while((n = n - 1) >= 0) {
+ i = n + 1;
+ }
+ return i;
+}
+assertEquals(1, f(0, 42));
+
+
+// Test do-while loop and continue.
+function g(a) {
+ var x = 0, c = 0;
+ do {
+ x = x + 1;
+ if (x < 5) continue;
+ c = c + 1;
+ } while(x < a);
+ return c;
+}
+
+assertEquals(6, g(10));
+
+// Test deoptimization in the loop condition.
+assertEquals(0, g("foo"));
diff --git a/test/mjsunit/regress/regress-1146.js b/test/mjsunit/compiler/null-compare.js
similarity index 66%
copy from test/mjsunit/regress/regress-1146.js
copy to test/mjsunit/compiler/null-compare.js
index e8028ce..e01b555 100644
--- a/test/mjsunit/regress/regress-1146.js
+++ b/test/mjsunit/compiler/null-compare.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,24 +25,30 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test keyed calls with different key types.
-function F() {}
-var a = new F();
-function f(i) { return a[i](); }
+function IsNull(x) {
+ if (x == null) return true; else return false;
+}
-a.first = function() { return 11; }
-a[0] = function() { return 22; }
-var obj = {};
-a[obj] = function() { return 33; }
+assertTrue(IsNull(null), "null == null");
+assertTrue(IsNull(void 0), "void 0 == null");
+assertFalse(IsNull(42), "42 != null");
-// Make object slow-case.
-a.foo = 0;
-delete a.foo;
-// Do multiple calls for IC transitions.
-var b = "first";
-f(b);
-f(b);
-assertEquals(11, f(b));
-assertEquals(22, f(0));
-assertEquals(33, f(obj));
+function IsNullStrict(x) {
+ if (x === null) return true; else return false;
+}
+
+assertTrue(IsNullStrict(null), "null === null");
+assertFalse(IsNullStrict(void 0), "void 0 != null");
+assertFalse(IsNullStrict(87), "87 !== null");
+
+
+function GimmeFalse(x) {
+ if ((x & 1) == null) return true;
+ if ((x | 3) === null) return true;
+ return false;
+}
+
+assertFalse(GimmeFalse(1), "GimmeFalse(1)");
+assertFalse(GimmeFalse(null), "GimmeFalse(null)");
+assertFalse(GimmeFalse({}), "GimmeFalse({})");
diff --git a/test/mjsunit/regress/regress-3408144.js b/test/mjsunit/compiler/optimized-function-calls.js
similarity index 60%
copy from test/mjsunit/regress/regress-3408144.js
copy to test/mjsunit/compiler/optimized-function-calls.js
index 6e292d6..1b5f3b0 100644
--- a/test/mjsunit/regress/regress-3408144.js
+++ b/test/mjsunit/compiler/optimized-function-calls.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,13 +25,55 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test incorrect code generation for alternations on ARM.
+// Flags: --expose-gc
-
-// Flags: --nofull-compiler
-
-function foo() {
- return (0 > ("10"||10) - 1);
+function f() {
+ gc();
+ return 87;
}
-assertFalse(foo());
+
+var x = 42, y = 99;
+function g() {
+ return x | f() | (y | (x | (f() | x)));
+}
+f(); // Give us a chance to optimize f.
+assertEquals(42 | 87 | 99, g());
+
+
+// Regression test for issue where we would try do an illegal
+// compile-time lookup on a null prototype.
+var object = { f: function() { return 42; }, x: 42 };
+delete object.x;
+function call_f(o) {
+ return o.f();
+}
+for (var i = 0; i < 10000000; i++) call_f(object);
+
+
+// Check that nested global function calls work.
+function f0() {
+ return 42;
+}
+
+function f1(a) {
+ return a;
+}
+
+function f2(a, b) {
+ return a * b;
+}
+
+function f3(a, b, c) {
+ return a + b - c;
+}
+
+function f4(a, b, c, d) {
+ return a * b + c - d;
+}
+
+function nested() {
+ return f4(f3(f2(f1(f0()),f0()),f1(f0()),f0()),f2(f1(f0()),f0()),f1(f0()),f0())
+ + f4(f0(),f1(f0()),f2(f1(f0()),f0()),f3(f2(f1(f0()),f0()),f1(f0()),f0()));
+}
+assertEquals(3113460, nested());
diff --git a/test/mjsunit/compiler/pic.js b/test/mjsunit/compiler/pic.js
new file mode 100644
index 0000000..a0b5d8f
--- /dev/null
+++ b/test/mjsunit/compiler/pic.js
@@ -0,0 +1,66 @@
+// Copyright 2010 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.
+
+function GetX(o) { return o.x; }
+function CallF(o) { return o.f(); }
+function SetX(o) { o.x = 42; }
+function SetXY(o,y) { return o.x = y; }
+
+
+function Test(o) {
+ SetX(o);
+ assertEquals(42, GetX(o));
+ assertEquals(87, SetXY(o, 87));
+ assertEquals(87, GetX(o));
+ assertTrue(SetXY(o, o) === o);
+ assertTrue(o === GetX(o), "o === GetX(o)");
+ assertEquals("hest", SetXY(o, "hest"));
+ assertEquals("hest", GetX(o));
+ assertTrue(SetXY(o, Test) === Test);
+ assertTrue(Test === GetX(o), "Test === GetX(o)");
+ assertEquals(99, CallF(o));
+}
+
+// Create a bunch of objects with different layouts.
+var o1 = { x: 0, y: 1 };
+var o2 = { y: 1, x: 0 };
+var o3 = { y: 1, z: 2, x: 0 };
+o1.f = o2.f = o3.f = function() { return 99; }
+
+// Run the test until we're fairly sure we've optimized the
+// polymorphic property access.
+for (var i = 0; i < 1000000; i++) {
+ Test(o1);
+ Test(o2);
+ Test(o3);
+}
+
+// Make sure that the following doesn't crash.
+GetX(0);
+SetX(0);
+SetXY(0, 0);
+assertThrows("CallF(0)", TypeError);
diff --git a/test/mjsunit/regress/regress-3408144.js b/test/mjsunit/compiler/property-calls.js
similarity index 82%
copy from test/mjsunit/regress/regress-3408144.js
copy to test/mjsunit/compiler/property-calls.js
index 6e292d6..3366971 100644
--- a/test/mjsunit/regress/regress-3408144.js
+++ b/test/mjsunit/compiler/property-calls.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,13 +25,13 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test incorrect code generation for alternations on ARM.
+function f(o) { return o.g(); }
+function g() { return 42; }
+var object = { };
+object.g = g;
+for (var i = 0; i < 10000000; i++) f(object);
+assertEquals(42, f(object));
-// Flags: --nofull-compiler
-
-function foo() {
- return (0 > ("10"||10) - 1);
-}
-
-assertFalse(foo());
+object = { g: function() { return 87; } };
+assertEquals(87, f(object));
diff --git a/test/mjsunit/regress/regress-1146.js b/test/mjsunit/compiler/property-refs.js
similarity index 74%
copy from test/mjsunit/regress/regress-1146.js
copy to test/mjsunit/compiler/property-refs.js
index e8028ce..3f6f793 100644
--- a/test/mjsunit/regress/regress-1146.js
+++ b/test/mjsunit/compiler/property-refs.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,24 +25,27 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test keyed calls with different key types.
-function F() {}
-var a = new F();
-function f(i) { return a[i](); }
+function Load(o) {
+ return o.outer.x | o.outer.inner.y;
+}
-a.first = function() { return 11; }
-a[0] = function() { return 22; }
-var obj = {};
-a[obj] = function() { return 33; }
+function StoreXY(o, x, y) {
+ o.outer.x = x;
+ o.outer.inner.y = y;
+}
-// Make object slow-case.
-a.foo = 0;
-delete a.foo;
-// Do multiple calls for IC transitions.
-var b = "first";
-f(b);
-f(b);
+function LoadXY(x, y) {
+ var object = {
+ outer: {
+ x: 0,
+ inner: { y: 0 }
+ }
+ };
+ StoreXY(object, x, y);
+ return Load(object);
+}
-assertEquals(11, f(b));
-assertEquals(22, f(0));
-assertEquals(33, f(obj));
+for (var i = 0; i < 10000; i++) LoadXY(i, i);
+assertEquals(42 | 87, LoadXY(42, 87));
+assertEquals(42 | 87, LoadXY(42, 87));
+assertEquals(42 | 99, LoadXY(42, "99"));
diff --git a/test/mjsunit/regress/regress-3408144.js b/test/mjsunit/compiler/property-stores.js
similarity index 77%
copy from test/mjsunit/regress/regress-3408144.js
copy to test/mjsunit/compiler/property-stores.js
index 6e292d6..0dec82a 100644
--- a/test/mjsunit/regress/regress-3408144.js
+++ b/test/mjsunit/compiler/property-stores.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,13 +25,19 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test incorrect code generation for alternations on ARM.
+var a = 42;
+var obj = {x: 0,
+ f: function() { this.x = 7; },
+ g: function() { this.x = a | 1; },
+ h: function() { this.x = a; }};
-// Flags: --nofull-compiler
+var i;
+for (i = 0; i < 10000; i++) { obj.f(); }
+assertEquals(7, obj.x);
-function foo() {
- return (0 > ("10"||10) - 1);
-}
+for (i = 0; i < 10000; i++) { obj.g(); }
+assertEquals(43, obj.x);
-assertFalse(foo());
+for (i = 0; i < 10000; i++) { obj.h(); }
+assertEquals(42, obj.x);
diff --git a/test/mjsunit/regress/regress-1146.js b/test/mjsunit/compiler/recursive-deopt.js
similarity index 72%
copy from test/mjsunit/regress/regress-1146.js
copy to test/mjsunit/compiler/recursive-deopt.js
index e8028ce..366f59a 100644
--- a/test/mjsunit/regress/regress-1146.js
+++ b/test/mjsunit/compiler/recursive-deopt.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,24 +25,24 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test keyed calls with different key types.
-function F() {}
-var a = new F();
-function f(i) { return a[i](); }
-a.first = function() { return 11; }
-a[0] = function() { return 22; }
-var obj = {};
-a[obj] = function() { return 33; }
+function f(n) {
+ // Force deopt in both leaf case and when returning. To make
+ // debugging easier, the operation that bails out (<<) is so simple
+ // that it doesn't cause GCs.
+ if (n == 0) return 1 << one;
+ return f(n - 1) << one;
+}
-// Make object slow-case.
-a.foo = 0;
-delete a.foo;
-// Do multiple calls for IC transitions.
-var b = "first";
-f(b);
-f(b);
+function RunTests() {
+ assertEquals(1 << 1, f(0));
+ assertEquals(1 << 2, f(1));
+ assertEquals(1 << 5, f(4));
+}
-assertEquals(11, f(b));
-assertEquals(22, f(0));
-assertEquals(33, f(obj));
+
+var one = 1;
+for (var i = 0; i < 1000000; i++) RunTests();
+
+var one = { valueOf: function() { return 1; } };
+for (var j = 0; j < 100000; j++) RunTests();
diff --git a/test/mjsunit/regress/regress-3408144.js b/test/mjsunit/compiler/regress-0.js
similarity index 84%
copy from test/mjsunit/regress/regress-3408144.js
copy to test/mjsunit/compiler/regress-0.js
index 6e292d6..df6dfee 100644
--- a/test/mjsunit/regress/regress-3408144.js
+++ b/test/mjsunit/compiler/regress-0.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,13 +25,13 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test incorrect code generation for alternations on ARM.
-
-
-// Flags: --nofull-compiler
-
-function foo() {
- return (0 > ("10"||10) - 1);
+function TestNestedLoops() {
+ var sum = 0;
+ for (var i = 0; i < 200; i = i + 1) {
+ for (var j = 0; j < 200; j = j + 1) {
+ sum = sum + 1;
+ }
+ }
+ return sum;
}
-
-assertFalse(foo());
+assertEquals(200 * 200, TestNestedLoops());
diff --git a/test/mjsunit/regress/regress-3408144.js b/test/mjsunit/compiler/regress-1.js
similarity index 82%
copy from test/mjsunit/regress/regress-3408144.js
copy to test/mjsunit/compiler/regress-1.js
index 6e292d6..cbae1a8 100644
--- a/test/mjsunit/regress/regress-3408144.js
+++ b/test/mjsunit/compiler/regress-1.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,13 +25,11 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test incorrect code generation for alternations on ARM.
-
-
-// Flags: --nofull-compiler
-
-function foo() {
- return (0 > ("10"||10) - 1);
+function DaysInYear(y) {
+ if (y % 4 != 0) return 365;
+ if (y % 4 == 0 && y % 100 != 0) return 366;
+ if (y % 100 == 0 && y % 400 != 0) return 365;
+ if (y % 400 == 0) return 366;
}
-
-assertFalse(foo());
+assertEquals(365, DaysInYear(1999));
+assertEquals(366, DaysInYear(2000));
diff --git a/test/mjsunit/regress/regress-3408144.js b/test/mjsunit/compiler/regress-2.js
similarity index 76%
copy from test/mjsunit/regress/regress-3408144.js
copy to test/mjsunit/compiler/regress-2.js
index 6e292d6..a26ef32 100644
--- a/test/mjsunit/regress/regress-3408144.js
+++ b/test/mjsunit/compiler/regress-2.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,13 +25,20 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test incorrect code generation for alternations on ARM.
-
-
-// Flags: --nofull-compiler
-
-function foo() {
- return (0 > ("10"||10) - 1);
+// The compilation of this function currently fails when resolving
+// control flow in the register allocator.
+function TestCreateString(n)
+{
+ var l = n * 1;
+ var r = 'r';
+ while (r.length < n)
+ {
+ r = r + r;
+ }
+ return r;
}
-assertFalse(foo());
+assertEquals("r", TestCreateString(1));
+assertEquals("rr", TestCreateString(2));
+assertEquals("rrrr", TestCreateString(3));
+assertEquals("rrrrrrrr", TestCreateString(6));
diff --git a/test/mjsunit/regress/regress-3408144.js b/test/mjsunit/compiler/regress-3.js
similarity index 86%
copy from test/mjsunit/regress/regress-3408144.js
copy to test/mjsunit/compiler/regress-3.js
index 6e292d6..6aa7078 100644
--- a/test/mjsunit/regress/regress-3408144.js
+++ b/test/mjsunit/compiler/regress-3.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,13 +25,13 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test incorrect code generation for alternations on ARM.
-
-
-// Flags: --nofull-compiler
-
-function foo() {
- return (0 > ("10"||10) - 1);
+function fib(n) {
+ var f0 = 0, f1 = 1;
+ for (; n > 0; n = n -1) {
+ var f2 = f0 + f1;
+ f0 = f1; f1 = f2;
+ }
+ return f0;
}
-assertFalse(foo());
+assertEquals(2111485077978050, fib(75));
diff --git a/test/mjsunit/regress/regress-1146.js b/test/mjsunit/compiler/regress-3136962.js
similarity index 72%
copy from test/mjsunit/regress/regress-1146.js
copy to test/mjsunit/compiler/regress-3136962.js
index e8028ce..147d833 100644
--- a/test/mjsunit/regress/regress-1146.js
+++ b/test/mjsunit/compiler/regress-3136962.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,24 +25,27 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test keyed calls with different key types.
-function F() {}
-var a = new F();
-function f(i) { return a[i](); }
+// Reduced regression test for a global value numbering bug. Original
+// value of global variable height was reused even after reassignment.
-a.first = function() { return 11; }
-a[0] = function() { return 22; }
-var obj = {};
-a[obj] = function() { return 33; }
+var height = 267;
-// Make object slow-case.
-a.foo = 0;
-delete a.foo;
-// Do multiple calls for IC transitions.
-var b = "first";
-f(b);
-f(b);
+var count = 0;
+function inner() { height = 0; ++count; }
+function outer() {}
-assertEquals(11, f(b));
-assertEquals(22, f(0));
-assertEquals(33, f(obj));
+function test() {
+ for (var i = 0; i < height; ++i) {
+ for (var j = -6; j < 7; ++j) {
+ if (i + j < 0 || i + j >= height) continue;
+ for (var k = -6; k < 7; ++k) {
+ inner();
+ }
+ }
+ outer();
+ }
+}
+
+test();
+
+assertEquals(13, count);
diff --git a/test/mjsunit/regress/regress-3408144.js b/test/mjsunit/compiler/regress-3185901.js
similarity index 86%
copy from test/mjsunit/regress/regress-3408144.js
copy to test/mjsunit/compiler/regress-3185901.js
index 6e292d6..1e1bbe7 100644
--- a/test/mjsunit/regress/regress-3408144.js
+++ b/test/mjsunit/compiler/regress-3185901.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,13 +25,11 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test incorrect code generation for alternations on ARM.
+// Inlined function call in a test context. Should never crash even
+// with --always-opt.
+var x;
+function f() { if (g()) { } }
+function g() { if (x) { return true; } }
-// Flags: --nofull-compiler
-
-function foo() {
- return (0 > ("10"||10) - 1);
-}
-
-assertFalse(foo());
+f();
diff --git a/test/mjsunit/compiler/regress-3218915.js b/test/mjsunit/compiler/regress-3218915.js
new file mode 100644
index 0000000..d27c319
--- /dev/null
+++ b/test/mjsunit/compiler/regress-3218915.js
@@ -0,0 +1,48 @@
+// Copyright 2010 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.
+
+// Regression test for failure to deoptimize properly when the most recent
+// side effect occurred in a comma expression in an effect context.
+
+// An unoptimizable function, calling it is a side effect.
+function side_effect() { try {} finally {} return "wrong"; }
+
+// A function to observe the value of its first argument.
+function observe(x, y) { try {} finally {} return x; }
+
+// If we optimize for x a smi, then x a string will deopt. The side effect
+// immediately before the deopt is in a comma expresion in an effect context
+// (i.e., itself the left subexpression of a comma expression).
+function test(x) { return observe(this, ((0, side_effect()), x + 1)); }
+
+// Run test enough times to get it optimized.
+for (var i = 0; i < 1000000; ++i) test(0);
+
+// Force test to deopt. If it behaves normally, it should return the global
+// object. If the value of the call to side_effect() is lingering after the
+// deopt, it will return the string "wrong".
+assertFalse(test("a") === "wrong");
diff --git a/test/mjsunit/regress/regress-1146.js b/test/mjsunit/compiler/regress-3249650.js
similarity index 69%
copy from test/mjsunit/regress/regress-1146.js
copy to test/mjsunit/compiler/regress-3249650.js
index e8028ce..1f06090 100644
--- a/test/mjsunit/regress/regress-1146.js
+++ b/test/mjsunit/compiler/regress-3249650.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,24 +25,29 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test keyed calls with different key types.
-function F() {}
-var a = new F();
-function f(i) { return a[i](); }
+// Among other things, this code covers the case of deoptimization
+// after a compare expression in an effect context.
-a.first = function() { return 11; }
-a[0] = function() { return 22; }
-var obj = {};
-a[obj] = function() { return 33; }
+function f0(x) { try { } catch (e) {}}
+function f1(x) { try { } catch (e) {}}
+function f2(x) { try { } catch (e) {}}
+function f3(x) { try { } catch (e) {}}
-// Make object slow-case.
-a.foo = 0;
-delete a.foo;
-// Do multiple calls for IC transitions.
-var b = "first";
-f(b);
-f(b);
+var object = { a: "", b: false, c: {}};
+object.f = function(x) { return this; }
-assertEquals(11, f(b));
-assertEquals(22, f(0));
-assertEquals(33, f(obj));
+
+function test(x) {
+ f0(x);
+ f1(x);
+ f2(x);
+ f3(x);
+ x.a.b == "";
+ object.f("A").b = true;
+ object.f("B").a = "";
+ object.f("C").c.display = "A";
+ object.f("D").c.display = "A";
+}
+
+var x = {a: {b: "" }};
+for (var i = 0; i < 1000000; i++) test(x);
diff --git a/test/mjsunit/regress/regress-3408144.js b/test/mjsunit/compiler/regress-3260426.js
similarity index 79%
copy from test/mjsunit/regress/regress-3408144.js
copy to test/mjsunit/compiler/regress-3260426.js
index 6e292d6..dfef424 100644
--- a/test/mjsunit/regress/regress-3408144.js
+++ b/test/mjsunit/compiler/regress-3260426.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,13 +25,12 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test incorrect code generation for alternations on ARM.
+// Falling off the end of a function returns the undefined value
+// (false in a test context). This should happen even when inlined
+// (e.g., if --always-opt) and when it is the only exit from the
+// function.
+function always_false() {}
+function test() { return always_false() ? 0 : 1; }
+assertEquals(1, test());
-// Flags: --nofull-compiler
-
-function foo() {
- return (0 > ("10"||10) - 1);
-}
-
-assertFalse(foo());
diff --git a/test/mjsunit/regress/regress-3408144.js b/test/mjsunit/compiler/regress-4.js
similarity index 83%
copy from test/mjsunit/regress/regress-3408144.js
copy to test/mjsunit/compiler/regress-4.js
index 6e292d6..0ec9a12 100644
--- a/test/mjsunit/regress/regress-3408144.js
+++ b/test/mjsunit/compiler/regress-4.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,13 +25,16 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test incorrect code generation for alternations on ARM.
-
-
-// Flags: --nofull-compiler
-
-function foo() {
- return (0 > ("10"||10) - 1);
+// Test deoptimization after a loop.
+function f(p) {
+ var y=0;
+ for (var x=0; x<10; x++) {
+ if (x > 5) { y=y+p; break;}
+ }
+ return y+x;
}
-assertFalse(foo());
+for (var i=0; i<10000000; i++) f(42);
+
+var result = f("foo");
+assertEquals("0foo6", result);
diff --git a/test/mjsunit/regress/regress-3408144.js b/test/mjsunit/compiler/regress-5.js
similarity index 83%
copy from test/mjsunit/regress/regress-3408144.js
copy to test/mjsunit/compiler/regress-5.js
index 6e292d6..5488d0e 100644
--- a/test/mjsunit/regress/regress-3408144.js
+++ b/test/mjsunit/compiler/regress-5.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,13 +25,19 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test incorrect code generation for alternations on ARM.
+// Test breaking out of labelled blocks.
+function f(y) {
+ var x = 0;
-
-// Flags: --nofull-compiler
-
-function foo() {
- return (0 > ("10"||10) - 1);
+ foo: {
+ x++;
+ bar: {
+ if (y == 0) break bar; else break foo;
+ }
+ x++;
+ }
+ return x;
}
-assertFalse(foo());
+assertEquals(2, f(0));
+assertEquals(1, f(1));
diff --git a/test/mjsunit/regress/regress-3408144.js b/test/mjsunit/compiler/regress-6.js
similarity index 76%
copy from test/mjsunit/regress/regress-3408144.js
copy to test/mjsunit/compiler/regress-6.js
index 6e292d6..e92b0e5 100644
--- a/test/mjsunit/regress/regress-3408144.js
+++ b/test/mjsunit/compiler/regress-6.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,13 +25,18 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test incorrect code generation for alternations on ARM.
-
-
-// Flags: --nofull-compiler
-
-function foo() {
- return (0 > ("10"||10) - 1);
+function f(a, b, c) {
+ if (a == 0 || b == 0) return a;
+ return a + c;
}
-assertFalse(foo());
+assertEquals(0, f(0, 0, 0));
+assertEquals(0, f(0, 1, 0));
+assertEquals(1, f(1, 0, 0));
+assertEquals(2, f(2, 1, 0));
+
+// Force deoptimization in --always-opt mode when evaluating
+// the 'a + c' expression. Make sure this doesn't end up
+// returning 'a'.
+assertEquals(1.5, f(1, 1, 0.5));
+assertEquals(2.5, f(2, 1, 0.5));
diff --git a/test/mjsunit/regress/regress-3408144.js b/test/mjsunit/compiler/regress-7.js
similarity index 84%
copy from test/mjsunit/regress/regress-3408144.js
copy to test/mjsunit/compiler/regress-7.js
index 6e292d6..d6034f9 100644
--- a/test/mjsunit/regress/regress-3408144.js
+++ b/test/mjsunit/compiler/regress-7.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,13 +25,17 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test incorrect code generation for alternations on ARM.
+// Test correct truncation of tagged values.
+var G = 42;
-
-// Flags: --nofull-compiler
-
-function foo() {
- return (0 > ("10"||10) - 1);
+function f() {
+ var v = G;
+ var w = v >> 0;
+ return w;
}
-assertFalse(foo());
+for(var i=0; i<10000; i++) f();
+
+assertEquals(G, f());
+G = 2000000000;
+assertEquals(G, f());
diff --git a/test/mjsunit/compiler/regress-8.js b/test/mjsunit/compiler/regress-8.js
new file mode 100644
index 0000000..3a23885
--- /dev/null
+++ b/test/mjsunit/compiler/regress-8.js
@@ -0,0 +1,109 @@
+// Copyright 2010 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.
+
+// Regression test for the register allocator.
+var gp = "";
+var yE = "";
+var W = "";
+var LA = "";
+var zE = "";
+var Fp = "";
+var AE = "";
+var Gob = "";
+var Hob = "";
+var Iob = "";
+var Job = "";
+var Kob = "";
+var Lob = "";
+var Mob = "";
+var p = "";
+function O() { this.append = function(a,b,c,d,e) { return a + b + c + d + e; } }
+
+function Nob(b,a) {
+ var c;
+ if (b==2) {
+ c=new O;
+ c.append(gp,
+ yE,
+ W,
+ LA+(a.Un+(zE+(Fp+(LA+(a.Im+(zE+(AE+(LA+(a.total+Gob))))))))),
+ p);
+ c=c.toString();
+ } else {
+ if (b==1) {
+ if(a.total>=2E6) {
+ c=new O;
+ c.append(gp,yE,W,LA+(a.Un+(zE+(Fp+(LA+(a.Im+Hob))))),p);
+ c=c.toString();
+ } else {
+ if(a.total>=2E5) {
+ c=new O;
+ c.append(gp,yE,W,LA+(a.Un+(zE+(Fp+(LA+(a.Im+Iob))))),p);
+ c=c.toString();
+ } else {
+ if(a.total>=2E4) {
+ c=new O;
+ c.append(gp,yE,W,LA+(a.Un+(zE+(Fp+(LA+(a.Im+Job))))),p);
+ c=c.toString();
+ } else {
+ if(a.total>=2E3) {
+ c=new O;
+ c.append(gp,yE,W,LA+(a.Un+(zE+(Fp+(LA+(a.Im+Kob))))),p);
+ c=c.toString();
+ } else {
+ if(a.total>=200) {
+ c=new O;
+ c.append(gp,yE,W,LA+(a.Un+(zE+(Fp+(LA+(a.Im+Lob))))),p);
+ c=c.toString();
+ } else {
+ c=new O;
+ c.append(gp,yE,W,
+ LA+(a.Un+(zE+(Fp+(LA+(a.Im+(zE+(Mob+(LA+(a.total+zE))))))))),
+ p);
+ c=c.toString();
+ }
+ c=c;
+ }
+ c=c;
+ }
+ c=c;
+ }
+ c=c;
+ }
+ c=c;
+ } else {
+ c=new O;
+ c.append(gp,yE,W,
+ LA+(a.Un+(zE+(Fp+(LA+(a.Im+(zE+(AE+(LA+(a.total+zE))))))))),
+ p);
+ c=c.toString();
+ }
+ c=c;
+ }
+ return c;
+}
+Nob(2, { Un: "" , Im: "" , total: 42});
diff --git a/test/mjsunit/regress/regress-1146.js b/test/mjsunit/compiler/regress-arguments.js
similarity index 73%
copy from test/mjsunit/regress/regress-1146.js
copy to test/mjsunit/compiler/regress-arguments.js
index e8028ce..234d3fb 100644
--- a/test/mjsunit/regress/regress-1146.js
+++ b/test/mjsunit/compiler/regress-arguments.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,24 +25,25 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test keyed calls with different key types.
-function F() {}
-var a = new F();
-function f(i) { return a[i](); }
+// Test of arguments.
-a.first = function() { return 11; }
-a[0] = function() { return 22; }
-var obj = {};
-a[obj] = function() { return 33; }
+// Test passing null or undefined as receiver.
+function f() { return this.foo; }
-// Make object slow-case.
-a.foo = 0;
-delete a.foo;
-// Do multiple calls for IC transitions.
-var b = "first";
-f(b);
-f(b);
+function g() { return f.apply(null, arguments); }
+function h() { return f.apply(void 0, arguments); }
-assertEquals(11, f(b));
-assertEquals(22, f(0));
-assertEquals(33, f(obj));
+var foo = 42;
+
+for (var i=0; i<1000000; i++) assertEquals(42, g());
+for (var i=0; i<1000000; i++) assertEquals(42, h());
+
+var G1 = 21;
+var G2 = 22;
+
+function u() {
+ var v = G1 + G2;
+ return f.apply(v, arguments);
+}
+
+for (var i=0; i<1000000; i++) assertEquals(void 0, u());
diff --git a/test/mjsunit/regress/regress-3408144.js b/test/mjsunit/compiler/regress-arrayliteral.js
similarity index 86%
copy from test/mjsunit/regress/regress-3408144.js
copy to test/mjsunit/compiler/regress-arrayliteral.js
index 6e292d6..8938785 100644
--- a/test/mjsunit/regress/regress-3408144.js
+++ b/test/mjsunit/compiler/regress-arrayliteral.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,13 +25,9 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test incorrect code generation for alternations on ARM.
+// Regression test for array literals.
-
-// Flags: --nofull-compiler
-
-function foo() {
- return (0 > ("10"||10) - 1);
-}
-
-assertFalse(foo());
+var G = 41;
+var H = 42;
+function f() { var v = [G,H]; return v[1]; }
+assertEquals(42, f());
diff --git a/test/mjsunit/compiler/regress-funarguments.js b/test/mjsunit/compiler/regress-funarguments.js
new file mode 100644
index 0000000..cea40bc
--- /dev/null
+++ b/test/mjsunit/compiler/regress-funarguments.js
@@ -0,0 +1,82 @@
+// Copyright 2010 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.
+
+// Test function.arguments.
+
+function A() {}
+function B() {}
+
+function fee(x, y) {
+ if (x == 1) return fee["arg" + "uments"];
+ if (x == 2) return gee["arg" + "uments"];
+ return 42;
+}
+
+function gee(x) { return this.f(2 - x, "f"); }
+
+function foo(x, y) {
+ if (x == 0) return foo["arg" + "uments"];
+ if (x == 1) return goo["arg" + "uments"];
+ return 42;
+}
+
+function goo(x) { return this.f(x, "f"); }
+
+A.prototype.f = fee;
+A.prototype.g = gee;
+
+B.prototype.f = foo;
+B.prototype.g = goo;
+
+var o = new A();
+
+function hej(x) {
+ if (x == 0) return o.g(x, "h");
+ if (x == 1) return o.g(x, "h");
+ return o.g(x, "z");
+}
+
+function stress() {
+ for (var i=0; i<5000000; i++) o.g(i, "g");
+ for (var j=0; j<5000000; j++) hej(j);
+}
+
+stress();
+
+assertArrayEquals([0, "g"], o.g(0, "g"));
+assertArrayEquals([1, "f"], o.g(1, "g"));
+assertArrayEquals([0, "h"], hej(0));
+assertArrayEquals([1, "f"], hej(1));
+
+o = new B();
+
+stress();
+
+assertArrayEquals([0, "f"], o.g(0, "g"));
+assertArrayEquals([1, "g"], o.g(1, "g"));
+assertArrayEquals([0, "f"], hej(0));
+assertArrayEquals([1, "h"], hej(1));
diff --git a/test/mjsunit/regress/regress-1146.js b/test/mjsunit/compiler/regress-funcaller.js
similarity index 62%
copy from test/mjsunit/regress/regress-1146.js
copy to test/mjsunit/compiler/regress-funcaller.js
index e8028ce..88db147 100644
--- a/test/mjsunit/regress/regress-1146.js
+++ b/test/mjsunit/compiler/regress-funcaller.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,24 +25,49 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test keyed calls with different key types.
-function F() {}
-var a = new F();
-function f(i) { return a[i](); }
+// Test function.caller.
+function A() {}
-a.first = function() { return 11; }
-a[0] = function() { return 22; }
-var obj = {};
-a[obj] = function() { return 33; }
+function fun(x) {
+ if (x == 0) return fun.caller;
+ if (x == 1) return gee.caller;
+ return 42;
+}
+function gee(x) { return this.f(x); }
-// Make object slow-case.
-a.foo = 0;
-delete a.foo;
-// Do multiple calls for IC transitions.
-var b = "first";
-f(b);
-f(b);
+A.prototype.f = fun;
+A.prototype.g = gee;
-assertEquals(11, f(b));
-assertEquals(22, f(0));
-assertEquals(33, f(obj));
+var o = new A();
+
+for (var i=0; i<5000000; i++) {
+ o.g(i);
+}
+assertEquals(gee, o.g(0));
+assertEquals(null, o.g(1));
+
+// Test when called from another function.
+function hej(x) {
+ if (x == 0) return o.g(x);
+ if (x == 1) return o.g(x);
+ return o.g(x);
+}
+
+for (var j=0; j<5000000; j++) {
+ hej(j);
+}
+assertEquals(gee, hej(0));
+assertEquals(hej, hej(1));
+
+// Test when called from eval.
+function from_eval(x) {
+ if (x == 0) return eval("o.g(x);");
+ if (x == 1) return eval("o.g(x);");
+ return o.g(x);
+}
+
+for (var j=0; j<5000000; j++) {
+ from_eval(j);
+}
+assertEquals(gee, from_eval(0));
+assertEquals(from_eval, from_eval(1));
diff --git a/test/mjsunit/compiler/regress-gap.js b/test/mjsunit/compiler/regress-gap.js
new file mode 100644
index 0000000..a812daa
--- /dev/null
+++ b/test/mjsunit/compiler/regress-gap.js
@@ -0,0 +1,130 @@
+// Copyright 2010 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.
+
+// Regression test that stresses the register allocator gap instruction.
+
+function small_select(n, v1, v2) {
+ for (var i = 0; i < n; ++i) {
+ var tmp = v1;
+ v1 = v2;
+ v2 = tmp;
+ }
+ return v1;
+}
+
+function select(n, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10) {
+ for (var i = 0; i < n; ++i) {
+ var tmp = v1;
+ v1 = v2;
+ v2 = v3;
+ v3 = v4;
+ v4 = v5;
+ v5 = v6;
+ v6 = v7;
+ v7 = v8;
+ v8 = v9;
+ v9 = v10;
+ v10 = tmp;
+ }
+ return v1;
+}
+
+function select_while(n, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10) {
+ var i = 0;
+ while (i < n) {
+ var tmp = v1;
+ v1 = v2;
+ v2 = v3;
+ v3 = v4;
+ v4 = v5;
+ v5 = v6;
+ v6 = v7;
+ v7 = v8;
+ v8 = v9;
+ v9 = v10;
+ v10 = tmp;
+ i++;
+ }
+ return v1;
+}
+
+function two_cycles(n, v1, v2, v3, v4, v5, x1, x2, x3, x4, x5) {
+ for (var i = 0; i < n; ++i) {
+ var tmp = v1;
+ v1 = v2;
+ v2 = v3;
+ v3 = v4;
+ v4 = v5;
+ v5 = tmp;
+ tmp = x1;
+ x1 = x2;
+ x2 = x3;
+ x3 = x4;
+ x4 = x5;
+ x5 = tmp;
+ }
+ return v1 + x1;
+}
+
+function two_cycles_while(n, v1, v2, v3, v4, v5, x1, x2, x3, x4, x5) {
+ var i = 0;
+ while (i < n) {
+ var tmp = v1;
+ v1 = v2;
+ v2 = v3;
+ v3 = v4;
+ v4 = v5;
+ v5 = tmp;
+ tmp = x1;
+ x1 = x2;
+ x2 = x3;
+ x3 = x4;
+ x4 = x5;
+ x5 = tmp;
+ i++;
+ }
+ return v1 + x1;
+}
+assertEquals(1, small_select(0, 1, 2));
+assertEquals(2, small_select(1, 1, 2));
+assertEquals(1, small_select(10, 1, 2));
+
+assertEquals(1, select(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
+assertEquals(4, select(3, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
+assertEquals(10, select(9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
+
+assertEquals(1 + 6, two_cycles(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
+assertEquals(4 + 9, two_cycles(3, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
+assertEquals(5 + 10, two_cycles(9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
+
+assertEquals(1, select_while(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
+assertEquals(4, select_while(3, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
+assertEquals(10, select_while(9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
+
+assertEquals(1 + 6, two_cycles_while(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
+assertEquals(4 + 9, two_cycles_while(3, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
+assertEquals(5 + 10, two_cycles_while(9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
diff --git a/test/mjsunit/regress/regress-3408144.js b/test/mjsunit/compiler/regress-gvn.js
similarity index 79%
copy from test/mjsunit/regress/regress-3408144.js
copy to test/mjsunit/compiler/regress-gvn.js
index 6e292d6..358daf7 100644
--- a/test/mjsunit/regress/regress-3408144.js
+++ b/test/mjsunit/compiler/regress-gvn.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,13 +25,27 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test incorrect code generation for alternations on ARM.
+// Flags: --noalways-opt
+//
+// Regression test for global value numbering.
-
-// Flags: --nofull-compiler
-
-function foo() {
- return (0 > ("10"||10) - 1);
+function test(a) {
+ var res = a[0] + a[0];
+ if (res == 0) {
+ a[0] = 1;
+ }
+ return a[0];
}
-assertFalse(foo());
+var a = new Array();
+
+var n = 100000000;
+
+var result = 0;
+for (var i = 0; i < n; ++i) {
+ a[0] = 0;
+ result += test(a);
+}
+
+
+assertEquals(n, result);
diff --git a/test/mjsunit/regress/regress-1146.js b/test/mjsunit/compiler/regress-intoverflow.js
similarity index 67%
copy from test/mjsunit/regress/regress-1146.js
copy to test/mjsunit/compiler/regress-intoverflow.js
index e8028ce..d3842f1 100644
--- a/test/mjsunit/regress/regress-1146.js
+++ b/test/mjsunit/compiler/regress-intoverflow.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,24 +25,38 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test keyed calls with different key types.
-function F() {}
-var a = new F();
-function f(i) { return a[i](); }
+// Test overflow checks in optimized code.
+function testMul(a, b) {
+ a *= 2;
+ b *= 2;
+ if (a < 1 && b < 1) {
+ return a * b;
+ }
+}
-a.first = function() { return 11; }
-a[0] = function() { return 22; }
-var obj = {};
-a[obj] = function() { return 33; }
+for (var i=0; i<1000000; i++) testMul(0,0);
+assertEquals(4611686018427388000, testMul(-0x40000000, -0x40000000));
-// Make object slow-case.
-a.foo = 0;
-delete a.foo;
-// Do multiple calls for IC transitions.
-var b = "first";
-f(b);
-f(b);
+function testAdd(a, b) {
+ a *= 2;
+ b *= 2;
+ if (a < 1 && b < 1) {
+ return a + b;
+ }
+}
-assertEquals(11, f(b));
-assertEquals(22, f(0));
-assertEquals(33, f(obj));
+for (var i=0; i<1000000; i++) testAdd(0,0);
+assertEquals(-4294967296, testAdd(-0x40000000, -0x40000000));
+
+
+function testSub(a, b) {
+ a *= 2;
+ b *= 2;
+ if (b == 2) {print(a); print(b);}
+ if (a < 1 && b < 3) {
+ return a - b;
+ }
+}
+
+for (var i=0; i<1000000; i++) testSub(0,0);
+assertEquals(-2147483650, testSub(-0x40000000, 1));
diff --git a/test/mjsunit/regress/regress-3408144.js b/test/mjsunit/compiler/regress-loop-deopt.js
similarity index 85%
copy from test/mjsunit/regress/regress-3408144.js
copy to test/mjsunit/compiler/regress-loop-deopt.js
index 6e292d6..7906761 100644
--- a/test/mjsunit/regress/regress-3408144.js
+++ b/test/mjsunit/compiler/regress-loop-deopt.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,13 +25,17 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test incorrect code generation for alternations on ARM.
-
-
-// Flags: --nofull-compiler
-
-function foo() {
- return (0 > ("10"||10) - 1);
+// Test while loops and continue.
+function h() {
+ var i = 3, j = 0;
+ while(--i >= 0) {
+ var x = i & 1;
+ if(x > 0) {
+ continue;
+ }
+ j++;
+ }
+ return j;
}
-assertFalse(foo());
+assertEquals(2, h());
diff --git a/test/mjsunit/regress/regress-3408144.js b/test/mjsunit/compiler/regress-max.js
similarity index 85%
copy from test/mjsunit/regress/regress-3408144.js
copy to test/mjsunit/compiler/regress-max.js
index 6e292d6..94c543a 100644
--- a/test/mjsunit/regress/regress-3408144.js
+++ b/test/mjsunit/compiler/regress-max.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2008 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:
@@ -25,13 +25,10 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test incorrect code generation for alternations on ARM.
+// Test Math.max with negative zero as input.
+function f(x, y) { return Math.max(x, y) }
+for (var i = 0; i < 1000000; i++) f(0, 0);
-// Flags: --nofull-compiler
-
-function foo() {
- return (0 > ("10"||10) - 1);
-}
-
-assertFalse(foo());
+var r = f(-0, -0);
+assertEquals(-Infinity, 1 / r);
diff --git a/test/mjsunit/regress/regress-1146.js b/test/mjsunit/compiler/regress-or.js
similarity index 72%
copy from test/mjsunit/regress/regress-1146.js
copy to test/mjsunit/compiler/regress-or.js
index e8028ce..89f7802 100644
--- a/test/mjsunit/regress/regress-1146.js
+++ b/test/mjsunit/compiler/regress-or.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,24 +25,33 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test keyed calls with different key types.
-function F() {}
-var a = new F();
-function f(i) { return a[i](); }
+// Test deoptimization inside short-circuited expressions.
+function f1(x) {
+ var c = "fail";
+ if (!x || g1()) {
+ c = ~x;
+ }
+ return c;
+}
-a.first = function() { return 11; }
-a[0] = function() { return 22; }
-var obj = {};
-a[obj] = function() { return 33; }
+function g1() { try { return 1; } finally {} }
-// Make object slow-case.
-a.foo = 0;
-delete a.foo;
-// Do multiple calls for IC transitions.
-var b = "first";
-f(b);
-f(b);
+for (var i=0; i<10000000; i++) f1(42);
-assertEquals(11, f(b));
-assertEquals(22, f(0));
-assertEquals(33, f(obj));
+assertEquals(-1, f1(0));
+assertEquals(-43, f1(42));
+assertEquals(-1, f1(""));
+
+function f2(x) {
+ var c = "fail";
+ if (!x || !g2()) {
+ c = ~x;
+ }
+ return c;
+}
+
+function g2() { try { return 0; } finally {} }
+
+for (var i=0; i<10000000; i++) f2(42);
+
+assertEquals(-1, f2(""));
diff --git a/test/mjsunit/regress/regress-3408144.js b/test/mjsunit/compiler/regress-rep-change.js
similarity index 81%
copy from test/mjsunit/regress/regress-3408144.js
copy to test/mjsunit/compiler/regress-rep-change.js
index 6e292d6..9370999 100644
--- a/test/mjsunit/regress/regress-3408144.js
+++ b/test/mjsunit/compiler/regress-rep-change.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,13 +25,18 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test incorrect code generation for alternations on ARM.
+// Regression test for the case where a phi has two input operands with
+// the same value.
-
-// Flags: --nofull-compiler
-
-function foo() {
- return (0 > ("10"||10) - 1);
+function test(start) {
+ if (true) {
+ for (var i = start; i < 10; i++) { }
+ }
+ for (var i = start; i < 10; i++) { }
}
-assertFalse(foo());
+var n = 5000000;
+
+for (var i = 0; i < n; ++i) {
+ test(0);
+}
diff --git a/test/mjsunit/regress/regress-1146.js b/test/mjsunit/compiler/regress-stacktrace-methods.js
similarity index 62%
copy from test/mjsunit/regress/regress-1146.js
copy to test/mjsunit/compiler/regress-stacktrace-methods.js
index e8028ce..4900ccf 100644
--- a/test/mjsunit/regress/regress-1146.js
+++ b/test/mjsunit/compiler/regress-stacktrace-methods.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,24 +25,40 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test keyed calls with different key types.
-function F() {}
-var a = new F();
-function f(i) { return a[i](); }
+// Test stack traces with method calls.
+function Hest() {}
+function Svin() {}
-a.first = function() { return 11; }
-a[0] = function() { return 22; }
-var obj = {};
-a[obj] = function() { return 33; }
+Svin.prototype.two = function() { /* xxxxxxx */ o.three(); }
-// Make object slow-case.
-a.foo = 0;
-delete a.foo;
-// Do multiple calls for IC transitions.
-var b = "first";
-f(b);
-f(b);
+Hest.prototype.one = function(x) { x.two(); }
-assertEquals(11, f(b));
-assertEquals(22, f(0));
-assertEquals(33, f(obj));
+Hest.prototype.three = function() { if (v == 42) throw new Error("urg"); }
+
+var o = new Hest();
+var s = new Svin();
+var v = 0;
+
+for (var i = 0; i < 1000000; i++) {
+ o.one(s);
+}
+
+v = 42;
+
+try {
+ o.one(s);
+} catch (e) {
+ var stack = e.stack.toString();
+ var p3 = stack.indexOf("at Hest.three");
+ var p2 = stack.indexOf("at Svin.two");
+ var p1 = stack.indexOf("at Hest.one");
+ assertTrue(p3 != -1);
+ assertTrue(p2 != -1);
+ assertTrue(p1 != -1);
+ assertTrue(p3 < p2);
+ assertTrue(p2 < p1);
+ assertTrue(stack.indexOf("36:56") != -1);
+ assertTrue(stack.indexOf("32:51") != -1);
+ assertTrue(stack.indexOf("34:38") != -1);
+ assertTrue(stack.indexOf("49:5") != -1);
+}
diff --git a/test/mjsunit/regress/regress-3408144.js b/test/mjsunit/compiler/regress-stacktrace.js
similarity index 73%
copy from test/mjsunit/regress/regress-3408144.js
copy to test/mjsunit/compiler/regress-stacktrace.js
index 6e292d6..843dd12 100644
--- a/test/mjsunit/regress/regress-3408144.js
+++ b/test/mjsunit/compiler/regress-stacktrace.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,13 +25,28 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test incorrect code generation for alternations on ARM.
+// Test correctness of stack traces with global functions.
+eval("function two() { /* xxxxxxx */ three(); }");
-
-// Flags: --nofull-compiler
-
-function foo() {
- return (0 > ("10"||10) - 1);
+function one() {
+ two();
}
-assertFalse(foo());
+function three() {
+ throw new Error("urg");
+}
+
+try {
+ one();
+} catch (e) {
+ var stack = e.stack.toString();
+ var p3 = stack.indexOf("at three");
+ var p2 = stack.indexOf("at two");
+ var p1 = stack.indexOf("at one");
+ assertTrue(p3 != -1);
+ assertTrue(p2 != -1);
+ assertTrue(p1 != -1);
+ assertTrue(p3 < p2);
+ assertTrue(p2 < p1);
+ print(stack);
+}
diff --git a/test/mjsunit/regress/regress-3408144.js b/test/mjsunit/compiler/safepoint.js
similarity index 86%
copy from test/mjsunit/regress/regress-3408144.js
copy to test/mjsunit/compiler/safepoint.js
index 6e292d6..ee8fcf0 100644
--- a/test/mjsunit/regress/regress-3408144.js
+++ b/test/mjsunit/compiler/safepoint.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,13 +25,15 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test incorrect code generation for alternations on ARM.
+// Flags: --expose-gc
-
-// Flags: --nofull-compiler
-
-function foo() {
- return (0 > ("10"||10) - 1);
+function Test(o) {
+ var x = o;
+ var y = this;
+ x.gc();
+ x.gc();
+ return y;
}
-assertFalse(foo());
+var o = {gc:gc};
+assertTrue(Test(o) === this);
diff --git a/test/mjsunit/compiler/simple-bailouts.js b/test/mjsunit/compiler/simple-bailouts.js
index af80b7f..ef7a0f4 100644
--- a/test/mjsunit/compiler/simple-bailouts.js
+++ b/test/mjsunit/compiler/simple-bailouts.js
@@ -25,8 +25,6 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Flags: --fast-compiler
-
function Test() {
this.result = 0;
this.x = 0;
@@ -92,6 +90,14 @@
| a; // 1.1
}
+Test.prototype.test10 = function() {
+ this.z = (a >> b) | (c >> c);
+}
+
+Test.prototype.test11 = function(x) {
+ this.z = x >> x;
+}
+
var t = new Test();
t.test0();
@@ -125,3 +131,13 @@
assertEquals(14, t.x);
assertEquals(6, t.y);
assertEquals(15, t.z);
+
+a = "2";
+t.test11(a);
+assertEquals(0, t.z);
+
+a = 4;
+b = "1";
+c = 2;
+t.test10();
+assertEquals(2, t.z);
diff --git a/test/mjsunit/compiler/simple-binary-op.js b/test/mjsunit/compiler/simple-binary-op.js
index 15e1a55..a4e8ab5 100644
--- a/test/mjsunit/compiler/simple-binary-op.js
+++ b/test/mjsunit/compiler/simple-binary-op.js
@@ -25,8 +25,6 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Flags: --fast-compiler
-
var a = 1;
var b = 2;
var c = 4;
diff --git a/test/mjsunit/compiler/simple-deopt.js b/test/mjsunit/compiler/simple-deopt.js
new file mode 100644
index 0000000..8befd9f
--- /dev/null
+++ b/test/mjsunit/compiler/simple-deopt.js
@@ -0,0 +1,101 @@
+// Copyright 2010 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.
+
+function f(x) {
+ return ~x;
+}
+
+f(42);
+assertEquals(~12, f(12.45));
+assertEquals(~42, f(42.87));
+
+
+var a = 1, b = 2, c = 4, d = 8;
+function g() {
+ return a | (b | (c | d));
+}
+
+g();
+c = "16";
+assertEquals(1 | 2 | 16 | 8, g());
+
+
+// Test deopt when global function changes.
+function h() {
+ return g();
+}
+assertEquals(1 | 2 | 16 | 8, h());
+g = function() { return 42; };
+assertEquals(42, h());
+
+
+// Test deopt when map changes.
+var obj = {};
+obj.g = g;
+function k(o) {
+ return o.g();
+}
+for (var i = 0; i < 1000000; i++) k(obj);
+assertEquals(42, k(obj));
+assertEquals(87, k({g: function() { return 87; }}));
+
+
+// Test deopt with assignments to parameters.
+function p(x,y) {
+ x = 42;
+ y = 1;
+ y = y << "0";
+ return x | y;
+}
+assertEquals(43, p(0,0));
+
+
+// Test deopt with literals on the expression stack.
+function LiteralToStack(x) {
+ return 'lit[' + (x + ']');
+}
+
+assertEquals('lit[-87]', LiteralToStack(-87));
+assertEquals('lit[0]', LiteralToStack(0));
+assertEquals('lit[42]', LiteralToStack(42));
+
+
+// Test deopt before call.
+var str = "abc";
+var r;
+function CallCharAt(n) { return str.charAt(n); }
+for (var i = 0; i < 1000000; i++) {
+ r = CallCharAt(0);
+}
+assertEquals("a", r);
+
+
+// Test of deopt in presence of spilling.
+function add4(a,b,c,d) {
+ return a+b+c+d;
+}
+assertEquals(0x40000003, add4(1,1,2,0x3fffffff));
diff --git a/test/mjsunit/compiler/simple-global-access.js b/test/mjsunit/compiler/simple-global-access.js
index 35746ba..87a641c 100644
--- a/test/mjsunit/compiler/simple-global-access.js
+++ b/test/mjsunit/compiler/simple-global-access.js
@@ -25,9 +25,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Flags: --fast-compiler
-
-// Test global variable loads with the fast compiler.
+// Test global variable loads.
var g1 = 42;
var g2 = 43;
var g3 = 44;
diff --git a/test/mjsunit/compiler/simple-inlining.js b/test/mjsunit/compiler/simple-inlining.js
new file mode 100644
index 0000000..219580f
--- /dev/null
+++ b/test/mjsunit/compiler/simple-inlining.js
@@ -0,0 +1,146 @@
+// Copyright 2010 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.
+
+// Test that we can inline a function that returns a constant.
+function TestInlineConstant(o) {
+ // Effect context.
+ o.f();
+ // Value context.
+ var x = o.f();
+ assertEquals(42, x);
+ assertEquals(42, o.f());
+ // Test context.
+ if (!o.f()) {
+ assertTrue(false); // Should not happen.
+ }
+}
+
+var o1 = {};
+o1.f = function() { return 42; };
+for (var i = 0; i < 10000; i++) TestInlineConstant(o1);
+TestInlineConstant({f: o1.f});
+
+
+// Test that we can inline a function that returns 'this'.
+function TestInlineThis(o) {
+ // Effect context.
+ o.g();
+ // Value context.
+ var x = o.g();
+ assertEquals(o, x);
+ assertEquals(o, o.g());
+ // Test context.
+ if (!o.g()) {
+ assertTrue(false); // Should not happen.
+ }
+}
+
+var o2 = {};
+o2.g = function() { return this; };
+for (var i = 0; i < 10000; i++) TestInlineThis(o2);
+TestInlineThis({g: o2.g});
+
+
+// Test that we can inline a function that returns 'this.x'.
+function TestInlineThisX(o) {
+ // Effect context.
+ o.h();
+ // Value context.
+ var x = o.h();
+ assertEquals(42, x);
+ assertEquals(42, o.h());
+ // Test context.
+ if (!o.h()) {
+ assertTrue(false); // Should not happen.
+ }
+}
+
+var o3 = {y:0,x:42};
+o3.h = function() { return this.x; };
+for (var i = 0; i < 10000; i++) TestInlineThisX(o3);
+TestInlineThisX({h: o3.h, x:42});
+
+
+// Test that we can inline a function that returns 'this.x.length'.
+function TestInlineThisXLength(o) {
+ // Effect context.
+ o.h();
+ // Value context.
+ var x = o.h();
+ assertEquals(3, x);
+ assertEquals(3, o.h());
+ // Test context.
+ if (!o.h()) {
+ assertTrue(false); // Should not happen.
+ }
+}
+
+var o4 = {x:[1,2,3]};
+o4.h = function() { return this.x.length; };
+for (var i = 0; i < 10000; i++) TestInlineThisXLength(o4);
+TestInlineThisXLength({h: o4.h, x:[1,2,3]});
+
+
+// Test that we can inline a function that returns 'this.x.y'.
+function TestInlineThisXY(o) {
+ // Effect context.
+ o.h();
+ // Value context.
+ var x = o.h();
+ assertEquals(42, x);
+ assertEquals(42, o.h());
+ // Test context.
+ if (!o.h()) {
+ assertTrue(false); // Should not happen.
+ }
+}
+
+var o6 = {y:42}
+var o5 = {e:o6};
+o5.h = function() { return this.e.y; };
+for (var i = 0; i < 10000; i++) TestInlineThisXY(o5);
+TestInlineThisXY({h: o5.h, e:o6});
+
+
+// Test that we can inline a function that returns 'this.x.length'.
+function TestInlineThisX0(o) {
+ // Effect context.
+ o.foo();
+ // Value context.
+ var x = o.foo();
+ assertEquals(42, x);
+ assertEquals(42, o.foo());
+ // Test context.
+ if (!o.foo()) {
+ assertTrue(false); // Should not happen.
+ }
+}
+
+var o7 = {x:[42,43,44]};
+o7.foo = function() { return this.x[0]; };
+for (var i = 0; i < 10000; i++) TestInlineThisX0(o7);
+TestInlineThisX0({foo: o7.foo, x:[42,0,0]});
diff --git a/test/mjsunit/regress/regress-3408144.js b/test/mjsunit/compiler/simple-osr.js
similarity index 82%
copy from test/mjsunit/regress/regress-3408144.js
copy to test/mjsunit/compiler/simple-osr.js
index 6e292d6..8ec1b2b 100644
--- a/test/mjsunit/regress/regress-3408144.js
+++ b/test/mjsunit/compiler/simple-osr.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,13 +25,20 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test incorrect code generation for alternations on ARM.
+// Flags: --use-osr
-
-// Flags: --nofull-compiler
-
-function foo() {
- return (0 > ("10"||10) - 1);
+function f() {
+ var sum = 0;
+ for (var i = 0; i < 1000000; i++) {
+ var x = i + 2;
+ var y = x + 5;
+ var z = y + 3;
+ sum += z;
+ }
+ return sum;
}
-assertFalse(foo());
+
+for (var i = 0; i < 2; i++) {
+ assertEquals(500009500000, f());
+}
diff --git a/test/mjsunit/regress/regress-3408144.js b/test/mjsunit/compiler/switch-bailout.js
similarity index 81%
copy from test/mjsunit/regress/regress-3408144.js
copy to test/mjsunit/compiler/switch-bailout.js
index 6e292d6..8011d44 100644
--- a/test/mjsunit/regress/regress-3408144.js
+++ b/test/mjsunit/compiler/switch-bailout.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,13 +25,15 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test incorrect code generation for alternations on ARM.
-
-
-// Flags: --nofull-compiler
-
-function foo() {
- return (0 > ("10"||10) - 1);
+// Test that bailing out of the optimized compilation doesn't mess with
+// the labels in the AST.
+function f(x) {
+ switch (x) {
+ case "foo": return 87;
+ case "bar": return 42;
+ }
+ return 99;
}
-assertFalse(foo());
+for (var i = 0; i < 10000; i++) f("foo");
+assertEquals(42, f("bar"));
diff --git a/test/mjsunit/compiler/this-property-refs.js b/test/mjsunit/compiler/this-property-refs.js
index 5e8ea59..1ee8e50 100644
--- a/test/mjsunit/compiler/this-property-refs.js
+++ b/test/mjsunit/compiler/this-property-refs.js
@@ -25,8 +25,6 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Flags: --fast-compiler
-
// Test references to properties of this.
function Test() {
this.a = 0;
diff --git a/test/mjsunit/compiler/thisfunction.js b/test/mjsunit/compiler/thisfunction.js
index 098fc3a..7615561 100644
--- a/test/mjsunit/compiler/thisfunction.js
+++ b/test/mjsunit/compiler/thisfunction.js
@@ -25,8 +25,6 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Flags: --always-full-compiler
-
// Test reference to this-function.
var g = (function f(x) {
diff --git a/test/mjsunit/compiler/variables.js b/test/mjsunit/compiler/variables.js
new file mode 100644
index 0000000..fac4878
--- /dev/null
+++ b/test/mjsunit/compiler/variables.js
@@ -0,0 +1,73 @@
+// Copyright 2010 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.
+
+// Simple tests of the various kinds of variable references in the
+// implementstion.
+
+// Global variables.
+var x = 0;
+function f0() { return x; }
+assertEquals(0, f0());
+
+
+// Parameters.
+function f1(x) { return x; }
+assertEquals(1, f1(1));
+
+
+// Stack-allocated locals.
+function f2() { var x = 2; return x; }
+assertEquals(2, f2());
+
+
+// Context-allocated locals. Local function forces x into f3's context.
+function f3(x) {
+ function g() { return x; }
+ return x;
+}
+assertEquals(3, f3(3));
+
+// Local function reads x from an outer context.
+function f4(x) {
+ function g() { return x; }
+ return g();
+}
+assertEquals(4, f4(4));
+
+
+// Lookup slots. 'With' forces x to be looked up at runtime.
+function f5(x) {
+ with ({}) return x;
+}
+assertEquals(5, f5(5));
+
+
+// Parameters rewritten to property accesses. Using the name 'arguments'
+// (even if it shadows the arguments object) forces all parameters to be
+// rewritten to explicit property accesses.
+function f6(arguments) { return arguments; }
+assertEquals(6, f6(6));
diff --git a/test/mjsunit/date.js b/test/mjsunit/date.js
index 57fc5a0..f13af82 100644
--- a/test/mjsunit/date.js
+++ b/test/mjsunit/date.js
@@ -167,8 +167,8 @@
// Modified test from WebKit
// LayoutTests/fast/js/script-tests/date-utc-timeclip.js:
-assertEquals(Date.UTC(275760, 8, 12, 23, 59, 59, 999), 8639999999999999);
-assertEquals(Date.UTC(275760, 8, 13), 8640000000000000);
+assertEquals(8639999999999999, Date.UTC(275760, 8, 12, 23, 59, 59, 999));
+assertEquals(8640000000000000, Date.UTC(275760, 8, 13));
assertTrue(isNaN(Date.UTC(275760, 8, 13, 0, 0, 0, 1)));
assertTrue(isNaN(Date.UTC(275760, 8, 14)));
@@ -176,3 +176,14 @@
assertEquals(Date.UTC(-271821, 3, 20), -8640000000000000);
assertTrue(isNaN(Date.UTC(-271821, 3, 19, 23, 59, 59, 999)));
assertTrue(isNaN(Date.UTC(-271821, 3, 19)));
+
+
+// Test creation of large date values.
+d = new Date(1969, 12, 1, 99999999999);
+assertTrue(isNaN(d.getTime()));
+d = new Date(1969, 12, 1, -99999999999);
+assertTrue(isNaN(d.getTime()));
+d = new Date(1969, 12, 1, Infinity);
+assertTrue(isNaN(d.getTime()));
+d = new Date(1969, 12, 1, -Infinity);
+assertTrue(isNaN(d.getTime()));
diff --git a/test/mjsunit/debug-changebreakpoint.js b/test/mjsunit/debug-changebreakpoint.js
index 936523a..897c3e3 100644
--- a/test/mjsunit/debug-changebreakpoint.js
+++ b/test/mjsunit/debug-changebreakpoint.js
@@ -33,6 +33,7 @@
listenerComplete = false;
exception = false;
+var breakpoint = -1;
var base_request = '"seq":0,"type":"request","command":"changebreakpoint"'
function safeEval(code) {
@@ -68,21 +69,21 @@
testArguments(dcp, '{}', false);
testArguments(dcp, '{"breakpoint":0,"condition":"false"}', false);
- // TODO(1241036) change this to 2 when break points have been restructured.
- testArguments(dcp, '{"breakpoint":3,"condition":"false"}', false);
+ testArguments(dcp, '{"breakpoint":' + (breakpoint + 1) + ',"condition":"false"}', false);
testArguments(dcp, '{"breakpoint":"xx","condition":"false"}', false);
// Test some legal clearbreakpoint requests.
- testArguments(dcp, '{"breakpoint":1}', true);
- testArguments(dcp, '{"breakpoint":1,"enabled":"true"}', true);
- testArguments(dcp, '{"breakpoint":1,"enabled":"false"}', true);
- testArguments(dcp, '{"breakpoint":1,"condition":"1==2"}', true);
- testArguments(dcp, '{"breakpoint":1,"condition":"false"}', true);
- testArguments(dcp, '{"breakpoint":1,"ignoreCount":7}', true);
- testArguments(dcp, '{"breakpoint":1,"ignoreCount":0}', true);
+ var bp_str = '"breakpoint":' + breakpoint;;
+ testArguments(dcp, '{' + bp_str + '}', true);
+ testArguments(dcp, '{' + bp_str + ',"enabled":"true"}', true);
+ testArguments(dcp, '{' + bp_str + ',"enabled":"false"}', true);
+ testArguments(dcp, '{' + bp_str + ',"condition":"1==2"}', true);
+ testArguments(dcp, '{' + bp_str + ',"condition":"false"}', true);
+ testArguments(dcp, '{' + bp_str + ',"ignoreCount":7}', true);
+ testArguments(dcp, '{' + bp_str + ',"ignoreCount":0}', true);
testArguments(
dcp,
- '{"breakpoint":1,"enabled":"true","condition":"false","ignoreCount":0}',
+ '{' + bp_str + ',"enabled":"true","condition":"false","ignoreCount":0}',
true);
// Indicate that all was processed.
@@ -99,8 +100,7 @@
function g() {};
// Set a break point and call to invoke the debug event listener.
-bp = Debug.setBreakPoint(g, 0, 0);
-assertEquals(1, bp);
+breakpoint = Debug.setBreakPoint(g, 0, 0);
g();
// Make sure that the debug event listener vas invoked.
diff --git a/test/mjsunit/debug-clearbreakpoint.js b/test/mjsunit/debug-clearbreakpoint.js
index 59479f2..58e1531 100644
--- a/test/mjsunit/debug-clearbreakpoint.js
+++ b/test/mjsunit/debug-clearbreakpoint.js
@@ -33,6 +33,7 @@
listenerComplete = false;
exception = false;
+var breakpoint = -1;
var base_request = '"seq":0,"type":"request","command":"clearbreakpoint"'
function safeEval(code) {
@@ -68,15 +69,14 @@
testArguments(dcp, '{}', false);
testArguments(dcp, '{"breakpoint":0}', false);
- // TODO(1241036) change this to 2 when break points have been restructured.
- testArguments(dcp, '{"breakpoint":3}', false);
+ testArguments(dcp, '{"breakpoint":' + (breakpoint + 1)+ '}', false);
testArguments(dcp, '{"breakpoint":"xx"}', false);
// Test some legal clearbreakpoint requests.
- testArguments(dcp, '{"breakpoint":1}', true);
+ testArguments(dcp, '{"breakpoint":' + breakpoint + '}', true);
// Cannot clear the same break point twice.
- testArguments(dcp, '{"breakpoint":1}', false);
+ testArguments(dcp, '{"breakpoint":' + breakpoint + '}', false);
// Indicate that all was processed.
listenerComplete = true;
@@ -92,8 +92,7 @@
function g() {};
// Set a break point and call to invoke the debug event listener.
-bp = Debug.setBreakPoint(g, 0, 0);
-assertEquals(1, bp);
+breakpoint = Debug.setBreakPoint(g, 0, 0);
g();
// Make sure that the debug event listener vas invoked.
diff --git a/test/mjsunit/debug-clearbreakpointgroup.js b/test/mjsunit/debug-clearbreakpointgroup.js
index e6677f9..0cfc5c9 100644
--- a/test/mjsunit/debug-clearbreakpointgroup.js
+++ b/test/mjsunit/debug-clearbreakpointgroup.js
@@ -115,3 +115,8 @@
assertEquals([bp2, bp3, bp5].sort(), breakpointNumbers.sort());
assertFalse(exception, "exception in listener");
+
+// Clear all breakpoints to allow the test to run again (--stress-opt).
+Debug.clearBreakPoint(bp2);
+Debug.clearBreakPoint(bp3);
+Debug.clearBreakPoint(bp5);
diff --git a/test/mjsunit/debug-evaluate-with-context.js b/test/mjsunit/debug-evaluate-with-context.js
new file mode 100644
index 0000000..5e1c83c
--- /dev/null
+++ b/test/mjsunit/debug-evaluate-with-context.js
@@ -0,0 +1,144 @@
+// Copyright 2008 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.
+
+// Flags: --expose-debug-as debug
+// Get the Debug object exposed from the debug context global object.
+Debug = debug.Debug
+
+var evaluate_callback;
+
+function listener(event, exec_state, event_data, data) {
+ try {
+ var context = { what_is_capybara: "a fish" };
+ var context2 = { what_is_capybara: "a fish", what_is_parrot: "a beard" };
+
+ // Try in frame's scope.
+ var local_expression =
+ "(what_is_capybara ? what_is_capybara : 'a beast') + '/' + what_is_parrot";
+ var result = evaluate_callback.in_top_frame(exec_state, local_expression, context);
+ assertEquals('a fish/a bird', result);
+
+ // Try in frame's scope with overrididen local variables.
+ var result = evaluate_callback.in_top_frame(exec_state, local_expression, context2);
+ assertEquals('a fish/a beard', result);
+
+ // Try in frame's scope, without context.
+ var local_expression2 = "what_is_parrot";
+ var result = evaluate_callback.in_top_frame(exec_state, local_expression2, void 0);
+ assertEquals('a bird', result);
+
+ // Try in global additional scope.
+ var global_expression = "what_is_capybara ? what_is_capybara : 'a beast'";
+ var result = evaluate_callback.globally(exec_state, global_expression, context);
+ assertEquals('a fish', result);
+
+ // Try in global scope with overridden global variables.
+ var context_with_undefined = { undefined: 'kitten' };
+ var global_expression2 = "'cat' + '/' + undefined";
+ var result = evaluate_callback.globally(exec_state, global_expression2, context_with_undefined);
+ assertEquals('cat/kitten', result);
+
+ // Try in global scope with no overridden global variables.
+ var result = evaluate_callback.globally(exec_state, global_expression2, void 0);
+ assertEquals('cat/undefined', result);
+
+ // Try in global scope without additional context.
+ var global_expression3 = "'cat' + '/' + 'dog'";
+ var result = evaluate_callback.globally(exec_state, global_expression3, void 0);
+ assertEquals('cat/dog', result);
+
+ listenerComplete = true;
+ } catch (e) {
+ exception = e
+ };
+};
+
+
+function f() {
+ var what_is_parrot = "a bird";
+ debugger;
+};
+
+function runF() {
+ exception = false;
+ listenerComplete = false;
+
+ Debug.setListener(listener);
+
+ // Add the debug event listener.
+ Debug.setListener(listener);
+
+ f();
+
+ assertFalse(exception, "exception in listener")
+ assertTrue(listenerComplete);
+}
+
+evaluate_callback = {
+ in_top_frame: function(exec_state, expression, additional_context) {
+ return exec_state.frame(0).evaluate(expression, void 0, additional_context).value();
+ },
+ globally: function(exec_state, expression, additional_context) {
+ return exec_state.evaluateGlobal(expression, void 0, additional_context).value();
+ },
+};
+
+
+runF();
+
+// Now try all the same, but via debug protocol.
+
+function evaluateViaProtocol(exec_state, expression, additional_context, frame_argument_adder) {
+ var dcp = exec_state.debugCommandProcessor("unspecified_running_state");
+ request_json = {"seq":17,"type":"request","command":"evaluate", arguments: { "expression": expression } };
+ frame_argument_adder(request_json.arguments);
+ if (additional_context) {
+ var context_json = [];
+ for (var key in additional_context) {
+ context_json.push({ name: key, handle: Debug.MakeMirror(additional_context[key]).handle() });
+ }
+ request_json.arguments.additional_context = context_json;
+ }
+ var request = JSON.stringify(request_json);
+ var response_json = dcp.processDebugJSONRequest(request);
+ var response = JSON.parse(response_json);
+
+ assertTrue(response.success);
+ var str_result = response.body.value;
+ return str_result;
+}
+
+evaluate_callback = {
+ in_top_frame: function(exec_state, expression, additional_context) {
+ return evaluateViaProtocol(exec_state, expression, additional_context, function(args) { args.frame = 0; });
+ },
+ globally: function(exec_state, expression, additional_context) {
+ return evaluateViaProtocol(exec_state, expression, additional_context, function(args) { args.global = true; });
+ },
+};
+
+runF();
diff --git a/test/mjsunit/debug-liveedit-2.js b/test/mjsunit/debug-liveedit-2.js
index 94e2780..39ebf3a 100644
--- a/test/mjsunit/debug-liveedit-2.js
+++ b/test/mjsunit/debug-liveedit-2.js
@@ -31,17 +31,14 @@
Debug = debug.Debug
-
-eval(
- "function ChooseAnimal(p) {\n " +
- " if (p == 7) {\n" + // Use p
- " return;\n" +
- " }\n" +
- " return function Chooser() {\n" +
- " return 'Cat';\n" +
- " };\n" +
- "}\n"
-);
+eval("function ChooseAnimal(p) {\n " +
+ " if (p == 7) {\n" + // Use p
+ " return;\n" +
+ " }\n" +
+ " return function Chooser() {\n" +
+ " return 'Cat';\n" +
+ " };\n" +
+ "}\n");
var old_closure = ChooseAnimal(19);
@@ -67,4 +64,3 @@
// Old instance of closure is not patched.
assertEquals("Cat", old_closure());
-
diff --git a/test/mjsunit/debug-liveedit-breakpoints.js b/test/mjsunit/debug-liveedit-breakpoints.js
index f01a8c4..1d28ab9 100644
--- a/test/mjsunit/debug-liveedit-breakpoints.js
+++ b/test/mjsunit/debug-liveedit-breakpoints.js
@@ -62,6 +62,8 @@
var script = Debug.findScript(F25);
+assertEquals(0, Debug.scriptBreakPoints().length);
+
Debug.setScriptBreakPoint(Debug.ScriptBreakPointType.ScriptId, script.id, 1, 1, "true || false || false");
Debug.setScriptBreakPoint(Debug.ScriptBreakPointType.ScriptId, script.id, 6, 1, "true || false || false");
Debug.setScriptBreakPoint(Debug.ScriptBreakPointType.ScriptId, script.id, 14, 1, "true || false || false");
@@ -96,3 +98,16 @@
assertTrue(break_position_map[1]);
assertTrue(break_position_map[11]);
+// Delete all breakpoints to make this test reentrant.
+var breaks = Debug.scriptBreakPoints();
+var breaks_ids = [];
+
+for (var i = 0; i < breaks.length; i++) {
+ breaks_ids.push(breaks[i].number());
+}
+
+for (var i = 0; i < breaks_ids.length; i++) {
+ Debug.clearBreakPoint(breaks_ids[i]);
+}
+
+assertEquals(0, Debug.scriptBreakPoints().length);
diff --git a/test/mjsunit/debug-liveedit-patch-positions.js b/test/mjsunit/debug-liveedit-patch-positions.js
index 027987f..b0d3c20 100644
--- a/test/mjsunit/debug-liveedit-patch-positions.js
+++ b/test/mjsunit/debug-liveedit-patch-positions.js
@@ -30,7 +30,7 @@
// Scenario: some function is being edited; the outer function has to have its
// positions patched. Accoring to a special markup of function text
-// corresponding byte-code PCs should conicide before change and after it.
+// corresponding byte-code PCs should coincide before change and after it.
Debug = debug.Debug
@@ -62,32 +62,65 @@
function ReadPCMap(func, positions) {
var res = new Array();
for (var i = 0; i < positions.length; i++) {
- res.push(Debug.LiveEdit.GetPcFromSourcePos(func, positions[i]));
+ var pc = Debug.LiveEdit.GetPcFromSourcePos(func, positions[i]);
+
+ if (typeof pc === 'undefined') {
+ // Function was marked for recompilation and it's code was replaced with a
+ // stub. This can happen at any time especially if we are running with
+ // --stress-opt. There is no way to get PCs now.
+ return;
+ }
+
+ res.push(pc);
}
+
return res;
}
-var res = ChooseAnimal();
-assertEquals("Cat15", res);
+function ApplyPatch(orig_animal, new_animal) {
+ var res = ChooseAnimal();
+ assertEquals(orig_animal + "15", res);
-var markerPositionsBefore = ReadMarkerPositions(ChooseAnimal);
-var pcArrayBefore = ReadPCMap(ChooseAnimal, markerPositionsBefore);
+ var script = Debug.findScript(ChooseAnimal);
-var script = Debug.findScript(ChooseAnimal);
+ var orig_string = "'" + orig_animal + "'";
+ var patch_string = "'" + new_animal + "'";
+ var patch_pos = script.source.indexOf(orig_string);
-var orig_animal = "'Cat'";
-var patch_pos = script.source.indexOf(orig_animal);
-var new_animal_patch = "'Capybara'";
+ var change_log = new Array();
-var change_log = new Array();
-Debug.LiveEdit.TestApi.ApplySingleChunkPatch(script, patch_pos, orig_animal.length, new_animal_patch, change_log);
-print("Change log: " + JSON.stringify(change_log) + "\n");
+ Debug.LiveEdit.TestApi.ApplySingleChunkPatch(script,
+ patch_pos,
+ orig_string.length,
+ patch_string,
+ change_log);
-var res = ChooseAnimal();
-assertEquals("Capybara15", res);
+ print("Change log: " + JSON.stringify(change_log) + "\n");
-var markerPositionsAfter = ReadMarkerPositions(ChooseAnimal);
-var pcArrayAfter = ReadPCMap(ChooseAnimal, markerPositionsAfter);
+ var markerPositions = ReadMarkerPositions(ChooseAnimal);
+ var pcArray = ReadPCMap(ChooseAnimal, markerPositions);
-assertArrayEquals(pcArrayBefore, pcArrayAfter);
+ var res = ChooseAnimal();
+ assertEquals(new_animal + "15", res);
+ return pcArray;
+}
+
+var pcArray1 = ApplyPatch('Cat', 'Dog');
+
+// When we patched function for the first time it was deoptimized.
+// Check that after the second patch maping between sources position and
+// pcs will not change.
+
+var pcArray2 = ApplyPatch('Dog', 'Capybara');
+
+print(pcArray1);
+print(pcArray2);
+
+// Function can be marked for recompilation at any point (especially if we are
+// running with --stress-opt). When we mark function for recompilation we
+// replace it's code with stub. So there is no reliable way to get PCs for
+// function.
+if (pcArray1 && pcArray2) {
+ assertArrayEquals(pcArray1, pcArray2);
+}
diff --git a/test/mjsunit/debug-stepout-recursive-function.js b/test/mjsunit/debug-stepout-recursive-function.js
index 475fe26..3741f26 100644
--- a/test/mjsunit/debug-stepout-recursive-function.js
+++ b/test/mjsunit/debug-stepout-recursive-function.js
@@ -97,7 +97,7 @@
EndTest(2);
BeginTest('Test 4');
-shouldBreak = function(x) { print(x); return x == 1 || x == 3; };
+shouldBreak = function(x) { return x == 1 || x == 3; };
step_out_count = 2;
fact(3);
EndTest(3);
diff --git a/test/mjsunit/fuzz-natives.js b/test/mjsunit/fuzz-natives.js
index cf08d7a..020e3c0 100644
--- a/test/mjsunit/fuzz-natives.js
+++ b/test/mjsunit/fuzz-natives.js
@@ -144,6 +144,9 @@
"NewArgumentsFast": true,
"PushContext": true,
"LazyCompile": true,
+ "LazyRecompile": true,
+ "NotifyDeoptimized": true,
+ "NotifyOSR": true,
"CreateObjectLiteralBoilerplate": true,
"CloneLiteralBoilerplate": true,
"CloneShallowLiteralBoilerplate": true,
diff --git a/test/mjsunit/get-own-property-descriptor.js b/test/mjsunit/get-own-property-descriptor.js
index 79c1fac..ceb7715 100644
--- a/test/mjsunit/get-own-property-descriptor.js
+++ b/test/mjsunit/get-own-property-descriptor.js
@@ -103,19 +103,3 @@
objWithProto[0] = 'bar';
var descWithProto = Object.getOwnPropertyDescriptor(objWithProto, '10');
assertEquals(undefined, descWithProto);
-
-// Test elements on global proxy object.
-var global = (function() { return this; })();
-
-global[42] = 42;
-
-function el_getter() { return 239; };
-function el_setter() {};
-Object.defineProperty(global, '239', {get: el_getter, set: el_setter});
-
-var descRegularElement = Object.getOwnPropertyDescriptor(global, '42');
-assertEquals(42, descRegularElement.value);
-
-var descAccessorElement = Object.getOwnPropertyDescriptor(global, '239');
-assertEquals(el_getter, descAccessorElement.get);
-assertEquals(el_setter, descAccessorElement.set);
diff --git a/test/mjsunit/json.js b/test/mjsunit/json.js
index 5353d6c..a0be8dd 100644
--- a/test/mjsunit/json.js
+++ b/test/mjsunit/json.js
@@ -25,45 +25,6 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-function GenericToJSONChecks(Constructor, value, alternative) {
- var n1 = new Constructor(value);
- n1.valueOf = function () { return alternative; };
- assertEquals(alternative, n1.toJSON());
- var n2 = new Constructor(value);
- n2.valueOf = null;
- assertThrows(function () { n2.toJSON(); }, TypeError);
- var n3 = new Constructor(value);
- n3.valueOf = function () { return {}; };
- assertThrows(function () { n3.toJSON(); }, TypeError, 'result_not_primitive');
- var n4 = new Constructor(value);
- n4.valueOf = function () {
- assertEquals(0, arguments.length);
- assertEquals(this, n4);
- return null;
- };
- assertEquals(null, n4.toJSON());
-}
-
-// Number toJSON
-assertEquals(3, (3).toJSON());
-assertEquals(3, (3).toJSON(true));
-assertEquals(4, (new Number(4)).toJSON());
-GenericToJSONChecks(Number, 5, 6);
-
-// Boolean toJSON
-assertEquals(true, (true).toJSON());
-assertEquals(true, (true).toJSON(false));
-assertEquals(false, (false).toJSON());
-assertEquals(true, (new Boolean(true)).toJSON());
-GenericToJSONChecks(Boolean, true, false);
-GenericToJSONChecks(Boolean, false, true);
-
-// String toJSON
-assertEquals("flot", "flot".toJSON());
-assertEquals("flot", "flot".toJSON(3));
-assertEquals("tolf", (new String("tolf")).toJSON());
-GenericToJSONChecks(String, "x", "y");
-
// Date toJSON
assertEquals("1970-01-01T00:00:00.000Z", new Date(0).toJSON());
assertEquals("1979-01-11T08:00:00.000Z", new Date("1979-01-11 08:00 GMT").toJSON());
@@ -74,9 +35,6 @@
var n2 = new Date(10001);
n2.toISOString = null;
assertThrows(function () { n2.toJSON(); }, TypeError);
-var n3 = new Date(10002);
-n3.toISOString = function () { return {}; };
-assertThrows(function () { n3.toJSON(); }, TypeError, "result_not_primitive");
var n4 = new Date(10003);
n4.toISOString = function () {
assertEquals(0, arguments.length);
@@ -88,9 +46,47 @@
assertTrue(Object.prototype === JSON.__proto__);
assertEquals("[object JSON]", Object.prototype.toString.call(JSON));
+//Test Date.prototype.toJSON as generic function.
+var d1 = {toJSON: Date.prototype.toJSON,
+ toISOString: function() { return 42; }};
+assertEquals(42, d1.toJSON());
+
+var d2 = {toJSON: Date.prototype.toJSON,
+ valueOf: function() { return Infinity; },
+ toISOString: function() { return 42; }};
+assertEquals(null, d2.toJSON());
+
+var d3 = {toJSON: Date.prototype.toJSON,
+ valueOf: "not callable",
+ toString: function() { return Infinity; },
+ toISOString: function() { return 42; }};
+
+assertEquals(null, d3.toJSON());
+
+var d4 = {toJSON: Date.prototype.toJSON,
+ valueOf: "not callable",
+ toString: "not callable either",
+ toISOString: function() { return 42; }};
+assertThrows("d4.toJSON()", TypeError); // ToPrimitive throws.
+
+var d5 = {toJSON: Date.prototype.toJSON,
+ valueOf: "not callable",
+ toString: function() { return "Infinity"; },
+ toISOString: function() { return 42; }};
+assertEquals(42, d5.toJSON());
+
+var d6 = {toJSON: Date.prototype.toJSON,
+ toISOString: function() { return ["not primitive"]; }};
+assertEquals(["not primitive"], d6.toJSON());
+
+var d7 = {toJSON: Date.prototype.toJSON,
+ ISOString: "not callable"};
+assertThrows("d7.toJSON()", TypeError);
+
// DontEnum
-for (var p in this)
+for (var p in this) {
assertFalse(p == "JSON");
+}
// Parse
assertEquals({}, JSON.parse("{}"));
@@ -278,9 +274,15 @@
JSON.stringify({a:"b",c:"d"}, null, 1));
assertEquals('{"y":6,"x":5}', JSON.stringify({x:5,y:6}, ['y', 'x']));
+// toJSON get string keys.
+var checker = {};
+var array = [checker];
+checker.toJSON = function(key) { return 1 + key; };
+assertEquals('["10"]', JSON.stringify(array));
+
// The gap is capped at ten characters if specified as string.
assertEquals('{\n "a": "b",\n "c": "d"\n}',
- JSON.stringify({a:"b",c:"d"}, null,
+ JSON.stringify({a:"b",c:"d"}, null,
" /*characters after 10th*/"));
//The gap is capped at ten characters if specified as number.
@@ -295,16 +297,16 @@
assertEquals(undefined, JSON.stringify(undefined));
assertEquals(undefined, JSON.stringify(function () { }));
-// Arrays with missing, undefined or function elements have those elements
+// Arrays with missing, undefined or function elements have those elements
// replaced by null.
-assertEquals("[null,null,null]",
+assertEquals("[null,null,null]",
JSON.stringify([undefined,,function(){}]));
// Objects with undefined or function properties (including replaced properties)
// have those properties ignored.
-assertEquals('{}',
+assertEquals('{}',
JSON.stringify({a: undefined, b: function(){}, c: 42, d: 42},
- function(k, v) { if (k == "c") return undefined;
+ function(k, v) { if (k == "c") return undefined;
if (k == "d") return function(){};
return v; }));
@@ -328,7 +330,7 @@
// Step 2.a
expected = '\\' + string;
} else if ("\b\t\n\r\f".indexOf(string) >= 0) {
- // Step 2.b
+ // Step 2.b
if (string == '\b') expected = '\\b';
else if (string == '\t') expected = '\\t';
else if (string == '\n') expected = '\\n';
@@ -343,6 +345,73 @@
}
} else {
expected = string;
- }
+ }
assertEquals('"' + expected + '"', encoded, "Codepoint " + i);
-}
+}
+
+
+// Ensure that wrappers and callables are handled correctly.
+var num37 = new Number(42);
+num37.valueOf = function() { return 37; };
+
+var numFoo = new Number(42);
+numFoo.valueOf = "not callable";
+numFoo.toString = function() { return "foo"; };
+
+var numTrue = new Number(42);
+numTrue.valueOf = function() { return true; }
+
+var strFoo = new String("bar");
+strFoo.toString = function() { return "foo"; };
+
+var str37 = new String("bar");
+str37.toString = "not callable";
+str37.valueOf = function() { return 37; };
+
+var strTrue = new String("bar");
+strTrue.toString = function() { return true; }
+
+var func = function() { /* Is callable */ };
+
+var funcJSON = function() { /* Is callable */ };
+funcJSON.toJSON = function() { return "has toJSON"; };
+
+var re = /Is callable/;
+
+var reJSON = /Is callable/;
+reJSON.toJSON = function() { return "has toJSON"; };
+
+assertEquals(
+ '[37,null,1,"foo","37","true",null,"has toJSON",null,"has toJSON"]',
+ JSON.stringify([num37, numFoo, numTrue,
+ strFoo, str37, strTrue,
+ func, funcJSON, re, reJSON]));
+
+
+var oddball = Object(42);
+oddball.__proto__ = { __proto__: null, toString: function() { return true; } };
+assertEquals('1', JSON.stringify(oddball));
+
+var getCount = 0;
+var callCount = 0;
+var counter = { get toJSON() { getCount++;
+ return function() { callCount++;
+ return 42; }; } };
+assertEquals('42', JSON.stringify(counter));
+assertEquals(1, getCount);
+assertEquals(1, callCount);
+
+var oddball2 = Object(42);
+var oddball3 = Object("foo");
+oddball3.__proto__ = { __proto__: null,
+ toString: "not callable",
+ valueOf: function() { return true; } };
+oddball2.__proto__ = { __proto__: null,
+ toJSON: function () { return oddball3; } }
+assertEquals('"true"', JSON.stringify(oddball2));
+
+
+var falseNum = Object("37");
+falseNum.__proto__ = Number.prototype;
+falseNum.toString = function() { return 42; };
+assertEquals('"42"', JSON.stringify(falseNum));
diff --git a/test/mjsunit/mirror-object.js b/test/mjsunit/mirror-object.js
index ad7add8..1888554 100644
--- a/test/mjsunit/mirror-object.js
+++ b/test/mjsunit/mirror-object.js
@@ -74,7 +74,7 @@
assertEquals('property', properties[i].type(), 'Unexpected mirror type');
assertEquals(names[i], properties[i].name(), 'Unexpected property name');
}
-
+
for (var p in obj) {
var property_mirror = mirror.property(p);
assertTrue(property_mirror instanceof debug.PropertyMirror);
diff --git a/test/mjsunit/mjsunit.status b/test/mjsunit/mjsunit.status
index 820dca7..eeeb3dc 100644
--- a/test/mjsunit/mjsunit.status
+++ b/test/mjsunit/mjsunit.status
@@ -30,6 +30,14 @@
# All tests in the bug directory are expected to fail.
bugs: FAIL
+
+##############################################################################
+# Too slow in debug mode with --stress-opt
+compiler/regress-stacktrace-methods: PASS, SKIP if $mode == debug
+compiler/regress-funcaller: PASS, SKIP if $mode == debug
+regress/regress-create-exception: PASS, SKIP if $mode == debug
+
+##############################################################################
# This one uses a built-in that's only present in debug mode. It takes
# too long to run in debug mode on ARM.
fuzz-natives: PASS, SKIP if ($mode == release || $arch == arm)
@@ -49,6 +57,8 @@
debug-liveedit-check-stack: SKIP
debug-liveedit-patch-positions-replace: SKIP
+
+##############################################################################
[ $arch == arm ]
# Slow tests which times out in debug mode.
@@ -60,15 +70,51 @@
unicode-test: PASS, (PASS || FAIL) if $mode == debug
# Times out often in release mode on ARM.
+compiler/regress-stacktrace-methods: PASS, PASS || TIMEOUT if $mode == release
array-splice: PASS || TIMEOUT
-# Skip long running test in debug mode on ARM.
-string-indexof-2: PASS, SKIP if $mode == debug
+# Long running test.
+mirror-object: PASS || TIMEOUT
+string-indexof-2: PASS || TIMEOUT
+
+# BUG(3251035): Timeouts in long looping crankshaft optimization
+# tests. Skipping because having them timeout takes too long on the
+# buildbot.
+compiler/alloc-number: SKIP
+compiler/array-length: SKIP
+compiler/assignment-deopt: SKIP
+compiler/deopt-args: SKIP
+compiler/inline-compare: SKIP
+compiler/inline-global-access: SKIP
+compiler/optimized-function-calls: SKIP
+compiler/pic: SKIP
+compiler/property-calls: SKIP
+compiler/recursive-deopt: SKIP
+compiler/regress-4: SKIP
+compiler/regress-funcaller: SKIP
+compiler/regress-gvn: SKIP
+compiler/regress-rep-change: SKIP
+compiler/regress-arguments: SKIP
+compiler/regress-funarguments: SKIP
+compiler/regress-or: SKIP
+compiler/regress-3249650: SKIP
+compiler/simple-deopt: SKIP
+regress/regress-490: SKIP
+regress/regress-634: SKIP
+regress/regress-create-exception: SKIP
+regress/regress-3218915: SKIP
+regress/regress-3247124: SKIP
+##############################################################################
+[ $arch == arm && $crankshaft ]
+
+# Test that currently fail with crankshaft on ARM.
+compiler/simple-osr: FAIL
+
+
+##############################################################################
[ $arch == mips ]
# Skip all tests on MIPS.
*: SKIP
-
-
diff --git a/test/mjsunit/object-define-property.js b/test/mjsunit/object-define-property.js
index b258aa7..d24a4e5 100644
--- a/test/mjsunit/object-define-property.js
+++ b/test/mjsunit/object-define-property.js
@@ -74,7 +74,7 @@
// Descriptors.
var emptyDesc = {};
-var accessorConfigurable = {
+var accessorConfigurable = {
set: setter1,
get: getter1,
configurable: true
@@ -83,7 +83,7 @@
var accessorNoConfigurable = {
set: setter2,
get: getter2,
- configurable: false
+ configurable: false
};
var accessorOnlySet = {
@@ -234,7 +234,7 @@
assertEquals(1, obj1.setOnly = 1);
assertEquals(2, val3);
-// The above should also work if redefining just a getter or setter on
+// The above should also work if redefining just a getter or setter on
// an existing property with both a getter and a setter.
Object.defineProperty(obj1, "both", accessorConfigurable);
@@ -384,7 +384,7 @@
assertEquals(desc.set, undefined);
-// Redefinition of an accessor defined using __defineGetter__ and
+// Redefinition of an accessor defined using __defineGetter__ and
// __defineSetter__.
function get(){return this.x}
function set(x){this.x=x};
@@ -462,7 +462,7 @@
// Test runtime calls to DefineOrRedefineDataProperty and
-// DefineOrRedefineAccessorProperty - make sure we don't
+// DefineOrRedefineAccessorProperty - make sure we don't
// crash.
try {
%DefineOrRedefineAccessorProperty(0, 0, 0, 0, 0);
@@ -511,7 +511,7 @@
// Test that all possible differences in step 6 in DefineOwnProperty are
// exercised, i.e., any difference in the given property descriptor and the
// existing properties should not return true, but throw an error if the
-// existing configurable property is false.
+// existing configurable property is false.
var obj5 = {};
// Enumerable will default to false.
@@ -727,7 +727,7 @@
var descElementNonConfigurable = { value: 'barfoo', configurable: false };
var descElementNonWritable = { value: 'foofoo', writable: false };
var descElementNonEnumerable = { value: 'barbar', enumerable: false };
-var descElementAllFalse = { value: 'foofalse',
+var descElementAllFalse = { value: 'foofalse',
configurable: false,
writable: false,
enumerable: false };
@@ -790,7 +790,7 @@
// Make sure that we can't redefine using direct access.
obj6[15] ='overwrite';
-assertEquals(obj6[15],'foobar');
+assertEquals(obj6[15],'foobar');
// Repeat the above tests on an array.
@@ -805,7 +805,7 @@
var descElementNonConfigurable = { value: 'barfoo', configurable: false };
var descElementNonWritable = { value: 'foofoo', writable: false };
var descElementNonEnumerable = { value: 'barbar', enumerable: false };
-var descElementAllFalse = { value: 'foofalse',
+var descElementAllFalse = { value: 'foofalse',
configurable: false,
writable: false,
enumerable: false };
@@ -866,4 +866,35 @@
assertFalse(desc.enumerable);
assertFalse(desc.configurable);
+// See issue 968: http://code.google.com/p/v8/issues/detail?id=968
+var o = { x : 42 };
+Object.defineProperty(o, "x", { writable: false });
+assertEquals(42, o.x);
+o.x = 37;
+assertEquals(42, o.x);
+o = { x : 42 };
+Object.defineProperty(o, "x", {});
+assertEquals(42, o.x);
+o.x = 37;
+// Writability is preserved.
+assertEquals(37, o.x);
+
+var o = { };
+Object.defineProperty(o, "x", { writable: false });
+assertEquals(undefined, o.x);
+o.x = 37;
+assertEquals(undefined, o.x);
+
+o = { get x() { return 87; } };
+Object.defineProperty(o, "x", { writable: false });
+assertEquals(undefined, o.x);
+o.x = 37;
+assertEquals(undefined, o.x);
+
+// Ignore inherited properties.
+o = { __proto__ : { x : 87 } };
+Object.defineProperty(o, "x", { writable: false });
+assertEquals(undefined, o.x);
+o.x = 37;
+assertEquals(undefined, o.x);
diff --git a/test/mjsunit/object-toprimitive.js b/test/mjsunit/object-toprimitive.js
new file mode 100644
index 0000000..3a67ced
--- /dev/null
+++ b/test/mjsunit/object-toprimitive.js
@@ -0,0 +1,104 @@
+// Copyright 2010 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.
+
+// Test the ToPrimitive internal function used by ToNumber/ToString.
+// Does it [[Get]] and [[Call]] the object's toString and valueOf properties
+// correctly. Specifically, does it call [[Get]] only once per property.
+
+var o1 = { toString: function() { return 42; },
+ valueOf: function() { return "37"; } };
+var n1 = Number(o1);
+var s1 = String(o1);
+assertTrue(typeof n1 == "number");
+assertTrue(typeof s1 == "string");
+
+var trace = [];
+var valueOfValue = 42;
+var toStringValue = "foo";
+function traceValueOf () {
+ trace.push("vo");
+ return valueOfValue;
+};
+function traceToString() {
+ trace.push("ts");
+ return toStringValue;
+};
+var valueOfFunc = traceValueOf;
+var toStringFunc = traceToString;
+
+var ot = { get toString() { trace.push("gts");
+ return toStringFunc; },
+ get valueOf() { trace.push("gvo");
+ return valueOfFunc; }
+};
+
+var nt = Number(ot);
+assertEquals(42, nt);
+assertEquals(["gvo","vo"], trace);
+
+trace = [];
+var st = String(ot);
+assertEquals("foo", st);
+assertEquals(["gts","ts"], trace);
+
+trace = [];
+valueOfValue = ["not primitive"];
+var nt = Number(ot);
+assertEquals(Number("foo"), nt);
+assertEquals(["gvo", "vo", "gts", "ts"], trace);
+
+trace = [];
+valueOfValue = 42;
+toStringValue = ["not primitive"];
+var st = String(ot);
+assertEquals(String(42), st);
+assertEquals(["gts", "ts", "gvo", "vo"], trace);
+
+trace = [];
+valueOfValue = ["not primitive"];
+assertThrows("Number(ot)", TypeError);
+assertEquals(["gvo", "vo", "gts", "ts"], trace);
+
+
+toStringFunc = "not callable";
+trace = [];
+valueOfValue = 42;
+var st = String(ot);
+assertEquals(String(42), st);
+assertEquals(["gts", "gvo", "vo"], trace);
+
+valueOfFunc = "not callable";
+trace = [];
+assertThrows("String(ot)", TypeError);
+assertEquals(["gts", "gvo"], trace);
+
+toStringFunc = traceToString;
+toStringValue = "87";
+trace = [];
+var nt = Number(ot);
+assertEquals(87, nt);
+assertEquals(["gvo", "gts", "ts"], trace);
diff --git a/test/mjsunit/regexp.js b/test/mjsunit/regexp.js
index b57b86d..4c1d2e3 100644
--- a/test/mjsunit/regexp.js
+++ b/test/mjsunit/regexp.js
@@ -202,6 +202,17 @@
assertFalse(re.test('a'));
assertFalse(re.test('Z'));
+// First - is treated as range operator, second as literal minus.
+// This follows the specification in parsing, but doesn't throw on
+// the \s at the beginning of the range.
+re = /[\s-0-9]/;
+assertTrue(re.test(' '));
+assertTrue(re.test('\xA0'));
+assertTrue(re.test('-'));
+assertTrue(re.test('0'));
+assertTrue(re.test('9'));
+assertFalse(re.test('1'));
+
// Test beginning and end of line assertions with or without the
// multiline flag.
re = /^\d+/;
@@ -647,3 +658,4 @@
assertEquals(["bc"], re.exec("zimzomzumbc"));
assertFalse(re.test("c"));
assertFalse(re.test(""));
+
diff --git a/test/mjsunit/regress/regress-3408144.js b/test/mjsunit/regress/regress-3006390.js
similarity index 87%
rename from test/mjsunit/regress/regress-3408144.js
rename to test/mjsunit/regress/regress-3006390.js
index 6e292d6..4f916ef 100644
--- a/test/mjsunit/regress/regress-3408144.js
+++ b/test/mjsunit/regress/regress-3006390.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,13 +25,9 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test incorrect code generation for alternations on ARM.
+function X() { }
+X.prototype.valueOf = function () { return 7; }
+function f(x, y) { return x % y; }
-// Flags: --nofull-compiler
-
-function foo() {
- return (0 > ("10"||10) - 1);
-}
-
-assertFalse(foo());
+assertEquals(1, f(8, new X()));
diff --git a/test/mjsunit/regress/regress-1146.js b/test/mjsunit/regress/regress-3185905.js
similarity index 74%
copy from test/mjsunit/regress/regress-1146.js
copy to test/mjsunit/regress/regress-3185905.js
index e8028ce..bd611ab 100644
--- a/test/mjsunit/regress/regress-1146.js
+++ b/test/mjsunit/regress/regress-3185905.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,24 +25,36 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test keyed calls with different key types.
-function F() {}
-var a = new F();
-function f(i) { return a[i](); }
+function test1(x) {
+ var a = arguments.callee;
+ x = 1;
+ x = 2;
+ assertEquals(2, x);
+}
+test1(0)
-a.first = function() { return 11; }
-a[0] = function() { return 22; }
-var obj = {};
-a[obj] = function() { return 33; }
+function test2(x) {
+ var a = arguments.callee;
+ x++;
+ x++;
+ assertEquals(2, x);
+}
+test2(0)
-// Make object slow-case.
-a.foo = 0;
-delete a.foo;
-// Do multiple calls for IC transitions.
-var b = "first";
-f(b);
-f(b);
+function test3(x) {
+ var a = arguments.callee;
+ x += 1;
+ x += 1;
+ assertEquals(2, x);
+}
+test3(0)
-assertEquals(11, f(b));
-assertEquals(22, f(0));
-assertEquals(33, f(obj));
+function test4(x) {
+ var arguments = { 0 : 3, 'x' : 4 };
+ x += 1;
+ x += 1;
+ assertEquals(2, x);
+ assertEquals(3, arguments[0])
+ assertEquals(4, arguments['x'])
+}
+test4(0)
diff --git a/test/mjsunit/regress/regress-3408144.js b/test/mjsunit/regress/regress-3199913.js
similarity index 77%
copy from test/mjsunit/regress/regress-3408144.js
copy to test/mjsunit/regress/regress-3199913.js
index 6e292d6..e202af1 100644
--- a/test/mjsunit/regress/regress-3408144.js
+++ b/test/mjsunit/regress/regress-3199913.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,13 +25,20 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test incorrect code generation for alternations on ARM.
+// Test that bailout during evaluation of the key for a keyed call works as
+// intended.
-
-// Flags: --nofull-compiler
-
-function foo() {
- return (0 > ("10"||10) - 1);
+var y = {
+ 'a' : function (x, y) { return 'called a(' + x + ', ' + y + ')' },
+ 'b' : function (x, y) { return 'called b(' + x + ', ' + y + ')' }
}
-assertFalse(foo());
+function C() {
+}
+
+C.prototype.f = function () {
+ return y[(this.a == 1 ? "a" : "b")](0, 1);
+}
+
+obj = new C()
+assertEquals('called b(0, 1)', obj.f())
diff --git a/test/mjsunit/regress/regress-3408144.js b/test/mjsunit/regress/regress-3218530.js
similarity index 81%
copy from test/mjsunit/regress/regress-3408144.js
copy to test/mjsunit/regress/regress-3218530.js
index 6e292d6..247f3df 100644
--- a/test/mjsunit/regress/regress-3408144.js
+++ b/test/mjsunit/regress/regress-3218530.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,13 +25,15 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test incorrect code generation for alternations on ARM.
+// This tests that a global key values are preserved when used in
+// an expression which will bail out.
+var m = Math;
+var p = "floor";
-// Flags: --nofull-compiler
-
-function foo() {
- return (0 > ("10"||10) - 1);
+function test() {
+ var bignumber = 31363200000;
+ assertDoesNotThrow(assertEquals(m[p](Math.round(bignumber/864E5)/7)+1, 52));
}
-assertFalse(foo());
+test();
diff --git a/test/mjsunit/regress/regress-3408144.js b/test/mjsunit/regress/regress-3218915.js
similarity index 76%
copy from test/mjsunit/regress/regress-3408144.js
copy to test/mjsunit/regress/regress-3218915.js
index 6e292d6..5fcbcec 100644
--- a/test/mjsunit/regress/regress-3408144.js
+++ b/test/mjsunit/regress/regress-3218915.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,13 +25,18 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test incorrect code generation for alternations on ARM.
+// Checks that comma expression in conditional context is processed correctly.
-
-// Flags: --nofull-compiler
-
-function foo() {
- return (0 > ("10"||10) - 1);
+function withCommaExpressionInConditional(x) {
+ if (x > 1000) { for (var i = 0; i < 10000; i++) { } }
+ var y;
+ if (y = x, y > 1) {
+ return 'big';
+ }
+ return (y = x + 1, y > 1) ? 'medium' : 'small';
}
-assertFalse(foo());
+for (var i = 0; i < 10000; i++) {
+ withCommaExpressionInConditional(i);
+}
+withCommaExpressionInConditional("1")
diff --git a/test/mjsunit/regress/regress-3408144.js b/test/mjsunit/regress/regress-3230771.js
similarity index 85%
copy from test/mjsunit/regress/regress-3408144.js
copy to test/mjsunit/regress/regress-3230771.js
index 6e292d6..bd00798 100644
--- a/test/mjsunit/regress/regress-3408144.js
+++ b/test/mjsunit/regress/regress-3230771.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,13 +25,11 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test incorrect code generation for alternations on ARM.
+// Regression test for missing stack-overflow check in
+// VisitForStatement in hydrogen graph building.
-
-// Flags: --nofull-compiler
-
-function foo() {
- return (0 > ("10"||10) - 1);
+function f() {
+ for (var h = typeof arguments[0] == "object" ? 0 : arguments; false; ) { }
}
-assertFalse(foo());
+f();
diff --git a/test/mjsunit/regress/regress-3408144.js b/test/mjsunit/regress/regress-3247124.js
similarity index 70%
copy from test/mjsunit/regress/regress-3408144.js
copy to test/mjsunit/regress/regress-3247124.js
index 6e292d6..fe4ec4e 100644
--- a/test/mjsunit/regress/regress-3408144.js
+++ b/test/mjsunit/regress/regress-3247124.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,13 +25,29 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test incorrect code generation for alternations on ARM.
+var foo = unescape("%E0%E2%EA%F4%FB%E3%F5%E1%E9%ED%F3%FA%E7%FC%C0%C2%CA%D4%DB%C3%D5%C1%C9%CD%D3%DA%C7%DC");
+function bar(x) {
+ var s = new String(x);
+ var a = new String(foo);
+ var b = new String('aaeouaoaeioucuAAEOUAOAEIOUCU');
-// Flags: --nofull-compiler
+ var i = new Number();
+ var j = new Number();
+ var c = new String();
+ var r = '';
-function foo() {
- return (0 > ("10"||10) - 1);
+ for (i = 0; i < s.length; i++) {
+ c = s.substring(i, i + 1);
+ for (j = 0; j < a.length; j++) {
+ if (a.substring(j, j + 1) == c) {
+ c = b.substring(j, j + 1);
+ }
+ }
+ r += c;
+ }
+
+ return r.toLowerCase();
}
-assertFalse(foo());
+for (var i = 0; i < 100; i++) bar(foo);
diff --git a/test/mjsunit/regress/regress-1146.js b/test/mjsunit/regress/regress-3252443.js
similarity index 67%
copy from test/mjsunit/regress/regress-1146.js
copy to test/mjsunit/regress/regress-3252443.js
index e8028ce..cd7aa40 100644
--- a/test/mjsunit/regress/regress-1146.js
+++ b/test/mjsunit/regress/regress-3252443.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,24 +25,21 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test keyed calls with different key types.
-function F() {}
-var a = new F();
-function f(i) { return a[i](); }
+var document = new Object();
+document.getElementById = function(s) { return { style: {}}};
+function x(p0, p1, p2, p3) {
+ document.getElementById(p1+p0).style.display='';
+ document.getElementById(p1+''+p0).style.backgroundColor = "";
+ document.getElementById(p1+''+p0).style.color="";
+ document.getElementById(p1+''+p0).style.borderBottomColor = "";
+ for (var i = p3; i <= p2; ++i) {
+ if (i != p0) {
+ document.getElementById(p1+i).style.display='';
+ document.getElementById(p1+''+i).style.backgroundColor = "";
+ document.getElementById(p1+''+i).style.color="";
+ document.getElementById(p1+''+i).style.borderBottomColor = "";
+ }
+ }
+}
-a.first = function() { return 11; }
-a[0] = function() { return 22; }
-var obj = {};
-a[obj] = function() { return 33; }
-
-// Make object slow-case.
-a.foo = 0;
-delete a.foo;
-// Do multiple calls for IC transitions.
-var b = "first";
-f(b);
-f(b);
-
-assertEquals(11, f(b));
-assertEquals(22, f(0));
-assertEquals(33, f(obj));
+x(1, "xxx", 10000, 1)
diff --git a/test/mjsunit/regress/regress-52801.js b/test/mjsunit/regress/regress-52801.js
index 80cc0c7..9a34b81 100644
--- a/test/mjsunit/regress/regress-52801.js
+++ b/test/mjsunit/regress/regress-52801.js
@@ -67,5 +67,3 @@
re.lastIndex = 0;
re.exec(str);
assertEquals(5, re.lastIndex); // Fails if caching.
-
-
diff --git a/test/mjsunit/regress/regress-580.js b/test/mjsunit/regress/regress-580.js
index c6b3db7..6b1d098 100644
--- a/test/mjsunit/regress/regress-580.js
+++ b/test/mjsunit/regress/regress-580.js
@@ -32,22 +32,22 @@
var x;
var tmp = 0;
x = (tmp = 1578221999, tmp)+(tmp = 572285336, tmp);
- assertEquals(2150507335, x);
+ assertEquals(2150507335, x, "++");
x = 1578221999 + 572285336;
assertEquals(2150507335, x);
x = (tmp = -1500000000, tmp)+(tmp = -2000000000, tmp);
- assertEquals(-3500000000, x);
+ assertEquals(-3500000000, x, "+-");
x = -1500000000 + -2000000000;
assertEquals(-3500000000, x);
x = (tmp = 1578221999, tmp)-(tmp = -572285336, tmp);
- assertEquals(2150507335, x);
+ assertEquals(2150507335, x, "--");
x = 1578221999 - -572285336;
assertEquals(2150507335, x);
x = (tmp = -1500000000, tmp)-(tmp = 2000000000, tmp);
- assertEquals(-3500000000, x);
+ assertEquals(-3500000000, x, "-+");
x = -1500000000 - 2000000000;
assertEquals(-3500000000, x);
}
diff --git a/test/mjsunit/regress/regress-687.js b/test/mjsunit/regress/regress-687.js
new file mode 100644
index 0000000..a917a44
--- /dev/null
+++ b/test/mjsunit/regress/regress-687.js
@@ -0,0 +1,75 @@
+// Copyright 2009 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.
+
+// This regression includes a number of cases where we did not correctly
+// update a accessor property to a data property using Object.defineProperty.
+
+var obj = { get value() {}, set value (v) { throw "Error";} };
+assertDoesNotThrow(
+ Object.defineProperty(obj, "value",
+ { value: 5, writable:true, configurable: true }));
+var desc = Object.getOwnPropertyDescriptor(obj, "value");
+assertEquals(obj.value, 5);
+assertTrue(desc.configurable);
+assertTrue(desc.enumerable);
+assertTrue(desc.writable);
+assertEquals(desc.get, undefined);
+assertEquals(desc.set, undefined);
+
+
+var proto = {
+ get value() {},
+ set value(v) { Object.defineProperty(this, "value", {value: v}); }
+};
+
+var create = Object.create(proto);
+
+assertEquals(create.value, undefined);
+assertDoesNotThrow(create.value = 4);
+assertEquals(create.value, 4);
+
+// These tests where provided in bug 959, but are all related to the this issue.
+var obj1 = {};
+Object.defineProperty(obj1, 'p', {get: undefined, set: undefined});
+assertTrue("p" in obj1);
+desc = Object.getOwnPropertyDescriptor(obj1, "p");
+assertFalse(desc.configurable);
+assertFalse(desc.enumerable);
+assertEquals(desc.value, undefined);
+assertEquals(desc.get, undefined);
+assertEquals(desc.set, undefined);
+
+
+var obj2 = { get p() {}};
+Object.defineProperty(obj2, 'p', {get: undefined})
+assertTrue("p" in obj2);
+desc = Object.getOwnPropertyDescriptor(obj2, "p");
+assertTrue(desc.configurable);
+assertTrue(desc.enumerable);
+assertEquals(desc.value, undefined);
+assertEquals(desc.get, undefined);
+assertEquals(desc.set, undefined);
diff --git a/test/mjsunit/regress/regress-1146.js b/test/mjsunit/regress/regress-962.js
similarity index 74%
copy from test/mjsunit/regress/regress-1146.js
copy to test/mjsunit/regress/regress-962.js
index e8028ce..f9f46e1 100644
--- a/test/mjsunit/regress/regress-1146.js
+++ b/test/mjsunit/regress/regress-962.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,24 +25,29 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test keyed calls with different key types.
-function F() {}
-var a = new F();
-function f(i) { return a[i](); }
+function L(scope) { this.s = new Object(); }
-a.first = function() { return 11; }
-a[0] = function() { return 22; }
-var obj = {};
-a[obj] = function() { return 33; }
+L.prototype.c = function() { return true; }
-// Make object slow-case.
-a.foo = 0;
-delete a.foo;
-// Do multiple calls for IC transitions.
-var b = "first";
-f(b);
-f(b);
+function F() {
+ this.l = [new L, new L];
+}
-assertEquals(11, f(b));
-assertEquals(22, f(0));
-assertEquals(33, f(obj));
+F.prototype.foo = function () {
+ var f, d = arguments,
+ e, b = this.l,
+ g;
+ for (e = 0; e < b.length; e++) {
+ g = b[e];
+ f = g.c.apply(g.s, d);
+ if (f === false) {
+ break
+ }
+ }
+ return f
+}
+
+
+var ctx = new F;
+
+for (var i = 0; i < 10000; i++) ctx.foo();
diff --git a/test/mjsunit/regress/regress-969.js b/test/mjsunit/regress/regress-969.js
new file mode 100644
index 0000000..c2ba0ac
--- /dev/null
+++ b/test/mjsunit/regress/regress-969.js
@@ -0,0 +1,127 @@
+// Copyright 2010 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.
+
+// Regression test for bugs when deoptimizing after assignments in effect
+// contexts.
+
+// Bug 989 is that there was an extra value on the expression stack when
+// deoptimizing after an assignment in effect context (the value of the
+// assignment was lingering). This is hard to observe in the unoptimized
+// code.
+//
+// This test uses comma expressions to put assignments in effect contexts,
+// references to deleted global variables to force deoptimization, and
+// function calls to observe an extra value.
+
+function first(x, y) { return x; }
+var y = 0;
+var o = {};
+o.x = 0;
+o[0] = 0;
+
+// Assignment to global variable.
+x0 = 0;
+function test0() { return first((y = 1, typeof x0), 2); }
+// Call the function once to compile it.
+assertEquals('number', test0());
+// Delete to force deoptimization on the next call.
+delete x0;
+assertEquals('undefined', test0());
+
+// Compound assignment to global variable.
+x1 = 0;
+function test1() { return first((y += 1, typeof x1), 2); }
+assertEquals('number', test1(), 'test1 before');
+delete x1;
+assertEquals('undefined', test1(), 'test1 after');
+
+// Pre and post-increment of global variable.
+x2 = 0;
+function test2() { return first((++y, typeof x2), 2); }
+assertEquals('number', test2(), 'test2 before');
+delete x2;
+assertEquals('undefined', test2(), 'test2 after');
+
+x3 = 0;
+function test3() { return first((y++, typeof x3), 2); }
+assertEquals('number', test3(), 'test3 before');
+delete x3;
+assertEquals('undefined', test3(), 'test3 after');
+
+
+// Assignment, compound assignment, and pre and post-increment of named
+// properties.
+x4 = 0;
+function test4() { return first((o.x = 1, typeof x4), 2); }
+assertEquals('number', test4());
+delete x4;
+assertEquals('undefined', test4());
+
+x5 = 0;
+function test5() { return first((o.x += 1, typeof x5), 2); }
+assertEquals('number', test5());
+delete x5;
+assertEquals('undefined', test5());
+
+x6 = 0;
+function test6() { return first((++o.x, typeof x6), 2); }
+assertEquals('number', test6());
+delete x6;
+assertEquals('undefined', test6());
+
+x7 = 0;
+function test7() { return first((o.x++, typeof x7), 2); }
+assertEquals('number', test7());
+delete x7;
+assertEquals('undefined', test7());
+
+
+// Assignment, compound assignment, and pre and post-increment of indexed
+// properties.
+x8 = 0;
+function test8(index) { return first((o[index] = 1, typeof x8), 2); }
+assertEquals('number', test8());
+delete x8;
+assertEquals('undefined', test8());
+
+x9 = 0;
+function test9(index) { return first((o[index] += 1, typeof x9), 2); }
+assertEquals('number', test9());
+delete x9;
+assertEquals('undefined', test9());
+
+x10 = 0;
+function test10(index) { return first((++o[index], typeof x10), 2); }
+assertEquals('number', test10());
+delete x10;
+assertEquals('undefined', test10());
+
+x11 = 0;
+function test11(index) { return first((o[index]++, typeof x11), 2); }
+assertEquals('number', test11());
+delete x11;
+assertEquals('undefined', test11());
diff --git a/test/mjsunit/regress/regress-3408144.js b/test/mjsunit/regress/regress-982.js
similarity index 83%
copy from test/mjsunit/regress/regress-3408144.js
copy to test/mjsunit/regress/regress-982.js
index 6e292d6..d88543a 100644
--- a/test/mjsunit/regress/regress-3408144.js
+++ b/test/mjsunit/regress/regress-982.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,13 +25,21 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test incorrect code generation for alternations on ARM.
+function f(a) {
+ return {className: 'xxx'};
+};
+var x = 1;
-// Flags: --nofull-compiler
-
-function foo() {
- return (0 > ("10"||10) - 1);
+function g(active) {
+ for (i = 1; i <= 20000; i++) {
+ if (i == active) {
+ x = i;
+ if (f("" + i) != null) { }
+ } else {
+ if (f("" + i) != null) { }
+ }
+ }
}
-assertFalse(foo());
+g(0);
diff --git a/test/mjsunit/regress/regress-1146.js b/test/mjsunit/regress/regress-995.js
similarity index 71%
copy from test/mjsunit/regress/regress-1146.js
copy to test/mjsunit/regress/regress-995.js
index e8028ce..e88121a 100644
--- a/test/mjsunit/regress/regress-1146.js
+++ b/test/mjsunit/regress/regress-995.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,24 +25,33 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test keyed calls with different key types.
-function F() {}
-var a = new F();
-function f(i) { return a[i](); }
+//
+// A number of hydrogen instructions did not correctly compare its
+// data during GVN.
+//
+// Flags: --allow-natives-syntax
-a.first = function() { return 11; }
-a[0] = function() { return 22; }
-var obj = {};
-a[obj] = function() { return 33; }
+// HHasInstance.
+function f(value) {
+ if (%_IsSpecObject(value)) {
+ if ((%_IsArray(value))) assertTrue(false);
+ }
+}
+f(new String("bar"));
-// Make object slow-case.
-a.foo = 0;
-delete a.foo;
-// Do multiple calls for IC transitions.
-var b = "first";
-f(b);
-f(b);
+// HClassOf.
+function g(value) {
+ if (%_ClassOf(value) === 'Date') {
+ if (%_ClassOf(value) === 'String') assertTrue(false);
+ }
+}
+g(new Date());
-assertEquals(11, f(b));
-assertEquals(22, f(0));
-assertEquals(33, f(obj));
+// HIsNull.
+function h(value) {
+ if (value == null) {
+ if (value === null) assertTrue(false);
+ }
+}
+h(undefined);
+
diff --git a/test/mjsunit/smi-ops-inlined.js b/test/mjsunit/smi-ops-inlined.js
new file mode 100644
index 0000000..afc6cc0
--- /dev/null
+++ b/test/mjsunit/smi-ops-inlined.js
@@ -0,0 +1,673 @@
+// Copyright 2010 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.
+
+// Flags: --always-inline-smi-code
+
+const SMI_MAX = (1 << 30) - 1;
+const SMI_MIN = -(1 << 30);
+const ONE = 1;
+const ONE_HUNDRED = 100;
+
+const OBJ_42 = new (function() {
+ this.valueOf = function() { return 42; };
+})();
+
+assertEquals(42, OBJ_42.valueOf());
+
+
+function Add1(x) {
+ return x + 1;
+}
+
+function Add100(x) {
+ return x + 100;
+}
+
+function Add1Reversed(x) {
+ return 1 + x;
+}
+
+function Add100Reversed(x) {
+ return 100 + x;
+}
+
+
+assertEquals(1, Add1(0)); // fast case
+assertEquals(1, Add1Reversed(0)); // fast case
+assertEquals(SMI_MAX + ONE, Add1(SMI_MAX), "smimax + 1");
+assertEquals(SMI_MAX + ONE, Add1Reversed(SMI_MAX), "1 + smimax");
+assertEquals(42 + ONE, Add1(OBJ_42)); // non-smi
+assertEquals(42 + ONE, Add1Reversed(OBJ_42)); // non-smi
+
+assertEquals(100, Add100(0)); // fast case
+assertEquals(100, Add100Reversed(0)); // fast case
+assertEquals(SMI_MAX + ONE_HUNDRED, Add100(SMI_MAX), "smimax + 100");
+assertEquals(SMI_MAX + ONE_HUNDRED, Add100Reversed(SMI_MAX), " 100 + smimax");
+assertEquals(42 + ONE_HUNDRED, Add100(OBJ_42)); // non-smi
+assertEquals(42 + ONE_HUNDRED, Add100Reversed(OBJ_42)); // non-smi
+
+
+
+function Sub1(x) {
+ return x - 1;
+}
+
+function Sub100(x) {
+ return x - 100;
+}
+
+function Sub1Reversed(x) {
+ return 1 - x;
+}
+
+function Sub100Reversed(x) {
+ return 100 - x;
+}
+
+
+assertEquals(0, Sub1(1)); // fast case
+assertEquals(-1, Sub1Reversed(2)); // fast case
+assertEquals(SMI_MIN - ONE, Sub1(SMI_MIN)); // overflow
+assertEquals(ONE - SMI_MIN, Sub1Reversed(SMI_MIN)); // overflow
+assertEquals(42 - ONE, Sub1(OBJ_42)); // non-smi
+assertEquals(ONE - 42, Sub1Reversed(OBJ_42)); // non-smi
+
+assertEquals(0, Sub100(100)); // fast case
+assertEquals(1, Sub100Reversed(99)); // fast case
+assertEquals(SMI_MIN - ONE_HUNDRED, Sub100(SMI_MIN)); // overflow
+assertEquals(ONE_HUNDRED - SMI_MIN, Sub100Reversed(SMI_MIN)); // overflow
+assertEquals(42 - ONE_HUNDRED, Sub100(OBJ_42)); // non-smi
+assertEquals(ONE_HUNDRED - 42, Sub100Reversed(OBJ_42)); // non-smi
+
+
+function Shr1(x) {
+ return x >>> 1;
+}
+
+function Shr100(x) {
+ return x >>> 100;
+}
+
+function Shr1Reversed(x) {
+ return 1 >>> x;
+}
+
+function Shr100Reversed(x) {
+ return 100 >>> x;
+}
+
+function Sar1(x) {
+ return x >> 1;
+}
+
+function Sar100(x) {
+ return x >> 100;
+}
+
+function Sar1Reversed(x) {
+ return 1 >> x;
+}
+
+function Sar100Reversed(x) {
+ return 100 >> x;
+}
+
+
+assertEquals(0, Shr1(1));
+assertEquals(0, Sar1(1));
+assertEquals(0, Shr1Reversed(2));
+assertEquals(0, Sar1Reversed(2));
+assertEquals(1610612736, Shr1(SMI_MIN));
+assertEquals(-536870912, Sar1(SMI_MIN));
+assertEquals(1, Shr1Reversed(SMI_MIN));
+assertEquals(1, Sar1Reversed(SMI_MIN));
+assertEquals(21, Shr1(OBJ_42));
+assertEquals(21, Sar1(OBJ_42));
+assertEquals(0, Shr1Reversed(OBJ_42));
+assertEquals(0, Sar1Reversed(OBJ_42));
+
+assertEquals(6, Shr100(100), "100 >>> 100");
+assertEquals(6, Sar100(100), "100 >> 100");
+assertEquals(12, Shr100Reversed(99));
+assertEquals(12, Sar100Reversed(99));
+assertEquals(201326592, Shr100(SMI_MIN));
+assertEquals(-67108864, Sar100(SMI_MIN));
+assertEquals(100, Shr100Reversed(SMI_MIN));
+assertEquals(100, Sar100Reversed(SMI_MIN));
+assertEquals(2, Shr100(OBJ_42));
+assertEquals(2, Sar100(OBJ_42));
+assertEquals(0, Shr100Reversed(OBJ_42));
+assertEquals(0, Sar100Reversed(OBJ_42));
+
+
+function Xor1(x) {
+ return x ^ 1;
+}
+
+function Xor100(x) {
+ return x ^ 100;
+}
+
+function Xor1Reversed(x) {
+ return 1 ^ x;
+}
+
+function Xor100Reversed(x) {
+ return 100 ^ x;
+}
+
+
+assertEquals(0, Xor1(1));
+assertEquals(3, Xor1Reversed(2));
+assertEquals(SMI_MIN + 1, Xor1(SMI_MIN));
+assertEquals(SMI_MIN + 1, Xor1Reversed(SMI_MIN));
+assertEquals(43, Xor1(OBJ_42));
+assertEquals(43, Xor1Reversed(OBJ_42));
+
+assertEquals(0, Xor100(100));
+assertEquals(7, Xor100Reversed(99));
+assertEquals(-1073741724, Xor100(SMI_MIN));
+assertEquals(-1073741724, Xor100Reversed(SMI_MIN));
+assertEquals(78, Xor100(OBJ_42));
+assertEquals(78, Xor100Reversed(OBJ_42));
+
+var x = 0x23; var y = 0x35;
+assertEquals(0x16, x ^ y);
+
+
+// Bitwise not.
+var v = 0;
+assertEquals(-1, ~v);
+v = SMI_MIN;
+assertEquals(0x3fffffff, ~v, "~smimin");
+v = SMI_MAX;
+assertEquals(-0x40000000, ~v, "~smimax");
+
+// Overflowing ++ and --.
+v = SMI_MAX;
+v++;
+assertEquals(0x40000000, v, "smimax++");
+v = SMI_MIN;
+v--;
+assertEquals(-0x40000001, v, "smimin--");
+
+// Not actually Smi operations.
+// Check that relations on unary ops work.
+var v = -1.2;
+assertTrue(v == v);
+assertTrue(v === v);
+assertTrue(v <= v);
+assertTrue(v >= v);
+assertFalse(v < v);
+assertFalse(v > v);
+assertFalse(v != v);
+assertFalse(v !== v);
+
+// Right hand side of unary minus is overwritable.
+v = 1.5
+assertEquals(-2.25, -(v * v));
+
+// Smi input to bitop gives non-smi result where the rhs is a float that
+// can be overwritten.
+var x1 = 0x10000000;
+var x2 = 0x40000002;
+var x3 = 0x40000000;
+assertEquals(0x40000000, x1 << (x2 - x3), "0x10000000<<1(1)");
+
+// Smi input to bitop gives non-smi result where the rhs could be overwritten
+// if it were a float, but it isn't.
+x1 = 0x10000000
+x2 = 4
+x3 = 2
+assertEquals(0x40000000, x1 << (x2 - x3), "0x10000000<<2(2)");
+
+
+// Test shift operators on non-smi inputs, giving smi and non-smi results.
+function testShiftNonSmis() {
+ var pos_non_smi = 2000000000;
+ var neg_non_smi = -pos_non_smi;
+ var pos_smi = 1000000000;
+ var neg_smi = -pos_smi;
+
+ // Begin block A
+ assertEquals(pos_non_smi, (pos_non_smi) >> 0);
+ assertEquals(pos_non_smi, (pos_non_smi) >>> 0);
+ assertEquals(pos_non_smi, (pos_non_smi) << 0);
+ assertEquals(neg_non_smi, (neg_non_smi) >> 0);
+ assertEquals(neg_non_smi + 0x100000000, (neg_non_smi) >>> 0);
+ assertEquals(neg_non_smi, (neg_non_smi) << 0);
+ assertEquals(pos_smi, (pos_smi) >> 0, "possmi >> 0");
+ assertEquals(pos_smi, (pos_smi) >>> 0, "possmi >>>0");
+ assertEquals(pos_smi, (pos_smi) << 0, "possmi << 0");
+ assertEquals(neg_smi, (neg_smi) >> 0, "negsmi >> 0");
+ assertEquals(neg_smi + 0x100000000, (neg_smi) >>> 0, "negsmi >>> 0");
+ assertEquals(neg_smi, (neg_smi) << 0), "negsmi << 0";
+
+ assertEquals(pos_non_smi / 2, (pos_non_smi) >> 1);
+ assertEquals(pos_non_smi / 2, (pos_non_smi) >>> 1);
+ assertEquals(-0x1194D800, (pos_non_smi) << 1);
+ assertEquals(pos_non_smi / 8, (pos_non_smi) >> 3);
+ assertEquals(pos_non_smi / 8, (pos_non_smi) >>> 3);
+ assertEquals(-0x46536000, (pos_non_smi) << 3);
+ assertEquals(0x73594000, (pos_non_smi) << 4);
+ assertEquals(pos_non_smi, (pos_non_smi + 0.5) >> 0);
+ assertEquals(pos_non_smi, (pos_non_smi + 0.5) >>> 0);
+ assertEquals(pos_non_smi, (pos_non_smi + 0.5) << 0);
+ assertEquals(pos_non_smi / 2, (pos_non_smi + 0.5) >> 1);
+ assertEquals(pos_non_smi / 2, (pos_non_smi + 0.5) >>> 1);
+ assertEquals(-0x1194D800, (pos_non_smi + 0.5) << 1);
+ assertEquals(pos_non_smi / 8, (pos_non_smi + 0.5) >> 3);
+ assertEquals(pos_non_smi / 8, (pos_non_smi + 0.5) >>> 3);
+ assertEquals(-0x46536000, (pos_non_smi + 0.5) << 3);
+ assertEquals(0x73594000, (pos_non_smi + 0.5) << 4);
+
+ assertEquals(neg_non_smi / 2, (neg_non_smi) >> 1, "negnonsmi >> 1");
+
+ assertEquals(neg_non_smi / 2 + 0x100000000 / 2, (neg_non_smi) >>> 1,
+ "negnonsmi >>> 1");
+ assertEquals(0x1194D800, (neg_non_smi) << 1);
+ assertEquals(neg_non_smi / 8, (neg_non_smi) >> 3);
+ assertEquals(neg_non_smi / 8 + 0x100000000 / 8, (neg_non_smi) >>> 3);
+ assertEquals(0x46536000, (neg_non_smi) << 3);
+ assertEquals(-0x73594000, (neg_non_smi) << 4);
+ assertEquals(neg_non_smi, (neg_non_smi - 0.5) >> 0);
+ assertEquals(neg_non_smi + 0x100000000, (neg_non_smi - 0.5) >>> 0,
+ "negnonsmi.5 >>> 0");
+ assertEquals(neg_non_smi, (neg_non_smi - 0.5) << 0);
+ assertEquals(neg_non_smi / 2, (neg_non_smi - 0.5) >> 1);
+ assertEquals(neg_non_smi / 2 + 0x100000000 / 2, (neg_non_smi - 0.5) >>> 1,
+ "negnonsmi.5 >>> 1");
+ assertEquals(0x1194D800, (neg_non_smi - 0.5) << 1);
+ assertEquals(neg_non_smi / 8, (neg_non_smi - 0.5) >> 3);
+ assertEquals(neg_non_smi / 8 + 0x100000000 / 8, (neg_non_smi - 0.5) >>> 3);
+ assertEquals(0x46536000, (neg_non_smi - 0.5) << 3);
+ assertEquals(-0x73594000, (neg_non_smi - 0.5) << 4);
+
+ assertEquals(pos_smi / 2, (pos_smi) >> 1);
+ assertEquals(pos_smi / 2, (pos_smi) >>> 1);
+ assertEquals(pos_non_smi, (pos_smi) << 1);
+ assertEquals(pos_smi / 8, (pos_smi) >> 3);
+ assertEquals(pos_smi / 8, (pos_smi) >>> 3);
+ assertEquals(-0x2329b000, (pos_smi) << 3);
+ assertEquals(0x73594000, (pos_smi) << 5);
+ assertEquals(pos_smi, (pos_smi + 0.5) >> 0, "possmi.5 >> 0");
+ assertEquals(pos_smi, (pos_smi + 0.5) >>> 0, "possmi.5 >>> 0");
+ assertEquals(pos_smi, (pos_smi + 0.5) << 0, "possmi.5 << 0");
+ assertEquals(pos_smi / 2, (pos_smi + 0.5) >> 1);
+ assertEquals(pos_smi / 2, (pos_smi + 0.5) >>> 1);
+ assertEquals(pos_non_smi, (pos_smi + 0.5) << 1);
+ assertEquals(pos_smi / 8, (pos_smi + 0.5) >> 3);
+ assertEquals(pos_smi / 8, (pos_smi + 0.5) >>> 3);
+ assertEquals(-0x2329b000, (pos_smi + 0.5) << 3);
+ assertEquals(0x73594000, (pos_smi + 0.5) << 5);
+
+ assertEquals(neg_smi / 2, (neg_smi) >> 1);
+ assertEquals(neg_smi / 2 + 0x100000000 / 2, (neg_smi) >>> 1);
+ assertEquals(neg_non_smi, (neg_smi) << 1);
+ assertEquals(neg_smi / 8, (neg_smi) >> 3);
+ assertEquals(neg_smi / 8 + 0x100000000 / 8, (neg_smi) >>> 3);
+ assertEquals(0x46536000, (neg_smi) << 4);
+ assertEquals(-0x73594000, (neg_smi) << 5);
+ assertEquals(neg_smi, (neg_smi - 0.5) >> 0, "negsmi.5 >> 0");
+ assertEquals(neg_smi + 0x100000000, (neg_smi - 0.5) >>> 0, "negsmi.5 >>> 0");
+ assertEquals(neg_smi, (neg_smi - 0.5) << 0, "negsmi.5 << 0");
+ assertEquals(neg_smi / 2, (neg_smi - 0.5) >> 1);
+ assertEquals(neg_smi / 2 + 0x100000000 / 2, (neg_smi - 0.5) >>> 1);
+ assertEquals(neg_non_smi, (neg_smi - 0.5) << 1);
+ assertEquals(neg_smi / 8, (neg_smi - 0.5) >> 3);
+ assertEquals(neg_smi / 8 + 0x100000000 / 8, (neg_smi - 0.5) >>> 3);
+ assertEquals(0x46536000, (neg_smi - 0.5) << 4);
+ assertEquals(-0x73594000, (neg_smi - 0.5) << 5);
+ // End block A
+
+ // Repeat block A with 2^32 added to positive numbers and
+ // 2^32 subtracted from negative numbers.
+ // Begin block A repeat 1
+ var two_32 = 0x100000000;
+ var neg_32 = -two_32;
+ assertEquals(pos_non_smi, (two_32 + pos_non_smi) >> 0);
+ assertEquals(pos_non_smi, (two_32 + pos_non_smi) >>> 0);
+ assertEquals(pos_non_smi, (two_32 + pos_non_smi) << 0);
+ assertEquals(neg_non_smi, (neg_32 + neg_non_smi) >> 0);
+ assertEquals(neg_non_smi + 0x100000000, (neg_32 + neg_non_smi) >>> 0);
+ assertEquals(neg_non_smi, (neg_32 + neg_non_smi) << 0);
+ assertEquals(pos_smi, (two_32 + pos_smi) >> 0, "2^32+possmi >> 0");
+ assertEquals(pos_smi, (two_32 + pos_smi) >>> 0, "2^32+possmi >>> 0");
+ assertEquals(pos_smi, (two_32 + pos_smi) << 0, "2^32+possmi << 0");
+ assertEquals(neg_smi, (neg_32 + neg_smi) >> 0, "2^32+negsmi >> 0");
+ assertEquals(neg_smi + 0x100000000, (neg_32 + neg_smi) >>> 0);
+ assertEquals(neg_smi, (neg_32 + neg_smi) << 0, "2^32+negsmi << 0");
+
+ assertEquals(pos_non_smi / 2, (two_32 + pos_non_smi) >> 1);
+ assertEquals(pos_non_smi / 2, (two_32 + pos_non_smi) >>> 1);
+ assertEquals(-0x1194D800, (two_32 + pos_non_smi) << 1);
+ assertEquals(pos_non_smi / 8, (two_32 + pos_non_smi) >> 3);
+ assertEquals(pos_non_smi / 8, (two_32 + pos_non_smi) >>> 3);
+ assertEquals(-0x46536000, (two_32 + pos_non_smi) << 3);
+ assertEquals(0x73594000, (two_32 + pos_non_smi) << 4);
+ assertEquals(pos_non_smi, (two_32 + pos_non_smi + 0.5) >> 0);
+ assertEquals(pos_non_smi, (two_32 + pos_non_smi + 0.5) >>> 0);
+ assertEquals(pos_non_smi, (two_32 + pos_non_smi + 0.5) << 0);
+ assertEquals(pos_non_smi / 2, (two_32 + pos_non_smi + 0.5) >> 1);
+ assertEquals(pos_non_smi / 2, (two_32 + pos_non_smi + 0.5) >>> 1);
+ assertEquals(-0x1194D800, (two_32 + pos_non_smi + 0.5) << 1);
+ assertEquals(pos_non_smi / 8, (two_32 + pos_non_smi + 0.5) >> 3);
+ assertEquals(pos_non_smi / 8, (two_32 + pos_non_smi + 0.5) >>> 3);
+ assertEquals(-0x46536000, (two_32 + pos_non_smi + 0.5) << 3);
+ assertEquals(0x73594000, (two_32 + pos_non_smi + 0.5) << 4);
+
+ assertEquals(neg_non_smi / 2, (neg_32 + neg_non_smi) >> 1);
+ assertEquals(neg_non_smi / 2 + 0x100000000 / 2, (neg_32 + neg_non_smi) >>> 1);
+ assertEquals(0x1194D800, (neg_32 + neg_non_smi) << 1);
+ assertEquals(neg_non_smi / 8, (neg_32 + neg_non_smi) >> 3);
+ assertEquals(neg_non_smi / 8 + 0x100000000 / 8, (neg_32 + neg_non_smi) >>> 3);
+ assertEquals(0x46536000, (neg_32 + neg_non_smi) << 3);
+ assertEquals(-0x73594000, (neg_32 + neg_non_smi) << 4);
+ assertEquals(neg_non_smi, (neg_32 + neg_non_smi - 0.5) >> 0);
+ assertEquals(neg_non_smi + 0x100000000, (neg_32 + neg_non_smi - 0.5) >>> 0);
+ assertEquals(neg_non_smi, (neg_32 + neg_non_smi - 0.5) << 0);
+ assertEquals(neg_non_smi / 2, (neg_32 + neg_non_smi - 0.5) >> 1);
+ assertEquals(neg_non_smi / 2 + 0x100000000 / 2, (neg_32 + neg_non_smi - 0.5)
+ >>> 1);
+ assertEquals(0x1194D800, (neg_32 + neg_non_smi - 0.5) << 1);
+ assertEquals(neg_non_smi / 8, (neg_32 + neg_non_smi - 0.5) >> 3);
+ assertEquals(neg_non_smi / 8 + 0x100000000 / 8, (neg_32 + neg_non_smi - 0.5)
+ >>> 3);
+ assertEquals(0x46536000, (neg_32 + neg_non_smi - 0.5) << 3);
+ assertEquals(-0x73594000, (neg_32 + neg_non_smi - 0.5) << 4);
+
+ assertEquals(pos_smi / 2, (two_32 + pos_smi) >> 1);
+ assertEquals(pos_smi / 2, (two_32 + pos_smi) >>> 1);
+ assertEquals(pos_non_smi, (two_32 + pos_smi) << 1);
+ assertEquals(pos_smi / 8, (two_32 + pos_smi) >> 3);
+ assertEquals(pos_smi / 8, (two_32 + pos_smi) >>> 3);
+ assertEquals(-0x2329b000, (two_32 + pos_smi) << 3);
+ assertEquals(0x73594000, (two_32 + pos_smi) << 5);
+ assertEquals(pos_smi, (two_32 + pos_smi + 0.5) >> 0);
+ assertEquals(pos_smi, (two_32 + pos_smi + 0.5) >>> 0);
+ assertEquals(pos_smi, (two_32 + pos_smi + 0.5) << 0);
+ assertEquals(pos_smi / 2, (two_32 + pos_smi + 0.5) >> 1);
+ assertEquals(pos_smi / 2, (two_32 + pos_smi + 0.5) >>> 1);
+ assertEquals(pos_non_smi, (two_32 + pos_smi + 0.5) << 1);
+ assertEquals(pos_smi / 8, (two_32 + pos_smi + 0.5) >> 3);
+ assertEquals(pos_smi / 8, (two_32 + pos_smi + 0.5) >>> 3);
+ assertEquals(-0x2329b000, (two_32 + pos_smi + 0.5) << 3);
+ assertEquals(0x73594000, (two_32 + pos_smi + 0.5) << 5);
+
+ assertEquals(neg_smi / 2, (neg_32 + neg_smi) >> 1);
+ assertEquals(neg_smi / 2 + 0x100000000 / 2, (neg_32 + neg_smi) >>> 1);
+ assertEquals(neg_non_smi, (neg_32 + neg_smi) << 1);
+ assertEquals(neg_smi / 8, (neg_32 + neg_smi) >> 3);
+ assertEquals((neg_smi + 0x100000000) / 8, (neg_32 + neg_smi) >>> 3);
+ assertEquals(0x46536000, (neg_32 + neg_smi) << 4);
+ assertEquals(-0x73594000, (neg_32 + neg_smi) << 5);
+ assertEquals(neg_smi, (neg_32 + neg_smi - 0.5) >> 0, "-2^32+negsmi.5 >> 0");
+ assertEquals(neg_smi + 0x100000000, (neg_32 + neg_smi - 0.5) >>> 0);
+ assertEquals(neg_smi, (neg_32 + neg_smi - 0.5) << 0, "-2^32+negsmi.5 << 0");
+ assertEquals(neg_smi / 2, (neg_32 + neg_smi - 0.5) >> 1);
+ assertEquals(neg_smi / 2 + 0x100000000 / 2, (neg_32 + neg_smi - 0.5) >>> 1);
+ assertEquals(neg_non_smi, (neg_32 + neg_smi - 0.5) << 1);
+ assertEquals(neg_smi / 8, (neg_32 + neg_smi - 0.5) >> 3);
+ assertEquals(neg_smi / 8 + 0x100000000 / 8, (neg_32 + neg_smi - 0.5) >>> 3);
+ assertEquals(0x46536000, (neg_32 + neg_smi - 0.5) << 4);
+ assertEquals(-0x73594000, (neg_32 + neg_smi - 0.5) << 5);
+ // End block A repeat 1
+ // Repeat block A with shift amounts in variables intialized with
+ // a constant.
+ var zero = 0;
+ var one = 1;
+ var three = 3;
+ var four = 4;
+ var five = 5;
+ // Begin block A repeat 2
+ assertEquals(pos_non_smi, (pos_non_smi) >> zero);
+ assertEquals(pos_non_smi, (pos_non_smi) >>> zero);
+ assertEquals(pos_non_smi, (pos_non_smi) << zero);
+ assertEquals(neg_non_smi, (neg_non_smi) >> zero);
+ assertEquals(neg_non_smi + 0x100000000, (neg_non_smi) >>> zero);
+ assertEquals(neg_non_smi, (neg_non_smi) << zero);
+ assertEquals(pos_smi, (pos_smi) >> zero);
+ assertEquals(pos_smi, (pos_smi) >>> zero);
+ assertEquals(pos_smi, (pos_smi) << zero);
+ assertEquals(neg_smi, (neg_smi) >> zero, "negsmi >> zero");
+ assertEquals(neg_smi + 0x100000000, (neg_smi) >>> zero);
+ assertEquals(neg_smi, (neg_smi) << zero, "negsmi << zero");
+
+ assertEquals(pos_non_smi / 2, (pos_non_smi) >> one);
+ assertEquals(pos_non_smi / 2, (pos_non_smi) >>> one);
+ assertEquals(-0x1194D800, (pos_non_smi) << one);
+ assertEquals(pos_non_smi / 8, (pos_non_smi) >> three);
+ assertEquals(pos_non_smi / 8, (pos_non_smi) >>> three);
+ assertEquals(-0x46536000, (pos_non_smi) << three);
+ assertEquals(0x73594000, (pos_non_smi) << four);
+ assertEquals(pos_non_smi, (pos_non_smi + 0.5) >> zero);
+ assertEquals(pos_non_smi, (pos_non_smi + 0.5) >>> zero);
+ assertEquals(pos_non_smi, (pos_non_smi + 0.5) << zero);
+ assertEquals(pos_non_smi / 2, (pos_non_smi + 0.5) >> one);
+ assertEquals(pos_non_smi / 2, (pos_non_smi + 0.5) >>> one);
+ assertEquals(-0x1194D800, (pos_non_smi + 0.5) << one);
+ assertEquals(pos_non_smi / 8, (pos_non_smi + 0.5) >> three);
+ assertEquals(pos_non_smi / 8, (pos_non_smi + 0.5) >>> three);
+ assertEquals(-0x46536000, (pos_non_smi + 0.5) << three);
+ assertEquals(0x73594000, (pos_non_smi + 0.5) << four);
+
+ assertEquals(neg_non_smi / 2, (neg_non_smi) >> one);
+ assertEquals(neg_non_smi / 2 + 0x100000000 / 2, (neg_non_smi) >>> one);
+ assertEquals(0x1194D800, (neg_non_smi) << one);
+ assertEquals(neg_non_smi / 8, (neg_non_smi) >> three);
+ assertEquals(neg_non_smi / 8 + 0x100000000 / 8, (neg_non_smi) >>> three);
+ assertEquals(0x46536000, (neg_non_smi) << three);
+ assertEquals(-0x73594000, (neg_non_smi) << four);
+ assertEquals(neg_non_smi, (neg_non_smi - 0.5) >> zero);
+ assertEquals(neg_non_smi + 0x100000000, (neg_non_smi - 0.5) >>> zero);
+ assertEquals(neg_non_smi, (neg_non_smi - 0.5) << zero);
+ assertEquals(neg_non_smi / 2, (neg_non_smi - 0.5) >> one);
+ assertEquals(neg_non_smi / 2 + 0x100000000 / 2, (neg_non_smi - 0.5) >>> one);
+ assertEquals(0x1194D800, (neg_non_smi - 0.5) << one);
+ assertEquals(neg_non_smi / 8, (neg_non_smi - 0.5) >> three);
+ assertEquals(neg_non_smi / 8 + 0x100000000 / 8, (neg_non_smi - 0.5)
+ >>> three);
+ assertEquals(0x46536000, (neg_non_smi - 0.5) << three);
+ assertEquals(-0x73594000, (neg_non_smi - 0.5) << four);
+
+ assertEquals(pos_smi / 2, (pos_smi) >> one);
+ assertEquals(pos_smi / 2, (pos_smi) >>> one);
+ assertEquals(pos_non_smi, (pos_smi) << one);
+ assertEquals(pos_smi / 8, (pos_smi) >> three);
+ assertEquals(pos_smi / 8, (pos_smi) >>> three);
+ assertEquals(-0x2329b000, (pos_smi) << three);
+ assertEquals(0x73594000, (pos_smi) << five);
+ assertEquals(pos_smi, (pos_smi + 0.5) >> zero);
+ assertEquals(pos_smi, (pos_smi + 0.5) >>> zero);
+ assertEquals(pos_smi, (pos_smi + 0.5) << zero);
+ assertEquals(pos_smi / 2, (pos_smi + 0.5) >> one);
+ assertEquals(pos_smi / 2, (pos_smi + 0.5) >>> one);
+ assertEquals(pos_non_smi, (pos_smi + 0.5) << one);
+ assertEquals(pos_smi / 8, (pos_smi + 0.5) >> three);
+ assertEquals(pos_smi / 8, (pos_smi + 0.5) >>> three);
+ assertEquals(-0x2329b000, (pos_smi + 0.5) << three);
+ assertEquals(0x73594000, (pos_smi + 0.5) << five);
+
+ assertEquals(neg_smi / 2, (neg_smi) >> one);
+ assertEquals(neg_smi / 2 + 0x100000000 / 2, (neg_smi) >>> one);
+ assertEquals(neg_non_smi, (neg_smi) << one);
+ assertEquals(neg_smi / 8, (neg_smi) >> three);
+ assertEquals(neg_smi / 8 + 0x100000000 / 8, (neg_smi) >>> three);
+ assertEquals(0x46536000, (neg_smi) << four);
+ assertEquals(-0x73594000, (neg_smi) << five);
+ assertEquals(neg_smi, (neg_smi - 0.5) >> zero);
+ assertEquals(neg_smi + 0x100000000, (neg_smi - 0.5) >>> zero);
+ assertEquals(neg_smi, (neg_smi - 0.5) << zero);
+ assertEquals(neg_smi / 2, (neg_smi - 0.5) >> one);
+ assertEquals(neg_smi / 2 + 0x100000000 / 2, (neg_smi - 0.5) >>> one);
+ assertEquals(neg_non_smi, (neg_smi - 0.5) << one);
+ assertEquals(neg_smi / 8, (neg_smi - 0.5) >> three);
+ assertEquals(neg_smi / 8 + 0x100000000 / 8, (neg_smi - 0.5) >>> three);
+ assertEquals(0x46536000, (neg_smi - 0.5) << four);
+ assertEquals(-0x73594000, (neg_smi - 0.5) << five);
+ // End block A repeat 2
+
+ // Repeat previous block, with computed values in the shift variables.
+ five = 0;
+ while (five < 5 ) ++five;
+ four = five - one;
+ three = four - one;
+ one = four - three;
+ zero = one - one;
+
+ // Begin block A repeat 3
+ assertEquals(pos_non_smi, (pos_non_smi) >> zero);
+ assertEquals(pos_non_smi, (pos_non_smi) >>> zero);
+ assertEquals(pos_non_smi, (pos_non_smi) << zero);
+ assertEquals(neg_non_smi, (neg_non_smi) >> zero);
+ assertEquals(neg_non_smi + 0x100000000, (neg_non_smi) >>> zero);
+ assertEquals(neg_non_smi, (neg_non_smi) << zero);
+ assertEquals(pos_smi, (pos_smi) >> zero);
+ assertEquals(pos_smi, (pos_smi) >>> zero);
+ assertEquals(pos_smi, (pos_smi) << zero);
+ assertEquals(neg_smi, (neg_smi) >> zero, "negsmi >> zero(2)");
+ assertEquals(neg_smi + 0x100000000, (neg_smi) >>> zero);
+ assertEquals(neg_smi, (neg_smi) << zero, "negsmi << zero(2)");
+
+ assertEquals(pos_non_smi / 2, (pos_non_smi) >> one);
+ assertEquals(pos_non_smi / 2, (pos_non_smi) >>> one);
+ assertEquals(-0x1194D800, (pos_non_smi) << one);
+ assertEquals(pos_non_smi / 8, (pos_non_smi) >> three);
+ assertEquals(pos_non_smi / 8, (pos_non_smi) >>> three);
+ assertEquals(-0x46536000, (pos_non_smi) << three);
+ assertEquals(0x73594000, (pos_non_smi) << four);
+ assertEquals(pos_non_smi, (pos_non_smi + 0.5) >> zero);
+ assertEquals(pos_non_smi, (pos_non_smi + 0.5) >>> zero);
+ assertEquals(pos_non_smi, (pos_non_smi + 0.5) << zero);
+ assertEquals(pos_non_smi / 2, (pos_non_smi + 0.5) >> one);
+ assertEquals(pos_non_smi / 2, (pos_non_smi + 0.5) >>> one);
+ assertEquals(-0x1194D800, (pos_non_smi + 0.5) << one);
+ assertEquals(pos_non_smi / 8, (pos_non_smi + 0.5) >> three);
+ assertEquals(pos_non_smi / 8, (pos_non_smi + 0.5) >>> three);
+ assertEquals(-0x46536000, (pos_non_smi + 0.5) << three);
+ assertEquals(0x73594000, (pos_non_smi + 0.5) << four);
+
+ assertEquals(neg_non_smi / 2, (neg_non_smi) >> one);
+ assertEquals(neg_non_smi / 2 + 0x100000000 / 2, (neg_non_smi) >>> one);
+ assertEquals(0x1194D800, (neg_non_smi) << one);
+ assertEquals(neg_non_smi / 8, (neg_non_smi) >> three);
+ assertEquals(neg_non_smi / 8 + 0x100000000 / 8, (neg_non_smi) >>> three);
+ assertEquals(0x46536000, (neg_non_smi) << three);
+ assertEquals(-0x73594000, (neg_non_smi) << four);
+ assertEquals(neg_non_smi, (neg_non_smi - 0.5) >> zero);
+ assertEquals(neg_non_smi + 0x100000000, (neg_non_smi - 0.5) >>> zero);
+ assertEquals(neg_non_smi, (neg_non_smi - 0.5) << zero);
+ assertEquals(neg_non_smi / 2, (neg_non_smi - 0.5) >> one);
+ assertEquals(neg_non_smi / 2 + 0x100000000 / 2, (neg_non_smi - 0.5) >>> one);
+ assertEquals(0x1194D800, (neg_non_smi - 0.5) << one);
+ assertEquals(neg_non_smi / 8, (neg_non_smi - 0.5) >> three);
+ assertEquals(neg_non_smi / 8 + 0x100000000 / 8, (neg_non_smi - 0.5)
+ >>> three);
+ assertEquals(0x46536000, (neg_non_smi - 0.5) << three);
+ assertEquals(-0x73594000, (neg_non_smi - 0.5) << four);
+
+ assertEquals(pos_smi / 2, (pos_smi) >> one);
+ assertEquals(pos_smi / 2, (pos_smi) >>> one);
+ assertEquals(pos_non_smi, (pos_smi) << one);
+ assertEquals(pos_smi / 8, (pos_smi) >> three);
+ assertEquals(pos_smi / 8, (pos_smi) >>> three);
+ assertEquals(-0x2329b000, (pos_smi) << three);
+ assertEquals(0x73594000, (pos_smi) << five);
+ assertEquals(pos_smi, (pos_smi + 0.5) >> zero);
+ assertEquals(pos_smi, (pos_smi + 0.5) >>> zero);
+ assertEquals(pos_smi, (pos_smi + 0.5) << zero);
+ assertEquals(pos_smi / 2, (pos_smi + 0.5) >> one);
+ assertEquals(pos_smi / 2, (pos_smi + 0.5) >>> one);
+ assertEquals(pos_non_smi, (pos_smi + 0.5) << one);
+ assertEquals(pos_smi / 8, (pos_smi + 0.5) >> three);
+ assertEquals(pos_smi / 8, (pos_smi + 0.5) >>> three);
+ assertEquals(-0x2329b000, (pos_smi + 0.5) << three);
+ assertEquals(0x73594000, (pos_smi + 0.5) << five);
+
+ assertEquals(neg_smi / 2, (neg_smi) >> one);
+ assertEquals(neg_smi / 2 + 0x100000000 / 2, (neg_smi) >>> one);
+ assertEquals(neg_non_smi, (neg_smi) << one);
+ assertEquals(neg_smi / 8, (neg_smi) >> three);
+ assertEquals(neg_smi / 8 + 0x100000000 / 8, (neg_smi) >>> three);
+ assertEquals(0x46536000, (neg_smi) << four);
+ assertEquals(-0x73594000, (neg_smi) << five);
+ assertEquals(neg_smi, (neg_smi - 0.5) >> zero, "negsmi.5 >> zero");
+ assertEquals(neg_smi + 0x100000000, (neg_smi - 0.5) >>> zero);
+ assertEquals(neg_smi, (neg_smi - 0.5) << zero, "negsmi.5 << zero");
+ assertEquals(neg_smi / 2, (neg_smi - 0.5) >> one);
+ assertEquals(neg_smi / 2 + 0x100000000 / 2, (neg_smi - 0.5) >>> one);
+ assertEquals(neg_non_smi, (neg_smi - 0.5) << one);
+ assertEquals(neg_smi / 8, (neg_smi - 0.5) >> three);
+ assertEquals(neg_smi / 8 + 0x100000000 / 8, (neg_smi - 0.5) >>> three);
+ assertEquals(0x46536000, (neg_smi - 0.5) << four);
+ assertEquals(-0x73594000, (neg_smi - 0.5) << five);
+ // End block A repeat 3
+
+ // Test non-integer shift value
+ assertEquals(5, 20.5 >> 2.4);
+ assertEquals(5, 20.5 >> 2.7);
+ var shift = 2.4;
+ assertEquals(5, 20.5 >> shift);
+ assertEquals(5, 20.5 >> shift + 0.3);
+ shift = shift + zero;
+ assertEquals(5, 20.5 >> shift);
+ assertEquals(5, 20.5 >> shift + 0.3);
+}
+
+testShiftNonSmis();
+
+function intConversion() {
+ function foo(x) {
+ assertEquals(x, (x * 1.0000000001) | 0, "foo more " + x);
+ assertEquals(x, x | 0, "foo " + x);
+ if (x > 0) {
+ assertEquals(x - 1, (x * 0.9999999999) | 0, "foo less " + x);
+ } else {
+ assertEquals(x + 1, (x * 0.9999999999) | 0, "foo less " + x);
+ }
+ }
+ for (var i = 1; i < 0x80000000; i *= 2) {
+ foo(i);
+ foo(-i);
+ }
+ for (var i = 1; i < 1/0; i *= 2) {
+ assertEquals(i | 0, (i * 1.0000000000000001) | 0, "b" + i);
+ assertEquals(-i | 0, (i * -1.0000000000000001) | 0, "c" + i);
+ }
+ for (var i = 0.5; i > 0; i /= 2) {
+ assertEquals(0, i | 0, "d" + i);
+ assertEquals(0, -i | 0, "e" + i);
+ }
+}
+
+intConversion();
+
+// Verify that we handle the (optimized) corner case of shifting by
+// zero even for non-smis.
+function shiftByZero(n) { return n << 0; }
+
+assertEquals(3, shiftByZero(3.1415));
diff --git a/test/mjsunit/smi-ops.js b/test/mjsunit/smi-ops.js
index 8fa6fec..7945855 100644
--- a/test/mjsunit/smi-ops.js
+++ b/test/mjsunit/smi-ops.js
@@ -699,3 +699,6 @@
// allocations we got the Smi overflow case wrong.
function f(x, y) { return y + ( 1 << (x & 31)); }
assertEquals(-2147483647, f(31, 1));
+
+// Regression test for correct handling of overflow in smi comparison.
+assertTrue(-0x40000000 < 42);
diff --git a/test/mjsunit/string-replace-gc.js b/test/mjsunit/string-replace-gc.js
index 26fba10..73b310f 100644
--- a/test/mjsunit/string-replace-gc.js
+++ b/test/mjsunit/string-replace-gc.js
@@ -25,7 +25,6 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Flags: --always-compact
//
// Regression test for the r1512 fix.
diff --git a/test/mjsunit/regress/regress-3408144.js b/test/mjsunit/sum-0-plus-undefined-is-NaN.js
similarity index 82%
copy from test/mjsunit/regress/regress-3408144.js
copy to test/mjsunit/sum-0-plus-undefined-is-NaN.js
index 6e292d6..fb98d0c 100644
--- a/test/mjsunit/regress/regress-3408144.js
+++ b/test/mjsunit/sum-0-plus-undefined-is-NaN.js
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2010 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:
@@ -25,13 +25,17 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Test incorrect code generation for alternations on ARM.
+/**
+ * @fileoverview Test addition of 0 and undefined.
+ */
+function sum(a, b) { return a + b; }
-// Flags: --nofull-compiler
-
-function foo() {
- return (0 > ("10"||10) - 1);
+function test(x, y, expectNaN) {
+ for (var i = 0; i < 1000; i++) {
+ assertEquals(expectNaN, isNaN(sum(x, y)));
+ }
}
-assertFalse(foo());
+test(0, 1, false);
+test(0, undefined, true);
diff --git a/test/mjsunit/tools/logreader.js b/test/mjsunit/tools/logreader.js
deleted file mode 100644
index 485990e..0000000
--- a/test/mjsunit/tools/logreader.js
+++ /dev/null
@@ -1,82 +0,0 @@
-// Copyright 2009 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.
-
-// Load CSV Parser and Log Reader implementations from <project root>/tools.
-// Files: tools/csvparser.js tools/logreader.js
-
-
-(function testAddressParser() {
- var reader = new devtools.profiler.LogReader({});
- var parser = reader.createAddressParser('test');
-
- // Test that 0x values are parsed, and prevAddresses_ are untouched.
- assertFalse('test' in reader.prevAddresses_);
- assertEquals(0, parser('0x0'));
- assertFalse('test' in reader.prevAddresses_);
- assertEquals(0x100, parser('0x100'));
- assertFalse('test' in reader.prevAddresses_);
- assertEquals(0xffffffff, parser('0xffffffff'));
- assertFalse('test' in reader.prevAddresses_);
-
- // Test that values that has no '+' or '-' prefix are parsed
- // and saved to prevAddresses_.
- assertEquals(0, parser('0'));
- assertEquals(0, reader.prevAddresses_.test);
- assertEquals(0x100, parser('100'));
- assertEquals(0x100, reader.prevAddresses_.test);
- assertEquals(0xffffffff, parser('ffffffff'));
- assertEquals(0xffffffff, reader.prevAddresses_.test);
-
- // Test that values prefixed with '+' or '-' are treated as deltas,
- // and prevAddresses_ is updated.
- // Set base value.
- assertEquals(0x100, parser('100'));
- assertEquals(0x100, reader.prevAddresses_.test);
- assertEquals(0x200, parser('+100'));
- assertEquals(0x200, reader.prevAddresses_.test);
- assertEquals(0x100, parser('-100'));
- assertEquals(0x100, reader.prevAddresses_.test);
-})();
-
-
-(function testAddressParser() {
- var reader = new devtools.profiler.LogReader({});
-
- assertEquals([0x10000000, 0x10001000, 0xffff000, 0x10000000],
- reader.processStack(0x10000000, 0, ['overflow',
- '+1000', '-2000', '+1000']));
-})();
-
-
-(function testExpandBackRef() {
- var reader = new devtools.profiler.LogReader({});
-
- assertEquals('aaaaaaaa', reader.expandBackRef_('aaaaaaaa'));
- assertEquals('aaaaaaaa', reader.expandBackRef_('#1'));
- assertEquals('bbbbaaaa', reader.expandBackRef_('bbbb#2:4'));
- assertEquals('"#1:1"', reader.expandBackRef_('"#1:1"'));
-})();
diff --git a/test/mjsunit/typeof.js b/test/mjsunit/typeof.js
index 15ab7bf..39dec72 100644
--- a/test/mjsunit/typeof.js
+++ b/test/mjsunit/typeof.js
@@ -25,8 +25,6 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Flags: --nofull-compiler
-
// The type of a regular expression should be 'function', including in
// the context of string equality comparisons.
diff --git a/test/mozilla/mozilla.status b/test/mozilla/mozilla.status
index 1768c39..1f9e6eb 100644
--- a/test/mozilla/mozilla.status
+++ b/test/mozilla/mozilla.status
@@ -45,6 +45,7 @@
prefix mozilla
def FAIL_OK = FAIL, OKAY
+
##################### SKIPPED TESTS #####################
# This test checks that we behave properly in an out-of-memory
@@ -52,6 +53,9 @@
# time to do so.
js1_5/Regress/regress-271716-n: SKIP
+# BUG(960): This test has an insane amount of output when it times out,
+# messing up ability to see other failures on the waterfall.
+js1_5/extensions/regress-342960: SKIP
# This test uses a unitialized variable. A Bug has been filed:
# https://bugzilla.mozilla.org/show_bug.cgi?id=575575
@@ -809,7 +813,37 @@
js1_5/Regress/regress-271716-n: PASS || SKIP if $FAST == yes
-[ $FAST == yes && $ARCH == arm ]
+[ $arch == arm ]
+
+# Times out and print so much output that we need to skip it to not
+# hang the builder.
+js1_5/extensions/regress-342960: SKIP
+
+# BUG(3251229): Times out when running new crankshaft test script.
+ecma/Date/15.9.5.12-2: SKIP
+ecma/Date/15.9.5.11-2: SKIP
+ecma/Date/15.9.5.10-2: SKIP
+ecma/Date/15.9.5.8: SKIP
+ecma_3/RegExp/regress-311414: SKIP
+js1_5/Array/regress-99120-02: SKIP
+js1_5/Regress/regress-203278-1: SKIP
+ecma/Date/15.9.5.8: SKIP
+ecma/Date/15.9.5.10-2: SKIP
+ecma/Date/15.9.5.11-2: SKIP
+ecma/Date/15.9.5.12-2: SKIP
+js1_5/Regress/regress-404755: SKIP
+js1_5/Regress/regress-451322: SKIP
+js1_5/extensions/regress-371636: SKIP
+
+
+[ $arch == arm && $crankshaft ]
+
+# Test that only fail with crankshaft.
+js1_5/Regress/regress-416628: CRASH
+js1_5/Regress/regress-96128-n: PASS || CRASH
+
+
+[ $fast == yes && $arch == arm ]
# In fast mode on arm we try to skip all tests that would time out,
# since running the tests takes so long in the first place.
diff --git a/test/sputnik/README b/test/sputnik/README
index 3d39a67..94c689b 100644
--- a/test/sputnik/README
+++ b/test/sputnik/README
@@ -1,6 +1,6 @@
To run the sputniktests you must check out the test suite from
googlecode.com. The test expectations are currently relative to
version 28. To get the tests run the following command within
-v8/tests/sputnik/
+v8/test/sputnik/
svn co http://sputniktests.googlecode.com/svn/trunk/ -r28 sputniktests
diff --git a/test/sputnik/sputnik.status b/test/sputnik/sputnik.status
index bc8c1e3..966500d 100644
--- a/test/sputnik/sputnik.status
+++ b/test/sputnik/sputnik.status
@@ -193,7 +193,6 @@
S9.9_A2: FAIL_OK
-
##################### SKIPPED TESTS #####################
# These tests take a looong time to run in debug mode.
@@ -254,6 +253,20 @@
S15.10.7_A3_T2: FAIL_OK
S15.10.7_A3_T1: FAIL_OK
+[ $arch == arm ]
+
+# BUG(3251225): Tests that timeout with --nocrankshaft.
+S15.1.3.1_A2.5_T1: SKIP
+S15.1.3.2_A2.5_T1: SKIP
+S15.1.3.1_A2.4_T1: SKIP
+S15.1.3.1_A2.5_T1: SKIP
+S15.1.3.2_A2.4_T1: SKIP
+S15.1.3.2_A2.5_T1: SKIP
+S15.1.3.3_A2.3_T1: SKIP
+S15.1.3.4_A2.3_T1: SKIP
+S15.1.3.1_A2.5_T1: SKIP
+S15.1.3.2_A2.5_T1: SKIP
+
[ $arch == mips ]
# Skip all tests on MIPS.