2014-06-03 00:34:01 +00:00
|
|
|
// Copyright 2014 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2015-04-16 12:17:46 +00:00
|
|
|
var $mapEntries;
|
|
|
|
var $mapIteratorNext;
|
|
|
|
var $setIteratorNext;
|
|
|
|
var $setValues;
|
|
|
|
|
2015-05-20 15:59:51 +00:00
|
|
|
(function(global, shared, exports) {
|
2015-04-16 12:17:46 +00:00
|
|
|
|
2014-12-10 14:40:54 +00:00
|
|
|
"use strict";
|
2014-06-03 00:34:01 +00:00
|
|
|
|
2015-04-16 12:17:46 +00:00
|
|
|
%CheckIsBootstrapping();
|
2014-06-03 00:34:01 +00:00
|
|
|
|
2015-04-16 12:17:46 +00:00
|
|
|
var GlobalMap = global.Map;
|
|
|
|
var GlobalSet = global.Set;
|
2014-06-03 00:34:01 +00:00
|
|
|
|
2015-04-16 12:17:46 +00:00
|
|
|
// -------------------------------------------------------------------
|
2014-06-03 00:34:01 +00:00
|
|
|
|
|
|
|
function SetIteratorConstructor(set, kind) {
|
|
|
|
%SetIteratorInitialize(this, set, kind);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function SetIteratorNextJS() {
|
|
|
|
if (!IS_SET_ITERATOR(this)) {
|
2015-04-17 08:35:59 +00:00
|
|
|
throw MakeTypeError(kIncompatibleMethodReceiver,
|
|
|
|
'Set Iterator.prototype.next', this);
|
2014-06-03 00:34:01 +00:00
|
|
|
}
|
2014-06-26 00:40:45 +00:00
|
|
|
|
|
|
|
var value_array = [UNDEFINED, UNDEFINED];
|
|
|
|
var entry = {value: value_array, done: false};
|
|
|
|
switch (%SetIteratorNext(this, value_array)) {
|
|
|
|
case 0:
|
|
|
|
entry.value = UNDEFINED;
|
|
|
|
entry.done = true;
|
|
|
|
break;
|
|
|
|
case ITERATOR_KIND_VALUES:
|
|
|
|
entry.value = value_array[0];
|
|
|
|
break;
|
|
|
|
case ITERATOR_KIND_ENTRIES:
|
|
|
|
value_array[1] = value_array[0];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return entry;
|
2014-06-03 00:34:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function SetEntries() {
|
|
|
|
if (!IS_SET(this)) {
|
2015-04-17 08:35:59 +00:00
|
|
|
throw MakeTypeError(kIncompatibleMethodReceiver,
|
|
|
|
'Set.prototype.entries', this);
|
2014-06-03 00:34:01 +00:00
|
|
|
}
|
|
|
|
return new SetIterator(this, ITERATOR_KIND_ENTRIES);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function SetValues() {
|
|
|
|
if (!IS_SET(this)) {
|
2015-04-17 08:35:59 +00:00
|
|
|
throw MakeTypeError(kIncompatibleMethodReceiver,
|
|
|
|
'Set.prototype.values', this);
|
2014-06-03 00:34:01 +00:00
|
|
|
}
|
|
|
|
return new SetIterator(this, ITERATOR_KIND_VALUES);
|
|
|
|
}
|
|
|
|
|
2015-04-16 12:17:46 +00:00
|
|
|
// -------------------------------------------------------------------
|
2014-06-03 00:34:01 +00:00
|
|
|
|
2015-04-16 12:17:46 +00:00
|
|
|
%SetCode(SetIterator, SetIteratorConstructor);
|
2015-05-15 15:09:46 +00:00
|
|
|
%FunctionSetPrototype(SetIterator, {__proto__: $iteratorPrototype});
|
2015-04-16 12:17:46 +00:00
|
|
|
%FunctionSetInstanceClassName(SetIterator, 'Set Iterator');
|
2015-05-05 09:15:56 +00:00
|
|
|
$installFunctions(SetIterator.prototype, DONT_ENUM, [
|
2015-04-16 12:17:46 +00:00
|
|
|
'next', SetIteratorNextJS
|
|
|
|
]);
|
2014-06-03 00:34:01 +00:00
|
|
|
|
2015-04-16 12:17:46 +00:00
|
|
|
%AddNamedProperty(SetIterator.prototype, symbolToStringTag,
|
|
|
|
"Set Iterator", READ_ONLY | DONT_ENUM);
|
2014-06-03 00:34:01 +00:00
|
|
|
|
2015-05-05 09:15:56 +00:00
|
|
|
$installFunctions(GlobalSet.prototype, DONT_ENUM, [
|
2015-04-16 12:17:46 +00:00
|
|
|
'entries', SetEntries,
|
|
|
|
'keys', SetValues,
|
|
|
|
'values', SetValues
|
|
|
|
]);
|
2014-06-03 00:34:01 +00:00
|
|
|
|
2015-04-16 12:17:46 +00:00
|
|
|
%AddNamedProperty(GlobalSet.prototype, symbolIterator, SetValues, DONT_ENUM);
|
2014-06-03 00:34:01 +00:00
|
|
|
|
2015-04-16 12:17:46 +00:00
|
|
|
$setIteratorNext = SetIteratorNextJS;
|
|
|
|
$setValues = SetValues;
|
2014-06-03 00:34:01 +00:00
|
|
|
|
2015-04-16 12:17:46 +00:00
|
|
|
// -------------------------------------------------------------------
|
2014-06-03 00:34:01 +00:00
|
|
|
|
|
|
|
function MapIteratorConstructor(map, kind) {
|
|
|
|
%MapIteratorInitialize(this, map, kind);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function MapIteratorNextJS() {
|
|
|
|
if (!IS_MAP_ITERATOR(this)) {
|
2015-04-17 08:35:59 +00:00
|
|
|
throw MakeTypeError(kIncompatibleMethodReceiver,
|
|
|
|
'Map Iterator.prototype.next', this);
|
2014-06-03 00:34:01 +00:00
|
|
|
}
|
2014-06-26 00:40:45 +00:00
|
|
|
|
|
|
|
var value_array = [UNDEFINED, UNDEFINED];
|
|
|
|
var entry = {value: value_array, done: false};
|
|
|
|
switch (%MapIteratorNext(this, value_array)) {
|
|
|
|
case 0:
|
|
|
|
entry.value = UNDEFINED;
|
|
|
|
entry.done = true;
|
|
|
|
break;
|
|
|
|
case ITERATOR_KIND_KEYS:
|
|
|
|
entry.value = value_array[0];
|
|
|
|
break;
|
|
|
|
case ITERATOR_KIND_VALUES:
|
|
|
|
entry.value = value_array[1];
|
|
|
|
break;
|
|
|
|
// ITERATOR_KIND_ENTRIES does not need any processing.
|
|
|
|
}
|
|
|
|
|
|
|
|
return entry;
|
2014-06-03 00:34:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function MapEntries() {
|
|
|
|
if (!IS_MAP(this)) {
|
2015-04-17 08:35:59 +00:00
|
|
|
throw MakeTypeError(kIncompatibleMethodReceiver,
|
|
|
|
'Map.prototype.entries', this);
|
2014-06-03 00:34:01 +00:00
|
|
|
}
|
|
|
|
return new MapIterator(this, ITERATOR_KIND_ENTRIES);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function MapKeys() {
|
|
|
|
if (!IS_MAP(this)) {
|
2015-04-17 08:35:59 +00:00
|
|
|
throw MakeTypeError(kIncompatibleMethodReceiver,
|
|
|
|
'Map.prototype.keys', this);
|
2014-06-03 00:34:01 +00:00
|
|
|
}
|
|
|
|
return new MapIterator(this, ITERATOR_KIND_KEYS);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function MapValues() {
|
|
|
|
if (!IS_MAP(this)) {
|
2015-04-17 08:35:59 +00:00
|
|
|
throw MakeTypeError(kIncompatibleMethodReceiver,
|
|
|
|
'Map.prototype.values', this);
|
2014-06-03 00:34:01 +00:00
|
|
|
}
|
|
|
|
return new MapIterator(this, ITERATOR_KIND_VALUES);
|
|
|
|
}
|
|
|
|
|
2015-04-16 12:17:46 +00:00
|
|
|
// -------------------------------------------------------------------
|
2014-06-03 00:34:01 +00:00
|
|
|
|
2015-04-16 12:17:46 +00:00
|
|
|
%SetCode(MapIterator, MapIteratorConstructor);
|
2015-05-15 15:09:46 +00:00
|
|
|
%FunctionSetPrototype(MapIterator, {__proto__: $iteratorPrototype});
|
2015-04-16 12:17:46 +00:00
|
|
|
%FunctionSetInstanceClassName(MapIterator, 'Map Iterator');
|
2015-05-05 09:15:56 +00:00
|
|
|
$installFunctions(MapIterator.prototype, DONT_ENUM, [
|
2015-04-16 12:17:46 +00:00
|
|
|
'next', MapIteratorNextJS
|
|
|
|
]);
|
2014-06-03 00:34:01 +00:00
|
|
|
|
2015-04-16 12:17:46 +00:00
|
|
|
%AddNamedProperty(MapIterator.prototype, symbolToStringTag,
|
|
|
|
"Map Iterator", READ_ONLY | DONT_ENUM);
|
2014-06-03 00:34:01 +00:00
|
|
|
|
|
|
|
|
2015-05-05 09:15:56 +00:00
|
|
|
$installFunctions(GlobalMap.prototype, DONT_ENUM, [
|
2015-04-16 12:17:46 +00:00
|
|
|
'entries', MapEntries,
|
|
|
|
'keys', MapKeys,
|
|
|
|
'values', MapValues
|
|
|
|
]);
|
2014-06-03 00:34:01 +00:00
|
|
|
|
2015-04-16 12:17:46 +00:00
|
|
|
%AddNamedProperty(GlobalMap.prototype, symbolIterator, MapEntries, DONT_ENUM);
|
2014-06-03 00:34:01 +00:00
|
|
|
|
2015-04-16 12:17:46 +00:00
|
|
|
$mapEntries = MapEntries;
|
|
|
|
$mapIteratorNext = MapIteratorNextJS;
|
2014-06-03 00:34:01 +00:00
|
|
|
|
2015-05-11 08:14:54 +00:00
|
|
|
})
|