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

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

Issue 1507683005: [Interpreter] Removes ToBoolean bytecode. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebased the patch. Created 5 years 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 1544 matching lines...) Expand 10 before | Expand all | Expand 10 after
1555 UNREACHABLE(); 1555 UNREACHABLE();
1556 } 1556 }
1557 } else if (obj->IsSmi()) { 1557 } else if (obj->IsSmi()) {
1558 builder->LoadLiteral(*Handle<Smi>::cast(obj)); 1558 builder->LoadLiteral(*Handle<Smi>::cast(obj));
1559 } else { 1559 } else {
1560 builder->LoadLiteral(obj); 1560 builder->LoadLiteral(obj);
1561 } 1561 }
1562 } 1562 }
1563 1563
1564 1564
1565 TEST(InterpreterToBoolean) {
1566 HandleAndZoneScope handles;
1567 i::Factory* factory = handles.main_isolate()->factory();
1568
1569 std::pair<Handle<Object>, bool> object_type_tuples[] = {
1570 std::make_pair(factory->undefined_value(), false),
1571 std::make_pair(factory->null_value(), false),
1572 std::make_pair(factory->false_value(), false),
1573 std::make_pair(factory->true_value(), true),
1574 std::make_pair(factory->NewNumber(9.1), true),
1575 std::make_pair(factory->NewNumberFromInt(0), false),
1576 std::make_pair(
1577 Handle<Object>::cast(factory->NewStringFromStaticChars("hello")),
1578 true),
1579 std::make_pair(
1580 Handle<Object>::cast(factory->NewStringFromStaticChars("")), false),
1581 };
1582
1583 for (size_t i = 0; i < arraysize(object_type_tuples); i++) {
1584 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone());
1585 Register r0(0);
1586 builder.set_locals_count(0);
1587 builder.set_context_count(0);
1588 builder.set_parameter_count(0);
1589 LoadAny(&builder, factory, object_type_tuples[i].first);
1590 builder.CastAccumulatorToBoolean();
1591 builder.Return();
1592 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
1593 InterpreterTester tester(handles.main_isolate(), bytecode_array);
1594 auto callable = tester.GetCallable<>();
1595 Handle<Object> return_value = callable().ToHandleChecked();
1596 CHECK(return_value->IsBoolean());
1597 CHECK_EQ(return_value->BooleanValue(), object_type_tuples[i].second);
1598 }
1599 }
1600
1601
1602 TEST(InterpreterUnaryNotNonBoolean) { 1565 TEST(InterpreterUnaryNotNonBoolean) {
1603 HandleAndZoneScope handles; 1566 HandleAndZoneScope handles;
1604 i::Factory* factory = handles.main_isolate()->factory(); 1567 i::Factory* factory = handles.main_isolate()->factory();
1605 1568
1606 std::pair<Handle<Object>, bool> object_type_tuples[] = { 1569 std::pair<Handle<Object>, bool> object_type_tuples[] = {
1607 std::make_pair(factory->undefined_value(), true), 1570 std::make_pair(factory->undefined_value(), true),
1608 std::make_pair(factory->null_value(), true), 1571 std::make_pair(factory->null_value(), true),
1609 std::make_pair(factory->false_value(), true), 1572 std::make_pair(factory->false_value(), true),
1610 std::make_pair(factory->true_value(), false), 1573 std::make_pair(factory->true_value(), false),
1611 std::make_pair(factory->NewNumber(9.1), false), 1574 std::make_pair(factory->NewNumber(9.1), false),
(...skipping 1472 matching lines...) Expand 10 before | Expand all | Expand 10 after
3084 callable(handle(Smi::FromInt(arg_value), handles.main_isolate())) 3047 callable(handle(Smi::FromInt(arg_value), handles.main_isolate()))
3085 .ToHandleChecked(); 3048 .ToHandleChecked();
3086 CHECK_EQ(Handle<Smi>::cast(return_val)->value(), samples[i].second); 3049 CHECK_EQ(Handle<Smi>::cast(return_val)->value(), samples[i].second);
3087 } 3050 }
3088 } 3051 }
3089 3052
3090 3053
3091 } // namespace interpreter 3054 } // namespace interpreter
3092 } // namespace internal 3055 } // namespace internal
3093 } // namespace v8 3056 } // namespace v8
OLDNEW
« no previous file with comments | « src/interpreter/interpreter.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