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

Side by Side Diff: lib/runtime/dart_runtime.js

Issue 1117793002: add checks needed for covariant generics, and List<E> (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 7 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
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 var dart, _js_helper; 5 var dart, _js_helper;
6 (function (dart) { 6 (function (dart) {
7 'use strict'; 7 'use strict';
8 8
9 let defineProperty = Object.defineProperty; 9 let defineProperty = Object.defineProperty;
10 let getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; 10 let getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 return to; 624 return to;
625 } 625 }
626 626
627 /** 627 /**
628 * Copy properties from source to destination object. 628 * Copy properties from source to destination object.
629 * This operation is commonly called `mixin` in JS. 629 * This operation is commonly called `mixin` in JS.
630 */ 630 */
631 function copyProperties(to, from) { 631 function copyProperties(to, from) {
632 return copyPropertiesHelper(to, from, getOwnNamesAndSymbols(from)); 632 return copyPropertiesHelper(to, from, getOwnNamesAndSymbols(from));
633 } 633 }
634 dart.copyProperties = copyProperties;
634 635
635 /** 636 /**
636 * Copy symbols from the prototype of the source to destination. 637 * Copy symbols from the prototype of the source to destination.
637 * These are the only properties safe to copy onto an existing public 638 * These are the only properties safe to copy onto an existing public
638 * JavaScript class. 639 * JavaScript class.
639 */ 640 */
640 function registerExtension(to, from) { 641 function registerExtension(to, from) {
641 return copyPropertiesHelper(to.prototype, from.prototype, 642 return copyPropertiesHelper(to.prototype, from.prototype,
642 getOwnPropertySymbols(from.prototype)); 643 getOwnPropertySymbols(from.prototype));
643 } 644 }
645 dart.registerExtension = registerExtension;
644 646
645 dart.copyProperties = copyProperties; 647 function setBaseClass(derived, base) {
646 dart.registerExtension = registerExtension; 648 // Link the extension to the type it's extending as a base class.
649 derived.prototype.__proto__ = base.prototype;
650 }
651 dart.setBaseClass = setBaseClass;
647 652
648 /** 653 /**
649 * This is called whenever a derived class needs to introduce a new field, 654 * This is called whenever a derived class needs to introduce a new field,
650 * shadowing a field or getter/setter pair on its parent. 655 * shadowing a field or getter/setter pair on its parent.
651 * 656 *
652 * This is important because otherwise, trying to read or write the field 657 * This is important because otherwise, trying to read or write the field
653 * would end up calling the getter or setter, and one of those might not even 658 * would end up calling the getter or setter, and one of those might not even
654 * exist, resulting in a runtime error. Even if they did exist, that's the 659 * exist, resulting in a runtime error. Even if they did exist, that's the
655 * wrong behavior if a new field was declared. 660 * wrong behavior if a new field was declared.
656 */ 661 */
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 // initializing them, but easier to not depend on that. 865 // initializing them, but easier to not depend on that.
861 for (let name of getOwnNamesAndSymbols(obj)) { 866 for (let name of getOwnNamesAndSymbols(obj)) {
862 // TODO(jmesserly): we can make this faster if needed. 867 // TODO(jmesserly): we can make this faster if needed.
863 objectKey.push(name); 868 objectKey.push(name);
864 objectKey.push(obj[name]); 869 objectKey.push(obj[name]);
865 } 870 }
866 return multiKeyPutIfAbsent(constants, objectKey, () => obj); 871 return multiKeyPutIfAbsent(constants, objectKey, () => obj);
867 } 872 }
868 dart.const = constant; 873 dart.const = constant;
869 874
870 /** Sets the runtime type of `obj` to be `type` */ 875 /** Sets the type of `obj` to be `type` */
871 function setType(obj, type) { 876 function setType(obj, type) {
877 obj.__proto__ = type.prototype;
878 }
879 dart.setType = setType;
880
881 /** Sets the internal runtime type of `obj` to be `type` */
882 function setRuntimeType(obj, type) {
872 obj[_runtimeType] = type; 883 obj[_runtimeType] = type;
873 } 884 }
874 dart.setType = setType; 885 dart.setRuntimeType = setRuntimeType;
875 886
876 // The following are helpers for Object methods when the receiver 887 // The following are helpers for Object methods when the receiver
877 // may be null or primitive. These should only be generated by 888 // may be null or primitive. These should only be generated by
878 // the compiler. 889 // the compiler.
879 function hashCode(obj) { 890 function hashCode(obj) {
880 if (obj == null) { 891 if (obj == null) {
881 return 0; 892 return 0;
882 } 893 }
883 // TODO(vsm): What should we do for primitives and non-Dart objects? 894 // TODO(vsm): What should we do for primitives and non-Dart objects?
884 switch (typeof obj) { 895 switch (typeof obj) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 dart.bottom = { toString() { return 'bottom'; } }; 942 dart.bottom = { toString() { return 'bottom'; } };
932 943
933 dart.global = window || global; 944 dart.global = window || global;
934 dart.JsSymbol = Symbol; 945 dart.JsSymbol = Symbol;
935 946
936 // TODO(jmesserly): hack to bootstrap the SDK 947 // TODO(jmesserly): hack to bootstrap the SDK
937 _js_helper = _js_helper || {}; 948 _js_helper = _js_helper || {};
938 _js_helper.checkNum = notNull; 949 _js_helper.checkNum = notNull;
939 950
940 })(dart || (dart = {})); 951 })(dart || (dart = {}));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698