Files
sdk/tests/lib/js/static_interop_test/call_utils.dart
T
Lasse R.H. Nielsen 0dfbab89cb Make tests/lib/js/static_interop not use minitest.
Change-Id: Id7a8a6ac0098df55b04fa089587c62b07e9cf3c2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/403860
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
2025-02-04 01:44:02 -08:00

56 lines
1.5 KiB
Dart

// Copyright (c) 2024, 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.
import 'dart:js_interop';
const dart2wasm = !bool.fromEnvironment('dart.library.html');
const ddc = const bool.fromEnvironment('dart.library._ddc_only');
@pragma('dart2js:noInline')
@pragma('dart2js:assumeDynamic')
dynamic confuse(dynamic x) => x;
@JS()
external JSAny? eval(String script);
void injectJS() {
eval('''
self.jsFunction = function(s) {
if (this == null) {
throw "`this` is null or undefined";
}
if (typeof s != 'string') {
throw "`s` is not a string";
}
return s.at(0);
};
self.jsObject = { call: function(s) {
if (this == null) {
throw "`this` is null or undefined";
}
if (typeof s != 'string') {
throw "`s` is not a string";
}
return s.at(0);
} };
self.NamedClass = class NamedClass {
call(s) {
if (this == null) {
throw "`this` is null or undefined";
}
if (typeof s != 'string') {
throw "`s` is not a string";
}
return s.at(0);
}
}
self.jsClass = new NamedClass();
''');
}
bool jsThisIsNullCheck(e) =>
e.toString().contains('`this` is null or undefined');
bool jsArgIsNotStringCheck(e) => e.toString().contains('`s` is not a string');