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

Side by Side Diff: test/cctest/interpreter/test-interpreter.cc

Issue 1402153004: Revert of [Interpreter] Support for operator new. (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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/execution.h" 7 #include "src/execution.h"
8 #include "src/handles.h" 8 #include "src/handles.h"
9 #include "src/interpreter/bytecode-array-builder.h" 9 #include "src/interpreter/bytecode-array-builder.h"
10 #include "src/interpreter/interpreter.h" 10 #include "src/interpreter/interpreter.h"
(...skipping 1709 matching lines...) Expand 10 before | Expand all | Expand 10 after
1720 std::string source(InterpreterTester::SourceForBody(literals[i].first)); 1720 std::string source(InterpreterTester::SourceForBody(literals[i].first));
1721 InterpreterTester tester(handles.main_isolate(), source.c_str()); 1721 InterpreterTester tester(handles.main_isolate(), source.c_str());
1722 auto callable = tester.GetCallable<>(); 1722 auto callable = tester.GetCallable<>();
1723 1723
1724 Handle<i::Object> return_value = callable().ToHandleChecked(); 1724 Handle<i::Object> return_value = callable().ToHandleChecked();
1725 CHECK(return_value->SameValue(*literals[i].second)); 1725 CHECK(return_value->SameValue(*literals[i].second));
1726 } 1726 }
1727 } 1727 }
1728 1728
1729 1729
1730 TEST(InterpreterConstruct) {
1731 HandleAndZoneScope handles;
1732
1733 std::string source(
1734 "function counter() { this.count = 0; }\n"
1735 "function " +
1736 InterpreterTester::function_name() +
1737 "() {\n"
1738 " var c = new counter();\n"
1739 " return c.count;\n"
1740 "}");
1741 InterpreterTester tester(handles.main_isolate(), source.c_str());
1742 auto callable = tester.GetCallable<>();
1743
1744 Handle<Object> return_val = callable().ToHandleChecked();
1745 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(0));
1746 }
1747
1748
1749 TEST(InterpreterConstructWithArgument) {
1750 HandleAndZoneScope handles;
1751
1752 std::string source(
1753 "function counter(arg0) { this.count = 17; this.x = arg0; }\n"
1754 "function " +
1755 InterpreterTester::function_name() +
1756 "() {\n"
1757 " var c = new counter(3);\n"
1758 " return c.x;\n"
1759 "}");
1760 InterpreterTester tester(handles.main_isolate(), source.c_str());
1761 auto callable = tester.GetCallable<>();
1762
1763 Handle<Object> return_val = callable().ToHandleChecked();
1764 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(3));
1765 }
1766
1767
1768 TEST(InterpreterConstructWithArguments) {
1769 HandleAndZoneScope handles;
1770
1771 std::string source(
1772 "function counter(arg0, arg1) {\n"
1773 " this.count = 7; this.x = arg0; this.y = arg1;\n"
1774 "}\n"
1775 "function " +
1776 InterpreterTester::function_name() +
1777 "() {\n"
1778 " var c = new counter(3, 5);\n"
1779 " return c.count + c.x + c.y;\n"
1780 "}");
1781 InterpreterTester tester(handles.main_isolate(), source.c_str());
1782 auto callable = tester.GetCallable<>();
1783
1784 Handle<Object> return_val = callable().ToHandleChecked();
1785 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(15));
1786 }
1787
1788
1789 TEST(InterpreterComma) { 1730 TEST(InterpreterComma) {
1790 HandleAndZoneScope handles; 1731 HandleAndZoneScope handles;
1791 i::Isolate* isolate = handles.main_isolate(); 1732 i::Isolate* isolate = handles.main_isolate();
1792 i::Factory* factory = isolate->factory(); 1733 i::Factory* factory = isolate->factory();
1793 1734
1794 std::pair<const char*, Handle<Object>> literals[6] = { 1735 std::pair<const char*, Handle<Object>> literals[6] = {
1795 std::make_pair("var a; return 0, a;\n", factory->undefined_value()), 1736 std::make_pair("var a; return 0, a;\n", factory->undefined_value()),
1796 std::make_pair("return 'a', 2.2, 3;\n", 1737 std::make_pair("return 'a', 2.2, 3;\n",
1797 Handle<Object>(Smi::FromInt(3), isolate)), 1738 Handle<Object>(Smi::FromInt(3), isolate)),
1798 std::make_pair("return 'a', 'b', 'c';\n", 1739 std::make_pair("return 'a', 'b', 'c';\n",
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1863 1804
1864 for (size_t i = 0; i < arraysize(literals); i++) { 1805 for (size_t i = 0; i < arraysize(literals); i++) {
1865 std::string source(InterpreterTester::SourceForBody(literals[i].first)); 1806 std::string source(InterpreterTester::SourceForBody(literals[i].first));
1866 InterpreterTester tester(handles.main_isolate(), source.c_str()); 1807 InterpreterTester tester(handles.main_isolate(), source.c_str());
1867 auto callable = tester.GetCallable<>(); 1808 auto callable = tester.GetCallable<>();
1868 1809
1869 Handle<i::Object> return_value = callable().ToHandleChecked(); 1810 Handle<i::Object> return_value = callable().ToHandleChecked();
1870 CHECK(return_value->SameValue(*literals[i].second)); 1811 CHECK(return_value->SameValue(*literals[i].second));
1871 } 1812 }
1872 } 1813 }
OLDNEW
« 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