diff --git a/pkg/compiler/lib/src/js_backend/resolution_listener.dart b/pkg/compiler/lib/src/js_backend/resolution_listener.dart index 289ae4290c5..118318285a4 100644 --- a/pkg/compiler/lib/src/js_backend/resolution_listener.dart +++ b/pkg/compiler/lib/src/js_backend/resolution_listener.dart @@ -312,26 +312,14 @@ class ResolutionEnqueuerListener extends EnqueuerListener { } // Enable isolate support if we start using something from the isolate - // library, or timers for the async library. We exclude constant fields, - // which are ending here because their initializing expression is - // compiled. - LibraryEntity library = member.library; - if (!_backendUsage.isIsolateInUse && !(member.isField && member.isConst)) { - Uri uri = library.canonicalUri; - if (uri == Uris.dart_isolate) { - _backendUsage.isIsolateInUse = true; - worldImpact - .addImpact(_enableIsolateSupport(_elementEnvironment.mainFunction)); - } else if (uri == Uris.dart_async) { - if (member.name == '_createTimer' || - member.name == '_createPeriodicTimer') { - // The [:Timer:] class uses the event queue of the isolate - // library, so we make sure that event queue is generated. - _backendUsage.isIsolateInUse = true; - worldImpact.addImpact( - _enableIsolateSupport(_elementEnvironment.mainFunction)); - } - } + // library. We exclude constant fields, which are ending here because their + // initializing expression is compiled. + if (!_backendUsage.isIsolateInUse && + !(member.isField && member.isConst) && + member.library.canonicalUri == Uris.dart_isolate) { + _backendUsage.isIsolateInUse = true; + worldImpact + .addImpact(_enableIsolateSupport(_elementEnvironment.mainFunction)); } if (member.isGetter && member.name == Identifiers.runtimeType_) { @@ -437,6 +425,10 @@ class ResolutionEnqueuerListener extends EnqueuerListener { _interceptorData.addInterceptorsForNativeClassMembers(cls); } else if (cls == _commonElements.jsIndexingBehaviorInterface) { _registerBackendImpact(impactBuilder, _impacts.jsIndexingBehavior); + } else if (cls.library.canonicalUri == Uris.dart_isolate) { + _backendUsage.isIsolateInUse = true; + impactBuilder + .addImpact(_enableIsolateSupport(_elementEnvironment.mainFunction)); } _customElementsAnalysis.registerInstantiatedClass(cls); diff --git a/sdk/lib/_internal/js_runtime/lib/isolate_helper.dart b/sdk/lib/_internal/js_runtime/lib/isolate_helper.dart index 86ef3ecc6b6..1b9ccc25fca 100644 --- a/sdk/lib/_internal/js_runtime/lib/isolate_helper.dart +++ b/sdk/lib/_internal/js_runtime/lib/isolate_helper.dart @@ -72,20 +72,15 @@ _callInIsolate(_IsolateContext isolate, Function function) { /// /// These functions only has to be called for code that can be run from a /// worker-isolate (so not for general dom operations). -enterJsAsync() { - _globalState.topEventLoop._activeJsAsyncCount++; -} +enterJsAsync() {} /// Marks leaving a javascript async operation. /// /// See [enterJsAsync]. -leaveJsAsync() { - _globalState.topEventLoop._activeJsAsyncCount--; - assert(_globalState.topEventLoop._activeJsAsyncCount >= 0); -} +leaveJsAsync() {} /// Returns true if we are currently in a worker context. -bool isWorker() => _globalState.isWorker; +bool isWorker() => globalWindow == null && globalPostMessageDefined; /** * Called by the compiler to fetch the current isolate context. @@ -787,7 +782,7 @@ class IsolateNatives { return JS('String', 'String(#.src)', currentScript); } // A worker has no script tag - so get an url from a stack-trace. - if (_globalState.isWorker) return computeThisScriptFromTrace(); + if (isWorker()) return computeThisScriptFromTrace(); // An isolate that doesn't support workers, but doesn't have a // currentScript either. This is most likely a Chrome extension. return null; @@ -1372,31 +1367,11 @@ class ReceivePortImpl extends Stream implements ReceivePort { class TimerImpl implements Timer { final bool _once; - bool _inEventLoop = false; int _handle; int _tick = 0; TimerImpl(int milliseconds, void callback()) : _once = true { - if (milliseconds == 0 && (!hasTimer() || _globalState.isWorker)) { - void internalCallback() { - _handle = null; - callback(); - } - - // Setting _handle to something different from null indicates that the - // callback has not been run. Hence, the choice of 1 is arbitrary. - _handle = 1; - - // This makes a dependency between the async library and the - // event loop of the isolate library. The compiler makes sure - // that the event loop is compiled if [Timer] is used. - // TODO(7907): In case of web workers, we need to use the event - // loop instead of setTimeout, to make sure the futures get executed in - // order. - _globalState.topEventLoop - .enqueue(_globalState.currentContext, internalCallback, 'timer'); - _inEventLoop = true; - } else if (hasTimer()) { + if (hasTimer()) { void internalCallback() { _handle = null; leaveJsAsync(); @@ -1409,8 +1384,7 @@ class TimerImpl implements Timer { _handle = JS('int', 'self.setTimeout(#, #)', convertDartClosureToJS(internalCallback, 0), milliseconds); } else { - assert(milliseconds > 0); - throw new UnsupportedError('Timer greater than 0.'); + throw new UnsupportedError('`setTimeout()` not found.'); } } @@ -1443,9 +1417,6 @@ class TimerImpl implements Timer { void cancel() { if (hasTimer()) { - if (_inEventLoop) { - throw new UnsupportedError('Timer in event loop cannot be canceled.'); - } if (_handle == null) return; leaveJsAsync(); if (_once) { diff --git a/tests/co19/co19-dart2js.status b/tests/co19/co19-dart2js.status index ceb259275c6..d8f09d78344 100644 --- a/tests/co19/co19-dart2js.status +++ b/tests/co19/co19-dart2js.status @@ -188,7 +188,8 @@ LibTest/isolate/Isolate/spawnUri_A01_t06: RuntimeError # Dart issue 15974 LibTest/isolate/Isolate/spawnUri_A01_t07: RuntimeError # Dart issue 15974 LibTest/isolate/Isolate/spawnUri_A02_t01: RuntimeError, Pass # Dart issue 15617 LibTest/isolate/Isolate/spawn_A02_t02: RuntimeError, Pass # Dart issue 15617 -LibTest/isolate/Isolate/spawn_A04_t01: RuntimeError # Dart issue 15974 +LibTest/isolate/Isolate/spawn_A04_t01: SkipByDesign +LibTest/isolate/Isolate/spawn_A04_t02: SkipByDesign LibTest/isolate/Isolate/spawn_A06_t06: Skip # Times out. Please triage this failure. LibTest/math/MutableRectangle/boundingBox_A01_t01: RuntimeError, Pass # co19-roll r706: Please triage this failure. LibTest/math/Rectangle/boundingBox_A01_t01: RuntimeError, Pass # co19-roll r706: Please triage this failure. diff --git a/tests/compiler/dart2js_extra/dart2js_extra.status b/tests/compiler/dart2js_extra/dart2js_extra.status index 5dce5f5eeb5..c44b6e22d0f 100644 --- a/tests/compiler/dart2js_extra/dart2js_extra.status +++ b/tests/compiler/dart2js_extra/dart2js_extra.status @@ -43,7 +43,6 @@ no_such_method_mirrors_test: Pass, Slow # TODO(kasperl): Please triage. [ $compiler == dart2js && $runtime == d8 && $fasta ] deferred_fail_and_retry_test: RuntimeError # Uses XHR in dart:html -deferred_fail_and_retry_worker_test: Fail # Uses XHR in dart:html unconditional_dartio_import_test: RuntimeError # Uses dart:io [ $compiler == dart2js && $runtime == ff && $system == windows ] @@ -52,9 +51,6 @@ consistent_index_error_string_test: Pass, Slow # Issue 25940 [ $compiler == dart2js && $runtime == none ] *: Fail, Pass # TODO(ahe): Triage these tests. -[ $compiler == dart2js && $runtime == safari ] -deferred_fail_and_retry_worker_test: Timeout # Issue 22106 - [ $compiler == dart2js && $checked ] variable_type_test/01: Fail, OK variable_type_test/03: Fail, OK @@ -77,7 +73,6 @@ closure_signature_unneeded_test: RuntimeError # Too eager signature generation. [ $compiler == dart2js && $csp ] deferred_custom_loader_test: SkipByDesign # Issue 25683 deferred_fail_and_retry_test: SkipByDesign # Uses eval to simulate failed loading. -deferred_fail_and_retry_worker_test: SkipByDesign # Uses eval to simulate failed loading. js_interop_optional_arg_test: RuntimeError # Issue 31082 js_interop_test: RuntimeError # Issue 31082 diff --git a/tests/compiler/dart2js_extra/deferred_fail_and_retry_worker_test.dart b/tests/compiler/dart2js_extra/deferred_fail_and_retry_worker_test.dart deleted file mode 100644 index dffa7391403..00000000000 --- a/tests/compiler/dart2js_extra/deferred_fail_and_retry_worker_test.dart +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (c) 2015, 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. - -// Test that when a deferred import from a worker fails to load, it is possible -// to retry. - -import "deferred_fail_and_retry_lib.dart" deferred as lib; -import "package:expect/expect.dart"; -import "package:async_helper/async_helper.dart"; -import "dart:isolate"; -import "dart:js" as js; - -void test(SendPort sendPort) { - // Patch XMLHttpRequest to fail on first load. - js.context.callMethod("eval", [ - """ - oldXMLHttpRequest = XMLHttpRequest; - XMLHttpRequest = function() { - XMLHttpRequest = oldXMLHttpRequest; - var instance = new XMLHttpRequest(); - this.addEventListener = function(x, y, z) { - instance.addEventListener(x, y, z); - } - this.send = function() { - instance.send(); - } - this.open = function(x, uri) { - instance.open(x, "non_existing.js"); - } - } - """ - ]); - lib.loadLibrary().then((_) { - sendPort.send("Library should not have loaded"); - }, onError: (error) { - sendPort.send("failed"); - lib.loadLibrary().then((_) { - sendPort.send(lib.foo()); - }, onError: (error) { - sendPort.send("Library should have loaded this time $error"); - }); - }); -} - -main() { - ReceivePort receivePort = new ReceivePort(); - asyncStart(); - bool receivedFailed = false; - receivePort.listen((message) { - if (!receivedFailed) { - Expect.equals("failed", message); - receivedFailed = true; - } else { - Expect.equals("loaded", message); - asyncEnd(); - } - }); - Isolate.spawn(test, receivePort.sendPort); -} diff --git a/tests/compiler/dart2js_native/dart2js_native.status b/tests/compiler/dart2js_native/dart2js_native.status index d3f454e6c2c..45d07d37b64 100644 --- a/tests/compiler/dart2js_native/dart2js_native.status +++ b/tests/compiler/dart2js_native/dart2js_native.status @@ -14,9 +14,6 @@ native_no_such_method_exception5_frog_test: SkipByDesign # mirrors not supported [ $browser ] *: Skip -[ $compiler == dart2js && $runtime == d8 && $system == windows && !$fasta ] -compute_this_script_test: Skip # Issue 17458 - [ $compiler == dart2js && $fasta ] native_library_same_name_used_frog_test: CompileTimeError subclassing_constructor_1_test: RuntimeError @@ -24,8 +21,5 @@ subclassing_super_call_test: RuntimeError subclassing_super_field_1_test: RuntimeError subclassing_super_field_2_test: RuntimeError -[ $compiler == dart2js && $fasta && $host_checked ] -compute_this_script_test: Crash # 'file:*/pkg/compiler/lib/src/ssa/types.dart': Failed assertion: line 63 pos 12: '!result.isEmpty': is not true. - [ $compiler == dart2js && $minified ] optimization_hints_test: RuntimeError, OK # Test relies on unminified names. diff --git a/tests/html/html.status b/tests/html/html.status index 632145d466e..be29f941cc1 100644 --- a/tests/html/html.status +++ b/tests/html/html.status @@ -26,6 +26,8 @@ webgl_1_test: StaticWarning window_nosuchmethod_test: StaticWarning [ $compiler == dart2js ] +async_spawnuri_test: SkipByDesign +async_test: SkipByDesign custom/document_register_type_extensions_test/construction: Pass, Timeout # Roll 50 failure custom/document_register_type_extensions_test/registration: Pass, Timeout # Roll 50 failure custom/entered_left_view_test/shadow_dom: Pass, Timeout # Roll 50 failure @@ -194,7 +196,6 @@ xhr_test/json: Fail # TODO(dart2js-team): Please triage this failure. [ $compiler == dart2js && $runtime == d8 && $fasta ] async_spawnuri_test: RuntimeError -async_test: RuntimeError audiobuffersourcenode_test: RuntimeError audiocontext_test: RuntimeError audioelement_test: RuntimeError diff --git a/tests/isolate/isolate.status b/tests/isolate/isolate.status index 753bf0c29a5..c5dcc41273a 100644 --- a/tests/isolate/isolate.status +++ b/tests/isolate/isolate.status @@ -7,6 +7,7 @@ browser/typed_data_message_test: StaticWarning [ $compiler == dart2js ] browser/issue_12474_test: CompileTimeError # Issue 22529 +deferred_in_isolate2_test: SkipByDesign enum_const_test/02: RuntimeError # Issue 21817 error_at_spawnuri_test: SkipByDesign # Test uses a ".dart" URI. error_exit_at_spawnuri_test: SkipByDesign # Test uses a ".dart" URI. @@ -23,9 +24,11 @@ message3_test/constList_identical: RuntimeError # Issue 21817 message3_test/constMap: RuntimeError # Issue 21817 non_fatal_exception_in_timer_callback_test: Skip # Issue 23876 spawn_uri_exported_main_test: SkipByDesign # Test uses a ".dart" URI. +spawn_uri_missing_from_isolate_test: SkipByDesign spawn_uri_nested_vm_test: SkipByDesign # Test uses a ".dart" URI. spawn_uri_vm_test: SkipByDesign # Test uses a ".dart" URI. stacktrace_message_test: RuntimeError # Fails to send stacktrace object. +timer_isolate_test: SkipByDesign [ $compiler == fasta ] browser/compute_this_script_browser_test: CompileTimeError # TODO(ahe): Support dart:html in Fasta. diff --git a/tests/lib_2/lib_2_dart2js.status b/tests/lib_2/lib_2_dart2js.status index 6277cb5ee57..5250745d057 100644 --- a/tests/lib_2/lib_2_dart2js.status +++ b/tests/lib_2/lib_2_dart2js.status @@ -8,6 +8,8 @@ convert/base64_test/01: Fail, OK # Uses bit-wise operations to detect invalid va convert/chunked_conversion_utf88_test: Slow, Pass convert/utf85_test: Slow, Pass developer/timeline_test: Skip # Not supported +html/async_spawnuri_test: SkipByDesign +html/async_test: SkipByDesign html/custom/document_register_type_extensions_test/construction: Pass, Timeout # Roll 50 failure html/custom/document_register_type_extensions_test/registration: Pass, Timeout # Roll 50 failure html/custom/element_upgrade_failure_test: MissingCompileTimeError @@ -26,6 +28,7 @@ html/svgelement_test/PathElement: Pass, RuntimeError # Roll 50 failure html/wrapping_collections_test: SkipByDesign # Testing an issue that is only relevant to Dartium html/xhr_test: Pass, Slow isolate/browser/issue_12474_test: CompileTimeError # Issue 22529 +isolate/deferred_in_isolate2_test: SkipByDesign isolate/enum_const_test/02: RuntimeError # Issue 21817 isolate/error_at_spawnuri_test: SkipByDesign # Test uses a ".dart" URI. isolate/error_exit_at_spawnuri_test: SkipByDesign # Test uses a ".dart" URI. @@ -42,9 +45,11 @@ isolate/message3_test/constList_identical: RuntimeError # Issue 21817 isolate/message3_test/constMap: RuntimeError # Issue 21817 isolate/non_fatal_exception_in_timer_callback_test: Skip # Issue 23876 isolate/spawn_uri_exported_main_test: SkipByDesign # Test uses a ".dart" URI. +isolate/spawn_uri_missing_from_isolate_test: SkipByDesign isolate/spawn_uri_nested_vm_test: SkipByDesign # Test uses a ".dart" URI. isolate/spawn_uri_vm_test: SkipByDesign # Test uses a ".dart" URI. isolate/stacktrace_message_test: RuntimeError # Fails to send stacktrace object. +isolate/timer_isolate_test: SkipByDesign math/double_pow_test: RuntimeError math/low_test: RuntimeError math/random_big_test: RuntimeError # Using bigint seeds for random.