mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 11:25:00 +00:00
Bug 1398273 - Rename LegacyIterator to PropertyIterator in jsiter. r=luke
And remove more unused legacy iterator stuff. --HG-- extra : rebase_source : dd7bdee142dcbead8c0b630b39800723879c6e76
This commit is contained in:
parent
99cec25d9f
commit
c1a618c582
@ -30,10 +30,6 @@ function LegacyIteratorThrow(exn) {
|
||||
}
|
||||
}
|
||||
|
||||
function LegacyIterator(iter) {
|
||||
callFunction(std_WeakMap_set, LegacyIteratorWrapperMap, this, iter);
|
||||
}
|
||||
|
||||
function LegacyGeneratorIterator(iter) {
|
||||
callFunction(std_WeakMap_set, LegacyIteratorWrapperMap, this, iter);
|
||||
}
|
||||
@ -55,9 +51,6 @@ function InitLegacyIterators() {
|
||||
props[std_iterator].configurable = true;
|
||||
props[std_iterator].writable = true;
|
||||
|
||||
var LegacyIteratorProto = std_Object_create(GetIteratorPrototype(), props);
|
||||
MakeConstructible(LegacyIterator, LegacyIteratorProto);
|
||||
|
||||
props.throw = std_Object_create(null);
|
||||
props.throw.value = LegacyIteratorThrow;
|
||||
props.throw.enumerable = false;
|
||||
@ -70,17 +63,11 @@ function InitLegacyIterators() {
|
||||
LegacyIteratorsInitialized.initialized = true;
|
||||
}
|
||||
|
||||
function NewLegacyIterator(iter, wrapper) {
|
||||
function LegacyGeneratorIteratorShim() {
|
||||
var iter = ToObject(this);
|
||||
|
||||
if (!LegacyIteratorsInitialized.initialized)
|
||||
InitLegacyIterators();
|
||||
|
||||
return new wrapper(iter);
|
||||
}
|
||||
|
||||
function LegacyIteratorShim() {
|
||||
return NewLegacyIterator(ToObject(this), LegacyIterator);
|
||||
}
|
||||
|
||||
function LegacyGeneratorIteratorShim() {
|
||||
return NewLegacyIterator(ToObject(this), LegacyGeneratorIterator);
|
||||
return new LegacyGeneratorIterator(iter);
|
||||
}
|
||||
|
@ -4443,7 +4443,7 @@ IsLegacyIterator(JSContext* cx, unsigned argc, Value* vp)
|
||||
if (args.length() < 1)
|
||||
args.rval().setBoolean(false);
|
||||
else
|
||||
args.rval().setBoolean(IsLegacyIterator(args[0]));
|
||||
args.rval().setBoolean(IsPropertyIterator(args[0]));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1,22 +0,0 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
// Library file for tests to load.
|
||||
|
||||
function Range(start, stop) {
|
||||
this.i = start;
|
||||
this.stop = stop;
|
||||
}
|
||||
Range.prototype = {
|
||||
__iterator__: function() { return this; },
|
||||
next: function() {
|
||||
if (this.i >= this.stop)
|
||||
throw StopIteration;
|
||||
return this.i++;
|
||||
}
|
||||
};
|
||||
|
||||
function range(start, stop) {
|
||||
return new Range(start, stop);
|
||||
}
|
@ -4,8 +4,6 @@
|
||||
* important on ARM as an explicit mask is required at the native instruction
|
||||
* level. */
|
||||
|
||||
load(libdir + 'range.js');
|
||||
|
||||
function testShiftLeft()
|
||||
{
|
||||
var r = [];
|
||||
|
@ -2,8 +2,6 @@
|
||||
* especially important on ARM as an explicit mask is required at the native
|
||||
* instruction level. */
|
||||
|
||||
load(libdir + 'range.js');
|
||||
|
||||
/* Test different combinations of literals/variables. */
|
||||
var s = 4;
|
||||
var t = 100;
|
||||
|
@ -2,8 +2,6 @@
|
||||
* especially important on ARM as an explicit mask is required at the native
|
||||
* instruction level. */
|
||||
|
||||
load(libdir + 'range.js');
|
||||
|
||||
function testShiftRightLogical()
|
||||
{
|
||||
var r = [];
|
||||
|
@ -1005,11 +1005,11 @@ IsObjectInContextCompartment(JSObject* obj, const JSContext* cx);
|
||||
|
||||
/*
|
||||
* NB: keep these in sync with the copy in builtin/SelfHostingDefines.h.
|
||||
* The first three are omitted because they shouldn't be used in new code.
|
||||
* The first two are omitted because they shouldn't be used in new code.
|
||||
*/
|
||||
#define JSITER_ENUMERATE 0x1 /* for-in compatible hidden default iterator */
|
||||
#define JSITER_FOREACH 0x2 /* get obj[key] for each property */
|
||||
#define JSITER_KEYVALUE 0x4 /* obsolete destructuring for-in wants [key, value] */
|
||||
/* 0x4 is no longer used */
|
||||
#define JSITER_OWNONLY 0x8 /* iterate over obj's own properties only */
|
||||
#define JSITER_HIDDEN 0x10 /* also enumerate non-enumerable properties */
|
||||
#define JSITER_SYMBOLS 0x20 /* also include symbol property keys */
|
||||
|
@ -73,12 +73,6 @@ NativeIterator::trace(JSTracer* trc)
|
||||
|
||||
typedef HashSet<jsid, DefaultHasher<jsid>> IdSet;
|
||||
|
||||
static inline bool
|
||||
NewKeyValuePair(JSContext* cx, jsid id, const Value& val, MutableHandleValue rval)
|
||||
{
|
||||
return NewValuePair(cx, IdToValue(id), val, rval);
|
||||
}
|
||||
|
||||
template <bool CheckForDuplicates>
|
||||
static inline bool
|
||||
Enumerate(JSContext* cx, HandleObject pobj, jsid id,
|
||||
@ -542,7 +536,7 @@ js::GetPropertyKeys(JSContext* cx, HandleObject obj, unsigned flags, AutoIdVecto
|
||||
props);
|
||||
}
|
||||
|
||||
static bool legacy_iterator_next(JSContext* cx, unsigned argc, Value* vp);
|
||||
static bool property_iterator_next(JSContext* cx, unsigned argc, Value* vp);
|
||||
|
||||
static inline PropertyIteratorObject*
|
||||
NewPropertyIteratorObject(JSContext* cx, unsigned flags)
|
||||
@ -583,7 +577,7 @@ NewPropertyIteratorObject(JSContext* cx, unsigned flags)
|
||||
// next method on the prototype doesn't break cross-global for .. in.
|
||||
// We don't have to do this for JSITER_ENUMERATE because that object always
|
||||
// takes an optimized path.
|
||||
RootedFunction next(cx, NewNativeFunction(cx, legacy_iterator_next, 0,
|
||||
RootedFunction next(cx, NewNativeFunction(cx, property_iterator_next, 0,
|
||||
HandlePropertyName(cx->names().next)));
|
||||
if (!next)
|
||||
return nullptr;
|
||||
@ -1048,22 +1042,19 @@ NativeIteratorNext(JSContext* cx, NativeIterator* ni, MutableHandleValue rval, b
|
||||
if (!GetProperty(cx, obj, obj, id, rval))
|
||||
return false;
|
||||
|
||||
// JS 1.7 only: for each (let [k, v] in obj)
|
||||
if (ni->flags & JSITER_KEYVALUE)
|
||||
return NewKeyValuePair(cx, id, rval, rval);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
js::IsLegacyIterator(HandleValue v)
|
||||
js::IsPropertyIterator(HandleValue v)
|
||||
{
|
||||
return v.isObject() && v.toObject().hasClass(&PropertyIteratorObject::class_);
|
||||
return v.isObject() && v.toObject().is<PropertyIteratorObject>();
|
||||
}
|
||||
|
||||
MOZ_ALWAYS_INLINE bool
|
||||
legacy_iterator_next_impl(JSContext* cx, const CallArgs& args)
|
||||
property_iterator_next_impl(JSContext* cx, const CallArgs& args)
|
||||
{
|
||||
MOZ_ASSERT(IsLegacyIterator(args.thisv()));
|
||||
MOZ_ASSERT(IsPropertyIterator(args.thisv()));
|
||||
|
||||
RootedObject thisObj(cx, &args.thisv().toObject());
|
||||
|
||||
@ -1084,10 +1075,10 @@ legacy_iterator_next_impl(JSContext* cx, const CallArgs& args)
|
||||
}
|
||||
|
||||
static bool
|
||||
legacy_iterator_next(JSContext* cx, unsigned argc, Value* vp)
|
||||
property_iterator_next(JSContext* cx, unsigned argc, Value* vp)
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
return CallNonGenericMethod<IsLegacyIterator, legacy_iterator_next_impl>(cx, args);
|
||||
return CallNonGenericMethod<IsPropertyIterator, property_iterator_next_impl>(cx, args);
|
||||
}
|
||||
|
||||
size_t
|
||||
@ -1198,9 +1189,6 @@ js::NewStringIteratorObject(JSContext* cx, NewObjectKind newKind)
|
||||
JSObject*
|
||||
js::ValueToIterator(JSContext* cx, unsigned flags, HandleValue vp)
|
||||
{
|
||||
/* JSITER_KEYVALUE must always come with JSITER_FOREACH */
|
||||
MOZ_ASSERT_IF(flags & JSITER_KEYVALUE, flags & JSITER_FOREACH);
|
||||
|
||||
RootedObject obj(cx);
|
||||
if (vp.isObject()) {
|
||||
/* Common case. */
|
||||
|
@ -218,7 +218,7 @@ extern JSObject*
|
||||
CreateIterResultObject(JSContext* cx, HandleValue value, bool done);
|
||||
|
||||
bool
|
||||
IsLegacyIterator(HandleValue v);
|
||||
IsPropertyIterator(HandleValue v);
|
||||
|
||||
extern JSObject*
|
||||
InitStopIterationClass(JSContext* cx, HandleObject obj);
|
||||
|
@ -36,7 +36,7 @@ keys = Object.keys(o),
|
||||
assertEq(arraysEqual(keys, ["a", "b"]), true,
|
||||
"" + keys);
|
||||
|
||||
o = { __iterator__: function() { return Iterator({a: 2, b: 3}); } };
|
||||
o = { __iterator__: function() { throw new Error("non-standard __iterator__ called?"); } };
|
||||
keys = Object.keys(o);
|
||||
assertEq(arraysEqual(keys, ["__iterator__"]), true,
|
||||
"" + keys);
|
||||
|
@ -7,9 +7,7 @@ function makeProxyPrototype(target) {
|
||||
return [];
|
||||
},
|
||||
get(t, pk, r) {
|
||||
// Handle the non-standard __iterator__ hook.
|
||||
if (pk !== "__iterator__")
|
||||
throw new Error("Unexpected [[Get]]: " + String(pk));
|
||||
throw new Error("Unexpected [[Get]]: " + String(pk));
|
||||
}
|
||||
}, {
|
||||
get(t, pk, r) {
|
||||
|
@ -16,7 +16,7 @@ if ("entries" in Object) {
|
||||
entries = Object.entries(o),
|
||||
assertDeepEq(entries, [["a", 17], ["b", 2]]);
|
||||
|
||||
o = { __iterator__: function() { return Iterator({a: 2, b: 3}); } };
|
||||
o = { __iterator__: function() { throw new Error("non-standard __iterator__ called?"); } };
|
||||
entries = Object.entries(o);
|
||||
assertDeepEq(entries, [["__iterator__", o.__iterator__]]);
|
||||
|
||||
|
@ -16,7 +16,7 @@ if ("values" in Object) {
|
||||
values = Object.values(o),
|
||||
assertDeepEq(values, [17, 2]);
|
||||
|
||||
o = { __iterator__: function() { return Iterator({a: 2, b: 3}); } };
|
||||
o = { __iterator__: function() { throw new Error("non-standard __iterator__ called?"); } };
|
||||
values = Object.values(o);
|
||||
assertDeepEq(values, [o.__iterator__]);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user