Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Bigint to bind u64/i64 #9384

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
189 changes: 80 additions & 109 deletions bindings/electron/src/meths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
*/

#[allow(unused_imports)]
use neon::{prelude::*, types::buffer::TypedArray};
use neon::{
prelude::*,
types::{buffer::TypedArray, JsBigInt},
};

// CancelledGreetingAttemptReason

Expand Down Expand Up @@ -1379,13 +1382,11 @@ fn struct_file_stat_js_to_rs<'a>(
js_val.value(cx)
};
let size = {
let js_val: Handle<JsNumber> = obj.get(cx, "size")?;
let js_val: Handle<JsBigInt> = obj.get(cx, "size")?;
{
let v = js_val.value(cx);
if v < (u64::MIN as f64) || (u64::MAX as f64) < v {
cx.throw_type_error("Not an u64 number")?
}
let v = v as u64;
let v = js_val
.to_u64(cx)
.or_else(|_| cx.throw_type_error("Not an u64 number"))?;
v
}
};
Expand Down Expand Up @@ -1442,7 +1443,7 @@ fn struct_file_stat_rs_to_js<'a>(
js_obj.set(cx, "isPlaceholder", js_is_placeholder)?;
let js_need_sync = JsBoolean::new(cx, rs_obj.need_sync);
js_obj.set(cx, "needSync", js_need_sync)?;
let js_size = JsNumber::new(cx, rs_obj.size as f64);
let js_size = JsBigInt::from_u64(cx, rs_obj.size);
js_obj.set(cx, "size", js_size)?;
Ok(js_obj)
}
Expand Down Expand Up @@ -3177,13 +3178,11 @@ fn struct_workspace_history_file_stat_js_to_rs<'a>(
}
};
let size = {
let js_val: Handle<JsNumber> = obj.get(cx, "size")?;
let js_val: Handle<JsBigInt> = obj.get(cx, "size")?;
{
let v = js_val.value(cx);
if v < (u64::MIN as f64) || (u64::MAX as f64) < v {
cx.throw_type_error("Not an u64 number")?
}
let v = v as u64;
let v = js_val
.to_u64(cx)
.or_else(|_| cx.throw_type_error("Not an u64 number"))?;
v
}
};
Expand Down Expand Up @@ -3234,7 +3233,7 @@ fn struct_workspace_history_file_stat_rs_to_js<'a>(
js_obj.set(cx, "updated", js_updated)?;
let js_version = JsNumber::new(cx, rs_obj.version as f64);
js_obj.set(cx, "version", js_version)?;
let js_size = JsNumber::new(cx, rs_obj.size as f64);
let js_size = JsBigInt::from_u64(cx, rs_obj.size);
js_obj.set(cx, "size", js_size)?;
Ok(js_obj)
}
Expand Down Expand Up @@ -3405,13 +3404,11 @@ fn variant_active_users_limit_js_to_rs<'a>(
match tag.as_str() {
"ActiveUsersLimitLimitedTo" => {
let x0 = {
let js_val: Handle<JsNumber> = obj.get(cx, "x0")?;
let js_val: Handle<JsBigInt> = obj.get(cx, "x0")?;
{
let v = js_val.value(cx);
if v < (u64::MIN as f64) || (u64::MAX as f64) < v {
cx.throw_type_error("Not an u64 number")?
}
let v = v as u64;
let v = js_val
.to_u64(cx)
.or_else(|_| cx.throw_type_error("Not an u64 number"))?;
v
}
};
Expand All @@ -3432,7 +3429,7 @@ fn variant_active_users_limit_rs_to_js<'a>(
libparsec::ActiveUsersLimit::LimitedTo(x0, ..) => {
let js_tag = JsString::try_new(cx, "LimitedTo").or_throw(cx)?;
js_obj.set(cx, "tag", js_tag)?;
let js_x0 = JsNumber::new(cx, x0 as f64);
let js_x0 = JsBigInt::from_u64(cx, x0);
js_obj.set(cx, "x0", js_x0)?;
}
libparsec::ActiveUsersLimit::NoLimit { .. } => {
Expand Down Expand Up @@ -4417,35 +4414,29 @@ fn variant_client_event_js_to_rs<'a>(
}
};
let blocks = {
let js_val: Handle<JsNumber> = obj.get(cx, "blocks")?;
let js_val: Handle<JsBigInt> = obj.get(cx, "blocks")?;
{
let v = js_val.value(cx);
if v < (u64::MIN as f64) || (u64::MAX as f64) < v {
cx.throw_type_error("Not an u64 number")?
}
let v = v as u64;
let v = js_val
.to_u64(cx)
.or_else(|_| cx.throw_type_error("Not an u64 number"))?;
v
}
};
let block_index = {
let js_val: Handle<JsNumber> = obj.get(cx, "blockIndex")?;
let js_val: Handle<JsBigInt> = obj.get(cx, "blockIndex")?;
{
let v = js_val.value(cx);
if v < (u64::MIN as f64) || (u64::MAX as f64) < v {
cx.throw_type_error("Not an u64 number")?
}
let v = v as u64;
let v = js_val
.to_u64(cx)
.or_else(|_| cx.throw_type_error("Not an u64 number"))?;
v
}
};
let blocksize = {
let js_val: Handle<JsNumber> = obj.get(cx, "blocksize")?;
let js_val: Handle<JsBigInt> = obj.get(cx, "blocksize")?;
{
let v = js_val.value(cx);
if v < (u64::MIN as f64) || (u64::MAX as f64) < v {
cx.throw_type_error("Not an u64 number")?
}
let v = v as u64;
let v = js_val
.to_u64(cx)
.or_else(|_| cx.throw_type_error("Not an u64 number"))?;
v
}
};
Expand Down Expand Up @@ -4738,11 +4729,11 @@ fn variant_client_event_rs_to_js<'a>(
})
.or_throw(cx)?;
js_obj.set(cx, "entryId", js_entry_id)?;
let js_blocks = JsNumber::new(cx, blocks as f64);
let js_blocks = JsBigInt::from_u64(cx, blocks);
js_obj.set(cx, "blocks", js_blocks)?;
let js_block_index = JsNumber::new(cx, block_index as f64);
let js_block_index = JsBigInt::from_u64(cx, block_index);
js_obj.set(cx, "blockIndex", js_block_index)?;
let js_blocksize = JsNumber::new(cx, blocksize as f64);
let js_blocksize = JsBigInt::from_u64(cx, blocksize);
js_obj.set(cx, "blocksize", js_blocksize)?;
}
libparsec::ClientEvent::WorkspaceOpsOutboundSyncStarted {
Expand Down Expand Up @@ -6094,13 +6085,11 @@ fn variant_entry_stat_js_to_rs<'a>(
js_val.value(cx)
};
let size = {
let js_val: Handle<JsNumber> = obj.get(cx, "size")?;
let js_val: Handle<JsBigInt> = obj.get(cx, "size")?;
{
let v = js_val.value(cx);
if v < (u64::MIN as f64) || (u64::MAX as f64) < v {
cx.throw_type_error("Not an u64 number")?
}
let v = v as u64;
let v = js_val
.to_u64(cx)
.or_else(|_| cx.throw_type_error("Not an u64 number"))?;
v
}
};
Expand Down Expand Up @@ -6305,7 +6294,7 @@ fn variant_entry_stat_rs_to_js<'a>(
js_obj.set(cx, "isPlaceholder", js_is_placeholder)?;
let js_need_sync = JsBoolean::new(cx, need_sync);
js_obj.set(cx, "needSync", js_need_sync)?;
let js_size = JsNumber::new(cx, size as f64);
let js_size = JsBigInt::from_u64(cx, size);
js_obj.set(cx, "size", js_size)?;
}
libparsec::EntryStat::Folder {
Expand Down Expand Up @@ -8558,13 +8547,11 @@ fn variant_parsed_parsec_addr_js_to_rs<'a>(
}
};
let key_index = {
let js_val: Handle<JsNumber> = obj.get(cx, "keyIndex")?;
let js_val: Handle<JsBigInt> = obj.get(cx, "keyIndex")?;
{
let v = js_val.value(cx);
if v < (u64::MIN as f64) || (u64::MAX as f64) < v {
cx.throw_type_error("Not an u64 number")?
}
let v = v as u64;
let v = js_val
.to_u64(cx)
.or_else(|_| cx.throw_type_error("Not an u64 number"))?;
v
}
};
Expand Down Expand Up @@ -8787,7 +8774,7 @@ fn variant_parsed_parsec_addr_rs_to_js<'a>(
})
.or_throw(cx)?;
js_obj.set(cx, "workspaceId", js_workspace_id)?;
let js_key_index = JsNumber::new(cx, key_index as f64);
let js_key_index = JsBigInt::from_u64(cx, key_index);
js_obj.set(cx, "keyIndex", js_key_index)?;
let js_encrypted_path = {
let mut js_buff = JsArrayBuffer::new(cx, encrypted_path.len())?;
Expand Down Expand Up @@ -10783,13 +10770,11 @@ fn variant_workspace_history_entry_stat_js_to_rs<'a>(
}
};
let size = {
let js_val: Handle<JsNumber> = obj.get(cx, "size")?;
let js_val: Handle<JsBigInt> = obj.get(cx, "size")?;
{
let v = js_val.value(cx);
if v < (u64::MIN as f64) || (u64::MAX as f64) < v {
cx.throw_type_error("Not an u64 number")?
}
let v = v as u64;
let v = js_val
.to_u64(cx)
.or_else(|_| cx.throw_type_error("Not an u64 number"))?;
v
}
};
Expand Down Expand Up @@ -10938,7 +10923,7 @@ fn variant_workspace_history_entry_stat_rs_to_js<'a>(
js_obj.set(cx, "updated", js_updated)?;
let js_version = JsNumber::new(cx, version as f64);
js_obj.set(cx, "version", js_version)?;
let js_size = JsNumber::new(cx, size as f64);
let js_size = JsBigInt::from_u64(cx, size);
js_obj.set(cx, "size", js_size)?;
}
libparsec::WorkspaceHistoryEntryStat::Folder {
Expand Down Expand Up @@ -18186,24 +18171,20 @@ fn workspace_fd_read(mut cx: FunctionContext) -> JsResult<JsPromise> {
}
};
let offset = {
let js_val = cx.argument::<JsNumber>(2)?;
let js_val = cx.argument::<JsBigInt>(2)?;
{
let v = js_val.value(&mut cx);
if v < (u64::MIN as f64) || (u64::MAX as f64) < v {
cx.throw_type_error("Not an u64 number")?
}
let v = v as u64;
let v = js_val
.to_u64(&mut cx)
.or_else(|_| cx.throw_type_error("Not an u64 number"))?;
v
}
};
let size = {
let js_val = cx.argument::<JsNumber>(3)?;
let js_val = cx.argument::<JsBigInt>(3)?;
{
let v = js_val.value(&mut cx);
if v < (u64::MIN as f64) || (u64::MAX as f64) < v {
cx.throw_type_error("Not an u64 number")?
}
let v = v as u64;
let v = js_val
.to_u64(&mut cx)
.or_else(|_| cx.throw_type_error("Not an u64 number"))?;
v
}
};
Expand Down Expand Up @@ -18281,13 +18262,11 @@ fn workspace_fd_resize(mut cx: FunctionContext) -> JsResult<JsPromise> {
}
};
let length = {
let js_val = cx.argument::<JsNumber>(2)?;
let js_val = cx.argument::<JsBigInt>(2)?;
{
let v = js_val.value(&mut cx);
if v < (u64::MIN as f64) || (u64::MAX as f64) < v {
cx.throw_type_error("Not an u64 number")?
}
let v = v as u64;
let v = js_val
.to_u64(&mut cx)
.or_else(|_| cx.throw_type_error("Not an u64 number"))?;
v
}
};
Expand Down Expand Up @@ -18432,13 +18411,11 @@ fn workspace_fd_write(mut cx: FunctionContext) -> JsResult<JsPromise> {
}
};
let offset = {
let js_val = cx.argument::<JsNumber>(2)?;
let js_val = cx.argument::<JsBigInt>(2)?;
{
let v = js_val.value(&mut cx);
if v < (u64::MIN as f64) || (u64::MAX as f64) < v {
cx.throw_type_error("Not an u64 number")?
}
let v = v as u64;
let v = js_val
.to_u64(&mut cx)
.or_else(|_| cx.throw_type_error("Not an u64 number"))?;
v
}
};
Expand All @@ -18462,7 +18439,7 @@ fn workspace_fd_write(mut cx: FunctionContext) -> JsResult<JsPromise> {
let js_obj = JsObject::new(&mut cx);
let js_tag = JsBoolean::new(&mut cx, true);
js_obj.set(&mut cx, "ok", js_tag)?;
let js_value = JsNumber::new(&mut cx, ok as f64);
let js_value = JsBigInt::from_u64(&mut cx, ok);
js_obj.set(&mut cx, "value", js_value)?;
js_obj
}
Expand Down Expand Up @@ -18513,13 +18490,11 @@ fn workspace_fd_write_constrained_io(mut cx: FunctionContext) -> JsResult<JsProm
}
};
let offset = {
let js_val = cx.argument::<JsNumber>(2)?;
let js_val = cx.argument::<JsBigInt>(2)?;
{
let v = js_val.value(&mut cx);
if v < (u64::MIN as f64) || (u64::MAX as f64) < v {
cx.throw_type_error("Not an u64 number")?
}
let v = v as u64;
let v = js_val
.to_u64(&mut cx)
.or_else(|_| cx.throw_type_error("Not an u64 number"))?;
v
}
};
Expand All @@ -18544,7 +18519,7 @@ fn workspace_fd_write_constrained_io(mut cx: FunctionContext) -> JsResult<JsProm
let js_obj = JsObject::new(&mut cx);
let js_tag = JsBoolean::new(&mut cx, true);
js_obj.set(&mut cx, "ok", js_tag)?;
let js_value = JsNumber::new(&mut cx, ok as f64);
let js_value = JsBigInt::from_u64(&mut cx, ok);
js_obj.set(&mut cx, "value", js_value)?;
js_obj
}
Expand Down Expand Up @@ -18614,7 +18589,7 @@ fn workspace_fd_write_start_eof(mut cx: FunctionContext) -> JsResult<JsPromise>
let js_obj = JsObject::new(&mut cx);
let js_tag = JsBoolean::new(&mut cx, true);
js_obj.set(&mut cx, "ok", js_tag)?;
let js_value = JsNumber::new(&mut cx, ok as f64);
let js_value = JsBigInt::from_u64(&mut cx, ok);
js_obj.set(&mut cx, "value", js_value)?;
js_obj
}
Expand Down Expand Up @@ -18792,24 +18767,20 @@ fn workspace_history_fd_read(mut cx: FunctionContext) -> JsResult<JsPromise> {
}
};
let offset = {
let js_val = cx.argument::<JsNumber>(2)?;
let js_val = cx.argument::<JsBigInt>(2)?;
{
let v = js_val.value(&mut cx);
if v < (u64::MIN as f64) || (u64::MAX as f64) < v {
cx.throw_type_error("Not an u64 number")?
}
let v = v as u64;
let v = js_val
.to_u64(&mut cx)
.or_else(|_| cx.throw_type_error("Not an u64 number"))?;
v
}
};
let size = {
let js_val = cx.argument::<JsNumber>(3)?;
let js_val = cx.argument::<JsBigInt>(3)?;
{
let v = js_val.value(&mut cx);
if v < (u64::MIN as f64) || (u64::MAX as f64) < v {
cx.throw_type_error("Not an u64 number")?
}
let v = v as u64;
let v = js_val
.to_u64(&mut cx)
.or_else(|_| cx.throw_type_error("Not an u64 number"))?;
v
}
};
Expand Down
Loading
Loading