mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 01:45:06 +00:00
[ddc, dart2js] Fix signature of js_util APIs expecting a constructor.
Since JavaScript constructor functions are not valid Dart functions, they should not be expected to have a Function type. For context see: https://github.com/dart-lang/sdk/issues/41259 Change-Id: I9092700ad60712f604cec7e5cf0189b23024839a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/142321 Reviewed-by: Johnni Winther <johnniwinther@google.com> Commit-Queue: Sigmund Cherem <sigmund@google.com>
This commit is contained in:
parent
e736495eb7
commit
795c0b1b64
|
@ -76,9 +76,13 @@ setProperty(o, name, value) => JS('', '#[#]=#', o, name, value);
|
|||
callMethod(o, String method, List args) =>
|
||||
JS('Object|Null', '#[#].apply(#, #)', o, method, o, args);
|
||||
|
||||
bool instanceof(o, Function type) => JS('bool', '# instanceof #', o, type);
|
||||
/// Check whether [o] is an instance of [type].
|
||||
///
|
||||
/// The value in [type] is expected to be a JS-interop object that
|
||||
/// represents a valid JavaScript constructor function.
|
||||
bool instanceof(o, Object type) => JS('bool', '# instanceof #', o, type);
|
||||
|
||||
callConstructor(Function constr, List arguments) {
|
||||
callConstructor(Object constr, List arguments) {
|
||||
if (arguments == null) {
|
||||
return JS('Object', 'new #()', constr);
|
||||
}
|
||||
|
|
|
@ -76,10 +76,14 @@ dynamic setProperty(Object o, Object name, Object? value) =>
|
|||
dynamic callMethod(Object o, String method, List<Object?> args) =>
|
||||
JS('Object|Null', '#[#].apply(#, #)', o, method, o, args);
|
||||
|
||||
bool instanceof(Object? o, Function type) =>
|
||||
/// Check whether [o] is an instance of [type].
|
||||
///
|
||||
/// The value in [type] is expected to be a JS-interop object that
|
||||
/// represents a valid JavaScript constructor function.
|
||||
bool instanceof(Object? o, Object type) =>
|
||||
JS('bool', '# instanceof #', o, type);
|
||||
|
||||
dynamic callConstructor(Function constr, List<Object?> arguments) {
|
||||
dynamic callConstructor(Object constr, List<Object?> arguments) {
|
||||
if (arguments == null) {
|
||||
return JS('Object', 'new #()', constr);
|
||||
}
|
||||
|
|
29
tests/lib/js/instanceof_test.dart
Normal file
29
tests/lib/js/instanceof_test.dart
Normal file
|
@ -0,0 +1,29 @@
|
|||
// Copyright (c) 2020, 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.
|
||||
|
||||
@JS()
|
||||
library instanceof_test;
|
||||
|
||||
import 'package:js/js.dart';
|
||||
import 'package:expect/expect.dart';
|
||||
import 'dart:js_util';
|
||||
|
||||
@JS()
|
||||
external void eval(String code);
|
||||
|
||||
@JS('Class')
|
||||
class Class {
|
||||
external Class();
|
||||
external Constructor get constructor;
|
||||
}
|
||||
|
||||
@JS()
|
||||
class Constructor {}
|
||||
|
||||
void main() {
|
||||
eval("self.Class = function Class() {}");
|
||||
var o = new Class();
|
||||
var constructor = o.constructor;
|
||||
Expect.isTrue(instanceof(o, constructor));
|
||||
}
|
|
@ -21,9 +21,7 @@ convert/utf85_test: Skip # Pass, Slow Issue 20111.
|
|||
async/future_or_only_in_async_test/00: MissingCompileTimeError
|
||||
convert/streamed_conversion_json_utf8_decode_test: Pass, Slow # Infrequent timeouts.
|
||||
html/*: SkipByDesign # dart:html not supported on VM.
|
||||
js/datetime_roundtrip_test: CompileTimeError
|
||||
js/null_test: CompileTimeError
|
||||
js/prototype_access_test: CompileTimeError
|
||||
js/*: SkipByDesign
|
||||
mirrors/deferred_type_test: CompileTimeError
|
||||
mirrors/generic_bounded_by_type_parameter_test/02: MissingCompileTimeError
|
||||
mirrors/generic_bounded_test/01: MissingCompileTimeError
|
||||
|
|
29
tests/lib_2/js/instanceof_test.dart
Normal file
29
tests/lib_2/js/instanceof_test.dart
Normal file
|
@ -0,0 +1,29 @@
|
|||
// Copyright (c) 2020, 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.
|
||||
|
||||
@JS()
|
||||
library instanceof_test;
|
||||
|
||||
import 'package:js/js.dart';
|
||||
import 'package:expect/expect.dart';
|
||||
import 'dart:js_util';
|
||||
|
||||
@JS()
|
||||
external void eval(String code);
|
||||
|
||||
@JS('Class')
|
||||
class Class {
|
||||
external Class();
|
||||
external Constructor get constructor;
|
||||
}
|
||||
|
||||
@JS()
|
||||
class Constructor {}
|
||||
|
||||
void main() {
|
||||
eval("self.Class = function Class() {}");
|
||||
var o = new Class();
|
||||
var constructor = o.constructor;
|
||||
Expect.isTrue(instanceof(o, constructor));
|
||||
}
|
|
@ -12,9 +12,7 @@ mirrors/immutable_collections_test: Pass, Slow # http://dartbug.com/33057
|
|||
async/future_or_only_in_async_test/00: MissingCompileTimeError
|
||||
convert/streamed_conversion_json_utf8_decode_test: Pass, Slow # Infrequent timeouts.
|
||||
html/*: SkipByDesign # dart:html not supported on VM.
|
||||
js/datetime_roundtrip_test: CompileTimeError
|
||||
js/null_test: CompileTimeError
|
||||
js/prototype_access_test: CompileTimeError
|
||||
js/*: SkipByDesign
|
||||
mirrors/deferred_type_test: CompileTimeError
|
||||
mirrors/generic_bounded_by_type_parameter_test/02: MissingCompileTimeError
|
||||
mirrors/generic_bounded_test/01: MissingCompileTimeError
|
||||
|
|
Loading…
Reference in a new issue