OLD | NEW |
---|---|
(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/runtime/runtime-utils.h" | |
6 | |
7 #include "src/arguments.h" | |
8 #include "src/isolate-inl.h" | |
9 | |
10 namespace v8 { | |
11 namespace internal { | |
12 | |
13 | |
14 static Object* MaybeBooleanHelper(Isolate* isolate, Maybe<bool> result, | |
15 bool negate = false) { | |
16 if (result.IsJust()) { | |
17 return isolate->heap()->ToBoolean(result.FromJust() ^ negate); | |
18 } else { | |
19 return isolate->heap()->exception(); | |
20 } | |
21 } | |
22 | |
23 | |
24 RUNTIME_FUNCTION(Runtime_InterpreterEquals) { | |
25 HandleScope scope(isolate); | |
26 DCHECK_EQ(2, args.length()); | |
27 CONVERT_ARG_HANDLE_CHECKED(Object, x, 0); | |
28 CONVERT_ARG_HANDLE_CHECKED(Object, y, 1); | |
29 return MaybeBooleanHelper(isolate, Object::Equals(x, y)); | |
Benedikt Meurer
2015/09/28 10:24:38
I'd really prefer to code it directly without the
oth
2015/09/28 10:38:45
Done.
| |
30 } | |
31 | |
32 | |
33 RUNTIME_FUNCTION(Runtime_InterpreterNotEquals) { | |
34 HandleScope scope(isolate); | |
35 DCHECK_EQ(2, args.length()); | |
36 CONVERT_ARG_HANDLE_CHECKED(Object, x, 0); | |
37 CONVERT_ARG_HANDLE_CHECKED(Object, y, 1); | |
38 return MaybeBooleanHelper(isolate, Object::Equals(x, y), true); | |
39 } | |
40 | |
41 | |
42 RUNTIME_FUNCTION(Runtime_InterpreterLessThan) { | |
43 HandleScope scope(isolate); | |
44 DCHECK_EQ(2, args.length()); | |
45 CONVERT_ARG_HANDLE_CHECKED(Object, x, 0); | |
46 CONVERT_ARG_HANDLE_CHECKED(Object, y, 1); | |
47 return MaybeBooleanHelper(isolate, Object::LessThan(x, y)); | |
48 } | |
49 | |
50 | |
51 RUNTIME_FUNCTION(Runtime_InterpreterGreaterThan) { | |
52 HandleScope scope(isolate); | |
53 DCHECK_EQ(2, args.length()); | |
54 CONVERT_ARG_HANDLE_CHECKED(Object, x, 0); | |
55 CONVERT_ARG_HANDLE_CHECKED(Object, y, 1); | |
56 return MaybeBooleanHelper(isolate, Object::GreaterThan(x, y)); | |
57 } | |
58 | |
59 | |
60 RUNTIME_FUNCTION(Runtime_InterpreterLessThanOrEqual) { | |
61 HandleScope scope(isolate); | |
62 DCHECK_EQ(2, args.length()); | |
63 CONVERT_ARG_HANDLE_CHECKED(Object, x, 0); | |
64 CONVERT_ARG_HANDLE_CHECKED(Object, y, 1); | |
65 return MaybeBooleanHelper(isolate, Object::LessThanOrEqual(x, y)); | |
66 } | |
67 | |
68 | |
69 RUNTIME_FUNCTION(Runtime_InterpreterGreaterThanOrEqual) { | |
70 HandleScope scope(isolate); | |
71 DCHECK_EQ(2, args.length()); | |
72 CONVERT_ARG_HANDLE_CHECKED(Object, x, 0); | |
73 CONVERT_ARG_HANDLE_CHECKED(Object, y, 1); | |
74 return MaybeBooleanHelper(isolate, Object::GreaterThanOrEqual(x, y)); | |
75 } | |
76 | |
77 | |
78 RUNTIME_FUNCTION(Runtime_InterpreterStrictEquals) { | |
79 SealHandleScope scope(isolate); | |
80 DCHECK_EQ(2, args.length()); | |
81 CONVERT_ARG_CHECKED(Object, x, 0); | |
82 CONVERT_ARG_CHECKED(Object, y, 1); | |
83 return isolate->heap()->ToBoolean(x->StrictEquals(y)); | |
84 } | |
85 | |
86 | |
87 RUNTIME_FUNCTION(Runtime_InterpreterStrictNotEquals) { | |
88 SealHandleScope scope(isolate); | |
89 DCHECK_EQ(2, args.length()); | |
90 CONVERT_ARG_CHECKED(Object, x, 0); | |
91 CONVERT_ARG_CHECKED(Object, y, 1); | |
92 return isolate->heap()->ToBoolean(!x->StrictEquals(y)); | |
93 } | |
94 | |
95 | |
96 RUNTIME_FUNCTION(Runtime_InterpreterCastToBoolean) { | |
97 SealHandleScope scope(isolate); | |
98 DCHECK_EQ(1, args.length()); | |
99 CONVERT_ARG_CHECKED(Object, x, 0); | |
100 return isolate->heap()->ToBoolean(x->BooleanValue()); | |
101 } | |
102 | |
103 | |
104 } // namespace internal | |
105 } // namespace v8 | |
OLD | NEW |