Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1728)

Unified Diff: test/cctest/interpreter/test-interpreter.cc

Issue 1416623003: [Interpreter] Add support for for count operations. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: test/cctest/interpreter/test-interpreter.cc
diff --git a/test/cctest/interpreter/test-interpreter.cc b/test/cctest/interpreter/test-interpreter.cc
index 6e933b9b4725e5738926bd7e7cff4663f0cf4bbe..6346705658a28644d783265b77aaf408c29d90bb 100644
--- a/test/cctest/interpreter/test-interpreter.cc
+++ b/test/cctest/interpreter/test-interpreter.cc
@@ -1999,3 +1999,83 @@ TEST(InterpreterTryFinally) {
Handle<Object> return_val = callable().ToHandleChecked();
CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(4));
}
+
+
+TEST(InterpreterCountOperators) {
+ HandleAndZoneScope handles;
+ i::Isolate* isolate = handles.main_isolate();
+ i::Factory* factory = isolate->factory();
+
+ std::pair<const char*, Handle<Object>> count_ops[16] = {
+ std::make_pair("var a = 1; return ++a;",
+ Handle<Object>(Smi::FromInt(2), isolate)),
Toon Verwaest 2015/10/20 13:42:28 you could just write handle(Smi::FromInt(2), isola
rmcilroy 2015/10/22 12:47:56 Good call, done this throughout, thanks!
+ std::make_pair("var a = 1; return a++;",
+ Handle<Object>(Smi::FromInt(1), isolate)),
+ std::make_pair("var a = 5; return --a;",
+ Handle<Object>(Smi::FromInt(4), isolate)),
+ std::make_pair("var a = 5; return a--;",
+ Handle<Object>(Smi::FromInt(5), isolate)),
+ std::make_pair("var a = 5.2; return --a;",
+ factory->NewHeapNumber(4.2)),
+ std::make_pair("var a = 'string'; return ++a;",
+ factory->nan_value()),
+ std::make_pair("var a = 'string'; return a--;",
+ factory->nan_value()),
+ std::make_pair("var a = true; return ++a;",
+ Handle<Object>(Smi::FromInt(2), isolate)),
+ std::make_pair("var a = false; return a--;",
+ Handle<Object>(Smi::FromInt(0), isolate)),
+ std::make_pair("var a = { val: 11 }; return ++a.val;",
+ Handle<Object>(Smi::FromInt(12), isolate)),
+ std::make_pair("var a = { val: 11 }; return a.val--;",
+ Handle<Object>(Smi::FromInt(11), isolate)),
+ std::make_pair("var a = { val: 11 }; return ++a.val;",
+ Handle<Object>(Smi::FromInt(12), isolate)),
+ std::make_pair("var name = 'val'; var a = { val: 22 }; return --a[name];",
+ Handle<Object>(Smi::FromInt(21), isolate)),
+ std::make_pair("var name = 'val'; var a = { val: 22 }; return a[name]++;",
+ Handle<Object>(Smi::FromInt(22), isolate)),
+ std::make_pair("var a = 1; (function() { a = 2 })(); return ++a;",
+ Handle<Object>(Smi::FromInt(3), isolate)),
+ std::make_pair("var a = 1; (function() { a = 2 })(); return a--;",
+ Handle<Object>(Smi::FromInt(2), isolate)),
+ };
+
+ for (size_t i = 0; i < arraysize(count_ops); i++) {
+ std::string source(InterpreterTester::SourceForBody(count_ops[i].first));
+ InterpreterTester tester(handles.main_isolate(), source.c_str());
+ auto callable = tester.GetCallable<>();
+
+ Handle<i::Object> return_value = callable().ToHandleChecked();
+ CHECK(return_value->SameValue(*count_ops[i].second));
+ }
+}
+
+
+TEST(InterpreterGlobalCountOperators) {
+ HandleAndZoneScope handles;
+ i::Isolate* isolate = handles.main_isolate();
+
+ std::pair<const char*, Handle<Object>> count_ops[6] = {
+ std::make_pair("var global = 100;function f(){ return ++global; }",
+ Handle<Object>(Smi::FromInt(101), isolate)),
+ std::make_pair("var global = 100; function f(){ return --global; }",
+ Handle<Object>(Smi::FromInt(99), isolate)),
+ std::make_pair("var global = 100; function f(){ return global++; }",
+ Handle<Object>(Smi::FromInt(100), isolate)),
+ std::make_pair("unallocated = 200; function f(){ return ++unallocated; }",
+ Handle<Object>(Smi::FromInt(201), isolate)),
+ std::make_pair("unallocated = 200; function f(){ return --unallocated; }",
+ Handle<Object>(Smi::FromInt(199), isolate)),
+ std::make_pair("unallocated = 200; function f(){ return unallocated++; }",
+ Handle<Object>(Smi::FromInt(200), isolate)),
+ };
+
+ for (size_t i = 0; i < arraysize(count_ops); i++) {
+ InterpreterTester tester(handles.main_isolate(), count_ops[i].first);
+ auto callable = tester.GetCallable<>();
+
+ Handle<i::Object> return_value = callable().ToHandleChecked();
+ CHECK(return_value->SameValue(*count_ops[i].second));
+ }
+}
« no previous file with comments | « test/cctest/interpreter/test-bytecode-generator.cc ('k') | test/unittests/interpreter/bytecode-array-builder-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698