[dart2js] Representing late/lazy fields with arrow functions.

Change-Id: Ic47077253eb07f5caa60b9409ccbf9bb87f34d4a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/209856
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Mark Zhou <markzipan@google.com>
This commit is contained in:
Mark Zhou 2021-10-14 21:04:15 +00:00 committed by commit-bot@chromium.org
parent 2bbb5dc907
commit ff26406d72
5 changed files with 69 additions and 1 deletions

View file

@ -1679,12 +1679,20 @@ class FragmentEmitter {
? locals.find('_lazyFinal', 'hunkHelpers.lazyFinal')
: locals.find('_lazy', 'hunkHelpers.lazy')
: locals.find('_lazyOld', 'hunkHelpers.lazyOld');
js.Expression staticFieldCode = field.code;
if (!_options.features.legacyJavaScript.isEnabled &&
staticFieldCode is js.Fun) {
js.Fun fun = staticFieldCode;
staticFieldCode = js.ArrowFunction(fun.params, fun.body,
asyncModifier: fun.asyncModifier)
.withSourceInformation(fun.sourceInformation);
}
js.Statement statement = js.js.statement("#(#, #, #, #);", [
helper,
_namer.globalObjectForStaticState(),
js.quoteName(field.name),
js.quoteName(field.getterName),
field.code,
staticFieldCode,
]);
registerEntityAst(field.element, statement,

View file

@ -0,0 +1,13 @@
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// @dart = 2.7
main() {
Class. /*1:main*/ field;
}
class Class {
static dynamic field = /*2:Class.field*/ throw '>ExceptionMarker<';
}

View file

@ -0,0 +1,17 @@
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// @dart = 2.7
main() {
Class. /*1:main*/ field;
}
class Class {
static dynamic field = /*2:Class.field*/ test();
@pragma('dart2js:noInline')
static test() {
/*3:Class.test*/ throw '>ExceptionMarker<';
}
}

View file

@ -0,0 +1,13 @@
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// @dart = 2.7
main() {
Class. /*1:main*/ field;
}
class Class {
static final field = /*2:Class.field*/ throw '>ExceptionMarker<';
}

View file

@ -0,0 +1,17 @@
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// @dart = 2.7
main() {
Class. /*1:main*/ field;
}
class Class {
static final field = /*2:Class.field*/ test();
@pragma('dart2js:noInline')
static test() {
/*3:Class.test*/ throw '>ExceptionMarker<';
}
}