Basic tests for private methods#1963
Conversation
| * the template provides c.ref() for external reference | ||
| */ | ||
|
|
||
| function hasOwnProperty(obj, name) { |
There was a problem hiding this comment.
Can you just use Reflect.has(obj, name) instead?
There was a problem hiding this comment.
Interesting... using Reflect.has I can also confirm the private method is not in the prototype chain. I wonder if I should use both.
| ---*/ | ||
|
|
||
| /*** | ||
| * template notes: |
There was a problem hiding this comment.
This new practice is excellent—thanks!
| /*--- | ||
| description: Private Async Generator (private method definitions in a class expression) | ||
| esid: prod-MethodDefinition | ||
| features: [async-iteration] |
There was a problem hiding this comment.
Missing class-methods-private
| * 1. Let methodDef be DefineMethod of MethodDefinition with argument homeObject. | ||
| * ... | ||
| */ | ||
| assert.sameValue(c.ref, other.ref, 'The method is defined once, and reused on every new instance'); |
There was a problem hiding this comment.
1. ref isn't a method
2. I'm certain these semantics are already well tested
| 'private methods are defined in an special internal slot and cannot be found as own properties' | ||
| ); | ||
| assert.sameValue(typeof this.#m, 'function'); | ||
| assert.sameValue(this.ref(), this.#m, 'returns the same value'); |
There was a problem hiding this comment.
ref is an accessor, so this should be assert.sameValue(this.ref, this.#m, 'returns the same value');.
|
|
||
| assert.sameValue(c.ref.name, '#m', 'function name is preserved external reference'); | ||
| ctorPromise.then(() => { | ||
| var iter = c.ref(); |
There was a problem hiding this comment.
I think it would be helpful if there was a comment that accompanied this line, which noted that this is actually calling this.#m
| 'private methods are defined in an special internal slot and cannot be found as own properties' | ||
| ); | ||
| assert.sameValue(typeof this.#m, 'function'); | ||
| assert.sameValue(this.ref(), this.#m, 'returns the same value'); |
There was a problem hiding this comment.
Same as above, should be fixed in https://github.com/tc39/test262/pull/1963/files#diff-0d2c472101ba48bbc07d267a50c4f19bR91
|
I pushed the changes, please review again, @rwaldron |
No description provided.