• 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/execution/arguments.h"
6 #include "src/execution/isolate-inl.h"
7 #include "src/heap/heap-inl.h"  // For ToBoolean. TODO(jkummerow): Drop.
8 #include "src/logging/counters.h"
9 #include "src/runtime/runtime-utils.h"
10 
11 namespace v8 {
12 namespace internal {
13 
RUNTIME_FUNCTION(Runtime_Add)14 RUNTIME_FUNCTION(Runtime_Add) {
15   HandleScope scope(isolate);
16   DCHECK_EQ(2, args.length());
17   Handle<Object> lhs = args.at(0);
18   Handle<Object> rhs = args.at(1);
19   RETURN_RESULT_OR_FAILURE(isolate, Object::Add(isolate, lhs, rhs));
20 }
21 
22 
RUNTIME_FUNCTION(Runtime_Equal)23 RUNTIME_FUNCTION(Runtime_Equal) {
24   HandleScope scope(isolate);
25   DCHECK_EQ(2, args.length());
26   Handle<Object> x = args.at(0);
27   Handle<Object> y = args.at(1);
28   Maybe<bool> result = Object::Equals(isolate, x, y);
29   if (result.IsNothing()) return ReadOnlyRoots(isolate).exception();
30   return isolate->heap()->ToBoolean(result.FromJust());
31 }
32 
RUNTIME_FUNCTION(Runtime_NotEqual)33 RUNTIME_FUNCTION(Runtime_NotEqual) {
34   HandleScope scope(isolate);
35   DCHECK_EQ(2, args.length());
36   Handle<Object> x = args.at(0);
37   Handle<Object> y = args.at(1);
38   Maybe<bool> result = Object::Equals(isolate, x, y);
39   if (result.IsNothing()) return ReadOnlyRoots(isolate).exception();
40   return isolate->heap()->ToBoolean(!result.FromJust());
41 }
42 
RUNTIME_FUNCTION(Runtime_StrictEqual)43 RUNTIME_FUNCTION(Runtime_StrictEqual) {
44   SealHandleScope scope(isolate);
45   DCHECK_EQ(2, args.length());
46   Object x = args[0];
47   Object y = args[1];
48   return isolate->heap()->ToBoolean(x.StrictEquals(y));
49 }
50 
RUNTIME_FUNCTION(Runtime_StrictNotEqual)51 RUNTIME_FUNCTION(Runtime_StrictNotEqual) {
52   SealHandleScope scope(isolate);
53   DCHECK_EQ(2, args.length());
54   Object x = args[0];
55   Object y = args[1];
56   return isolate->heap()->ToBoolean(!x.StrictEquals(y));
57 }
58 
RUNTIME_FUNCTION(Runtime_ReferenceEqual)59 RUNTIME_FUNCTION(Runtime_ReferenceEqual) {
60   SealHandleScope scope(isolate);
61   DCHECK_EQ(2, args.length());
62   Object x = args[0];
63   Object y = args[1];
64   return isolate->heap()->ToBoolean(x == y);
65 }
66 
RUNTIME_FUNCTION(Runtime_LessThan)67 RUNTIME_FUNCTION(Runtime_LessThan) {
68   HandleScope scope(isolate);
69   DCHECK_EQ(2, args.length());
70   Handle<Object> x = args.at(0);
71   Handle<Object> y = args.at(1);
72   Maybe<bool> result = Object::LessThan(isolate, x, y);
73   if (result.IsNothing()) return ReadOnlyRoots(isolate).exception();
74   return isolate->heap()->ToBoolean(result.FromJust());
75 }
76 
RUNTIME_FUNCTION(Runtime_GreaterThan)77 RUNTIME_FUNCTION(Runtime_GreaterThan) {
78   HandleScope scope(isolate);
79   DCHECK_EQ(2, args.length());
80   Handle<Object> x = args.at(0);
81   Handle<Object> y = args.at(1);
82   Maybe<bool> result = Object::GreaterThan(isolate, x, y);
83   if (result.IsNothing()) return ReadOnlyRoots(isolate).exception();
84   return isolate->heap()->ToBoolean(result.FromJust());
85 }
86 
RUNTIME_FUNCTION(Runtime_LessThanOrEqual)87 RUNTIME_FUNCTION(Runtime_LessThanOrEqual) {
88   HandleScope scope(isolate);
89   DCHECK_EQ(2, args.length());
90   Handle<Object> x = args.at(0);
91   Handle<Object> y = args.at(1);
92   Maybe<bool> result = Object::LessThanOrEqual(isolate, x, y);
93   if (result.IsNothing()) return ReadOnlyRoots(isolate).exception();
94   return isolate->heap()->ToBoolean(result.FromJust());
95 }
96 
RUNTIME_FUNCTION(Runtime_GreaterThanOrEqual)97 RUNTIME_FUNCTION(Runtime_GreaterThanOrEqual) {
98   HandleScope scope(isolate);
99   DCHECK_EQ(2, args.length());
100   Handle<Object> x = args.at(0);
101   Handle<Object> y = args.at(1);
102   Maybe<bool> result = Object::GreaterThanOrEqual(isolate, x, y);
103   if (result.IsNothing()) return ReadOnlyRoots(isolate).exception();
104   return isolate->heap()->ToBoolean(result.FromJust());
105 }
106 
107 }  // namespace internal
108 }  // namespace v8
109