Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 "use strict"; | 5 "use strict"; |
| 6 | 6 |
| 7 // This file relies on the fact that the following declaration has been made | 7 // This file relies on the fact that the following declaration has been made |
| 8 // in runtime.js: | 8 // in runtime.js: |
| 9 // var $Array = global.Array; | 9 // var $Array = global.Array; |
| 10 | 10 |
| 11 var $Set = global.Set; | 11 var $Set = global.Set; |
| 12 var $Map = global.Map; | 12 var $Map = global.Map; |
| 13 | 13 |
| 14 | 14 |
| 15 // 7.4.1 CheckIterable ( obj ) | |
|
arv (Not doing code reviews)
2014/06/18 21:02:05
This should probably go in v8natives.js once this
rossberg
2014/06/23 14:16:00
Agreed. Maybe add a TODO to that end?
We could al
arv (Not doing code reviews)
2014/06/23 15:43:56
Done.
| |
| 16 function CheckIterable(obj) { | |
| 17 if (!IS_SPEC_OBJECT(obj)) { | |
| 18 return UNDEFINED; | |
| 19 } | |
| 20 return obj[symbolIterator]; | |
| 21 } | |
| 22 | |
| 23 | |
| 24 // 7.4.2 GetIterator ( obj, method ) | |
| 25 function GetIterator(obj, method) { | |
| 26 if (IS_UNDEFINED(method)) { | |
| 27 method = CheckIterable(obj); | |
| 28 } | |
| 29 if (!IS_SPEC_FUNCTION(method)) { | |
| 30 throw MakeTypeError('not_iterable', [obj]); | |
| 31 } | |
| 32 var iterator = %_CallFunction(obj, method); | |
| 33 if (!IS_SPEC_OBJECT(iterator)) { | |
| 34 throw MakeTypeError('not_an_iterator', [iterator]); | |
| 35 } | |
| 36 return iterator; | |
| 37 } | |
| 38 | |
| 39 | |
| 15 // ------------------------------------------------------------------- | 40 // ------------------------------------------------------------------- |
| 16 // Harmony Set | 41 // Harmony Set |
| 17 | 42 |
| 18 function SetConstructor() { | 43 function SetConstructor(iterable) { |
| 19 if (%_IsConstructCall()) { | 44 if (!%_IsConstructCall()) { |
| 20 %SetInitialize(this); | |
| 21 } else { | |
| 22 throw MakeTypeError('constructor_not_function', ['Set']); | 45 throw MakeTypeError('constructor_not_function', ['Set']); |
| 23 } | 46 } |
| 47 | |
| 48 var iter, adder; | |
| 49 | |
| 50 if (!IS_NULL_OR_UNDEFINED(iterable)) { | |
| 51 iter = GetIterator(iterable); | |
| 52 adder = this.add; | |
| 53 if (!IS_SPEC_FUNCTION(adder)) { | |
| 54 throw MakeTypeError('property_not_function', ['add', this]); | |
| 55 } | |
| 56 } | |
| 57 | |
| 58 %SetInitialize(this); | |
| 59 | |
| 60 if (IS_UNDEFINED(iter)) return; | |
| 61 | |
| 62 var next, done; | |
| 63 while (!(next = iter.next()).done) { | |
| 64 if (!IS_SPEC_OBJECT(next)) { | |
| 65 throw MakeTypeError('not_an_object', [next]); | |
| 66 } | |
| 67 %_CallFunction(this, next.value, adder); | |
| 68 } | |
| 24 } | 69 } |
| 25 | 70 |
| 26 | 71 |
| 27 function SetAddJS(key) { | 72 function SetAddJS(key) { |
| 28 if (!IS_SET(this)) { | 73 if (!IS_SET(this)) { |
| 29 throw MakeTypeError('incompatible_method_receiver', | 74 throw MakeTypeError('incompatible_method_receiver', |
| 30 ['Set.prototype.add', this]); | 75 ['Set.prototype.add', this]); |
| 31 } | 76 } |
| 32 return %SetAdd(this, key); | 77 return %SetAdd(this, key); |
| 33 } | 78 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 "forEach", SetForEach | 155 "forEach", SetForEach |
| 111 )); | 156 )); |
| 112 } | 157 } |
| 113 | 158 |
| 114 SetUpSet(); | 159 SetUpSet(); |
| 115 | 160 |
| 116 | 161 |
| 117 // ------------------------------------------------------------------- | 162 // ------------------------------------------------------------------- |
| 118 // Harmony Map | 163 // Harmony Map |
| 119 | 164 |
| 120 function MapConstructor() { | 165 function MapConstructor(iterable) { |
| 121 if (%_IsConstructCall()) { | 166 if (!%_IsConstructCall()) { |
| 122 %MapInitialize(this); | |
| 123 } else { | |
| 124 throw MakeTypeError('constructor_not_function', ['Map']); | 167 throw MakeTypeError('constructor_not_function', ['Map']); |
| 125 } | 168 } |
| 169 | |
| 170 var iter, adder; | |
| 171 | |
| 172 if (!IS_NULL_OR_UNDEFINED(iterable)) { | |
| 173 iter = GetIterator(iterable); | |
| 174 adder = this.set; | |
| 175 if (!IS_SPEC_FUNCTION(adder)) { | |
| 176 throw MakeTypeError('property_not_function', ['set', this]); | |
| 177 } | |
| 178 } | |
| 179 | |
| 180 %MapInitialize(this); | |
| 181 | |
| 182 if (IS_UNDEFINED(iter)) return; | |
| 183 | |
| 184 var next, done, nextItem; | |
| 185 while (!(next = iter.next()).done) { | |
| 186 if (!IS_SPEC_OBJECT(next)) { | |
| 187 throw MakeTypeError('not_an_object', [next]); | |
|
rossberg
2014/06/23 14:15:59
We typically give more specific error messages in
arv (Not doing code reviews)
2014/06/23 15:43:56
Great idea.
Done.
| |
| 188 } | |
| 189 nextItem = next.value; | |
| 190 if (!IS_SPEC_OBJECT(nextItem)) { | |
| 191 throw MakeTypeError('not_an_object', [nextItem]); | |
| 192 } | |
| 193 %_CallFunction(this, nextItem[0], nextItem[1], adder); | |
| 194 } | |
| 126 } | 195 } |
| 127 | 196 |
| 128 | 197 |
| 129 function MapGetJS(key) { | 198 function MapGetJS(key) { |
| 130 if (!IS_MAP(this)) { | 199 if (!IS_MAP(this)) { |
| 131 throw MakeTypeError('incompatible_method_receiver', | 200 throw MakeTypeError('incompatible_method_receiver', |
| 132 ['Map.prototype.get', this]); | 201 ['Map.prototype.get', this]); |
| 133 } | 202 } |
| 134 return %MapGet(this, key); | 203 return %MapGet(this, key); |
| 135 } | 204 } |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 "get", MapGetJS, | 286 "get", MapGetJS, |
| 218 "set", MapSetJS, | 287 "set", MapSetJS, |
| 219 "has", MapHasJS, | 288 "has", MapHasJS, |
| 220 "delete", MapDeleteJS, | 289 "delete", MapDeleteJS, |
| 221 "clear", MapClearJS, | 290 "clear", MapClearJS, |
| 222 "forEach", MapForEach | 291 "forEach", MapForEach |
| 223 )); | 292 )); |
| 224 } | 293 } |
| 225 | 294 |
| 226 SetUpMap(); | 295 SetUpMap(); |
| OLD | NEW |