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

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

Issue 1410853002: [Interpreter] Add support for RegExp literals. (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 1626 matching lines...) Expand 10 before | Expand all | Expand 10 after
1637 "}"); 1637 "}");
1638 InterpreterTester tester(handles.main_isolate(), source.c_str()); 1638 InterpreterTester tester(handles.main_isolate(), source.c_str());
1639 auto callable = tester.GetCallable<Handle<Object>>(); 1639 auto callable = tester.GetCallable<Handle<Object>>();
1640 1640
1641 Handle<i::Object> return_val = callable( 1641 Handle<i::Object> return_val = callable(
1642 Handle<Smi>(Smi::FromInt(3), handles.main_isolate())).ToHandleChecked(); 1642 Handle<Smi>(Smi::FromInt(3), handles.main_isolate())).ToHandleChecked();
1643 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(5)); 1643 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(5));
1644 } 1644 }
1645 1645
1646 1646
1647 TEST(InterpreterRegExpLiterals) {
1648 HandleAndZoneScope handles;
1649 i::Isolate* isolate = handles.main_isolate();
1650 i::Factory* factory = isolate->factory();
1651
1652 std::pair<const char*, Handle<Object>> literals[5] = {
1653 std::make_pair("return /abd/.exec('cccabbdd');\n",
1654 factory->null_value()),
1655 std::make_pair("return /ab+d/.exec('cccabbdd')[0];\n",
1656 factory->NewStringFromStaticChars("abbd")),
1657 std::make_pair("return /AbC/i.exec('ssaBC')[0];\n",
1658 factory->NewStringFromStaticChars("aBC")),
1659 std::make_pair("return 'ssaBC'.match(/AbC/i)[0];\n",
1660 factory->NewStringFromStaticChars("aBC")),
1661 std::make_pair("return 'ssaBCtAbC'.match(/(AbC)/gi)[1];\n",
1662 factory->NewStringFromStaticChars("AbC")),
1663 };
1664
1665 for (size_t i = 0; i < arraysize(literals); i++) {
1666 std::string source(InterpreterTester::SourceForBody(literals[i].first));
1667 InterpreterTester tester(handles.main_isolate(), source.c_str());
1668 auto callable = tester.GetCallable<>();
1669
1670 Handle<i::Object> return_value = callable().ToHandleChecked();
1671 CHECK(return_value->SameValue(*literals[i].second));
1672 }
1673 }
1674
1675
1647 TEST(InterpreterArrayLiterals) { 1676 TEST(InterpreterArrayLiterals) {
1648 HandleAndZoneScope handles; 1677 HandleAndZoneScope handles;
1649 i::Isolate* isolate = handles.main_isolate(); 1678 i::Isolate* isolate = handles.main_isolate();
1650 i::Factory* factory = isolate->factory(); 1679 i::Factory* factory = isolate->factory();
1651 1680
1652 std::pair<const char*, Handle<Object>> literals[6] = { 1681 std::pair<const char*, Handle<Object>> literals[6] = {
1653 std::make_pair("return [][0];\n", 1682 std::make_pair("return [][0];\n",
1654 factory->undefined_value()), 1683 factory->undefined_value()),
1655 std::make_pair("return [1, 3, 2][1];\n", 1684 std::make_pair("return [1, 3, 2][1];\n",
1656 Handle<Object>(Smi::FromInt(3), isolate)), 1685 Handle<Object>(Smi::FromInt(3), isolate)),
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
1833 1862
1834 // TODO(rmcilroy): modify tests when we have real try finally support. 1863 // TODO(rmcilroy): modify tests when we have real try finally support.
1835 std::string source(InterpreterTester::SourceForBody( 1864 std::string source(InterpreterTester::SourceForBody(
1836 "var a = 1; try { a = a + 1; } finally { a = a + 2; }; return a;")); 1865 "var a = 1; try { a = a + 1; } finally { a = a + 2; }; return a;"));
1837 InterpreterTester tester(handles.main_isolate(), source.c_str()); 1866 InterpreterTester tester(handles.main_isolate(), source.c_str());
1838 auto callable = tester.GetCallable<>(); 1867 auto callable = tester.GetCallable<>();
1839 1868
1840 Handle<Object> return_val = callable().ToHandleChecked(); 1869 Handle<Object> return_val = callable().ToHandleChecked();
1841 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(4)); 1870 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(4));
1842 } 1871 }
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