OLD | NEW |
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 2127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2138 }; | 2138 }; |
2139 | 2139 |
2140 for (size_t i = 0; i < arraysize(count_ops); i++) { | 2140 for (size_t i = 0; i < arraysize(count_ops); i++) { |
2141 InterpreterTester tester(handles.main_isolate(), count_ops[i].first); | 2141 InterpreterTester tester(handles.main_isolate(), count_ops[i].first); |
2142 auto callable = tester.GetCallable<>(); | 2142 auto callable = tester.GetCallable<>(); |
2143 | 2143 |
2144 Handle<i::Object> return_value = callable().ToHandleChecked(); | 2144 Handle<i::Object> return_value = callable().ToHandleChecked(); |
2145 CHECK(return_value->SameValue(*count_ops[i].second)); | 2145 CHECK(return_value->SameValue(*count_ops[i].second)); |
2146 } | 2146 } |
2147 } | 2147 } |
| 2148 |
| 2149 |
| 2150 TEST(InterpreterCompoundExpressions) { |
| 2151 HandleAndZoneScope handles; |
| 2152 i::Isolate* isolate = handles.main_isolate(); |
| 2153 i::Factory* factory = isolate->factory(); |
| 2154 |
| 2155 std::pair<const char*, Handle<Object>> compound_expr[5] = { |
| 2156 std::make_pair("var a = 1; a += 2; return a;", |
| 2157 Handle<Object>(Smi::FromInt(3), isolate)), |
| 2158 std::make_pair("var a = 10; a /= 2; return a;", |
| 2159 Handle<Object>(Smi::FromInt(5), isolate)), |
| 2160 std::make_pair("var a = 'test'; a += 'ing'; return a;", |
| 2161 factory->NewStringFromStaticChars("testing")), |
| 2162 std::make_pair("var a = { val: 2 }; a.val *= 2; return a.val;", |
| 2163 Handle<Object>(Smi::FromInt(4), isolate)), |
| 2164 std::make_pair("var a = 1; (function f() { a = 2; })(); a += 24;" |
| 2165 "return a;", |
| 2166 Handle<Object>(Smi::FromInt(26), isolate)), |
| 2167 }; |
| 2168 |
| 2169 for (size_t i = 0; i < arraysize(compound_expr); i++) { |
| 2170 std::string source( |
| 2171 InterpreterTester::SourceForBody(compound_expr[i].first)); |
| 2172 InterpreterTester tester(handles.main_isolate(), source.c_str()); |
| 2173 auto callable = tester.GetCallable<>(); |
| 2174 |
| 2175 Handle<i::Object> return_value = callable().ToHandleChecked(); |
| 2176 CHECK(return_value->SameValue(*compound_expr[i].second)); |
| 2177 } |
| 2178 } |
| 2179 |
| 2180 |
| 2181 TEST(InterpreterGlobalCompoundExpressions) { |
| 2182 HandleAndZoneScope handles; |
| 2183 i::Isolate* isolate = handles.main_isolate(); |
| 2184 |
| 2185 std::pair<const char*, Handle<Object>> compound_expr[2] = { |
| 2186 std::make_pair("var global = 100;" |
| 2187 "function f() { global += 20; return global; }", |
| 2188 Handle<Object>(Smi::FromInt(120), isolate)), |
| 2189 std::make_pair("unallocated = 100;" |
| 2190 "function f() { unallocated -= 20; return unallocated; }", |
| 2191 Handle<Object>(Smi::FromInt(80), isolate)), |
| 2192 }; |
| 2193 |
| 2194 for (size_t i = 0; i < arraysize(compound_expr); i++) { |
| 2195 InterpreterTester tester(handles.main_isolate(), compound_expr[i].first); |
| 2196 auto callable = tester.GetCallable<>(); |
| 2197 |
| 2198 Handle<i::Object> return_value = callable().ToHandleChecked(); |
| 2199 CHECK(return_value->SameValue(*compound_expr[i].second)); |
| 2200 } |
| 2201 } |
OLD | NEW |