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

Undesired access gain between 2 instances of different types. #15

@PedroUrday

Description

@PedroUrday

Hi @TremayneChrist

I have found an error when there are two or more instances of different types. The error can be described with the next source code example:

function A() {}
function B() {}

A.prototype.public = function (b) {
    console.log("Called A public method");
    b.public(this);
};

B.prototype.public = function (a) {
    console.log("Called B public method");
    a._private(this);
};

A.prototype._private = function (b) {
    console.log("Called A private method. It should not pass :(");
    b._private(this);
};

B.prototype._private = function (a) {
    console.log("Called B private method. It too should not pass :(");
};

protect(A);
protect(B);

var a = new A();
var b = new B();

a.public(b);

I try to solve this without success! I'm checking my own fork. I tried with the proxy pattern (https://en.wikipedia.org/wiki/Proxy_pattern) but I think that leads to more problems.

Best regards!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions