Skip to content

Commit

Permalink
Merge pull request #897 from vamedyakov/fix_throwJSError
Browse files Browse the repository at this point in the history
Fix error RN 0.70: No member named 'throwJSError'
  • Loading branch information
chrfalch authored Sep 8, 2022
2 parents 15e7828 + 2c2170e commit 33aefb1
Show file tree
Hide file tree
Showing 12 changed files with 94 additions and 94 deletions.
8 changes: 4 additions & 4 deletions package/cpp/api/JsiSkContourMeasure.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace RNSkia
{
if (contourMeasure == nullptr)
{
jsi::detail::throwJSError(*context->getJsRuntime(), "Contour measure is null");
throw jsi::JSError(*context->getJsRuntime(), "Contour measure is null");
}
};

Expand All @@ -41,7 +41,7 @@ namespace RNSkia
auto result = getObject()->getPosTan(dist, &position, &tangent);
if (!result)
{
jsi::detail::throwJSError(runtime, "getSegment() failed");
throw jsi::JSError(runtime, "getSegment() failed");
}
auto posTan = jsi::Object(runtime);
posTan.setProperty(runtime, "px", position.x());
Expand Down Expand Up @@ -70,7 +70,7 @@ namespace RNSkia
auto result = getObject()->getSegment(start, end, &path, startWithMoveTo);
if (!result)
{
jsi::detail::throwJSError(runtime, "getSegment() failed");
throw jsi::JSError(runtime, "getSegment() failed");
}
return JsiSkPath::toValue(runtime, getContext(), std::move(path));
}
Expand Down Expand Up @@ -99,4 +99,4 @@ namespace RNSkia
->getObject();
}
};
} // namespace RNSkia
} // namespace RNSkia
6 changes: 3 additions & 3 deletions package/cpp/api/JsiSkDataFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,18 @@ namespace RNSkia {
size_t len;
auto err = SkBase64::Decode(&base64.utf8(runtime).c_str()[0], size, nullptr, &len);
if(err != SkBase64::Error::kNoError) {
jsi::detail::throwJSError(runtime, "Error decoding base64 string");
throw jsi::JSError(runtime, "Error decoding base64 string");
return jsi::Value::undefined();
}

// Create data object and decode
auto data = SkData::MakeUninitialized(len);
err = SkBase64::Decode(&base64.utf8(runtime).c_str()[0], size, data->writable_data(), &len);
if(err != SkBase64::Error::kNoError) {
jsi::detail::throwJSError(runtime, "Error decoding base64 string");
throw jsi::JSError(runtime, "Error decoding base64 string");
return jsi::Value::undefined();
}

return jsi::Object::createFromHostObject(runtime,
std::make_shared<JsiSkData>(
getContext(), std::move(data)));
Expand Down
2 changes: 1 addition & 1 deletion package/cpp/api/JsiSkFont.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ namespace RNSkia

if (glyphs.size() > positions.size())
{
jsi::detail::throwJSError(runtime, "Not enough x,y position pairs for glyphs");
throw jsi::JSError(runtime, "Not enough x,y position pairs for glyphs");
return jsi::Value::null();
}
auto sects = getObject()->getIntercepts(glyphs.data(), SkToInt(glyphs.size()), positions.data(), top, bottom);
Expand Down
2 changes: 1 addition & 1 deletion package/cpp/api/JsiSkPathFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class JsiSkPathFactory : public JsiSkHostObject {
SkPath result;

if (!SkParsePath::FromSVGString(svgString.c_str(), &result)) {
jsi::detail::throwJSError(runtime, "Could not parse Svg path");
throw jsi::JSError(runtime, "Could not parse Svg path");
return jsi::Value(nullptr);
}

Expand Down
2 changes: 1 addition & 1 deletion package/cpp/api/JsiSkPictureFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class JsiSkPictureFactory : public JsiSkHostObject {
public:
JSI_HOST_FUNCTION(MakePicture) {
if(!arguments[0].isObject()) {
jsi::detail::throwJSError(runtime, "Expected arraybuffer as first parameter");
throw jsi::JSError(runtime, "Expected arraybuffer as first parameter");
}
auto array = arguments[0].asObject(runtime);
jsi::ArrayBuffer buffer = array
Expand Down
12 changes: 6 additions & 6 deletions package/cpp/api/JsiSkRuntimeEffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace RNSkia
: public JsiSkWrappingSkPtrHostObject<SkRuntimeEffect>
{
public:

static sk_sp<SkRuntimeEffect> fromValue(jsi::Runtime &runtime, const jsi::Value &obj) {
const auto& object = obj.asObject(runtime);
return object.asHostObject<JsiSkRuntimeEffect>(runtime)->getObject();
Expand All @@ -44,7 +44,7 @@ namespace RNSkia
JSI_HOST_FUNCTION(makeShader)
{
auto uniforms = castUniforms(runtime, arguments[0]);

auto matrix = count >= 2 && !arguments[1].isUndefined() && !arguments[1].isNull() ? JsiSkMatrix::fromValue(runtime, arguments[1]).get() : nullptr;

// Create and return shader as host object
Expand All @@ -57,7 +57,7 @@ namespace RNSkia
JSI_HOST_FUNCTION(makeShaderWithChildren)
{
auto uniforms = castUniforms(runtime, arguments[0]);

// Children
std::vector<sk_sp<SkShader>> children;
auto jsiChildren = arguments[1].asObject(runtime).asArray(runtime);
Expand Down Expand Up @@ -96,7 +96,7 @@ namespace RNSkia
{
auto i = static_cast<int>(arguments[0].asNumber());
if (i < 0 || i >= getObject()->uniforms().size()) {
jsi::detail::throwJSError(runtime, "invalid uniform index");
throw jsi::JSError(runtime, "invalid uniform index");
}
auto it = getObject()->uniforms().begin() + i;
return jsi::String::createFromAscii(runtime, it->name.c_str());
Expand All @@ -106,7 +106,7 @@ namespace RNSkia
{
auto i = static_cast<int>(arguments[0].asNumber());
if (i < 0 || i >= getObject()->uniforms().size()) {
jsi::detail::throwJSError(runtime, "invalid uniform index");
throw jsi::JSError(runtime, "invalid uniform index");
}
auto it = getObject()->uniforms().begin() + i;
auto result = jsi::Object(runtime);
Expand Down Expand Up @@ -144,7 +144,7 @@ namespace RNSkia
std::to_string(jsiUniformsSize) +
" expected " +
std::to_string(getObject()->uniformSize() / sizeof(float));
jsi::detail::throwJSError(runtime, msg.c_str());
throw jsi::JSError(runtime, msg.c_str());
}

auto uniforms = SkData::MakeUninitialized(getObject()->uniformSize());
Expand Down
2 changes: 1 addition & 1 deletion package/cpp/api/JsiSkRuntimeEffectFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class JsiSkRuntimeEffectFactory : public JsiSkHostObject {
auto effect = result.effect;
auto errorText = result.errorText;
if (!effect) {
jsi::detail::throwJSError(
throw jsi::JSError(
runtime,
std::string("Error in sksl:\n" + std::string(errorText.c_str()))
.c_str());
Expand Down
60 changes: 30 additions & 30 deletions package/cpp/rnskia/RNSkJsiViewApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ class RNSkJsiViewApi : public JsiHostObject, public std::enable_shared_from_this
"setJsiProperty: First argument must be a number");
return jsi::Value::undefined();
}

if (!arguments[1].isString()) {
_platformContext->raiseError(
"setJsiProperty: Second argument must be the name of the property to set.");

return jsi::Value::undefined();
}
auto nativeId = arguments[0].asNumber();
auto nativeId = arguments[0].asNumber();
auto info = getEnsuredViewInfo(nativeId);

std::lock_guard<std::mutex> lock(_mutex);
info->props.emplace(arguments[1].asString(runtime).utf8(runtime), JsiValueWrapper(runtime, arguments[2]));

Expand All @@ -64,10 +64,10 @@ class RNSkJsiViewApi : public JsiHostObject, public std::enable_shared_from_this
info->view->setJsiProperties(info->props);
info->props.clear();
}

return jsi::Value::undefined();
}

/**
Calls a custom command / method on a view by the view id.
*/
Expand All @@ -76,34 +76,34 @@ class RNSkJsiViewApi : public JsiHostObject, public std::enable_shared_from_this
_platformContext->raiseError(
std::string("callCustomCommand: Expected at least 2 arguments, got " +
std::to_string(count) + "."));

return jsi::Value::undefined();
}

if (!arguments[0].isNumber()) {
_platformContext->raiseError(
"callCustomCommand: First argument must be a number");

return jsi::Value::undefined();
}

if (!arguments[1].isString()) {
_platformContext->raiseError(
"callCustomCommand: Second argument must be the name of the action to call.");

return jsi::Value::undefined();
}

auto nativeId = arguments[0].asNumber();
auto action = arguments[1].asString(runtime).utf8(runtime);

auto info = getEnsuredViewInfo(nativeId);

if(info->view == nullptr) {
jsi::detail::throwJSError(runtime,
throw jsi::JSError(runtime,
std::string("callCustomCommand: Could not call action " + action +
" on view - view not ready.").c_str());

return jsi::Value::undefined();
}

Expand All @@ -112,7 +112,7 @@ class RNSkJsiViewApi : public JsiHostObject, public std::enable_shared_from_this
const jsi::Value* params = paramsCount > 0 ? &arguments[2] : nullptr;
return info->view->callJsiMethod(runtime, action, params, paramsCount);
}

JSI_HOST_FUNCTION(requestRedraw) {
if (count < 2) {
_platformContext->raiseError(
Expand All @@ -137,7 +137,7 @@ class RNSkJsiViewApi : public JsiHostObject, public std::enable_shared_from_this
}
return jsi::Value::undefined();
}

JSI_HOST_FUNCTION(makeImageSnapshot) {
if (count < 1) {
_platformContext->raiseError(std::string("makeImageSnapshot: Expected at least 1 argument, got " + std::to_string(count) + "."));
Expand All @@ -148,7 +148,7 @@ class RNSkJsiViewApi : public JsiHostObject, public std::enable_shared_from_this
_platformContext->raiseError("makeImageSnapshot: First argument must be a number");
return jsi::Value::undefined();
}

// find Skia view
int nativeId = arguments[0].asNumber();
sk_sp<SkImage> image;
Expand All @@ -161,33 +161,33 @@ class RNSkJsiViewApi : public JsiHostObject, public std::enable_shared_from_this
image = info->view->makeImageSnapshot(nullptr);
}
if(image == nullptr) {
jsi::detail::throwJSError(runtime, "Could not create image from current surface.");
throw jsi::JSError(runtime, "Could not create image from current surface.");
return jsi::Value::undefined();
}
return jsi::Object::createFromHostObject(runtime, std::make_shared<JsiSkImage>(_platformContext, image));
}
jsi::detail::throwJSError(runtime, "No Skia View currently available.");
throw jsi::JSError(runtime, "No Skia View currently available.");
return jsi::Value::undefined();
}

JSI_HOST_FUNCTION(registerValuesInView) {
// Check params
if(!arguments[1].isObject() || !arguments[1].asObject(runtime).isArray(runtime)) {
jsi::detail::throwJSError(runtime, "Expected array of Values as second parameter");
throw jsi::JSError(runtime, "Expected array of Values as second parameter");
return jsi::Value::undefined();
}

// Get identifier of native SkiaView
int nativeId = arguments[0].asNumber();

// Get values that should be added as dependencies
auto values = arguments[1].asObject(runtime).asArray(runtime);
std::vector<std::function<void()>> unsubscribers;
const std::size_t size = values.size(runtime);
unsubscribers.reserve(size);
for(size_t i=0; i<size; ++i) {
auto value = values.getValueAtIndex(runtime, i).asObject(runtime).asHostObject<RNSkReadonlyValue>(runtime);

if(value != nullptr) {
// Add change listener
unsubscribers.push_back(value->addListener([weakSelf = weak_from_this(), nativeId](jsi::Runtime&){
Expand All @@ -201,7 +201,7 @@ class RNSkJsiViewApi : public JsiHostObject, public std::enable_shared_from_this
}));
}
}

// Return unsubscribe method that unsubscribes to all values
// that we subscribed to.
return jsi::Function::createFromHostFunction(runtime,
Expand All @@ -215,7 +215,7 @@ class RNSkJsiViewApi : public JsiHostObject, public std::enable_shared_from_this
return jsi::Value::undefined();
});
}

JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(RNSkJsiViewApi, setJsiProperty),
JSI_EXPORT_FUNC(RNSkJsiViewApi, callJsiMethod),
JSI_EXPORT_FUNC(RNSkJsiViewApi, registerValuesInView),
Expand Down Expand Up @@ -272,12 +272,12 @@ class RNSkJsiViewApi : public JsiHostObject, public std::enable_shared_from_this
return;
}
auto info = getEnsuredViewInfo(nativeId);

std::lock_guard<std::mutex> lock(_mutex);
info->view = nullptr;
_viewInfos.erase(nativeId);
}

/**
Sets a skia draw view for the given id. This function can be used
to mark that an underlying SkiaView is not available (it could be
Expand Down Expand Up @@ -314,7 +314,7 @@ class RNSkJsiViewApi : public JsiHostObject, public std::enable_shared_from_this
}
return &_viewInfos.at(nativeId);
}

std::unordered_map<size_t, RNSkViewInfo> _viewInfos;
std::shared_ptr<RNSkPlatformContext> _platformContext;
std::mutex _mutex;
Expand Down
22 changes: 11 additions & 11 deletions package/cpp/rnskia/values/RNSkComputedValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,32 @@ class RNSkComputedValue : public RNSkReadonlyValue
// Verify input
if(!arguments[0].isObject() ||
!arguments[0].asObject(runtime).isFunction(runtime)) {
jsi::detail::throwJSError(runtime, "Expected callback function as first parameter");
throw jsi::JSError(runtime, "Expected callback function as first parameter");
}

if(!arguments[1].isObject() ||
!arguments[1].asObject(runtime).isArray(runtime)) {
jsi::detail::throwJSError(runtime, "Expected array of dependencies as second parameter");
throw jsi::JSError(runtime, "Expected array of dependencies as second parameter");
}

// Get callback for calculating result
_callback = std::make_shared<jsi::Function>(arguments[0].asObject(runtime).asFunction(runtime));
}

void invalidate() override {
RNSkReadonlyValue::invalidate();

// Unregister listeners
for(const auto &unsubscribe: _unsubscribers) {
unsubscribe();
}
_unsubscribers.clear();
}

void initializeDependencies(jsi::Runtime &runtime, const jsi::Value *arguments, size_t count) {
// Save dependencies
std::vector<std::shared_ptr<RNSkReadonlyValue>> dependencies;

// Ensure that all dependencies are Values
auto deps = arguments[1].asObject(runtime).asArray(runtime);
const std::size_t size = deps.size(runtime);
Expand All @@ -73,7 +73,7 @@ class RNSkComputedValue : public RNSkReadonlyValue
}
dependencies.push_back(value);
}

// register change handler on dependencies
_unsubscribers.reserve(_unsubscribers.size() + size);
for(const auto &dep: dependencies) {
Expand All @@ -85,11 +85,11 @@ class RNSkComputedValue : public RNSkReadonlyValue
}
}));
}

// Set initial value
dependencyUpdated(runtime);
}

private:
void dependencyUpdated(jsi::Runtime &runtime) {
// Calculate new value
Expand Down
Loading

0 comments on commit 33aefb1

Please sign in to comment.