Skip to content

Updating meta of proto object wrongly #53

@arpit-agarwal

Description

@arpit-agarwal

When we have a mutable value on proto object and update the same to save on self. It is updating the metadata value on proto object as well.

I do understand that I should clone the value before updating but still when we get values from proto ( not self) it should be cloned and passed to avoid accidental fail. I could have done thsi but this was @angular/ compiler code that was causing an issue.

I have froked the repo here https://github.com/arpit-agarwal/reflect-metadata and added a test-case which fails on your repo and works after my fix for cloning. If desired i may create a pull request.
MutableKeyValueDefinedOnPrototype

    it("MutableKeyValueDefinedOnPrototype", () => {
        let prototype = {};
        let obj = Object.create(prototype);
        Reflect.defineMetadata("key", ["value_proto"], prototype, undefined);
        let result = Reflect.getMetadata("key", obj, undefined);
        assert.equal(result[0], "value_proto");
        result.push("value_self");
        Reflect.defineMetadata("key", result , obj, undefined);
        let result_proto = Reflect.getMetadata("key", prototype, undefined);
        let result_self = Reflect.getMetadata("key", obj, undefined);
        assert.equal(result_proto.length, 1);
        assert.equal(result_self.length, 2);

    });

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions