mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 17:35:46 +00:00
[ddc] Change JSArray rti property into a getter
- Avoids the need to set the value in the JSArray factories. - Delays the construction of the rti value until it is actually needed. Issue: https://github.com/dart-lang/sdk/issues/48585 Change-Id: Iecc28533453742eaeedc0cbc48053b7660e3eee3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/325450 Reviewed-by: Sigmund Cherem <sigmund@google.com> Commit-Queue: Nicholas Shahan <nshahan@google.com>
This commit is contained in:
parent
183420bb1d
commit
6bf8844ab9
|
@ -1757,6 +1757,11 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
|
|||
js_ast.Expression type;
|
||||
var memberName = _declareMemberName(member);
|
||||
if (member.isAccessor) {
|
||||
// These signatures are used for dynamic access and to inform the
|
||||
// debugger. The `arrayRti` accessor is only used by the dart:_rti
|
||||
// library internals and should not be included in the accessible
|
||||
// signatures.
|
||||
if (c == _jsArrayClass && name == 'arrayRti') continue;
|
||||
type = _emitType(member.isGetter
|
||||
? reifiedType.returnType
|
||||
: reifiedType.positionalParameters[0]);
|
||||
|
@ -6681,6 +6686,12 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
|
|||
js_ast.Expression _emitEmbeddedGlobal(StaticInvocation node) {
|
||||
var constantExpression = node.arguments.positional[1] as ConstantExpression;
|
||||
var name = constantExpression.constant as StringConstant;
|
||||
var value = name.value;
|
||||
if (value == 'arrayRti') {
|
||||
// Special case for the rti on a JSArray. These are defined via the dartx
|
||||
// extension functionality.
|
||||
return _emitMemberName('arrayRti', memberClass: _jsArrayClass);
|
||||
}
|
||||
return runtimeCall('#', [name.value]);
|
||||
}
|
||||
|
||||
|
|
|
@ -106,9 +106,6 @@ void nativeNonNullAsserts(bool enable) {
|
|||
_nativeNonNullAsserts = enable;
|
||||
}
|
||||
|
||||
/// A JavaScript Symbol used to store the Rti object on a native array.
|
||||
final arrayRti = JS('', r'Symbol("$ti")');
|
||||
|
||||
/// A JavaScript Symbol used to store the Rti signature object on a function.
|
||||
///
|
||||
/// Accessed by a call to `JS_GET_NAME(JsGetName.SIGNATURE_NAME)`.
|
||||
|
|
|
@ -25,9 +25,6 @@ class JSArray<E> extends JavaScriptObject
|
|||
// TODO(jmesserly): this uses special compiler magic to close over the
|
||||
// parameterized ES6 'JSArray' class.
|
||||
jsObjectSetPrototypeOf(list, JS('', 'JSArray.prototype'));
|
||||
if (JS_GET_FLAG('NEW_RUNTIME_TYPES'))
|
||||
JS('', '#.# = #', list, JS_EMBEDDED_GLOBAL('', ARRAY_RTI_PROPERTY),
|
||||
JSArray<E>);
|
||||
return JS('-dynamic', '#', list);
|
||||
}
|
||||
|
||||
|
@ -35,9 +32,6 @@ class JSArray<E> extends JavaScriptObject
|
|||
factory JSArray.fixed(@notNull Object list) {
|
||||
jsObjectSetPrototypeOf(list, JS('', 'JSArray.prototype'));
|
||||
JS('', r'#.fixed$length = Array', list);
|
||||
if (JS_GET_FLAG('NEW_RUNTIME_TYPES'))
|
||||
JS('', '#.# = #', list, JS_EMBEDDED_GLOBAL('', ARRAY_RTI_PROPERTY),
|
||||
JSArray<E>);
|
||||
return JS('-dynamic', '#', list);
|
||||
}
|
||||
|
||||
|
@ -45,12 +39,27 @@ class JSArray<E> extends JavaScriptObject
|
|||
jsObjectSetPrototypeOf(list, JS('', 'JSArray.prototype'));
|
||||
JS('', r'#.fixed$length = Array', list);
|
||||
JS('', r'#.immutable$list = Array', list);
|
||||
if (JS_GET_FLAG('NEW_RUNTIME_TYPES'))
|
||||
JS('', '#.# = #', list, JS_EMBEDDED_GLOBAL('', ARRAY_RTI_PROPERTY),
|
||||
JSArray<E>);
|
||||
return JS('-dynamic', '#', list);
|
||||
}
|
||||
|
||||
/// Provides the Rti object for this.
|
||||
///
|
||||
/// Only intended for use by the dart:_rti library.
|
||||
///
|
||||
/// NOTE: The name of this getter is directly tied to the result of compiling
|
||||
/// `JS_EMBEDDED_GLOBAL('', ARRAY_RTI_PROPERTY)`.
|
||||
Object get arrayRti => JS_GET_FLAG('NEW_RUNTIME_TYPES')
|
||||
? dart.typeRep<JSArray<E>>()
|
||||
: throw dart.throwUnimplementedInOldRti();
|
||||
|
||||
/// Unsupported action, only provided here to help diagnosis of an accidental
|
||||
/// attempt to set the value manually.
|
||||
///
|
||||
/// NOTE: The name of this setter is directly tied to the result of compiling
|
||||
/// `JS_EMBEDDED_GLOBAL('', ARRAY_RTI_PROPERTY)`.
|
||||
set arrayRti(_) =>
|
||||
throw UnsupportedError('Setting arrayRti is not supported in DDC.');
|
||||
|
||||
static void markFixedList(list) {
|
||||
// Functions are stored in the hidden class and not as properties in
|
||||
// the object. We never actually look at the value, but only want
|
||||
|
|
Loading…
Reference in a new issue