Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions dwds/test/inspector_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart';

import 'fixtures/context.dart';

final context = TestContext(
directory: '../example', path: 'scopes.html', pathToServe: 'web');
final context = TestContext(path: 'scopes/scopes.html');

WipConnection get tabConnection => context.tabConnection;

Expand All @@ -35,11 +34,11 @@ void main() {
await context.tearDown();
});

final url = 'org-dartlang-app:///web/scopes_main.dart';
final url = 'org-dartlang-app:///example/scopes/scopes_main.dart';

/// A convenient way to get a library variable without boilerplate.
String libraryVariableExpression(String variable) =>
'${globalLoadStrategy.loadModuleSnippet}("dart_sdk").dart.getModuleLibraries("web/scopes_main")["$url"]["$variable"];';
'${globalLoadStrategy.loadModuleSnippet}("dart_sdk").dart.getModuleLibraries("example/scopes/scopes_main")["$url"]["$variable"];';

Future<RemoteObject> libraryPublicFinal() =>
inspector.jsEvaluate(libraryVariableExpression('libraryPublicFinal'));
Expand Down Expand Up @@ -225,27 +224,27 @@ void main() {
}

final jsMultiLineExceptionWithStackTrace = '''
Error: Assertion failed: org-dartlang-app:///web/scopes_main.dart:4:11
Error: Assertion failed: org-dartlang-app:///example/scopes/scopes_main.dart:4:11
false
"THIS IS THE ASSERT MESSAGE"
at Object.assertFailed (org-dartlang-app:///web/scopes_main.dart.js:5297:15)
at Object.assertFailed (org-dartlang-app:///example/scopes/scopes_main.dart.js:5297:15)
''';

final formattedMultiLineExceptionWithStackTrace = '''
Error: Assertion failed: org-dartlang-app:///web/scopes_main.dart:4:11
Error: Assertion failed: org-dartlang-app:///example/scopes/scopes_main.dart:4:11
false
"THIS IS THE ASSERT MESSAGE"
org-dartlang-app:///web/scopes_main.dart.js 5297:15 assertFailed
org-dartlang-app:///example/scopes/scopes_main.dart.js 5297:15 assertFailed
''';

final jsMultiLineExceptionNoStackTrace = '''
Error: Assertion failed: org-dartlang-app:///web/scopes_main.dart:4:11
Error: Assertion failed: org-dartlang-app:///example/scopes/scopes_main.dart:4:11
false
"THIS IS THE ASSERT MESSAGE"
''';

final formattedMultiLineExceptionNoStackTrace = '''
Error: Assertion failed: org-dartlang-app:///web/scopes_main.dart:4:11
Error: Assertion failed: org-dartlang-app:///example/scopes/scopes_main.dart:4:11
false
"THIS IS THE ASSERT MESSAGE"
''';
Expand Down
9 changes: 4 additions & 5 deletions dwds/test/instance_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart';

import 'fixtures/context.dart';

final context = TestContext(
directory: '../example', path: 'scopes.html', pathToServe: 'web');
final context = TestContext(path: 'scopes/scopes.html');

WipConnection get tabConnection => context.tabConnection;

Expand All @@ -34,10 +33,10 @@ void main() {
await context.tearDown();
});

final url = 'org-dartlang-app:///web/scopes_main.dart';
final url = 'org-dartlang-app:///example/scopes/scopes_main.dart';

String libraryVariableExpression(String variable) =>
'${globalLoadStrategy.loadModuleSnippet}("dart_sdk").dart.getModuleLibraries("web/scopes_main")'
'${globalLoadStrategy.loadModuleSnippet}("dart_sdk").dart.getModuleLibraries("example/scopes/scopes_main")'
'["$url"]["$variable"];';

/// A reference to the the variable `libraryPublicFinal`, an instance of
Expand Down Expand Up @@ -81,7 +80,7 @@ void main() {
expect(classRef.name, 'MyTestClass<dynamic>');
expect(
classRef.id,
'classes|org-dartlang-app:///web/scopes_main.dart'
'classes|org-dartlang-app:///example/scopes/scopes_main.dart'
'|MyTestClass<dynamic>');
});

Expand Down
3 changes: 1 addition & 2 deletions dwds/test/variable_scope_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart';

import 'fixtures/context.dart';

final context = TestContext(
directory: '../example', path: 'scopes.html', pathToServe: 'web');
final context = TestContext(path: 'scopes/scopes.html');
ChromeProxyService get service =>
fetchChromeProxyService(context.debugConnection);
WipConnection get tabConnection => context.tabConnection;
Expand Down
File renamed without changes.
7 changes: 7 additions & 0 deletions fixtures/_testSound/example/scopes/scopes.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<html>

<head>
<script defer src="scopes_main.dart.js"></script>
</head>

</html>
165 changes: 165 additions & 0 deletions fixtures/_testSound/example/scopes/scopes_main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
// Copyright (c) 2019, 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.

/// An example with more complicated scope
import 'dart:async';
import 'dart:collection';

final libraryPublicFinal = MyTestClass();

final _libraryPrivateFinal = 1;
Object? libraryNull;
var libraryPublic = <String>['library', 'public', 'variable'];
var notAList = NotReallyAList();

var _libraryPrivate = ['library', 'private', 'variable'];

var identityMap = <String, int>{};

var map = <Object, Object>{};

void staticFunction(int formal) {
print(formal); // Breakpoint: staticFunction
}

void main() async {
print('Initial print from scopes app');
var local = 'local in main';
var intLocalInMain = 42;
var testClass = MyTestClass();
Object? localThatsNull;
identityMap['a'] = 1;
identityMap['b'] = 2;
map['a'] = [1, 2, 3];
map['b'] = 'something';
notAList.add(7);

String nestedFunction<T>(T parameter, Object aClass) {
var another = int.tryParse('$parameter');
return '$local: parameter, $another'; // Breakpoint: nestedFunction
}

dynamic nestedWithClosure(String banana) {
return () => '$local + $banana';
}

Timer.periodic(const Duration(seconds: 1), (Timer t) {
var ticks = t.tick;
// ignore: unused_local_variable, prefer_typing_uninitialized_variables
var closureLocal;
libraryPublicFinal.printCount();
staticFunction(1);
print('ticking... $ticks (the answer is $intLocalInMain)');
print(nestedFunction('$ticks ${testClass.message}', Timer));
print(localThatsNull);
print(libraryNull);
var localList = libraryPublic;
print(localList);
localList.add('abc');
var f = testClass.methodWithVariables();
print(f('parameter'));
var num = '1234'.someExtensionMethod();
print('$num');
});

print(_libraryPrivateFinal);
print(_libraryPrivate);
print(nestedFunction(_libraryPrivate.first, Object));
print(nestedWithClosure(_libraryPrivate.first)());
}

String libraryFunction(String arg) {
print('calling a library function with $arg');
var concat = 'some constant plus $arg plus whatever';
print(concat);
return concat;
}

abstract class MyAbstractClass {
String abstractField = 'abstract-field-value';
}

class MyTestClass<T> extends MyAbstractClass {
final String message;

String? notFinal;

MyTestClass({this.message = 'world'}) {
myselfField = this;
tornOff = toString;
}

String hello() => message;

String Function(String) methodWithVariables() {
var local = '$message + something';
print(local);
return (String parameter) {
// Be sure to use a field from this, so it isn't entirely optimized away.
var closureLocalInsideMethod = '$message/$local/$parameter';
print(closureLocalInsideMethod);
return closureLocalInsideMethod; // Breakpoint: nestedClosure
};
}

//ignore: avoid_returning_this
MyTestClass get myselfGetter => this;

late final MyTestClass myselfField;

var count = 0;

// An easy location to add a breakpoint.
void printCount() {
print('The count is ${++count}');
libraryFunction('abc'); // Breakpoint: printMethod
}

final _privateField = 'a private field';

// ignore: unused_element
String privateMethod(String s) => '$s : $_privateField';

@override
String toString() => 'A test class with message $message';

bool equals(Object other) {
if (other is MyTestClass) return message == other.hello();
return false;
}

Function closure = someFunction;

late final String Function() tornOff;
}

Function? someFunction() => null;

// ignore: unused_element
int _libraryPrivateFunction(int a, int b) => a + b;

class NotReallyAList extends ListBase<Object?> {
final List<Object?> _internal;

NotReallyAList() : _internal = [];

@override
Object? operator [](x) => _internal[x];

@override
operator []=(int x, Object? y) => _internal[x] = y;

@override
int get length => _internal.length;

@override
set length(x) => _internal.length = x;
}

extension NumberParsing on String {
int someExtensionMethod() {
var ret = int.parse(this);
return ret; // Breakpoint: extension
}
}