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

Feature/duktape migration #94

Merged
merged 26 commits into from
Sep 5, 2018
Merged

Feature/duktape migration #94

merged 26 commits into from
Sep 5, 2018

Conversation

borjantrajanoski
Copy link
Contributor

No description provided.

@borjantrajanoski borjantrajanoski mentioned this pull request Aug 28, 2018
3 tasks
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
Copy link
Contributor

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() {}
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, will remove it

@@ -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
Copy link
Contributor

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.

Copy link
Contributor Author

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

m.fetchFunctionChan <- fetchFunction{
id: id,
respChan: respChan,
}
fn := <-respChan
context := <-respChan
Copy link
Contributor

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or vm

Copy link
Contributor Author

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


})
if err != nil {
m.logger.Error(err.Error())
}
err = context.PevalString(objArgs)
Copy link
Contributor

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)

Copy link
Contributor Author

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

  1. Object is being created
objArgs, err := m.vm.Object("(" + payload + ")")
	if err != nil {
		return err
	}

In duktape we do objArgs := "(" + payload + ")"

  1. 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

id, err := funcId.ToInteger()
require.Nil(t, err)
require.Equal(t, int64(1), id)
id := funcId + 1 // @TODO Maybe handle funcId better
Copy link
Contributor

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?

context.DupTop()
context.PushUndefined()
context.Call(1)
// @TODO find a way to test "expected value to be undefined"
Copy link
Contributor

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()?

Copy link
Contributor Author

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,
Copy link
Contributor

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"})

Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.


return otto.Value{}

//@TODO FIND OUT WHY DO WE NEED TO CLEAR THE STACK LIKE THIS?
Copy link
Contributor

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?

Copy link
Contributor Author

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.

if generatedBytes != "1, 4, 6" {
panic(err)
generatedBytes := (context.ToString(-1))
if generatedBytes != "[1 4 6]" {
Copy link
Contributor

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

Copy link
Contributor Author

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"

@florianlenz florianlenz merged commit d886554 into develop Sep 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants