Home | History | Annotate | Download | only in runtime
      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 
     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   Handle<Object> result;
     18   ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result,
     19                                      Object::Multiply(isolate, lhs, rhs));
     20   return *result;
     21 }
     22 
     23 
     24 RUNTIME_FUNCTION(Runtime_Multiply_Strong) {
     25   HandleScope scope(isolate);
     26   DCHECK_EQ(2, args.length());
     27   CONVERT_ARG_HANDLE_CHECKED(Object, lhs, 0);
     28   CONVERT_ARG_HANDLE_CHECKED(Object, rhs, 1);
     29   Handle<Object> result;
     30   ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
     31       isolate, result, Object::Multiply(isolate, lhs, rhs, Strength::STRONG));
     32   return *result;
     33 }
     34 
     35 
     36 RUNTIME_FUNCTION(Runtime_Divide) {
     37   HandleScope scope(isolate);
     38   DCHECK_EQ(2, args.length());
     39   CONVERT_ARG_HANDLE_CHECKED(Object, lhs, 0);
     40   CONVERT_ARG_HANDLE_CHECKED(Object, rhs, 1);
     41   Handle<Object> result;
     42   ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result,
     43                                      Object::Divide(isolate, lhs, rhs));
     44   return *result;
     45 }
     46 
     47 
     48 RUNTIME_FUNCTION(Runtime_Divide_Strong) {
     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   Handle<Object> result;
     54   ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
     55       isolate, result, Object::Divide(isolate, lhs, rhs, Strength::STRONG));
     56   return *result;
     57 }
     58 
     59 
     60 RUNTIME_FUNCTION(Runtime_Modulus) {
     61   HandleScope scope(isolate);
     62   DCHECK_EQ(2, args.length());
     63   CONVERT_ARG_HANDLE_CHECKED(Object, lhs, 0);
     64   CONVERT_ARG_HANDLE_CHECKED(Object, rhs, 1);
     65   Handle<Object> result;
     66   ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result,
     67                                      Object::Modulus(isolate, lhs, rhs));
     68   return *result;
     69 }
     70 
     71 
     72 RUNTIME_FUNCTION(Runtime_Modulus_Strong) {
     73   HandleScope scope(isolate);
     74   DCHECK_EQ(2, args.length());
     75   CONVERT_ARG_HANDLE_CHECKED(Object, lhs, 0);
     76   CONVERT_ARG_HANDLE_CHECKED(Object, rhs, 1);
     77   Handle<Object> result;
     78   ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
     79       isolate, result, Object::Modulus(isolate, lhs, rhs, Strength::STRONG));
     80   return *result;
     81 }
     82 
     83 
     84 RUNTIME_FUNCTION(Runtime_Add) {
     85   HandleScope scope(isolate);
     86   DCHECK_EQ(2, args.length());
     87   CONVERT_ARG_HANDLE_CHECKED(Object, lhs, 0);
     88   CONVERT_ARG_HANDLE_CHECKED(Object, rhs, 1);
     89   Handle<Object> result;
     90   ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result,
     91                                      Object::Add(isolate, lhs, rhs));
     92   return *result;
     93 }
     94 
     95 
     96 RUNTIME_FUNCTION(Runtime_Add_Strong) {
     97   HandleScope scope(isolate);
     98   DCHECK_EQ(2, args.length());
     99   CONVERT_ARG_HANDLE_CHECKED(Object, lhs, 0);
    100   CONVERT_ARG_HANDLE_CHECKED(Object, rhs, 1);
    101   Handle<Object> result;
    102   ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
    103       isolate, result, Object::Add(isolate, lhs, rhs, Strength::STRONG));
    104   return *result;
    105 }
    106 
    107 
    108 RUNTIME_FUNCTION(Runtime_Subtract) {
    109   HandleScope scope(isolate);
    110   DCHECK_EQ(2, args.length());
    111   CONVERT_ARG_HANDLE_CHECKED(Object, lhs, 0);
    112   CONVERT_ARG_HANDLE_CHECKED(Object, rhs, 1);
    113   Handle<Object> result;
    114   ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result,
    115                                      Object::Subtract(isolate, lhs, rhs));
    116   return *result;
    117 }
    118 
    119 
    120 RUNTIME_FUNCTION(Runtime_Subtract_Strong) {
    121   HandleScope scope(isolate);
    122   DCHECK_EQ(2, args.length());
    123   CONVERT_ARG_HANDLE_CHECKED(Object, lhs, 0);
    124   CONVERT_ARG_HANDLE_CHECKED(Object, rhs, 1);
    125   Handle<Object> result;
    126   ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
    127       isolate, result, Object::Subtract(isolate, lhs, rhs, Strength::STRONG));
    128   return *result;
    129 }
    130 
    131 
    132 RUNTIME_FUNCTION(Runtime_ShiftLeft) {
    133   HandleScope scope(isolate);
    134   DCHECK_EQ(2, args.length());
    135   CONVERT_ARG_HANDLE_CHECKED(Object, lhs, 0);
    136   CONVERT_ARG_HANDLE_CHECKED(Object, rhs, 1);
    137   Handle<Object> result;
    138   ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result,
    139                                      Object::ShiftLeft(isolate, lhs, rhs));
    140   return *result;
    141 }
    142 
    143 
    144 RUNTIME_FUNCTION(Runtime_ShiftLeft_Strong) {
    145   HandleScope scope(isolate);
    146   DCHECK_EQ(2, args.length());
    147   CONVERT_ARG_HANDLE_CHECKED(Object, lhs, 0);
    148   CONVERT_ARG_HANDLE_CHECKED(Object, rhs, 1);
    149   Handle<Object> result;
    150   ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
    151       isolate, result, Object::ShiftLeft(isolate, lhs, rhs, Strength::STRONG));
    152   return *result;
    153 }
    154 
    155 
    156 RUNTIME_FUNCTION(Runtime_ShiftRight) {
    157   HandleScope scope(isolate);
    158   DCHECK_EQ(2, args.length());
    159   CONVERT_ARG_HANDLE_CHECKED(Object, lhs, 0);
    160   CONVERT_ARG_HANDLE_CHECKED(Object, rhs, 1);
    161   Handle<Object> result;
    162   ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result,
    163                                      Object::ShiftRight(isolate, lhs, rhs));
    164   return *result;
    165 }
    166 
    167 
    168 RUNTIME_FUNCTION(Runtime_ShiftRight_Strong) {
    169   HandleScope scope(isolate);
    170   DCHECK_EQ(2, args.length());
    171   CONVERT_ARG_HANDLE_CHECKED(Object, lhs, 0);
    172   CONVERT_ARG_HANDLE_CHECKED(Object, rhs, 1);
    173   Handle<Object> result;
    174   ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
    175       isolate, result, Object::ShiftRight(isolate, lhs, rhs, Strength::STRONG));
    176   return *result;
    177 }
    178 
    179 
    180 RUNTIME_FUNCTION(Runtime_ShiftRightLogical) {
    181   HandleScope scope(isolate);
    182   DCHECK_EQ(2, args.length());
    183   CONVERT_ARG_HANDLE_CHECKED(Object, lhs, 0);
    184   CONVERT_ARG_HANDLE_CHECKED(Object, rhs, 1);
    185   Handle<Object> result;
    186   ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
    187       isolate, result, Object::ShiftRightLogical(isolate, lhs, rhs));
    188   return *result;
    189 }
    190 
    191 
    192 RUNTIME_FUNCTION(Runtime_ShiftRightLogical_Strong) {
    193   HandleScope scope(isolate);
    194   DCHECK_EQ(2, args.length());
    195   CONVERT_ARG_HANDLE_CHECKED(Object, lhs, 0);
    196   CONVERT_ARG_HANDLE_CHECKED(Object, rhs, 1);
    197   Handle<Object> result;
    198   ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
    199       isolate, result,
    200       Object::ShiftRightLogical(isolate, lhs, rhs, Strength::STRONG));
    201   return *result;
    202 }
    203 
    204 
    205 RUNTIME_FUNCTION(Runtime_BitwiseAnd) {
    206   HandleScope scope(isolate);
    207   DCHECK_EQ(2, args.length());
    208   CONVERT_ARG_HANDLE_CHECKED(Object, lhs, 0);
    209   CONVERT_ARG_HANDLE_CHECKED(Object, rhs, 1);
    210   Handle<Object> result;
    211   ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result,
    212                                      Object::BitwiseAnd(isolate, lhs, rhs));
    213   return *result;
    214 }
    215 
    216 
    217 RUNTIME_FUNCTION(Runtime_BitwiseAnd_Strong) {
    218   HandleScope scope(isolate);
    219   DCHECK_EQ(2, args.length());
    220   CONVERT_ARG_HANDLE_CHECKED(Object, lhs, 0);
    221   CONVERT_ARG_HANDLE_CHECKED(Object, rhs, 1);
    222   Handle<Object> result;
    223   ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
    224       isolate, result, Object::BitwiseAnd(isolate, lhs, rhs, Strength::STRONG));
    225   return *result;
    226 }
    227 
    228 
    229 RUNTIME_FUNCTION(Runtime_BitwiseOr) {
    230   HandleScope scope(isolate);
    231   DCHECK_EQ(2, args.length());
    232   CONVERT_ARG_HANDLE_CHECKED(Object, lhs, 0);
    233   CONVERT_ARG_HANDLE_CHECKED(Object, rhs, 1);
    234   Handle<Object> result;
    235   ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result,
    236                                      Object::BitwiseOr(isolate, lhs, rhs));
    237   return *result;
    238 }
    239 
    240 
    241 RUNTIME_FUNCTION(Runtime_BitwiseOr_Strong) {
    242   HandleScope scope(isolate);
    243   DCHECK_EQ(2, args.length());
    244   CONVERT_ARG_HANDLE_CHECKED(Object, lhs, 0);
    245   CONVERT_ARG_HANDLE_CHECKED(Object, rhs, 1);
    246   Handle<Object> result;
    247   ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
    248       isolate, result, Object::BitwiseOr(isolate, lhs, rhs, Strength::STRONG));
    249   return *result;
    250 }
    251 
    252 
    253 RUNTIME_FUNCTION(Runtime_BitwiseXor) {
    254   HandleScope scope(isolate);
    255   DCHECK_EQ(2, args.length());
    256   CONVERT_ARG_HANDLE_CHECKED(Object, lhs, 0);
    257   CONVERT_ARG_HANDLE_CHECKED(Object, rhs, 1);
    258   Handle<Object> result;
    259   ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result,
    260                                      Object::BitwiseXor(isolate, lhs, rhs));
    261   return *result;
    262 }
    263 
    264 
    265 RUNTIME_FUNCTION(Runtime_BitwiseXor_Strong) {
    266   HandleScope scope(isolate);
    267   DCHECK_EQ(2, args.length());
    268   CONVERT_ARG_HANDLE_CHECKED(Object, lhs, 0);
    269   CONVERT_ARG_HANDLE_CHECKED(Object, rhs, 1);
    270   Handle<Object> result;
    271   ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
    272       isolate, result, Object::BitwiseXor(isolate, lhs, rhs, Strength::STRONG));
    273   return *result;
    274 }
    275 
    276 }  // namespace internal
    277 }  // namespace v8
    278