Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: test/mjsunit/es6/iteration-semantics.js

Issue 929733003: for-of should throw if result object is not an object (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: add strings and move runtime function Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/runtime/runtime-internal.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 results([{ done: false }, 193 results([{ done: false },
194 { value: 1, done: false }, 194 { value: 1, done: false },
195 // A missing "done" is the same as undefined, which 195 // A missing "done" is the same as undefined, which
196 // is false. 196 // is false.
197 { value: 2 }, 197 { value: 2 },
198 // Not done. 198 // Not done.
199 { value: 3, done: 0 }, 199 { value: 3, done: 0 },
200 // Done. 200 // Done.
201 { value: 4, done: 42 }]))); 201 { value: 4, done: 42 }])));
202 // Results that are not objects. 202 // Results that are not objects.
203 assertEquals([undefined, undefined, undefined], 203 assertThrows(function() {
204 fold(append, [], 204 assertEquals([undefined, undefined, undefined],
205 results([10, "foo", /qux/, { value: 37, done: true }]))); 205 fold(append, [],
206 results([10, "foo", /qux/, { value: 37, done: true }])));
207 }, TypeError);
206 // Getters (shudder). 208 // Getters (shudder).
207 assertEquals([1, 2], 209 assertEquals([1, 2],
208 fold(append, [], 210 fold(append, [],
209 results([one_time_getter({ value: 1 }, 'done', false), 211 results([one_time_getter({ value: 1 }, 'done', false),
210 one_time_getter({ done: false }, 'value', 2), 212 one_time_getter({ done: false }, 'value', 2),
211 { value: 37, done: true }, 213 { value: 37, done: true },
212 never_getter(never_getter({}, 'done'), 'value')]))); 214 never_getter(never_getter({}, 'done'), 'value')])));
213 215
214 // Unlike the case with for-in, null and undefined cause an error. 216 // Unlike the case with for-in, null and undefined cause an error.
215 assertThrows('fold(sum, 0, unreachable(null))', TypeError); 217 assertThrows('fold(sum, 0, unreachable(null))', TypeError);
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 if (name == 'next' && n-- < 0) throw "unreachable"; 329 if (name == 'next' && n-- < 0) throw "unreachable";
328 return iterator[name]; 330 return iterator[name];
329 }, 331 },
330 // Needed for integers_until(10)'s this.n++. 332 // Needed for integers_until(10)'s this.n++.
331 set: function(receiver, name, val) { 333 set: function(receiver, name, val) {
332 return iterator[name] = val; 334 return iterator[name] = val;
333 } 335 }
334 })); 336 }));
335 } 337 }
336 assertEquals(45, fold(sum, 0, poison_proxy_after(integers_until(10), 10))); 338 assertEquals(45, fold(sum, 0, poison_proxy_after(integers_until(10), 10)));
339
340
341 function test_iterator_result_object_non_object(value, descr) {
342 var arr = [];
343 var ex;
344 var message = 'Iterator result ' + (descr || value) + ' is not an object';
345 try {
346 fold(append, arr,
347 results([{value: 1}, {}, value, {value: 2}, {done: true}]));
348 } catch (e) {
349 ex = e;
350 }
351 assertInstanceof(ex, TypeError);
352 assertEquals(message, ex.message);
353 assertArrayEquals([1, undefined], arr);
354 }
355 test_iterator_result_object_non_object(null);
356 test_iterator_result_object_non_object(undefined);
357 test_iterator_result_object_non_object(42);
358 test_iterator_result_object_non_object('abc');
359 test_iterator_result_object_non_object(false);
360 test_iterator_result_object_non_object(Symbol('x'), 'Symbol(x)');
OLDNEW
« no previous file with comments | « src/runtime/runtime-internal.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698