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

Side by Side Diff: frog/frogsh

Issue 8467034: Isolates in frog - tweaks in existing js code to make things run (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: '' Created 9 years, 1 month 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
OLDNEW
1 #!/usr/bin/env node 1 #!/usr/bin/env node
2 // ********** Library dart:core ************** 2 // ********** Library dart:core **************
3 // ********** Natives core.js ************** 3 // ********** Natives core.js **************
4 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 4 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
5 // for details. All rights reserved. Use of this source code is governed by a 5 // for details. All rights reserved. Use of this source code is governed by a
6 // BSD-style license that can be found in the LICENSE file. 6 // BSD-style license that can be found in the LICENSE file.
7 7
8 // TODO(jimhug): Completeness - see tests/corelib 8 // TODO(jimhug): Completeness - see tests/corelib
9 9
10 /** Implements extends for dart classes on javascript prototypes. */ 10 /** Implements extends for dart classes on javascript prototypes. */
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 } 325 }
326 326
327 function $varMethod(name, methods) { 327 function $varMethod(name, methods) {
328 Object.prototype[name] = function() { 328 Object.prototype[name] = function() {
329 $patchMethod(this, name, methods); 329 $patchMethod(this, name, methods);
330 this[name].apply(this, Array.prototype.slice.call(arguments)); 330 this[name].apply(this, Array.prototype.slice.call(arguments));
331 }; 331 };
332 } 332 }
333 333
334 Object.prototype.get$typeName = function() { 334 Object.prototype.get$typeName = function() {
335 // TODO(vsm): how can we make this go down the fast path for Chrome? 335 // TODO(sigmund): find a way to make this work on all browsers, including
336 //(for Chrome: return this.constructor.name;) 336 // checking the typeName on prototype objects (so we can fix dynamic
337 // dispatching on $varMethod).
338 if (window.constructor.name == 'DOMWindow') { // fast-path for Chrome
339 return this.constructor.name;
340 }
337 var str = Object.prototype.toString.call(this); 341 var str = Object.prototype.toString.call(this);
338 return str.substring(8, str.length - 1); 342 return str.substring(8, str.length - 1);
339 } 343 }
340 344
341 function $patchMethod(obj, name, methods) { 345 function $patchMethod(obj, name, methods) {
342 // Get the prototype to patch. 346 // Get the prototype to patch.
343 // Don't overwrite an existing stub, like the one on Object.prototype 347 // Don't overwrite an existing stub, like the one on Object.prototype
344 var proto = Object.getPrototypeOf(obj); 348 var proto = Object.getPrototypeOf(obj);
345 if (!proto || proto.hasOwnProperty(name)) proto = obj; 349 if (!proto || proto.hasOwnProperty(name)) proto = obj;
346 var method; 350 var method;
347 while (obj && !(method = methods[obj.get$typeName()])) { 351 while (obj && !(method = methods[obj.get$typeName()])) {
348 obj = Object.getPrototypeOf(obj); 352 obj = Object.getPrototypeOf(obj);
349 } 353 }
350 Object.defineProperty(proto, name, {value: method || methods['Object']}); 354 obj[name] = method || methods['Object'];
351 } 355 }
352 // ********** Code for Clock ************** 356 // ********** Code for Clock **************
353 function Clock() {} 357 function Clock() {}
354 Clock.now = function() { 358 Clock.now = function() {
355 return new Date().getTime(); 359 return new Date().getTime();
356 } 360 }
357 Clock.frequency = function() { 361 Clock.frequency = function() {
358 return 1000; 362 return 1000;
359 } 363 }
360 // ********** Code for AssertError ************** 364 // ********** Code for AssertError **************
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 function print(obj) { 512 function print(obj) {
509 if (typeof console == 'object') { 513 if (typeof console == 'object') {
510 if (obj) obj = obj.toString(); 514 if (obj) obj = obj.toString();
511 console.log(obj); 515 console.log(obj);
512 } else { 516 } else {
513 write(obj); 517 write(obj);
514 write('\n'); 518 write('\n');
515 } 519 }
516 } 520 }
517 // ********** Library dart:coreimpl ************** 521 // ********** Library dart:coreimpl **************
522 // ********** Natives isolate.js **************
523 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
524 // for details. All rights reserved. Use of this source code is governed by a
525 // BSD-style license that can be found in the LICENSE file.
526
527 var isolate$current = null;
528 var isolate$rootIsolate = null; // Will only be set in the main worker.
529 var isolate$inits = [];
530 var isolate$globalThis = this;
531
532 var isolate$inWorker =
533 (typeof isolate$globalThis['importScripts']) != "undefined";
534 var isolate$supportsWorkers =
535 isolate$inWorker || ((typeof isolate$globalThis['Worker']) != 'undefined');
536
537 var isolate$MAIN_WORKER_ID = 0;
538 // Non-main workers will update the id variable.
539 var isolate$thisWorkerId = isolate$MAIN_WORKER_ID;
540
541 // Whether to use web workers when implementing isolates.
542 var isolate$useWorkers = isolate$supportsWorkers;
543 // Uncomment this to not use web workers even if they're available.
544 // isolate$useWorkers = false;
545
546 // Whether to use the web-worker JSON-based message serialization protocol,
547 // even if not using web workers.
548 var isolate$useWorkerSerializationProtocol = false;
549 // Uncomment this to always use the web-worker JSON-based message
550 // serialization protocol, e.g. for testing purposes.
551 // isolate$useWorkerSerializationProtocol = true;
552
553
554 // ------- SendPort -------
555
556 function isolate$receiveMessage(port, isolate,
557 serializedMessage, serializedReplyTo) {
558 isolate$IsolateEvent.enqueue(isolate, function() {
559 var message = isolate$deserializeMessage(serializedMessage);
560 var replyTo = isolate$deserializeMessage(serializedReplyTo);
561 port._callback(message, replyTo);
562 });
563 }
564
565 // -------- Registry ---------
566 function isolate$Registry() {
567 this.map = {};
568 this.count = 0;
569 }
570
571 isolate$Registry.prototype.register = function(id, val) {
572 if (this.map[id]) {
573 throw Error("Registry: Elements must be registered only once.");
574 }
575 this.map[id] = val;
576 this.count++;
577 };
578
579 isolate$Registry.prototype.unregister = function(id) {
580 if (id in this.map) {
581 delete this.map[id];
582 this.count--;
583 }
584 };
585
586 isolate$Registry.prototype.get = function(id) {
587 return this.map[id];
588 };
589
590 isolate$Registry.prototype.isEmpty = function() {
591 return this.count === 0;
592 };
593
594
595 // ------- Worker registry -------
596 // Only used in the main worker.
597 var isolate$workerRegistry = new isolate$Registry();
598
599 // ------- Isolate registry -------
600 // Isolates must be registered if, and only if, receive ports are alive.
601 // Normally no open receive-ports means that the isolate is dead, but
602 // DOM callbacks could resurrect it.
603 var isolate$isolateRegistry = new isolate$Registry();
604
605 // ------- Debugging log function -------
606 function isolate$log(msg) {
607 return;
608 if (isolate$inWorker) {
609 isolate$mainWorker.postMessage({ command: 'log', msg: msg });
610 } else {
611 try {
612 isolate$globalThis.console.log(msg);
613 } catch(e) {
614 throw String(e.stack);
615 }
616 }
617 }
618
619 function isolate$initializeWorker(workerId) {
620 isolate$thisWorkerId = workerId;
621 }
622
623 var isolate$workerPrint = false;
624 if (isolate$inWorker) {
625 isolate$workerPrint = function(msg){
626 isolate$mainWorker.postMessage({ command: 'print', msg: msg });
627 }
628 }
629
630 // ------- Message handler -------
631 function isolate$processWorkerMessage(sender, e) {
632 var msg = e.data;
633 switch (msg.command) {
634 case 'start':
635 isolate$log("starting worker: " + msg.id + " " + msg.factoryName);
636 isolate$initializeWorker(msg.id);
637 var runnerObject = new (isolate$globalThis[msg.factoryName])();
638 var serializedReplyTo = msg.replyTo;
639 isolate$IsolateEvent.enqueue(new isolate$Isolate(), function() {
640 var replyTo = isolate$deserializeMessage(serializedReplyTo);
641 _IsolateJsUtil._startIsolate(runnerObject, replyTo);
642 });
643 isolate$runEventLoop();
644 break;
645 case 'spawn-worker':
646 isolate$spawnWorker(msg.factoryName, msg.replyPort);
647 break;
648 case 'message':
649 IsolateNatives.sendMessage(
650 msg.workerId, msg.isolateId, msg.portId, msg.msg, msg.replyTo);
651 isolate$runEventLoop();
652 break;
653 case 'close':
654 isolate$log("Closing Worker");
655 isolate$workerRegistry.unregister(sender.id);
656 sender.terminate();
657 isolate$runEventLoop();
658 break;
659 case 'log':
660 isolate$log(msg.msg);
661 break;
662 case 'print':
663 _IsolateJsUtil._print(msg.msg);
664 break;
665 case 'error':
666 throw msg.msg;
667 break;
668 }
669 }
670
671
672 if (isolate$supportsWorkers) {
673 isolate$globalThis.onmessage = function(e) {
674 isolate$processWorkerMessage(isolate$mainWorker, e);
675 };
676 }
677
678 // ------- Default Worker -------
679 function isolate$MainWorker() {
680 this.id = isolate$MAIN_WORKER_ID;
681 }
682
683 var isolate$mainWorker = new isolate$MainWorker();
684 isolate$mainWorker.postMessage = function(msg) {
685 isolate$globalThis.postMessage(msg);
686 };
687
688 var isolate$nextFreeIsolateId = 1;
689
690 // Native methods for isolate functionality.
691 /**
692 * @constructor
693 */
694 function isolate$Isolate() {
695 // The isolate ids is only unique within the current worker and frame.
696 this.id = isolate$nextFreeIsolateId++;
697 // When storing information on DOM nodes the isolate's id is not enough.
698 // We instead use a token with a hashcode. The token can be stored in the
699 // DOM node (since it is small and will not keep much data alive).
700 this.token = new Object();
701 this.token.hashCode = (Math.random() * 0xFFFFFFF) >>> 0;
702 this.receivePorts = new isolate$Registry();
703 this.run(function() {
704 // The Dart-to-JavaScript compiler builds a list of functions that
705 // need to run for each isolate to setup the state of static
706 // variables. Run through the list and execute each function.
707 for (var i = 0, len = isolate$inits.length; i < len; i++) {
708 isolate$inits[i]();
709 }
710 });
711 }
712
713 // It is allowed to stack 'run' calls. The stacked isolates can be different.
714 // That is Isolate1.run could call the DOM which then calls Isolate2.run.
715 isolate$Isolate.prototype.run = function(code) {
716 var old = isolate$current;
717 isolate$current = this;
718 var result = null;
719 try {
720 result = code();
721 } finally {
722 isolate$current = old;
723 }
724 return result;
725 };
726
727 isolate$Isolate.prototype.registerReceivePort = function(id, port) {
728 if (this.receivePorts.isEmpty()) {
729 isolate$isolateRegistry.register(this.id, this);
730 }
731 this.receivePorts.register(id, port);
732 };
733
734 isolate$Isolate.prototype.unregisterReceivePort = function(id) {
735 this.receivePorts.unregister(id);
736 if (this.receivePorts.isEmpty()) {
737 isolate$isolateRegistry.unregister(this.id);
738 }
739 };
740
741 isolate$Isolate.prototype.getReceivePortForId = function(id) {
742 return this.receivePorts.get(id);
743 };
744
745 var isolate$events = [];
746
747 /**
748 * @constructor
749 */
750 function isolate$IsolateEvent(isolate, fn) {
751 this.isolate = isolate;
752 this.fn = fn;
753 }
754
755 isolate$IsolateEvent.prototype.process = function() {
756 this.isolate.run(this.fn);
757 };
758
759 isolate$IsolateEvent.enqueue = function(isolate, fn) {
760 isolate$events.push(new isolate$IsolateEvent(isolate, fn));
761 };
762
763
764 isolate$IsolateEvent.dequeue = function() {
765 if (isolate$events.length == 0) return null;
766 var result = isolate$events[0];
767 isolate$events.splice(0, 1);
768 return result;
769 };
770
771 function IsolateNatives() {}
772
773 IsolateNatives.sendMessage = function (workerId, isolateId, receivePortId,
774 message, replyTo) {
775 // Both, the message and the replyTo are already serialized.
776 if (workerId == isolate$thisWorkerId) {
777 var isolate = isolate$isolateRegistry.get(isolateId);
778 if (!isolate) return; // Isolate has been closed.
779 var receivePort = isolate.getReceivePortForId(receivePortId);
780 if (!receivePort) return; // ReceivePort has been closed.
781 isolate$receiveMessage(receivePort, isolate, message, replyTo);
782 } else {
783 var worker;
784 if (isolate$inWorker) {
785 worker = isolate$mainWorker;
786 } else {
787 worker = isolate$workerRegistry.get(workerId);
788 }
789 worker.postMessage({ command: 'message',
790 workerId: workerId,
791 isolateId: isolateId,
792 portId: receivePortId,
793 msg: message,
794 replyTo: replyTo });
795 }
796 }
797
798 // Wrap a 0-arg dom-callback to bind it with the current isolate:
799 function $wrap_call$0(fn) { return fn && fn.wrap$call$0(); }
800 Function.prototype.wrap$call$0 = function() {
801 var isolate = isolate$current;
802 var self = this;
803 this.wrap$0 = function() {
804 isolate.run(function() {
805 self();
806 });
807 isolate$runEventLoop();
808 };
809 this.wrap$call$0 = function() { return this.wrap$0; };
810 return this.wrap$0;
811 }
812
813 // Wrap a 1-arg dom-callback to bind it with the current isolate:
814 function $wrap_call$1(fn) { return fn && fn.wrap$call$1(); }
815 Function.prototype.wrap$call$1 = function() {
816 var isolate = isolate$current;
817 var self = this;
818 this.wrap$1 = function(arg) {
819 isolate.run(function() {
820 self(arg);
821 });
822 isolate$runEventLoop();
823 };
824 this.wrap$call$1 = function() { return this.wrap$1; };
825 return this.wrap$1;
826 }
827
828 IsolateNatives._spawn = function(runnable, light, replyPort) {
829 // TODO(floitsch): throw exception if runnable's class doesn't have a
830 // default constructor.
831 if (isolate$useWorkers && !light) {
832 isolate$startWorker(runnable, replyPort);
833 } else {
834 isolate$startNonWorker(runnable, replyPort);
835 }
836 }
837
838 IsolateNatives.get$shouldSerialize = function() {
839 return isolate$useWorkers || isolate$useWorkerSerializationProtocol;
840 }
841
842 IsolateNatives.registerPort = function(id, port) {
843 isolate$current.registerReceivePort(id, port);
844 }
845
846 IsolateNatives.unregisterPort = function(id) {
847 isolate$current.unregisterReceivePort(id);
848 }
849
850 IsolateNatives._currentWorkerId = function() {
851 return isolate$thisWorkerId;
852 }
853
854 IsolateNatives._currentIsolateId = function() {
855 return isolate$current.id;
856 }
857
858 function isolate$startNonWorker(runnable, replyTo) {
859 // Spawn a new isolate and create the receive port in it.
860 var spawned = new isolate$Isolate();
861
862 // Instead of just running the provided runnable, we create a
863 // new cloned instance of it with a fresh state in the spawned
864 // isolate. This way, we do not get cross-isolate references
865 // through the runnable.
866 var ctor = runnable.constructor;
867 isolate$IsolateEvent.enqueue(spawned, function() {
868 _IsolateJsUtil._startIsolate(new ctor(), replyTo);
869 });
870 }
871
872 // This field is only used by the main worker.
873 var isolate$nextFreeWorkerId = isolate$thisWorkerId + 1;
874
875 var isolate$thisScript = function() {
876 if (!isolate$supportsWorkers || isolate$inWorker) return null;
877
878 // TODO(5334778): Find a cross-platform non-brittle way of getting the
879 // currently running script.
880 var scripts = document.getElementsByTagName('script');
881 // The scripts variable only contains the scripts that have already been
882 // executed. The last one is the currently running script.
883 var script = scripts[scripts.length - 1];
884 var src = script.src;
885 if (!src) {
886 // TODO()
887 src = "FIXME:5407062" + "_" + Math.random().toString();
888 script.src = src;
889 }
890 return src;
891 }();
892
893 function isolate$startWorker(runnable, replyPort) {
894 // TODO(sigmund): make this browser independent
895 var factoryName = runnable.constructor.name;
896 var serializedReplyPort = isolate$serializeMessage(replyPort);
897 if (isolate$inWorker) {
898 isolate$mainWorker.postMessage({ command: 'spawn-worker',
899 factoryName: factoryName,
900 replyPort: serializedReplyPort } );
901 } else {
902 isolate$spawnWorker(factoryName, serializedReplyPort);
903 }
904 }
905
906 function isolate$spawnWorker(factoryName, serializedReplyPort) {
907 var worker = new Worker(isolate$thisScript);
908 worker.onmessage = function(e) {
909 isolate$processWorkerMessage(worker, e);
910 };
911 var workerId = isolate$nextFreeWorkerId++;
912 // We also store the id on the worker itself so that we can unregister it.
913 worker.id = workerId;
914 isolate$workerRegistry.register(workerId, worker);
915 worker.postMessage({ command: 'start',
916 id: workerId,
917 replyTo: serializedReplyPort,
918 factoryName: factoryName });
919 }
920
921 function isolate$closeWorkerIfNecessary() {
922 if (!isolate$isolateRegistry.isEmpty()) return;
923 isolate$mainWorker.postMessage( { command: 'close' } );
924 }
925
926 function isolate$doOneEventLoopIteration() {
927 var CONTINUE_LOOP = true;
928 var STOP_LOOP = false;
929 var event = isolate$IsolateEvent.dequeue();
930 if (!event) {
931 if (isolate$inWorker) {
932 isolate$closeWorkerIfNecessary();
933 } else if (!isolate$isolateRegistry.isEmpty() &&
934 isolate$workerRegistry.isEmpty() &&
935 !isolate$supportsWorkers && (typeof(window) == 'undefined')) {
936 // This should only trigger when running on the command-line.
937 // We don't want this check to execute in the browser where the isolate
938 // might still be alive due to DOM callbacks.
939 // throw Error("Program exited with open ReceivePorts.");
940 }
941 return STOP_LOOP;
942 } else {
943 event.process();
944 return CONTINUE_LOOP;
945 }
946 }
947
948 function isolate$doRunEventLoop() {
949 if (typeof window != 'undefined' && window.setTimeout) {
950 (function next() {
951 var continueLoop = isolate$doOneEventLoopIteration();
952 if (!continueLoop) return;
953 // TODO(kasperl): It might turn out to be too expensive to call
954 // setTimeout for every single event. This needs more investigation.
955 window.setTimeout(next, 0);
956 })();
957 } else {
958 while (true) {
959 var continueLoop = isolate$doOneEventLoopIteration();
960 if (!continueLoop) break;
961 }
962 }
963 }
964
965 function isolate$runEventLoop() {
966 if (!isolate$inWorker) {
967 isolate$doRunEventLoop();
968 } else {
969 try {
970 isolate$doRunEventLoop();
971 } catch(e) {
972 // TODO(floitsch): try to send stack-trace to the other side.
973 isolate$mainWorker.postMessage({ command: 'error', msg: "" + e });
974 }
975 }
976 }
977
978 function RunEntry(entry, args) {
979 // Don't start the main loop again, if we are in a worker.
980 if (isolate$inWorker) return;
981 var isolate = new isolate$Isolate();
982 isolate$rootIsolate = isolate;
983 isolate$IsolateEvent.enqueue(isolate, function() {
984 entry(args);
985 });
986 isolate$runEventLoop();
987
988 // BUG(5151491): This should not be necessary, but because closures
989 // passed to the DOM as event handlers do not bind their isolate
990 // automatically we try to give them a reasonable context to live in
991 // by having a "default" isolate (the first one created).
992 isolate$current = isolate;
993 }
994
995 // ------- Message Serializing and Deserializing -------
996
997 function isolate$serializeMessage(message) {
998 if (isolate$useWorkers || isolate$useWorkerSerializationProtocol) {
999 return _IsolateJsUtil._serializeObject(message);
1000 } else {
1001 return _IsolateJsUtil._copyObject(message);
1002 }
1003 }
1004
1005 function isolate$deserializeMessage(message_) {
1006 if (isolate$useWorkers || isolate$useWorkerSerializationProtocol) {
1007 return _IsolateJsUtil._deserializeMessage(message_);
1008 } else {
1009 // Nothing more to do.
1010 return message_;
1011 }
1012 }
1013
1014 function _IsolateJsUtil() {}
518 // ********** Code for ListFactory ************** 1015 // ********** Code for ListFactory **************
519 ListFactory = Array; 1016 ListFactory = Array;
520 ListFactory.prototype.is$List = function(){return this;}; 1017 ListFactory.prototype.is$List = function(){return this;};
521 ListFactory.prototype.is$List$ArgumentNode = function(){return this;}; 1018 ListFactory.prototype.is$List$ArgumentNode = function(){return this;};
522 ListFactory.prototype.is$List$EvaluatedValue = function(){return this;}; 1019 ListFactory.prototype.is$List$EvaluatedValue = function(){return this;};
523 ListFactory.prototype.is$List$HInstruction = function(){return this;}; 1020 ListFactory.prototype.is$List$HInstruction = function(){return this;};
524 ListFactory.prototype.is$List$String = function(){return this;}; 1021 ListFactory.prototype.is$List$String = function(){return this;};
525 ListFactory.prototype.is$List$T = function(){return this;}; 1022 ListFactory.prototype.is$List$T = function(){return this;};
526 ListFactory.prototype.is$List$Value = function(){return this;}; 1023 ListFactory.prototype.is$List$Value = function(){return this;};
527 ListFactory.prototype.is$List$int = function(){return this;}; 1024 ListFactory.prototype.is$List$int = function(){return this;};
(...skipping 8086 matching lines...) Expand 10 before | Expand all | Expand 10 after
8614 world.get$coreimpl().types.$index('NumImplementation').markUsed(); 9111 world.get$coreimpl().types.$index('NumImplementation').markUsed();
8615 world.get$coreimpl().types.$index('StringImplementation').markUsed(); 9112 world.get$coreimpl().types.$index('StringImplementation').markUsed();
8616 this.writeTypes(world.get$coreimpl()); 9113 this.writeTypes(world.get$coreimpl());
8617 this.writeTypes(world.corelib); 9114 this.writeTypes(world.corelib);
8618 var matchConstructor = world.get$coreimpl().types.$index('MatchImplementation' ).getConstructor(''); 9115 var matchConstructor = world.get$coreimpl().types.$index('MatchImplementation' ).getConstructor('');
8619 this.genMethod((matchConstructor && matchConstructor.is$Member())); 9116 this.genMethod((matchConstructor && matchConstructor.is$Member()));
8620 matchConstructor.generator.writeDefinition(this.writer, null); 9117 matchConstructor.generator.writeDefinition(this.writer, null);
8621 this.writeTypes(this.main.declaringType.get$library()); 9118 this.writeTypes(this.main.declaringType.get$library());
8622 this._writeDynamicStubs(world.functionType); 9119 this._writeDynamicStubs(world.functionType);
8623 this._writeGlobals(); 9120 this._writeGlobals();
8624 this.writer.writeln(('' + mainCall.code + ';')); 9121 this.writer.writeln(('RunEntry(function () {' + mainCall.code + ';}, []);'));
8625 } 9122 }
8626 WorldGenerator.prototype.globalForStaticField = function(field, fieldValue, depe ndencies) { 9123 WorldGenerator.prototype.globalForStaticField = function(field, fieldValue, depe ndencies) {
8627 var fullname = ("" + field.declaringType.get$jsname() + "." + field.get$jsname () + ""); 9124 var fullname = ("" + field.declaringType.get$jsname() + "." + field.get$jsname () + "");
8628 if ($notnull_bool(!$notnull_bool(this.globals.containsKey(fullname)))) { 9125 if ($notnull_bool(!$notnull_bool(this.globals.containsKey(fullname)))) {
8629 this.globals.$setindex(fullname, GlobalValue.GlobalValue$fromStatic$factory( field, fieldValue, dependencies)); 9126 this.globals.$setindex(fullname, GlobalValue.GlobalValue$fromStatic$factory( field, fieldValue, dependencies));
8630 } 9127 }
8631 return this.globals.$index(fullname); 9128 return this.globals.$index(fullname);
8632 } 9129 }
8633 WorldGenerator.prototype.globalForConst = function(exp, dependencies) { 9130 WorldGenerator.prototype.globalForConst = function(exp, dependencies) {
8634 var code = exp.canonicalCode; 9131 var code = exp.canonicalCode;
(...skipping 8834 matching lines...) Expand 10 before | Expand all | Expand 10 after
17469 var checked = !$notnull_bool(isDynamic); 17966 var checked = !$notnull_bool(isDynamic);
17470 var callMethod = toType.getCallMethod(); 17967 var callMethod = toType.getCallMethod();
17471 if ($notnull_bool($ne(callMethod, null))) { 17968 if ($notnull_bool($ne(callMethod, null))) {
17472 if ($notnull_bool(checked && !$notnull_bool(toType.isAssignable(this.type))) ) { 17969 if ($notnull_bool(checked && !$notnull_bool(toType.isAssignable(this.type))) ) {
17473 this.convertWarning(toType, node); 17970 this.convertWarning(toType, node);
17474 } 17971 }
17475 var arity = callMethod.get$parameters().length; 17972 var arity = callMethod.get$parameters().length;
17476 var myCall = this.type.getCallMethod(); 17973 var myCall = this.type.getCallMethod();
17477 if ($notnull_bool(myCall == null || myCall.get$parameters().length != arity) ) { 17974 if ($notnull_bool(myCall == null || myCall.get$parameters().length != arity) ) {
17478 var stub = world.functionType.getCallStub(Arguments.Arguments$bare$factory (arity)); 17975 var stub = world.functionType.getCallStub(Arguments.Arguments$bare$factory (arity));
17479 return new Value(toType, ('to\$' + stub.name + '(' + this.code + ')'), fal se, true, false); 17976 var val = new Value(toType, ('to\$' + stub.name + '(' + this.code + ')'), false, true, false);
17977 return $notnull_bool(this._isDomCallback(toType) && !$notnull_bool(this._i sDomCallback(this.type))) ? val._wrapDomCallback(toType, arity) : val;
17978 }
17979 else if ($notnull_bool(this._isDomCallback(toType) && !$notnull_bool(this._i sDomCallback(this.type)))) {
17980 return this._wrapDomCallback(toType, arity);
17480 } 17981 }
17481 } 17982 }
17482 if ($notnull_bool(!$notnull_bool(options.enableTypeChecks))) { 17983 if ($notnull_bool(!$notnull_bool(options.enableTypeChecks))) {
17483 return this; 17984 return this;
17484 } 17985 }
17485 var fromType = this.type; 17986 var fromType = this.type;
17486 if ($notnull_bool(this.type.get$isVar() && this.code != 'null')) { 17987 if ($notnull_bool(this.type.get$isVar() && this.code != 'null')) {
17487 fromType = world.objectType; 17988 fromType = world.objectType;
17488 } 17989 }
17489 var bothNum = this.type.get$isNum() && toType.get$isNum(); 17990 var bothNum = this.type.get$isNum() && toType.get$isNum();
(...skipping 14 matching lines...) Expand all
17504 } 18005 }
17505 else { 18006 else {
17506 if ($notnull_bool(this.code.startsWith('\$notnull_bool'))) { 18007 if ($notnull_bool(this.code.startsWith('\$notnull_bool'))) {
17507 return this; 18008 return this;
17508 } 18009 }
17509 else { 18010 else {
17510 return new Value(world.boolType, ('\$notnull_bool(' + this.code + ')'), fa lse, true, false); 18011 return new Value(world.boolType, ('\$notnull_bool(' + this.code + ')'), fa lse, true, false);
17511 } 18012 }
17512 } 18013 }
17513 } 18014 }
18015 Value.prototype._isDomCallback = function(toType) {
18016 return ((toType.get$definition() instanceof FunctionTypeDefinition) && $eq(toT ype.get$library(), world.get$dom()));
18017 }
18018 Value.prototype._wrapDomCallback = function(toType, arity) {
18019 return new Value(toType, ('\$wrap_call\$' + arity + '(' + this.code + ')'), fa lse, true, false);
18020 }
17514 Value.prototype._typeAssert = function(context, toType, node) { 18021 Value.prototype._typeAssert = function(context, toType, node) {
17515 if ($notnull_bool((toType instanceof ParameterType))) { 18022 if ($notnull_bool((toType instanceof ParameterType))) {
17516 var p = toType; 18023 var p = toType;
17517 toType = p.extendsType; 18024 toType = p.extendsType;
17518 } 18025 }
17519 if ($notnull_bool(toType.get$isObject() || toType.get$isVar())) { 18026 if ($notnull_bool(toType.get$isObject() || toType.get$isVar())) {
17520 world.internalError(('We thought ' + this.type.name + ' is not a subtype of ' + toType.name + '?')); 18027 world.internalError(('We thought ' + this.type.name + ' is not a subtype of ' + toType.name + '?'));
17521 } 18028 }
17522 if ($notnull_bool(toType.get$isNum())) toType = world.numType; 18029 if ($notnull_bool(toType.get$isNum())) toType = world.numType;
17523 var check; 18030 var check;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
17583 for (var i = 0; 18090 for (var i = 0;
17584 $notnull_bool(i < args.get$length()); i++) { 18091 $notnull_bool(i < args.get$length()); i++) {
17585 argsCode.add(args.values.$index(i).code); 18092 argsCode.add(args.values.$index(i).code);
17586 } 18093 }
17587 pos = Strings.join((argsCode && argsCode.is$List$String()), ", "); 18094 pos = Strings.join((argsCode && argsCode.is$List$String()), ", ");
17588 } 18095 }
17589 var noSuchArgs = [new Value(world.stringType, ('"' + name + '"'), false, true, false), new Value(world.listType, ('[' + pos + ']'), false, true, false)]; 18096 var noSuchArgs = [new Value(world.stringType, ('"' + name + '"'), false, true, false), new Value(world.listType, ('[' + pos + ']'), false, true, false)];
17590 return this._tryResolveMember(context, 'noSuchMethod').invoke$4(context, node, this, new Arguments(null, noSuchArgs)); 18097 return this._tryResolveMember(context, 'noSuchMethod').invoke$4(context, node, this, new Arguments(null, noSuchArgs));
17591 } 18098 }
17592 Value.prototype.invokeSpecial = function(name, args, returnType) { 18099 Value.prototype.invokeSpecial = function(name, args, returnType) {
17593 $assert(name.startsWith('\$'), "name.startsWith('\\$')", "value.dart", 417, 12 ); 18100 $assert(name.startsWith('\$'), "name.startsWith('\\$')", "value.dart", 431, 12 );
17594 $assert(!$notnull_bool(args.get$hasNames()), "!args.hasNames", "value.dart", 4 18, 12); 18101 $assert(!$notnull_bool(args.get$hasNames()), "!args.hasNames", "value.dart", 4 32, 12);
17595 var argsString = args.getCode(); 18102 var argsString = args.getCode();
17596 if ($notnull_bool(name == '\$index' || name == '\$setindex')) { 18103 if ($notnull_bool(name == '\$index' || name == '\$setindex')) {
17597 return new Value(returnType, ('' + this.code + '.' + name + '(' + argsString + ')'), false, true, false); 18104 return new Value(returnType, ('' + this.code + '.' + name + '(' + argsString + ')'), false, true, false);
17598 } 18105 }
17599 else { 18106 else {
17600 if ($notnull_bool(argsString.length > 0)) argsString = (', ' + argsString + ''); 18107 if ($notnull_bool(argsString.length > 0)) argsString = (', ' + argsString + '');
17601 return new Value(returnType, ('' + name + '(' + this.code + '' + argsString + ')'), false, true, false); 18108 return new Value(returnType, ('' + name + '(' + this.code + '' + argsString + ')'), false, true, false);
17602 } 18109 }
17603 } 18110 }
17604 Value.prototype.get_$3 = function($0, $1, $2) { 18111 Value.prototype.get_$3 = function($0, $1, $2) {
(...skipping 1054 matching lines...) Expand 10 before | Expand all | Expand 10 after
18659 IMPORT, 19166 IMPORT,
18660 INTERFACE, 19167 INTERFACE,
18661 LIBRARY, 19168 LIBRARY,
18662 NATIVE, 19169 NATIVE,
18663 NEGATE, 19170 NEGATE,
18664 OPERATOR, 19171 OPERATOR,
18665 SET, 19172 SET,
18666 SOURCE, 19173 SOURCE,
18667 STATIC, 19174 STATIC,
18668 TYPEDEF ]*/; 19175 TYPEDEF ]*/;
18669 main(); 19176 RunEntry(function () {main();}, []);
jimhug 2011/11/08 15:39:01 500 lines is a lot to add - but considering that w
Siggi Cherem (dart-lang) 2011/11/08 17:56:42 Yeah - I'll be working this week on bringing this
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698