Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
bdemann committed Oct 3, 2023
1 parent bf01489 commit f3da2dd
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 17 deletions.
2 changes: 2 additions & 0 deletions src/compiler/rust/canister/src/ic/call_raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ pub fn native_function<'a>(

if should_resolve {
let resolve = global
.get_property("_azleResolveIds").unwrap()
.get_property(format!("_resolve_{promise_id}").as_str())
.unwrap();
resolve.call(&resolve, &[js_value_ref]).unwrap();
} else {
let reject = global
.get_property("_azleRejectIds").unwrap()
.get_property(format!("_reject_{promise_id}").as_str())
.unwrap();
reject.call(&reject, &[js_value_ref]).unwrap();
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/rust/canister/src/ic/call_raw128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ pub fn native_function<'a>(

if should_resolve {
let resolve = global
.get_property("_azleResolveIds").unwrap()
.get_property(format!("_resolve_{promise_id}").as_str())
.unwrap();
resolve.call(&resolve, &[js_value_ref]).unwrap();
} else {
let reject = global
.get_property("_azleRejectIds").unwrap()
.get_property(format!("_reject_{promise_id}").as_str())
.unwrap();
reject.call(&reject, &[js_value_ref]).unwrap();
Expand Down
1 change: 1 addition & 0 deletions src/compiler/rust/canister/src/ic/set_timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub fn native_function<'a>(
let global = context.global_object().unwrap();

let timer_callback = global
.get_property("_azleTimerCallbackIds").unwrap()
.get_property(callback_id.as_str())
.unwrap_or_else(|e| ic_cdk::api::trap(e.to_string().as_str()));

Expand Down
1 change: 1 addition & 0 deletions src/compiler/rust/canister/src/ic/set_timer_interval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub fn native_function<'a>(
let global = context.global_object().unwrap();

let timer_callback = global
.get_property("_azleTimerCallbackIds").unwrap()
.get_property(callback_id.as_str())
.unwrap_or_else(|e| ic_cdk::api::trap(e.to_string().as_str()));

Expand Down
47 changes: 30 additions & 17 deletions src/lib/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,41 @@ declare global {
var _azleRejectIds: { [key: string]: (err: any) => void };
var icTimers: { [key: string]: string };
var _azleTimerCallbackIds: { [key: string]: () => void };
}

interface global {}

export declare var globalThis: {
_azleCandidInitParams: any[];
_azleCandidMethods: any[];
_azleCandidTypes: any[];
Buffer: BufferConstructor;
console: any;
crypto: {
getRandomValues: () => Uint8Array;
};
icTimers: {
var _azleCandidInitParams: any[];
var _azleCandidMethods: any[];
var _azleCandidTypes: any[];
var Buffer: BufferConstructor;
// var console: Console;
// var crypto: Crypto;
var icTimers: {
[key: string]: string;
};
TextDecoder: any;
TextEncoder: any;
};
// var TextDecoder: any;
// var TextEncoder: any;
}

// export declare var globalThis: {
// _azleCandidInitParams: any[];
// _azleCandidMethods: any[];
// _azleCandidTypes: any[];
// Buffer: BufferConstructor;
// console: any;
// crypto: {
// getRandomValues: () => Uint8Array;
// };
// icTimers: {
// [key: string]: string;
// };
// TextDecoder: any;
// TextEncoder: any;
// };

globalThis.TextDecoder = require('text-encoding').TextDecoder;
globalThis.TextEncoder = require('text-encoding').TextEncoder;
globalThis.icTimers ||= {};
globalThis._azleResolveIds = {};
globalThis._azleRejectIds = {};
globalThis._azleTimerCallbackIds = {};

globalThis.console = {
...globalThis.console,
Expand All @@ -42,6 +54,7 @@ globalThis.console = {
// TODO be careful we are using a random seed of 0 I think
// TODO the randomness is predictable
globalThis.crypto = {
...globalThis.crypto,
getRandomValues: () => {
let array = new Uint8Array(32);

Expand Down

0 comments on commit f3da2dd

Please sign in to comment.