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

Commit d190eef

Browse files
author
Olivier Chafik
committed
Convert dart_utils.js to input_sdk/lib/_internal/utils.dart (#310)
1 parent 4b6319b commit d190eef

File tree

17 files changed

+232
-114
lines changed

17 files changed

+232
-114
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/_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+
});

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";

test/codegen/expect/collection/src/unmodifiable_wrappers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ dart_library.library('collection/src/unmodifiable_wrappers', null, /* Imports */
77
], function(exports, dart, collection, core, wrappers) {
88
'use strict';
99
let dartx = dart.dartx;
10-
dart.export(exports, collection, ['UnmodifiableListView', 'UnmodifiableMapView'], []);
10+
dart.export_(exports, collection, ['UnmodifiableListView', 'UnmodifiableMapView'], []);
1111
const NonGrowableListMixin$ = dart.generic(function(E) {
1212
class NonGrowableListMixin extends core.Object {
1313
static _throw() {

test/codegen/expect/collection/wrappers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ dart_library.library('collection/wrappers', null, /* Imports */[
99
], function(exports, dart, canonicalized_map, core, math, collection, unmodifiable_wrappers) {
1010
'use strict';
1111
let dartx = dart.dartx;
12-
dart.export(exports, canonicalized_map);
13-
dart.export(exports, unmodifiable_wrappers);
12+
dart.export_(exports, canonicalized_map);
13+
dart.export_(exports, unmodifiable_wrappers);
1414
const _base = Symbol('_base');
1515
const _DelegatingIterableBase$ = dart.generic(function(E) {
1616
class _DelegatingIterableBase extends core.Object {

test/codegen/expect/dir/html_input_b.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ dart_library.library('dir/html_input_b', null, /* Imports */[
55
], function(exports, dart, html_input_d) {
66
'use strict';
77
let dartx = dart.dartx;
8-
dart.export(exports, html_input_d);
8+
dart.export_(exports, html_input_d);
99
exports.x = 3;
1010
});

test/codegen/expect/js/js.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ dart_library.library('js/js', null, /* Imports */[
66
], function(exports, dart, js, core) {
77
'use strict';
88
let dartx = dart.dartx;
9-
dart.export(exports, js, ['allowInterop', 'allowInteropCaptureThis'], []);
9+
dart.export_(exports, js, ['allowInterop', 'allowInteropCaptureThis'], []);
1010
class JS extends core.Object {
1111
JS(name) {
1212
if (name === void 0)

test/codegen/expect/unittest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ dart_library.library('unittest', null, /* Imports */[
1111
], function(exports, dart, matcher, dom, core, async, interfaces, util, description$) {
1212
'use strict';
1313
let dartx = dart.dartx;
14-
dart.export(exports, matcher);
14+
dart.export_(exports, matcher);
1515
function group(name, body) {
1616
return dart.dsend(dom.window, 'suite', name, body);
1717
}

test/codegen/expect/unittest/unittest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ dart_library.library('unittest/unittest', null, /* Imports */[
1111
], function(exports, dart, matcher, dom, core, async, interfaces, util, description$) {
1212
'use strict';
1313
let dartx = dart.dartx;
14-
dart.export(exports, matcher);
14+
dart.export_(exports, matcher);
1515
function group(name, body) {
1616
return dart.dsend(dom.window, 'suite', name, body);
1717
}

tool/build_sdk.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ echo "*** Compiling SDK to JavaScript"
1111
dart -c bin/dartdevc.dart --no-source-maps --arrow-fn-bind-this --sdk-check \
1212
--force-compile -l warning --dart-sdk tool/generated_sdk -o lib/runtime/ \
1313
"$@" \
14+
dart:_utils \
1415
dart:js dart:mirrors \
1516
> tool/sdk_expected_errors.txt || true

tool/input_sdk/lib/_internal/libraries.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,12 @@ const Map<String, LibraryInfo> LIBRARIES = const {
216216
category: "Internal",
217217
documented: false,
218218
platforms: DART2JS_PLATFORM),
219+
220+
"_utils": const LibraryInfo(
221+
"_internal/compiler/js_lib/utils.dart",
222+
category: "Internal",
223+
documented: false,
224+
platforms: DART2JS_PLATFORM),
219225
};
220226

221227
/**

0 commit comments

Comments
 (0)