Skip to content

Commit

Permalink
Remove implicit cast from JSWrappedValue to JSValue (#5804)
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyashton authored Jan 2, 2024
1 parent ec85703 commit 42c8db1
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 150 deletions.
21 changes: 11 additions & 10 deletions src/apps/js_generic/js_generic_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ namespace ccfapp

const auto& rt = ctx.runtime();

if (JS_IsException(val))
if (val.is_exception())
{
bool time_out = ctx.interrupt_data.request_timed_out;
std::string error_msg = "Exception thrown while executing.";
Expand Down Expand Up @@ -405,7 +405,7 @@ namespace ccfapp
}

// Handle return value: {body, headers, statusCode}
if (!JS_IsObject(val))
if (!val.is_obj())
{
endpoint_ctx.rpc_ctx->set_error(
HTTP_STATUS_INTERNAL_SERVER_ERROR,
Expand All @@ -417,24 +417,25 @@ namespace ccfapp
// Response body (also sets a default response content-type header)
{
auto response_body_js = val["body"];
if (!JS_IsUndefined(response_body_js))
if (!response_body_js.is_undefined())
{
std::vector<uint8_t> response_body;
size_t buf_size;
size_t buf_offset;
auto typed_array_buffer = ctx.get_typed_array_buffer(
response_body_js, &buf_offset, &buf_size, nullptr);
uint8_t* array_buffer;
if (!JS_IsException(typed_array_buffer))
if (!typed_array_buffer.is_exception())
{
size_t buf_size_total;
array_buffer =
JS_GetArrayBuffer(ctx, &buf_size_total, typed_array_buffer);
JS_GetArrayBuffer(ctx, &buf_size_total, typed_array_buffer.val);
array_buffer += buf_offset;
}
else
{
array_buffer = JS_GetArrayBuffer(ctx, &buf_size, response_body_js);
array_buffer =
JS_GetArrayBuffer(ctx, &buf_size, response_body_js.val);
}
if (array_buffer)
{
Expand All @@ -447,7 +448,7 @@ namespace ccfapp
else
{
std::optional<std::string> str;
if (JS_IsString(response_body_js))
if (response_body_js.is_str())
{
endpoint_ctx.rpc_ctx->set_response_header(
http::headers::CONTENT_TYPE,
Expand All @@ -460,7 +461,7 @@ namespace ccfapp
http::headers::CONTENT_TYPE,
http::headervalues::contenttype::JSON);
auto rval = ctx.json_stringify(response_body_js);
if (JS_IsException(rval))
if (rval.is_exception())
{
auto [reason, trace] = js::js_error_message(ctx);

Expand Down Expand Up @@ -573,8 +574,8 @@ namespace ccfapp
// Response status code
int response_status_code = HTTP_STATUS_OK;
{
auto status_code_js = ctx(JS_GetPropertyStr(ctx, val, "statusCode"));
if (!JS_IsUndefined(status_code_js) && !JS_IsNull(status_code_js))
auto status_code_js = val["statusCode"];
if (!status_code_js.is_undefined() && !JS_IsNull(status_code_js.val))
{
if (JS_VALUE_GET_TAG(status_code_js.val) != JS_TAG_INT)
{
Expand Down
16 changes: 10 additions & 6 deletions src/js/crypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,8 @@ namespace ccf::js
JS_CHECK_EXC(label_val);

size_t label_buf_size = 0;
uint8_t* label_buf = JS_GetArrayBuffer(ctx, &label_buf_size, label_val);
uint8_t* label_buf =
JS_GetArrayBuffer(ctx, &label_buf_size, label_val.val);

std::optional<std::vector<uint8_t>> label_opt = std::nullopt;
if (label_buf && label_buf_size > 0)
Expand Down Expand Up @@ -623,7 +624,7 @@ namespace ccf::js
JS_CHECK_EXC(aes_key_size_value);

int32_t aes_key_size = 0;
if (JS_ToInt32(ctx, &aes_key_size, aes_key_size_value) < 0)
if (JS_ToInt32(ctx, &aes_key_size, aes_key_size_value.val) < 0)
{
return ccf::js::constants::Exception;
}
Expand All @@ -632,7 +633,8 @@ namespace ccf::js
JS_CHECK_EXC(label_val);

size_t label_buf_size = 0;
uint8_t* label_buf = JS_GetArrayBuffer(ctx, &label_buf_size, label_val);
uint8_t* label_buf =
JS_GetArrayBuffer(ctx, &label_buf_size, label_val.val);

std::optional<std::vector<uint8_t>> label_opt = std::nullopt;
if (label_buf && label_buf_size > 0)
Expand Down Expand Up @@ -716,7 +718,8 @@ namespace ccf::js
JS_CHECK_EXC(label_val);

size_t label_buf_size = 0;
uint8_t* label_buf = JS_GetArrayBuffer(ctx, &label_buf_size, label_val);
uint8_t* label_buf =
JS_GetArrayBuffer(ctx, &label_buf_size, label_val.val);

std::optional<std::vector<uint8_t>> label_opt = std::nullopt;
if (label_buf && label_buf_size > 0)
Expand Down Expand Up @@ -754,7 +757,7 @@ namespace ccf::js
JS_CHECK_EXC(aes_key_size_value);

int32_t aes_key_size = 0;
if (JS_ToInt32(ctx, &aes_key_size, aes_key_size_value) < 0)
if (JS_ToInt32(ctx, &aes_key_size, aes_key_size_value.val) < 0)
{
return ccf::js::constants::Exception;
}
Expand All @@ -763,7 +766,8 @@ namespace ccf::js
JS_CHECK_EXC(label_val);

size_t label_buf_size = 0;
uint8_t* label_buf = JS_GetArrayBuffer(ctx, &label_buf_size, label_val);
uint8_t* label_buf =
JS_GetArrayBuffer(ctx, &label_buf_size, label_val.val);

std::optional<std::vector<uint8_t>> label_opt = std::nullopt;
if (label_buf && label_buf_size > 0)
Expand Down
Loading

0 comments on commit 42c8db1

Please sign in to comment.