Skip to content

Props validation fails for type 'Object' on prototype-less objects #1680

@jum-odoo

Description

@jum-odoo

Scenario

import { Component, mount, xml } from "@odoo/owl";

class Child extends Component {
    static template = xml`<span t-esc="props.object.value" />`;
    static props = {
        object: {
            type: Object,
            shape: {
                value: String,
            },
        },
    };
}

// Main root component
class Root extends Component {
    static components = { Child };
    static template = xml`Hello <Child object="object" />`;

    setup() {
        this.object = Object.create(null);
        this.object.value = "World";
    }
}

mount(Root, document.body, { dev: true });

Issue

Props validation fails, while the given object prop is indeed an object with the correct shape, although not having the "Object" prototype. While this object does not meet the "instanceof" check, I think it should still be validated as an object.

Cause

Object validation is made via <x> instanceof <Class>, which fails for objects without a prototype (i.e. Object.create(null)).

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