{"action":"created","issue":{"url":"https://api.github.com/repos/sq/JSIL/issues/773","labels_url":"https://api.github.com/repos/sq/JSIL/issues/773/labels{/name}","comments_url":"https://api.github.com/repos/sq/JSIL/issues/773/comments","events_url":"https://api.github.com/repos/sq/JSIL/issues/773/events","html_url":"https://github.com/sq/JSIL/pull/773","id":98503114,"number":773,"title":"JS Numeric types are wrapped if passed as object.","user":{"login":"iskiselev","id":5084964,"avatar_url":"https://avatars.githubusercontent.com/u/5084964?v=3","gravatar_id":"","url":"https://api.github.com/users/iskiselev","html_url":"https://github.com/iskiselev","followers_url":"https://api.github.com/users/iskiselev/followers","following_url":"https://api.github.com/users/iskiselev/following{/other_user}","gists_url":"https://api.github.com/users/iskiselev/gists{/gist_id}","starred_url":"https://api.github.com/users/iskiselev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iskiselev/subscriptions","organizations_url":"https://api.github.com/users/iskiselev/orgs","repos_url":"https://api.github.com/users/iskiselev/repos","events_url":"https://api.github.com/users/iskiselev/events{/privacy}","received_events_url":"https://api.github.com/users/iskiselev/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":11,"created_at":"2015-08-01T03:33:23Z","updated_at":"2015-10-06T11:12:45Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/sq/JSIL/pulls/773","html_url":"https://github.com/sq/JSIL/pull/773","diff_url":"https://github.com/sq/JSIL/pull/773.diff","patch_url":"https://github.com/sq/JSIL/pull/773.patch"},"body":"I've tried to implement fix for #349 - as was discussed, boxed numeric types are also boxed from Raw JS types in JavaScript.\r\nThis PR is still **not ready for merging**, but @kg, I'd like to discuss it with you and probably will need your help.\r\n- With this change dynamic work with numeric types was broken. Please look on DynamicBinaryOperators test for example. As dynamic variables are objects, integers are wrapped. I've not found how can I avoid this behavior, as I have no information that I'm processing translated dynamic CallSite in my WrapLiterals visitors - that information was stripped on function translation\r\n- Second problem is VerbatimVariablesExistingArray test. Integers inside `object[]` are wrapped, so probable `Verbatim.Expression` should unwrap them. On other side, it may not be a problem at all as can be solved inside expression by end user.\r\n\r\nThen, not all problems are solved:\r\n- We still need resolve type based on it's information in translation-time if it is unwrapped - as you suggested in first comment to #349.\r\n- Type of expressions like `(byte)12` incorrectly treated as `Int32` - this information is lost inside `ILBlockTranslator.Translate_Box` method. Should discuss how we can solve it."},"comment":{"url":"https://api.github.com/repos/sq/JSIL/issues/comments/145824390","html_url":"https://github.com/sq/JSIL/pull/773#issuecomment-145824390","issue_url":"https://api.github.com/repos/sq/JSIL/issues/773","id":145824390,"user":{"login":"kg","id":198130,"avatar_url":"https://avatars.githubusercontent.com/u/198130?v=3","gravatar_id":"","url":"https://api.github.com/users/kg","html_url":"https://github.com/kg","followers_url":"https://api.github.com/users/kg/followers","following_url":"https://api.github.com/users/kg/following{/other_user}","gists_url":"https://api.github.com/users/kg/gists{/gist_id}","starred_url":"https://api.github.com/users/kg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kg/subscriptions","organizations_url":"https://api.github.com/users/kg/orgs","repos_url":"https://api.github.com/users/kg/repos","events_url":"https://api.github.com/users/kg/events{/privacy}","received_events_url":"https://api.github.com/users/kg/received_events","type":"User","site_admin":false},"created_at":"2015-10-06T11:12:45Z","updated_at":"2015-10-06T11:12:45Z","body":"I think we only care about types that are translated as JS native types. So: numbers, char, string, array. We need to maintain the JS protocols, though, which is a real problem. I think our only choice there is to not wrap strings or arrays. For arrays, we can probably attach type information to them with a weakmap or a custom named property (the latter works alright in engines now, I believe). For strings I think we will stick with JS String and just have to deal with the fact that they don't ever have referential equality. (Though maybe ```str[i]``` works on ```new String``` in JS? I've never tried.)\r\n\r\nSo I think the path forward looks mostly like what you have here with wrapping. We have a generic 'box' type, maybe just an improvement on the one currently used for ref/out vars, and it is used to store boxed numeric types (including ```char```). We switch char over to a numeric type.\r\n\r\nThe box type will need to get smarter: ```toString``` and ```valueOf``` on it will need to be implemented appropriately, such that ```'hello' + (new Box<char>(33))``` produces ```'hello!'```. I think that's probably not too hard to do, though. Most (all?) of the code JSILc generates won't rely on that property, but we want to make sure JS interop scenarios don't end up totally hosed. There will definitely be issues where JS grabs an unboxed numeric type out of a field and passes it back into C#, but I think that will just be a place where JS needs to obey protocols when dealing with JSIL data structures (maybe in special cases we can have an attribute that forces fields to always be boxed so it's safe for JS to touch them.)"}}