-
Notifications
You must be signed in to change notification settings - Fork 0
/
ember-debug.js
199 lines (160 loc) · 5.69 KB
/
ember-debug.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
(function() {
var Ember = { assert: function() {}, FEATURES: { isEnabled: function() {} } };
/*!
* @overview Ember - JavaScript Application Framework
* @copyright Copyright 2011-2014 Tilde Inc. and contributors
* Portions Copyright 2006-2011 Strobe Inc.
* Portions Copyright 2008-2011 Apple Inc. All rights reserved.
* @license Licensed under MIT license
* See https://raw.github.com/emberjs/ember.js/master/LICENSE
* @version 1.4.0-beta.1+canary.ed89e1ea
*/
(function() {
/*global __fail__*/
/**
Ember Debug
@module ember
@submodule ember-debug
*/
/**
@class Ember
*/
if ('undefined' === typeof Ember) {
Ember = {};
if ('undefined' !== typeof window) {
window.Em = window.Ember = Em = Ember;
}
}
// This needs to be kept in sync with the logic in
// `packages/ember-metal/lib/core.js`.
//
// This is duplicated here to ensure that `Ember.ENV`
// is setup even if `Ember` is not loaded yet.
if (Ember.ENV) {
// do nothing if Ember.ENV is already setup
} else if ('undefined' !== typeof EmberENV) {
Ember.ENV = EmberENV;
} else if('undefined' !== typeof ENV) {
Ember.ENV = ENV;
} else {
Ember.ENV = {};
}
if (!('MANDATORY_SETTER' in Ember.ENV)) {
Ember.ENV.MANDATORY_SETTER = true; // default to true for debug dist
}
/**
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 a 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.
*/
Ember.assert = function(desc, test) {
if (!test) {
throw new Ember.Error("Assertion Failed: " + desc);
}
};
/**
Display a warning with the provided message. Ember build tools will
remove any calls to `Ember.warn()` when doing a production build.
@method warn
@param {String} message A warning to display.
@param {Boolean} test An optional boolean. If falsy, the warning
will be displayed.
*/
Ember.warn = function(message, test) {
if (!test) {
Ember.Logger.warn("WARNING: "+message);
if ('trace' in Ember.Logger) Ember.Logger.trace();
}
};
/**
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.
*/
Ember.debug = function(message) {
Ember.Logger.debug("DEBUG: "+message);
};
/**
Display a deprecation warning with the provided message and a stack trace
(Chrome and Firefox only). Ember build tools will remove any calls to
`Ember.deprecate()` when doing a production build.
@method deprecate
@param {String} message A description of the deprecation.
@param {Boolean} test An optional boolean. If falsy, the deprecation
will be displayed.
*/
Ember.deprecate = function(message, test) {
if (Ember.TESTING_DEPRECATION) { return; }
if (arguments.length === 1) { test = false; }
if (test) { return; }
if (Ember.ENV.RAISE_ON_DEPRECATION) { throw new Ember.Error(message); }
var error;
// When using new Error, we can't do the arguments check for Chrome. Alternatives are welcome
try { __fail__.fail(); } catch (e) { error = e; }
if (Ember.LOG_STACKTRACE_ON_DEPRECATION && error.stack) {
var stack, stackStr = '';
if (error['arguments']) {
// Chrome
stack = error.stack.replace(/^\s+at\s+/gm, '').
replace(/^([^\(]+?)([\n$])/gm, '{anonymous}($1)$2').
replace(/^Object.<anonymous>\s*\(([^\)]+)\)/gm, '{anonymous}($1)').split('\n');
stack.shift();
} else {
// Firefox
stack = error.stack.replace(/(?:\n@:0)?\s+$/m, '').
replace(/^\(/gm, '{anonymous}(').split('\n');
}
stackStr = "\n " + stack.slice(2).join("\n ");
message = message + stackStr;
}
Ember.Logger.warn("DEPRECATION: "+message);
};
/**
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 {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
*/
Ember.deprecateFunc = function(message, func) {
return function() {
Ember.deprecate(message);
return func.apply(this, arguments);
};
};
// Inform the developer about the Ember Inspector if not installed.
if (!Ember.testing) {
if (typeof window !== 'undefined' && window.chrome && window.addEventListener) {
window.addEventListener("load", function() {
if (document.body && document.body.dataset && !document.body.dataset.emberExtension) {
Ember.debug('For more advanced debugging, install the Ember Inspector from https://chrome.google.com/webstore/detail/ember-inspector/bmdblncegkenkacieihfhpjfppoconhi');
}
}, false);
}
}
})();
exports.precompile = Ember.Handlebars.precompile;
exports.EmberHandlebars = Ember.Handlebars;
})();