Index: test/cctest/interpreter/test-interpreter.cc |
diff --git a/test/cctest/interpreter/test-interpreter.cc b/test/cctest/interpreter/test-interpreter.cc |
index 8128be5ddf675130ba3f3965fbed306d1a811746..63df7f73692f31e4ba7f629cdc271cde2fdb70e3 100644 |
--- a/test/cctest/interpreter/test-interpreter.cc |
+++ b/test/cctest/interpreter/test-interpreter.cc |
@@ -1724,11 +1724,11 @@ TEST(InterpreterArrayLiterals) { |
std::make_pair("return [][0];\n", |
factory->undefined_value()), |
std::make_pair("return [1, 3, 2][1];\n", |
- Handle<Object>(Smi::FromInt(3), isolate)), |
+ handle(Smi::FromInt(3), isolate)), |
std::make_pair("return ['a', 'b', 'c'][2];\n", |
factory->NewStringFromStaticChars("c")), |
std::make_pair("var a = 100; return [a, a + 1, a + 2, a + 3][2];\n", |
- Handle<Object>(Smi::FromInt(102), isolate)), |
+ handle(Smi::FromInt(102), isolate)), |
std::make_pair("return [[1, 2, 3], ['a', 'b', 'c']][1][0];\n", |
factory->NewStringFromStaticChars("a")), |
std::make_pair("var t = 't'; return [[t, t + 'est'], [1 + t]][0][1];\n", |
@@ -1757,26 +1757,26 @@ TEST(InterpreterObjectLiterals) { |
std::make_pair("return { name: 'string', val: 9.2 }.name;", |
factory->NewStringFromStaticChars("string")), |
std::make_pair("var a = 15; return { name: 'string', val: a }.val;", |
- Handle<Object>(Smi::FromInt(15), isolate)), |
+ handle(Smi::FromInt(15), isolate)), |
std::make_pair("var a = 5; return { val: a, val: a + 1 }.val;", |
- Handle<Object>(Smi::FromInt(6), isolate)), |
+ handle(Smi::FromInt(6), isolate)), |
std::make_pair("return { func: function() { return 'test' } }.func();", |
factory->NewStringFromStaticChars("test")), |
std::make_pair("return { func(a) { return a + 'st'; } }.func('te');", |
factory->NewStringFromStaticChars("test")), |
std::make_pair("return { get a() { return 22; } }.a;", |
- Handle<Object>(Smi::FromInt(22), isolate)), |
+ handle(Smi::FromInt(22), isolate)), |
std::make_pair("var a = { get b() { return this.x + 't'; },\n" |
" set b(val) { this.x = val + 's' } };\n" |
"a.b = 'te';\n" |
"return a.b;", |
factory->NewStringFromStaticChars("test")), |
std::make_pair("var a = 123; return { 1: a }[1];", |
- Handle<Object>(Smi::FromInt(123), isolate)), |
+ handle(Smi::FromInt(123), isolate)), |
std::make_pair("return Object.getPrototypeOf({ __proto__: null });", |
factory->null_value()), |
std::make_pair("var a = 'test'; return { [a]: 1 }.test;", |
- Handle<Object>(Smi::FromInt(1), isolate)), |
+ handle(Smi::FromInt(1), isolate)), |
std::make_pair("var a = 'test'; return { b: a, [a]: a + 'ing' }['test']", |
factory->NewStringFromStaticChars("testing")), |
std::make_pair("var a = 'proto_str';\n" |
@@ -1785,7 +1785,7 @@ TEST(InterpreterObjectLiterals) { |
factory->NewStringFromStaticChars("proto_str")), |
std::make_pair("var n = 'name';\n" |
"return { [n]: 'val', get a() { return 987 } }['a'];", |
- Handle<Object>(Smi::FromInt(987), isolate)), |
+ handle(Smi::FromInt(987), isolate)), |
}; |
for (size_t i = 0; i < arraysize(literals); i++) { |
@@ -1864,19 +1864,19 @@ TEST(InterpreterContextVariables) { |
std::pair<const char*, Handle<Object>> context_vars[5] = { |
std::make_pair("var a; (function() { a = 1; })(); return a;", |
- Handle<Object>(Smi::FromInt(1), isolate)), |
+ handle(Smi::FromInt(1), isolate)), |
std::make_pair("var a = 10; (function() { a; })(); return a;", |
- Handle<Object>(Smi::FromInt(10), isolate)), |
+ handle(Smi::FromInt(10), isolate)), |
std::make_pair("var a = 20; var b = 30;\n" |
"return (function() { return a + b; })();", |
- Handle<Object>(Smi::FromInt(50), isolate)), |
+ handle(Smi::FromInt(50), isolate)), |
std::make_pair("'use strict'; let a = 1;\n" |
"{ let b = 2; return (function() { return a + b; })(); }", |
- Handle<Object>(Smi::FromInt(3), isolate)), |
+ handle(Smi::FromInt(3), isolate)), |
std::make_pair("'use strict'; let a = 10;\n" |
"{ let b = 20; var c = function() { [a, b] };\n" |
" return a + b; }", |
- Handle<Object>(Smi::FromInt(30), isolate)), |
+ handle(Smi::FromInt(30), isolate)), |
}; |
for (size_t i = 0; i < arraysize(context_vars); i++) { |
@@ -1896,11 +1896,11 @@ TEST(InterpreterContextParameters) { |
std::pair<const char*, Handle<Object>> context_params[3] = { |
std::make_pair("return (function() { return arg1; })();", |
- Handle<Object>(Smi::FromInt(1), isolate)), |
+ handle(Smi::FromInt(1), isolate)), |
std::make_pair("(function() { arg1 = 4; })(); return arg1;", |
- Handle<Object>(Smi::FromInt(4), isolate)), |
+ handle(Smi::FromInt(4), isolate)), |
std::make_pair("(function() { arg3 = arg2 - arg1; })(); return arg3;", |
- Handle<Object>(Smi::FromInt(1), isolate)), |
+ handle(Smi::FromInt(1), isolate)), |
}; |
for (size_t i = 0; i < arraysize(context_params); i++) { |
@@ -1910,9 +1910,9 @@ TEST(InterpreterContextParameters) { |
auto callable = |
tester.GetCallable<Handle<Object>, Handle<Object>, Handle<Object>>(); |
- Handle<Object> a1 = Handle<Object>(Smi::FromInt(1), isolate); |
- Handle<Object> a2 = Handle<Object>(Smi::FromInt(2), isolate); |
- Handle<Object> a3 = Handle<Object>(Smi::FromInt(3), isolate); |
+ Handle<Object> a1 = handle(Smi::FromInt(1), isolate); |
+ Handle<Object> a2 = handle(Smi::FromInt(2), isolate); |
+ Handle<Object> a3 = handle(Smi::FromInt(3), isolate); |
Handle<i::Object> return_value = callable(a1, a2, a3).ToHandleChecked(); |
CHECK(return_value->SameValue(*context_params[i].second)); |
} |
@@ -1927,14 +1927,14 @@ TEST(InterpreterComma) { |
std::pair<const char*, Handle<Object>> literals[6] = { |
std::make_pair("var a; return 0, a;\n", factory->undefined_value()), |
std::make_pair("return 'a', 2.2, 3;\n", |
- Handle<Object>(Smi::FromInt(3), isolate)), |
+ handle(Smi::FromInt(3), isolate)), |
std::make_pair("return 'a', 'b', 'c';\n", |
factory->NewStringFromStaticChars("c")), |
std::make_pair("return 3.2, 2.3, 4.5;\n", factory->NewNumber(4.5)), |
std::make_pair("var a = 10; return b = a, b = b+1;\n", |
- Handle<Object>(Smi::FromInt(11), isolate)), |
+ handle(Smi::FromInt(11), isolate)), |
std::make_pair("var a = 10; return b = a, b = b+1, b + 10;\n", |
- Handle<Object>(Smi::FromInt(21), isolate))}; |
+ handle(Smi::FromInt(21), isolate))}; |
for (size_t i = 0; i < arraysize(literals); i++) { |
std::string source(InterpreterTester::SourceForBody(literals[i].first)); |
@@ -1955,7 +1955,7 @@ TEST(InterpreterLogicalOr) { |
std::pair<const char*, Handle<Object>> literals[5] = { |
std::make_pair("var a, b; return a || b;\n", factory->undefined_value()), |
std::make_pair("var a, b = 10; return a || b;\n", |
- Handle<Object>(Smi::FromInt(10), isolate)), |
+ handle(Smi::FromInt(10), isolate)), |
std::make_pair("var a = '0', b = 10; return a || b;\n", |
factory->NewStringFromStaticChars("0")), |
std::make_pair("return 0 || 3.2;\n", factory->NewNumber(3.2)), |
@@ -1982,17 +1982,17 @@ TEST(InterpreterLogicalAnd) { |
std::make_pair("var a, b = 10; return a && b;\n", |
factory->undefined_value()), |
std::make_pair("var a = 0, b = 10; return a && b / a;\n", |
- Handle<Object>(Smi::FromInt(0), isolate)), |
+ handle(Smi::FromInt(0), isolate)), |
std::make_pair("var a = '0', b = 10; return a && b;\n", |
- Handle<Object>(Smi::FromInt(10), isolate)), |
+ handle(Smi::FromInt(10), isolate)), |
std::make_pair("return 0.0 && 3.2;\n", |
- Handle<Object>(Smi::FromInt(0), isolate)), |
+ handle(Smi::FromInt(0), isolate)), |
std::make_pair("return 'a' && 'b';\n", |
factory->NewStringFromStaticChars("b")), |
std::make_pair("return 'a' && 0 || 'b', 'c';\n", |
factory->NewStringFromStaticChars("c")), |
std::make_pair("var x = 1, y = 3; return x && 0 + 1 || y;\n", |
- Handle<Object>(Smi::FromInt(1), isolate))}; |
+ handle(Smi::FromInt(1), isolate))}; |
for (size_t i = 0; i < arraysize(literals); i++) { |
std::string source(InterpreterTester::SourceForBody(literals[i].first)); |
@@ -2043,7 +2043,7 @@ TEST(InterpreterThrow) { |
std::make_pair("throw undefined;\n", |
factory->undefined_value()), |
std::make_pair("throw 1;\n", |
- Handle<Object>(Smi::FromInt(1), isolate)), |
+ handle(Smi::FromInt(1), isolate)), |
std::make_pair("throw 'Error';\n", |
factory->NewStringFromStaticChars("Error")), |
std::make_pair("var a = true; if (a) { throw 'Error'; }\n", |
@@ -2065,3 +2065,83 @@ TEST(InterpreterThrow) { |
CHECK(thrown_obj->SameValue(*throws[i].second)); |
} |
} |
+ |
+ |
+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(Smi::FromInt(2), isolate)), |
+ std::make_pair("var a = 1; return a++;", |
+ handle(Smi::FromInt(1), isolate)), |
+ std::make_pair("var a = 5; return --a;", |
+ handle(Smi::FromInt(4), isolate)), |
+ std::make_pair("var a = 5; return a--;", |
+ handle(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(Smi::FromInt(2), isolate)), |
+ std::make_pair("var a = false; return a--;", |
+ handle(Smi::FromInt(0), isolate)), |
+ std::make_pair("var a = { val: 11 }; return ++a.val;", |
+ handle(Smi::FromInt(12), isolate)), |
+ std::make_pair("var a = { val: 11 }; return a.val--;", |
+ handle(Smi::FromInt(11), isolate)), |
+ std::make_pair("var a = { val: 11 }; return ++a.val;", |
+ handle(Smi::FromInt(12), isolate)), |
+ std::make_pair("var name = 'val'; var a = { val: 22 }; return --a[name];", |
+ handle(Smi::FromInt(21), isolate)), |
+ std::make_pair("var name = 'val'; var a = { val: 22 }; return a[name]++;", |
+ handle(Smi::FromInt(22), isolate)), |
+ std::make_pair("var a = 1; (function() { a = 2 })(); return ++a;", |
+ handle(Smi::FromInt(3), isolate)), |
+ std::make_pair("var a = 1; (function() { a = 2 })(); return a--;", |
+ handle(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(Smi::FromInt(101), isolate)), |
+ std::make_pair("var global = 100; function f(){ return --global; }", |
+ handle(Smi::FromInt(99), isolate)), |
+ std::make_pair("var global = 100; function f(){ return global++; }", |
+ handle(Smi::FromInt(100), isolate)), |
+ std::make_pair("unallocated = 200; function f(){ return ++unallocated; }", |
+ handle(Smi::FromInt(201), isolate)), |
+ std::make_pair("unallocated = 200; function f(){ return --unallocated; }", |
+ handle(Smi::FromInt(199), isolate)), |
+ std::make_pair("unallocated = 200; function f(){ return unallocated++; }", |
+ handle(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)); |
+ } |
+} |