LCOV - code coverage report
Current view: top level - src/runtime - runtime-bigint.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 70 72 97.2 %
Date: 2019-04-17 Functions: 12 23 52.2 %

          Line data    Source code
       1             : // Copyright 2017 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-inl.h"
       6             : #include "src/counters.h"
       7             : #include "src/objects-inl.h"
       8             : #include "src/objects/bigint.h"
       9             : #include "src/runtime/runtime-utils.h"
      10             : 
      11             : namespace v8 {
      12             : namespace internal {
      13             : 
      14        2772 : RUNTIME_FUNCTION(Runtime_BigIntCompareToBigInt) {
      15             :   SealHandleScope shs(isolate);
      16             :   DCHECK_EQ(3, args.length());
      17        1386 :   CONVERT_ARG_HANDLE_CHECKED(Smi, mode, 0);
      18        1386 :   CONVERT_ARG_HANDLE_CHECKED(BigInt, lhs, 1);
      19        1386 :   CONVERT_ARG_HANDLE_CHECKED(BigInt, rhs, 2);
      20        1386 :   bool result = ComparisonResultToBool(static_cast<Operation>(mode->value()),
      21        1386 :                                        BigInt::CompareToBigInt(lhs, rhs));
      22        2772 :   return *isolate->factory()->ToBoolean(result);
      23             : }
      24             : 
      25        1440 : RUNTIME_FUNCTION(Runtime_BigIntCompareToNumber) {
      26             :   SealHandleScope shs(isolate);
      27             :   DCHECK_EQ(3, args.length());
      28         720 :   CONVERT_ARG_HANDLE_CHECKED(Smi, mode, 0);
      29         720 :   CONVERT_ARG_HANDLE_CHECKED(BigInt, lhs, 1);
      30             :   CONVERT_ARG_HANDLE_CHECKED(Object, rhs, 2);
      31         720 :   bool result = ComparisonResultToBool(static_cast<Operation>(mode->value()),
      32         720 :                                        BigInt::CompareToNumber(lhs, rhs));
      33        1440 :   return *isolate->factory()->ToBoolean(result);
      34             : }
      35             : 
      36         504 : RUNTIME_FUNCTION(Runtime_BigIntCompareToString) {
      37             :   HandleScope scope(isolate);
      38             :   DCHECK_EQ(3, args.length());
      39         252 :   CONVERT_ARG_HANDLE_CHECKED(Smi, mode, 0);
      40         252 :   CONVERT_ARG_HANDLE_CHECKED(BigInt, lhs, 1);
      41         252 :   CONVERT_ARG_HANDLE_CHECKED(String, rhs, 2);
      42             :   bool result =
      43         252 :       ComparisonResultToBool(static_cast<Operation>(mode->value()),
      44         252 :                              BigInt::CompareToString(isolate, lhs, rhs));
      45         504 :   return *isolate->factory()->ToBoolean(result);
      46             : }
      47             : 
      48       30024 : RUNTIME_FUNCTION(Runtime_BigIntEqualToBigInt) {
      49             :   SealHandleScope shs(isolate);
      50             :   DCHECK_EQ(2, args.length());
      51       15012 :   CONVERT_ARG_HANDLE_CHECKED(BigInt, lhs, 0);
      52       15012 :   CONVERT_ARG_HANDLE_CHECKED(BigInt, rhs, 1);
      53       15012 :   bool result = BigInt::EqualToBigInt(*lhs, *rhs);
      54       30024 :   return *isolate->factory()->ToBoolean(result);
      55             : }
      56             : 
      57        1728 : RUNTIME_FUNCTION(Runtime_BigIntEqualToNumber) {
      58             :   SealHandleScope shs(isolate);
      59             :   DCHECK_EQ(2, args.length());
      60         864 :   CONVERT_ARG_HANDLE_CHECKED(BigInt, lhs, 0);
      61             :   CONVERT_ARG_HANDLE_CHECKED(Object, rhs, 1);
      62         864 :   bool result = BigInt::EqualToNumber(lhs, rhs);
      63        1728 :   return *isolate->factory()->ToBoolean(result);
      64             : }
      65             : 
      66         666 : RUNTIME_FUNCTION(Runtime_BigIntEqualToString) {
      67             :   HandleScope scope(isolate);
      68             :   DCHECK_EQ(2, args.length());
      69         333 :   CONVERT_ARG_HANDLE_CHECKED(BigInt, lhs, 0);
      70         333 :   CONVERT_ARG_HANDLE_CHECKED(String, rhs, 1);
      71         333 :   bool result = BigInt::EqualToString(isolate, lhs, rhs);
      72         666 :   return *isolate->factory()->ToBoolean(result);
      73             : }
      74             : 
      75         566 : RUNTIME_FUNCTION(Runtime_BigIntToBoolean) {
      76             :   SealHandleScope shs(isolate);
      77             :   DCHECK_EQ(1, args.length());
      78         283 :   CONVERT_ARG_HANDLE_CHECKED(BigInt, bigint, 0);
      79         566 :   return *isolate->factory()->ToBoolean(bigint->ToBoolean());
      80             : }
      81             : 
      82         936 : RUNTIME_FUNCTION(Runtime_BigIntToNumber) {
      83             :   HandleScope scope(isolate);
      84             :   DCHECK_EQ(1, args.length());
      85         468 :   CONVERT_ARG_HANDLE_CHECKED(BigInt, x, 0);
      86         936 :   return *BigInt::ToNumber(isolate, x);
      87             : }
      88             : 
      89        1006 : RUNTIME_FUNCTION(Runtime_ToBigInt) {
      90             :   HandleScope scope(isolate);
      91             :   DCHECK_EQ(1, args.length());
      92             :   CONVERT_ARG_HANDLE_CHECKED(Object, x, 0);
      93        1006 :   RETURN_RESULT_OR_FAILURE(isolate, BigInt::FromObject(isolate, x));
      94             : }
      95             : 
      96      200368 : RUNTIME_FUNCTION(Runtime_BigIntBinaryOp) {
      97             :   HandleScope scope(isolate);
      98             :   DCHECK_EQ(3, args.length());
      99             :   CONVERT_ARG_HANDLE_CHECKED(Object, left_obj, 0);
     100             :   CONVERT_ARG_HANDLE_CHECKED(Object, right_obj, 1);
     101      100184 :   CONVERT_SMI_ARG_CHECKED(opcode, 2);
     102             :   Operation op = static_cast<Operation>(opcode);
     103             : 
     104      198460 :   if (!left_obj->IsBigInt() || !right_obj->IsBigInt()) {
     105        6240 :     THROW_NEW_ERROR_RETURN_FAILURE(
     106             :         isolate, NewTypeError(MessageTemplate::kBigIntMixedTypes));
     107             :   }
     108             :   Handle<BigInt> left(Handle<BigInt>::cast(left_obj));
     109             :   Handle<BigInt> right(Handle<BigInt>::cast(right_obj));
     110             :   MaybeHandle<BigInt> result;
     111       97064 :   switch (op) {
     112             :     case Operation::kAdd:
     113       46548 :       result = BigInt::Add(isolate, left, right);
     114             :       break;
     115             :     case Operation::kSubtract:
     116         810 :       result = BigInt::Subtract(isolate, left, right);
     117             :       break;
     118             :     case Operation::kMultiply:
     119       46359 :       result = BigInt::Multiply(isolate, left, right);
     120             :       break;
     121             :     case Operation::kDivide:
     122         392 :       result = BigInt::Divide(isolate, left, right);
     123             :       break;
     124             :     case Operation::kModulus:
     125         387 :       result = BigInt::Remainder(isolate, left, right);
     126             :       break;
     127             :     case Operation::kExponentiate:
     128         633 :       result = BigInt::Exponentiate(isolate, left, right);
     129             :       break;
     130             :     case Operation::kBitwiseAnd:
     131         369 :       result = BigInt::BitwiseAnd(isolate, left, right);
     132             :       break;
     133             :     case Operation::kBitwiseOr:
     134         342 :       result = BigInt::BitwiseOr(isolate, left, right);
     135             :       break;
     136             :     case Operation::kBitwiseXor:
     137         342 :       result = BigInt::BitwiseXor(isolate, left, right);
     138             :       break;
     139             :     case Operation::kShiftLeft:
     140         423 :       result = BigInt::LeftShift(isolate, left, right);
     141             :       break;
     142             :     case Operation::kShiftRight:
     143         342 :       result = BigInt::SignedRightShift(isolate, left, right);
     144             :       break;
     145             :     case Operation::kShiftRightLogical:
     146         117 :       result = BigInt::UnsignedRightShift(isolate, left, right);
     147             :       break;
     148             :     default:
     149           0 :       UNREACHABLE();
     150             :   }
     151       97064 :   RETURN_RESULT_OR_FAILURE(isolate, result);
     152             : }
     153             : 
     154       15288 : RUNTIME_FUNCTION(Runtime_BigIntUnaryOp) {
     155             :   HandleScope scope(isolate);
     156             :   DCHECK_EQ(2, args.length());
     157        7644 :   CONVERT_ARG_HANDLE_CHECKED(BigInt, x, 0);
     158        7644 :   CONVERT_SMI_ARG_CHECKED(opcode, 1);
     159             :   Operation op = static_cast<Operation>(opcode);
     160             : 
     161             :   MaybeHandle<BigInt> result;
     162        7644 :   switch (op) {
     163             :     case Operation::kBitwiseNot:
     164         342 :       result = BigInt::BitwiseNot(isolate, x);
     165             :       break;
     166             :     case Operation::kNegate:
     167        6338 :       result = BigInt::UnaryMinus(isolate, x);
     168             :       break;
     169             :     case Operation::kIncrement:
     170         482 :       result = BigInt::Increment(isolate, x);
     171             :       break;
     172             :     case Operation::kDecrement:
     173         482 :       result = BigInt::Decrement(isolate, x);
     174             :       break;
     175             :     default:
     176           0 :       UNREACHABLE();
     177             :   }
     178        7644 :   RETURN_RESULT_OR_FAILURE(isolate, result);
     179             : }
     180             : 
     181             : }  // namespace internal
     182      121996 : }  // namespace v8

Generated by: LCOV version 1.10