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

Side by Side Diff: test/unittests/runtime/runtime-interpreter-unittest.cc

Issue 1744163002: [stubs] Introduce a proper ToBooleanStub. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix mips Created 4 years, 9 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/type-info.h ('k') | test/unittests/unittests.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "src/v8.h"
6
7 #include "src/factory.h"
8 #include "src/heap/heap.h"
9 #include "src/heap/heap-inl.h"
10 #include "src/runtime/runtime.h"
11 #include "test/unittests/test-utils.h"
12
13 namespace v8 {
14 namespace internal {
15 namespace interpreter {
16
17 class RuntimeInterpreterTest : public TestWithIsolateAndZone {
18 public:
19 typedef Object* (*RuntimeMethod)(int, Object**, Isolate*);
20
21 RuntimeInterpreterTest() {}
22 ~RuntimeInterpreterTest() override {}
23
24 bool TestOperatorWithObjects(RuntimeMethod method, Handle<Object> lhs,
25 Handle<Object> rhs, bool expected);
26 };
27
28
29 bool RuntimeInterpreterTest::TestOperatorWithObjects(RuntimeMethod method,
30 Handle<Object> lhs,
31 Handle<Object> rhs,
32 bool expected) {
33 Object* args_object[] = {*rhs, *lhs};
34 Handle<Object> result =
35 handle(method(2, &args_object[1], isolate()), isolate());
36 CHECK(result->IsTrue() || result->IsFalse());
37 return result->IsTrue() == expected;
38 }
39
40
41 TEST_F(RuntimeInterpreterTest, ToBoolean) {
42 double quiet_nan = std::numeric_limits<double>::quiet_NaN();
43 std::pair<Handle<Object>, bool> cases[] = {
44 std::make_pair(isolate()->factory()->NewNumberFromInt(0), false),
45 std::make_pair(isolate()->factory()->NewNumberFromInt(1), true),
46 std::make_pair(isolate()->factory()->NewNumberFromInt(100), true),
47 std::make_pair(isolate()->factory()->NewNumberFromInt(-1), true),
48 std::make_pair(isolate()->factory()->NewNumber(7.7), true),
49 std::make_pair(isolate()->factory()->NewNumber(0.00001), true),
50 std::make_pair(isolate()->factory()->NewNumber(quiet_nan), false),
51 std::make_pair(isolate()->factory()->NewHeapNumber(0.0), false),
52 std::make_pair(isolate()->factory()->undefined_value(), false),
53 std::make_pair(isolate()->factory()->null_value(), false),
54 std::make_pair(isolate()->factory()->true_value(), true),
55 std::make_pair(isolate()->factory()->false_value(), false),
56 std::make_pair(isolate()->factory()->NewStringFromStaticChars(""), false),
57 std::make_pair(isolate()->factory()->NewStringFromStaticChars("_"), true),
58 };
59
60 for (size_t i = 0; i < arraysize(cases); i++) {
61 auto& value_expected_tuple = cases[i];
62 Object* args_object[] = {*value_expected_tuple.first};
63 Handle<Object> result = handle(
64 Runtime_InterpreterToBoolean(1, &args_object[0], isolate()), isolate());
65 CHECK(result->IsBoolean());
66 CHECK_EQ(result->IsTrue(), value_expected_tuple.second);
67 }
68 }
69
70
71 } // namespace interpreter
72 } // namespace internal
73 } // namespace v8
OLDNEW
« no previous file with comments | « src/type-info.h ('k') | test/unittests/unittests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698