2.4.1: Fix VM.require

This commit is contained in:
Evgeny Kuzyakov 2023-09-14 08:55:28 -07:00
parent 9f8acccced
commit 6fbc54ade6
4 changed files with 13 additions and 3 deletions

View File

@ -1,5 +1,9 @@
# Changelog
## 2.4.1
- FIX: Resolve bug with `VM.require` affected by the introduction of `useState` and `useEffect` hooks.
## 2.4.0
- Introduce `useState` and `useEffect`. They should work similarly to the React hooks. Example:

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{
"name": "near-social-vm",
"version": "2.4.0",
"version": "2.4.1",
"description": "Near Social VM",
"main": "dist/index.js",
"files": [

View File

@ -1017,6 +1017,9 @@ class VmStack {
"Method: useState. The hook can an only be called from the top of the stack"
);
}
if (!this.vm.hooks) {
throw new Error("Hooks are unavailable for modules");
}
if (args.length < 1) {
throw new Error(
"Method: useState. Required arguments: 'initialState'"
@ -1046,6 +1049,9 @@ class VmStack {
"Method: useEffect. The hook can an only be called from the top of the stack"
);
}
if (!this.vm.hooks) {
throw new Error("Hooks are unavailable for modules");
}
if (args.length < 1) {
throw new Error(
"Method: useEffect. Required arguments: 'setup'. Optional: 'dependencies'"
@ -2098,7 +2104,7 @@ export default class VM {
return "Too deep";
}
this.gIndex = 0;
const { hooks, state } = reactState;
const { hooks, state } = reactState ?? {};
this.hooks = hooks;
this.state = {
props: isObject(props) ? Object.assign({}, props) : props,