-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement accept_message, rejection stuff, and method name
- Loading branch information
Showing
5 changed files
with
70 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
use quickjs_wasm_rs::{CallbackArg, JSContextRef, JSValueRef}; | ||
use std::convert::TryFrom; | ||
|
||
pub fn native_function<'a>( | ||
context: &'a JSContextRef, | ||
_this: &CallbackArg, | ||
_args: &[CallbackArg], | ||
) -> Result<JSValueRef<'a>, anyhow::Error> { | ||
ic_cdk::api::call::accept_message(); | ||
context.undefined_value() | ||
use wasmedge_quickjs::{Context, JsFn, JsValue}; | ||
|
||
pub struct NativeFunction; | ||
impl JsFn for NativeFunction { | ||
fn call(context: &mut Context, this_val: JsValue, argv: &[JsValue]) -> JsValue { | ||
ic_cdk::api::call::accept_message(); | ||
|
||
JsValue::UnDefined | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; | ||
use wasmedge_quickjs::{Context, JsFn, JsValue}; | ||
|
||
pub fn native_function<'a>( | ||
context: &'a JSContextRef, | ||
_this: &CallbackArg, | ||
_args: &[CallbackArg], | ||
) -> Result<JSValueRef<'a>, anyhow::Error> { | ||
let method_name_js_value: JSValue = ic_cdk::api::call::method_name().into(); | ||
to_qjs_value(&context, &method_name_js_value) | ||
pub struct NativeFunction; | ||
impl JsFn for NativeFunction { | ||
fn call(context: &mut Context, this_val: JsValue, argv: &[JsValue]) -> JsValue { | ||
context.new_string(&ic_cdk::api::call::method_name()).into() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,20 @@ | ||
use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; | ||
use wasmedge_quickjs::{Context, JsFn, JsValue}; | ||
|
||
pub fn native_function<'a>( | ||
context: &'a JSContextRef, | ||
_this: &CallbackArg, | ||
_args: &[CallbackArg], | ||
) -> Result<JSValueRef<'a>, anyhow::Error> { | ||
let reject_code = ic_cdk::api::call::reject_code(); | ||
pub struct NativeFunction; | ||
impl JsFn for NativeFunction { | ||
fn call(context: &mut Context, this_val: JsValue, argv: &[JsValue]) -> JsValue { | ||
let reject_code = ic_cdk::api::call::reject_code(); | ||
|
||
let reject_code_as_u8 = match reject_code { | ||
ic_cdk::api::call::RejectionCode::NoError => 0, | ||
ic_cdk::api::call::RejectionCode::SysFatal => 1, | ||
ic_cdk::api::call::RejectionCode::SysTransient => 2, | ||
ic_cdk::api::call::RejectionCode::DestinationInvalid => 3, | ||
ic_cdk::api::call::RejectionCode::CanisterReject => 4, | ||
ic_cdk::api::call::RejectionCode::CanisterError => 5, | ||
ic_cdk::api::call::RejectionCode::Unknown => 6, | ||
}; | ||
let reject_code_number = match reject_code { | ||
ic_cdk::api::call::RejectionCode::NoError => 0, | ||
ic_cdk::api::call::RejectionCode::SysFatal => 1, | ||
ic_cdk::api::call::RejectionCode::SysTransient => 2, | ||
ic_cdk::api::call::RejectionCode::DestinationInvalid => 3, | ||
ic_cdk::api::call::RejectionCode::CanisterReject => 4, | ||
ic_cdk::api::call::RejectionCode::CanisterError => 5, | ||
ic_cdk::api::call::RejectionCode::Unknown => 6, | ||
}; | ||
|
||
let reject_code_as_js_value: JSValue = reject_code_as_u8.into(); | ||
|
||
to_qjs_value(&context, &reject_code_as_js_value) | ||
reject_code_number.into() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; | ||
use wasmedge_quickjs::{Context, JsFn, JsValue}; | ||
|
||
pub fn native_function<'a>( | ||
context: &'a JSContextRef, | ||
_this: &CallbackArg, | ||
_args: &[CallbackArg], | ||
) -> Result<JSValueRef<'a>, anyhow::Error> { | ||
let return_js_value: JSValue = ic_cdk::api::call::reject_message().into(); | ||
to_qjs_value(&context, &return_js_value) | ||
pub struct NativeFunction; | ||
impl JsFn for NativeFunction { | ||
fn call(context: &mut Context, this_val: JsValue, argv: &[JsValue]) -> JsValue { | ||
context | ||
.new_string(&ic_cdk::api::call::reject_message()) | ||
.into() | ||
} | ||
} |