Skip to content

Wrong function prototype lookup after setPrototypeOf #5970

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
barak007 opened this issue Feb 24, 2019 · 1 comment
Closed

Wrong function prototype lookup after setPrototypeOf #5970

barak007 opened this issue Feb 24, 2019 · 1 comment

Comments

@barak007
Copy link

Hi,
Sadly I can't reproduce the issue in minimal way but the behavior I'm experiencing in edge 44 is that a function prototype is being changed without any triggers from my side.

This is the basic idea of the broken setup.

I have a factory of functions:

function create(value, obj){
    ...
    function inner(){ ... }
    obj.someField = value
    /* override function prototype */
    Object.setPrototypeOf(inner, obj)
    return inner
}

The factory is used to create function instances

// usage of the factory
const f1 = create('1', {$: true})
const f2 = create('2', {$: true}) // this will be the test subject

Then, later on in code, f2 is being passed as an argument to another function. Here's a simplified version of that one:

function test(fn /* passing f2 */){
  console.log(fn.someField) // logs 2
  const values = ['someField'].map((key)=>fn[key]) // something went wrong here
  console.log(fn.someField) // logs 1, should log 2
}

It appears the second .someField lookup (inside the second console.log) gets the prototype of f1 instead of f2. Behavior suggests this is a JS engine caching issue for prototype lookup.

Same code functions properly in Chrome/FF.

I have managed to work around the issue by setting a property on the function itself:

function create(value, obj){
    ...
    function inner(){ ... }
    obj.someField = value
    /* override function prototype */
    Object.setPrototypeOf(inner, obj)
    inner.workAround = Math.random()
    return inner
}

maybe related to #5915

@rhuanjl
Copy link
Collaborator

rhuanjl commented Mar 26, 2020

This doesn't repro in 1.11 or master so closing as assumed already fixed.

@rhuanjl rhuanjl closed this as completed Mar 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants