File tree 1 file changed +8
-3
lines changed
1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -647,6 +647,13 @@ var bigInt = (function (undefined) {
647
647
return y ;
648
648
} ;
649
649
SmallInteger . prototype . pow = BigInteger . prototype . pow ;
650
+
651
+ var pow ;
652
+ if ( supportsNativeBigInt ) {
653
+ // forced to use eval because ** is a syntax error on pre-ECMAScript2017 environments.
654
+ pow = eval ( "(a,b)=>a**b" ) ;
655
+ }
656
+
650
657
NativeBigInt . prototype . pow = function ( v ) {
651
658
var n = parseValue ( v ) ;
652
659
var a = this . value , b = n . value ;
@@ -655,9 +662,7 @@ var bigInt = (function (undefined) {
655
662
if ( a === BigInt ( 1 ) ) return Integer [ 1 ] ;
656
663
if ( a === BigInt ( - 1 ) ) return n . isEven ( ) ? Integer [ 1 ] : Integer [ - 1 ] ;
657
664
if ( n . isNegative ( ) ) return new NativeBigInt ( BigInt ( 0 ) ) ;
658
- // forced to use eval because ** is a syntax error on pre-ECMAScript2017 environments.
659
- // should be fine w.r.t. security because parseValue(v) will throw an error if v is a malicious string.
660
- return new NativeBigInt ( eval ( "BigInt('" + a + "') ** BigInt('" + b + "')" ) ) ;
665
+ return new NativeBigInt ( pow ( a , b ) ) ;
661
666
}
662
667
663
668
BigInteger . prototype . modPow = function ( exp , mod ) {
You can’t perform that action at this time.
0 commit comments