-
Notifications
You must be signed in to change notification settings - Fork 684
Add %TypedArray%.prototype.subarray([ begin [, end ] ]) support. #2410
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* Copyright JS Foundation and other contributors, http://js.foundation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
var a = new Int32Array([1, 2, 3, 4, 5]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if the original Int32Array is mapped only to a subarray of the arraybuffer? I would like a test case for that as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. If the new tests aren't what you requested please put your request into pseudocode. |
||
assert(a.subarray().toString() === '1,2,3,4,5'); | ||
assert(a.subarray(3).toString() === '4,5'); | ||
assert(a.subarray(1, 3).toString() === '2,3'); | ||
assert(a.subarray(-3).toString() === '3,4,5'); | ||
assert(a.subarray(-3, -1).toString() === '3,4'); | ||
assert(a.subarray(3, 2).toString() === ''); | ||
assert(a.subarray(-2, -3).toString() === ''); | ||
assert(a.subarray(4, 1).toString() === ''); | ||
assert(a.subarray(-1, -4).toString() === ''); | ||
assert(a.subarray(1).subarray(1).toString() === '3,4,5'); | ||
assert(a.subarray(1, 4).subarray(1, 2).toString() === '3'); | ||
|
||
var b = new Uint8Array([]); | ||
assert(b.subarray(123456, -123456).toString() === ''); | ||
assert(b.subarray().subarray().toString() === ''); | ||
|
||
var ab = new ArrayBuffer(28); | ||
var tmp = new Int32Array(ab); | ||
tmp.set([0, 1, 2, 3, 4, 5, 0]); | ||
var c = new Int32Array(ab, 4, 5); | ||
assert(c.toString() === '1,2,3,4,5'); | ||
assert(c.subarray().toString() === '1,2,3,4,5'); | ||
assert(c.subarray(3).toString() === '4,5'); | ||
assert(c.subarray(1, 3).toString() === '2,3'); | ||
assert(c.subarray(-3).toString() === '3,4,5'); | ||
assert(c.subarray(-3, -1).toString() === '3,4'); | ||
assert(c.subarray(3, 2).toString() === ''); | ||
assert(c.subarray(-2, -3).toString() === ''); | ||
assert(c.subarray(4, 1).toString() === ''); | ||
assert(c.subarray(-1, -4).toString() === ''); | ||
assert(c.subarray(1).subarray(1).toString() === '3,4,5'); | ||
assert(c.subarray(1, 4).subarray(1, 2).toString() === '3'); |
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.
We should return here if
ret_value
contains an error. TheECMA_OP_TO_NUMBER_TRY_CATCH
might fail, so it can fill theret_value
with an error.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.
Done