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

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
« no previous file with comments | « lib/runtime/dart/math.js ('k') | lib/src/codegen/js_codegen.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) 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, _js_primitives; 5 var dart, _js_helper, _js_primitives;
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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 // initializing them, but easier to not depend on that. 867 // initializing them, but easier to not depend on that.
863 for (let name of getOwnNamesAndSymbols(obj)) { 868 for (let name of getOwnNamesAndSymbols(obj)) {
864 // TODO(jmesserly): we can make this faster if needed. 869 // TODO(jmesserly): we can make this faster if needed.
865 objectKey.push(name); 870 objectKey.push(name);
866 objectKey.push(obj[name]); 871 objectKey.push(obj[name]);
867 } 872 }
868 return multiKeyPutIfAbsent(constants, objectKey, () => obj); 873 return multiKeyPutIfAbsent(constants, objectKey, () => obj);
869 } 874 }
870 dart.const = constant; 875 dart.const = constant;
871 876
872 /** Sets the runtime type of `obj` to be `type` */ 877 /** Sets the type of `obj` to be `type` */
873 function setType(obj, type) { 878 function setType(obj, type) {
879 obj.__proto__ = type.prototype;
880 }
881 dart.setType = setType;
882
883 /** Sets the internal runtime type of `obj` to be `type` */
884 function setRuntimeType(obj, type) {
874 obj[_runtimeType] = type; 885 obj[_runtimeType] = type;
875 } 886 }
876 dart.setType = setType; 887 dart.setRuntimeType = setRuntimeType;
877 888
878 // The following are helpers for Object methods when the receiver 889 // The following are helpers for Object methods when the receiver
879 // may be null or primitive. These should only be generated by 890 // may be null or primitive. These should only be generated by
880 // the compiler. 891 // the compiler.
881 function hashCode(obj) { 892 function hashCode(obj) {
882 if (obj == null) { 893 if (obj == null) {
883 return 0; 894 return 0;
884 } 895 }
885 // TODO(vsm): What should we do for primitives and non-Dart objects? 896 // TODO(vsm): What should we do for primitives and non-Dart objects?
886 switch (typeof obj) { 897 switch (typeof obj) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 dart.JsSymbol = Symbol; 947 dart.JsSymbol = Symbol;
937 948
938 // TODO(jmesserly): hack to bootstrap the SDK 949 // TODO(jmesserly): hack to bootstrap the SDK
939 _js_helper = _js_helper || {}; 950 _js_helper = _js_helper || {};
940 _js_helper.checkNum = notNull; 951 _js_helper.checkNum = notNull;
941 952
942 _js_primitives = _js_primitives || {}; 953 _js_primitives = _js_primitives || {};
943 _js_primitives.printString = (s) => console.log(s); 954 _js_primitives.printString = (s) => console.log(s);
944 955
945 })(dart || (dart = {})); 956 })(dart || (dart = {}));
OLDNEW
« no previous file with comments | « lib/runtime/dart/math.js ('k') | lib/src/codegen/js_codegen.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698