Skip to content
This repository was archived by the owner on Aug 17, 2022. It is now read-only.
This repository was archived by the owner on Aug 17, 2022. It is now read-only.

Instanceof / Upcast equivalent #4

@magcius

Description

@magcius

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions