Skip to content

Commit

Permalink
add checks
Browse files Browse the repository at this point in the history
  • Loading branch information
achamayou committed Oct 19, 2023
1 parent 18266af commit 4053a0b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 27 deletions.
30 changes: 4 additions & 26 deletions src/js/conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,13 @@ namespace ccf::js
}

auto str = jsctx.to_str(argv[0]);

if (!str)
{
js_dump_error(ctx);
return ccf::js::constants::Exception;
}

auto buf = jsctx.new_array_buffer_copy((uint8_t*)str->c_str(), str->size());

if (JS_IsException(buf))
{
js_dump_error(ctx);
return ccf::js::constants::Exception;
}
JS_CHECK_EXC(buf);

return buf.take();
}
Expand All @@ -60,12 +53,7 @@ namespace ccf::js
}

auto str = jsctx.new_string_len((char*)buf, buf_size);

if (JS_IsException(str))
{
js::js_dump_error(ctx);
return ccf::js::constants::Exception;
}
JS_CHECK_EXC(str);

return str.take();
}
Expand All @@ -82,12 +70,7 @@ namespace ccf::js
}

auto str = jsctx.json_stringify(JSWrappedValue(ctx, argv[0]));

if (JS_IsException(str))
{
js::js_dump_error(ctx);
return str.take();
}
JS_CHECK_EXC(str);

return js_str_to_buf(ctx, ccf::js::constants::Null, 1, &str.val);
}
Expand Down Expand Up @@ -117,12 +100,7 @@ namespace ccf::js

auto obj =
jsctx.parse_json((char*)buf_null_terminated.data(), buf_size, "<json>");

if (JS_IsException(obj))
{
js::js_dump_error(ctx);
return ccf::js::constants::Exception;
}
JS_CHECK_EXC(obj);

return obj.take();
}
Expand Down
2 changes: 1 addition & 1 deletion src/js/wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
{ \
if (val.is_exception()) \
{ \
return ccf::js::constants::Exception; \
return val.take(); \
} \
} while (0)

Expand Down

0 comments on commit 4053a0b

Please sign in to comment.