Skip to content

Don't ignore array type for special JS array types #599

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

Merged
merged 5 commits into from
Feb 26, 2017

Conversation

flimzy
Copy link
Member

@flimzy flimzy commented Feb 26, 2017

This PR should fix the problem mentioned in #597 .

Using this sample program:

package main

import "honnef.co/go/js/console"

func main() {
	x := []byte{}
	var y []byte
	z := []byte{0x01}
	console.Log(x)
	console.Log(y)
	console.Log(z)
}

Before:

[]
[]
Uint8Array [ 1 ]

After:

Uint8Array [  ]
Uint8Array [  ]
Uint8Array [ 1 ]

js/js_test.go Outdated

func instanceof(x interface{}, y *js.Object) bool {
return js.Global.Call("$instanceof", x, y).Bool()
}
Copy link
Member Author

Choose a reason for hiding this comment

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

There may be a better way to do this test; I'm not sure what it would be.

Copy link
Member

Choose a reason for hiding this comment

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

This is fine I think.

Copy link
Member

Choose a reason for hiding this comment

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

I just realized that you added a new file for this. I'd prefer the eval method of line 15 for this. Also, could you maybe try to add a function to dummys that simply returns the parameter (thus externalizing the value) and then try .Get("constructor") != uint8Array?

Copy link
Member Author

Choose a reason for hiding this comment

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

A clever solution. Done.

@@ -120,7 +120,7 @@ var $substring = function(str, low, high) {

var $sliceToArray = function(slice) {
if (slice.$length === 0) {
return [];
return new slice.$array.constructor;
Copy link
Member

Choose a reason for hiding this comment

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

Can we simply remove this special case? subarray and slice with a length of 0 should give the same result.

Copy link
Member Author

Choose a reason for hiding this comment

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

I tested with that entirely removed at first, and it worked just as well. I wondered if the special case served as a meaningful optimization, so left it in there.

If you're in favor of removing it, that is of course fine with me. I can make that change.

@neelance
Copy link
Member

Cool. Thanks the updates and for contributing in general. Merging.

@neelance neelance merged commit 96e2b0e into gopherjs:master Feb 26, 2017
@flimzy flimzy deleted the arrayfix branch February 26, 2017 18:41
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