Browse Source

[web] Share more runtime code between ddc and dart2js

Creates a new 'dart:_js_shared_embedded_names' library for the names
accessed from the shared 'dart:_rti' library. Migrate all of the shared
symbols and uses to the new location.

Change-Id: Iaa72c4522888ad630782b921b0b70d7a2626d1b9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241507
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
pull/49158/head
Nicholas Shahan 1 month ago
committed by Commit Bot
parent
commit
444982f364
  1. 4
      pkg/compiler/lib/src/common/elements.dart
  2. 4
      pkg/compiler/lib/src/common/names.dart
  3. 2
      pkg/compiler/lib/src/js_backend/namer.dart
  4. 13
      pkg/compiler/lib/src/js_emitter/startup_emitter/model_emitter.dart
  5. 2
      pkg/compiler/lib/src/kernel/dart2js_target.dart
  6. 2
      pkg/compiler/lib/src/kernel/element_map_impl.dart
  7. 2
      pkg/compiler/lib/src/ssa/builder.dart
  8. 117
      pkg/js_runtime/lib/synced/embedded_names.dart
  9. 116
      pkg/js_shared/lib/synced/embedded_names.dart
  10. 9
      sdk/lib/_internal/js_runtime/lib/foreign_helper.dart
  11. 6
      sdk/lib/_internal/js_runtime/lib/js_helper.dart
  12. 117
      sdk/lib/_internal/js_runtime/lib/synced/embedded_names.dart
  13. 18
      sdk/lib/_internal/js_shared/lib/rti.dart
  14. 116
      sdk/lib/_internal/js_shared/lib/synced/embedded_names.dart
  15. 5
      sdk/lib/_internal/sdk_library_metadata/lib/libraries.dart
  16. 3
      sdk/lib/libraries.json
  17. 3
      sdk/lib/libraries.yaml
  18. 2
      tests/web/internal/rti/subtype_test.dart
  19. 2
      tests/web_2/internal/rti/subtype_test.dart

4
pkg/compiler/lib/src/common/elements.dart

@ -915,7 +915,7 @@ abstract class CommonElements {
// From dart:_js_embedded_names
late final ClassEntity jsGetNameEnum = _findClass(
_env.lookupLibrary(Uris.dart__js_embedded_names, required: true),
_env.lookupLibrary(Uris.dart__js_shared_embedded_names, required: true),
'JsGetName')!;
/// Returns `true` if [member] is a "foreign helper", that is, a member whose
@ -1185,7 +1185,7 @@ class JCommonElements extends CommonElements {
'NativeTypedArrayOfDouble')!;
late final ClassEntity jsBuiltinEnum = _findClass(
_env.lookupLibrary(Uris.dart__js_embedded_names, required: true),
_env.lookupLibrary(Uris.dart__js_shared_embedded_names, required: true),
'JsBuiltin')!;
bool isForeign(MemberEntity element) => element.library == foreignLibrary;

4
pkg/compiler/lib/src/common/names.dart

@ -249,6 +249,10 @@ class Uris {
static final Uri dart__js_embedded_names =
Uri(scheme: 'dart', path: '_js_embedded_names');
/// The URI for 'dart:_js_shared_embedded_names'.
static final Uri dart__js_shared_embedded_names =
Uri(scheme: 'dart', path: '_js_shared_embedded_names');
/// The URI for 'dart:js'.
static final Uri dart_js = Uri(scheme: 'dart', path: 'js');

2
pkg/compiler/lib/src/js_backend/namer.dart

@ -9,7 +9,7 @@ library js_backend.namer;
import 'package:front_end/src/api_unstable/dart2js.dart'
show $0, $9, $A, $Z, $_, $a, $g, $s, $z;
import 'package:js_runtime/synced/embedded_names.dart' show JsGetName;
import 'package:js_shared/synced/embedded_names.dart' show JsGetName;
import '../closure.dart';
import '../common.dart';

13
pkg/compiler/lib/src/js_emitter/startup_emitter/model_emitter.dart

@ -10,7 +10,6 @@ import 'dart:convert' show JsonEncoder;
import 'package:js_runtime/synced/embedded_names.dart'
show
ARRAY_RTI_PROPERTY,
DEFERRED_INITIALIZED,
DEFERRED_LIBRARY_PARTS,
DEFERRED_PART_URIS,
@ -19,18 +18,22 @@ import 'package:js_runtime/synced/embedded_names.dart'
INTERCEPTORS_BY_TAG,
IS_HUNK_INITIALIZED,
IS_HUNK_LOADED,
JsGetName,
LEAF_TAGS,
MANGLED_GLOBAL_NAMES,
MANGLED_NAMES,
METADATA,
NATIVE_SUPERCLASS_TAG_NAME,
RTI_UNIVERSE,
RtiUniverseFieldNames,
RUNTIME_METRICS,
STARTUP_METRICS,
TearOffParametersPropertyNames,
TYPE_TO_INTERCEPTOR_MAP,
TYPE_TO_INTERCEPTOR_MAP;
import 'package:js_shared/synced/embedded_names.dart'
show
ARRAY_RTI_PROPERTY,
JsGetName,
RTI_UNIVERSE,
RtiUniverseFieldNames,
TYPES;
import 'package:js_ast/src/precedence.dart' as js_precedence;

2
pkg/compiler/lib/src/kernel/dart2js_target.dart

@ -261,6 +261,7 @@ const requiredLibraries = <String, List<String>>{
'dart:_js_helper',
'dart:_js_names',
'dart:_js_primitives',
'dart:_js_shared_embedded_names',
'dart:_late_helper',
'dart:_metadata',
'dart:_native_typed_data',
@ -296,6 +297,7 @@ const requiredLibraries = <String, List<String>>{
'dart:_js_helper',
'dart:_js_names',
'dart:_js_primitives',
'dart:_js_shared_embedded_names',
'dart:_late_helper',
'dart:_native_typed_data',
'dart:_recipe_syntax',

2
pkg/compiler/lib/src/kernel/element_map_impl.dart

@ -6,7 +6,7 @@
import 'package:front_end/src/api_prototype/constant_evaluator.dart' as ir;
import 'package:front_end/src/api_unstable/dart2js.dart' as ir;
import 'package:js_runtime/synced/embedded_names.dart';
import 'package:js_shared/synced/embedded_names.dart' show JsGetName;
import 'package:kernel/ast.dart' as ir;
import 'package:kernel/class_hierarchy.dart' as ir;
import 'package:kernel/core_types.dart' as ir;

2
pkg/compiler/lib/src/ssa/builder.dart

@ -5,6 +5,8 @@
// @dart = 2.10
import 'package:js_runtime/synced/embedded_names.dart';
import 'package:js_shared/synced/embedded_names.dart'
show JsBuiltin, JsGetName, TYPES;
import 'package:kernel/ast.dart' as ir;
import '../closure.dart';

117
pkg/js_runtime/lib/synced/embedded_names.dart

@ -26,22 +26,12 @@ const NATIVE_SUPERCLASS_TAG_NAME = r"$nativeSuperclassTag";
/// the static function's unique (potentially minified) name.
const STATIC_FUNCTION_NAME_PROPERTY_NAME = r'$static_name';
/// The name of a property on the constructor function of Dart Object
/// and interceptor types, used for caching Rti types.
const CONSTRUCTOR_RTI_CACHE_PROPERTY_NAME = r'$ccache';
/// The name of the embedded global for metadata.
///
/// Use [JsBuiltin.getMetadata] instead of directly accessing this embedded
/// global.
const METADATA = 'metadata';
/// A list of types used in the program e.g. for reflection or encoding of
/// function types.
///
/// Use [JsBuiltin.getType] instead of directly accessing this embedded global.
const TYPES = 'types';
/// A JS map from mangled global names to their unmangled names.
///
/// If the program does not use reflection, this embedded global may be empty
@ -94,11 +84,6 @@ const GET_ISOLATE_TAG = 'getIsolateTag';
// [INTERCEPTORS_BY_TAG] and [LEAF_TAGS].
const ISOLATE_TAG = 'isolateTag';
/// An embedded global that contains the property used to store type information
/// on JavaScript Array instances. This is a Symbol (except for IE11, where is
/// is a String).
const ARRAY_RTI_PROPERTY = 'arrayRti';
/// This embedded global (a function) returns the isolate-specific dispatch-tag
/// that is used to accelerate interceptor calls.
const DISPATCH_PROPERTY_NAME = "dispatchPropertyName";
@ -174,11 +159,6 @@ const IS_HUNK_INITIALIZED = 'isHunkInitialized';
/// globals don't clash with it.
const DEFERRED_INITIALIZED = 'deferredInitialized';
/// A 'Universe' object used by 'dart:_rti'.
///
/// This embedded global is used for --experiment-new-rti.
const RTI_UNIVERSE = 'typeUniverse';
/// An embedded global used to collect and access runtime metrics.
const RUNTIME_METRICS = 'rm';
@ -188,103 +168,6 @@ const RUNTIME_METRICS_CONTAINER = 'runtimeMetrics';
/// An embedded global used to collect and access startup metrics.
const STARTUP_METRICS = 'sm';
/// Names that are supported by [JS_GET_NAME].
// TODO(herhut): Make entries lower case (as in fields) and find a better name.
enum JsGetName {
GETTER_PREFIX,
SETTER_PREFIX,
CALL_PREFIX,
CALL_PREFIX0,
CALL_PREFIX1,
CALL_PREFIX2,
CALL_PREFIX3,
CALL_PREFIX4,
CALL_PREFIX5,
CALL_CATCH_ALL,
REQUIRED_PARAMETER_PROPERTY,
DEFAULT_VALUES_PROPERTY,
CALL_NAME_PROPERTY,
DEFERRED_ACTION_PROPERTY,
/// Prefix used for generated type test property on classes.
OPERATOR_IS_PREFIX,
/// Name used for generated function types on classes and methods.
SIGNATURE_NAME,
/// Name of JavaScript property used to store runtime-type information on
/// instances of parameterized classes.
RTI_NAME,
/// String representation of the type of the Future class.
FUTURE_CLASS_TYPE_NAME,
/// Field name used for determining if an object or its interceptor has
/// JavaScript indexing behavior.
IS_INDEXABLE_FIELD_NAME,
/// String representation of the type of the null class.
NULL_CLASS_TYPE_NAME,
/// String representation of the type of the object class.
OBJECT_CLASS_TYPE_NAME,
/// String representation of the type of the List class.
LIST_CLASS_TYPE_NAME,
/// Property name for Rti._as field.
RTI_FIELD_AS,
/// Property name for Rti._is field.
RTI_FIELD_IS,
}
enum JsBuiltin {
/// Returns the JavaScript constructor function for Dart's Object class.
/// This can be used for type tests, as in
///
/// var constructor = JS_BUILTIN('', JsBuiltin.dartObjectConstructor);
/// if (JS('bool', '# instanceof #', obj, constructor))
/// ...
dartObjectConstructor,
/// Returns the JavaScript constructor function for the runtime's Closure
/// class, the base class of all closure objects. This can be used for type
/// tests, as in
///
/// var constructor = JS_BUILTIN('', JsBuiltin.dartClosureConstructor);
/// if (JS('bool', '# instanceof #', obj, constructor))
/// ...
dartClosureConstructor,
/// Returns true if the given type is a type argument of a js-interop class
/// or a supertype of a js-interop class.
///
/// JS_BUILTIN('bool', JsBuiltin.isJsInteropTypeArgument, o)
isJsInteropTypeArgument,
/// Returns the metadata of the given [index].
///
/// JS_BUILTIN('returns:var;effects:none;depends:none',
/// JsBuiltin.getMetadata, index);
getMetadata,
/// Returns the type of the given [index].
///
/// JS_BUILTIN('returns:var;effects:none;depends:none',
/// JsBuiltin.getType, index);
getType,
}
/// Names of fields of the Rti Universe object.
class RtiUniverseFieldNames {
static String evalCache = 'eC';
static String typeRules = 'tR';
static String erasedTypes = 'eT';
static String typeParameterVariances = 'tPV';
static String sharedEmptyArray = 'sEA';
}
/// Names of fields of collected tear-off parameters object.
///
/// Tear-off getters are created before the Dart classes are initialized, so a

116
pkg/js_shared/lib/synced/embedded_names.dart

@ -0,0 +1,116 @@
// Copyright (c) 2022, 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.12
/// A 'Universe' object used by 'dart:_rti'.
const RTI_UNIVERSE = 'typeUniverse';
/// An embedded global that contains the property used to store type information
/// on JavaScript Array instances. This is a Symbol (except for IE11, where is
/// is a String).
const ARRAY_RTI_PROPERTY = 'arrayRti';
/// A list of types used in the program e.g. for reflection or encoding of
/// function types.
///
/// Use [JsBuiltin.getType] instead of directly accessing this embedded global.
const TYPES = 'types';
/// Names that are supported by [JS_GET_NAME].
// TODO(herhut): Make entries lower case (as in fields) and find a better name.
enum JsGetName {
GETTER_PREFIX,
SETTER_PREFIX,
CALL_PREFIX,
CALL_PREFIX0,
CALL_PREFIX1,
CALL_PREFIX2,
CALL_PREFIX3,
CALL_PREFIX4,
CALL_PREFIX5,
CALL_CATCH_ALL,
REQUIRED_PARAMETER_PROPERTY,
DEFAULT_VALUES_PROPERTY,
CALL_NAME_PROPERTY,
DEFERRED_ACTION_PROPERTY,
/// Prefix used for generated type test property on classes.
OPERATOR_IS_PREFIX,
/// Name used for generated function types on classes and methods.
SIGNATURE_NAME,
/// Name of JavaScript property used to store runtime-type information on
/// instances of parameterized classes.
RTI_NAME,
/// String representation of the type of the Future class.
FUTURE_CLASS_TYPE_NAME,
/// Field name used for determining if an object or its interceptor has
/// JavaScript indexing behavior.
IS_INDEXABLE_FIELD_NAME,
/// String representation of the type of the null class.
NULL_CLASS_TYPE_NAME,
/// String representation of the type of the object class.
OBJECT_CLASS_TYPE_NAME,
/// String representation of the type of the List class.
LIST_CLASS_TYPE_NAME,
/// Property name for Rti._as field.
RTI_FIELD_AS,
/// Property name for Rti._is field.
RTI_FIELD_IS,
}
enum JsBuiltin {
/// Returns the JavaScript constructor function for Dart's Object class.
/// This can be used for type tests, as in
///
/// var constructor = JS_BUILTIN('', JsBuiltin.dartObjectConstructor);
/// if (JS('bool', '# instanceof #', obj, constructor))
/// ...
dartObjectConstructor,
/// Returns the JavaScript constructor function for the runtime's Closure
/// class, the base class of all closure objects. This can be used for type
/// tests, as in
///
/// var constructor = JS_BUILTIN('', JsBuiltin.dartClosureConstructor);
/// if (JS('bool', '# instanceof #', obj, constructor))
/// ...
dartClosureConstructor,
/// Returns true if the given type is a type argument of a js-interop class
/// or a supertype of a js-interop class.
///
/// JS_BUILTIN('bool', JsBuiltin.isJsInteropTypeArgument, o)
isJsInteropTypeArgument,
/// Returns the metadata of the given [index].
///
/// JS_BUILTIN('returns:var;effects:none;depends:none',
/// JsBuiltin.getMetadata, index);
getMetadata,
/// Returns the type of the given [index].
///
/// JS_BUILTIN('returns:var;effects:none;depends:none',
/// JsBuiltin.getType, index);
getType,
}
/// Names of fields of the Rti Universe object.
class RtiUniverseFieldNames {
static String evalCache = 'eC';
static String typeRules = 'tR';
static String erasedTypes = 'eT';
static String typeParameterVariances = 'tPV';
static String sharedEmptyArray = 'sEA';
}

9
sdk/lib/_internal/js_runtime/lib/foreign_helper.dart

@ -4,7 +4,7 @@
library _foreign_helper;
import 'dart:_js_embedded_names' show JsGetName, JsBuiltin;
import 'dart:_js_shared_embedded_names' show JsGetName, JsBuiltin;
import 'dart:_rti' show Rti;
/// Emits a JavaScript code fragment parametrized by arguments.
@ -215,13 +215,14 @@ external String JS_GET_NAME(JsGetName name);
/// Reads an embedded global.
///
/// The [name] should be a constant defined in the `_embedded_names` library.
/// The [name] should be a constant defined in the `_embedded_names` or
/// `_js_shared_embedded_names` library.
external JS_EMBEDDED_GLOBAL(String typeDescription, String name);
/// Instructs the compiler to execute the [builtinName] action at the call-site.
///
/// The [builtin] should be a constant defined in the `_embedded_names`
/// library.
/// The [builtin] should be a constant defined in the
/// `_js_shared_embedded_names` library.
// Add additional optional arguments if needed. The method is treated internally
// as a variable argument method.
external JS_BUILTIN(String typeDescription, JsBuiltin builtin,

6
sdk/lib/_internal/js_runtime/lib/js_helper.dart

@ -6,19 +6,15 @@ library _js_helper;
import 'dart:_js_embedded_names'
show
ARRAY_RTI_PROPERTY,
CURRENT_SCRIPT,
DEFERRED_LIBRARY_PARTS,
DEFERRED_PART_URIS,
DEFERRED_PART_HASHES,
GET_ISOLATE_TAG,
INITIALIZE_LOADED_HUNK,
INTERCEPTED_NAMES,
INTERCEPTORS_BY_TAG,
IS_HUNK_LOADED,
IS_HUNK_INITIALIZED,
JsBuiltin,
JsGetName,
LEAF_TAGS,
NATIVE_SUPERCLASS_TAG_NAME,
RUNTIME_METRICS,
@ -26,6 +22,8 @@ import 'dart:_js_embedded_names'
STATIC_FUNCTION_NAME_PROPERTY_NAME,
TearOffParametersPropertyNames;
import 'dart:_js_shared_embedded_names' show JsBuiltin, JsGetName;
import 'dart:collection';
import 'dart:async' show Completer, DeferredLoadException, Future, Zone;

117
sdk/lib/_internal/js_runtime/lib/synced/embedded_names.dart

@ -26,22 +26,12 @@ const NATIVE_SUPERCLASS_TAG_NAME = r"$nativeSuperclassTag";
/// the static function's unique (potentially minified) name.
const STATIC_FUNCTION_NAME_PROPERTY_NAME = r'$static_name';
/// The name of a property on the constructor function of Dart Object
/// and interceptor types, used for caching Rti types.
const CONSTRUCTOR_RTI_CACHE_PROPERTY_NAME = r'$ccache';
/// The name of the embedded global for metadata.
///
/// Use [JsBuiltin.getMetadata] instead of directly accessing this embedded
/// global.
const METADATA = 'metadata';
/// A list of types used in the program e.g. for reflection or encoding of
/// function types.
///
/// Use [JsBuiltin.getType] instead of directly accessing this embedded global.
const TYPES = 'types';
/// A JS map from mangled global names to their unmangled names.
///
/// If the program does not use reflection, this embedded global may be empty
@ -94,11 +84,6 @@ const GET_ISOLATE_TAG = 'getIsolateTag';
// [INTERCEPTORS_BY_TAG] and [LEAF_TAGS].
const ISOLATE_TAG = 'isolateTag';
/// An embedded global that contains the property used to store type information
/// on JavaScript Array instances. This is a Symbol (except for IE11, where is
/// is a String).
const ARRAY_RTI_PROPERTY = 'arrayRti';
/// This embedded global (a function) returns the isolate-specific dispatch-tag
/// that is used to accelerate interceptor calls.
const DISPATCH_PROPERTY_NAME = "dispatchPropertyName";
@ -174,11 +159,6 @@ const IS_HUNK_INITIALIZED = 'isHunkInitialized';
/// globals don't clash with it.
const DEFERRED_INITIALIZED = 'deferredInitialized';
/// A 'Universe' object used by 'dart:_rti'.
///
/// This embedded global is used for --experiment-new-rti.
const RTI_UNIVERSE = 'typeUniverse';
/// An embedded global used to collect and access runtime metrics.
const RUNTIME_METRICS = 'rm';
@ -188,103 +168,6 @@ const RUNTIME_METRICS_CONTAINER = 'runtimeMetrics';
/// An embedded global used to collect and access startup metrics.
const STARTUP_METRICS = 'sm';
/// Names that are supported by [JS_GET_NAME].
// TODO(herhut): Make entries lower case (as in fields) and find a better name.
enum JsGetName {
GETTER_PREFIX,
SETTER_PREFIX,
CALL_PREFIX,
CALL_PREFIX0,
CALL_PREFIX1,
CALL_PREFIX2,
CALL_PREFIX3,
CALL_PREFIX4,
CALL_PREFIX5,
CALL_CATCH_ALL,
REQUIRED_PARAMETER_PROPERTY,
DEFAULT_VALUES_PROPERTY,
CALL_NAME_PROPERTY,
DEFERRED_ACTION_PROPERTY,
/// Prefix used for generated type test property on classes.
OPERATOR_IS_PREFIX,
/// Name used for generated function types on classes and methods.
SIGNATURE_NAME,
/// Name of JavaScript property used to store runtime-type information on
/// instances of parameterized classes.
RTI_NAME,
/// String representation of the type of the Future class.
FUTURE_CLASS_TYPE_NAME,
/// Field name used for determining if an object or its interceptor has
/// JavaScript indexing behavior.
IS_INDEXABLE_FIELD_NAME,
/// String representation of the type of the null class.
NULL_CLASS_TYPE_NAME,
/// String representation of the type of the object class.
OBJECT_CLASS_TYPE_NAME,
/// String representation of the type of the List class.
LIST_CLASS_TYPE_NAME,
/// Property name for Rti._as field.
RTI_FIELD_AS,
/// Property name for Rti._is field.
RTI_FIELD_IS,
}
enum JsBuiltin {
/// Returns the JavaScript constructor function for Dart's Object class.
/// This can be used for type tests, as in
///
/// var constructor = JS_BUILTIN('', JsBuiltin.dartObjectConstructor);
/// if (JS('bool', '# instanceof #', obj, constructor))
/// ...
dartObjectConstructor,
/// Returns the JavaScript constructor function for the runtime's Closure
/// class, the base class of all closure objects. This can be used for type
/// tests, as in
///
/// var constructor = JS_BUILTIN('', JsBuiltin.dartClosureConstructor);
/// if (JS('bool', '# instanceof #', obj, constructor))
/// ...
dartClosureConstructor,
/// Returns true if the given type is a type argument of a js-interop class
/// or a supertype of a js-interop class.
///
/// JS_BUILTIN('bool', JsBuiltin.isJsInteropTypeArgument, o)
isJsInteropTypeArgument,
/// Returns the metadata of the given [index].
///
/// JS_BUILTIN('returns:var;effects:none;depends:none',
/// JsBuiltin.getMetadata, index);
getMetadata,
/// Returns the type of the given [index].
///
/// JS_BUILTIN('returns:var;effects:none;depends:none',
/// JsBuiltin.getType, index);
getType,
}
/// Names of fields of the Rti Universe object.
class RtiUniverseFieldNames {
static String evalCache = 'eC';
static String typeRules = 'tR';
static String erasedTypes = 'eT';
static String typeParameterVariances = 'tPV';
static String sharedEmptyArray = 'sEA';
}
/// Names of fields of collected tear-off parameters object.
///
/// Tear-off getters are created before the Dart classes are initialized, so a

18
sdk/lib/_internal/js_shared/lib/rti.dart

@ -18,24 +18,16 @@ import 'dart:_foreign_helper'
RAW_DART_FUNCTION_REF,
TYPE_REF,
LEGACY_TYPE_REF;
import 'dart:_interceptors'
show JavaScriptFunction, JSArray, JSNull, JSUnmodifiableArray;
import 'dart:_js_names' show unmangleGlobalNameIfPreservedAnyways;
import 'dart:_js_embedded_names'
show
JsBuiltin,
JsGetName,
RtiUniverseFieldNames,
ARRAY_RTI_PROPERTY,
CONSTRUCTOR_RTI_CACHE_PROPERTY_NAME,
RTI_UNIVERSE,
TYPES;
import 'dart:_js_shared_embedded_names';
import 'dart:_recipe_syntax';
/// The name of a property on the constructor function of Dart Object
/// and interceptor types, used for caching Rti types.
const CONSTRUCTOR_RTI_CACHE_PROPERTY_NAME = r'$ccache';
// The top type `Object?` is used throughout this library even when values are
// not nullable or have narrower types in order to avoid incurring type checks
// before the type checking infrastructure has been set up.

116
sdk/lib/_internal/js_shared/lib/synced/embedded_names.dart

@ -0,0 +1,116 @@
// Copyright (c) 2022, 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.12
/// A 'Universe' object used by 'dart:_rti'.
const RTI_UNIVERSE = 'typeUniverse';
/// An embedded global that contains the property used to store type information
/// on JavaScript Array instances. This is a Symbol (except for IE11, where is
/// is a String).
const ARRAY_RTI_PROPERTY = 'arrayRti';
/// A list of types used in the program e.g. for reflection or encoding of
/// function types.
///
/// Use [JsBuiltin.getType] instead of directly accessing this embedded global.
const TYPES = 'types';
/// Names that are supported by [JS_GET_NAME].
// TODO(herhut): Make entries lower case (as in fields) and find a better name.
enum JsGetName {
GETTER_PREFIX,
SETTER_PREFIX,
CALL_PREFIX,
CALL_PREFIX0,
CALL_PREFIX1,
CALL_PREFIX2,
CALL_PREFIX3,
CALL_PREFIX4,
CALL_PREFIX5,
CALL_CATCH_ALL,
REQUIRED_PARAMETER_PROPERTY,
DEFAULT_VALUES_PROPERTY,
CALL_NAME_PROPERTY,
DEFERRED_ACTION_PROPERTY,
/// Prefix used for generated type test property on classes.
OPERATOR_IS_PREFIX,
/// Name used for generated function types on classes and methods.
SIGNATURE_NAME,
/// Name of JavaScript property used to store runtime-type information on
/// instances of parameterized classes.
RTI_NAME,
/// String representation of the type of the Future class.
FUTURE_CLASS_TYPE_NAME,
/// Field name used for determining if an object or its interceptor has
/// JavaScript indexing behavior.
IS_INDEXABLE_FIELD_NAME,
/// String representation of the type of the null class.
NULL_CLASS_TYPE_NAME,
/// String representation of the type of the object class.
OBJECT_CLASS_TYPE_NAME,
/// String representation of the type of the List class.
LIST_CLASS_TYPE_NAME,
/// Property name for Rti._as field.
RTI_FIELD_AS,
/// Property name for Rti._is field.
RTI_FIELD_IS,
}
enum JsBuiltin {
/// Returns the JavaScript constructor function for Dart's Object class.
/// This can be used for type tests, as in
///
/// var constructor = JS_BUILTIN('', JsBuiltin.dartObjectConstructor);
/// if (JS('bool', '# instanceof #', obj, constructor))
/// ...
dartObjectConstructor,
/// Returns the JavaScript constructor function for the runtime's Closure
/// class, the base class of all closure objects. This can be used for type
/// tests, as in
///
/// var constructor = JS_BUILTIN('', JsBuiltin.dartClosureConstructor);
/// if (JS('bool', '# instanceof #', obj, constructor))
/// ...
dartClosureConstructor,
/// Returns true if the given type is a type argument of a js-interop class
/// or a supertype of a js-interop class.
///
/// JS_BUILTIN('bool', JsBuiltin.isJsInteropTypeArgument, o)
isJsInteropTypeArgument,
/// Returns the metadata of the given [index].
///
/// JS_BUILTIN('returns:var;effects:none;depends:none',
/// JsBuiltin.getMetadata, index);
getMetadata,
/// Returns the type of the given [index].
///
/// JS_BUILTIN('returns:var;effects:none;depends:none',
/// JsBuiltin.getType, index);
getType,
}
/// Names of fields of the Rti Universe object.
class RtiUniverseFieldNames {
static String evalCache = 'eC';
static String typeRules = 'tR';
static String erasedTypes = 'eT';
static String typeParameterVariances = 'tPV';
static String sharedEmptyArray = 'sEA';
}

5
sdk/lib/_internal/sdk_library_metadata/lib/libraries.dart

@ -176,6 +176,11 @@ const Map<String, LibraryInfo> libraries = const {
categories: "",
documented: false,
platforms: DART2JS_PLATFORM),
"_js_shared_embedded_names": const LibraryInfo(
"_internal/js_shared/lib/synced/embedded_names.dart",
categories: "",
documented: false,
platforms: DART2JS_PLATFORM),
"_async_await_error_codes": const LibraryInfo(
"_internal/js_runtime/lib/synced/async_await_error_codes.dart",
categories: "",

3
sdk/lib/libraries.json

@ -386,6 +386,9 @@
"_js_embedded_names": {
"uri": "_internal/js_runtime/lib/synced/embedded_names.dart"
},
"_js_shared_embedded_names": {
"uri": "_internal/js_shared/lib/synced/embedded_names.dart"
},
"_async_await_error_codes": {
"uri": "_internal/js_runtime/lib/synced/async_await_error_codes.dart"
},

3
sdk/lib/libraries.yaml

@ -354,6 +354,9 @@ _dart2js_common:
_js_embedded_names:
uri: "_internal/js_runtime/lib/synced/embedded_names.dart"
_js_shared_embedded_names:
uri: "_internal/js_shared/lib/synced/embedded_names.dart"
_async_await_error_codes:
uri: "_internal/js_runtime/lib/synced/async_await_error_codes.dart"

2
tests/web/internal/rti/subtype_test.dart

@ -3,7 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
import 'dart:_foreign_helper' show JS, JS_GET_NAME, TYPE_REF;
import 'dart:_js_embedded_names' show JsGetName;
import 'dart:_js_shared_embedded_names' show JsGetName;
import 'dart:_rti' as rti;
import 'package:expect/expect.dart';

2
tests/web_2/internal/rti/subtype_test.dart

@ -5,7 +5,7 @@
// @dart = 2.7
import 'dart:_foreign_helper' show JS, JS_GET_NAME, TYPE_REF;
import 'dart:_js_embedded_names' show JsGetName;
import 'dart:_js_shared_embedded_names' show JsGetName;
import 'dart:_rti' as rti;
import 'subtype_utils.dart';

Loading…
Cancel
Save