Add some (possibly temporary) noexcept/throw specifications
Reviewed By: mhorowitz Differential Revision: D3435575 fbshipit-source-id: 93b60a5d6890d21db6b3726784bc6fd868af5ba0
This commit is contained in:
parent
b4a4c71a68
commit
1731598428
|
@ -93,7 +93,7 @@ static JSValueRef nativeInjectHMRUpdate(
|
|||
static std::string executeJSCallWithJSC(
|
||||
JSGlobalContextRef ctx,
|
||||
const std::string& methodName,
|
||||
const std::vector<folly::dynamic>& arguments) {
|
||||
const std::vector<folly::dynamic>& arguments) throw(JSException) {
|
||||
SystraceSection s("JSCExecutor.executeJSCall",
|
||||
"method", methodName);
|
||||
|
||||
|
@ -115,7 +115,7 @@ std::unique_ptr<JSExecutor> JSCExecutorFactory::createJSExecutor(
|
|||
JSCExecutor::JSCExecutor(std::shared_ptr<ExecutorDelegate> delegate,
|
||||
std::shared_ptr<MessageQueueThread> messageQueueThread,
|
||||
const std::string& cacheDir,
|
||||
const folly::dynamic& jscConfig) :
|
||||
const folly::dynamic& jscConfig) throw(JSException) :
|
||||
m_delegate(delegate),
|
||||
m_deviceCacheDir(cacheDir),
|
||||
m_messageQueueThread(messageQueueThread),
|
||||
|
@ -199,7 +199,7 @@ void JSCExecutor::destroy() {
|
|||
});
|
||||
}
|
||||
|
||||
void JSCExecutor::initOnJSVMThread() {
|
||||
void JSCExecutor::initOnJSVMThread() throw(JSException) {
|
||||
SystraceSection s("JSCExecutor.initOnJSVMThread");
|
||||
|
||||
#if defined(WITH_FB_JSC_TUNING)
|
||||
|
@ -269,7 +269,7 @@ void JSCExecutor::terminateOnJSVMThread() {
|
|||
m_context = nullptr;
|
||||
}
|
||||
|
||||
void JSCExecutor::loadApplicationScript(std::unique_ptr<const JSBigString> script, std::string sourceURL) {
|
||||
void JSCExecutor::loadApplicationScript(std::unique_ptr<const JSBigString> script, std::string sourceURL) throw(JSException) {
|
||||
SystraceSection s("JSCExecutor::loadApplicationScript",
|
||||
"sourceURL", sourceURL);
|
||||
|
||||
|
@ -300,14 +300,15 @@ void JSCExecutor::setJSModulesUnbundle(std::unique_ptr<JSModulesUnbundle> unbund
|
|||
m_unbundle = std::move(unbundle);
|
||||
}
|
||||
|
||||
void JSCExecutor::flush() {
|
||||
void JSCExecutor::flush() throw(JSException) {
|
||||
// TODO: Make this a first class function instead of evaling. #9317773
|
||||
std::string calls = executeJSCallWithJSC(m_context, "flushedQueue", std::vector<folly::dynamic>());
|
||||
m_delegate->callNativeModules(*this, std::move(calls), true);
|
||||
}
|
||||
|
||||
void JSCExecutor::callFunction(const std::string& moduleId, const std::string& methodId, const folly::dynamic& arguments) {
|
||||
void JSCExecutor::callFunction(const std::string& moduleId, const std::string& methodId, const folly::dynamic& arguments) throw(JSException) {
|
||||
// TODO: Make this a first class function instead of evaling. #9317773
|
||||
// TODO(cjhopman): This copies args.
|
||||
std::vector<folly::dynamic> call{
|
||||
moduleId,
|
||||
methodId,
|
||||
|
@ -317,8 +318,9 @@ void JSCExecutor::callFunction(const std::string& moduleId, const std::string& m
|
|||
m_delegate->callNativeModules(*this, std::move(calls), true);
|
||||
}
|
||||
|
||||
void JSCExecutor::invokeCallback(const double callbackId, const folly::dynamic& arguments) {
|
||||
void JSCExecutor::invokeCallback(const double callbackId, const folly::dynamic& arguments) throw(JSException) {
|
||||
// TODO: Make this a first class function instead of evaling. #9317773
|
||||
// TODO(cjhopman): This copies args.
|
||||
std::vector<folly::dynamic> call{
|
||||
(double) callbackId,
|
||||
std::move(arguments)
|
||||
|
@ -327,7 +329,7 @@ void JSCExecutor::invokeCallback(const double callbackId, const folly::dynamic&
|
|||
m_delegate->callNativeModules(*this, std::move(calls), true);
|
||||
}
|
||||
|
||||
void JSCExecutor::setGlobalVariable(std::string propName, std::unique_ptr<const JSBigString> jsonValue) {
|
||||
void JSCExecutor::setGlobalVariable(std::string propName, std::unique_ptr<const JSBigString> jsonValue) throw(JSException) {
|
||||
SystraceSection s("JSCExecutor.setGlobalVariable",
|
||||
"propName", propName);
|
||||
|
||||
|
|
|
@ -52,24 +52,24 @@ public:
|
|||
explicit JSCExecutor(std::shared_ptr<ExecutorDelegate> delegate,
|
||||
std::shared_ptr<MessageQueueThread> messageQueueThread,
|
||||
const std::string& cacheDir,
|
||||
const folly::dynamic& jscConfig);
|
||||
const folly::dynamic& jscConfig) throw(JSException);
|
||||
~JSCExecutor() override;
|
||||
|
||||
virtual void loadApplicationScript(
|
||||
std::unique_ptr<const JSBigString> script,
|
||||
std::string sourceURL) override;
|
||||
std::string sourceURL) throw(JSException) override;
|
||||
virtual void setJSModulesUnbundle(
|
||||
std::unique_ptr<JSModulesUnbundle> unbundle) override;
|
||||
virtual void callFunction(
|
||||
const std::string& moduleId,
|
||||
const std::string& methodId,
|
||||
const folly::dynamic& arguments) override;
|
||||
const folly::dynamic& arguments) throw(JSException) override;
|
||||
virtual void invokeCallback(
|
||||
const double callbackId,
|
||||
const folly::dynamic& arguments) override;
|
||||
const folly::dynamic& arguments) throw(JSException) override;
|
||||
virtual void setGlobalVariable(
|
||||
std::string propName,
|
||||
std::unique_ptr<const JSBigString> jsonValue) override;
|
||||
std::unique_ptr<const JSBigString> jsonValue) throw(JSException) override;
|
||||
virtual void* getJavaScriptContext() override;
|
||||
virtual bool supportsProfiling() override;
|
||||
virtual void startProfiler(const std::string &titleString) override;
|
||||
|
@ -103,9 +103,9 @@ private:
|
|||
std::unordered_map<std::string, std::string> globalObjAsJSON,
|
||||
const folly::dynamic& jscConfig);
|
||||
|
||||
void initOnJSVMThread();
|
||||
void initOnJSVMThread() throw(JSException);
|
||||
void terminateOnJSVMThread();
|
||||
void flush();
|
||||
void flush() throw(JSException);
|
||||
void flushQueueImmediate(std::string queueJSON);
|
||||
void loadModule(uint32_t moduleId);
|
||||
|
||||
|
|
|
@ -12,29 +12,9 @@
|
|||
#include <stdexcept>
|
||||
#include <algorithm>
|
||||
|
||||
#include "Value.h"
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
class JSException : public std::runtime_error {
|
||||
public:
|
||||
explicit JSException(const char* msg)
|
||||
: std::runtime_error(msg)
|
||||
, stack_("") {}
|
||||
|
||||
JSException(const char* msg, const char* stack)
|
||||
: std::runtime_error(msg)
|
||||
, stack_(stack) {}
|
||||
|
||||
const std::string& getStack() const {
|
||||
return stack_;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string stack_;
|
||||
};
|
||||
|
||||
inline void throwJSExecutionException(const char* msg) {
|
||||
throw JSException(msg);
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace react {
|
|||
#define REQUEST_PARAMSS 2
|
||||
#define REQUEST_CALLID 3
|
||||
|
||||
std::vector<MethodCall> parseMethodCalls(const std::string& json) {
|
||||
std::vector<MethodCall> parseMethodCalls(const std::string& json) throw(std::invalid_argument) {
|
||||
folly::dynamic jsonData = folly::parseJson(json);
|
||||
|
||||
if (jsonData.isNull()) {
|
||||
|
|
|
@ -24,6 +24,6 @@ struct MethodCall {
|
|||
, callId(cid) {}
|
||||
};
|
||||
|
||||
std::vector<MethodCall> parseMethodCalls(const std::string& json);
|
||||
std::vector<MethodCall> parseMethodCalls(const std::string& json) throw(std::invalid_argument);
|
||||
|
||||
} }
|
||||
|
|
|
@ -30,7 +30,7 @@ JSContextRef Value::context() const {
|
|||
return m_context;
|
||||
}
|
||||
|
||||
std::string Value::toJSONString(unsigned indent) const {
|
||||
std::string Value::toJSONString(unsigned indent) const throw(JSException) {
|
||||
JSValueRef exn;
|
||||
auto stringToAdopt = JSValueCreateJSONString(m_context, m_value, indent, &exn);
|
||||
if (stringToAdopt == nullptr) {
|
||||
|
@ -41,7 +41,7 @@ std::string Value::toJSONString(unsigned indent) const {
|
|||
}
|
||||
|
||||
/* static */
|
||||
Value Value::fromJSON(JSContextRef ctx, const String& json) {
|
||||
Value Value::fromJSON(JSContextRef ctx, const String& json) throw(JSException) {
|
||||
auto result = JSValueMakeFromJSONString(ctx, json);
|
||||
if (!result) {
|
||||
throwJSExecutionException("Failed to create String from JSON");
|
||||
|
|
|
@ -24,6 +24,25 @@ namespace react {
|
|||
class Value;
|
||||
class Context;
|
||||
|
||||
class JSException : public std::runtime_error {
|
||||
public:
|
||||
explicit JSException(const char* msg)
|
||||
: std::runtime_error(msg)
|
||||
, stack_("") {}
|
||||
|
||||
JSException(const char* msg, const char* stack)
|
||||
: std::runtime_error(msg)
|
||||
, stack_(stack) {}
|
||||
|
||||
const std::string& getStack() const {
|
||||
return stack_;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string stack_;
|
||||
};
|
||||
|
||||
|
||||
class String : public noncopyable {
|
||||
public:
|
||||
explicit String(const char* utf8) :
|
||||
|
@ -228,12 +247,12 @@ public:
|
|||
return JSValueIsString(context(), m_value);
|
||||
}
|
||||
|
||||
String toString() {
|
||||
String toString() noexcept {
|
||||
return String::adopt(JSValueToStringCopy(context(), m_value, nullptr));
|
||||
}
|
||||
|
||||
std::string toJSONString(unsigned indent = 0) const;
|
||||
static Value fromJSON(JSContextRef ctx, const String& json);
|
||||
std::string toJSONString(unsigned indent = 0) const throw(JSException);
|
||||
static Value fromJSON(JSContextRef ctx, const String& json) throw(JSException);
|
||||
protected:
|
||||
JSContextRef context() const;
|
||||
JSContextRef m_context;
|
||||
|
|
Loading…
Reference in New Issue