Bug 952873 part 2. Expose JSAPI for doing for-of iteration. r=jorendorff
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
#include "jsarray.h"
|
||||
#include "jsatom.h"
|
||||
#include "jscntxt.h"
|
||||
#include "jsfriendapi.h"
|
||||
#include "jsgc.h"
|
||||
#include "jsobj.h"
|
||||
#include "jsopcode.h"
|
||||
@@ -39,6 +40,7 @@
|
||||
|
||||
using namespace js;
|
||||
using namespace js::gc;
|
||||
using JS::ForOfIterator;
|
||||
|
||||
using mozilla::ArrayLength;
|
||||
#ifdef JS_MORE_DETERMINISTIC
|
||||
@@ -1268,8 +1270,8 @@ const Class StopIterationObject::class_ = {
|
||||
nullptr /* construct */
|
||||
};
|
||||
|
||||
bool
|
||||
ForOfIterator::init(HandleValue iterable)
|
||||
JS_FRIEND_API(bool)
|
||||
ForOfIterator::init(HandleValue iterable, NonIterableBehavior nonIterableBehavior)
|
||||
{
|
||||
JSContext *cx = cx_;
|
||||
RootedObject iterableObj(cx, ToObject(cx, iterable));
|
||||
@@ -1286,10 +1288,13 @@ ForOfIterator::init(HandleValue iterable)
|
||||
if (!JSObject::getProperty(cx, iterableObj, iterableObj, cx->names().std_iterator, &callee))
|
||||
return false;
|
||||
|
||||
// Throw if obj[@@iterator] isn't callable. js::Invoke is about to check
|
||||
// for this kind of error anyway, but it would throw an inscrutable
|
||||
// error message about |method| rather than this nice one about |obj|.
|
||||
// Throw if obj[@@iterator] isn't callable if we were asked to do so.
|
||||
// js::Invoke is about to check for this kind of error anyway, but it would
|
||||
// throw an inscrutable error message about |method| rather than this nice
|
||||
// one about |obj|.
|
||||
if (!callee.isObject() || !callee.toObject().isCallable()) {
|
||||
if (nonIterableBehavior == AllowNonIterable)
|
||||
return true;
|
||||
char *bytes = DecompileValueGenerator(cx, JSDVG_SEARCH_STACK, iterable, NullPtr());
|
||||
if (!bytes)
|
||||
return false;
|
||||
@@ -1309,7 +1314,7 @@ ForOfIterator::init(HandleValue iterable)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
JS_FRIEND_API(bool)
|
||||
ForOfIterator::next(MutableHandleValue vp, bool *done)
|
||||
{
|
||||
JS_ASSERT(iterator);
|
||||
|
||||
Reference in New Issue
Block a user