TypedArray constructor throws TypeError when it should throw RangeError

RESOLVED FIXED in Firefox 49

Status

()

Core
JavaScript Engine
RESOLVED FIXED
3 years ago
2 years ago

People

(Reporter: lth, Assigned: lth)

Tracking

(Blocks: 1 bug)

unspecified
mozilla49
Points:
---

Firefox Tracking Flags

(firefox49 fixed)

Details

Attachments

(1 attachment)

(Assignee)

Description

3 years ago
Today's mozilla-inbound.  I think it's been this way for a while.

The spec 22.2.1.5 says that TypedArray should throw RangeError if the start offset does not divide the element size or if the end offset minus the start offset does not divide the element size.  SpiderMonkey throws TypeError in both cases.

js> var AB = new ArrayBuffer(12)
js> new Int32Array(AB, 2)
typein:3:1 TypeError: invalid arguments
Stack:
  @typein:3:1
js> var BC = new ArrayBuffer(14)
js> new Int32Array(BC)
typein:5:1 TypeError: invalid arguments
Stack:
  @typein:5:1
js>
(Assignee)

Updated

3 years ago
Blocks: 694100
(Assignee)

Comment 1

2 years ago
Jason, isn't there a bug for tracking spec deviations like this?
Flags: needinfo?(jorendorff)
No, there's not a separate meta bug for functionality that's implemented in a buggy way. Bug 694100 is the right block-ee for all deviations from spec.
Flags: needinfo?(jorendorff)
(Assignee)

Comment 5

2 years ago
Created attachment 8753827 [details] [diff] [review]
throw correct error type
Attachment #8753827 - Flags: review?(jorendorff)
(Assignee)

Updated

2 years ago
Assignee: nobody → lhansen
Status: NEW → ASSIGNED
Comment on attachment 8753827 [details] [diff] [review]
throw correct error type

Review of attachment 8753827 [details] [diff] [review]:
-----------------------------------------------------------------

Thanks!

::: js/src/vm/TypedArrayObject.cpp
@@ +604,5 @@
>              buffer = static_cast<ArrayBufferObjectMaybeShared*>(&AsSharedArrayBuffer(bufobj));
>          }
>  
>          if (byteOffset > buffer->byteLength() || byteOffset % sizeof(NativeType) != 0) {
> +            JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_BAD_INDEX);

The error message this makes is technically correct and *maybe* better than "invalid arguments" but not ideal.
We could splurge and add another error message to js.msg. Your call.
Attachment #8753827 - Flags: review?(jorendorff) → review+

Comment 8

2 years ago
bugherder
https://hg.mozilla.org/mozilla-central/rev/8302c77d1f23
Status: ASSIGNED → RESOLVED
Last Resolved: 2 years ago
status-firefox49: --- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla49
You need to log in before you can comment on or make changes to this bug.