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

feat: skvm support timer module #120

Merged
merged 1 commit into from
Aug 21, 2023
Merged
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
4 changes: 4 additions & 0 deletions packages/skchain/src/lib/contract/__tests__/vm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ describe('vm', () => {
expect(res.funcResult).toEqual('2');
expect(res.cuCost.reduce((acc, cur) => acc + Number(cur), 0)).toEqual(38);
});
it('should Date fn ok', async () => {
const res = await evalFunction('() => Date.now()');
expect(res.funcResult.length).toEqual(13);
});
it('should simple class ok', async () => {
const codeStr = `
${generateBaseContractCode(new Address(testAccounts[0].id))}
Expand Down
1 change: 1 addition & 0 deletions packages/skvm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ default = ["console_error_panic_hook"]
[dependencies]
wasm-bindgen = "0.2.84"
getrandom = { version = "0.2.8", features = ["js"] }
chrono = { version = "0.4.26", default-features = false, features = ["clock", "std", "wasmbind"] }
boa_engine = { path = "./skboa/boa_engine" }
wasm-bindgen-test = "0.3.13"
js-sys = "0.3.61"
Expand Down
27 changes: 21 additions & 6 deletions packages/skvm/pkg/node/skvm_bg.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ function makeMutClosure(arg0, arg1, dtor, f) {
return real;
}
function __wbg_adapter_28(arg0, arg1, arg2) {
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h2eb5e7682dd29212(arg0, arg1, addHeapObject(arg2));
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h5451c65af4a43c91(arg0, arg1, addHeapObject(arg2));
}

/**
Expand Down Expand Up @@ -274,11 +274,11 @@ export function __wbgtest_console_error(args) {
}

function __wbg_adapter_80(arg0, arg1, arg2, arg3, arg4) {
wasm.wasm_bindgen__convert__closures__invoke3_mut__h716e9571233e6ab5(arg0, arg1, addHeapObject(arg2), arg3, addHeapObject(arg4));
wasm.wasm_bindgen__convert__closures__invoke3_mut__h2315033f19a55d71(arg0, arg1, addHeapObject(arg2), arg3, addHeapObject(arg4));
}

function __wbg_adapter_95(arg0, arg1, arg2, arg3) {
wasm.wasm_bindgen__convert__closures__invoke2_mut__h207fa8e2cab371d6(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
function __wbg_adapter_101(arg0, arg1, arg2, arg3) {
wasm.wasm_bindgen__convert__closures__invoke2_mut__h3541220db1e62064(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
}

/**
Expand Down Expand Up @@ -605,14 +605,29 @@ export function __wbg_call_9495de66fdbe016b() { return handleError(function (arg
return addHeapObject(ret);
}, arguments) };

export function __wbg_getTime_7c59072d1651a3cf(arg0) {
const ret = getObject(arg0).getTime();
return ret;
};

export function __wbg_getTimezoneOffset_2a6b27fb18493a56(arg0) {
const ret = getObject(arg0).getTimezoneOffset();
return ret;
};

export function __wbg_new0_25059e40b1c02766() {
const ret = new Date();
return addHeapObject(ret);
};

export function __wbg_new_9d3a9ce4282a18a8(arg0, arg1) {
try {
var state0 = {a: arg0, b: arg1};
var cb0 = (arg0, arg1) => {
const a = state0.a;
state0.a = 0;
try {
return __wbg_adapter_95(a, state0.b, arg0, arg1);
return __wbg_adapter_101(a, state0.b, arg0, arg1);
} finally {
state0.a = a;
}
Expand Down Expand Up @@ -677,7 +692,7 @@ export function __wbindgen_memory() {
return addHeapObject(ret);
};

export function __wbindgen_closure_wrapper5102(arg0, arg1, arg2) {
export function __wbindgen_closure_wrapper5109(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 1333, __wbg_adapter_28);
return addHeapObject(ret);
};
Expand Down
Binary file modified packages/skvm/pkg/node/skvm_bg.wasm
Binary file not shown.
6 changes: 3 additions & 3 deletions packages/skvm/pkg/node/skvm_bg.wasm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ export function __wbgtest_console_error(a: number): void;
export function __wbindgen_malloc(a: number): number;
export function __wbindgen_realloc(a: number, b: number, c: number): number;
export const __wbindgen_export_2: WebAssembly.Table;
export function _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h2eb5e7682dd29212(a: number, b: number, c: number): void;
export function _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h5451c65af4a43c91(a: number, b: number, c: number): void;
export function __wbindgen_add_to_stack_pointer(a: number): number;
export function __wbindgen_exn_store(a: number): void;
export function __wbindgen_free(a: number, b: number): void;
export function wasm_bindgen__convert__closures__invoke3_mut__h716e9571233e6ab5(a: number, b: number, c: number, d: number, e: number): void;
export function wasm_bindgen__convert__closures__invoke2_mut__h207fa8e2cab371d6(a: number, b: number, c: number, d: number): void;
export function wasm_bindgen__convert__closures__invoke3_mut__h2315033f19a55d71(a: number, b: number, c: number, d: number, e: number): void;
export function wasm_bindgen__convert__closures__invoke2_mut__h3541220db1e62064(a: number, b: number, c: number, d: number): void;
6 changes: 3 additions & 3 deletions packages/skvm/pkg/web/skvm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ export interface InitOutput {
readonly __wbindgen_malloc: (a: number) => number;
readonly __wbindgen_realloc: (a: number, b: number, c: number) => number;
readonly __wbindgen_export_2: WebAssembly.Table;
readonly _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h2eb5e7682dd29212: (a: number, b: number, c: number) => void;
readonly _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h5451c65af4a43c91: (a: number, b: number, c: number) => void;
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
readonly __wbindgen_exn_store: (a: number) => void;
readonly __wbindgen_free: (a: number, b: number) => void;
readonly wasm_bindgen__convert__closures__invoke3_mut__h716e9571233e6ab5: (a: number, b: number, c: number, d: number, e: number) => void;
readonly wasm_bindgen__convert__closures__invoke2_mut__h207fa8e2cab371d6: (a: number, b: number, c: number, d: number) => void;
readonly wasm_bindgen__convert__closures__invoke3_mut__h2315033f19a55d71: (a: number, b: number, c: number, d: number, e: number) => void;
readonly wasm_bindgen__convert__closures__invoke2_mut__h3541220db1e62064: (a: number, b: number, c: number, d: number) => void;
}

export type SyncInitInput = BufferSource | WebAssembly.Module;
Expand Down
24 changes: 18 additions & 6 deletions packages/skvm/pkg/web/skvm.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function makeMutClosure(arg0, arg1, dtor, f) {
return real;
}
function __wbg_adapter_28(arg0, arg1, arg2) {
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h2eb5e7682dd29212(arg0, arg1, addHeapObject(arg2));
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h5451c65af4a43c91(arg0, arg1, addHeapObject(arg2));
}

/**
Expand Down Expand Up @@ -266,11 +266,11 @@ export function __wbgtest_console_error(args) {
}

function __wbg_adapter_80(arg0, arg1, arg2, arg3, arg4) {
wasm.wasm_bindgen__convert__closures__invoke3_mut__h716e9571233e6ab5(arg0, arg1, addHeapObject(arg2), arg3, addHeapObject(arg4));
wasm.wasm_bindgen__convert__closures__invoke3_mut__h2315033f19a55d71(arg0, arg1, addHeapObject(arg2), arg3, addHeapObject(arg4));
}

function __wbg_adapter_95(arg0, arg1, arg2, arg3) {
wasm.wasm_bindgen__convert__closures__invoke2_mut__h207fa8e2cab371d6(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
function __wbg_adapter_101(arg0, arg1, arg2, arg3) {
wasm.wasm_bindgen__convert__closures__invoke2_mut__h3541220db1e62064(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
}

/**
Expand Down Expand Up @@ -588,14 +588,26 @@ function __wbg_get_imports() {
const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));
return addHeapObject(ret);
}, arguments) };
imports.wbg.__wbg_getTime_7c59072d1651a3cf = function(arg0) {
const ret = getObject(arg0).getTime();
return ret;
};
imports.wbg.__wbg_getTimezoneOffset_2a6b27fb18493a56 = function(arg0) {
const ret = getObject(arg0).getTimezoneOffset();
return ret;
};
imports.wbg.__wbg_new0_25059e40b1c02766 = function() {
const ret = new Date();
return addHeapObject(ret);
};
imports.wbg.__wbg_new_9d3a9ce4282a18a8 = function(arg0, arg1) {
try {
var state0 = {a: arg0, b: arg1};
var cb0 = (arg0, arg1) => {
const a = state0.a;
state0.a = 0;
try {
return __wbg_adapter_95(a, state0.b, arg0, arg1);
return __wbg_adapter_101(a, state0.b, arg0, arg1);
} finally {
state0.a = a;
}
Expand Down Expand Up @@ -648,7 +660,7 @@ function __wbg_get_imports() {
const ret = wasm.memory;
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper5102 = function(arg0, arg1, arg2) {
imports.wbg.__wbindgen_closure_wrapper5109 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 1333, __wbg_adapter_28);
return addHeapObject(ret);
};
Expand Down
Binary file modified packages/skvm/pkg/web/skvm_bg.wasm
Binary file not shown.
6 changes: 3 additions & 3 deletions packages/skvm/pkg/web/skvm_bg.wasm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ export function __wbgtest_console_error(a: number): void;
export function __wbindgen_malloc(a: number): number;
export function __wbindgen_realloc(a: number, b: number, c: number): number;
export const __wbindgen_export_2: WebAssembly.Table;
export function _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h2eb5e7682dd29212(a: number, b: number, c: number): void;
export function _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h5451c65af4a43c91(a: number, b: number, c: number): void;
export function __wbindgen_add_to_stack_pointer(a: number): number;
export function __wbindgen_exn_store(a: number): void;
export function __wbindgen_free(a: number, b: number): void;
export function wasm_bindgen__convert__closures__invoke3_mut__h716e9571233e6ab5(a: number, b: number, c: number, d: number, e: number): void;
export function wasm_bindgen__convert__closures__invoke2_mut__h207fa8e2cab371d6(a: number, b: number, c: number, d: number): void;
export function wasm_bindgen__convert__closures__invoke3_mut__h2315033f19a55d71(a: number, b: number, c: number, d: number, e: number): void;
export function wasm_bindgen__convert__closures__invoke2_mut__h3541220db1e62064(a: number, b: number, c: number, d: number): void;
1 change: 1 addition & 0 deletions packages/skvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ mod utils;

use boa_engine::{Context, Source};
use getrandom as _;
use chrono as _;
use js_sys::{Array, Uint8Array};
use proto_rs::eval_result;
use protobuf::{Message, SpecialFields};
Expand Down
Loading