Closed Bug 312138 Opened 20 years ago Closed 20 years ago

Array.sort swallows JS exceptions (ecma_3/Array/15.4.4.11-01.js)

Categories

(Core :: JavaScript Engine, defect)

x86
Linux
defect
Not set
normal

Tracking

()

VERIFIED FIXED

People

(Reporter: igor, Assigned: igor)

References

()

Details

(Keywords: verified1.8.1)

Attachments

(2 files, 2 obsolete files)

Consider the following example: var N = 0; var array = [4,3,2,1]; try { array.sort(function() { throw ++N; }); } catch (e) { print("e="+e+" N="+N); } When executed in jsshell it prints "e=5 N=5" instead of expected "e=1 N=1" as Array.prototype.sort implementation swallows all JS exceptions except the last generated during sort execution. A similar problem is with aborting too-long running script. Try to execute [0,1,2].sort(function() { for (;;) continue; }) in the browser, it would ask to terminate the script exactly the number of times the comparison function is called.
Attached patch Fix (obsolete) — Splinter Review
The patch adds error propagation to HeapSort so it would return immediately after a failed compare call.
Summary: Array.sort swallows JS execeptions → Array.sort swallows JS exceptions
Checking in 15.4.4.11-01.js; /cvsroot/mozilla/js/tests/ecma_3/Array/15.4.4.11-01.js,v <-- 15.4.4.11-01.js initial revision: 1.1 done
Flags: testcase+
Igor, are you willing to take this bug, request review on the patch, and get it checked in? That would be a help. The CVS trunk is open for 1.9alpha changes, and only one review stamp of approval is required for SpiderMonkey changes. Let me know if you'd rather someone else take this. /be
(In reply to comment #3) > Igor, are you willing to take this bug, request review on the patch, and get it > checked in? I will ask for review some time next week or so.
Status: NEW → ASSIGNED
Assignee: general → igor.bukanov
Status: ASSIGNED → NEW
Status: NEW → ASSIGNED
Attachment #199273 - Attachment is obsolete: true
Attachment #201253 - Flags: review?(brendan)
Comment on attachment 201253 [details] [diff] [review] Updated fix to reflect trunk changes I'll get to this by end of tomorrow for sure. Higher priority stuff in the short run, bear with me. /be
Attachment #201253 - Attachment is obsolete: true
Attachment #203129 - Flags: review?(brendan)
Attachment #201253 - Flags: review?(brendan)
Comment on attachment 203129 [details] [diff] [review] Updated fix to reflect trunk changes No need for goto done and goto quit if those labels are affixed to return statements -- just return true or false at the goto site. r=me with that change. /be
Attachment #203129 - Flags: review?(brendan) → review+
Attached patch Patch to commitSplinter Review
Patch with goto->return changes to reflect above comment.
I committed the last patch
Status: ASSIGNED → RESOLVED
Closed: 20 years ago
Resolution: --- → FIXED
verified fixed cvs trunk builds 2005-11-23 windows/linux
Status: RESOLVED → VERIFIED
Summary: Array.sort swallows JS exceptions → Array.sort swallows JS exceptions (ecma_3/Array/15.4.4.11-01.js)
fixed by Bug 336373 on the 1.8.1 branch. verified fixed 1.8.1 with windows/macppc/linux 20060707
Keywords: verified1.8.1
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: