From cbc8b7c7a4459a75e5a92075a8b66112acf2b845 Mon Sep 17 00:00:00 2001 From: Kubilay Kahveci Date: Tue, 4 Dec 2018 09:55:31 +0000 Subject: [PATCH] test: Ensure private methods are visible from all initializers --- .../prod-private-method-initialize-order.case | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/class-elements/prod-private-method-initialize-order.case diff --git a/src/class-elements/prod-private-method-initialize-order.case b/src/class-elements/prod-private-method-initialize-order.case new file mode 100644 index 0000000000..d6e72eb5c0 --- /dev/null +++ b/src/class-elements/prod-private-method-initialize-order.case @@ -0,0 +1,40 @@ +// Copyright (C) 2018 Kubilay Kahveci (Bloomberg LP). All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: Private methods are added before any field initializer is run, even if they appear textually later +info: | + + InitializeInstanceElements ( O, constructor ) + ... + 4. For each item element in order from elements, + a. If element.[[Placement]] is "own" and element.[[Kind]] is "method", + i. Perform ? DefineClassElement(O, element). + 5. For each item element in order from elements, + a. If element.[[Placement]] is "own" and element.[[Kind]] is "field", + i. Assert: element.[[Descriptor]] does not have a [[Value]], [[Get]] or [[Set]] slot. + ii. Perform ? DefineClassElement(O, element). + 6. Return. + + EDITOR'S NOTE: + Value properties are added before initializers so that private methods are visible from all initializers. + +template: private-methods +features: [class-methods-private, class-fields-private] +---*/ + +//- element +a = this.#m(); + +#m() { return 42; } +get bGetter() { return this.#b; } + +#b = this.#m(); + +//- constructor +assert.sameValue(this.a, 42); +assert.sameValue(this.#b, 42); + +//- assertions +assert.sameValue(c.a, 42); +assert.sameValue(c.bGetter, 42);