Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(458)

Side by Side Diff: lib/isolate/frog/isolateimpl.dart

Issue 9478027: spawnUri: fixing test with recent support for multi-script tests. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | lib/isolate/isolate_frog.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /** Implementation of [Isolate2]. */ 5 /** Implementation of [Isolate2]. */
6 class _Isolate2Impl implements Isolate2 { 6 class _Isolate2Impl implements Isolate2 {
7 SendPort sendPort; 7 SendPort sendPort;
8 8
9 _Isolate2Impl(this.sendPort); 9 _Isolate2Impl(this.sendPort);
10 } 10 }
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 'replyPort': _serializeMessage(replyPort)})); 329 'replyPort': _serializeMessage(replyPort)}));
330 } else { 330 } else {
331 _spawnWorker(factoryName, _serializeMessage(replyPort)); 331 _spawnWorker(factoryName, _serializeMessage(replyPort));
332 } 332 }
333 } 333 }
334 334
335 /** 335 /**
336 * The src url for the script tag that loaded this code. Used to create 336 * The src url for the script tag that loaded this code. Used to create
337 * JavaScript workers. 337 * JavaScript workers.
338 */ 338 */
339 static String get _thisScript() => 339 static String get _thisScript() {
340 _thisScriptCache != null ? _thisScriptCache : _computeThisScript(); 340 if (_thisScriptCache == null) {
341 _thisScriptCache = _computeThisScript();
342 }
343 return _thisScriptCache;
344 }
341 345
342 static String _thisScriptCache; 346 static String _thisScriptCache;
343 347
344 // TODO(sigmund): fix - this code should be run synchronously when loading the 348 // TODO(sigmund): fix - this code should be run synchronously when loading the
345 // script. Running lazily on DOMContentLoaded will yield incorrect results. 349 // script. Running lazily on DOMContentLoaded will yield incorrect results.
346 static String _computeThisScript() native @""" 350 static String _computeThisScript() native @"""
347 if (!$globalState.supportsWorkers || $globalState.isWorker) return null; 351 if (!$globalState.supportsWorkers || $globalState.isWorker) return null;
348 352
349 // TODO(5334778): Find a cross-platform non-brittle way of getting the 353 // TODO(5334778): Find a cross-platform non-brittle way of getting the
350 // currently running script. 354 // currently running script.
351 var scripts = document.getElementsByTagName('script'); 355 var scripts = document.getElementsByTagName('script');
352 // The scripts variable only contains the scripts that have already been 356 // The scripts variable only contains the scripts that have already been
353 // executed. The last one is the currently running script. 357 // executed. The last one is the currently running script.
354 var script = scripts[scripts.length - 1]; 358 var script = scripts[scripts.length - 1];
355 var src = script && script.src; 359 var src = script && script.src;
356 if (!src) { 360 if (!src) {
357 // TODO() 361 // TODO()
358 src = "FIXME:5407062" + "_" + Math.random().toString(); 362 src = "FIXME:5407062" + "_" + Math.random().toString();
359 if (script) script.src = src; 363 if (script) script.src = src;
360 } 364 }
361 _IsolateNatives._thisScriptCache = src;
Siggi Cherem (dart-lang) 2012/02/28 02:40:48 this was not working because the code was generate
362 return src; 365 return src;
363 """; 366 """;
364 367
365 /** Starts a new worker with the given URL. */ 368 /** Starts a new worker with the given URL. */
366 static _Worker _newWorker(url) native "return new Worker(url);"; 369 static _Worker _newWorker(url) native "return new Worker(url);";
367 370
368 /** 371 /**
369 * Spawns an isolate in a worker. [factoryName] is the Javascript constructor 372 * Spawns an isolate in a worker. [factoryName] is the Javascript constructor
370 * name for the isolate entry point class. 373 * name for the isolate entry point class.
371 */ 374 */
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 } 602 }
600 603
601 /** 604 /**
602 * Spawns an isolate in a worker. [factoryName] is the Javascript constructor 605 * Spawns an isolate in a worker. [factoryName] is the Javascript constructor
603 * name for the isolate entry point class. 606 * name for the isolate entry point class.
604 */ 607 */
605 static void _spawnWorker2(functionName, uri, replyPort) { 608 static void _spawnWorker2(functionName, uri, replyPort) {
606 // TODO(eub): convert to 'main' once we switch back to port at top-level. 609 // TODO(eub): convert to 'main' once we switch back to port at top-level.
607 if (functionName == null) functionName = 'isolateMain'; 610 if (functionName == null) functionName = 'isolateMain';
608 if (uri == null) uri = _thisScript; 611 if (uri == null) uri = _thisScript;
612 if (!(new Uri.fromString(uri).isAbsolute())) {
613 String prefix = _thisScript.substring(0, _thisScript.lastIndexOf('/'));
614 uri = "$prefix/$uri";
615 }
609 final worker = _newWorker(uri); 616 final worker = _newWorker(uri);
610 worker.onmessage = (e) { _processWorkerMessage(worker, e); }; 617 worker.onmessage = (e) { _processWorkerMessage(worker, e); };
611 var workerId = globalState.nextWorkerId++; 618 var workerId = globalState.nextWorkerId++;
612 // We also store the id on the worker itself so that we can unregister it. 619 // We also store the id on the worker itself so that we can unregister it.
613 worker.id = workerId; 620 worker.id = workerId;
614 globalState.workers[workerId] = worker; 621 globalState.workers[workerId] = worker;
615 worker.postMessage(_serializeMessage({ 622 worker.postMessage(_serializeMessage({
616 'command': 'start2', 623 'command': 'start2',
617 'id': workerId, 624 'id': workerId,
618 // Note: we serialize replyPort twice because the child worker needs to 625 // Note: we serialize replyPort twice because the child worker needs to
619 // first deserialize the worker id, before it can correctly deserialize 626 // first deserialize the worker id, before it can correctly deserialize
620 // the port (port deserialization is sensitive to what is the current 627 // the port (port deserialization is sensitive to what is the current
621 // workerId). 628 // workerId).
622 'replyTo': _serializeMessage(replyPort), 629 'replyTo': _serializeMessage(replyPort),
623 'functionName': functionName })); 630 'functionName': functionName }));
624 } 631 }
625 } 632 }
OLDNEW
« no previous file with comments | « no previous file | lib/isolate/isolate_frog.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698