michael@0: // String.prototype.iterator is generic. michael@0: michael@0: load(libdir + "asserts.js"); michael@0: load(libdir + "iteration.js"); michael@0: load(libdir + "string.js"); michael@0: michael@0: function test(obj) { michael@0: var it = String.prototype[std_iterator].call(obj); michael@0: var s = String(obj); michael@0: for (var i = 0, length = s.length; i < length;) { michael@0: var r = s[i++]; michael@0: if (isHighSurrogate(r) && i < length && isLowSurrogate(s[i])) { michael@0: r += s[i++]; michael@0: } michael@0: assertIteratorNext(it, r); michael@0: } michael@0: assertIteratorDone(it, undefined); michael@0: } michael@0: michael@0: test({toString: () => ""}); michael@0: test({toString: () => "xyz"}); michael@0: test({toString: () => "\ud808\udf45"}); michael@0: test({valueOf: () => ""}); michael@0: test({valueOf: () => "xyz"}); michael@0: test({valueOf: () => "\ud808\udf45"});