Skip to content
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

self shouldn't be allowed inside of a non-method #107

Closed
jmarr opened this issue Mar 11, 2016 · 2 comments
Closed

self shouldn't be allowed inside of a non-method #107

jmarr opened this issue Mar 11, 2016 · 2 comments
Milestone

Comments

@jmarr
Copy link

jmarr commented Mar 11, 2016

Example:

@implementation Foo
 var foobar = function( ) {
  return [self bar];
}
@end

The [self bar] call should not be allowed.

@iccir
Copy link
Member

iccir commented Mar 12, 2016

That should be a compiler error, as self makes no sense in that context. Implementation-wise, it currently compiles to this, but that has never been guaranteed.

In vanilla browser-based JavaScript, self is a property on the window object which returns a WindowProxy.

Hence, there may be situations where you'd want to use self in a function inside of an @implementation block (although this wouldn't be valid in your example, as we'd be messaging the WindowProxy with an oj msgSend). I don't feel comfortable preventing this use as an error.

However, I could see the case for a "warn when self is used inside of an @implementation block but not inside of a method". Or possibly even "warn when self is used in a non-method inside of an oj file".

But probably not "always warn about the usage of self", as it may be validly used in a JavaScript library or pure-JS file.

iccir added a commit that referenced this issue Mar 26, 2016
iccir added a commit that referenced this issue Mar 26, 2016
@iccir
Copy link
Member

iccir commented Mar 26, 2016

Added a new --warn-self-in-non-methods option, which warns on any usage of self outside of a non-method. For JS libraries or pure-JS files, see #113

@iccir iccir closed this as completed Mar 26, 2016
@iccir iccir added this to the 2.0 milestone Mar 26, 2016
iccir added a commit that referenced this issue Mar 9, 2023
iccir added a commit that referenced this issue Mar 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants