OLD | NEW |
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 Loading... |
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 Loading... |
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 Loading... |
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 result = obj[_extensionType]; |
| 697 if (result) return result; |
| 698 return null; |
689 } | 699 } |
690 function getFunctionType(obj) { | 700 function getFunctionType(obj) { |
691 let args = Array(obj.length).fill(dynamicR); | 701 let args = Array(obj.length).fill(dynamicR); |
692 return definiteFunctionType(bottom, args); | 702 return definiteFunctionType(bottom, args); |
693 } | 703 } |
694 function realRuntimeType(obj) { | 704 function realRuntimeType(obj) { |
695 let result = checkPrimitiveType(obj); | 705 let result = checkPrimitiveType(obj); |
696 if (result !== null) return result; | 706 if (result !== null) return result; |
697 result = obj[_runtimeType]; | 707 result = obj[_runtimeType]; |
698 if (result) return result; | 708 if (result) return result; |
| 709 result = obj[_extensionType]; |
| 710 if (result) return result; |
699 result = obj.constructor; | 711 result = obj.constructor; |
700 if (result == Function) { | 712 if (result == Function) { |
701 return jsobject; | 713 return jsobject; |
702 } | 714 } |
703 return result; | 715 return result; |
704 } | 716 } |
705 function LazyTagged(infoFn) { | 717 function LazyTagged(infoFn) { |
706 class _Tagged { | 718 class _Tagged { |
707 get [_runtimeType]() { | 719 get [_runtimeType]() { |
708 return infoFn(); | 720 return infoFn(); |
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1192 exports.generic = generic; | 1204 exports.generic = generic; |
1193 exports.getGenericClass = getGenericClass; | 1205 exports.getGenericClass = getGenericClass; |
1194 exports.getGenericArgs = getGenericArgs; | 1206 exports.getGenericArgs = getGenericArgs; |
1195 exports.getMethodType = getMethodType; | 1207 exports.getMethodType = getMethodType; |
1196 exports.classGetConstructorType = classGetConstructorType; | 1208 exports.classGetConstructorType = classGetConstructorType; |
1197 exports.bind = bind; | 1209 exports.bind = bind; |
1198 exports.setSignature = setSignature; | 1210 exports.setSignature = setSignature; |
1199 exports.hasMethod = hasMethod; | 1211 exports.hasMethod = hasMethod; |
1200 exports.virtualField = virtualField; | 1212 exports.virtualField = virtualField; |
1201 exports.defineNamedConstructor = defineNamedConstructor; | 1213 exports.defineNamedConstructor = defineNamedConstructor; |
| 1214 exports.getExtensionType = getExtensionType; |
1202 exports.dartx = dartx; | 1215 exports.dartx = dartx; |
1203 exports.getExtensionSymbol = getExtensionSymbol; | 1216 exports.getExtensionSymbol = getExtensionSymbol; |
1204 exports.defineExtensionNames = defineExtensionNames; | 1217 exports.defineExtensionNames = defineExtensionNames; |
1205 exports.registerExtension = registerExtension; | 1218 exports.registerExtension = registerExtension; |
1206 exports.defineExtensionMembers = defineExtensionMembers; | 1219 exports.defineExtensionMembers = defineExtensionMembers; |
1207 exports.canonicalMember = canonicalMember; | 1220 exports.canonicalMember = canonicalMember; |
1208 exports.setType = setType; | 1221 exports.setType = setType; |
1209 exports.list = list; | 1222 exports.list = list; |
1210 exports.setBaseClass = setBaseClass; | 1223 exports.setBaseClass = setBaseClass; |
1211 exports.throwCastError = throwCastError; | 1224 exports.throwCastError = throwCastError; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1301 exports.copyProperties = copyProperties; | 1314 exports.copyProperties = copyProperties; |
1302 exports.export = export_; | 1315 exports.export = export_; |
1303 exports.defineLazyClass = defineLazyClass; | 1316 exports.defineLazyClass = defineLazyClass; |
1304 exports.defineLazyProperties = defineLazyProperties; | 1317 exports.defineLazyProperties = defineLazyProperties; |
1305 exports.defineLazyClassGeneric = defineLazyClassGeneric; | 1318 exports.defineLazyClassGeneric = defineLazyClassGeneric; |
1306 exports.as = as_; | 1319 exports.as = as_; |
1307 exports.is = is_; | 1320 exports.is = is_; |
1308 exports.global = global_; | 1321 exports.global = global_; |
1309 exports.JsSymbol = JsSymbol; | 1322 exports.JsSymbol = JsSymbol; |
1310 }); | 1323 }); |
OLD | NEW |