mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 15:17:07 +00:00
Reland "Re-land "Add a generic return type for js_util functions""
This reverts commitb70a134933
. Reason for revert: google3 linter bugs disabled with a comment and Flutter PR with new js_util landed with ignore comments. Should be safe to reland. Original change's description: > Revert "Re-land "Add a generic return type for js_util functions"" > > This reverts commit66cbeb6718
. > > Reason for revert: Causes dart analyzer and dart linter to find > issues within google3 and flutter, causing breakages and blocking > the roll. > > Original change's description: > > Re-land "Add a generic return type for js_util functions" > > > > This relands commit46486cf260
. > > > > The differences from the original commit: > > - jsify is no longer being made generic > > - Updated the CHANGELOG > > > > Change-Id: Ibc3402833cce2babbec9a57ad73963d7b9442ed8 > > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/216920 > > Commit-Queue: Riley Porter <rileyporter@google.com> > > Reviewed-by: Sigmund Cherem <sigmund@google.com> > > TBR=sigmund@google.com,srujzs@google.com,rileyporter@google.com > > Change-Id: Ic2ff63bc9658ccafcab3db75bdd06814d2f17b76 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/216963 > Reviewed-by: Siva Annamalai <asiva@google.com> > Commit-Queue: Siva Annamalai <asiva@google.com> # Not skipping CQ checks because original CL landed > 1 day ago. Change-Id: Ia8c753b568b0aca10e7784126048bddd9e1ab976 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/217148 Reviewed-by: Riley Porter <rileyporter@google.com> Reviewed-by: Sigmund Cherem <sigmund@google.com> Commit-Queue: Riley Porter <rileyporter@google.com>
This commit is contained in:
parent
60d2df4a42
commit
d17fd4b14f
3 changed files with 39 additions and 25 deletions
|
@ -421,6 +421,12 @@
|
|||
- Add `RawSocket.sendMessage`, `RawSocket.receiveMessage` that allow passing of
|
||||
file handle references via Unix domain sockets.
|
||||
|
||||
#### `dart:js_util`
|
||||
|
||||
- The `js_util` methods `getProperty`, `setProperty`, `callMethod`,
|
||||
`callConstructor`, and `newObject` now support a generic type argument
|
||||
to specify the return type.
|
||||
|
||||
### Tools
|
||||
|
||||
#### Dart command line
|
||||
|
|
|
@ -138,6 +138,8 @@ class JsUtilOptimizer extends Transformer {
|
|||
Arguments([
|
||||
VariableGet(function.positionalParameters.first),
|
||||
StringLiteral(_getExtensionMemberName(node))
|
||||
], types: [
|
||||
DynamicType()
|
||||
]))
|
||||
..fileOffset = node.fileOffset;
|
||||
return ReturnStatement(
|
||||
|
@ -157,6 +159,8 @@ class JsUtilOptimizer extends Transformer {
|
|||
VariableGet(function.positionalParameters.first),
|
||||
StringLiteral(_getExtensionMemberName(node)),
|
||||
VariableGet(function.positionalParameters.last)
|
||||
], types: [
|
||||
DynamicType()
|
||||
]))
|
||||
..fileOffset = node.fileOffset;
|
||||
return ReturnStatement(AsExpression(
|
||||
|
@ -178,6 +182,8 @@ class JsUtilOptimizer extends Transformer {
|
|||
.sublist(1)
|
||||
.map((argument) => VariableGet(argument))
|
||||
.toList())
|
||||
], types: [
|
||||
DynamicType()
|
||||
]))
|
||||
..fileOffset = node.fileOffset;
|
||||
return ReturnStatement(AsExpression(
|
||||
|
@ -224,7 +230,6 @@ class JsUtilOptimizer extends Transformer {
|
|||
/// Removing the checks allows further inlining by the compilers.
|
||||
StaticInvocation _lowerSetProperty(StaticInvocation node) {
|
||||
Arguments arguments = node.arguments;
|
||||
assert(arguments.types.isEmpty);
|
||||
assert(arguments.positional.length == 3);
|
||||
assert(arguments.named.isEmpty);
|
||||
|
||||
|
@ -244,7 +249,6 @@ class JsUtilOptimizer extends Transformer {
|
|||
/// Removing the checks allows further inlining by the compilers.
|
||||
StaticInvocation _lowerCallMethod(StaticInvocation node) {
|
||||
Arguments arguments = node.arguments;
|
||||
assert(arguments.types.isEmpty);
|
||||
assert(arguments.positional.length == 3);
|
||||
assert(arguments.named.isEmpty);
|
||||
|
||||
|
@ -260,7 +264,6 @@ class JsUtilOptimizer extends Transformer {
|
|||
/// Removing the checks allows further inlining by the compilers.
|
||||
StaticInvocation _lowerCallConstructor(StaticInvocation node) {
|
||||
Arguments arguments = node.arguments;
|
||||
assert(arguments.types.isEmpty);
|
||||
assert(arguments.positional.length == 2);
|
||||
assert(arguments.named.isEmpty);
|
||||
|
||||
|
@ -283,8 +286,13 @@ class JsUtilOptimizer extends Transformer {
|
|||
// Lower arguments in a List.empty factory call.
|
||||
if (argumentsList is StaticInvocation &&
|
||||
argumentsList.target == _listEmptyFactory) {
|
||||
return _createCallUncheckedNode(callUncheckedTargets, [],
|
||||
originalArguments, node.fileOffset, node.arguments.fileOffset);
|
||||
return _createCallUncheckedNode(
|
||||
callUncheckedTargets,
|
||||
node.arguments.types,
|
||||
[],
|
||||
originalArguments,
|
||||
node.fileOffset,
|
||||
node.arguments.fileOffset);
|
||||
}
|
||||
|
||||
// Lower arguments in other kinds of Lists.
|
||||
|
@ -323,6 +331,7 @@ class JsUtilOptimizer extends Transformer {
|
|||
|
||||
return _createCallUncheckedNode(
|
||||
callUncheckedTargets,
|
||||
node.arguments.types,
|
||||
callUncheckedArguments,
|
||||
originalArguments,
|
||||
node.fileOffset,
|
||||
|
@ -333,6 +342,7 @@ class JsUtilOptimizer extends Transformer {
|
|||
/// with the given 0-4 arguments.
|
||||
StaticInvocation _createCallUncheckedNode(
|
||||
List<Procedure> callUncheckedTargets,
|
||||
List<DartType> callUncheckedTypes,
|
||||
List<Expression> callUncheckedArguments,
|
||||
List<Expression> originalArguments,
|
||||
int nodeFileOffset,
|
||||
|
@ -342,7 +352,7 @@ class JsUtilOptimizer extends Transformer {
|
|||
callUncheckedTargets[callUncheckedArguments.length],
|
||||
Arguments(
|
||||
[...originalArguments, ...callUncheckedArguments],
|
||||
types: [],
|
||||
types: callUncheckedTypes,
|
||||
)..fileOffset = argumentsFileOffset)
|
||||
..fileOffset = nodeFileOffset;
|
||||
}
|
||||
|
|
|
@ -64,65 +64,63 @@ Object _convertDataTree(Object data) {
|
|||
return _convert(data)!;
|
||||
}
|
||||
|
||||
dynamic newObject() => JS('=Object', '{}');
|
||||
T newObject<T>() => JS('=Object', '{}');
|
||||
|
||||
bool hasProperty(Object o, Object name) => JS('bool', '# in #', name, o);
|
||||
|
||||
// A CFE transformation will optimize all calls to `getProperty`.
|
||||
dynamic getProperty(Object o, Object name) =>
|
||||
JS('Object|Null', '#[#]', o, name);
|
||||
T getProperty<T>(Object o, Object name) => JS('Object|Null', '#[#]', o, name);
|
||||
|
||||
// A CFE transformation may optimize calls to `setProperty`, when [value] is
|
||||
// statically known to be a non-function.
|
||||
dynamic setProperty(Object o, Object name, Object? value) {
|
||||
T setProperty<T>(Object o, Object name, T? value) {
|
||||
assertInterop(value);
|
||||
return JS('', '#[#]=#', o, name, value);
|
||||
}
|
||||
|
||||
/// Unchecked version of setProperty, only used in a CFE transformation.
|
||||
@pragma('dart2js:tryInline')
|
||||
dynamic _setPropertyUnchecked(Object o, Object name, Object? value) {
|
||||
T _setPropertyUnchecked<T>(Object o, Object name, T? value) {
|
||||
return JS('', '#[#]=#', o, name, value);
|
||||
}
|
||||
|
||||
// A CFE transformation may optimize calls to `callMethod` when [args] is a
|
||||
// a list literal or const list containing at most 4 values, all of which are
|
||||
// statically known to be non-functions.
|
||||
dynamic callMethod(Object o, String method, List<Object?> args) {
|
||||
T callMethod<T>(Object o, String method, List<Object?> args) {
|
||||
assertInteropArgs(args);
|
||||
return JS('Object|Null', '#[#].apply(#, #)', o, method, o, args);
|
||||
}
|
||||
|
||||
/// Unchecked version for 0 arguments, only used in a CFE transformation.
|
||||
@pragma('dart2js:tryInline')
|
||||
dynamic _callMethodUnchecked0(Object o, String method) {
|
||||
T _callMethodUnchecked0<T>(Object o, String method) {
|
||||
return JS('Object|Null', '#[#]()', o, method);
|
||||
}
|
||||
|
||||
/// Unchecked version for 1 argument, only used in a CFE transformation.
|
||||
@pragma('dart2js:tryInline')
|
||||
dynamic _callMethodUnchecked1(Object o, String method, Object? arg1) {
|
||||
T _callMethodUnchecked1<T>(Object o, String method, Object? arg1) {
|
||||
return JS('Object|Null', '#[#](#)', o, method, arg1);
|
||||
}
|
||||
|
||||
/// Unchecked version for 2 arguments, only used in a CFE transformation.
|
||||
@pragma('dart2js:tryInline')
|
||||
dynamic _callMethodUnchecked2(
|
||||
T _callMethodUnchecked2<T>(
|
||||
Object o, String method, Object? arg1, Object? arg2) {
|
||||
return JS('Object|Null', '#[#](#, #)', o, method, arg1, arg2);
|
||||
}
|
||||
|
||||
/// Unchecked version for 3 arguments, only used in a CFE transformation.
|
||||
@pragma('dart2js:tryInline')
|
||||
dynamic _callMethodUnchecked3(
|
||||
T _callMethodUnchecked3<T>(
|
||||
Object o, String method, Object? arg1, Object? arg2, Object? arg3) {
|
||||
return JS('Object|Null', '#[#](#, #, #)', o, method, arg1, arg2, arg3);
|
||||
}
|
||||
|
||||
/// Unchecked version for 4 arguments, only used in a CFE transformation.
|
||||
@pragma('dart2js:tryInline')
|
||||
dynamic _callMethodUnchecked4(Object o, String method, Object? arg1,
|
||||
Object? arg2, Object? arg3, Object? arg4) {
|
||||
T _callMethodUnchecked4<T>(Object o, String method, Object? arg1, Object? arg2,
|
||||
Object? arg3, Object? arg4) {
|
||||
return JS(
|
||||
'Object|Null', '#[#](#, #, #, #)', o, method, arg1, arg2, arg3, arg4);
|
||||
}
|
||||
|
@ -134,7 +132,7 @@ dynamic _callMethodUnchecked4(Object o, String method, Object? arg1,
|
|||
bool instanceof(Object? o, Object type) =>
|
||||
JS('bool', '# instanceof #', o, type);
|
||||
|
||||
dynamic callConstructor(Object constr, List<Object?>? arguments) {
|
||||
T callConstructor<T>(Object constr, List<Object?>? arguments) {
|
||||
if (arguments == null) {
|
||||
return JS('Object', 'new #()', constr);
|
||||
} else {
|
||||
|
@ -197,32 +195,32 @@ dynamic callConstructor(Object constr, List<Object?>? arguments) {
|
|||
|
||||
/// Unchecked version for 0 arguments, only used in a CFE transformation.
|
||||
@pragma('dart2js:tryInline')
|
||||
dynamic _callConstructorUnchecked0(Object constr) {
|
||||
T _callConstructorUnchecked0<T>(Object constr) {
|
||||
return JS('Object', 'new #()', constr);
|
||||
}
|
||||
|
||||
/// Unchecked version for 1 argument, only used in a CFE transformation.
|
||||
@pragma('dart2js:tryInline')
|
||||
dynamic _callConstructorUnchecked1(Object constr, Object? arg1) {
|
||||
T _callConstructorUnchecked1<T>(Object constr, Object? arg1) {
|
||||
return JS('Object', 'new #(#)', constr, arg1);
|
||||
}
|
||||
|
||||
/// Unchecked version for 2 arguments, only used in a CFE transformation.
|
||||
@pragma('dart2js:tryInline')
|
||||
dynamic _callConstructorUnchecked2(Object constr, Object? arg1, Object? arg2) {
|
||||
T _callConstructorUnchecked2<T>(Object constr, Object? arg1, Object? arg2) {
|
||||
return JS('Object', 'new #(#, #)', constr, arg1, arg2);
|
||||
}
|
||||
|
||||
/// Unchecked version for 3 arguments, only used in a CFE transformation.
|
||||
@pragma('dart2js:tryInline')
|
||||
dynamic _callConstructorUnchecked3(
|
||||
T _callConstructorUnchecked3<T>(
|
||||
Object constr, Object? arg1, Object? arg2, Object? arg3) {
|
||||
return JS('Object', 'new #(#, #, #)', constr, arg1, arg2, arg3);
|
||||
}
|
||||
|
||||
/// Unchecked version for 4 arguments, only used in a CFE transformation.
|
||||
@pragma('dart2js:tryInline')
|
||||
dynamic _callConstructorUnchecked4(
|
||||
T _callConstructorUnchecked4<T>(
|
||||
Object constr, Object? arg1, Object? arg2, Object? arg3, Object? arg4) {
|
||||
return JS('Object', 'new #(#, #, #, #)', constr, arg1, arg2, arg3, arg4);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue