Coding in web browsers
Nov. 11th, 2010 12:55 pm![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
![[livejournal.com profile]](https://www.dreamwidth.org/img/external/lj-userinfo.gif)
At the moment we write Javascript in web pages, which is then compiled down by the various JIT methods that Firefox/IE/Webkit use to make it super fast.
Seeing as what's run clearly isn't the actual JS itself, but bytecode, why not have a standardised bytecode that all browsers would support, which would then mean you could write your code in any language you liked, providing there was a compiler to convert it to the standardised bytecode?
At the moment Google uses GWT to convert Java into Javascript that then gets converted into the running code, (And MS used to have something similar) wouldn't it be handy if the intermediate step wasn't necessary?
no subject
Date: 2010-11-11 01:04 pm (UTC)Compile? What is this 'compile'?
no subject
Date: 2010-11-11 01:18 pm (UTC)But for stuff that's linked in there's no reason that the equivalent of:
<script type="byte/code" language="bytecode" src="http://myserver/somecode.byt"></script>
no subject
Date: 2010-11-11 02:16 pm (UTC)(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:no subject
Date: 2010-11-11 02:40 pm (UTC)First is turning the source into platform-independent bytecode, this happens upfront.
Second is "Just in Time compilation" during execution, when the runtime needs to use a method that has not been used before, and so needs to turn the bytecode for it into something that can actually execute on whatever cpu.
I'd say that Andrew is referring to the first of these.
no subject
Date: 2010-11-11 02:46 pm (UTC)(no subject)
From:(no subject)
From:no subject
Date: 2010-11-11 01:11 pm (UTC)no subject
Date: 2010-11-11 01:19 pm (UTC)It'd need to be part of HTML6, obviously :->
no subject
Date: 2010-11-11 03:15 pm (UTC)(no subject)
From:no subject
Date: 2010-11-11 01:18 pm (UTC)no subject
Date: 2010-11-11 02:00 pm (UTC)no subject
Date: 2010-11-11 01:20 pm (UTC)no subject
Date: 2010-11-11 01:26 pm (UTC)(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:no subject
Date: 2010-11-11 01:21 pm (UTC)(The answer is because Javascript is lacking some functionality, not specified with sufficient rigour, in too many versions, with varying degrees of implementation in the browsers, and it takes too long to get changes into the spec, but I don't see how another spec for bytecode is going to be any different in this respect. You can only get round these problems by owning and implementing the spec yourself -- in which case you're re-inventing Flash or Silverlight.)
no subject
Date: 2010-11-11 01:26 pm (UTC)Heck, I'd be happy with either Java bytecode or IL if they were suitable.
Compiling Java into JS seems terribly suboptimal to me, although I'm prepared to be told that actually it's a good fit. Having something that can be implemented in a standard way by the big 3 would be good.
(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:no subject
Date: 2010-11-11 02:45 pm (UTC)Currently yes. But there's no reason why that should be so. In fact, isn't that the proposal?
Something like how The Java and .Net bytecodes are standardised and designed to be platform-independent, which is kinda the point. They can be executed by different engines. Those engines may have different internals, but executing that standard bytecode is their entire purpose.
.Net bytecode is less obviously "platform-independent" than Java. But there are 32 and 64 bit windows runtimes that work with the same bytecode. And mono/Linux run that same bytecode.
Native Client
Date: 2010-11-11 02:12 pm (UTC)http://code.google.com/p/nativeclient/
It probably will use LLVM bytecode at some point (I think it already supports that). Atm., it executes x86.
The hard part is the sandboxing. But it seems they have done well on this in the Natice Client.
Re: Native Client
Date: 2010-11-11 02:35 pm (UTC)no subject
Date: 2010-11-11 02:36 pm (UTC)A bytecode standard is not a bad idea.
no subject
Date: 2010-11-11 03:08 pm (UTC)no subject
Date: 2010-11-11 03:16 pm (UTC)no subject
Date: 2010-11-11 03:18 pm (UTC)Security in bytecode systems is a problem that has been solved more than once, so it doesn't appear to be that hard. JS has no pointers, hence no buffer overflows, and I'd expect the bytecode to be likewise. In Java or .Net bytecode, security is mainly about gating access to the system API by untrusted bytecode.
(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:no subject
Date: 2010-11-11 04:01 pm (UTC)no subject
Date: 2010-11-11 03:51 pm (UTC)no subject
Date: 2010-11-11 03:55 pm (UTC)no subject
Date: 2010-11-12 02:20 am (UTC)llvm would be a nice idea but is still relatively young and unsuitable for jit compilation or mobile devices.
anything higher up (like an object system or datatypes like a string or a list or a hash) would present the same problems as compiling to javascript.