fix #30907, add library constants for all SDK libraries

Change-Id: I34669398e9bd7dfb2c9c5130279e88c772b3a5b3
Reviewed-on: https://dart-review.googlesource.com/53162
Reviewed-by: Vijay Menon <vsm@google.com>
This commit is contained in:
Jenny Messerly 2018-05-02 19:33:36 +00:00
parent 61c226b4ea
commit cbca4006f8
5 changed files with 46 additions and 33 deletions

View file

@ -34,6 +34,7 @@ import 'package:source_maps/source_maps.dart';
import '../compiler/js_names.dart' as JS;
import '../compiler/module_builder.dart'
show transformModuleFormat, ModuleFormat;
import '../compiler/shared_command.dart';
import '../js_ast/js_ast.dart' as JS;
import '../js_ast/js_ast.dart' show js;
import '../js_ast/source_map_printer.dart' show SourceMapPrintingContext;
@ -113,17 +114,8 @@ class ModuleCompiler {
context.resultProvider =
new InputPackagesResultProvider(context, summaryData);
}
var variables = <String, String>{};
variables.addAll(options.declaredVariables);
variables.addAll({
'dart.isVM': 'false',
// TODO(vsm): Should this be hardcoded?
'dart.library.html': 'true',
'dart.library.io': 'false',
'dart.library.ui': 'false',
'dart.library.mirrors': 'false',
'dart.library.isolate': 'false'
});
var variables = new Map<String, String>.from(options.declaredVariables)
..addAll(sdkLibraryVariables);
context.declaredVariables = new DeclaredVariables.fromMap(variables);
if (!context.analysisOptions.strongMode) {

View file

@ -0,0 +1,36 @@
// Copyright (c) 2018, 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.
/// Shared code between Analyzer and Kernel CLI interfaces.
///
/// This file should only implement functionality that does not depend on
/// Analyzer/Kernel imports.
/// Variables that indicate which libraries are available in dev compiler.
// TODO(jmesserly): provide an option to compile without dart:html & friends?
Map<String, String> sdkLibraryVariables = {
'dart.isVM': 'false',
'dart.library.async': 'true',
'dart.library.core': 'true',
'dart.library.collection': 'true',
'dart.library.convert': 'true',
// TODO(jmesserly): this is not really supported in dart4web other than
// `debugger()`
'dart.library.developer': 'true',
'dart.library.io': 'false',
'dart.library.isolate': 'false',
'dart.library.js': 'true',
'dart.library.js_util': 'true',
'dart.library.math': 'true',
'dart.library.mirrors': 'false',
'dart.library.typed_data': 'true',
'dart.library.indexed_db': 'true',
'dart.library.html': 'true',
'dart.library.html_common': 'true',
'dart.library.svg': 'true',
'dart.library.ui': 'false',
'dart.library.web_audio': 'true',
'dart.library.web_gl': 'true',
'dart.library.web_sql': 'true',
};

View file

@ -7,7 +7,6 @@ import 'dart:convert' show json;
import 'dart:io';
import 'package:args/args.dart';
import 'package:dev_compiler/src/kernel/target.dart';
import 'package:front_end/src/api_prototype/standard_file_system.dart';
import 'package:front_end/src/api_unstable/ddc.dart' as fe;
import 'package:front_end/src/multi_root_file_system.dart';
@ -17,9 +16,11 @@ import 'package:source_maps/source_maps.dart';
import '../compiler/js_names.dart' as JS;
import '../compiler/module_builder.dart';
import '../compiler/shared_command.dart';
import '../js_ast/js_ast.dart' as JS;
import '../js_ast/source_map_printer.dart' show SourceMapPrintingContext;
import 'compiler.dart';
import 'target.dart';
const _binaryName = 'dartdevk';
@ -373,15 +374,7 @@ Map<String, String> parseAndRemoveDeclaredVariables(List<String> args) {
}
// Add platform defined variables
declaredVariables.addAll({
'dart.isVM': 'false',
// TODO(vsm): Should this be hardcoded?
'dart.library.html': 'true',
'dart.library.io': 'false',
'dart.library.ui': 'false',
'dart.library.mirrors': 'false',
'dart.library.isolate': 'false'
});
declaredVariables.addAll(sdkLibraryVariables);
return declaredVariables;
}

View file

@ -4652,8 +4652,7 @@ class ProgramCompiler extends Object
args.positional.length == 1 &&
// TODO(jmesserly): this does not correctly handle when the arguments to
// fromEnvironment are constant non-literal values.
args.positional[0] is BasicLiteral &&
(args.named.isEmpty || args.named[0].value is BasicLiteral)) {
args.positional[0] is BasicLiteral) {
var varName = (args.positional[0] as StringLiteral).value;
var value = declaredVariables[varName];
var defaultArg = args.named.isNotEmpty ? args.named[0].value : null;

View file

@ -98,9 +98,6 @@ issue31596_test: CompileTimeError
issue32353_test: RuntimeError
label_test: RuntimeError
left_shift_test: RuntimeError # Ints and doubles are unified.
library_env_test/has_io_support: RuntimeError # Intended to fail, bool.fromEnvironment("dart.library.async") is false
library_env_test/has_mirror_support: RuntimeError # Intended to fail, bool.fromEnvironment("dart.library.async") is false
library_env_test/has_no_html_support: RuntimeError # Intended to fail, bool.fromEnvironment("dart.library.async") is false
method_override_test: CompileTimeError # Negative test
mixin_super_2_test/01: MissingCompileTimeError
mixin_super_2_test/03: MissingCompileTimeError
@ -424,9 +421,6 @@ issue31596_super_test/02: MissingCompileTimeError
issue31596_super_test/03: CompileTimeError
issue31596_super_test/04: MissingCompileTimeError
issue31596_super_test/05: RuntimeError
library_env_test/has_io_support: RuntimeError # Unsupported operation: bool.fromEnvironment can only be used as a const constructor
library_env_test/has_mirror_support: RuntimeError # Unsupported operation: bool.fromEnvironment can only be used as a const constructor
library_env_test/has_no_html_support: RuntimeError # Unsupported operation: bool.fromEnvironment can only be used as a const constructor
malbounded_instantiation_test/01: MissingCompileTimeError
malbounded_instantiation_test/02: MissingCompileTimeError
malbounded_instantiation_test/03: MissingCompileTimeError
@ -716,10 +710,9 @@ issue21159_test: RuntimeError # Issue 30701; TypeError: method.bind is not a fun
issue23244_test: RuntimeError # Issue 29920; Uncaught Unsupported operation: only top-level functions can be spawned.
least_upper_bound_expansive_test/none: RuntimeError # 30908; Uncaught RangeError: Maximum call stack size exceeded
left_shift_test: RuntimeError # Ints and doubles are unified.; Expect.equals(expected: <1>, actual: <-4294967295>) fails.
library_env_test/has_html_support: RuntimeError # Issue 30907; Unsupported operation: bool.fromEnvironment can only be used as a const constructor
library_env_test/has_no_io_support: RuntimeError # Issue 30907; Unsupported operation: bool.fromEnvironment can only be used as a const constructor
library_env_test/has_no_mirror_support: RuntimeError # Issue 30907; Unsupported operation: bool.fromEnvironment can only be used as a const constructor
library_env_test/none: RuntimeError # Issue 30907; Unsupported operation: bool.fromEnvironment can only be used as a const constructor
library_env_test/has_io_support: RuntimeError, OK # Intended to fail, bool.fromEnvironment("dart.library.async") is false
library_env_test/has_mirror_support: RuntimeError, OK # Intended to fail, bool.fromEnvironment("dart.library.async") is false
library_env_test/has_no_html_support: RuntimeError, OK # Intended to fail, bool.fromEnvironment("dart.library.async") is false
local_function2_test/none: RuntimeError # ReferenceError: TToNull is not defined
local_function3_test/none: RuntimeError # Expect.equals(expected: <true>, actual: <false>) fails.
local_function_test/none: RuntimeError # Expect.equals(expected: <true>, actual: <false>) fails.