912005267d
Change-Id: I46be49b2effec3e38a3dc44cd45cfe736f77fa78 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/182680 Commit-Queue: Sigmund Cherem <sigmund@google.com> Reviewed-by: Joshua Litt <joshualitt@google.com> Reviewed-by: Nicholas Shahan <nshahan@google.com> Reviewed-by: Stephen Adams <sra@google.com>
52 lines
1.5 KiB
Dart
52 lines
1.5 KiB
Dart
// Copyright (c) 2016, 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.7
|
|
|
|
// Native testing library. Provides support for mock @Native classes and
|
|
// collects common imports.
|
|
|
|
import "package:expect/expect.dart";
|
|
import 'dart:_js_helper' show Native;
|
|
import 'dart:_foreign_helper' show JS;
|
|
|
|
export "package:expect/expect.dart";
|
|
export 'dart:_js_helper'
|
|
show Creates, Native, JSName, Returns, applyTestExtensions;
|
|
export 'dart:_foreign_helper' show JS;
|
|
|
|
void nativeTesting() {
|
|
JS('', r'''
|
|
((function() {
|
|
var toStringResultProperty = "_toStringResult";
|
|
var objectToStringMethod = Object.prototype.toString;
|
|
|
|
Object.prototype.toString = function() {
|
|
if (this != null) {
|
|
var constructor = this.constructor;
|
|
if (constructor != null) {
|
|
var result = constructor[toStringResultProperty];
|
|
if (typeof result == "string") return result;
|
|
}
|
|
}
|
|
return objectToStringMethod.call(this);
|
|
};
|
|
|
|
// To mock a @Native class with JavaScript constructor `Foo`, add
|
|
//
|
|
// self.nativeConstructor(Foo);
|
|
//
|
|
// to the JavaScript code.
|
|
self.nativeConstructor = function(constructor, opt_name) {
|
|
var toStringResult = "[object " + (opt_name || constructor.name) + "]";
|
|
constructor[toStringResultProperty] = toStringResult;
|
|
};
|
|
})())
|
|
''');
|
|
}
|
|
|
|
@pragma('dart2js:noInline')
|
|
@pragma('dart2js:assumeDynamic')
|
|
confuse(x) => x;
|