-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEATURE ember-debug-handlers] #11833
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/*global __fail__*/ | ||
|
||
import Ember from 'ember-metal/core'; | ||
import EmberError from 'ember-metal/error'; | ||
import Logger from 'ember-metal/logger'; | ||
import { registerHandler as genericRegisterHandler, invoke } from 'ember-debug/handlers'; | ||
|
||
export function registerHandler(handler) { | ||
genericRegisterHandler('deprecate', handler); | ||
} | ||
|
||
function formatMessage(_message, options) { | ||
let message = _message; | ||
|
||
if (options && options.id) { | ||
message = message + ` [deprecation id: ${options.id}]`; | ||
} | ||
|
||
if (options && options.url) { | ||
message += ' See ' + options.url + ' for more details.'; | ||
} | ||
|
||
return message; | ||
} | ||
|
||
registerHandler(function logDeprecationToConsole(message, options) { | ||
let updatedMessage = formatMessage(message, options); | ||
|
||
Logger.warn('DEPRECATION: ' + updatedMessage); | ||
}); | ||
|
||
registerHandler(function logDeprecationStackTrace(message, options, next) { | ||
if (Ember.LOG_STACKTRACE_ON_DEPRECATION) { | ||
let stackStr = ''; | ||
let error, stack; | ||
|
||
// When using new Error, we can't do the arguments check for Chrome. Alternatives are welcome | ||
try { __fail__.fail(); } catch (e) { error = e; } | ||
|
||
if (error.stack) { | ||
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 '); | ||
} | ||
|
||
let updatedMessage = formatMessage(message, options); | ||
|
||
Logger.warn('DEPRECATION: ' + updatedMessage + stackStr); | ||
} else { | ||
next(...arguments); | ||
} | ||
}); | ||
|
||
registerHandler(function raiseOnDeprecation(message, options, next) { | ||
if (Ember.ENV.RAISE_ON_DEPRECATION) { | ||
let updatedMessage = formatMessage(message); | ||
|
||
throw new EmberError(updatedMessage); | ||
} else { | ||
next(...arguments); | ||
} | ||
}); | ||
|
||
/** | ||
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|Function} test An optional boolean. If falsy, the deprecation | ||
will be displayed. If this is a function, it will be executed and its return | ||
value will be used as condition. | ||
@param {Object} options An optional object that can be used to pass | ||
in a `url` to the transition guide on the emberjs.com website, and a unique | ||
`id` for this deprecation. The `id` can be used by Ember debugging tools | ||
to change the behavior (raise, log or silence) for that specific deprecation. | ||
The `id` should be namespaced by dots, e.g. "view.helper.select". | ||
@public | ||
*/ | ||
export default function() { | ||
invoke('deprecate', ...arguments); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import isPlainFunction from 'ember-debug/is-plain-function'; | ||
|
||
export let HANDLERS = { }; | ||
|
||
function normalizeTest(test) { | ||
return isPlainFunction(test) ? test() : test; | ||
} | ||
|
||
export function registerHandler(type, callback) { | ||
let nextHandler = HANDLERS[type] || function() { }; | ||
|
||
HANDLERS[type] = function(message, options) { | ||
callback(message, options, nextHandler); | ||
}; | ||
} | ||
|
||
export function invoke(type, message, test, options) { | ||
if (normalizeTest(test)) { return; } | ||
|
||
let handlerForType = HANDLERS[type]; | ||
|
||
if (!handlerForType) { return; } | ||
|
||
if (handlerForType) { | ||
handlerForType(message, options); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function isPlainFunction(test) { | ||
return typeof test === 'function' && test.PrototypeMixin === undefined; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import Logger from 'ember-metal/logger'; | ||
import { registerHandler as genericRegisterHandler, invoke } from 'ember-debug/handlers'; | ||
|
||
export function registerHandler(handler) { | ||
genericRegisterHandler('warn', handler); | ||
} | ||
|
||
registerHandler(function logWarning(message, options) { | ||
Logger.warn('WARNING: ' + message); | ||
if ('trace' in Logger) { | ||
Logger.trace(); | ||
} | ||
}); | ||
|
||
/** | ||
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. | ||
@public | ||
*/ | ||
export default function warn() { | ||
invoke('warn', ...arguments); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe you need to evict these somehow in tests, otherwise you will retain deprecations across app and isolated container instances.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you mean, these are global and are not changed per application or container.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah never mind I thought for a second this was going to hold a map of arrays. This is clearly not the case https://github.com/emberjs/ember.js/pull/11833/files#diff-889b83df6e6038c39617a4a40aec777fR12.