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
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) {
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);
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);
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();