runtime-operators.cc 3.61 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
#include "src/logging/counters.h"
9 10 11 12 13 14 15 16 17 18
#include "src/runtime/runtime-utils.h"

namespace v8 {
namespace internal {

RUNTIME_FUNCTION(Runtime_Add) {
  HandleScope scope(isolate);
  DCHECK_EQ(2, args.length());
  CONVERT_ARG_HANDLE_CHECKED(Object, lhs, 0);
  CONVERT_ARG_HANDLE_CHECKED(Object, rhs, 1);
19
  RETURN_RESULT_OR_FAILURE(isolate, Object::Add(isolate, lhs, rhs));
20 21 22
}


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

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

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

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

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

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

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

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

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

107 108
}  // namespace internal
}  // namespace v8