Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Names used by Object.prototype properties cannot be defined as isolate scope properties #9343

Closed
jrencz opened this issue Sep 30, 2014 · 9 comments

Comments

@jrencz
Copy link

jrencz commented Sep 30, 2014

I run into an issue after defining a directive like this:

angular
    .module('foo', [])
    .directive('foo', function () {
        return {
            scope: {
                watch: '@',
            },
        };
    });

The top of the trace was:

Error: listeners.push is not a function
$CompileProvider/this.$get</Attributes.prototype.$observe@http://0.0.0.0:8505/vendor/forks/angular-1.3.0-rc.3-fork/angular/angular.js:6216:9

After I changed the name of the scope attribute into something else (like check) the issue was gone.

While researching the issue my teammate run into #8068 there the problem with watch as a get parameter was described and fixed.

I did check Firefox-only Object.prototype properties:

  • toSource
  • watch
  • unwatch

and they all make Firefox break, but not Chrome.

I checked some other Object.prototype properties:

  • valueOf
  • toString

those break in both Firefox and Chrome.

Changing the binding policy from @ to = does not cause an error.
Changing the binding policy from @ to & does not cause an error.

@mgol
Copy link
Member

mgol commented Sep 30, 2014

Thanks for the report! This looks like it should have a simple test case; could you create one on http://plnkr.co/ and check if the issue happens on the snapshot version as well?

@caitp
Copy link
Contributor

caitp commented Sep 30, 2014

yes its probably the same issue because of how $bindings are constructed, i'll take a quick look

@mgol
Copy link
Member

mgol commented Sep 30, 2014

Actually, I'm bumping the frequency as this can cause existing apps to break just because a browser adds a new thing to Object.prototype.

@caitp
Copy link
Contributor

caitp commented Sep 30, 2014

this doesn't look like it should affect the master branch, but lets test it and see

@mgol
Copy link
Member

mgol commented Sep 30, 2014

It affects at least 1.3.0-rc.3 (this is a bug report from a co-worker), I asked for a test case to make sure it hasn't been fixed recently.

@caitp
Copy link
Contributor

caitp commented Sep 30, 2014

yeah this does seem to be broken in snapshot... looking into it

@jrencz
Copy link
Author

jrencz commented Sep 30, 2014

Im away from keyboard right now. I'll provide the demo as soon as I get back to work later today.

@caitp
Copy link
Contributor

caitp commented Sep 30, 2014

I see the problem, will have a patch shortly

caitp added a commit to caitp/angular.js that referenced this issue Sep 30, 2014
Prevent accidentally treating a builtin function from Object.prototype as the binding object, and thus
preventing the compiler from throwing when using attribute binding names which match a property of the
Object prototype.

Closes angular#9343
@caitp
Copy link
Contributor

caitp commented Sep 30, 2014

no need for a demo, patch is up. now we wait for review

@caitp caitp closed this as completed in a27d827 Sep 30, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants