runtime-operators.cc 3.3 KB
Newer Older
1 2 3 4
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
#include "src/execution/arguments.h"
#include "src/execution/isolate-inl.h"
7
#include "src/heap/heap-inl.h"  // For ToBoolean. TODO(jkummerow): Drop.
8 9 10 11 12 13 14

namespace v8 {
namespace internal {

RUNTIME_FUNCTION(Runtime_Add) {
  HandleScope scope(isolate);
  DCHECK_EQ(2, args.length());
15 16
  Handle<Object> lhs = args.at(0);
  Handle<Object> rhs = args.at(1);
17
  RETURN_RESULT_OR_FAILURE(isolate, Object::Add(isolate, lhs, rhs));
18 19 20
}


21
RUNTIME_FUNCTION(Runtime_Equal) {
22 23
  HandleScope scope(isolate);
  DCHECK_EQ(2, args.length());
24 25
  Handle<Object> x = args.at(0);
  Handle<Object> y = args.at(1);
26
  Maybe<bool> result = Object::Equals(isolate, x, y);
27
  if (result.IsNothing()) return ReadOnlyRoots(isolate).exception();
28 29 30
  return isolate->heap()->ToBoolean(result.FromJust());
}

31
RUNTIME_FUNCTION(Runtime_NotEqual) {
32 33
  HandleScope scope(isolate);
  DCHECK_EQ(2, args.length());
34 35
  Handle<Object> x = args.at(0);
  Handle<Object> y = args.at(1);
36
  Maybe<bool> result = Object::Equals(isolate, x, y);
37
  if (result.IsNothing()) return ReadOnlyRoots(isolate).exception();
38 39 40
  return isolate->heap()->ToBoolean(!result.FromJust());
}

41
RUNTIME_FUNCTION(Runtime_StrictEqual) {
42 43
  SealHandleScope scope(isolate);
  DCHECK_EQ(2, args.length());
44 45
  Object x = args[0];
  Object y = args[1];
46
  return isolate->heap()->ToBoolean(x.StrictEquals(y));
47 48
}

49
RUNTIME_FUNCTION(Runtime_StrictNotEqual) {
50 51
  SealHandleScope scope(isolate);
  DCHECK_EQ(2, args.length());
52 53
  Object x = args[0];
  Object y = args[1];
54
  return isolate->heap()->ToBoolean(!x.StrictEquals(y));
55 56
}

57 58 59
RUNTIME_FUNCTION(Runtime_ReferenceEqual) {
  SealHandleScope scope(isolate);
  DCHECK_EQ(2, args.length());
60 61
  Object x = args[0];
  Object y = args[1];
62 63 64
  return isolate->heap()->ToBoolean(x == y);
}

65 66 67
RUNTIME_FUNCTION(Runtime_LessThan) {
  HandleScope scope(isolate);
  DCHECK_EQ(2, args.length());
68 69
  Handle<Object> x = args.at(0);
  Handle<Object> y = args.at(1);
70
  Maybe<bool> result = Object::LessThan(isolate, x, y);
71
  if (result.IsNothing()) return ReadOnlyRoots(isolate).exception();
72 73 74 75 76 77
  return isolate->heap()->ToBoolean(result.FromJust());
}

RUNTIME_FUNCTION(Runtime_GreaterThan) {
  HandleScope scope(isolate);
  DCHECK_EQ(2, args.length());
78 79
  Handle<Object> x = args.at(0);
  Handle<Object> y = args.at(1);
80
  Maybe<bool> result = Object::GreaterThan(isolate, x, y);
81
  if (result.IsNothing()) return ReadOnlyRoots(isolate).exception();
82 83 84 85 86 87
  return isolate->heap()->ToBoolean(result.FromJust());
}

RUNTIME_FUNCTION(Runtime_LessThanOrEqual) {
  HandleScope scope(isolate);
  DCHECK_EQ(2, args.length());
88 89
  Handle<Object> x = args.at(0);
  Handle<Object> y = args.at(1);
90
  Maybe<bool> result = Object::LessThanOrEqual(isolate, x, y);
91
  if (result.IsNothing()) return ReadOnlyRoots(isolate).exception();
92 93 94 95 96 97
  return isolate->heap()->ToBoolean(result.FromJust());
}

RUNTIME_FUNCTION(Runtime_GreaterThanOrEqual) {
  HandleScope scope(isolate);
  DCHECK_EQ(2, args.length());
98 99
  Handle<Object> x = args.at(0);
  Handle<Object> y = args.at(1);
100
  Maybe<bool> result = Object::GreaterThanOrEqual(isolate, x, y);
101
  if (result.IsNothing()) return ReadOnlyRoots(isolate).exception();
102 103 104
  return isolate->heap()->ToBoolean(result.FromJust());
}

105 106
}  // namespace internal
}  // namespace v8