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 ) {
13
4
'use strict' ;
14
-
15
5
const defineProperty = Object . defineProperty ;
16
6
const getOwnPropertyDescriptor = Object . getOwnPropertyDescriptor ;
17
7
const getOwnPropertyNames = Object . getOwnPropertyNames ;
18
8
const getOwnPropertySymbols = Object . getOwnPropertySymbols ;
19
-
20
9
const hasOwnProperty = Object . prototype . hasOwnProperty ;
21
-
22
- class StrongModeError extends Error {
23
- constructor ( message ) {
24
- super ( message ) ;
10
+ const StrongModeError = ( function ( ) {
11
+ function StrongModeError ( message ) {
12
+ Error . call ( this ) ;
13
+ this . message = message ;
25
14
}
26
- }
27
-
28
- /** This error indicates a strong mode specific failure.
29
- */
15
+ ;
16
+ Object . setPrototypeOf ( StrongModeError . prototype , Error . prototype ) ;
17
+ return StrongModeError ;
18
+ } ) ( ) ;
30
19
function throwStrongModeError ( message ) {
31
20
throw new StrongModeError ( message ) ;
32
21
}
33
- dart_utils . throwStrongModeError = throwStrongModeError ;
34
-
35
- /** This error indicates a bug in the runtime or the compiler.
36
- */
37
22
function throwInternalError ( message ) {
38
23
throw Error ( message ) ;
39
24
}
40
- dart_utils . throwInternalError = throwInternalError ;
41
-
42
- function assert ( condition ) {
43
- if ( ! condition ) throwInternalError ( "The compiler is broken: failed assert" ) ;
25
+ function assert_ ( condition ) {
26
+ if ( ! condition )
27
+ throwInternalError ( "The compiler is broken: failed assert" ) ;
44
28
}
45
- dart_utils . assert = assert ;
46
-
47
29
function getOwnNamesAndSymbols ( obj ) {
48
30
return getOwnPropertyNames ( obj ) . concat ( getOwnPropertySymbols ( obj ) ) ;
49
31
}
50
- dart_utils . getOwnNamesAndSymbols = getOwnNamesAndSymbols ;
51
-
52
32
function safeGetOwnProperty ( obj , name ) {
53
33
let desc = getOwnPropertyDescriptor ( obj , name ) ;
54
- if ( desc ) return desc . value ;
34
+ if ( desc )
35
+ return desc . value ;
55
36
}
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
37
function defineLazyProperty ( to , name , desc ) {
65
38
let init = desc . get ;
66
39
let value = null ;
67
-
68
40
function lazySetter ( x ) {
69
41
init = null ;
70
42
value = x ;
@@ -73,61 +45,62 @@ var dart_utils =
73
45
throwInternalError ( 'circular initialization for field ' + name ) ;
74
46
}
75
47
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 ;
79
50
let f = init ;
80
51
init = circularInitError ;
81
52
lazySetter ( f ( ) ) ;
82
53
return value ;
83
54
}
84
55
desc . get = lazyGetter ;
85
56
desc . configurable = true ;
86
- if ( desc . set ) desc . set = lazySetter ;
57
+ if ( desc . set )
58
+ desc . set = lazySetter ;
87
59
return defineProperty ( to , name , desc ) ;
88
60
}
89
- dart_utils . defineLazyProperty = defineLazyProperty ;
90
-
91
61
function defineLazy ( to , from ) {
92
62
for ( let name of getOwnNamesAndSymbols ( from ) ) {
93
63
defineLazyProperty ( to , name , getOwnPropertyDescriptor ( from , name ) ) ;
94
64
}
95
65
}
96
- dart_utils . defineLazy = defineLazy ;
97
-
98
66
function defineMemoizedGetter ( obj , name , getter ) {
99
67
return defineLazyProperty ( obj , name , { get : getter } ) ;
100
68
}
101
- dart_utils . defineMemoizedGetter = defineMemoizedGetter ;
102
-
103
69
function copyTheseProperties ( to , from , names ) {
104
70
for ( let name of names ) {
105
71
defineProperty ( to , name , getOwnPropertyDescriptor ( from , name ) ) ;
106
72
}
107
73
return to ;
108
74
}
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
75
function copyProperties ( to , from ) {
116
76
return copyTheseProperties ( to , from , getOwnNamesAndSymbols ( from ) ) ;
117
77
}
118
- dart_utils . copyProperties = copyProperties ;
119
-
120
- /** Exports from one Dart module to another. */
121
78
function export_ ( to , from , show , hide ) {
122
79
if ( show == void 0 ) {
123
80
show = getOwnNamesAndSymbols ( from ) ;
124
81
}
125
82
if ( hide != void 0 ) {
126
83
var hideMap = new Set ( hide ) ;
127
- show = show . filter ( ( k ) => ! hideMap . has ( k ) ) ;
84
+ show = show . filter ( k => ! hideMap . has ( k ) ) ;
128
85
}
129
86
return copyTheseProperties ( to , from , show ) ;
130
87
}
131
- dart_utils . export = export_ ;
132
-
133
- } ) ( dart_utils ) ;
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
+ } ) ;
0 commit comments