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

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

Issue 1076883003: Initial support for runtime function types and type checking (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: uncomment code Created 5 years, 8 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 var _js_helper; 1 var _js_helper;
2 (function(exports) { 2 (function(exports) {
3 'use strict'; 3 'use strict';
4 class NoSideEffects extends core.Object { 4 class NoSideEffects extends core.Object {
5 NoSideEffects() { 5 NoSideEffects() {
6 } 6 }
7 } 7 }
8 class NoThrows extends core.Object { 8 class NoThrows extends core.Object {
9 NoThrows() { 9 NoThrows() {
10 } 10 }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 let keys = this[_keys]; 95 let keys = this[_keys];
96 for (let i = 0; i['<'](dart.dload(keys, 'length')); i = dart.notNull(i) + 1) { 96 for (let i = 0; i['<'](dart.dload(keys, 'length')); i = dart.notNull(i) + 1) {
97 let key = dart.dindex(keys, i); 97 let key = dart.dindex(keys, i);
98 f(dart.as(key, K), dart.as(this[_fetch](key), V)); 98 f(dart.as(key, K), dart.as(this[_fetch](key), V));
99 } 99 }
100 } 100 }
101 get keys() { 101 get keys() {
102 return new (_ConstantMapKeyIterable$(K))(this); 102 return new (_ConstantMapKeyIterable$(K))(this);
103 } 103 }
104 get values() { 104 get values() {
105 return new (_internal.MappedIterable$(K, V))(this[_keys], dart.as(((key) => this[_fetch](key)).bind(this), dart.throw_("Unimplemented type (K) → V"))); 105 return new (_internal.MappedIterable$(K, V))(this[_keys], dart.as(((key) => this[_fetch](key)).bind(this), dart.functionType(V, [K])));
106 } 106 }
107 } 107 }
108 ConstantStringMap[dart.implements] = () => [_internal.EfficientLength]; 108 ConstantStringMap[dart.implements] = () => [_internal.EfficientLength];
109 dart.defineNamedConstructor(ConstantStringMap, _$); 109 dart.defineNamedConstructor(ConstantStringMap, _$);
110 return ConstantStringMap; 110 return ConstantStringMap;
111 }); 111 });
112 let ConstantStringMap = ConstantStringMap$(); 112 let ConstantStringMap = ConstantStringMap$();
113 let _protoValue = Symbol('_protoValue'); 113 let _protoValue = Symbol('_protoValue');
114 let ConstantProtoMap$ = dart.generic(function(K, V) { 114 let ConstantProtoMap$ = dart.generic(function(K, V) {
115 class ConstantProtoMap extends ConstantStringMap$(K, V) { 115 class ConstantProtoMap extends ConstantStringMap$(K, V) {
(...skipping 1610 matching lines...) Expand 10 before | Expand all | Expand 10 after
1726 hash = Math.random() * 0x3fffffff | 0; 1726 hash = Math.random() * 0x3fffffff | 0;
1727 object.$identityHash = hash; 1727 object.$identityHash = hash;
1728 } 1728 }
1729 return hash; 1729 return hash;
1730 } 1730 }
1731 static [_throwFormatException](string) { 1731 static [_throwFormatException](string) {
1732 throw new core.FormatException(string); 1732 throw new core.FormatException(string);
1733 } 1733 }
1734 static parseInt(source, radix, handleError) { 1734 static parseInt(source, radix, handleError) {
1735 if (handleError == null) 1735 if (handleError == null)
1736 handleError = dart.as(Primitives[_throwFormatException], dart.throw_("Un implemented type (String) → int")); 1736 handleError = dart.as(Primitives[_throwFormatException], dart.functionTy pe(core.int, [core.String]));
1737 checkString(source); 1737 checkString(source);
1738 let match = /^\s*[+-]?((0x[a-f0-9]+)|(\d+)|([a-z0-9]+))\s*$/i.exec(source) ; 1738 let match = /^\s*[+-]?((0x[a-f0-9]+)|(\d+)|([a-z0-9]+))\s*$/i.exec(source) ;
1739 let digitsIndex = 1; 1739 let digitsIndex = 1;
1740 let hexIndex = 2; 1740 let hexIndex = 2;
1741 let decimalIndex = 3; 1741 let decimalIndex = 3;
1742 let nonDecimalHexIndex = 4; 1742 let nonDecimalHexIndex = 4;
1743 if (radix == null) { 1743 if (radix == null) {
1744 radix = 10; 1744 radix = 10;
1745 if (match != null) { 1745 if (match != null) {
1746 if (dart.dindex(match, hexIndex) != null) { 1746 if (dart.dindex(match, hexIndex) != null) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1778 } 1778 }
1779 } 1779 }
1780 } 1780 }
1781 if (match == null) 1781 if (match == null)
1782 return handleError(source); 1782 return handleError(source);
1783 return parseInt(source, radix); 1783 return parseInt(source, radix);
1784 } 1784 }
1785 static parseDouble(source, handleError) { 1785 static parseDouble(source, handleError) {
1786 checkString(source); 1786 checkString(source);
1787 if (handleError == null) 1787 if (handleError == null)
1788 handleError = dart.as(Primitives[_throwFormatException], dart.throw_("Un implemented type (String) → double")); 1788 handleError = dart.as(Primitives[_throwFormatException], dart.functionTy pe(core.double, [core.String]));
1789 if (!/^\s*[+-]?(?:Infinity|NaN|(?:\.\d+|\d+(?:\.\d*)?)(?:[eE][+-]?\d+)?)\s *$/.test(source)) { 1789 if (!/^\s*[+-]?(?:Infinity|NaN|(?:\.\d+|\d+(?:\.\d*)?)(?:[eE][+-]?\d+)?)\s *$/.test(source)) {
1790 return handleError(source); 1790 return handleError(source);
1791 } 1791 }
1792 let result = parseFloat(source); 1792 let result = parseFloat(source);
1793 if (result.isNaN) { 1793 if (result.isNaN) {
1794 let trimmed = source.trim(); 1794 let trimmed = source.trim();
1795 if (dart.notNull(trimmed == 'NaN') || dart.notNull(trimmed == '+NaN') || dart.notNull(trimmed == '-NaN')) { 1795 if (dart.notNull(trimmed == 'NaN') || dart.notNull(trimmed == '+NaN') || dart.notNull(trimmed == '-NaN')) {
1796 return result; 1796 return result;
1797 } 1797 }
1798 return handleError(source); 1798 return handleError(source);
(...skipping 1841 matching lines...) Expand 10 before | Expand all | Expand 10 after
3640 } 3640 }
3641 // Function jsonEncodeNative: (String) → String 3641 // Function jsonEncodeNative: (String) → String
3642 function jsonEncodeNative(string) { 3642 function jsonEncodeNative(string) {
3643 return JSON.stringify(string); 3643 return JSON.stringify(string);
3644 } 3644 }
3645 // Function getIsolateAffinityTag: (String) → String 3645 // Function getIsolateAffinityTag: (String) → String
3646 function getIsolateAffinityTag(name) { 3646 function getIsolateAffinityTag(name) {
3647 let isolateTagGetter = _foreign_helper.JS_EMBEDDED_GLOBAL('', _js_embedded_n ames.GET_ISOLATE_TAG); 3647 let isolateTagGetter = _foreign_helper.JS_EMBEDDED_GLOBAL('', _js_embedded_n ames.GET_ISOLATE_TAG);
3648 return isolateTagGetter(name); 3648 return isolateTagGetter(name);
3649 } 3649 }
3650 class LoadLibraryFunctionType extends core.Function {} 3650 let LoadLibraryFunctionType = dart.typedef('LoadLibraryFunctionType', () => da rt.functionType(async.Future$(core.Null), []));
3651 // Function _loadLibraryWrapper: (String) → () → Future<Null> 3651 // Function _loadLibraryWrapper: (String) → () → Future<Null>
3652 function _loadLibraryWrapper(loadId) { 3652 function _loadLibraryWrapper(loadId) {
3653 return () => loadDeferredLibrary(loadId); 3653 return () => loadDeferredLibrary(loadId);
3654 } 3654 }
3655 dart.defineLazyProperties(exports, { 3655 dart.defineLazyProperties(exports, {
3656 get _loadingLibraries() { 3656 get _loadingLibraries() {
3657 return dart.map(); 3657 return dart.map();
3658 }, 3658 },
3659 get _loadedLibraries() { 3659 get _loadedLibraries() {
3660 return new (core.Set$(core.String))(); 3660 return new (core.Set$(core.String))();
3661 } 3661 }
3662 }); 3662 });
3663 class DeferredLoadCallback extends core.Function {} 3663 let DeferredLoadCallback = dart.typedef('DeferredLoadCallback', () => dart.fun ctionType(dart.void, []));
3664 exports.deferredLoadHook = null; 3664 exports.deferredLoadHook = null;
3665 // Function loadDeferredLibrary: (String) → Future<Null> 3665 // Function loadDeferredLibrary: (String) → Future<Null>
3666 function loadDeferredLibrary(loadId) { 3666 function loadDeferredLibrary(loadId) {
3667 let urisMap = _foreign_helper.JS_EMBEDDED_GLOBAL('', _js_embedded_names.DEFE RRED_LIBRARY_URIS); 3667 let urisMap = _foreign_helper.JS_EMBEDDED_GLOBAL('', _js_embedded_names.DEFE RRED_LIBRARY_URIS);
3668 let uris = dart.as(urisMap[loadId], core.List$(core.String)); 3668 let uris = dart.as(urisMap[loadId], core.List$(core.String));
3669 let hashesMap = _foreign_helper.JS_EMBEDDED_GLOBAL('', _js_embedded_names.DE FERRED_LIBRARY_HASHES); 3669 let hashesMap = _foreign_helper.JS_EMBEDDED_GLOBAL('', _js_embedded_names.DE FERRED_LIBRARY_HASHES);
3670 let hashes = dart.as(hashesMap[loadId], core.List$(core.String)); 3670 let hashes = dart.as(hashesMap[loadId], core.List$(core.String));
3671 if (uris == null) 3671 if (uris == null)
3672 return dart.as(new async.Future.value(null), async.Future$(core.Null)); 3672 return dart.as(new async.Future.value(null), async.Future$(core.Null));
3673 let indices = dart.as(new core.List.generate(uris[core.$length], dart.as((i) => i, dart.throw_("Unimplemented type (int) → dynamic"))), core.List$(core.int) ); 3673 let indices = dart.as(new core.List.generate(uris[core.$length], dart.as((i) => i, dart.functionType(dynamic, [core.int]))), core.List$(core.int));
3674 let isHunkLoaded = _foreign_helper.JS_EMBEDDED_GLOBAL('', _js_embedded_names .IS_HUNK_LOADED); 3674 let isHunkLoaded = _foreign_helper.JS_EMBEDDED_GLOBAL('', _js_embedded_names .IS_HUNK_LOADED);
3675 let isHunkInitialized = _foreign_helper.JS_EMBEDDED_GLOBAL('', _js_embedded_ names.IS_HUNK_INITIALIZED); 3675 let isHunkInitialized = _foreign_helper.JS_EMBEDDED_GLOBAL('', _js_embedded_ names.IS_HUNK_INITIALIZED);
3676 let indicesToLoad = indices[core.$where]((i) => !isHunkLoaded(hashes[core.$g et](i)))[core.$toList](); 3676 let indicesToLoad = indices[core.$where]((i) => !isHunkLoaded(hashes[core.$g et](i)))[core.$toList]();
3677 return dart.as(async.Future.wait(dart.as(indicesToLoad[core.$map]((i) => _lo adHunk(uris[core.$get](i))), core.Iterable$(async.Future))).then(dart.as((_) => { 3677 return dart.as(async.Future.wait(dart.as(indicesToLoad[core.$map]((i) => _lo adHunk(uris[core.$get](i))), core.Iterable$(async.Future))).then(dart.as((_) => {
3678 let indicesToInitialize = indices[core.$where]((i) => !isHunkInitialized(h ashes[core.$get](i)))[core.$toList](); 3678 let indicesToInitialize = indices[core.$where]((i) => !isHunkInitialized(h ashes[core.$get](i)))[core.$toList]();
3679 for (let i of indicesToInitialize) { 3679 for (let i of indicesToInitialize) {
3680 let initializer = _foreign_helper.JS_EMBEDDED_GLOBAL('', _js_embedded_na mes.INITIALIZE_LOADED_HUNK); 3680 let initializer = _foreign_helper.JS_EMBEDDED_GLOBAL('', _js_embedded_na mes.INITIALIZE_LOADED_HUNK);
3681 initializer(hashes[core.$get](i)); 3681 initializer(hashes[core.$get](i));
3682 } 3682 }
3683 let updated = exports._loadedLibraries.add(loadId); 3683 let updated = exports._loadedLibraries.add(loadId);
3684 if (dart.notNull(updated) && dart.notNull(exports.deferredLoadHook != null )) { 3684 if (dart.notNull(updated) && dart.notNull(exports.deferredLoadHook != null )) {
3685 exports.deferredLoadHook(); 3685 exports.deferredLoadHook();
3686 } 3686 }
3687 }, dart.throw_("Unimplemented type (List<dynamic>) → dynamic"))), async.Futu re$(core.Null)); 3687 }, dart.functionType(dynamic, [core.List]))), async.Future$(core.Null));
3688 } 3688 }
3689 // Function _loadHunk: (String) → Future<Null> 3689 // Function _loadHunk: (String) → Future<Null>
3690 function _loadHunk(hunkName) { 3690 function _loadHunk(hunkName) {
3691 let future = exports._loadingLibraries.get(hunkName); 3691 let future = exports._loadingLibraries.get(hunkName);
3692 if (future != null) { 3692 if (future != null) {
3693 return dart.as(future.then(dart.as((_) => null, dart.throw_("Unimplemented type (Null) → dynamic"))), async.Future$(core.Null)); 3693 return dart.as(future.then(dart.as((_) => null, dart.functionType(dynamic, [core.Null]))), async.Future$(core.Null));
3694 } 3694 }
3695 let uri = _isolate_helper.IsolateNatives.thisScript; 3695 let uri = _isolate_helper.IsolateNatives.thisScript;
3696 let index = uri.lastIndexOf('/'); 3696 let index = uri.lastIndexOf('/');
3697 uri = `${uri.substring(0, dart.notNull(index) + 1)}${hunkName}`; 3697 uri = `${uri.substring(0, dart.notNull(index) + 1)}${hunkName}`;
3698 if (dart.notNull(Primitives.isJsshell) || dart.notNull(Primitives.isD8)) { 3698 if (dart.notNull(Primitives.isJsshell) || dart.notNull(Primitives.isD8)) {
3699 return exports._loadingLibraries.set(hunkName, new (async.Future$(core.Nul l))(() => { 3699 return exports._loadingLibraries.set(hunkName, new (async.Future$(core.Nul l))(() => {
3700 try { 3700 try {
3701 new Function(`load("${uri}")`)(); 3701 new Function(`load("${uri}")`)();
3702 } catch (error) { 3702 } catch (error) {
3703 let stackTrace = dart.stackTrace(error); 3703 let stackTrace = dart.stackTrace(error);
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
4003 exports.jsonEncodeNative = jsonEncodeNative; 4003 exports.jsonEncodeNative = jsonEncodeNative;
4004 exports.getIsolateAffinityTag = getIsolateAffinityTag; 4004 exports.getIsolateAffinityTag = getIsolateAffinityTag;
4005 exports.LoadLibraryFunctionType = LoadLibraryFunctionType; 4005 exports.LoadLibraryFunctionType = LoadLibraryFunctionType;
4006 exports.DeferredLoadCallback = DeferredLoadCallback; 4006 exports.DeferredLoadCallback = DeferredLoadCallback;
4007 exports.loadDeferredLibrary = loadDeferredLibrary; 4007 exports.loadDeferredLibrary = loadDeferredLibrary;
4008 exports.MainError = MainError; 4008 exports.MainError = MainError;
4009 exports.missingMain = missingMain; 4009 exports.missingMain = missingMain;
4010 exports.badMain = badMain; 4010 exports.badMain = badMain;
4011 exports.mainHasTooManyParameters = mainHasTooManyParameters; 4011 exports.mainHasTooManyParameters = mainHasTooManyParameters;
4012 })(_js_helper || (_js_helper = {})); 4012 })(_js_helper || (_js_helper = {}));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698