1// Copyright 2014 the V8 project authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5'use strict'; 6 7 8// This file relies on the fact that the following declaration has been made 9// in runtime.js: 10// var $Set = global.Set; 11// var $Map = global.Map; 12 13 14function SetIteratorConstructor(set, kind) { 15 %SetIteratorInitialize(this, set, kind); 16} 17 18 19function SetIteratorNextJS() { 20 if (!IS_SET_ITERATOR(this)) { 21 throw MakeTypeError('incompatible_method_receiver', 22 ['Set Iterator.prototype.next', this]); 23 } 24 return %SetIteratorNext(this); 25} 26 27 28function SetIteratorSymbolIterator() { 29 return this; 30} 31 32 33function SetEntries() { 34 if (!IS_SET(this)) { 35 throw MakeTypeError('incompatible_method_receiver', 36 ['Set.prototype.entries', this]); 37 } 38 return new SetIterator(this, ITERATOR_KIND_ENTRIES); 39} 40 41 42function SetValues() { 43 if (!IS_SET(this)) { 44 throw MakeTypeError('incompatible_method_receiver', 45 ['Set.prototype.values', this]); 46 } 47 return new SetIterator(this, ITERATOR_KIND_VALUES); 48} 49 50 51function SetUpSetIterator() { 52 %CheckIsBootstrapping(); 53 54 %SetCode(SetIterator, SetIteratorConstructor); 55 %FunctionSetPrototype(SetIterator, new $Object()); 56 %FunctionSetInstanceClassName(SetIterator, 'Set Iterator'); 57 InstallFunctions(SetIterator.prototype, DONT_ENUM, $Array( 58 'next', SetIteratorNextJS 59 )); 60 61 %FunctionSetName(SetIteratorSymbolIterator, '[Symbol.iterator]'); 62 %SetProperty(SetIterator.prototype, symbolIterator, 63 SetIteratorSymbolIterator, DONT_ENUM); 64} 65 66SetUpSetIterator(); 67 68 69function ExtendSetPrototype() { 70 %CheckIsBootstrapping(); 71 72 InstallFunctions($Set.prototype, DONT_ENUM, $Array( 73 'entries', SetEntries, 74 'values', SetValues 75 )); 76 77 %SetProperty($Set.prototype, symbolIterator, SetValues, 78 DONT_ENUM); 79} 80 81ExtendSetPrototype(); 82 83 84 85function MapIteratorConstructor(map, kind) { 86 %MapIteratorInitialize(this, map, kind); 87} 88 89 90function MapIteratorSymbolIterator() { 91 return this; 92} 93 94 95function MapIteratorNextJS() { 96 if (!IS_MAP_ITERATOR(this)) { 97 throw MakeTypeError('incompatible_method_receiver', 98 ['Map Iterator.prototype.next', this]); 99 } 100 return %MapIteratorNext(this); 101} 102 103 104function MapEntries() { 105 if (!IS_MAP(this)) { 106 throw MakeTypeError('incompatible_method_receiver', 107 ['Map.prototype.entries', this]); 108 } 109 return new MapIterator(this, ITERATOR_KIND_ENTRIES); 110} 111 112 113function MapKeys() { 114 if (!IS_MAP(this)) { 115 throw MakeTypeError('incompatible_method_receiver', 116 ['Map.prototype.keys', this]); 117 } 118 return new MapIterator(this, ITERATOR_KIND_KEYS); 119} 120 121 122function MapValues() { 123 if (!IS_MAP(this)) { 124 throw MakeTypeError('incompatible_method_receiver', 125 ['Map.prototype.values', this]); 126 } 127 return new MapIterator(this, ITERATOR_KIND_VALUES); 128} 129 130 131function SetUpMapIterator() { 132 %CheckIsBootstrapping(); 133 134 %SetCode(MapIterator, MapIteratorConstructor); 135 %FunctionSetPrototype(MapIterator, new $Object()); 136 %FunctionSetInstanceClassName(MapIterator, 'Map Iterator'); 137 InstallFunctions(MapIterator.prototype, DONT_ENUM, $Array( 138 'next', MapIteratorNextJS 139 )); 140 141 %FunctionSetName(MapIteratorSymbolIterator, '[Symbol.iterator]'); 142 %SetProperty(MapIterator.prototype, symbolIterator, 143 MapIteratorSymbolIterator, DONT_ENUM); 144} 145 146SetUpMapIterator(); 147 148 149function ExtendMapPrototype() { 150 %CheckIsBootstrapping(); 151 152 InstallFunctions($Map.prototype, DONT_ENUM, $Array( 153 'entries', MapEntries, 154 'keys', MapKeys, 155 'values', MapValues 156 )); 157 158 %SetProperty($Map.prototype, symbolIterator, MapEntries, 159 DONT_ENUM); 160} 161 162ExtendMapPrototype(); 163