• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 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/arguments.h"
6 #include "src/isolate-inl.h"
7 #include "src/runtime/runtime-utils.h"
8 
9 namespace v8 {
10 namespace internal {
11 
RUNTIME_FUNCTION(Runtime_Multiply)12 RUNTIME_FUNCTION(Runtime_Multiply) {
13   HandleScope scope(isolate);
14   DCHECK_EQ(2, args.length());
15   CONVERT_ARG_HANDLE_CHECKED(Object, lhs, 0);
16   CONVERT_ARG_HANDLE_CHECKED(Object, rhs, 1);
17   RETURN_RESULT_OR_FAILURE(isolate, Object::Multiply(isolate, lhs, rhs));
18 }
19 
20 
RUNTIME_FUNCTION(Runtime_Divide)21 RUNTIME_FUNCTION(Runtime_Divide) {
22   HandleScope scope(isolate);
23   DCHECK_EQ(2, args.length());
24   CONVERT_ARG_HANDLE_CHECKED(Object, lhs, 0);
25   CONVERT_ARG_HANDLE_CHECKED(Object, rhs, 1);
26   RETURN_RESULT_OR_FAILURE(isolate, Object::Divide(isolate, lhs, rhs));
27 }
28 
29 
RUNTIME_FUNCTION(Runtime_Modulus)30 RUNTIME_FUNCTION(Runtime_Modulus) {
31   HandleScope scope(isolate);
32   DCHECK_EQ(2, args.length());
33   CONVERT_ARG_HANDLE_CHECKED(Object, lhs, 0);
34   CONVERT_ARG_HANDLE_CHECKED(Object, rhs, 1);
35   RETURN_RESULT_OR_FAILURE(isolate, Object::Modulus(isolate, lhs, rhs));
36 }
37 
38 
RUNTIME_FUNCTION(Runtime_Add)39 RUNTIME_FUNCTION(Runtime_Add) {
40   HandleScope scope(isolate);
41   DCHECK_EQ(2, args.length());
42   CONVERT_ARG_HANDLE_CHECKED(Object, lhs, 0);
43   CONVERT_ARG_HANDLE_CHECKED(Object, rhs, 1);
44   RETURN_RESULT_OR_FAILURE(isolate, Object::Add(isolate, lhs, rhs));
45 }
46 
47 
RUNTIME_FUNCTION(Runtime_Subtract)48 RUNTIME_FUNCTION(Runtime_Subtract) {
49   HandleScope scope(isolate);
50   DCHECK_EQ(2, args.length());
51   CONVERT_ARG_HANDLE_CHECKED(Object, lhs, 0);
52   CONVERT_ARG_HANDLE_CHECKED(Object, rhs, 1);
53   RETURN_RESULT_OR_FAILURE(isolate, Object::Subtract(isolate, lhs, rhs));
54 }
55 
56 
RUNTIME_FUNCTION(Runtime_ShiftLeft)57 RUNTIME_FUNCTION(Runtime_ShiftLeft) {
58   HandleScope scope(isolate);
59   DCHECK_EQ(2, args.length());
60   CONVERT_ARG_HANDLE_CHECKED(Object, lhs, 0);
61   CONVERT_ARG_HANDLE_CHECKED(Object, rhs, 1);
62   RETURN_RESULT_OR_FAILURE(isolate, Object::ShiftLeft(isolate, lhs, rhs));
63 }
64 
65 
RUNTIME_FUNCTION(Runtime_ShiftRight)66 RUNTIME_FUNCTION(Runtime_ShiftRight) {
67   HandleScope scope(isolate);
68   DCHECK_EQ(2, args.length());
69   CONVERT_ARG_HANDLE_CHECKED(Object, lhs, 0);
70   CONVERT_ARG_HANDLE_CHECKED(Object, rhs, 1);
71   RETURN_RESULT_OR_FAILURE(isolate, Object::ShiftRight(isolate, lhs, rhs));
72 }
73 
74 
RUNTIME_FUNCTION(Runtime_ShiftRightLogical)75 RUNTIME_FUNCTION(Runtime_ShiftRightLogical) {
76   HandleScope scope(isolate);
77   DCHECK_EQ(2, args.length());
78   CONVERT_ARG_HANDLE_CHECKED(Object, lhs, 0);
79   CONVERT_ARG_HANDLE_CHECKED(Object, rhs, 1);
80   RETURN_RESULT_OR_FAILURE(isolate,
81                            Object::ShiftRightLogical(isolate, lhs, rhs));
82 }
83 
84 
RUNTIME_FUNCTION(Runtime_BitwiseAnd)85 RUNTIME_FUNCTION(Runtime_BitwiseAnd) {
86   HandleScope scope(isolate);
87   DCHECK_EQ(2, args.length());
88   CONVERT_ARG_HANDLE_CHECKED(Object, lhs, 0);
89   CONVERT_ARG_HANDLE_CHECKED(Object, rhs, 1);
90   RETURN_RESULT_OR_FAILURE(isolate, Object::BitwiseAnd(isolate, lhs, rhs));
91 }
92 
93 
RUNTIME_FUNCTION(Runtime_BitwiseOr)94 RUNTIME_FUNCTION(Runtime_BitwiseOr) {
95   HandleScope scope(isolate);
96   DCHECK_EQ(2, args.length());
97   CONVERT_ARG_HANDLE_CHECKED(Object, lhs, 0);
98   CONVERT_ARG_HANDLE_CHECKED(Object, rhs, 1);
99   RETURN_RESULT_OR_FAILURE(isolate, Object::BitwiseOr(isolate, lhs, rhs));
100 }
101 
102 
RUNTIME_FUNCTION(Runtime_BitwiseXor)103 RUNTIME_FUNCTION(Runtime_BitwiseXor) {
104   HandleScope scope(isolate);
105   DCHECK_EQ(2, args.length());
106   CONVERT_ARG_HANDLE_CHECKED(Object, lhs, 0);
107   CONVERT_ARG_HANDLE_CHECKED(Object, rhs, 1);
108   RETURN_RESULT_OR_FAILURE(isolate, Object::BitwiseXor(isolate, lhs, rhs));
109 }
110 
RUNTIME_FUNCTION(Runtime_Equal)111 RUNTIME_FUNCTION(Runtime_Equal) {
112   HandleScope scope(isolate);
113   DCHECK_EQ(2, args.length());
114   CONVERT_ARG_HANDLE_CHECKED(Object, x, 0);
115   CONVERT_ARG_HANDLE_CHECKED(Object, y, 1);
116   Maybe<bool> result = Object::Equals(x, y);
117   if (!result.IsJust()) return isolate->heap()->exception();
118   return isolate->heap()->ToBoolean(result.FromJust());
119 }
120 
RUNTIME_FUNCTION(Runtime_NotEqual)121 RUNTIME_FUNCTION(Runtime_NotEqual) {
122   HandleScope scope(isolate);
123   DCHECK_EQ(2, args.length());
124   CONVERT_ARG_HANDLE_CHECKED(Object, x, 0);
125   CONVERT_ARG_HANDLE_CHECKED(Object, y, 1);
126   Maybe<bool> result = Object::Equals(x, y);
127   if (!result.IsJust()) return isolate->heap()->exception();
128   return isolate->heap()->ToBoolean(!result.FromJust());
129 }
130 
RUNTIME_FUNCTION(Runtime_StrictEqual)131 RUNTIME_FUNCTION(Runtime_StrictEqual) {
132   SealHandleScope scope(isolate);
133   DCHECK_EQ(2, args.length());
134   CONVERT_ARG_CHECKED(Object, x, 0);
135   CONVERT_ARG_CHECKED(Object, y, 1);
136   return isolate->heap()->ToBoolean(x->StrictEquals(y));
137 }
138 
RUNTIME_FUNCTION(Runtime_StrictNotEqual)139 RUNTIME_FUNCTION(Runtime_StrictNotEqual) {
140   SealHandleScope scope(isolate);
141   DCHECK_EQ(2, args.length());
142   CONVERT_ARG_CHECKED(Object, x, 0);
143   CONVERT_ARG_CHECKED(Object, y, 1);
144   return isolate->heap()->ToBoolean(!x->StrictEquals(y));
145 }
146 
RUNTIME_FUNCTION(Runtime_LessThan)147 RUNTIME_FUNCTION(Runtime_LessThan) {
148   HandleScope scope(isolate);
149   DCHECK_EQ(2, args.length());
150   CONVERT_ARG_HANDLE_CHECKED(Object, x, 0);
151   CONVERT_ARG_HANDLE_CHECKED(Object, y, 1);
152   Maybe<bool> result = Object::LessThan(x, y);
153   if (!result.IsJust()) return isolate->heap()->exception();
154   return isolate->heap()->ToBoolean(result.FromJust());
155 }
156 
RUNTIME_FUNCTION(Runtime_GreaterThan)157 RUNTIME_FUNCTION(Runtime_GreaterThan) {
158   HandleScope scope(isolate);
159   DCHECK_EQ(2, args.length());
160   CONVERT_ARG_HANDLE_CHECKED(Object, x, 0);
161   CONVERT_ARG_HANDLE_CHECKED(Object, y, 1);
162   Maybe<bool> result = Object::GreaterThan(x, y);
163   if (!result.IsJust()) return isolate->heap()->exception();
164   return isolate->heap()->ToBoolean(result.FromJust());
165 }
166 
RUNTIME_FUNCTION(Runtime_LessThanOrEqual)167 RUNTIME_FUNCTION(Runtime_LessThanOrEqual) {
168   HandleScope scope(isolate);
169   DCHECK_EQ(2, args.length());
170   CONVERT_ARG_HANDLE_CHECKED(Object, x, 0);
171   CONVERT_ARG_HANDLE_CHECKED(Object, y, 1);
172   Maybe<bool> result = Object::LessThanOrEqual(x, y);
173   if (!result.IsJust()) return isolate->heap()->exception();
174   return isolate->heap()->ToBoolean(result.FromJust());
175 }
176 
RUNTIME_FUNCTION(Runtime_GreaterThanOrEqual)177 RUNTIME_FUNCTION(Runtime_GreaterThanOrEqual) {
178   HandleScope scope(isolate);
179   DCHECK_EQ(2, args.length());
180   CONVERT_ARG_HANDLE_CHECKED(Object, x, 0);
181   CONVERT_ARG_HANDLE_CHECKED(Object, y, 1);
182   Maybe<bool> result = Object::GreaterThanOrEqual(x, y);
183   if (!result.IsJust()) return isolate->heap()->exception();
184   return isolate->heap()->ToBoolean(result.FromJust());
185 }
186 
RUNTIME_FUNCTION(Runtime_InstanceOf)187 RUNTIME_FUNCTION(Runtime_InstanceOf) {
188   HandleScope shs(isolate);
189   DCHECK_EQ(2, args.length());
190   CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
191   CONVERT_ARG_HANDLE_CHECKED(Object, callable, 1);
192   RETURN_RESULT_OR_FAILURE(isolate,
193                            Object::InstanceOf(isolate, object, callable));
194 }
195 
196 }  // namespace internal
197 }  // namespace v8
198