Const and Types

The “const” keyword can either be ignored for member declarations, or be replaced with “var”. Types disappear in JavaScript.

// JavaScript:
var num = 1.0;

int and uint

In JavaScript you only have one Number data type, while ActionScript supports Number, int, and uint. This is quite problematic, because int and uint represent 32-bit integers with smaller number ranges than Number’s:

The implications are devastating. You can imagine that injecting utility function calls for every numeric operation involving uint and int will result in slow JavaScript code. In order to prevent that we might have to bend the rules. Here are three ideas:

“Roll overs are bugs” – Don’t inject utility function calls and live with the differences between ActionScript and JavaScript.

“Use Number instead” – Drop support for uint and int and throw a syntax error if the client code uses uint or int.

“It’s only bad in debug” – Use “dart rules” and inject function calls only in debug mode. In release mode we would use the original expressions.

Besides potentially having to inject utility function calls for numeric operations we probably also need to create fake int and uint classes for things like MAX_VALUE and instanceof:

E4X

According to Wikipedia “ECMAScript for XML (E4X) is a programming language extension that adds native XML support to ECMAScript (which includes ActionScript, JavaScript, and JScript)”. This feature seems to be quite popular. For example, Open Source Media Framework (OSMF), away3D, and papervision3D all use E4X . But reality is that none of the major browsers except for Firefox support E4X and it seems unlikely that they ever will. Even Mozilla seems to have moved away from E4X. On their website they warn:

Warning: Mozilla is not actively maintaining E4X except
for security bugs. Do not use it for any new work.

Cross-compiling E4X to JavaScript can be done but it’s probably not worth the trouble. You would have to inject appropriate utility function calls for every E4X expression. My recommendation would be dropping support for E4X when cross-compiling ActionScript to JavaScript. In other words if the client code uses E4X our cross-compiler needs to report clear error messages.