From 30213757d9f45b20bbb9b29ff0f673342f41eae1 Mon Sep 17 00:00:00 2001 From: Ashok Menon Date: Thu, 8 Dec 2016 16:23:35 -0800 Subject: [PATCH] Making CompiledSourceError a C enum, to keep `JSBase.h` as a C header Reviewed By: javache Differential Revision: D4299281 fbshipit-source-id: 14cdc6d4502a70300919dc6a98a5f274076134c7 --- ReactCommon/cxxreact/JSCExecutor.cpp | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/ReactCommon/cxxreact/JSCExecutor.cpp b/ReactCommon/cxxreact/JSCExecutor.cpp index 6e57f5a4280..6383d26fb7a 100644 --- a/ReactCommon/cxxreact/JSCExecutor.cpp +++ b/ReactCommon/cxxreact/JSCExecutor.cpp @@ -382,24 +382,26 @@ void JSCExecutor::loadApplicationScript( JSCompiledSourceError jsError; auto bcSourceCode = JSCreateCompiledSourceCode(fd, jsSourceURL, &jsError); - if (jsError == JSCompiledSourceErrorOnRead || - jsError == JSCompiledSourceErrorNotCompiled) { + switch (jsError) { + case JSCompiledSourceErrorOnRead: + case JSCompiledSourceErrorNotCompiled: // Not bytecode, fall through. return JSExecutor::loadApplicationScript(fd, sourceURL); - } else if (jsError == JSCompiledSourceErrorVersionMismatch) { + + case JSCompiledSourceErrorVersionMismatch: throw std::runtime_error("Compiled Source Version Mismatch"); + + case JSCompiledSourceErrorNone: + folly::throwOnFail( + bcSourceCode != nullptr, + "Unexpected error opening compiled bundle" + ); + break; + + default: + throw std::runtime_error("Unhandled Compiled Source Error"); } - folly::throwOnFail( - jsError == JSCompiledSourceErrorNone, - "Unhandled Compiled Source Error" - ); - - folly::throwOnFail( - bcSourceCode != nullptr, - "Unexpected error opening compiled bundle" - ); - ReactMarker::logMarker("RUN_JS_BUNDLE_START"); evaluateSourceCode(m_context, bcSourceCode, jsSourceURL);