2016-11-01 18:38:43 +00:00
|
|
|
// Copyright 2004-present Facebook. All Rights Reserved.
|
|
|
|
|
|
|
|
#include "JSCUtils.h"
|
|
|
|
|
|
|
|
namespace facebook {
|
|
|
|
namespace react {
|
|
|
|
|
2016-11-18 14:25:29 +00:00
|
|
|
String jsStringFromBigString(JSContextRef ctx, const JSBigString& bigstr) {
|
2016-11-01 18:38:43 +00:00
|
|
|
if (bigstr.isAscii()) {
|
2016-11-18 14:25:29 +00:00
|
|
|
return String::createExpectingAscii(ctx, bigstr.c_str(), bigstr.size());
|
2016-11-01 18:38:43 +00:00
|
|
|
} else {
|
2016-11-18 14:25:29 +00:00
|
|
|
return String(ctx, bigstr.c_str());
|
2016-11-01 18:38:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-21 15:34:41 +00:00
|
|
|
std::pair<uint32_t, uint32_t> parseNativeRequireParameters(
|
|
|
|
const JSGlobalContextRef& context,
|
|
|
|
const JSValueRef arguments[],
|
|
|
|
size_t argumentCount) {
|
|
|
|
double moduleId = 0, bundleId = 0;
|
|
|
|
|
|
|
|
if (argumentCount == 1) {
|
|
|
|
moduleId = Value(context, arguments[0]).asNumber();
|
|
|
|
} else if (argumentCount == 2) {
|
|
|
|
moduleId = Value(context, arguments[0]).asNumber();
|
|
|
|
bundleId = Value(context, arguments[1]).asNumber();
|
|
|
|
} else {
|
|
|
|
throw std::invalid_argument("Got wrong number of args");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (moduleId < 0) {
|
|
|
|
throw std::invalid_argument(folly::to<std::string>("Received invalid module ID: ",
|
|
|
|
Value(context, arguments[0]).toString().str()));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bundleId < 0) {
|
|
|
|
throw std::invalid_argument(folly::to<std::string>("Received invalid bundle ID: ",
|
|
|
|
Value(context, arguments[1]).toString().str()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::make_pair(static_cast<uint32_t>(bundleId), static_cast<uint32_t>(moduleId));
|
|
|
|
}
|
|
|
|
|
2016-11-01 18:38:43 +00:00
|
|
|
}
|
|
|
|
}
|