зеркало из https://github.com/mozilla/gecko-dev.git
Bug 725907 - for-of improvements, part 5: Make ctypes arrays iterable. r=bhackett.
--HG-- extra : rebase_source : 598baa07d9cfa41255aadff979ca8319e288a05b
This commit is contained in:
Родитель
8b0cc30abf
Коммит
2653778cd0
|
@ -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
|
||||
};
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
Загрузка…
Ссылка в новой задаче