-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
Copy pathindex.js
305 lines (257 loc) · 9.57 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
import Ember from 'ember-metal/core';
import {
warn,
deprecate,
debug,
setDebugFunction
} from 'ember-metal/debug';
import isEnabled, { FEATURES } from 'ember-metal/features';
import EmberError from 'ember-metal/error';
import Logger from 'ember-metal/logger';
import environment from 'ember-metal/environment';
import _deprecate, {
registerHandler as registerDeprecationHandler
} from 'ember-debug/deprecate';
import _warn, {
registerHandler as registerWarnHandler
} from 'ember-debug/warn';
import isPlainFunction from 'ember-debug/is-plain-function';
import { generateTestAsFunctionDeprecation } from 'ember-debug/handlers';
/**
@module ember
@submodule ember-debug
*/
/**
@class Ember
@public
*/
/**
Define an assertion that will throw an exception if the condition is not
met. Ember build tools will remove any calls to `Ember.assert()` when
doing an Ember.js framework production build and will make the assertion a
no-op for an application production build. Example:
```javascript
// Test for truthiness
Ember.assert('Must pass a valid object', obj);
// Fail unconditionally
Ember.assert('This code path should never be run');
```
@method assert
@param {String} desc A description of the assertion. This will become
the text of the Error thrown if the assertion fails.
@param {Boolean} test Must be truthy for the assertion to pass. If
falsy, an exception will be thrown.
@public
*/
setDebugFunction('assert', function assert(desc, test) {
let throwAssertion;
if (isPlainFunction(test)) {
deprecate(
generateTestAsFunctionDeprecation('Ember.assert'),
false,
{ id: 'ember-debug.deprecate-test-as-function', until: '2.5.0' }
);
throwAssertion = !test();
} else {
throwAssertion = !test;
}
if (throwAssertion) {
throw new EmberError('Assertion Failed: ' + desc);
}
});
/**
Display a debug notice. Ember build tools will remove any calls to
`Ember.debug()` when doing a production build.
```javascript
Ember.debug('I\'m a debug notice!');
```
@method debug
@param {String} message A debug message to display.
@public
*/
setDebugFunction('debug', function debug(message) {
Logger.debug('DEBUG: ' + message);
});
/**
Display an info notice.
@method info
@private
*/
setDebugFunction('info', function info() {
Logger.info.apply(undefined, arguments);
});
/**
Alias an old, deprecated method with its new counterpart.
Display a deprecation warning with the provided message and a stack trace
(Chrome and Firefox only) when the assigned method is called.
Ember build tools will not remove calls to `Ember.deprecateFunc()`, though
no warnings will be shown in production.
```javascript
Ember.oldMethod = Ember.deprecateFunc('Please use the new, updated method', Ember.newMethod);
```
@method deprecateFunc
@param {String} message A description of the deprecation.
@param {Object} [options] The options object for Ember.deprecate.
@param {Function} func The new function called to replace its deprecated counterpart.
@return {Function} a new function that wrapped the original function with a deprecation warning
@private
*/
setDebugFunction('deprecateFunc', function deprecateFunc(...args) {
if (args.length === 3) {
let [message, options, func] = args;
return function() {
deprecate(message, false, options);
return func.apply(this, arguments);
};
} else {
let [message, func] = args;
return function() {
deprecate(message);
return func.apply(this, arguments);
};
}
});
/**
Run a function meant for debugging. Ember build tools will remove any calls to
`Ember.runInDebug()` when doing a production build.
```javascript
Ember.runInDebug(() => {
Ember.Component.reopen({
didInsertElement() {
console.log("I'm happy");
}
});
});
```
@method runInDebug
@param {Function} func The function to be executed.
@since 1.5.0
@public
*/
setDebugFunction('runInDebug', function runInDebug(func) {
func();
});
setDebugFunction('debugSeal', function debugSeal(obj) {
Object.seal(obj);
});
setDebugFunction('deprecate', _deprecate);
setDebugFunction('warn', _warn);
/**
Will call `Ember.warn()` if ENABLE_OPTIONAL_FEATURES or
any specific FEATURES flag is truthy.
This method is called automatically in debug canary builds.
@private
@method _warnIfUsingStrippedFeatureFlags
@return {void}
*/
export function _warnIfUsingStrippedFeatureFlags(FEATURES, featuresWereStripped) {
if (featuresWereStripped) {
warn('Ember.ENV.ENABLE_OPTIONAL_FEATURES is only available in canary builds.', !Ember.ENV.ENABLE_OPTIONAL_FEATURES, { id: 'ember-debug.feature-flag-with-features-stripped' });
for (var key in FEATURES) {
if (FEATURES.hasOwnProperty(key) && key !== 'isEnabled') {
warn('FEATURE["' + key + '"] is set as enabled, but FEATURE flags are only available in canary builds.', !FEATURES[key], { id: 'ember-debug.feature-flag-with-features-stripped' });
}
}
}
}
if (!Ember.testing) {
// Complain if they're using FEATURE flags in builds other than canary
FEATURES['features-stripped-test'] = true;
var featuresWereStripped = true;
if (isEnabled('features-stripped-test')) {
featuresWereStripped = false;
}
delete FEATURES['features-stripped-test'];
_warnIfUsingStrippedFeatureFlags(Ember.ENV.FEATURES, featuresWereStripped);
// Inform the developer about the Ember Inspector if not installed.
var isFirefox = environment.isFirefox;
var isChrome = environment.isChrome;
if (typeof window !== 'undefined' && (isFirefox || isChrome) && window.addEventListener) {
window.addEventListener('load', function() {
if (document.documentElement && document.documentElement.dataset && !document.documentElement.dataset.emberExtension) {
var downloadURL;
if (isChrome) {
downloadURL = 'https://chrome.google.com/webstore/detail/ember-inspector/bmdblncegkenkacieihfhpjfppoconhi';
} else if (isFirefox) {
downloadURL = 'https://addons.mozilla.org/en-US/firefox/addon/ember-inspector/';
}
debug('For more advanced debugging, install the Ember Inspector from ' + downloadURL);
}
}, false);
}
}
/**
@public
@class Ember.Debug
*/
Ember.Debug = { };
if (isEnabled('ember-debug-handlers')) {
/**
Allows for runtime registration of handler functions that override the default deprecation behavior.
Deprecations are invoked by calls to [Ember.deprecate](http://emberjs.com/api/classes/Ember.html#method_deprecate).
The following example demonstrates its usage by registering a handler that throws an error if the
message contains the word "should", otherwise defers to the default handler.
```javascript
Ember.Debug.registerDeprecationHandler((message, options, next) => {
if (message.indexOf('should') !== -1) {
throw new Error(`Deprecation message with should: ${message}`);
} else {
// defer to whatever handler was registered before this one
next(message, options);
}
}
```
The handler function takes the following arguments:
<ul>
<li> <code>message</code> - The message received from the deprecation call. </li>
<li> <code>options</code> - An object passed in with the deprecation call containing additional information including:</li>
<ul>
<li> <code>id</code> - an id of the deprecation in the form of <code>package-name.specific-deprecation</code>.</li>
<li> <code>until</code> - is the version number Ember the feature and deprecation will be removed in.</li>
</ul>
<li> <code>next</code> - a function that calls into the previously registered handler.</li>
</ul>
@public
@static
@method registerDeprecationHandler
@param handler {Function} a function to handle deprecation calls
@since 2.1.0
*/
Ember.Debug.registerDeprecationHandler = registerDeprecationHandler;
/**
Allows for runtime registration of handler functions that override the default warning behavior.
Warnings are invoked by calls made to [Ember.warn](http://emberjs.com/api/classes/Ember.html#method_warn).
The following example demonstrates its usage by registering a handler that does nothing overriding Ember's
default warning behavior.
```javascript
// next is not called, so no warnings get the default behavior
Ember.Debug.registerWarnHandler(() => {});
```
The handler function takes the following arguments:
<ul>
<li> <code>message</code> - The message received from the warn call. </li>
<li> <code>options</code> - An object passed in with the warn call containing additional information including:</li>
<ul>
<li> <code>id</code> - an id of the warning in the form of <code>package-name.specific-warning</code>.</li>
</ul>
<li> <code>next</code> - a function that calls into the previously registered handler.</li>
</ul>
@public
@static
@method registerWarnHandler
@param handler {Function} a function to handle warnings
@since 2.1.0
*/
Ember.Debug.registerWarnHandler = registerWarnHandler;
}
/*
We are transitioning away from `ember.js` to `ember.debug.js` to make
it much clearer that it is only for local development purposes.
This flag value is changed by the tooling (by a simple string replacement)
so that if `ember.js` (which must be output for backwards compat reasons) is
used a nice helpful warning message will be printed out.
*/
export var runningNonEmberDebugJS = false;
if (runningNonEmberDebugJS) {
warn('Please use `ember.debug.js` instead of `ember.js` for development and debugging.');
}