Throw if first argument to TypedArray.set is a number.
Further refinement to semantics that I have missed in previous change. Both Blink and Firefox are permissive with arguments to .set method. However, when first argument to "set" is a number, all implementations throw, so that users know that a.set(0,27) does not assign 27 to 0th element of a, not 0 to 27th element of a. R=bmeurer@chromium.org Review URL: https://codereview.chromium.org/19210002 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15684 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
c0637c1828
commit
11a38ed875
@ -154,6 +154,13 @@ function TypedArraySet(obj, offset) {
|
||||
|
||||
var l = obj.length;
|
||||
if (IS_UNDEFINED(l)) {
|
||||
if (IS_NUMBER(obj)) {
|
||||
// For number as a first argument, throw TypeError
|
||||
// instead of silently ignoring the call, so that
|
||||
// the user knows (s)he did something wrong.
|
||||
// (Consistent with Firefox and Blink/WebKit)
|
||||
throw MakeTypeError("invalid_argument");
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (intOffset + l > this.length) {
|
||||
|
@ -606,7 +606,7 @@ a61.set(a62)
|
||||
assertArrayPrefix([1, 12], a61)
|
||||
|
||||
// Invalid source
|
||||
a.set(0); // does not throw
|
||||
assertThrows(function() { a.set(0); }, TypeError);
|
||||
assertArrayPrefix([1,2,3,4,5,6], a);
|
||||
a.set({}); // does not throw
|
||||
assertArrayPrefix([1,2,3,4,5,6], a);
|
||||
|
@ -605,7 +605,7 @@ a61.set(a62)
|
||||
assertArrayPrefix([1, 12], a61)
|
||||
|
||||
// Invalid source
|
||||
a.set(0); // does not throw
|
||||
assertThrows(function() { a.set(0); }, TypeError);
|
||||
assertArrayPrefix([1,2,3,4,5,6], a);
|
||||
a.set({}); // does not throw
|
||||
assertArrayPrefix([1,2,3,4,5,6], a);
|
||||
|
@ -458,12 +458,13 @@ function TestTypedArraySet() {
|
||||
a[i] = i;
|
||||
expected.push(i);
|
||||
}
|
||||
a.set(0);
|
||||
assertArrayPrefix(expected, a);
|
||||
a.set({});
|
||||
assertArrayPrefix(expected, a);
|
||||
assertThrows(function() { a.set.call({}) }, TypeError);
|
||||
assertThrows(function() { a.set.call([]) }, TypeError);
|
||||
|
||||
assertThrows(function() { a.set(0); }, TypeError);
|
||||
assertThrows(function() { a.set(0, 1); }, TypeError);
|
||||
}
|
||||
|
||||
TestTypedArraySet();
|
||||
|
Loading…
Reference in New Issue
Block a user