github.com/igggame/nebulas-go@v2.1.0+incompatible/nf/nvm/v8/lib/nvm_error.h (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 6 // modify 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 17 // <http://www.gnu.org/licenses/>. 18 // 19 20 #ifndef _NEBULAS_NF_NVM_V8_ERROR_H_ 21 #define _NEBULAS_NF_NVM_V8_ERROR_H_ 22 23 /* 24 success or crash 25 */ 26 #define REPORT_UNEXPECTED_ERR() do{ \ 27 if (NULL == isolate) {\ 28 LogFatalf("Unexpected Error: invalid argument, ioslate is NULL");\ 29 }\ 30 Local<Context> context = isolate->GetCurrentContext();\ 31 V8Engine *e = GetV8EngineInstance(context);\ 32 if (NULL == e) {\ 33 LogFatalf("Unexpected Error: failed to get V8Engine");\ 34 }\ 35 TerminateExecution(e);\ 36 e->is_unexpected_error_happen = true;\ 37 } while(0) 38 39 #define DEAL_ERROR_FROM_GOLANG(err) do {\ 40 if (NVM_UNEXPECTED_ERR == err || (NVM_EXCEPTION_ERR == err && NULL == exceptionInfo) ||\ 41 (NVM_SUCCESS == err && NULL == result)) {\ 42 info.GetReturnValue().SetNull();\ 43 REPORT_UNEXPECTED_ERR();\ 44 } else if (NVM_EXCEPTION_ERR == err) {\ 45 isolate->ThrowException(String::NewFromUtf8(isolate, exceptionInfo));\ 46 } else if (NVM_SUCCESS == err) {\ 47 info.GetReturnValue().Set(String::NewFromUtf8(isolate, result));\ 48 } else {\ 49 info.GetReturnValue().SetNull();\ 50 REPORT_UNEXPECTED_ERR();\ 51 }\ 52 } while(0) 53 54 enum nvmErrno { 55 NVM_SUCCESS = 0, 56 NVM_EXCEPTION_ERR = -1, 57 NVM_MEM_LIMIT_ERR = -2, 58 NVM_GAS_LIMIT_ERR = -3, 59 NVM_UNEXPECTED_ERR = -4, 60 NVM_EXE_TIMEOUT_ERR = -5, 61 NVM_INNER_EXE_ERR = -6, 62 }; 63 64 #endif //_NEBULAS_NF_NVM_V8_ENGINE_ERROR_H_