Chromium Code Reviews| 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 1273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1284 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1284 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 1285 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1285 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 1286 auto callable = tester.GetCallable<>(); | 1286 auto callable = tester.GetCallable<>(); |
| 1287 Handle<Object> return_value = callable().ToHandleChecked(); | 1287 Handle<Object> return_value = callable().ToHandleChecked(); |
| 1288 CHECK(return_value->IsBoolean()); | 1288 CHECK(return_value->IsBoolean()); |
| 1289 CHECK_EQ(return_value->BooleanValue(), expected_value); | 1289 CHECK_EQ(return_value->BooleanValue(), expected_value); |
| 1290 } | 1290 } |
| 1291 } | 1291 } |
| 1292 | 1292 |
| 1293 | 1293 |
| 1294 TEST(InterpreterUnaryNot) { | |
| 1295 HandleAndZoneScope handles; | |
| 1296 for (size_t i = 1; i < 10; i++) { | |
| 1297 bool expected_value = ((i & 1) == 1); | |
| 1298 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); | |
| 1299 Register r0(0); | |
| 1300 builder.set_locals_count(0); | |
| 1301 builder.set_parameter_count(0); | |
| 1302 builder.EnterBlock(); | |
| 1303 builder.LoadFalse(); | |
|
rmcilroy
2015/10/06 10:39:15
Could you add a tests with a non-boolean parameter
oth
2015/10/06 12:35:06
Done.
| |
| 1304 for (size_t j = 0; j < i; j++) { | |
| 1305 builder.LogicalNot(); | |
| 1306 } | |
| 1307 builder.LeaveBlock().Return(); | |
| 1308 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | |
| 1309 InterpreterTester tester(handles.main_isolate(), bytecode_array); | |
| 1310 auto callable = tester.GetCallable<>(); | |
| 1311 Handle<Object> return_value = callable().ToHandleChecked(); | |
| 1312 CHECK(return_value->IsBoolean()); | |
| 1313 CHECK_EQ(return_value->BooleanValue(), expected_value); | |
| 1314 } | |
| 1315 } | |
| 1316 | |
| 1317 | |
| 1318 static void LoadAny(BytecodeArrayBuilder* builder, | |
| 1319 v8::internal::Factory* factory, Handle<Object> obj) { | |
| 1320 if (obj->IsOddball()) { | |
| 1321 if (obj->SameValue(*factory->true_value())) { | |
| 1322 builder->LoadTrue(); | |
| 1323 } else if (obj->SameValue(*factory->false_value())) { | |
| 1324 builder->LoadFalse(); | |
| 1325 } else if (obj->SameValue(*factory->the_hole_value())) { | |
| 1326 builder->LoadTheHole(); | |
| 1327 } else if (obj->SameValue(*factory->null_value())) { | |
| 1328 builder->LoadNull(); | |
| 1329 } else if (obj->SameValue(*factory->undefined_value())) { | |
| 1330 builder->LoadUndefined(); | |
| 1331 } else { | |
| 1332 UNREACHABLE(); | |
| 1333 } | |
| 1334 } else if (obj->IsSmi()) { | |
| 1335 builder->LoadLiteral(*Handle<Smi>::cast(obj)); | |
| 1336 } else { | |
| 1337 builder->LoadLiteral(obj); | |
| 1338 } | |
| 1339 } | |
| 1340 | |
| 1341 | |
| 1342 TEST(InterpreterTypeOf) { | |
| 1343 HandleAndZoneScope handles; | |
| 1344 i::Factory* factory = handles.main_isolate()->factory(); | |
| 1345 | |
| 1346 std::pair<Handle<Object>, const char*> object_type_tuples[] = { | |
| 1347 std::make_pair(factory->undefined_value(), "undefined"), | |
| 1348 std::make_pair(factory->null_value(), "object"), | |
| 1349 std::make_pair(factory->true_value(), "boolean"), | |
| 1350 std::make_pair(factory->false_value(), "boolean"), | |
| 1351 std::make_pair(factory->NewNumber(9.1), "number"), | |
| 1352 std::make_pair(factory->NewNumberFromInt(7771), "number"), | |
| 1353 std::make_pair( | |
| 1354 Handle<Object>::cast(factory->NewStringFromStaticChars("hello")), | |
| 1355 "string"), | |
| 1356 }; | |
| 1357 | |
| 1358 for (size_t i = 0; i < arraysize(object_type_tuples); i++) { | |
| 1359 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); | |
| 1360 Register r0(0); | |
| 1361 builder.set_locals_count(0); | |
| 1362 builder.set_parameter_count(0); | |
| 1363 builder.EnterBlock(); | |
| 1364 LoadAny(&builder, factory, object_type_tuples[i].first); | |
| 1365 builder.TypeOf(); | |
| 1366 builder.LeaveBlock().Return(); | |
| 1367 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | |
| 1368 InterpreterTester tester(handles.main_isolate(), bytecode_array); | |
| 1369 auto callable = tester.GetCallable<>(); | |
| 1370 Handle<v8::internal::String> return_value = | |
| 1371 Handle<v8::internal::String>::cast(callable().ToHandleChecked()); | |
| 1372 auto actual = return_value->ToCString(); | |
| 1373 CHECK_EQ(strcmp(&actual[0], object_type_tuples[i].second), 0); | |
| 1374 } | |
| 1375 } | |
| 1376 | |
| 1377 | |
| 1294 TEST(InterpreterCallRuntime) { | 1378 TEST(InterpreterCallRuntime) { |
| 1295 HandleAndZoneScope handles; | 1379 HandleAndZoneScope handles; |
| 1296 | 1380 |
| 1297 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); | 1381 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
| 1298 builder.set_locals_count(2); | 1382 builder.set_locals_count(2); |
| 1299 builder.set_parameter_count(1); | 1383 builder.set_parameter_count(1); |
| 1300 builder.LoadLiteral(Smi::FromInt(15)) | 1384 builder.LoadLiteral(Smi::FromInt(15)) |
| 1301 .StoreAccumulatorInRegister(Register(0)) | 1385 .StoreAccumulatorInRegister(Register(0)) |
| 1302 .LoadLiteral(Smi::FromInt(40)) | 1386 .LoadLiteral(Smi::FromInt(40)) |
| 1303 .StoreAccumulatorInRegister(Register(1)) | 1387 .StoreAccumulatorInRegister(Register(1)) |
| 1304 .CallRuntime(Runtime::kAdd, Register(0), 2) | 1388 .CallRuntime(Runtime::kAdd, Register(0), 2) |
| 1305 .Return(); | 1389 .Return(); |
| 1306 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1390 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 1307 | 1391 |
| 1308 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1392 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 1309 auto callable = tester.GetCallable<>(); | 1393 auto callable = tester.GetCallable<>(); |
| 1310 | 1394 |
| 1311 Handle<Object> return_val = callable().ToHandleChecked(); | 1395 Handle<Object> return_val = callable().ToHandleChecked(); |
| 1312 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(55)); | 1396 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(55)); |
| 1313 } | 1397 } |
| OLD | NEW |