Change object instantiation to create wrappers and not wrapped classes.

Review Request #12906 — Created March 22, 2023 and submitted — Latest diff uploaded

Information

Spina
master

Reviewers

In Spina 1, when instantiating a Spina-wrapped class, the wrapper would
return an instance of the wrapped class, rather than the wrapper. The
aim was to get as close as possible to returning the defined class.
However, this had issues:

  1. Consumers couldn't do instanceof checks against the class, because
    the wrapped class's instance would never be an instance of the
    wrapper.

  2. Operations on the wrapper's prototype wouldn't apply to the wrapped
    class's prototype, and this would break things like Jasmine spies or
    any operations that needed to deal with instances or state on
    prototypes.

  3. It just generally made it confusing, having MyClass and
    new MyClass() being very different things.

Ultimately, there's no reason to avoid returning an instance of the
wrapper class. This change updates the logic so we're always getting an
instance of the class the caller constructed.

This shouldn't negatively impact any callers, but it is a big enough
change in behavior that we're calling this Spina 2.0. (More
potentially-breaking changes are also coming).

Tested this in Review Board, along with some upcoming changes, and
verified all tests passed.

Manually tested construction of wrapper classes, making sure that
the instances were in fact instances of the wrapper class and not the
wrapped class.

Commits

Files

    Loading...