{"action":"opened","issue":{"url":"https://api.github.com/repos/scala-js/scala-js/issues/1882","labels_url":"https://api.github.com/repos/scala-js/scala-js/issues/1882/labels{/name}","comments_url":"https://api.github.com/repos/scala-js/scala-js/issues/1882/comments","events_url":"https://api.github.com/repos/scala-js/scala-js/issues/1882/events","html_url":"https://github.com/scala-js/scala-js/issues/1882","id":103444474,"number":1882,"title":"Provide implementations for missing Javascript Native statements","user":{"login":"mdedetrich","id":2337269,"avatar_url":"https://avatars.githubusercontent.com/u/2337269?v=3","gravatar_id":"","url":"https://api.github.com/users/mdedetrich","html_url":"https://github.com/mdedetrich","followers_url":"https://api.github.com/users/mdedetrich/followers","following_url":"https://api.github.com/users/mdedetrich/following{/other_user}","gists_url":"https://api.github.com/users/mdedetrich/gists{/gist_id}","starred_url":"https://api.github.com/users/mdedetrich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mdedetrich/subscriptions","organizations_url":"https://api.github.com/users/mdedetrich/orgs","repos_url":"https://api.github.com/users/mdedetrich/repos","events_url":"https://api.github.com/users/mdedetrich/events{/privacy}","received_events_url":"https://api.github.com/users/mdedetrich/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-08-27T07:19:49Z","updated_at":"2015-08-27T07:19:49Z","closed_at":null,"body":"This is mainly for performance considerations, which aren't an issue for most use cases, but definitely is an issue for other use cases (my current use case is implementing like `TimSort` for Scala.js)\r\n\r\nA lot of these high performant algorithm implementations tend to use stuff like `break`, `continue` and `break to label`, i.e. in java this looks like\r\n\r\n```java\r\nfirst:\r\nfor( int i = 0; i < 10; i++) {\r\n  second:\r\n  for(int j = 0; j < 5; j ++ )\r\n  {\r\n    break first;\r\n  }\r\n}\r\n```\r\n\r\nUnfortunately Scala doesn't labelled `while`/`for` loops. Scala also doesn't implement `break`, there is an implementation of `break` in `scala.util.Control.Breaks`, however this throws an exception (i.e. its not an actual `break` in the Java sense). Stuff like continue to label can be implemented using functions/closures, however it will have less performance that your `break to label` implementation.\r\n\r\nScala did not implement `break` because in context of closures/lambda's, the behaviour of break isn't defined. In Scala however, you could always get around this by just implementing that code in Java and then interfacing with it in Scala. You can't really do this in `Scala.js`, you are forced to use 100% Scala.\r\n\r\nIs there merit in providing a library that allows you to implement this functionality in Scala.js so it maps directly to Javascript. That is, being able to write a `break` in Scala.js so that is compiles to an actual break in `Javascript`, and same deal with `continue`/`break to label`? Note that this may not be an issue if the optimizer does actually do this automatically (I will have to verify myself when I actually finish `Timsort`), however I remember with my other work on soda-time, even with full optimizations, stuff generally doesn't get compiled down to `break`/`break to label`/`continue`."}}