Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
achamayou committed Oct 23, 2023
1 parent 0024962 commit 7439497
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 19 deletions.
3 changes: 2 additions & 1 deletion src/apps/js_generic/js_generic_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,9 @@ namespace ccfapp
"Invalid endpoint function return value (header type).");
return;
}
auto prop_val = response_headers_js.get_property(prop_name);
auto prop_val_str =
ctx.to_str(response_headers_js.get_property(prop_name));
ctx.to_str(prop_val);
if (!prop_val_str)
{
endpoint_ctx.rpc_ctx->set_error(
Expand Down
26 changes: 17 additions & 9 deletions src/js/wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,22 @@ namespace ccf::js
return JS_IsException(val);
}

bool is_obj() const
{
return JS_IsObject(val);
}

bool is_str() const
{
return JS_IsString(val);
}

bool is_true() const
{
int rc = JS_ToBool(ctx, val);
return rc > 0;
}

JSValue take()
{
JSValue r = val;
Expand Down Expand Up @@ -506,15 +522,7 @@ namespace ccf::js

JSWrappedValue get_global_property(const char* s) const
{
return W(JS_GetPropertyStr(ctx, get_global_obj(), s));
}

JSWrappedValue stringify(
const JSWrappedValue& obj,
const JSWrappedValue& replacer,
const JSWrappedValue& space0) const
{
return W(JS_JSONStringify(ctx, obj, replacer, space0));
return W(JS_GetPropertyStr(ctx, JS_GetGlobalObject(ctx), s));
}

JSWrappedValue json_stringify(const JSWrappedValue& obj) const
Expand Down
14 changes: 6 additions & 8 deletions src/node/gov/handlers/proposals.h
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ namespace ccf::gov::endpoints

// Handle error cases of validation
{
if (JS_IsException(validate_result))
if (validate_result.is_exception())
{
auto [reason, trace] = js_error_message(context);
if (context.interrupt_data.request_timed_out)
Expand All @@ -485,7 +485,7 @@ namespace ccf::gov::endpoints
return;
}

if (!JS_IsObject(validate_result))
if (!validate_result.is_obj())
{
detail::set_gov_error(
ctx.rpc_ctx,
Expand All @@ -496,16 +496,14 @@ namespace ccf::gov::endpoints
}

std::string description;
auto desc = context(
JS_GetPropertyStr(context, validate_result, "description"));
if (JS_IsString(desc))
auto desc = validate_result["description"];
if (desc.is_str())
{
description = context.to_str(desc).value_or("");
}

auto valid =
context(JS_GetPropertyStr(context, validate_result, "valid"));
if (!JS_ToBool(context, valid))
auto valid = validate_result["valid"];
if (!valid.is_true())
{
detail::set_gov_error(
ctx.rpc_ctx,
Expand Down
2 changes: 1 addition & 1 deletion src/node/rpc/member_frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ namespace ccf
&tx,
js::RuntimeLimitsPolicy::NO_LOWER_THAN_DEFAULTS);

if (!JS_IsException(val))
if (!val.is_exception())
{
votes.emplace_back(mid, JS_ToBool(context, val));
}
Expand Down

0 comments on commit 7439497

Please sign in to comment.