77d50cd8e7
This patch implements the declaration of private accessors. When iterating over the class properties, we track private accessors associated with the same name in a ZoneHashMap. Once we get to all the necessary components for a private name (we know statically whether we should expect only a setter, only a getter, or both), we emit a call to a runtime function `CreatePrivateAccessors` that creates an AccessorPair, and store the components in it. The AccessorPair is then associated with the private name variable and stored in the context for later retrieval when the private accessors are accessed. Design doc: https://docs.google.com/document/d/10W4begYfs7lmldSqBoQBBt_BKamgT8igqxF9u50RGrI/edit Bug: v8:8330 Change-Id: Ie6d3882507d143b1f645d7ae82b21b7358656e89 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1725670 Commit-Queue: Joyee Cheung <joyee@igalia.com> Reviewed-by: Ross McIlroy <rmcilroy@chromium.org> Cr-Commit-Position: refs/heads/master@{#63284}
57 lines
1.0 KiB
JavaScript
57 lines
1.0 KiB
JavaScript
// Copyright 2019 the V8 project authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
// Flags: --harmony-private-methods
|
|
|
|
"use strict";
|
|
|
|
// Complementary private accessors.
|
|
{
|
|
class C {
|
|
get #a() { }
|
|
set #a(val) { }
|
|
}
|
|
|
|
new C;
|
|
}
|
|
|
|
// Accessing super in private accessors.
|
|
{
|
|
class A { foo(val) {} }
|
|
class C extends A {
|
|
set #a(val) { super.foo(val); }
|
|
}
|
|
new C();
|
|
|
|
class D extends A {
|
|
get #a() { return super.foo; }
|
|
}
|
|
new D();
|
|
|
|
class E extends A {
|
|
set #a(val) { super.foo(val); }
|
|
get #a() { return super.foo; }
|
|
}
|
|
new E();
|
|
}
|
|
|
|
// Nested private accessors.
|
|
{
|
|
class C {
|
|
a() { this.#a; }
|
|
get #a() {
|
|
class D { get #a() { } }
|
|
return new D;
|
|
}
|
|
}
|
|
new C().a();
|
|
}
|
|
|
|
// Duplicate private accessors.
|
|
// https://tc39.es/proposal-private-methods/#sec-static-semantics-early-errors
|
|
{
|
|
assertThrows('class C { get #a() {} get #a() {} }', SyntaxError);
|
|
assertThrows('class C { set #a(val) {} set #a(val) {} }', SyntaxError);
|
|
}
|