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

Commit 76c630f

Browse files
author
Olivier Chafik
committed
Convert dart_utils.js to input_sdk/lib/_internal/utils.dart (#310)
1 parent 9230be9 commit 76c630f

23 files changed

+260
-129
lines changed

lib/runtime/dart/_classes.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
// TODO(leafp): Consider splitting some of this out.
1313
dart_library.library('dart/_classes', null, /* Imports */[
1414
], /* Lazy Imports */[
15+
'dart/_utils',
1516
'dart/core',
1617
'dart/_interceptors',
1718
'dart/_types',
1819
'dart/_rtti',
19-
], function(exports, core, _interceptors, types, rtti) {
20+
], function(exports, dart_utils, core, _interceptors, types, rtti) {
2021
'use strict';
2122

22-
const assert = dart_utils.assert;
23+
const assert = dart_utils.assert_;
2324
const copyProperties = dart_utils.copyProperties;
2425
const copyTheseProperties = dart_utils.copyTheseProperties;
2526
const defineMemoizedGetter = dart_utils.defineMemoizedGetter;

lib/runtime/dart/_internal.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ dart_library.library('dart/_internal', null, /* Imports */[
620620
super.IterableBase();
621621
}
622622
get iterator() {
623-
return new (ExpandIterator$(S, T))(this[_iterable][dartx.iterator], dart.as(this[_f], __CastType0));
623+
return new (ExpandIterator$(S, T))(this[_iterable][dartx.iterator], dart.as(this[_f], __CastType0$(S, T)));
624624
}
625625
}
626626
dart.setSignature(ExpandIterable, {
@@ -1317,7 +1317,7 @@ dart_library.library('dart/_internal', null, /* Imports */[
13171317
}
13181318
where(iterable, f) {
13191319
dart.as(f, dart.functionType(core.bool, [dart.dynamic]));
1320-
return new (WhereIterable$(T))(dart.as(iterable, core.Iterable$(T)), dart.as(f, __CastType2));
1320+
return new (WhereIterable$(T))(dart.as(iterable, core.Iterable$(T)), dart.as(f, __CastType2$(T)));
13211321
}
13221322
static map(iterable, f) {
13231323
dart.as(f, dart.functionType(dart.dynamic, [dart.dynamic]));

lib/runtime/dart/_operations.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88
dart_library.library('dart/_operations', null, /* Imports */[
99
], /* Lazy Imports */[
10+
'dart/_utils',
1011
'dart/async',
1112
'dart/collection',
1213
'dart/core',
@@ -15,7 +16,7 @@ dart_library.library('dart/_operations', null, /* Imports */[
1516
'dart/_errors',
1617
'dart/_rtti',
1718
'dart/_types'
18-
], function(exports, async, collection, core, _js_helper, classes, errors, rtti,
19+
], function(exports, dart_utils, async, collection, core, _js_helper, classes, errors, rtti,
1920
types) {
2021
'use strict';
2122

lib/runtime/dart/_rtti.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88

99
dart_library.library('dart/_rtti', null, /* Imports */[
1010
], /* Lazy Imports */[
11+
'dart/_utils',
1112
'dart/core',
1213
'dart/_types'
13-
], function(exports, core, types) {
14+
], function(exports, dart_utils, core, types) {
1415
'use strict';
1516

1617
const defineLazyProperty = dart_utils.defineLazyProperty;

lib/runtime/dart/_runtime.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
dart_library.library('dart/_runtime', null, /* Imports */[
6+
'dart/_utils',
67
'dart/_classes',
78
'dart/_errors',
89
'dart/_generators',
@@ -11,7 +12,7 @@ dart_library.library('dart/_runtime', null, /* Imports */[
1112
'dart/_types',
1213
], /* Lazy Imports */[
1314
'dart/_js_helper'
14-
], function(exports, classes, errors, generators, operations, rtti, types,
15+
], function(exports, dart_utils, classes, errors, generators, operations, rtti, types,
1516
_js_helper) {
1617
'use strict';
1718

@@ -64,7 +65,7 @@ dart_library.library('dart/_runtime', null, /* Imports */[
6465
]);
6566

6667
// From dart_utils
67-
exportFrom(dart_utils, ['copyProperties', 'export']);
68+
exportFrom(dart_utils, ['copyProperties', 'export_']);
6869
// Renames
6970
exports.defineLazyClass = _export(dart_utils.defineLazy);
7071
exports.defineLazyProperties = _export(dart_utils.defineLazy);

lib/runtime/dart/_types.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77

88
dart_library.library('dart/_types', null, /* Imports */[
99
], /* Lazy Imports */[
10+
'dart/_utils',
1011
'dart/core',
1112
'dart/_classes',
1213
'dart/_rtti'
13-
], function(exports, core, classes, rtti) {
14+
], function(exports, dart_utils, core, classes, rtti) {
1415
'use strict';
1516

1617
const getOwnPropertyNames = Object.getOwnPropertyNames;
1718

18-
const assert = dart_utils.assert;
19+
const assert = dart_utils.assert_;
1920

2021
/**
2122
* Types in dart are represented at runtime as follows.
@@ -24,12 +25,12 @@ dart_library.library('dart/_types', null, /* Imports */[
2425
* If the type is the result of instantiating a generic class,
2526
* then the "classes" module manages the association between the
2627
* instantiated class and the original class declaration
27-
* and the type arguments with which it was instantiated. This
28+
* and the type arguments with which it was instantiated. This
2829
* assocation can be queried via the "classes" module".
2930
*
3031
* - All other types are represented as instances of class TypeRep,
3132
* defined in this module.
32-
* - Dynamic, Void, and Bottom are singleton instances of sentinal
33+
* - Dynamic, Void, and Bottom are singleton instances of sentinal
3334
* classes.
3435
* - Function types are instances of subclasses of AbstractFunctionType.
3536
*

lib/runtime/dart/_utils.js

Lines changed: 66 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,42 @@
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
3-
// BSD-style license that can be found in the LICENSE file.
4-
5-
/* This library defines a set of general javascript utilities for us
6-
* by the Dart runtime.
7-
*/
8-
9-
var dart_utils =
10-
typeof module != "undefined" && module.exports || {};
11-
12-
(function (dart_utils) {
1+
dart_library.library('dart/_utils', null, /* Imports */[
2+
], /* Lazy imports */[
3+
], function(exports, dart) {
134
'use strict';
14-
15-
const defineProperty = Object.defineProperty;
16-
const getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
17-
const getOwnPropertyNames = Object.getOwnPropertyNames;
18-
const getOwnPropertySymbols = Object.getOwnPropertySymbols;
19-
20-
const hasOwnProperty = Object.prototype.hasOwnProperty;
21-
22-
class StrongModeError extends Error {
23-
constructor(message) {
24-
super(message);
5+
let defineProperty = Object.defineProperty;
6+
let getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
7+
let getOwnPropertyNames = Object.getOwnPropertyNames;
8+
let getOwnPropertySymbols = Object.getOwnPropertySymbols;
9+
let hasOwnProperty = Object.prototype.hasOwnProperty;
10+
let StrongModeError = (function() {
11+
function StrongModeError(message) {
12+
Error.call(this);
13+
this.message = message;
2514
}
26-
}
27-
28-
/** This error indicates a strong mode specific failure.
29-
*/
30-
function throwStrongModeError(message) {
15+
;
16+
Object.setPrototypeOf(StrongModeError.prototype, Error.prototype);
17+
return StrongModeError;
18+
})();
19+
let throwStrongModeError = function(message) {
3120
throw new StrongModeError(message);
32-
}
33-
dart_utils.throwStrongModeError = throwStrongModeError;
34-
35-
/** This error indicates a bug in the runtime or the compiler.
36-
*/
37-
function throwInternalError(message) {
21+
};
22+
let throwInternalError = function(message) {
3823
throw Error(message);
39-
}
40-
dart_utils.throwInternalError = throwInternalError;
41-
42-
function assert(condition) {
43-
if (!condition) throwInternalError("The compiler is broken: failed assert");
44-
}
45-
dart_utils.assert = assert;
46-
47-
function getOwnNamesAndSymbols(obj) {
24+
};
25+
let assert_ = function(condition) {
26+
if (!condition)
27+
throwInternalError("The compiler is broken: failed assert");
28+
};
29+
let getOwnNamesAndSymbols = function(obj) {
4830
return getOwnPropertyNames(obj).concat(getOwnPropertySymbols(obj));
49-
}
50-
dart_utils.getOwnNamesAndSymbols = getOwnNamesAndSymbols;
51-
52-
function safeGetOwnProperty(obj, name) {
31+
};
32+
let safeGetOwnProperty = function(obj, name) {
5333
let desc = getOwnPropertyDescriptor(obj, name);
54-
if (desc) return desc.value;
55-
}
56-
dart_utils.safeGetOwnProperty = safeGetOwnProperty;
57-
58-
/**
59-
* Defines a lazy property.
60-
* After initial get or set, it will replace itself with a value property.
61-
*/
62-
// TODO(jmesserly): reusing descriptor objects has been shown to improve
63-
// performance in other projects (e.g. webcomponents.js ShadowDOM polyfill).
64-
function defineLazyProperty(to, name, desc) {
34+
if (desc)
35+
return desc.value;
36+
};
37+
let defineLazyProperty = function(to, name, desc) {
6538
let init = desc.get;
6639
let value = null;
67-
6840
function lazySetter(x) {
6941
init = null;
7042
value = x;
@@ -73,61 +45,62 @@ var dart_utils =
7345
throwInternalError('circular initialization for field ' + name);
7446
}
7547
function lazyGetter() {
76-
if (init == null) return value;
77-
78-
// Compute and store the value, guarding against reentry.
48+
if (init == null)
49+
return value;
7950
let f = init;
8051
init = circularInitError;
8152
lazySetter(f());
8253
return value;
8354
}
8455
desc.get = lazyGetter;
8556
desc.configurable = true;
86-
if (desc.set) desc.set = lazySetter;
57+
if (desc.set)
58+
desc.set = lazySetter;
8759
return defineProperty(to, name, desc);
88-
}
89-
dart_utils.defineLazyProperty = defineLazyProperty;
90-
91-
function defineLazy(to, from) {
60+
};
61+
let defineLazy = function(to, from) {
9262
for (let name of getOwnNamesAndSymbols(from)) {
9363
defineLazyProperty(to, name, getOwnPropertyDescriptor(from, name));
9464
}
95-
}
96-
dart_utils.defineLazy = defineLazy;
97-
98-
function defineMemoizedGetter(obj, name, getter) {
65+
};
66+
let defineMemoizedGetter = function(obj, name, getter) {
9967
return defineLazyProperty(obj, name, {get: getter});
100-
}
101-
dart_utils.defineMemoizedGetter = defineMemoizedGetter;
102-
103-
function copyTheseProperties(to, from, names) {
68+
};
69+
let copyTheseProperties = function(to, from, names) {
10470
for (let name of names) {
10571
defineProperty(to, name, getOwnPropertyDescriptor(from, name));
10672
}
10773
return to;
108-
}
109-
dart_utils.copyTheseProperties = copyTheseProperties;
110-
111-
/**
112-
* Copy properties from source to destination object.
113-
* This operation is commonly called `mixin` in JS.
114-
*/
115-
function copyProperties(to, from) {
74+
};
75+
let copyProperties = function(to, from) {
11676
return copyTheseProperties(to, from, getOwnNamesAndSymbols(from));
117-
}
118-
dart_utils.copyProperties = copyProperties;
119-
120-
/** Exports from one Dart module to another. */
121-
function export_(to, from, show, hide) {
77+
};
78+
let export_ = function(to, from, show, hide) {
12279
if (show == void 0) {
12380
show = getOwnNamesAndSymbols(from);
12481
}
12582
if (hide != void 0) {
12683
var hideMap = new Set(hide);
127-
show = show.filter((k) => !hideMap.has(k));
84+
show = show.filter(k => !hideMap.has(k));
12885
}
12986
return copyTheseProperties(to, from, show);
130-
}
131-
dart_utils.export = export_;
132-
133-
})(dart_utils);
87+
};
88+
// Exports:
89+
exports.defineProperty = defineProperty;
90+
exports.getOwnPropertyDescriptor = getOwnPropertyDescriptor;
91+
exports.getOwnPropertyNames = getOwnPropertyNames;
92+
exports.getOwnPropertySymbols = getOwnPropertySymbols;
93+
exports.hasOwnProperty = hasOwnProperty;
94+
exports.StrongModeError = StrongModeError;
95+
exports.throwStrongModeError = throwStrongModeError;
96+
exports.throwInternalError = throwInternalError;
97+
exports.assert_ = assert_;
98+
exports.getOwnNamesAndSymbols = getOwnNamesAndSymbols;
99+
exports.safeGetOwnProperty = safeGetOwnProperty;
100+
exports.defineLazyProperty = defineLazyProperty;
101+
exports.defineLazy = defineLazy;
102+
exports.defineMemoizedGetter = defineMemoizedGetter;
103+
exports.copyTheseProperties = copyTheseProperties;
104+
exports.copyProperties = copyProperties;
105+
exports.export_ = export_;
106+
});

lib/runtime/dart/async.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ dart_library.library('dart/async', null, /* Imports */[
920920
onData(handleData) {
921921
dart.as(handleData, dart.functionType(dart.void, [T]));
922922
if (handleData == null)
923-
handleData = dart.as(_nullDataHandler, __CastType20);
923+
handleData = dart.as(_nullDataHandler, __CastType20$(T));
924924
this[_onData] = dart.as(this[_zone].registerUnaryCallback(handleData), _DataHandler$(T));
925925
}
926926
onError(handleError) {
@@ -1583,7 +1583,7 @@ dart_library.library('dart/async', null, /* Imports */[
15831583
this[_forEachListener](dart.as(dart.fn(subscription => {
15841584
dart.as(subscription, _BroadcastSubscription$(T));
15851585
subscription[_close]();
1586-
}, dart.dynamic, [_BroadcastSubscription$(T)]), __CastType2));
1586+
}, dart.dynamic, [_BroadcastSubscription$(T)]), __CastType2$(T)));
15871587
} else {
15881588
dart.assert(this[_doneFuture] != null);
15891589
dart.assert(this[_doneFuture][_mayComplete]);
@@ -2272,7 +2272,7 @@ dart_library.library('dart/async', null, /* Imports */[
22722272
let onError = opts && 'onError' in opts ? opts.onError : null;
22732273
let result = new (_Future$())();
22742274
if (!dart.notNull(core.identical(result[_zone], _ROOT_ZONE))) {
2275-
f = dart.as(result[_zone].registerUnaryCallback(f), __CastType6);
2275+
f = dart.as(result[_zone].registerUnaryCallback(f), __CastType6$(T));
22762276
if (onError != null) {
22772277
onError = _registerErrorHandler(onError, result[_zone]);
22782278
}
@@ -3365,12 +3365,12 @@ dart_library.library('dart/async', null, /* Imports */[
33653365
return null;
33663366
}
33673367
}
3368-
class _NoCallbackAsyncStreamController extends dart.mixin(_StreamController, _AsyncStreamControllerDispatch, _NoCallbacks) {
3368+
class _NoCallbackAsyncStreamController extends dart.mixin(_StreamController$(dart.dynamic), _AsyncStreamControllerDispatch$(dart.dynamic), _NoCallbacks) {
33693369
_NoCallbackAsyncStreamController() {
33703370
super._StreamController(...arguments);
33713371
}
33723372
}
3373-
class _NoCallbackSyncStreamController extends dart.mixin(_StreamController, _SyncStreamControllerDispatch, _NoCallbacks) {
3373+
class _NoCallbackSyncStreamController extends dart.mixin(_StreamController$(dart.dynamic), _SyncStreamControllerDispatch$(dart.dynamic), _NoCallbacks) {
33743374
_NoCallbackSyncStreamController() {
33753375
super._StreamController(...arguments);
33763376
}
@@ -4877,9 +4877,9 @@ dart_library.library('dart/async', null, /* Imports */[
48774877
super._StreamSinkTransformer(dart.as(dart.fn(outputSink => {
48784878
dart.as(outputSink, EventSink$(T));
48794879
if (handleData == null)
4880-
handleData = dart.as(_StreamHandlerTransformer$()._defaultHandleData, __CastType27);
4880+
handleData = dart.as(_StreamHandlerTransformer$()._defaultHandleData, __CastType27$(S, T));
48814881
if (handleError == null)
4882-
handleError = dart.as(_StreamHandlerTransformer$()._defaultHandleError, __CastType30);
4882+
handleError = dart.as(_StreamHandlerTransformer$()._defaultHandleError, __CastType30$(T));
48834883
if (handleDone == null)
48844884
handleDone = _StreamHandlerTransformer$()._defaultHandleDone;
48854885
return new (_HandlerEventSink$(S, T))(handleData, handleError, handleDone, outputSink);

lib/runtime/dart/js.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ dart_library.library('dart/js', null, /* Imports */[
176176
from(other) {
177177
super._fromJs((() => {
178178
let _ = [];
179-
_[dartx.addAll](other[dartx.map](dart.as(_convertToJS, __CastType0)));
179+
_[dartx.addAll](other[dartx.map](dart.as(_convertToJS, __CastType0$(E))));
180180
return _;
181181
})());
182182
}

test/browser/runtime_tests.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ var dartx = dart.dartx;
1313
// If we decide to expose them, this can go away.
1414
var classes = dart_library.import('dart/_classes');
1515
var types = dart_library.import('dart/_types');
16+
var dart_utils = dart_library.import('dart/_utils');
1617

1718
suite('generic', () => {
1819
"use strict";

0 commit comments

Comments
 (0)