Host bindings, DOM in particular, use subclasses a lot. We would need some ability to do type discrimination. For instance, if I were to receive a DOMEvent object, I would likely want to be able to determine that this is DOMMouseEvent, and be able to call DOMMouseEvent-y things on it.
The details on runtime typechecking in the current proposal are vague (it just says "Throw TypeError (as now) if the wrong type is stored in a Table." but does not elaborate on what "the wrong type" means). Assuming that this is a strict 1:1 type-check, we would need some way to do runtime type discrimination, and a way to cast from one type to another.
Possible idea: a CAST instruction which takes two table indexes src and dest. The instruction checks src instanceof TableType(dest). If the check passes, 1 is pushed to the stack and the object's address copied into dest, so it exists in both tables. Otherwise, 0 is pushed to the stack. Cleanup for both src and dest is left to native code.
A variant of the instruction which takes a table index and a typeidx might also be entertained, in case of if (foo instanceof Type) checks that have no need to access the resulting casted object.
Host bindings, DOM in particular, use subclasses a lot. We would need some ability to do type discrimination. For instance, if I were to receive a
DOMEventobject, I would likely want to be able to determine that this isDOMMouseEvent, and be able to callDOMMouseEvent-y things on it.The details on runtime typechecking in the current proposal are vague (it just says "Throw TypeError (as now) if the wrong type is stored in a Table." but does not elaborate on what "the wrong type" means). Assuming that this is a strict 1:1 type-check, we would need some way to do runtime type discrimination, and a way to cast from one type to another.
Possible idea: a
CASTinstruction which takes two table indexessrcanddest. The instruction checkssrc instanceof TableType(dest). If the check passes,1is pushed to the stack and the object's address copied intodest, so it exists in both tables. Otherwise,0is pushed to the stack. Cleanup for bothsrcanddestis left to native code.A variant of the instruction which takes a table index and a typeidx might also be entertained, in case of
if (foo instanceof Type)checks that have no need to access the resulting casted object.