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

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

Issue 1402093002: [Interpreter]: Add fake support for try/catch/finally. (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
« no previous file with comments | « src/interpreter/bytecode-generator.cc ('k') | test/cctest/interpreter/test-interpreter.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/compiler.h" 7 #include "src/compiler.h"
8 #include "src/interpreter/bytecode-array-iterator.h" 8 #include "src/interpreter/bytecode-array-iterator.h"
9 #include "src/interpreter/bytecode-generator.h" 9 #include "src/interpreter/bytecode-generator.h"
10 #include "src/interpreter/interpreter.h" 10 #include "src/interpreter/interpreter.h"
11 #include "test/cctest/cctest.h" 11 #include "test/cctest/cctest.h"
12 #include "test/cctest/test-feedback-vector.h" 12 #include "test/cctest/test-feedback-vector.h"
13 13
14 namespace v8 { 14 namespace v8 {
15 namespace internal { 15 namespace internal {
16 namespace interpreter { 16 namespace interpreter {
17 17
18 class BytecodeGeneratorHelper { 18 class BytecodeGeneratorHelper {
19 public: 19 public:
20 const char* kFunctionName = "f"; 20 const char* kFunctionName = "f";
21 21
22 static const int kLastParamIndex = 22 static const int kLastParamIndex =
23 -InterpreterFrameConstants::kLastParamFromRegisterPointer / kPointerSize; 23 -InterpreterFrameConstants::kLastParamFromRegisterPointer / kPointerSize;
24 24
25 BytecodeGeneratorHelper() { 25 BytecodeGeneratorHelper() {
26 i::FLAG_vector_stores = true; 26 i::FLAG_vector_stores = true;
27 i::FLAG_ignition = true; 27 i::FLAG_ignition = true;
28 i::FLAG_ignition_fake_try_catch = true;
28 i::FLAG_ignition_filter = StrDup(kFunctionName); 29 i::FLAG_ignition_filter = StrDup(kFunctionName);
29 i::FLAG_always_opt = false; 30 i::FLAG_always_opt = false;
30 i::FLAG_allow_natives_syntax = true; 31 i::FLAG_allow_natives_syntax = true;
31 CcTest::i_isolate()->interpreter()->Initialize(); 32 CcTest::i_isolate()->interpreter()->Initialize();
32 } 33 }
33 34
34 Isolate* isolate() { return CcTest::i_isolate(); } 35 Isolate* isolate() { return CcTest::i_isolate(); }
35 Factory* factory() { return CcTest::i_isolate()->factory(); } 36 Factory* factory() { return CcTest::i_isolate()->factory(); }
36 37
37 38
(...skipping 2006 matching lines...) Expand 10 before | Expand all | Expand 10 after
2044 InstanceType::FIXED_ARRAY_TYPE}}, 2045 InstanceType::FIXED_ARRAY_TYPE}},
2045 }; 2046 };
2046 2047
2047 for (size_t i = 0; i < arraysize(snippets); i++) { 2048 for (size_t i = 0; i < arraysize(snippets); i++) {
2048 Handle<BytecodeArray> bytecode_array = 2049 Handle<BytecodeArray> bytecode_array =
2049 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 2050 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
2050 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 2051 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
2051 } 2052 }
2052 } 2053 }
2053 2054
2055
2056 TEST(TryCatch) {
2057 InitializedHandleScope handle_scope;
2058 BytecodeGeneratorHelper helper;
2059
2060 // TODO(rmcilroy): modify tests when we have real try catch support.
2061 ExpectedSnippet<int> snippets[] = {
2062 {"try { return 1; } catch(e) { return 2; }",
2063 0,
2064 1,
2065 5,
2066 {
2067 B(LdaSmi8), U8(1), //
2068 B(Return), //
2069 B(LdaUndefined), //
2070 B(Return), //
2071 },
2072 0},
2073 };
2074
2075 for (size_t i = 0; i < arraysize(snippets); i++) {
2076 Handle<BytecodeArray> bytecode_array =
2077 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
2078 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
2079 }
2080 }
2081
2082
2083 TEST(TryFinally) {
2084 InitializedHandleScope handle_scope;
2085 BytecodeGeneratorHelper helper;
2086
2087 // TODO(rmcilroy): modify tests when we have real try finally support.
2088 ExpectedSnippet<int> snippets[] = {
2089 {"var a = 1; try { a = 2; } finally { a = 3; }",
2090 1 * kPointerSize,
2091 1,
2092 14,
2093 {
2094 B(LdaSmi8), U8(1), //
2095 B(Star), R(0), //
2096 B(LdaSmi8), U8(2), //
2097 B(Star), R(0), //
2098 B(LdaSmi8), U8(3), //
2099 B(Star), R(0), //
2100 B(LdaUndefined), //
2101 B(Return), //
2102 },
2103 0},
2104 {"var a = 1; try { a = 2; } catch(e) { a = 20 } finally { a = 3; }",
2105 1 * kPointerSize,
2106 1,
2107 14,
2108 {
2109 B(LdaSmi8), U8(1), //
2110 B(Star), R(0), //
2111 B(LdaSmi8), U8(2), //
2112 B(Star), R(0), //
2113 B(LdaSmi8), U8(3), //
2114 B(Star), R(0), //
2115 B(LdaUndefined), //
2116 B(Return), //
2117 },
2118 0},
2119 };
2120
2121 for (size_t i = 0; i < arraysize(snippets); i++) {
2122 Handle<BytecodeArray> bytecode_array =
2123 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
2124 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
2125 }
2126 }
2127
2054 } // namespace interpreter 2128 } // namespace interpreter
2055 } // namespace internal 2129 } // namespace internal
2056 } // namespace v8 2130 } // namespace v8
OLDNEW
« no previous file with comments | « src/interpreter/bytecode-generator.cc ('k') | test/cctest/interpreter/test-interpreter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698