mirror of
https://github.com/dart-lang/sdk
synced 2024-09-19 14:32:49 +00:00
[js_util] Add globalThis
getter.
Change-Id: I325f3ea7f5aad84dff9e08c6a958b478d6926cb6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/240962 Reviewed-by: Srujan Gaddam <srujzs@google.com> Reviewed-by: Riley Porter <rileyporter@google.com> Commit-Queue: Joshua Litt <joshualitt@google.com>
This commit is contained in:
parent
ecf42a3815
commit
d06fd8d081
|
@ -64,6 +64,9 @@ Object _convertDataTree(Object data) {
|
|||
return _convert(data)!;
|
||||
}
|
||||
|
||||
@pragma('dart2js:tryInline')
|
||||
Object get globalThis => JS('', 'globalThis');
|
||||
|
||||
T newObject<T>() => JS('=Object', '{}');
|
||||
|
||||
bool hasProperty(Object o, Object name) => JS('bool', '# in #', name, o);
|
||||
|
|
|
@ -189,8 +189,21 @@ main() {
|
|||
function Five(a, b, c, d, e) {
|
||||
this.count = 5;
|
||||
}
|
||||
|
||||
globalThis.globalKey = 'foo';
|
||||
""");
|
||||
|
||||
group('globalThis', () {
|
||||
test('create', () {
|
||||
expect(identical(js_util.globalThis, js_util.globalThis), isTrue);
|
||||
});
|
||||
|
||||
test('isGlobalThis', () {
|
||||
expect(js_util.hasProperty(js_util.globalThis, 'One'), isTrue);
|
||||
expect(js_util.getProperty(js_util.globalThis, 'globalKey'), 'foo');
|
||||
});
|
||||
});
|
||||
|
||||
group('newObject', () {
|
||||
test('create', () {
|
||||
expect(identical(js_util.newObject(), js_util.newObject()), isFalse);
|
||||
|
|
|
@ -191,8 +191,21 @@ main() {
|
|||
function Five(a, b, c, d, e) {
|
||||
this.count = 5;
|
||||
}
|
||||
|
||||
globalThis.globalKey = 'foo';
|
||||
""");
|
||||
|
||||
group('globalThis', () {
|
||||
test('create', () {
|
||||
expect(identical(js_util.globalThis, js_util.globalThis), isTrue);
|
||||
});
|
||||
|
||||
test('isGlobalThis', () {
|
||||
expect(js_util.hasProperty(js_util.globalThis, 'One'), isTrue);
|
||||
expect(js_util.getProperty(js_util.globalThis, 'globalKey'), 'foo');
|
||||
});
|
||||
});
|
||||
|
||||
group('newObject', () {
|
||||
test('create', () {
|
||||
expect(identical(js_util.newObject(), js_util.newObject()), isFalse);
|
||||
|
|
Loading…
Reference in a new issue