github.com/igggame/nebulas-go@v2.1.0+incompatible/nf/nvm/v8/lib/1.0.5/execution_env.js (about) 1 // Copyright (C) 2017 go-nebulas authors 2 // 3 // This file is part of the go-nebulas library. 4 // 5 // the go-nebulas library is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // the go-nebulas library is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with the go-nebulas library. If not, see <http://www.gnu.org/licenses/>. 17 // 18 19 Function.prototype.toString = function(){return "";}; 20 21 const require = (function (global) { 22 var PathDoubleDotRegex = /\.{2}\//; 23 var modules = new Map(); 24 25 var Module = function (id, parent) { 26 this.exports = {}; 27 Object.defineProperty(this, "id", { 28 enumerable: false, 29 configurable: false, 30 writable: false, 31 value: id 32 }); 33 34 if (parent && !(parent instanceof Module)) { 35 throw new Error("parent parameter of Module construction must be instance of Module or null."); 36 } 37 }; 38 39 Module.prototype = { 40 _load: function () { 41 var $this = this, 42 native_req_func = _native_require(this.id), 43 temp_global = Object.create(global); 44 native_req_func.call(temp_global, this.exports, this, curry(require_func, $this)); 45 }, 46 _resolve: function (id) { 47 if (PathDoubleDotRegex.test(id)) { 48 throw new Error("invalid path '../'"); 49 } 50 id = "lib/" + id; 51 var paths = []; 52 53 for (const p of id.split("/")) { 54 if (p == "" || p == ".") { 55 continue; 56 } else { 57 paths.push(p); 58 } 59 } 60 61 if (paths.length > 0 && paths[0] == "") { 62 paths.shift(); 63 } 64 65 return paths.join("/"); 66 }, 67 }; 68 69 var globalModule = new Module("main.js"); 70 modules.set(globalModule.id, globalModule); 71 72 function require_func(parent, id) { 73 id = parent._resolve(id); 74 var module = modules.get(id); 75 if (!module || !(module instanceof Module)) { 76 module = new Module(id, parent); 77 module._load(); 78 modules.set(id, module); 79 } 80 return module.exports; 81 }; 82 83 function curry(uncurried) { 84 var parameters = Array.prototype.slice.call(arguments, 1); 85 var f = function () { 86 return uncurried.apply(this, parameters.concat( 87 Array.prototype.slice.call(arguments, 0) 88 )); 89 }; 90 Object.defineProperty(f, "main", { 91 enumerable: true, 92 configurable: false, 93 writable: false, 94 value: globalModule, 95 }); 96 return f; 97 }; 98 99 return curry(require_func, globalModule); 100 })(this); 101 102 const GlobalVars = {}; 103 104 const console = require('console.js'); 105 const Event = require('event.js'); 106 const ContractStorage = require('storage.js'); 107 const LocalContractStorage = ContractStorage.lcs; 108 const GlobalContractStorage = ContractStorage.gcs; 109 const BigNumber = require('bignumber.js'); 110 const Uint = require('uint.js'); 111 const Blockchain = require('blockchain.js'); 112 GlobalVars.Blockchain = Blockchain; 113 114 var Date = require('date.js'); 115 Math.random = require('random.js');