mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 09:31:58 +00:00
Support to run co19_2 on ddk
Change-Id: I93b9752655385d0e26cdf97d0f8224a88c198657 Reviewed-on: https://dart-review.googlesource.com/c/90781 Commit-Queue: Vijay Menon <vsm@google.com> Reviewed-by: Jenny Messerly <jmesserly@google.com>
This commit is contained in:
parent
812a6af41a
commit
8fc9eaf06c
|
@ -6482,14 +6482,11 @@ String jsLibraryName(String libraryRoot, LibraryElement library) {
|
|||
// TODO(vsm): This is not unique if an escaped '/'appears in a filename.
|
||||
// E.g., "foo/bar.dart" and "foo$47bar.dart" would collide.
|
||||
qualifiedPath = uri.pathSegments.skip(1).join(encodedSeparator);
|
||||
} else if (path.isWithin(libraryRoot, uri.toFilePath())) {
|
||||
} else {
|
||||
qualifiedPath = path
|
||||
.relative(uri.toFilePath(), from: libraryRoot)
|
||||
.replaceAll(path.separator, encodedSeparator);
|
||||
} else {
|
||||
// We don't have a unique name.
|
||||
throw 'Invalid library root. $libraryRoot does not contain '
|
||||
'${uri.toFilePath()}';
|
||||
.replaceAll(path.separator, encodedSeparator)
|
||||
.replaceAll('..', encodedSeparator);
|
||||
}
|
||||
return pathToJSIdentifier(qualifiedPath);
|
||||
}
|
||||
|
@ -6501,10 +6498,6 @@ String jsLibraryDebuggerName(String libraryRoot, LibraryElement library) {
|
|||
if (uri.scheme == 'dart' || uri.scheme == 'package') return uri.toString();
|
||||
|
||||
var filePath = uri.toFilePath();
|
||||
if (!path.isWithin(libraryRoot, filePath)) {
|
||||
throw 'Invalid library root. $libraryRoot does not contain '
|
||||
'${uri.toFilePath()}';
|
||||
}
|
||||
// Relative path to the library.
|
||||
return path.relative(filePath, from: libraryRoot);
|
||||
}
|
||||
|
|
|
@ -33,6 +33,93 @@ String dart2jsHtml(String title, String scriptPath) {
|
|||
</html>""";
|
||||
}
|
||||
|
||||
/// Escape [name] to make it into a valid identifier.
|
||||
String _toJSIdentifier(String name) {
|
||||
if (name.length == 0) return r'$';
|
||||
|
||||
// Escape any invalid characters
|
||||
StringBuffer buffer = null;
|
||||
for (int i = 0; i < name.length; i++) {
|
||||
var ch = name[i];
|
||||
var needsEscape = ch == r'$' || _invalidCharInIdentifier.hasMatch(ch);
|
||||
if (needsEscape && buffer == null) {
|
||||
buffer = StringBuffer(name.substring(0, i));
|
||||
}
|
||||
if (buffer != null) {
|
||||
buffer.write(needsEscape ? '\$${ch.codeUnits.join("")}' : ch);
|
||||
}
|
||||
}
|
||||
|
||||
var result = buffer != null ? '$buffer' : name;
|
||||
// Ensure the identifier first character is not numeric and that the whole
|
||||
// identifier is not a keyword.
|
||||
if (result.startsWith(RegExp('[0-9]')) || _invalidVariableName(result)) {
|
||||
return '\$$result';
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Invalid characters for identifiers, which would need to be escaped.
|
||||
final _invalidCharInIdentifier = RegExp(r'[^A-Za-z_$0-9]');
|
||||
|
||||
bool _invalidVariableName(String keyword, {bool strictMode = true}) {
|
||||
switch (keyword) {
|
||||
// http://www.ecma-international.org/ecma-262/6.0/#sec-future-reserved-words
|
||||
case "await":
|
||||
|
||||
case "break":
|
||||
case "case":
|
||||
case "catch":
|
||||
case "class":
|
||||
case "const":
|
||||
case "continue":
|
||||
case "debugger":
|
||||
case "default":
|
||||
case "delete":
|
||||
case "do":
|
||||
case "else":
|
||||
case "enum":
|
||||
case "export":
|
||||
case "extends":
|
||||
case "finally":
|
||||
case "for":
|
||||
case "function":
|
||||
case "if":
|
||||
case "import":
|
||||
case "in":
|
||||
case "instanceof":
|
||||
case "let":
|
||||
case "new":
|
||||
case "return":
|
||||
case "super":
|
||||
case "switch":
|
||||
case "this":
|
||||
case "throw":
|
||||
case "try":
|
||||
case "typeof":
|
||||
case "var":
|
||||
case "void":
|
||||
case "while":
|
||||
case "with":
|
||||
return true;
|
||||
case "arguments":
|
||||
case "eval":
|
||||
// http://www.ecma-international.org/ecma-262/6.0/#sec-future-reserved-words
|
||||
// http://www.ecma-international.org/ecma-262/6.0/#sec-identifiers-static-semantics-early-errors
|
||||
case "implements":
|
||||
case "interface":
|
||||
case "let":
|
||||
case "package":
|
||||
case "private":
|
||||
case "protected":
|
||||
case "public":
|
||||
case "static":
|
||||
case "yield":
|
||||
return strictMode;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Generates the HTML template file needed to load and run a dartdevc test in
|
||||
/// the browser.
|
||||
///
|
||||
|
@ -40,6 +127,7 @@ String dart2jsHtml(String title, String scriptPath) {
|
|||
/// or extension, like "math_test". The [testJSDir] is the relative path to the
|
||||
/// build directory where the dartdevc-generated JS file is stored.
|
||||
String dartdevcHtml(String testName, String testJSDir, Compiler compiler) {
|
||||
var testId = _toJSIdentifier(testName);
|
||||
var isKernel = compiler == Compiler.dartdevk;
|
||||
var sdkPath = isKernel ? 'kernel/amd/dart_sdk' : 'js/amd/dart_sdk';
|
||||
var pkgDir = isKernel ? 'pkg_kernel' : 'pkg';
|
||||
|
@ -85,7 +173,7 @@ window.ddcSettings = {
|
|||
src="/root_dart/third_party/requirejs/require.js"></script>
|
||||
<script type="text/javascript">
|
||||
requirejs(["$testName", "dart_sdk", "async_helper"],
|
||||
function($testName, sdk, async_helper) {
|
||||
function($testId, sdk, async_helper) {
|
||||
sdk.dart.ignoreWhitelistedErrors(false);
|
||||
sdk._isolate_helper.startRootIsolate(function() {}, []);
|
||||
sdk._debugger.registerDevtoolsFormatter();
|
||||
|
@ -111,7 +199,7 @@ requirejs(["$testName", "dart_sdk", "async_helper"],
|
|||
return lines.join("\\n");
|
||||
};
|
||||
|
||||
dartMainRunner($testName.$testName.main);
|
||||
dartMainRunner($testId.$testId.main);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
|
Loading…
Reference in a new issue