Skip to content

Commit

Permalink
nf: lib improve
Browse files Browse the repository at this point in the history
  • Loading branch information
bibibong committed Jun 25, 2018
2 parents 7843312 + 19ac23f commit 7470724
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
23 changes: 21 additions & 2 deletions nf/nvm/v8/lib/1.0.0/bignumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
;(function (globalObj) {
'use strict';

const ErrIsNaNOrInfinity = new Error("NaN or Infinity");
const NaNAndInfinityCheckHeight = 504800;

function checkNaNOrInfinity(n) {
if (GlobalVars.Blockchain && GlobalVars.Blockchain.block && GlobalVars.Blockchain.block.height >= NaNAndInfinityCheckHeight) {
if (n.isNaN() || !n.isFinite()) {
throw ErrIsNaNOrInfinity;
}
}
}
/*
bignumber.js v4.1.0
A JavaScript library for arbitrary-precision arithmetic.
Expand Down Expand Up @@ -143,6 +153,14 @@

// CONSTRUCTOR

function BigNumber( n, b ) {
var x = BigNumberOrigin.apply(this, arguments);
if (x == undefined || typeof(x) != 'object') {
x = this;
}
checkNaNOrInfinity(x);
return x;
}

/*
* The BigNumber constructor and exported function.
Expand All @@ -151,7 +169,7 @@
* n {number|string|BigNumber} A numeric value.
* [b] {number} The base of n. Integer, 2 to 64 inclusive.
*/
function BigNumber( n, b ) {
function BigNumberOrigin( n, b ) {
var c, e, i, num, len, str,
x = this;

Expand Down Expand Up @@ -209,7 +227,7 @@
if ( ( num = typeof n == 'number' ) && n * 0 != 0 ||
!( new RegExp( '^-?' + ( c = '[' + ALPHABET.slice( 0, b ) + ']+' ) +
'(?:\\.' + c + ')?$',b < 37 ? 'i' : '' ) ).test(str) ) {
return parseNumeric( x, str, num, b );
return parseNumeric( x, str, num, b );
}

if (num) {
Expand Down Expand Up @@ -309,6 +327,7 @@
}

id = 0;

}


Expand Down
3 changes: 3 additions & 0 deletions nf/nvm/v8/lib/1.0.0/execution_env.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,15 @@ const require = (function (global) {
return curry(require_func, globalModule);
})(this);

const GlobalVars = {};

const console = require('console.js');
const ContractStorage = require('storage.js');
const LocalContractStorage = ContractStorage.lcs;
const GlobalContractStorage = ContractStorage.gcs;
const BigNumber = require('bignumber.js');
const Blockchain = require('blockchain.js');
GlobalVars.Blockchain = Blockchain;
const Event = require('event.js');

var Date = require('date.js');
Expand Down
3 changes: 3 additions & 0 deletions nf/nvm/v8/lib/1.0.5/execution_env.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ const require = (function (global) {
return curry(require_func, globalModule);
})(this);

const GlobalVars = {};

const console = require('console.js');
const Event = require('event.js');
const ContractStorage = require('storage.js');
Expand All @@ -107,6 +109,7 @@ const GlobalContractStorage = ContractStorage.gcs;
const BigNumber = require('bignumber.js');
const Uint = require('uint.js');
const Blockchain = require('blockchain.js');
GlobalVars.Blockchain = Blockchain;

var Date = require('date.js');
Math.random = require('random.js');
1 change: 1 addition & 0 deletions nf/nvm/v8/lib/1.0.5/uint.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const MAX_UINTS = {

class Uint {
constructor(n, b, s) {

Object.defineProperties(this, {
_inner: {
value: new BigNumber(n, b)
Expand Down

0 comments on commit 7470724

Please sign in to comment.