2016-05-04 02:29:58 +00:00
|
|
|
// Copyright 2004-present Facebook. All Rights Reserved.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2016-05-14 00:15:06 +00:00
|
|
|
#include "Executor.h"
|
|
|
|
#include "Value.h"
|
|
|
|
|
2016-05-04 02:29:58 +00:00
|
|
|
#include <JavaScriptCore/JSContextRef.h>
|
|
|
|
#include <JavaScriptCore/JSObjectRef.h>
|
|
|
|
#include <JavaScriptCore/JSValueRef.h>
|
|
|
|
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
namespace facebook {
|
|
|
|
namespace react {
|
|
|
|
|
|
|
|
inline void throwJSExecutionException(const char* msg) {
|
2016-06-16 21:28:28 +00:00
|
|
|
throw JSException(msg);
|
2016-05-04 02:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename... Args>
|
|
|
|
inline void throwJSExecutionException(const char* fmt, Args... args) {
|
|
|
|
int msgSize = snprintf(nullptr, 0, fmt, args...);
|
|
|
|
msgSize = std::min(512, msgSize + 1);
|
|
|
|
char *msg = (char*) alloca(msgSize);
|
|
|
|
snprintf(msg, msgSize, fmt, args...);
|
2016-06-16 21:28:28 +00:00
|
|
|
throw JSException(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename... Args>
|
|
|
|
inline void throwJSExecutionExceptionWithStack(const char* msg, const char* stack) {
|
|
|
|
throw JSException(msg, stack);
|
2016-05-04 02:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void installGlobalFunction(
|
|
|
|
JSGlobalContextRef ctx,
|
|
|
|
const char* name,
|
|
|
|
JSObjectCallAsFunctionCallback callback);
|
|
|
|
|
|
|
|
JSValueRef makeJSCException(
|
|
|
|
JSContextRef ctx,
|
|
|
|
const char* exception_text);
|
|
|
|
|
2016-05-14 00:15:06 +00:00
|
|
|
String jsStringFromBigString(const JSBigString& bigstr);
|
|
|
|
|
2016-05-04 02:29:58 +00:00
|
|
|
JSValueRef evaluateScript(
|
|
|
|
JSContextRef ctx,
|
|
|
|
JSStringRef script,
|
|
|
|
JSStringRef sourceURL);
|
|
|
|
|
2016-05-10 12:02:56 +00:00
|
|
|
JSValueRef makeJSError(JSContextRef ctx, const char *error);
|
|
|
|
|
|
|
|
JSValueRef translatePendingCppExceptionToJSError(JSContextRef ctx, const char *exceptionLocation);
|
|
|
|
|
2016-05-04 02:29:58 +00:00
|
|
|
} }
|