Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit258ca1e

Browse files
authored
Deferred: RenamegetStackHook togetErrorHook
Rename `jQuery.Deferred.getStackHook` to `jQuery.Deferred.getErrorHook`to indicate passing an error instance is usually a better choice - itworks with source maps while a raw stack generally does not.In jQuery `3.7.0`, we'll keep both names, marking the old one asdeprecated. In jQuery `4.0.0` we'll just keep the new one. Thischange implements the `4.0.0` version; PRgh-5212 implementsthe `3.7.0` one.Fixesgh-5201Closesgh-5211Refgh-5212
1 parentf088c36 commit258ca1e

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

‎src/deferred.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ jQuery.extend( {
188188

189189
if(jQuery.Deferred.exceptionHook){
190190
jQuery.Deferred.exceptionHook(e,
191-
process.stackTrace);
191+
process.error);
192192
}
193193

194194
// Support: Promises/A+ section 2.3.3.3.4.1
@@ -216,10 +216,10 @@ jQuery.extend( {
216216
process();
217217
}else{
218218

219-
// Call an optional hook to record thestack, in case of exception
219+
// Call an optional hook to record theerror, in case of exception
220220
// since it's otherwise lost when execution goes async
221-
if(jQuery.Deferred.getStackHook){
222-
process.stackTrace=jQuery.Deferred.getStackHook();
221+
if(jQuery.Deferred.getErrorHook){
222+
process.error=jQuery.Deferred.getErrorHook();
223223
}
224224
window.setTimeout(process);
225225
}

‎src/deferred/exceptionHook.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ import "../deferred.js";
66
// warn about them ASAP rather than swallowing them by default.
77
varrerrorNames=/^(Eval|Internal|Range|Reference|Syntax|Type|URI)Error$/;
88

9-
jQuery.Deferred.exceptionHook=function(error,stack){
9+
// If `jQuery.Deferred.getErrorHook` is defined, `asyncError` is an error
10+
// captured before the async barrier to get the original error cause
11+
// which may otherwise be hidden.
12+
jQuery.Deferred.exceptionHook=function(error,asyncError){
1013

1114
if(error&&rerrorNames.test(error.name)){
1215
window.console.warn(
1316
"jQuery.Deferred exception",
1417
error,
15-
stack
18+
asyncError
1619
);
1720
}
1821
};

‎test/unit/deferred.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -602,34 +602,34 @@ QUnit.test( "jQuery.Deferred.exceptionHook", function( assert ) {
602602
defer.resolve();
603603
});
604604

605-
QUnit.test("jQuery.Deferred.exceptionHook withstack hooks",function(assert){
605+
QUnit.test("jQuery.Deferred.exceptionHook witherror hooks",function(assert){
606606

607607
assert.expect(2);
608608

609609
vardone=assert.async(),
610610
defer=jQuery.Deferred(),
611611
oldWarn=window.console.warn;
612612

613-
jQuery.Deferred.getStackHook=function(){
613+
jQuery.Deferred.getErrorHook=function(){
614614

615615
// Default exceptionHook assumes the stack is in a form console.warn can log,
616-
// but a customgetStackHook+exceptionHook pair could save a raw form and
616+
// but a customgetErrorHook+exceptionHook pair could save a raw form and
617617
// format it to a string only when an exception actually occurs.
618618
// For the unit test we just ensure the plumbing works.
619-
return"NOSTACK FOR YOU";
619+
return"NOERROR FOR YOU";
620620
};
621621

622622
window.console.warn=function(){
623623
varmsg=Array.prototype.join.call(arguments," ");
624624
assert.ok(/cough_up_hairball/.test(msg),"Function mentioned: "+msg);
625-
assert.ok(/NOSTACKFORYOU/.test(msg),"Stack trace included: "+msg);
625+
assert.ok(/NOERRORFORYOU/.test(msg),"Error included: "+msg);
626626
};
627627

628628
defer.then(function(){
629629
jQuery.cough_up_hairball();
630630
}).then(null,function(){
631631
window.console.warn=oldWarn;
632-
deletejQuery.Deferred.getStackHook;
632+
deletejQuery.Deferred.getErrorHook;
633633
done();
634634
});
635635

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp