github.com/igggame/nebulas-go@v2.1.0+incompatible/nf/nvm/v8/lib/1.0.0/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 PathRegexForNotLibFile = /^\.{0,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 var paths = this.id.split("/"); 48 paths.pop(); 49 50 if (!PathRegexForNotLibFile.test(id)) { 51 id = "lib/" + id; 52 paths = []; 53 } 54 55 for (const p of id.split("/")) { 56 if (p == "" || p == ".") { 57 continue; 58 } else if (p == ".." && paths.length > 0) { 59 paths.pop(); 60 } else { 61 paths.push(p); 62 } 63 } 64 65 if (paths.length > 0 && paths[0] == "") { 66 paths.shift(); 67 } 68 69 return paths.join("/"); 70 }, 71 }; 72 73 var globalModule = new Module("main.js"); 74 modules.set(globalModule.id, globalModule); 75 76 function require_func(parent, id) { 77 id = parent._resolve(id); 78 var module = modules.get(id); 79 if (!module || !(module instanceof Module)) { 80 module = new Module(id, parent); 81 module._load(); 82 modules.set(id, module); 83 } 84 return module.exports; 85 }; 86 87 function curry(uncurried) { 88 var parameters = Array.prototype.slice.call(arguments, 1); 89 var f = function () { 90 return uncurried.apply(this, parameters.concat( 91 Array.prototype.slice.call(arguments, 0) 92 )); 93 }; 94 Object.defineProperty(f, "main", { 95 enumerable: true, 96 configurable: false, 97 writable: false, 98 value: globalModule, 99 }); 100 return f; 101 }; 102 103 return curry(require_func, globalModule); 104 })(this); 105 106 const GlobalVars = {}; 107 108 const console = require('console.js'); 109 const ContractStorage = require('storage.js'); 110 const LocalContractStorage = ContractStorage.lcs; 111 const GlobalContractStorage = ContractStorage.gcs; 112 const BigNumber = require('bignumber.js'); 113 const Blockchain = require('blockchain.js'); 114 GlobalVars.Blockchain = Blockchain; 115 const Event = require('event.js'); 116 117 var Date = require('date.js'); 118 Math.random = require('random.js');