Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit d0d57f2

Browse files
author
Olivier Chafik
committed
Use a symbol for static length/name (conflicts with Function properties in ES5: cannot redefine Function.name/length properties) (issue #312)
1 parent 41ef1f0 commit d0d57f2

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

lib/runtime/dart/_internal.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,7 +1862,7 @@ dart_library.library('dart/_internal', null, /* Imports */[
18621862
static change() {
18631863
return new core.UnsupportedError("Cannot change the content of an unmodifiable List");
18641864
}
1865-
static length() {
1865+
static [dartx.length]() {
18661866
return new core.UnsupportedError("Cannot change length of unmodifiable List");
18671867
}
18681868
static remove() {
@@ -1873,16 +1873,16 @@ dart_library.library('dart/_internal', null, /* Imports */[
18731873
statics: () => ({
18741874
add: [core.UnsupportedError, []],
18751875
change: [core.UnsupportedError, []],
1876-
length: [core.UnsupportedError, []],
1876+
[dartx.length]: [core.UnsupportedError, []],
18771877
remove: [core.UnsupportedError, []]
18781878
}),
1879-
names: ['add', 'change', 'length', 'remove']
1879+
names: ['add', 'change', dartx.length, 'remove']
18801880
});
18811881
class NonGrowableListError extends core.Object {
18821882
static add() {
18831883
return new core.UnsupportedError("Cannot add to non-growable List");
18841884
}
1885-
static length() {
1885+
static [dartx.length]() {
18861886
return new core.UnsupportedError("Cannot change length of non-growable List");
18871887
}
18881888
static remove() {
@@ -1892,10 +1892,10 @@ dart_library.library('dart/_internal', null, /* Imports */[
18921892
dart.setSignature(NonGrowableListError, {
18931893
statics: () => ({
18941894
add: [core.UnsupportedError, []],
1895-
length: [core.UnsupportedError, []],
1895+
[dartx.length]: [core.UnsupportedError, []],
18961896
remove: [core.UnsupportedError, []]
18971897
}),
1898-
names: ['add', 'length', 'remove']
1898+
names: ['add', dartx.length, 'remove']
18991899
});
19001900
function makeListFixedLength(growableList) {
19011901
_interceptors.JSArray.markFixedList(growableList);

lib/runtime/dart/collection.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2440,7 +2440,7 @@ dart_library.library('dart/collection', null, /* Imports */[
24402440
static getValues(map) {
24412441
return map.keys[dartx.map](dart.fn(key => map.get(key)));
24422442
}
2443-
static length(map) {
2443+
static [dartx.length](map) {
24442444
return map.keys[dartx.length];
24452445
}
24462446
static isEmpty(map) {
@@ -2507,15 +2507,15 @@ dart_library.library('dart/collection', null, /* Imports */[
25072507
clear: [dart.dynamic, [core.Map]],
25082508
forEach: [dart.dynamic, [core.Map, dart.functionType(dart.void, [dart.dynamic, dart.dynamic])]],
25092509
getValues: [core.Iterable, [core.Map]],
2510-
length: [core.int, [core.Map]],
2510+
[dartx.length]: [core.int, [core.Map]],
25112511
isEmpty: [core.bool, [core.Map]],
25122512
isNotEmpty: [core.bool, [core.Map]],
25132513
mapToString: [core.String, [core.Map]],
25142514
_id: [dart.dynamic, [dart.dynamic]],
25152515
_fillMapWithMappedIterable: [dart.void, [core.Map, core.Iterable, dart.functionType(dart.dynamic, [dart.dynamic]), dart.functionType(dart.dynamic, [dart.dynamic])]],
25162516
_fillMapWithIterables: [dart.void, [core.Map, core.Iterable, core.Iterable]]
25172517
}),
2518-
names: ['containsValue', 'containsKey', 'putIfAbsent', 'clear', 'forEach', 'getValues', 'length', 'isEmpty', 'isNotEmpty', 'mapToString', '_id', '_fillMapWithMappedIterable', '_fillMapWithIterables']
2518+
names: ['containsValue', 'containsKey', 'putIfAbsent', 'clear', 'forEach', 'getValues', dartx.length, 'isEmpty', 'isNotEmpty', 'mapToString', '_id', '_fillMapWithMappedIterable', '_fillMapWithIterables']
25192519
});
25202520
const Queue$ = dart.generic(function(E) {
25212521
class Queue extends core.Object {

lib/src/codegen/js_codegen.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3391,8 +3391,13 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ClosureAnnotator {
33913391
bool unary: false,
33923392
bool isStatic: false,
33933393
bool allowExtensions: true}) {
3394-
// Static members skip the rename steps.
3395-
if (isStatic) return _propertyName(name);
3394+
// Static members skip the rename steps, except for Function properties.
3395+
if (isStatic) {
3396+
if (name == 'length' || name == 'name') {
3397+
return js.call('dartx.#', _propertyName(name));
3398+
}
3399+
return _propertyName(name);
3400+
}
33963401

33973402
if (name.startsWith('_')) {
33983403
return _privateNames.putIfAbsent(

0 commit comments

Comments
 (0)