You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, I doubt that is a Zig-related problem.
As I know, the value of the this keyword depends on its context.
Then, what is the value of this, if I call a function in a WASM?
Additional note
I tried an arrow function, but it made this._in_call_that_will_be_revertedundefined, and this was not a Tangle instance. (it was a function.) moduleImports[importName] = (...args) => {
I want to figure out why this happens, but the keyword this was nearly impossible to search.
The text was updated successfully, but these errors were encountered:
Ok, things get complicated.
We want this to be an instance of Tangle. It is easy to solve: we can use bind(tangle).
However, instantiation of Tangle needs a time_machine instance.
Because time_machine.setup instantiate the WASM binary, we need to modify imported functions before the setup.
It is something like the chicken-egg problem.
For now, we are trying to access a property of an uninitialized instance.
It is hard to solve...
Maybe I misunderstood the issue. When is the function containing _in_call_that_will_be_reverted called? If you bind, it should still have access to the time_machine once it's set?
Options I'm thinking:
do not require the time_machine in the constructor, although this makes it temporarily unsafe?
bind the importObjects from Time Machine in the Tangle constructor (makes Time Machine only assignable to 1 instance)
create a 3rd object with the references it needs and use it after everything is setup?
I'm sure there are better solutions, I'm just curious what would help :)
The function containing _in_call_that_will_be_reverted is called when I call an imported function.
In addition, the function does not need a time_machine instance.
I prefer your 3rd option, but I am not sure.
Description
tangle/tangle_ts/src/tangle.ts
Lines 92 to 97 in 9abd443
When I call imported JS functions,
this
becomesundefined
.So,
this._in_call_that_will_be_reverted
cannot be read.What I did
I ran the example
counter
but in Zig instead of AssemblyScript.my_wasm.zig
However, I doubt that is a Zig-related problem.
As I know, the value of the
this
keyword depends on its context.Then, what is the value of
this
, if I call a function in a WASM?To check that, I modified
tangle.js:
Then it says:
The first 4 calls are
exports.increment(1)
s, and others areexports.multiply.callAndRevert(3)
s.This shows that wrapping a function call did not help!
tangle/tangle_ts/src/tangle.ts
Lines 328 to 331 in 9abd443
Additional note
I tried an arrow function, but it made
this._in_call_that_will_be_reverted
undefined
, andthis
was not aTangle
instance. (it was a function.)moduleImports[importName] = (...args) => {
I want to figure out why this happens, but the keyword
this
was nearly impossible to search.The text was updated successfully, but these errors were encountered: