gopherjs / gopherwasm

This package is deprecated. Use syscall/js of GopherJS instead.
BSD 2-Clause "Simplified" License
79 stars 5 forks source link

Fix js.ValueOf() with map[string]interface{} under gopherjs - fixes #19 #20

Closed ncw closed 5 years ago

ncw commented 5 years ago

I'm not 100% sure this is the right fix, but it seems to work!

ncw commented 5 years ago

Will add []interface{} and tests shortly!

ncw commented 5 years ago

I've updated the commit with tests too!

I've added a commit to fix a typo in the .travis.yml also which meant it was testing gopherjs not gopherwasm.

I'm still not 100% sure travis is testing the pull request though rather than master.

In .travis.yml there is the line

  - go get github.com/gopherjs/gopherwasm@master

Which seems to me it overwrites the already checked out pull request with master doesn't it? Or maybe it doesn't since this is outside GOPATH? :confused:

hajimehoshi commented 5 years ago

Thank you for fixing! I didn't realize the misspelling :-)

Which seems to me it overwrites the already checked out pull request with master doesn't it?

This go get is module-get for the current directory and doesn't affect $GOPATH/go. GopherJS doesn't recognize modules, so the test includes both go get. After GopherJS accepts modules, I'll merge them into module-get.

ncw commented 5 years ago

I've added JSON.stringify - it works much better :-)

I had to only have one item in the object as the order of the keys can vary, but I don't think that is a problem.

Thanks for your explanation about the go mod stuff.

hajimehoshi commented 5 years ago

I had to only have one item in the object as the order of the keys can vary, but I don't think that is a problem.

Right, that's a good point. I think the current test is totally fine.

ncw commented 5 years ago

PS Thanks for a great project - it is very useful! I'm using it here https://gpython.org/

hajimehoshi commented 5 years ago

Thank you for your PR! Is that a Python interpreter in Go? Awesome work!

ncw commented 5 years ago

Thank you for your PR! Is that a Python interpreter in Go? Awesome work!

It is! Not the full thing alas since too many modules are in C but the core is there :-) I was amazed that gopherjs just compiled it no fuss and it worked! (Well I found one bug in gopherjs (which I reported) but that is pretty minor! Try 2**10 in the gpython repl if you want to see it in action!)

hajimehoshi commented 5 years ago

Cool! I tried but on GopherJS version, there were errors:

>>> 2 ** 10
[USER]: runtime error: invalid memory address or nil pointer dereference
Error: runtime error: invalid memory address or nil pointer dereference
    at $callDeferred (https://gpython.org/gpython.js:4:22511)
    at $panic (https://gpython.org/gpython.js:4:22957)
    at AK (https://gpython.org/gpython.js:10:2423)
    at Object.$throwNilPointerError (https://gpython.org/gpython.js:4:486)
    at Object.get (https://gpython.org/gpython.js:4:4522)
    at Object.$packages.math/big.BL.ptr.Exp (https://gpython.org/gpython.js:38:95689)
    at Object.$packages.github.com/go-python/gpython/py.BH.ptr.pow (https://gpython.org/gpython.js:41:102703)
    at Object.$packages.github.com/go-python/gpython/py.BH.ptr.M__pow__ (https://gpython.org/gpython.js:41:103772)
    at $packages.github.com/go-python/gpython/py.EQ.M__pow__ (https://gpython.org/gpython.js:41:236522)
    at Object.AZ [as Pow] (https://gpython.org/gpython.js:41:73603)
    at V (https://gpython.org/gpython.js:44:18787)
    at DO (https://gpython.org/gpython.js:44:91592)
    at DU (https://gpython.org/gpython.js:44:107450)
    at Object.DW [as Run] (https://gpython.org/gpython.js:44:109015)
    at Object.$packages.github.com/go-python/gpython/repl.G.ptr.Run (https://gpython.org/gpython.js:56:3575)
    at $b (https://gpython.org/gpython.js:60:3908)
    at $b (https://gpython.org/gpython.js:59:2625)
    at r (https://gpython.org/gpython.js:4:23443)
    at $runScheduled (https://gpython.org/gpython.js:4:24007)
    at $schedule (https://gpython.org/gpython.js:4:24184)
    at $go (https://gpython.org/gpython.js:4:23907)
    at https://gpython.org/gpython.js:59:2237
    at jQuery.fn.init.e.$externalizeWrapper.e.$externalizeWrapper (https://gpython.org/gpython.js:4:28925)
    at a (https://cdnjs.cloudflare.com/ajax/libs/jquery.terminal/1.23.2/js/jquery.terminal.min.js:40:82615)
    at jQuery.fn.init.k (https://cdnjs.cloudflare.com/ajax/libs/jquery.terminal/1.23.2/js/jquery.terminal.min.js:40:83463)
    at Object.ENTER (https://cdnjs.cloudflare.com/ajax/libs/jquery.terminal/1.23.2/js/jquery.terminal.min.js:40:14915)
    at HTMLHtmlElement.$e (https://cdnjs.cloudflare.com/ajax/libs/jquery.terminal/1.23.2/js/jquery.terminal.min.js:40:28362)
    at HTMLHtmlElement.dispatch (https://code.jquery.com/jquery-latest.js:4641:9)
    at HTMLHtmlElement.elemData.handle (https://code.jquery.com/jquery-latest.js:4309:28)

EDIT: Ah ok, I understood this is the bug in GopherJS.