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 2246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2257 }; | 2257 }; |
2258 | 2258 |
2259 InterpreterTester tester(handles.main_isolate(), create_args[i].first); | 2259 InterpreterTester tester(handles.main_isolate(), create_args[i].first); |
2260 auto callable = | 2260 auto callable = |
2261 tester.GetCallable<Handle<Object>, Handle<Object>, Handle<Object>>(); | 2261 tester.GetCallable<Handle<Object>, Handle<Object>, Handle<Object>>(); |
2262 Handle<Object> return_val = | 2262 Handle<Object> return_val = |
2263 callable(args[0], args[1], args[2]).ToHandleChecked(); | 2263 callable(args[0], args[1], args[2]).ToHandleChecked(); |
2264 CHECK(return_val->SameValue(*args[create_args[i].second])); | 2264 CHECK(return_val->SameValue(*args[create_args[i].second])); |
2265 } | 2265 } |
2266 } | 2266 } |
| 2267 |
| 2268 |
| 2269 TEST(InterpreterConditional) { |
| 2270 HandleAndZoneScope handles; |
| 2271 i::Isolate* isolate = handles.main_isolate(); |
| 2272 |
| 2273 std::pair<const char*, Handle<Object>> conditional[8] = { |
| 2274 std::make_pair("return true ? 2 : 3;", |
| 2275 handle(Smi::FromInt(2), isolate)), |
| 2276 std::make_pair("return false ? 2 : 3;", |
| 2277 handle(Smi::FromInt(3), isolate)), |
| 2278 std::make_pair("var a = 1; return a ? 20 : 30;", |
| 2279 handle(Smi::FromInt(20), isolate)), |
| 2280 std::make_pair("var a = 1; return a ? 20 : 30;", |
| 2281 handle(Smi::FromInt(20), isolate)), |
| 2282 std::make_pair("var a = 'string'; return a ? 20 : 30;", |
| 2283 handle(Smi::FromInt(20), isolate)), |
| 2284 std::make_pair("var a = undefined; return a ? 20 : 30;", |
| 2285 handle(Smi::FromInt(30), isolate)), |
| 2286 std::make_pair("return 1 ? 2 ? 3 : 4 : 5;", |
| 2287 handle(Smi::FromInt(3), isolate)), |
| 2288 std::make_pair("return 0 ? 2 ? 3 : 4 : 5;", |
| 2289 handle(Smi::FromInt(5), isolate)), |
| 2290 }; |
| 2291 |
| 2292 for (size_t i = 0; i < arraysize(conditional); i++) { |
| 2293 std::string source(InterpreterTester::SourceForBody(conditional[i].first)); |
| 2294 InterpreterTester tester(handles.main_isolate(), source.c_str()); |
| 2295 auto callable = tester.GetCallable<>(); |
| 2296 |
| 2297 Handle<i::Object> return_value = callable().ToHandleChecked(); |
| 2298 CHECK(return_value->SameValue(*conditional[i].second)); |
| 2299 } |
| 2300 } |
OLD | NEW |