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.
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);
});
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