Bug 725907 - for-of improvements, part 5: Make ctypes arrays iterable. r=bhackett.

--HG--
extra : rebase_source : 598baa07d9cfa41255aadff979ca8319e288a05b
This commit is contained in:
Jason Orendorff 2012-07-04 10:24:06 -05:00
parent f9a50fa00d
commit 0d459625e3
2 changed files with 18 additions and 0 deletions

View File

@ -514,6 +514,7 @@ static JSPropertySpec sArrayProps[] = {
static JSFunctionSpec sArrayInstanceFunctions[] = {
JS_FN("addressOfElement", ArrayType::AddressOfElement, 1, CDATAFN_FLAGS),
JS_FN("iterator", JS_ArrayIterator, 0, CDATAFN_FLAGS),
JS_FS_END
};

View File

@ -0,0 +1,17 @@
// for-of works on CData objects of array type, but throws for other CData objects.
if (this.ctypes) {
load(libdir + "asserts.js");
var v = ctypes.int32_t(17);
assertThrowsInstanceOf(function () { for (var x of v) ; }, TypeError);
var intarray_t = ctypes.int32_t.array();
var a = new intarray_t([0, 1, 1, 2, 3]);
var b = [x for (x of a)];
assertEq(b.join(), '0,1,1,2,3');
var it = a.iterator();
assertEq(it.next(), 0);
a[1] = -100;
assertEq(it.next(), -100);
}