-
Notifications
You must be signed in to change notification settings - Fork 6
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
Feature/duktape migration #94
Conversation
dapp/dapp.go
Outdated
@@ -132,7 +130,8 @@ func New(l *logger.Logger, app *Data, vmModules []module.Module, closer chan<- * | |||
|
|||
// start the DApp async | |||
go func() { | |||
_, err := vm.Run(app.Code) | |||
//@TODO make sure that the logic of otto's vm.Run is equivalent to vm.PevalString in this use case |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it? Did you figure it out?
dapp/dapp.go
Outdated
@@ -147,7 +146,7 @@ func New(l *logger.Logger, app *Data, vmModules []module.Module, closer chan<- * | |||
} | |||
return dApp, nil | |||
case <-time.After(timeOut): | |||
vm.Interrupt <- func() {} | |||
//vm.Interrupt <- func() {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can remove this I guess
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, will remove it
dapp/module/callbacks/module.go
Outdated
@@ -146,37 +146,34 @@ func (m *Module) Close() error { | |||
// e.g. myRegisteredFunction(payloadObj, cb) | |||
// the callback must be called in order to "return" from the function | |||
func (m *Module) CallFunction(id uint, payload string) error { | |||
|
|||
idInt := int(id) - 1 // @TODO find out why there are discrepencies between the id and stack positioning |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you figure it out? If you can't figure it out you can maybe create an GH issue and ask for it. Or on stack overflow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe here my description sounds more serious than it is. I think there is no general issue, my best guess is that it's related to where we start counting, from 0
or from 1
, will look into it
dapp/module/callbacks/module.go
Outdated
m.fetchFunctionChan <- fetchFunction{ | ||
id: id, | ||
respChan: respChan, | ||
} | ||
fn := <-respChan | ||
context := <-respChan |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for readability I would rename this to dkt
(if you want it short) or duktape
or something else
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or vm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, will rename it to something more descriptive
dapp/module/callbacks/module.go
Outdated
|
||
}) | ||
if err != nil { | ||
m.logger.Error(err.Error()) | ||
} | ||
err = context.PevalString(objArgs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what exactly are you doing here? (maybe add a comment why you are doing it and what)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Otto implementation had a few steps
- Object is being created
objArgs, err := m.vm.Object("(" + payload + ")")
if err != nil {
return err
}
In duktape we do
objArgs := "(" + payload + ")"
- Object is being pushed at the stack as first argument
_, err = fn.Call(*fn, ==> objArgs, <== func(call otto.FunctionCall) otto.Value {
In duktape we do
err = context.PevalString(objArgs)
which is pushing the object as first argument in the stack
dapp/module/callbacks/module_test.go
Outdated
id, err := funcId.ToInteger() | ||
require.Nil(t, err) | ||
require.Equal(t, int64(1), id) | ||
id := funcId + 1 // @TODO Maybe handle funcId better |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is it funcId + 1
?
dapp/module/callbacks/module_test.go
Outdated
context.DupTop() | ||
context.PushUndefined() | ||
context.Call(1) | ||
// @TODO find a way to test "expected value to be undefined" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is about about to call IsUndefined()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't able to find an easy solution to test IsUndefined()
from here as in Otto we can get a return value directly and test if that IsUndefined()
but in Duktape it doesn't work the same. Open to ideas / suggestions on this one.
|
||
// make sure function exist | ||
respChan := make(chan *otto.Value) | ||
respChan := make(chan *duktape.Context) | ||
m.fetchFunctionChan <- fetchFunction{ | ||
id: 1, | ||
respChan: respChan, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no error assertion on m.CallFunction(1,
{key: "value"})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And I think it's not called twice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will look into the error assertion on m.CallFunction
Similar as the comment before, I wasn't able to find an easy way to get the value "Callback: Already called callback
, which is why it's not implemented in the automated tests, however I did manual tests to ensure that indeed it gets called twice and it did.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually running go test ./...
suppresses stdout / fmt output somehow, so you might need to navigate into the actual module dir, and just run go test
and with this it can be confirmed that it gets called twice.
dapp/module/message/message.go
Outdated
|
||
return otto.Value{} | ||
|
||
//@TODO FIND OUT WHY DO WE NEED TO CLEAR THE STACK LIKE THIS? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you figure it out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, on https://duktape.org/api.html
, each function description includes Stack : (No effect on value stack.)
or a description of the effect it has on the stack, so when we call functions which modify the stack, we need to Pop them in order for things to work as intended.
dapp/module/randBytes/module_test.go
Outdated
if generatedBytes != "1, 4, 6" { | ||
panic(err) | ||
generatedBytes := (context.ToString(-1)) | ||
if generatedBytes != "[1 4 6]" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The old value "1, 4, 6"
is better to turn into a array on the JS side
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will modify it to match the old value "1, 4, 6"
…passing them to vm.Call
No description provided.