Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 // TODO(vsm): This is referenced (as init.globalState) from | 9 // TODO(vsm): This is referenced (as init.globalState) from |
| 10 // isolate_helper.dart. Where should it go? | 10 // isolate_helper.dart. Where should it go? |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 35 let r = argDecl[1].split(FN_ARG_SPLIT); | 35 let r = argDecl[1].split(FN_ARG_SPLIT); |
| 36 for (let arg of r) { | 36 for (let arg of r) { |
| 37 arg.replace(FN_ARG, function(all, underscore, name){ | 37 arg.replace(FN_ARG, function(all, underscore, name){ |
| 38 args.push(name); | 38 args.push(name); |
| 39 }); | 39 }); |
| 40 } | 40 } |
| 41 return args; | 41 return args; |
| 42 } | 42 } |
| 43 | 43 |
| 44 function dload(obj, field) { | 44 function dload(obj, field) { |
| 45 field = _canonicalFieldName(obj, field); | |
| 46 if (_getMethodType(obj, field) !== void 0) { | |
| 47 return dart.tearoff(obj, field); | |
| 48 } | |
| 45 // TODO(vsm): Implement NSM robustly. An 'in' check breaks on certain | 49 // TODO(vsm): Implement NSM robustly. An 'in' check breaks on certain |
| 46 // types. hasOwnProperty doesn't chase the proto chain. | 50 // types. hasOwnProperty doesn't chase the proto chain. |
| 47 // Also, do we want an NSM on regular JS objects? | 51 // Also, do we want an NSM on regular JS objects? |
| 48 // See: https://github.com/dart-lang/dev_compiler/issues/169 | 52 // See: https://github.com/dart-lang/dev_compiler/issues/169 |
| 49 var result = obj[field]; | 53 var result = obj[field]; |
| 50 | 54 |
| 51 // TODO(vsm): Check this more robustly. | 55 // TODO(leafp): Decide whether to keep this for javascript |
| 56 // objects, or just use the javascript semantics. | |
| 52 if (typeof result == "function" && | 57 if (typeof result == "function" && |
| 53 !Object.prototype.hasOwnProperty.call(obj, field)) { | 58 !Object.prototype.hasOwnProperty.call(obj, field)) { |
| 54 // This appears to be a method tearoff. Bind this. | 59 // This appears to be a method tearoff. Bind this. |
| 55 return result.bind(obj); | 60 return result.bind(obj); |
| 56 } | 61 } |
| 57 return result; | 62 return result; |
| 58 } | 63 } |
| 59 dart.dload = dload; | 64 dart.dload = dload; |
| 60 | 65 |
| 61 function dput(obj, field, value) { | 66 function dput(obj, field, value) { |
| 67 field = _canonicalFieldName(obj, field); | |
| 62 // TODO(vsm): Implement NSM and type checks. | 68 // TODO(vsm): Implement NSM and type checks. |
| 63 // See: https://github.com/dart-lang/dev_compiler/issues/170 | 69 // See: https://github.com/dart-lang/dev_compiler/issues/170 |
| 64 obj[field] = value; | 70 obj[field] = value; |
| 65 } | 71 } |
| 66 dart.dput = dput; | 72 dart.dput = dput; |
| 67 | 73 |
| 68 // TODO(jmesserly): this should call noSuchMethod, not throw. | 74 // TODO(jmesserly): this should call noSuchMethod, not throw. |
| 69 function throwNoSuchMethod(obj, name, args, opt_func) { | 75 function throwNoSuchMethod(obj, name, args, opt_func) { |
| 70 if (obj === void 0) obj = opt_func; | 76 if (obj === void 0) obj = opt_func; |
| 71 throw new core.NoSuchMethodError(obj, name, args); | 77 throw new core.NoSuchMethodError(obj, name, args); |
| 72 } | 78 } |
| 73 | 79 |
| 74 function checkAndCall(f, obj, args, name) { | 80 function checkAndCall(f, ftype, obj, args, name) { |
| 75 if (!(f instanceof Function)) { | 81 if (!(f instanceof Function)) { |
| 82 // We're not a function (and hence not a method either) | |
| 76 // Grab the `call` method if it's not a function. | 83 // Grab the `call` method if it's not a function. |
| 77 if (f !== null) f = f.call; | 84 if (f !== null) { |
| 85 f = f.call; | |
| 86 ftype = _getMethodType(f, 'call'); | |
| 87 } | |
| 78 if (!(f instanceof Function)) { | 88 if (!(f instanceof Function)) { |
| 79 throwNoSuchMethod(obj, name, args); | 89 throwNoSuchMethod(obj, name, args); |
| 80 } | 90 } |
| 81 } | 91 } |
| 82 // TODO(jmesserly): enable this when we can fix => and methods. | 92 // If f is a function, but not a method (no method type) |
| 83 /* | 93 // then it should have been a function valued field, so |
| 84 let formals = formalParameterList(f); | 94 // get the type from the function. |
| 85 // TODO(vsm): Type check args! We need to encode sufficient type info on f. | 95 if (ftype === void 0) { |
| 86 if (formals.length < args.length) { | 96 ftype = _getFunctionType(f); |
| 87 throwNoSuchMethod(obj, name, args, f); | |
| 88 } else if (formals.length > args.length) { | |
| 89 for (let i = args.length; i < formals.length; ++i) { | |
| 90 if (formals[i].indexOf("opt$") != 0) { | |
| 91 throwNoSuchMethod(obj, name, args, f); | |
| 92 } | |
| 93 } | |
| 94 } | 97 } |
| 95 */ | 98 assert(ftype); |
| 96 return f.apply(obj, args); | 99 |
| 100 if (ftype.checkApply(args)) return f.apply(obj, args); | |
|
vsm
2015/05/18 17:35:10
A TODO here to throw the right error? If arity ma
Leaf
2015/05/19 00:02:20
Done.
| |
| 101 | |
| 102 throwNoSuchMethod(obj, name, args, f); | |
| 97 } | 103 } |
| 98 | 104 |
| 99 function dcall(f/*, ...args*/) { | 105 function dcall(f/*, ...args*/) { |
| 100 let args = Array.prototype.slice.call(arguments, 1); | 106 let args = Array.prototype.slice.call(arguments, 1); |
| 101 return checkAndCall(f, void 0, args, 'call'); | 107 let ftype = _getFunctionType(f); |
| 108 return checkAndCall(f, ftype, void 0, args, 'call'); | |
| 102 } | 109 } |
| 103 dart.dcall = dcall; | 110 dart.dcall = dcall; |
| 104 | 111 |
| 105 // TODO(vsm): Automatically build this. | 112 // TODO(vsm): Automatically build this. |
| 106 // All dynamic methods should check for these. | 113 // All dynamic methods should check for these. |
| 107 // See: https://github.com/dart-lang/dev_compiler/issues/142 | 114 // See: https://github.com/dart-lang/dev_compiler/issues/142 |
| 108 var _extensionMethods = { | 115 var _extensionMethods = { |
| 109 // Lazy - as these symbols may not be loaded yet. | 116 // Lazy - as these symbols may not be loaded yet. |
| 110 // TODO(vsm): This should record / check the receiver type | 117 // TODO(vsm): This should record / check the receiver type |
| 111 // as well. E.g., only look for core.$map if the receiver | 118 // as well. E.g., only look for core.$map if the receiver |
| 112 // is an Iterable. | 119 // is an Iterable. |
| 113 'map': () => core.$map, | 120 'map': () => core.$map, |
| 114 }; | 121 }; |
| 115 | 122 |
| 123 // TODO(leafp): Integrate this with the eventual proper extension | |
| 124 // method system. | |
| 125 function _canonicalFieldName(obj, name) { | |
| 126 if (obj[field] === void 0) return _extensionMethods[name](); | |
| 127 return name; | |
| 128 } | |
| 129 | |
| 116 function dsend(obj, method/*, ...args*/) { | 130 function dsend(obj, method/*, ...args*/) { |
| 117 let args = Array.prototype.slice.call(arguments, 2); | 131 let args = Array.prototype.slice.call(arguments, 2); |
| 118 var f = obj[method]; | 132 let symbol = _canonicalFieldName(obj, method); |
| 119 if (f === void 0) { | 133 let f = obj[symbol]; |
| 120 var symbol = _extensionMethods[method](); | 134 let ftype = _getMethodType(obj, symbol); |
| 121 f = obj[symbol]; | 135 return checkAndCall(f, ftype, obj, args, method); |
| 122 } | |
| 123 return checkAndCall(f, obj, args, method); | |
| 124 } | 136 } |
| 125 dart.dsend = dsend; | 137 dart.dsend = dsend; |
| 126 | 138 |
| 127 function dindex(obj, index) { | 139 function dindex(obj, index) { |
| 128 // TODO(jmesserly): remove this special case once Array extensions are | 140 // TODO(jmesserly): remove this special case once Array extensions are |
| 129 // hooked up. | 141 // hooked up. |
| 130 if (obj instanceof Array && realRuntimeType(index) == core.int) { | 142 if (obj instanceof Array && realRuntimeType(index) == core.int) { |
| 131 return obj[index]; | 143 return obj[index]; |
| 132 } | 144 } |
| 133 return checkAndCall(obj.get, obj, [index], '[]'); | 145 return checkAndCall(obj.get, obj, [index], '[]'); |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 437 dart.equals = equals; | 449 dart.equals = equals; |
| 438 | 450 |
| 439 /** Checks that `x` is not null or undefined. */ | 451 /** Checks that `x` is not null or undefined. */ |
| 440 function notNull(x) { | 452 function notNull(x) { |
| 441 if (x == null) throw 'expected not-null value'; | 453 if (x == null) throw 'expected not-null value'; |
| 442 return x; | 454 return x; |
| 443 } | 455 } |
| 444 dart.notNull = notNull; | 456 dart.notNull = notNull; |
| 445 | 457 |
| 446 function _typeName(type) { | 458 function _typeName(type) { |
| 459 if (type === void 0) throw "Undefined type"; | |
| 447 var name = type.name; | 460 var name = type.name; |
| 448 if (!name) throw 'Unexpected type: ' + type; | 461 if (!name) throw 'Unexpected type: ' + type; |
| 449 return name; | 462 return name; |
| 450 } | 463 } |
| 451 | 464 |
| 452 class AbstractFunctionType { | 465 class AbstractFunctionType { |
| 453 constructor() { | 466 constructor() { |
| 454 this._stringValue = null; | 467 this._stringValue = null; |
| 455 } | 468 } |
| 456 | 469 |
| 470 /// Check that a function of this type can be applied to | |
| 471 /// actuals. | |
| 472 checkApply(actuals) { | |
| 473 if (actuals.length < this.args.length) return false; | |
| 474 var index = 0; | |
| 475 for(let i = 0; i < this.args.length; ++i) { | |
| 476 let t = realRuntimeType(actuals[i]); | |
| 477 if (!isSubtype(t, this.args[i])) return false; | |
| 478 ++index; | |
| 479 } | |
| 480 if (actuals.length == this.args.length) return true; | |
| 481 let extras = actuals.length - this.args.length; | |
| 482 if (this.optionals.length > 0) { | |
| 483 if (extras > this.optionals.length) return false; | |
| 484 for(let i = 0; i < extras; ++i) { | |
| 485 let t = realRuntimeType(actuals[index + i]); | |
| 486 if (!isSubtype(t, this.optionals[i])) return false; | |
| 487 } | |
| 488 return true; | |
| 489 } | |
| 490 // TODO(leafp): We can't tell when someone might be calling | |
| 491 // something expecting an optional argument with named arguments | |
| 492 | |
| 493 if (extras != 1) return false; | |
| 494 // An empty named list means no named arguments | |
| 495 if (getOwnPropertyNames(this.named).length == 0) return false; | |
| 496 let opts = actuals[index]; | |
| 497 let names = getOwnPropertyNames(opts); | |
| 498 // This is something other than a map | |
| 499 if (names.length == 0) return false; | |
| 500 for (name of names) { | |
| 501 if (!(Object.prototype.hasOwnProperty.call(this.named, name))) { | |
| 502 return false; | |
| 503 } | |
| 504 let t = realRuntimeType(opts[name]); | |
| 505 if (!isSubtype(t, this.named[name])) return false; | |
| 506 } | |
| 507 return true; | |
| 508 } | |
| 509 | |
| 457 get name() { | 510 get name() { |
| 458 if (this._stringValue) return this._stringValue; | 511 if (this._stringValue) return this._stringValue; |
| 459 | 512 |
| 460 var buffer = '('; | 513 var buffer = '('; |
| 461 for (let i = 0; i < this.args.length; ++i) { | 514 for (let i = 0; i < this.args.length; ++i) { |
| 462 if (i > 0) { | 515 if (i > 0) { |
| 463 buffer += ', '; | 516 buffer += ', '; |
| 464 } | 517 } |
| 465 buffer += _typeName(this.args[i]); | 518 buffer += _typeName(this.args[i]); |
| 466 } | 519 } |
| 467 if (this.optionals.length > 0) { | 520 if (this.optionals.length > 0) { |
| 468 if (this.args.length > 0) buffer += ', '; | 521 if (this.args.length > 0) buffer += ', '; |
| 469 buffer += '['; | 522 buffer += '['; |
| 470 for (let i = 0; i < this.optionals.length; ++i) { | 523 for (let i = 0; i < this.optionals.length; ++i) { |
| 471 if (i > 0) { | 524 if (i > 0) { |
| 472 buffer += ', '; | 525 buffer += ', '; |
| 473 } | 526 } |
| 474 buffer += _typeName(this.optionals[i]); | 527 buffer += _typeName(this.optionals[i]); |
| 475 } | 528 } |
| 476 buffer += ']'; | 529 buffer += ']'; |
| 477 } else if (this.named.length > 0) { | 530 } else if (Object.keys(this.named).length > 0) { |
| 478 if (this.args.length > 0) buffer += ', '; | 531 if (this.args.length > 0) buffer += ', '; |
| 479 buffer += '{'; | 532 buffer += '{'; |
| 480 let names = getOwnPropertyNames(this.named).sort(); | 533 let names = getOwnPropertyNames(this.named).sort(); |
| 481 for (let i = 0; i < names.length; ++i) { | 534 for (let i = 0; i < names.length; ++i) { |
| 482 if (i > 0) { | 535 if (i > 0) { |
| 483 buffer += ', '; | 536 buffer += ', '; |
| 484 } | 537 } |
| 485 buffer += names[i] + ': ' + _typeName(this.named[names[i]]); | 538 buffer += names[i] + ': ' + _typeName(this.named[names[i]]); |
| 486 } | 539 } |
| 487 buffer += '}'; | 540 buffer += '}'; |
| 488 } | 541 } |
| 489 | 542 |
| 490 buffer += ') -> ' + _typeName(this.returnType); | 543 buffer += ') -> ' + _typeName(this.returnType); |
| 491 this._stringValue = buffer; | 544 this._stringValue = buffer; |
| 492 return buffer; | 545 return buffer; |
| 493 } | 546 } |
| 494 } | 547 } |
| 495 | 548 |
| 496 class FunctionType extends AbstractFunctionType { | 549 class FunctionType extends AbstractFunctionType { |
| 497 constructor(returnType, args, optionals, named) { | 550 constructor(returnType, args, optionals, named) { |
| 498 super(); | 551 super(); |
| 499 this.returnType = returnType; | 552 this.returnType = returnType; |
| 500 this.args = args; | 553 this.args = args; |
| 501 this.optionals = optionals; | 554 this.optionals = optionals; |
| 502 this.named = named; | 555 this.named = named; |
| 503 } | 556 } |
| 504 } | 557 } |
| 505 | 558 |
| 559 /// Tag a closure with a type, using one of three forms: | |
| 560 /// dart.fn(cls) marks cls has having no optional or named | |
| 561 /// parameters, with all argument and return types as dynamic | |
| 562 /// dart.fn(cls, func) marks cls with the lazily computed | |
| 563 /// runtime type as computed by func() | |
| 564 /// dart.fn(cls, rType, argsT, extras) marks cls as having the | |
| 565 /// runtime type dart.functionType(rType, argsT, extras) | |
| 566 function fn(closure/* ...args*/) { | |
| 567 // Closure and a lazy type constructor | |
| 568 if (arguments.length == 2) { | |
| 569 defineLazyProperty(closure, _runtimeType, {get : arguments[1]}); | |
| 570 return closure; | |
| 571 } | |
| 572 var t; | |
| 573 if (arguments.length == 1) { | |
| 574 // No type arguments, it's all dynamic | |
| 575 let len = closure.length; | |
| 576 let args = Array.apply(null, new Array(len)).map(() => dart.dynamic); | |
| 577 t = functionType(dart.dynamic, args); | |
| 578 } else { | |
| 579 // We're passed the piecewise components of the function type, | |
| 580 // construct it. | |
| 581 let args = Array.prototype.slice.call(arguments, 1); | |
| 582 t = functionType.apply(functionType, args); | |
| 583 } | |
| 584 setRuntimeType(closure, t); | |
| 585 return closure; | |
| 586 } | |
| 587 dart.fn = fn; | |
| 588 | |
| 506 function functionType(returnType, args, extra) { | 589 function functionType(returnType, args, extra) { |
| 507 // TODO(vsm): Cache / memomize? | 590 // TODO(vsm): Cache / memomize? |
| 508 var optionals; | 591 var optionals; |
| 509 var named; | 592 var named; |
| 510 if (extra === void 0) { | 593 if (extra === void 0) { |
| 511 optionals = []; | 594 optionals = []; |
| 512 named = {}; | 595 named = {}; |
| 513 } else if (extra instanceof Array) { | 596 } else if (extra instanceof Array) { |
| 514 optionals = extra; | 597 optionals = extra; |
| 515 named = {}; | 598 named = {}; |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 771 } | 854 } |
| 772 // Run base initializer. | 855 // Run base initializer. |
| 773 let init = base.prototype[base.name]; | 856 let init = base.prototype[base.name]; |
| 774 if (init) init.apply(this, arguments); | 857 if (init) init.apply(this, arguments); |
| 775 } | 858 } |
| 776 } | 859 } |
| 777 // Copy each mixin's methods, with later ones overwriting earlier entries. | 860 // Copy each mixin's methods, with later ones overwriting earlier entries. |
| 778 for (let m of mixins) { | 861 for (let m of mixins) { |
| 779 copyProperties(Mixin.prototype, m.prototype); | 862 copyProperties(Mixin.prototype, m.prototype); |
| 780 } | 863 } |
| 864 | |
| 865 // Set the signature of the Mixin class to be the composition | |
| 866 // of the signatures of the mixins. | |
| 867 dart.setSignature(Mixin, { | |
| 868 methods : () => { | |
| 869 let s = {}; | |
| 870 for (let m of mixins) { | |
|
Jennifer Messerly
2015/05/19 18:19:01
this should be reverse order right? e.g.
class Ba
Leaf
2015/05/19 22:31:12
I don't think so, but could be wrong. This is mir
Jennifer Messerly
2015/05/19 22:49:48
ah, right, later ones should overwrite. I think th
| |
| 871 copyProperties(s, m[dart.sig]); | |
| 872 } | |
| 873 return s; | |
| 874 }, | |
| 875 statics : () => {}, // statics are not inherited | |
|
Jennifer Messerly
2015/05/19 18:19:01
these could be skipped right? as setSignature igno
Leaf
2015/05/19 22:31:12
Done.
| |
| 876 names : [], | |
| 877 }); | |
| 878 | |
| 781 // Save mixins for reflection | 879 // Save mixins for reflection |
| 782 Mixin[dart.mixins] = mixins; | 880 Mixin[dart.mixins] = mixins; |
| 783 return Mixin; | 881 return Mixin; |
| 784 } | 882 } |
| 785 dart.mixin = mixin; | 883 dart.mixin = mixin; |
| 786 | 884 |
| 787 /** | 885 /** |
| 788 * Creates a dart:collection LinkedHashMap. | 886 * Creates a dart:collection LinkedHashMap. |
| 789 * | 887 * |
| 790 * For a map with string keys an object literal can be used, for example | 888 * For a map with string keys an object literal can be used, for example |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 882 } | 980 } |
| 883 map.set(arg, value); | 981 map.set(arg, value); |
| 884 } | 982 } |
| 885 } | 983 } |
| 886 return value; | 984 return value; |
| 887 } | 985 } |
| 888 return makeGenericType; | 986 return makeGenericType; |
| 889 } | 987 } |
| 890 dart.generic = generic; | 988 dart.generic = generic; |
| 891 | 989 |
| 990 dart.sig = Symbol("sig"); | |
| 991 dart._sig = Symbol("_sig"); | |
|
Jennifer Messerly
2015/05/19 18:19:01
are all of these needed from generated code? If no
Leaf
2015/05/19 22:31:12
Done.
| |
| 992 dart.sigStatic = Symbol("sigStatic"); | |
| 993 dart._sigStatic = Symbol("_sigStatic"); | |
| 994 | |
| 995 /// Get the type of a function using the store runtime type | |
| 996 function _getFunctionType(f) { | |
| 997 return f[_runtimeType]; | |
| 998 } | |
| 999 | |
| 1000 /// Get the type of a method using the stored signature | |
| 1001 function _getMethodType(obj, name) { | |
| 1002 if (obj === void 0) return void 0; | |
| 1003 if (obj == null) return void 0; | |
| 1004 let sigObj = obj.__proto__.constructor[dart.sig]; | |
| 1005 if (sigObj === void 0) return void 0; | |
| 1006 let sig = sigObj[name]; | |
| 1007 return sig; | |
| 1008 } | |
| 1009 | |
| 1010 /// Given an object and a method name, tear off the method. | |
| 1011 /// Sets the runtime type of the torn off method appropriately, | |
| 1012 /// and also binds the object. | |
| 1013 /// TODO(leafp): Consider caching the tearoff on the object? | |
| 1014 function tearoff(obj, name) { | |
| 1015 let f = obj[name].bind(obj); | |
| 1016 let sig = _getMethodType(obj, name) | |
| 1017 assert(sig); | |
| 1018 setRuntimeType(f, sig); | |
| 1019 return f; | |
| 1020 } | |
| 1021 dart.tearoff = tearoff; | |
| 1022 | |
| 1023 // Set up the method signature field on the constructor | |
| 1024 function _setMethodSignature(f, sigF) { | |
|
Jennifer Messerly
2015/05/19 18:19:01
could this function just be:
defineLazyGetter(f,
Leaf
2015/05/19 22:31:12
Done.
| |
| 1025 f[dart._sig] = null; | |
|
Jennifer Messerly
2015/05/19 18:19:01
could this just be a closed over local?
let sigOb
Leaf
2015/05/19 22:31:12
Oh yeah, nice! Factored out into a helper per pre
| |
| 1026 function getter() { | |
| 1027 if (f[dart._sig] != null) return f[dart._sig]; | |
| 1028 let sigObj = sigF(); | |
| 1029 sigObj.__proto__ = f.__proto__[dart.sig]; | |
| 1030 f[dart._sig] = sigObj; | |
| 1031 return sigObj; | |
| 1032 } | |
| 1033 defineProperty(f, dart.sig, {get : getter}) | |
| 1034 } | |
| 1035 | |
| 1036 // Set up the static signature field on the constructor | |
| 1037 function _setStaticSignature(f, sigF) { | |
| 1038 f[dart._sigStatic] = null; | |
| 1039 function getter() { | |
| 1040 if (f[dart._sigStatic] != null) return f[dart._sigStatic]; | |
| 1041 let sigObj = sigF(); | |
| 1042 f[dart._sigStatic] = sigObj; | |
| 1043 return sigObj; | |
| 1044 } | |
| 1045 defineProperty(f, dart.sigStatic, {get : getter}) | |
| 1046 } | |
| 1047 | |
| 1048 // Set the lazily computed runtime type field on static methods | |
| 1049 function _setStaticTypes(f, names) { | |
| 1050 for (let name of names) { | |
| 1051 function getT() { return f[dart.sigStatic][name];}; | |
| 1052 defineProperty(f[name], _runtimeType, {get : getT}); | |
| 1053 } | |
| 1054 } | |
| 1055 | |
| 1056 /// Set up the type signature of a class (constructor object) | |
| 1057 /// f is a constructor object | |
| 1058 /// signature is an object containing optional properties as follows: | |
| 1059 /// methods: A function returning an object mapping method names | |
| 1060 /// to method types. The function is evaluated lazily and cached. | |
| 1061 /// statics: A function returning an object mapping static method | |
| 1062 /// names to types. The function is evalutated lazily and cached. | |
| 1063 /// names: An array of the names of the static methods. Used to | |
| 1064 /// permit eagerly setting the runtimeType field on the methods | |
| 1065 /// while still lazily computing the type descriptor object. | |
| 1066 function setSignature(f, signature) { | |
| 1067 let methods = | |
| 1068 ('methods' in signature) ? signature.methods : () => ({}); | |
| 1069 let statics = | |
| 1070 ('statics' in signature) ? signature.statics : () => ({}); | |
| 1071 let names = | |
| 1072 ('names' in signature) ? signature.names : []; | |
| 1073 _setMethodSignature(f, methods); | |
| 1074 _setStaticSignature(f, statics); | |
| 1075 _setStaticTypes(f, names); | |
| 1076 }; | |
| 1077 dart.setSignature = setSignature; | |
| 1078 | |
| 892 let _value = Symbol('_value'); | 1079 let _value = Symbol('_value'); |
| 893 /** | 1080 /** |
| 894 * Looks up a sequence of [keys] in [map], recursively, and | 1081 * Looks up a sequence of [keys] in [map], recursively, and |
| 895 * returns the result. If the value is not found, [valueFn] will be called to | 1082 * returns the result. If the value is not found, [valueFn] will be called to |
| 896 * add it. For example: | 1083 * add it. For example: |
| 897 * | 1084 * |
| 898 * var map = new Map(); | 1085 * var map = new Map(); |
| 899 * putIfAbsent(map, [1, 2, 'hi ', 'there '], () => 'world'); | 1086 * putIfAbsent(map, [1, 2, 'hi ', 'there '], () => 'world'); |
| 900 * | 1087 * |
| 901 * ... will create a Map with a structure like: | 1088 * ... will create a Map with a structure like: |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1019 next() { | 1206 next() { |
| 1020 let i = this.dartIterator; | 1207 let i = this.dartIterator; |
| 1021 var done = !i.moveNext(); | 1208 var done = !i.moveNext(); |
| 1022 return { done: done, value: done ? void 0 : i.current }; | 1209 return { done: done, value: done ? void 0 : i.current }; |
| 1023 } | 1210 } |
| 1024 } | 1211 } |
| 1025 dart.JsIterator = JsIterator; | 1212 dart.JsIterator = JsIterator; |
| 1026 | 1213 |
| 1027 // TODO(jmesserly): right now this is a sentinel. It should be a type object | 1214 // TODO(jmesserly): right now this is a sentinel. It should be a type object |
| 1028 // of some sort, assuming we keep around `dynamic` at runtime. | 1215 // of some sort, assuming we keep around `dynamic` at runtime. |
| 1029 dart.dynamic = { toString() { return 'dynamic'; } }; | 1216 dart.dynamic = { toString() { return 'dynamic'; }, get name() {return toString ();}}; |
| 1030 dart.void = { toString() { return 'void'; } }; | 1217 dart.void = { toString() { return 'void'; }, get name() {return toString();}}; |
| 1031 dart.bottom = { toString() { return 'bottom'; } }; | 1218 dart.bottom = { toString() { return 'bottom'; }, get name() {return toString() ;}}; |
| 1032 | 1219 |
| 1033 dart.global = window || global; | 1220 dart.global = window || global; |
| 1034 dart.JsSymbol = Symbol; | 1221 dart.JsSymbol = Symbol; |
| 1035 | 1222 |
| 1036 function import_(value) { | 1223 function import_(value) { |
| 1037 // TODO(vsm): Change this to a hard throw. | 1224 // TODO(vsm): Change this to a hard throw. |
| 1038 // For now, we're missing some libraries. E.g., dart:js: | 1225 // For now, we're missing some libraries. E.g., dart:js: |
| 1039 // https://github.com/dart-lang/dev_compiler/issues/168 | 1226 // https://github.com/dart-lang/dev_compiler/issues/168 |
| 1040 if (!value) { | 1227 if (!value) { |
| 1041 console.log('missing required module'); | 1228 console.log('missing required module'); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1095 Number.prototype['>'] = function(arg) { return this.valueOf() > arg; }; | 1282 Number.prototype['>'] = function(arg) { return this.valueOf() > arg; }; |
| 1096 Number.prototype['+'] = function(arg) { return this.valueOf() + arg; }; | 1283 Number.prototype['+'] = function(arg) { return this.valueOf() + arg; }; |
| 1097 | 1284 |
| 1098 // TODO(vsm): DOM facades? | 1285 // TODO(vsm): DOM facades? |
| 1099 // See: https://github.com/dart-lang/dev_compiler/issues/173 | 1286 // See: https://github.com/dart-lang/dev_compiler/issues/173 |
| 1100 NodeList.prototype.get = function(i) { return this[i]; }; | 1287 NodeList.prototype.get = function(i) { return this[i]; }; |
| 1101 NamedNodeMap.prototype.get = function(i) { return this[i]; }; | 1288 NamedNodeMap.prototype.get = function(i) { return this[i]; }; |
| 1102 DOMTokenList.prototype.get = function(i) { return this[i]; }; | 1289 DOMTokenList.prototype.get = function(i) { return this[i]; }; |
| 1103 | 1290 |
| 1104 })(dart || (dart = {})); | 1291 })(dart || (dart = {})); |
| OLD | NEW |