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

Side by Side Diff: lib/runtime/dart/_runtime.js

Issue 1680263002: Support for dart:typed_data (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Address comments, rebase Created 4 years, 10 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/_native_typed_data.js ('k') | lib/runtime/dart/collection.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 dart_library.library('dart/_runtime', null, /* Imports */[ 1 dart_library.library('dart/_runtime', null, /* Imports */[
2 ], /* Lazy imports */[ 2 ], /* Lazy imports */[
3 'dart/core', 3 'dart/core',
4 'dart/_interceptors', 4 'dart/_interceptors',
5 'dart/_js_helper', 5 'dart/_js_helper',
6 'dart/async', 6 'dart/async',
7 'dart/collection' 7 'dart/collection'
8 ], function(exports, core, _interceptors, _js_helper, async, collection) { 8 ], function(exports, core, _interceptors, _js_helper, async, collection) {
9 'use strict'; 9 'use strict';
10 function mixin(base, ...mixins) { 10 function mixin(base, ...mixins) {
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 function defineNamedConstructor(clazz, name) { 166 function defineNamedConstructor(clazz, name) {
167 let proto = clazz.prototype; 167 let proto = clazz.prototype;
168 let initMethod = proto[name]; 168 let initMethod = proto[name];
169 let ctor = function() { 169 let ctor = function() {
170 return initMethod.apply(this, arguments); 170 return initMethod.apply(this, arguments);
171 }; 171 };
172 ctor.prototype = proto; 172 ctor.prototype = proto;
173 defineProperty(clazz, name, {value: ctor, configurable: true}); 173 defineProperty(clazz, name, {value: ctor, configurable: true});
174 } 174 }
175 const _extensionType = Symbol("extensionType"); 175 const _extensionType = Symbol("extensionType");
176 function getExtensionType(obj) {
177 return obj[_extensionType];
178 }
176 const dartx = {}; 179 const dartx = {};
177 function getExtensionSymbol(name) { 180 function getExtensionSymbol(name) {
178 let sym = dartx[name]; 181 let sym = dartx[name];
179 if (!sym) dartx[name] = sym = Symbol('dartx.' + name); 182 if (!sym) dartx[name] = sym = Symbol('dartx.' + name);
180 return sym; 183 return sym;
181 } 184 }
182 function defineExtensionNames(names) { 185 function defineExtensionNames(names) {
183 return names.forEach(getExtensionSymbol); 186 return names.forEach(getExtensionSymbol);
184 } 187 }
188 function _installProperties(jsProto, extProto) {
189 if (extProto !== core.Object.prototype && extProto !== jsProto) {
190 _installProperties(jsProto, extProto.__proto__);
191 }
192 copyTheseProperties(jsProto, extProto, getOwnPropertySymbols(extProto));
193 }
185 function registerExtension(jsType, dartExtType) { 194 function registerExtension(jsType, dartExtType) {
186 let extProto = dartExtType.prototype; 195 let extProto = dartExtType.prototype;
187 let jsProto = jsType.prototype; 196 let jsProto = jsType.prototype;
188 assert_(jsProto[_extensionType] === void 0); 197 assert_(jsProto[_extensionType] === void 0);
189 jsProto[_extensionType] = extProto; 198 jsProto[_extensionType] = dartExtType;
190 let dartObjProto = core.Object.prototype; 199 _installProperties(jsProto, extProto);
191 while (extProto !== dartObjProto && extProto !== jsProto) {
192 copyTheseProperties(jsProto, extProto, getOwnPropertySymbols(extProto));
193 extProto = extProto.__proto__;
194 }
195 let originalSigFn = getOwnPropertyDescriptor(dartExtType, _methodSig).get; 200 let originalSigFn = getOwnPropertyDescriptor(dartExtType, _methodSig).get;
196 assert_(originalSigFn); 201 assert_(originalSigFn);
197 defineMemoizedGetter(jsType, _methodSig, originalSigFn); 202 defineMemoizedGetter(jsType, _methodSig, originalSigFn);
198 } 203 }
199 function defineExtensionMembers(type, methodNames) { 204 function defineExtensionMembers(type, methodNames) {
200 let proto = type.prototype; 205 let proto = type.prototype;
201 for (let name of methodNames) { 206 for (let name of methodNames) {
202 let method = getOwnPropertyDescriptor(proto, name); 207 let method = getOwnPropertyDescriptor(proto, name);
203 defineProperty(proto, getExtensionSymbol(name), method); 208 defineProperty(proto, getExtensionSymbol(name), method);
204 } 209 }
205 let originalSigFn = getOwnPropertyDescriptor(type, _methodSig).get; 210 let originalSigFn = getOwnPropertyDescriptor(type, _methodSig).get;
206 defineMemoizedGetter(type, _methodSig, function() { 211 defineMemoizedGetter(type, _methodSig, function() {
207 let sig = originalSigFn(); 212 let sig = originalSigFn();
208 for (let name of methodNames) { 213 for (let name of methodNames) {
209 sig[getExtensionSymbol(name)] = sig[name]; 214 sig[getExtensionSymbol(name)] = sig[name];
210 } 215 }
211 return sig; 216 return sig;
212 }); 217 });
213 } 218 }
214 function canonicalMember(obj, name) { 219 function canonicalMember(obj, name) {
215 if (obj != null && obj[_extensionType]) return dartx[name]; 220 if (obj != null && obj[_extensionType]) return dartx[name];
216 if (name == 'constructor' || name == 'prototype') { 221 if (name == 'constructor' || name == 'prototype') {
217 name = '+' + name; 222 name = '+' + name;
218 } 223 }
219 return name; 224 return name;
220 } 225 }
221 function setType(obj, type) { 226 function setType(obj, type) {
222 obj.__proto__ = type.prototype; 227 obj.__proto__ = type.prototype;
228 obj.__proto__[_extensionType] = type;
223 return obj; 229 return obj;
224 } 230 }
225 function list(obj, elementType) { 231 function list(obj, elementType) {
226 return setType(obj, getGenericClass(_interceptors.JSArray)(elementType)); 232 return setType(obj, getGenericClass(_interceptors.JSArray)(elementType));
227 } 233 }
228 function setBaseClass(derived, base) { 234 function setBaseClass(derived, base) {
229 derived.prototype.__proto__ = base.prototype; 235 derived.prototype.__proto__ = base.prototype;
230 } 236 }
231 function throwCastError(actual, type) { 237 function throwCastError(actual, type) {
232 throw_(new _js_helper.CastErrorImplementation(actual, type)); 238 throw_(new _js_helper.CastErrorImplementation(actual, type));
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 } 475 }
470 function _ignoreTypeFailure(actual, type) { 476 function _ignoreTypeFailure(actual, type) {
471 if (isSubtype(type, core.Iterable) && isSubtype(actual, core.Iterable) || is Subtype(type, async.Future) && isSubtype(actual, async.Future) || isSubtype(type , core.Map) && isSubtype(actual, core.Map) || isSubtype(type, core.Function) && isSubtype(actual, core.Function) || isSubtype(type, async.Stream) && isSubtype(a ctual, async.Stream) || isSubtype(type, async.StreamSubscription) && isSubtype(a ctual, async.StreamSubscription)) { 477 if (isSubtype(type, core.Iterable) && isSubtype(actual, core.Iterable) || is Subtype(type, async.Future) && isSubtype(actual, async.Future) || isSubtype(type , core.Map) && isSubtype(actual, core.Map) || isSubtype(type, core.Function) && isSubtype(actual, core.Function) || isSubtype(type, async.Stream) && isSubtype(a ctual, async.Stream) || isSubtype(type, async.StreamSubscription) && isSubtype(a ctual, async.StreamSubscription)) {
472 console.warn('Ignoring cast fail from ' + typeName(actual) + ' to ' + type Name(type)); 478 console.warn('Ignoring cast fail from ' + typeName(actual) + ' to ' + type Name(type));
473 return true; 479 return true;
474 } 480 }
475 return false; 481 return false;
476 } 482 }
477 function strongInstanceOf(obj, type, ignoreFromWhiteList) { 483 function strongInstanceOf(obj, type, ignoreFromWhiteList) {
478 let actual = realRuntimeType(obj); 484 let actual = realRuntimeType(obj);
479 if (isSubtype(actual, type) || actual == jsobject) return true; 485 if (isSubtype(actual, type) || actual == jsobject || actual == core.int && t ype == core.double) return true;
480 if (ignoreFromWhiteList == void 0) return false; 486 if (ignoreFromWhiteList == void 0) return false;
481 if (isGroundType(type)) return false; 487 if (isGroundType(type)) return false;
482 if (_ignoreTypeFailure(actual, type)) return true; 488 if (_ignoreTypeFailure(actual, type)) return true;
483 return false; 489 return false;
484 } 490 }
485 function instanceOfOrNull(obj, type) { 491 function instanceOfOrNull(obj, type) {
486 if (obj == null || strongInstanceOf(obj, type, true)) return true; 492 if (obj == null || strongInstanceOf(obj, type, true)) return true;
487 return false; 493 return false;
488 } 494 }
489 function instanceOf(obj, type) { 495 function instanceOf(obj, type) {
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 { 684 {
679 return Symbol; 685 return Symbol;
680 } 686 }
681 } 687 }
682 if (obj === null) return core.Null; 688 if (obj === null) return core.Null;
683 return null; 689 return null;
684 } 690 }
685 function runtimeType(obj) { 691 function runtimeType(obj) {
686 let result = checkPrimitiveType(obj); 692 let result = checkPrimitiveType(obj);
687 if (result !== null) return result; 693 if (result !== null) return result;
688 return obj.runtimeType; 694 result = obj.runtimeType;
695 if (result) return result;
696 return _nonPrimitiveRuntimeType(obj);
689 } 697 }
690 function getFunctionType(obj) { 698 function getFunctionType(obj) {
691 let args = Array(obj.length).fill(dynamicR); 699 let args = Array(obj.length).fill(dynamicR);
692 return definiteFunctionType(bottom, args); 700 return definiteFunctionType(bottom, args);
693 } 701 }
694 function realRuntimeType(obj) { 702 function realRuntimeType(obj) {
695 let result = checkPrimitiveType(obj); 703 let result = checkPrimitiveType(obj);
696 if (result !== null) return result; 704 if (result !== null) return result;
697 result = obj[_runtimeType]; 705 return _nonPrimitiveRuntimeType(obj);
706 }
707 function _nonPrimitiveRuntimeType(obj) {
708 let result = obj[_runtimeType];
709 if (result) return result;
710 result = obj[_extensionType];
698 if (result) return result; 711 if (result) return result;
699 result = obj.constructor; 712 result = obj.constructor;
700 if (result == Function) { 713 if (result == Function) {
701 return jsobject; 714 return jsobject;
702 } 715 }
703 return result; 716 return result;
704 } 717 }
705 function LazyTagged(infoFn) { 718 function LazyTagged(infoFn) {
706 class _Tagged { 719 class _Tagged {
707 get [_runtimeType]() { 720 get [_runtimeType]() {
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
1192 exports.generic = generic; 1205 exports.generic = generic;
1193 exports.getGenericClass = getGenericClass; 1206 exports.getGenericClass = getGenericClass;
1194 exports.getGenericArgs = getGenericArgs; 1207 exports.getGenericArgs = getGenericArgs;
1195 exports.getMethodType = getMethodType; 1208 exports.getMethodType = getMethodType;
1196 exports.classGetConstructorType = classGetConstructorType; 1209 exports.classGetConstructorType = classGetConstructorType;
1197 exports.bind = bind; 1210 exports.bind = bind;
1198 exports.setSignature = setSignature; 1211 exports.setSignature = setSignature;
1199 exports.hasMethod = hasMethod; 1212 exports.hasMethod = hasMethod;
1200 exports.virtualField = virtualField; 1213 exports.virtualField = virtualField;
1201 exports.defineNamedConstructor = defineNamedConstructor; 1214 exports.defineNamedConstructor = defineNamedConstructor;
1215 exports.getExtensionType = getExtensionType;
1202 exports.dartx = dartx; 1216 exports.dartx = dartx;
1203 exports.getExtensionSymbol = getExtensionSymbol; 1217 exports.getExtensionSymbol = getExtensionSymbol;
1204 exports.defineExtensionNames = defineExtensionNames; 1218 exports.defineExtensionNames = defineExtensionNames;
1205 exports.registerExtension = registerExtension; 1219 exports.registerExtension = registerExtension;
1206 exports.defineExtensionMembers = defineExtensionMembers; 1220 exports.defineExtensionMembers = defineExtensionMembers;
1207 exports.canonicalMember = canonicalMember; 1221 exports.canonicalMember = canonicalMember;
1208 exports.setType = setType; 1222 exports.setType = setType;
1209 exports.list = list; 1223 exports.list = list;
1210 exports.setBaseClass = setBaseClass; 1224 exports.setBaseClass = setBaseClass;
1211 exports.throwCastError = throwCastError; 1225 exports.throwCastError = throwCastError;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1301 exports.copyProperties = copyProperties; 1315 exports.copyProperties = copyProperties;
1302 exports.export = export_; 1316 exports.export = export_;
1303 exports.defineLazyClass = defineLazyClass; 1317 exports.defineLazyClass = defineLazyClass;
1304 exports.defineLazyProperties = defineLazyProperties; 1318 exports.defineLazyProperties = defineLazyProperties;
1305 exports.defineLazyClassGeneric = defineLazyClassGeneric; 1319 exports.defineLazyClassGeneric = defineLazyClassGeneric;
1306 exports.as = as_; 1320 exports.as = as_;
1307 exports.is = is_; 1321 exports.is = is_;
1308 exports.global = global_; 1322 exports.global = global_;
1309 exports.JsSymbol = JsSymbol; 1323 exports.JsSymbol = JsSymbol;
1310 }); 1324 });
OLDNEW
« no previous file with comments | « lib/runtime/dart/_native_typed_data.js ('k') | lib/runtime/dart/collection.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698