This PR implements a change I wanted to do for a while. The bindings defined JS variables inconsistently, using const, let, and var all over the place. As it turns out, most variables can be declared as const and everything else can be var. So I create a simple API for creating variables. This API also takes care of resolving naming conflicts, so we'll never have to worry about temporary variables conflicting with argument names ever again. In the future, this system may also be used to resolve other naming conflicts, but I kept it simple for now.
For those needing a refresher on var, let, and const in JS:
const name = value: A block-scoped variable that cannot be reassigned.
let name = value: A block-scoped variable that can be reassigned.
var name = value: A function-scoped variable that can be reassigned.
Changes:
New API for JsBinding that handles the creating of variables. The new function automatically resolves name conflicts and ensure that temporary variable names never conflict with parameter names. The main functions of the new API are:
alias(name, expr): This creates a JS const variable. The variable is immutable.
var(name, initial): This creates a JS var variable. The variable is mutable AND visible in the finally block.
guarnatee_alias: Same as alias, but panics if the name is taken. This is necessary, because one instruction assumes that a variable called retptr has been created, so we can't rename that variable.
Use the new API everywhere. All variables are now created with the new API.
This PR implements a change I wanted to do for a while. The bindings defined JS variables inconsistently, using
const
,let
, andvar
all over the place. As it turns out, most variables can be declared asconst
and everything else can bevar
. So I create a simple API for creating variables. This API also takes care of resolving naming conflicts, so we'll never have to worry about temporary variables conflicting with argument names ever again. In the future, this system may also be used to resolve other naming conflicts, but I kept it simple for now.For those needing a refresher on
var
,let
, andconst
in JS:const name = value
: A block-scoped variable that cannot be reassigned.let name = value
: A block-scoped variable that can be reassigned.var name = value
: A function-scoped variable that can be reassigned.Changes:
JsBinding
that handles the creating of variables. The new function automatically resolves name conflicts and ensure that temporary variable names never conflict with parameter names. The main functions of the new API are:alias(name, expr)
: This creates a JSconst
variable. The variable is immutable.var(name, initial)
: This creates a JSvar
variable. The variable is mutable AND visible in thefinally
block.guarnatee_alias
: Same as alias, but panics if the name is taken. This is necessary, because one instruction assumes that a variable calledretptr
has been created, so we can't rename that variable.