Skip to content

Commit 498ecbc

Browse files
author
John Messerly
committed
small cleanups to dart_runtime.js
these were caught by the webstorm ES6 plugin biggest one is strict mode doesn't like local functions except at top level, I think becasue the name is not scoped correctly (for historical reasons). Instead `let name = () => ...;` allows correct scoping for `name`. [email protected] Review URL: https://codereview.chromium.org/1152783005
1 parent 9277398 commit 498ecbc

File tree

1 file changed

+13
-37
lines changed

1 file changed

+13
-37
lines changed

pkg/dev_compiler/lib/runtime/dart_runtime.js

Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,6 @@ var dart, _js_helper, _js_primitives;
2020
return getOwnPropertyNames(obj).concat(getOwnPropertySymbols(obj));
2121
}
2222

23-
// Adapted from Angular.js
24-
let FN_ARGS = /^function\s*[^\(]*\(\s*([^\)]*)\)/m;
25-
let FN_ARG_SPLIT = /,/;
26-
let FN_ARG = /^\s*(_?)(\S+?)\1\s*$/;
27-
let STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
28-
29-
function formalParameterList(fn) {
30-
let fnText,argDecl;
31-
let args=[];
32-
fnText = fn.toString().replace(STRIP_COMMENTS, '');
33-
argDecl = fnText.match(FN_ARGS);
34-
35-
let r = argDecl[1].split(FN_ARG_SPLIT);
36-
for (let arg of r) {
37-
arg.replace(FN_ARG, function(all, underscore, name){
38-
args.push(name);
39-
});
40-
}
41-
return args;
42-
}
43-
4423
function dload(obj, field) {
4524
field = _canonicalFieldName(obj, field);
4625
if (_getMethodType(obj, field) !== void 0) {
@@ -126,7 +105,7 @@ var dart, _js_helper, _js_primitives;
126105
// TODO(vsm): This should record / check the receiver type
127106
// as well. E.g., only look for core.$map if the receiver
128107
// is an Iterable.
129-
'map': () => core.$map,
108+
'map': () => core.$map
130109
};
131110

132111
// TODO(leafp): Integrate this with the eventual proper extension
@@ -572,10 +551,10 @@ var dart, _js_helper, _js_primitives;
572551
if (arguments.length == 1) {
573552
// No type arguments, it's all dynamic
574553
let len = closure.length;
575-
function build() {
554+
let build = () => {
576555
let args = Array.apply(null, new Array(len)).map(() => core.Object);
577556
return functionType(core.Object, args);
578-
}
557+
};
579558
// We could be called before Object is defined.
580559
if (core.Object === void 0) return fn(closure, build);
581560
t = build();
@@ -1021,8 +1000,7 @@ var dart, _js_helper, _js_primitives;
10211000
if (sigObj === void 0) return void 0;
10221001
let parts = sigObj[name];
10231002
if (parts === void 0) return void 0;
1024-
let sig = functionType.apply(null, parts);
1025-
return sig;
1003+
return functionType.apply(null, parts);
10261004
}
10271005

10281006
/// Get the type of a constructor from a class using the stored signature
@@ -1036,8 +1014,7 @@ var dart, _js_helper, _js_primitives;
10361014
if (sigCtor === void 0) return void 0;
10371015
let parts = sigCtor[name];
10381016
if (parts === void 0) return void 0;
1039-
let sig = functionType.apply(null, parts);
1040-
return sig;
1017+
return functionType.apply(null, parts);
10411018
}
10421019
dart.classGetConstructorType = _getConstructorType;
10431020

@@ -1047,7 +1024,7 @@ var dart, _js_helper, _js_primitives;
10471024
/// TODO(leafp): Consider caching the tearoff on the object?
10481025
function bind(obj, name) {
10491026
let f = obj[name].bind(obj);
1050-
let sig = _getMethodType(obj, name)
1027+
let sig = _getMethodType(obj, name);
10511028
assert(sig);
10521029
setRuntimeType(f, sig);
10531030
return f;
@@ -1076,11 +1053,10 @@ var dart, _js_helper, _js_primitives;
10761053
// Set the lazily computed runtime type field on static methods
10771054
function _setStaticTypes(f, names) {
10781055
for (let name of names) {
1079-
function getT() {
1056+
defineProperty(f[name], _runtimeType, { get: function() {
10801057
let parts = f[_staticSig][name];
10811058
return functionType.apply(null, parts);
1082-
};
1083-
defineProperty(f[name], _runtimeType, {get : getT});
1059+
}});
10841060
}
10851061
}
10861062

@@ -1107,7 +1083,7 @@ var dart, _js_helper, _js_primitives;
11071083
_setMethodSignature(f, methods);
11081084
_setStaticSignature(f, statics);
11091085
_setStaticTypes(f, names);
1110-
};
1086+
}
11111087
dart.setSignature = setSignature;
11121088

11131089
let _value = Symbol('_value');
@@ -1290,13 +1266,13 @@ var dart, _js_helper, _js_primitives;
12901266
let result = _split.apply(this, arguments);
12911267
dart.setType(result, core.List$(core.String));
12921268
return result;
1293-
}
1269+
};
12941270
String.prototype.get = function(i) {
12951271
return this[i];
1296-
}
1272+
};
12971273
String.prototype.codeUnitAt = function(i) {
12981274
return this.charCodeAt(i);
1299-
}
1275+
};
13001276
String.prototype.replaceAllMapped = function(from, cb) {
13011277
return this.replace(from.multiple, function() {
13021278
// Remove offset & string from the result array
@@ -1305,7 +1281,7 @@ var dart, _js_helper, _js_primitives;
13051281
// The callback receives match, p1, ..., pn
13061282
return cb(matches);
13071283
});
1308-
}
1284+
};
13091285
String.prototype['+'] = function(arg) { return this.valueOf() + arg; };
13101286

13111287
Boolean.prototype['!'] = function() { return !this.valueOf(); };

0 commit comments

Comments
 (0)