runtime-operators.cc 3.36 KB
Newer Older
1 2 3 4 5
// 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.

#include "src/arguments.h"
6
#include "src/counters.h"
7
#include "src/heap/heap-inl.h"  // For ToBoolean. TODO(jkummerow): Drop.
8 9 10 11 12 13 14 15 16 17 18
#include "src/isolate-inl.h"
#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 48 49 50
  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->StrictEquals(y));
}

51
RUNTIME_FUNCTION(Runtime_StrictNotEqual) {
52 53 54 55 56 57 58
  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->StrictEquals(y));
}

59 60 61 62 63
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);
64
  Maybe<bool> result = Object::LessThan(isolate, x, y);
65
  if (result.IsNothing()) return ReadOnlyRoots(isolate).exception();
66 67 68 69 70 71 72 73
  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);
74
  Maybe<bool> result = Object::GreaterThan(isolate, x, y);
75
  if (result.IsNothing()) return ReadOnlyRoots(isolate).exception();
76 77 78 79 80 81 82 83
  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);
84
  Maybe<bool> result = Object::LessThanOrEqual(isolate, x, y);
85
  if (result.IsNothing()) return ReadOnlyRoots(isolate).exception();
86 87 88 89 90 91 92 93
  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);
94
  Maybe<bool> result = Object::GreaterThanOrEqual(isolate, x, y);
95
  if (result.IsNothing()) return ReadOnlyRoots(isolate).exception();
96 97 98
  return isolate->heap()->ToBoolean(result.FromJust());
}

99 100
}  // namespace internal
}  // namespace v8