From dde90bf17885baeb617549f1d1ef727071479040 Mon Sep 17 00:00:00 2001 From: Leo Balter <leonardo.balter@gmail.com> Date: Mon, 19 Nov 2018 14:42:22 -0500 Subject: [PATCH] Apply review feedback --- .../private-methods/cls-decl.template | 32 +++++++----------- .../private-methods/cls-expr.template | 33 +++++++------------ .../prod-private-async-generator.case | 1 + .../prod-private-async-method.case | 1 + .../prod-private-generator.case | 1 + src/class-elements/prod-private-method.case | 1 + 6 files changed, 27 insertions(+), 42 deletions(-) diff --git a/src/class-elements/private-methods/cls-decl.template b/src/class-elements/private-methods/cls-decl.template index 677c338146..8ef950e3cd 100644 --- a/src/class-elements/private-methods/cls-decl.template +++ b/src/class-elements/private-methods/cls-decl.template @@ -73,8 +73,12 @@ esid: prod-MethodDefinition * the template provides c.ref() for external reference */ -function hasOwnProperty(obj, name) { - return Object.prototype.hasOwnProperty.call(obj, name); +function hasProp(obj, name, expected, msg) { + var hasOwnProperty = Object.prototype.hasOwnProperty.call(obj, name); + assert.sameValue(hasOwnProperty, expected, msg); + + var hasProperty = Reflect.has(obj, name); + assert.sameValue(hasProperty, expected, msg); } class C { @@ -83,12 +87,9 @@ class C { get ref() { return this.#m; } constructor() { - assert.sameValue( - hasOwnProperty(this, '#m'), false, - 'private methods are defined in an special internal slot and cannot be found as own properties' - ); + hasProp(this, '#m', false, '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'); + assert.sameValue(this.ref, this.#m, 'returns the same value'); /*{ constructor }*/ } @@ -97,20 +98,9 @@ class C { var c = new C(); var other = new C(); -assert.sameValue( - hasOwnProperty(C.prototype, '#m'), false, - 'method is not defined in the prototype' -); - -assert.sameValue( - hasOwnProperty(C, '#m'), false, - 'method is not defined in the contructor' -); - -assert.sameValue( - hasOwnProperty(c, '#m'), false, - 'method cannot be seen outside of the class' -); +hasProp(C.prototype, '#m', false, 'method is not defined in the prototype'); +hasProp(C, '#m', false, 'method is not defined in the contructor'); +hasProp(c, '#m', false, 'method cannot be seen outside of the class'); /*** * MethodDefinition : ClassElementName ( UniqueFormalParameters ) { FunctionBody } diff --git a/src/class-elements/private-methods/cls-expr.template b/src/class-elements/private-methods/cls-expr.template index 781304d72c..dd301c9065 100644 --- a/src/class-elements/private-methods/cls-expr.template +++ b/src/class-elements/private-methods/cls-expr.template @@ -4,6 +4,7 @@ /*--- path: language/expressions/class/private-methods/ name: private method definitions in a class expression +features: [class, class-methods-private] info: | ClassElement : MethodDefinition @@ -73,8 +74,12 @@ esid: prod-MethodDefinition * 2. the template provides c.ref/other.ref for external reference */ -function hasOwnProperty(obj, name) { - return Object.prototype.hasOwnProperty.call(obj, name); +function hasProp(obj, name, expected, msg) { + var hasOwnProperty = Object.prototype.hasOwnProperty.call(obj, name); + assert.sameValue(hasOwnProperty, expected, msg); + + var hasProperty = Reflect.has(obj, name); + assert.sameValue(hasProperty, expected, msg); } var C = class { @@ -83,12 +88,9 @@ var C = class { get ref() { return this.#m; } constructor() { - assert.sameValue( - hasOwnProperty(this, '#m'), false, - 'private methods are defined in an special internal slot and cannot be found as own properties' - ); + hasProp(this, '#m', false, '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'); + assert.sameValue(this.ref, this.#m, 'returns the same value'); /*{ constructor }*/ } @@ -97,20 +99,9 @@ var C = class { var c = new C(); var other = new C(); -assert.sameValue( - hasOwnProperty(C.prototype, '#m'), false, - 'method is not defined in the prototype' -); - -assert.sameValue( - hasOwnProperty(C, '#m'), false, - 'method is not defined in the contructor' -); - -assert.sameValue( - hasOwnProperty(c, '#m'), false, - 'method cannot be seen outside of the class' -); +hasProp(C.prototype, '#m', false, 'method is not defined in the prototype'); +hasProp(C, '#m', false, 'method is not defined in the contructor'); +hasProp(c, '#m', false, 'method cannot be seen outside of the class'); /*** * MethodDefinition : ClassElementName ( UniqueFormalParameters ) { FunctionBody } diff --git a/src/class-elements/prod-private-async-generator.case b/src/class-elements/prod-private-async-generator.case index 6c3c0299a7..58490b7934 100644 --- a/src/class-elements/prod-private-async-generator.case +++ b/src/class-elements/prod-private-async-generator.case @@ -26,6 +26,7 @@ assert.sameValue(this.#m.name, '#m', 'function name inside constructor'); //- assertions assert.sameValue(c.ref.name, '#m', 'function name is preserved external reference'); ctorPromise.then(() => { + // gets the returned async iterator from #m var iter = c.ref(); return iter.next().then(({ value, done }) => { assert.sameValue(value, 42, 'return from generator method'); diff --git a/src/class-elements/prod-private-async-method.case b/src/class-elements/prod-private-async-method.case index 173575866b..872c31c74b 100644 --- a/src/class-elements/prod-private-async-method.case +++ b/src/class-elements/prod-private-async-method.case @@ -23,6 +23,7 @@ ctorPromise = this.#m().then(value => { //- assertions assert.sameValue(c.ref.name, '#m', 'function name is preserved external reference'); ctorPromise.then(() => { + // gets the returned promise from #m return c.ref().then(value => { assert.sameValue(value, 42, 'function return'); }); diff --git a/src/class-elements/prod-private-generator.case b/src/class-elements/prod-private-generator.case index 5d5821a900..334ca1cb12 100644 --- a/src/class-elements/prod-private-generator.case +++ b/src/class-elements/prod-private-generator.case @@ -17,6 +17,7 @@ assert.sameValue(res.done, true, 'iterator is done, inside ctor'); assert.sameValue(this.#m.name, '#m', 'function name inside constructor'); //- assertions +// gets the returned iterator from #m var res = c.ref().next(); assert.sameValue(res.value, 42, 'return from generator method'); assert.sameValue(res.done, true, 'iterator is done'); diff --git a/src/class-elements/prod-private-method.case b/src/class-elements/prod-private-method.case index 4e82ae18b7..38a9168779 100644 --- a/src/class-elements/prod-private-method.case +++ b/src/class-elements/prod-private-method.case @@ -14,5 +14,6 @@ assert.sameValue(this.#m(), 42, 'already defined in the ctor'); assert.sameValue(this.#m.name, '#m', 'function name inside constructor'); //- assertions +// gets the returned value from #m assert.sameValue(c.ref(), 42, 'function return'); assert.sameValue(c.ref.name, '#m', 'function name is preserved external reference'); -- GitLab