dart-sdk/sdk/lib
Lasse R.H. Nielsen 18f37dd8f3 Add extension name getter on Enum.
We use an extension getter instead of an instance getter because
it doesn't conflict with any potential existing or future enums
which want an element named `name`.
Keeping the namespace for enum elements open is a priority.
We currently only reserve `index` and `values`.

BUG: https://github.com/dart-lang/language/issues/1511

Fixes language issue #1511, which is a long-standing request,
and should replace a number of alternative implementations
which are based on parsing the `toString()`.


This version has two fields on the shared superclass, the index
and private name, and has a separate `toString` for each `enum` class
which hard-codes that enum's class name.

An earlier version had both `"name"` and `"ClassName.name"` as fields
to be able to reuse the same `toString` method on all enum classes,
but that cost too much for JS compiled code.
Even having just `ClassName.` as a field and then combining inside
`toString` requires more code to create the enum instances.
Instead this version hardcodes the `ClassName.` string once
in the `toString` method, which means each enum class has its own
toString (which can *potentially* be tree-shaken then.)

This still tree-shakes slightly worse than the previous implementation
where every enum class had its own `index` and `_name` fields
independent of each other, which could then be tree-shaken independently.
However, the `index` was already made an interface member with the
addition of the `Enum` interface, so code which accesses `.index`
on something of the `Enum` supertype could prevent tree-shaking of
all enum classes' `index` fields.
Likewise any general access to the "name" of an enum would necessarily
do the same for the name.
This CL makes up for some of that by sharing more implementation
between enum classes.

DartVM AOT CodeSize impact: ~0.15% regression on gallery (little less on big g3 app)

TEST= New tests added to enum_test.dart

Change-Id: Id25334e6c987f470f558de3c141d0e3ff542b020
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/210480
Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2021-09-22 14:20:16 +00:00
..
_http [io/http] Add a HTTP Client parameter on WebSocket.connect to allow a custom HTTP Client for web socket connections. 2021-09-15 18:06:42 +00:00
_internal Add fixes for Remaining renames 2021-09-21 16:07:30 +00:00
async [vm] Remove support for dart-ext: imports 2021-09-02 14:14:35 +00:00
cli Deprecate the dart:cli library and waitFor method. 2021-08-16 13:49:48 +00:00
collection Tweaks, refactoring and updates on DoubleLinkedQueue. 2021-08-31 12:44:39 +00:00
convert fix todos linked to issue #38725 2021-05-17 20:51:52 +00:00
core Add extension name getter on Enum. 2021-09-22 14:20:16 +00:00
developer [ Timeline ] Don't try to log async timeline events when Dart stream is 2021-09-17 18:49:21 +00:00
ffi [vm] Adds args_n to FFI resolver. 2021-09-13 07:57:00 +00:00
html [dart:html] Migrate python scripts to python 3 2021-09-08 22:10:53 +00:00
indexed_db/dart2js [dart:html] Add doc changes to templates and source files 2021-07-22 19:59:54 +00:00
internal Tweaks, refactoring and updates on DoubleLinkedQueue. 2021-08-31 12:44:39 +00:00
io Update SDK documentation for new lookup code. 2021-06-28 17:33:30 +00:00
isolate [vm] Rewrite isolate message serialization. 2021-07-29 16:55:55 +00:00
js various fixes to the dart: lib dartdocs 2020-09-09 16:45:59 +00:00
js_util Optimize js_util callConstructor for 0-4 arguments. 2021-09-13 22:43:10 +00:00
math Fix behavior for -infinity width/height of rectangles. 2021-06-21 13:29:39 +00:00
mirrors Update SDK documentation for new lookup code. 2021-06-28 17:33:30 +00:00
svg/dart2js [dart:html] Unify shared attribute metadata from MDN 2020-08-25 23:48:43 +00:00
typed_data fix todos linked to issue #38725 2021-05-17 20:51:52 +00:00
vmservice [VM] [CFE]: Expression compilation inside extension method 2021-09-10 12:02:57 +00:00
web_audio/dart2js Update SDK documentation for new lookup code. 2021-06-28 17:33:30 +00:00
web_gl/dart2js [dart:html] Revert "[dart:html] Revert commits using MDN compatibility info" 2020-07-14 23:18:43 +00:00
web_sql/dart2js [web] deprecate dart:web_sql 2021-04-23 19:04:42 +00:00
libraries.json [vm] Implement constant Maps in the VM 2021-09-06 06:28:59 +00:00
libraries.yaml [vm] Implement constant Maps in the VM 2021-09-06 06:28:59 +00:00
vmservice_libraries.json [Core Libraries] Eliminate the fork in the core libraries. 2020-06-16 23:37:36 +00:00
vmservice_libraries.yaml update the tooling to generate libraries.json from libraries.yaml 2021-07-27 23:02:50 +00:00