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

Side by Side Diff: test/mjsunit/harmony/object-observe.js

Issue 11280118: Object.observe: More tests for accessor reconfiguration. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 delete obj.a; 289 delete obj.a;
290 obj.a = 4; 290 obj.a = 4;
291 obj.a = 4; // ignored 291 obj.a = 4; // ignored
292 obj.a = 5; 292 obj.a = 5;
293 Object.defineProperty(obj, "a", {value: 6}); 293 Object.defineProperty(obj, "a", {value: 6});
294 Object.defineProperty(obj, "a", {writable: false}); 294 Object.defineProperty(obj, "a", {writable: false});
295 obj.a = 7; // ignored 295 obj.a = 7; // ignored
296 Object.defineProperty(obj, "a", {value: 8}); 296 Object.defineProperty(obj, "a", {value: 8});
297 Object.defineProperty(obj, "a", {value: 7, writable: true}); 297 Object.defineProperty(obj, "a", {value: 7, writable: true});
298 Object.defineProperty(obj, "a", {get: function() {}}); 298 Object.defineProperty(obj, "a", {get: function() {}});
299 Object.defineProperty(obj, "a", {get: function() {}}); 299 Object.defineProperty(obj, "a", {get: frozenFunction});
300 Object.defineProperty(obj, "a", {get: frozenFunction}); // ignored
301 Object.defineProperty(obj, "a", {get: frozenFunction, set: frozenFunction});
302 Object.defineProperty(obj, "a", {set: frozenFunction}); // ignored
303 Object.defineProperty(obj, "a", {get: undefined, set: frozenFunction});
300 delete obj.a; 304 delete obj.a;
301 delete obj.a; 305 delete obj.a;
302 Object.defineProperty(obj, "a", {get: function() {}, configurable: true}); 306 Object.defineProperty(obj, "a", {get: function() {}, configurable: true});
303 Object.defineProperty(obj, "a", {value: 9, writable: true}); 307 Object.defineProperty(obj, "a", {value: 9, writable: true});
304 obj.a = 10; 308 obj.a = 10;
305 delete obj.a; 309 delete obj.a;
306 Object.defineProperty(obj, "a", {value: 11, configurable: true}); 310 Object.defineProperty(obj, "a", {value: 11, configurable: true});
307 Object.deliverChangeRecords(observer.callback); 311 Object.deliverChangeRecords(observer.callback);
308 observer.assertCallbackRecords([ 312 observer.assertCallbackRecords([
309 { object: obj, name: "a", type: "updated", oldValue: 1 }, 313 { object: obj, name: "a", type: "updated", oldValue: 1 },
310 { object: obj, name: "a", type: "updated", oldValue: 2 }, 314 { object: obj, name: "a", type: "updated", oldValue: 2 },
311 { object: obj, name: "a", type: "deleted", oldValue: 3 }, 315 { object: obj, name: "a", type: "deleted", oldValue: 3 },
312 { object: obj, name: "a", type: "new" }, 316 { object: obj, name: "a", type: "new" },
313 { object: obj, name: "a", type: "updated", oldValue: 4 }, 317 { object: obj, name: "a", type: "updated", oldValue: 4 },
314 { object: obj, name: "a", type: "updated", oldValue: 5 }, 318 { object: obj, name: "a", type: "updated", oldValue: 5 },
315 { object: obj, name: "a", type: "reconfigured", oldValue: 6 }, 319 { object: obj, name: "a", type: "reconfigured", oldValue: 6 },
316 { object: obj, name: "a", type: "updated", oldValue: 6 }, 320 { object: obj, name: "a", type: "updated", oldValue: 6 },
317 { object: obj, name: "a", type: "reconfigured", oldValue: 8 }, 321 { object: obj, name: "a", type: "reconfigured", oldValue: 8 },
318 { object: obj, name: "a", type: "reconfigured", oldValue: 7 }, 322 { object: obj, name: "a", type: "reconfigured", oldValue: 7 },
319 { object: obj, name: "a", type: "reconfigured" }, 323 { object: obj, name: "a", type: "reconfigured" },
324 { object: obj, name: "a", type: "reconfigured" },
325 { object: obj, name: "a", type: "reconfigured" },
320 { object: obj, name: "a", type: "deleted" }, 326 { object: obj, name: "a", type: "deleted" },
321 { object: obj, name: "a", type: "new" }, 327 { object: obj, name: "a", type: "new" },
322 { object: obj, name: "a", type: "reconfigured" }, 328 { object: obj, name: "a", type: "reconfigured" },
323 { object: obj, name: "a", type: "updated", oldValue: 9 }, 329 { object: obj, name: "a", type: "updated", oldValue: 9 },
324 { object: obj, name: "a", type: "deleted", oldValue: 10 }, 330 { object: obj, name: "a", type: "deleted", oldValue: 10 },
325 { object: obj, name: "a", type: "new" }, 331 { object: obj, name: "a", type: "new" },
326 ]); 332 ]);
327 333
328 // Observing indexed properties. 334 // Observing indexed properties.
329 reset(); 335 reset();
330 var obj = {'1': 1} 336 var obj = {'1': 1}
331 Object.observe(obj, observer.callback); 337 Object.observe(obj, observer.callback);
332 obj[1] = 2; 338 obj[1] = 2;
333 obj[1] = 3; 339 obj[1] = 3;
334 delete obj[1]; 340 delete obj[1];
335 obj[1] = 4; 341 obj[1] = 4;
336 obj[1] = 4; // ignored 342 obj[1] = 4; // ignored
337 obj[1] = 5; 343 obj[1] = 5;
338 Object.defineProperty(obj, "1", {value: 6}); 344 Object.defineProperty(obj, "1", {value: 6});
339 Object.defineProperty(obj, "1", {writable: false}); 345 Object.defineProperty(obj, "1", {writable: false});
340 obj[1] = 7; // ignored 346 obj[1] = 7; // ignored
341 Object.defineProperty(obj, "1", {value: 8}); 347 Object.defineProperty(obj, "1", {value: 8});
342 Object.defineProperty(obj, "1", {value: 7, writable: true}); 348 Object.defineProperty(obj, "1", {value: 7, writable: true});
343 Object.defineProperty(obj, "1", {get: function() {}}); 349 Object.defineProperty(obj, "1", {get: function() {}});
344 Object.defineProperty(obj, "1", {get: function() {}}); 350 Object.defineProperty(obj, "1", {get: frozenFunction});
351 Object.defineProperty(obj, "1", {get: frozenFunction}); // ignored
352 Object.defineProperty(obj, "1", {get: frozenFunction, set: frozenFunction});
353 Object.defineProperty(obj, "1", {set: frozenFunction}); // ignored
354 Object.defineProperty(obj, "1", {get: undefined, set: frozenFunction});
345 delete obj[1]; 355 delete obj[1];
346 delete obj[1]; 356 delete obj[1];
347 Object.defineProperty(obj, "1", {get: function() {}, configurable: true}); 357 Object.defineProperty(obj, "1", {get: function() {}, configurable: true});
348 Object.defineProperty(obj, "1", {value: 9, writable: true}); 358 Object.defineProperty(obj, "1", {value: 9, writable: true});
349 obj[1] = 10; 359 obj[1] = 10;
350 delete obj[1]; 360 delete obj[1];
351 Object.defineProperty(obj, "1", {value: 11, configurable: true}); 361 Object.defineProperty(obj, "1", {value: 11, configurable: true});
352 Object.deliverChangeRecords(observer.callback); 362 Object.deliverChangeRecords(observer.callback);
353 observer.assertCallbackRecords([ 363 observer.assertCallbackRecords([
354 { object: obj, name: "1", type: "updated", oldValue: 1 }, 364 { object: obj, name: "1", type: "updated", oldValue: 1 },
355 { object: obj, name: "1", type: "updated", oldValue: 2 }, 365 { object: obj, name: "1", type: "updated", oldValue: 2 },
356 { object: obj, name: "1", type: "deleted", oldValue: 3 }, 366 { object: obj, name: "1", type: "deleted", oldValue: 3 },
357 { object: obj, name: "1", type: "new" }, 367 { object: obj, name: "1", type: "new" },
358 { object: obj, name: "1", type: "updated", oldValue: 4 }, 368 { object: obj, name: "1", type: "updated", oldValue: 4 },
359 { object: obj, name: "1", type: "updated", oldValue: 5 }, 369 { object: obj, name: "1", type: "updated", oldValue: 5 },
360 { object: obj, name: "1", type: "reconfigured", oldValue: 6 }, 370 { object: obj, name: "1", type: "reconfigured", oldValue: 6 },
361 { object: obj, name: "1", type: "updated", oldValue: 6 }, 371 { object: obj, name: "1", type: "updated", oldValue: 6 },
362 { object: obj, name: "1", type: "reconfigured", oldValue: 8 }, 372 { object: obj, name: "1", type: "reconfigured", oldValue: 8 },
363 { object: obj, name: "1", type: "reconfigured", oldValue: 7 }, 373 { object: obj, name: "1", type: "reconfigured", oldValue: 7 },
364 { object: obj, name: "1", type: "reconfigured" }, 374 { object: obj, name: "1", type: "reconfigured" },
375 { object: obj, name: "1", type: "reconfigured" },
376 { object: obj, name: "1", type: "reconfigured" },
365 { object: obj, name: "1", type: "deleted" }, 377 { object: obj, name: "1", type: "deleted" },
366 { object: obj, name: "1", type: "new" }, 378 { object: obj, name: "1", type: "new" },
367 { object: obj, name: "1", type: "reconfigured" }, 379 { object: obj, name: "1", type: "reconfigured" },
368 { object: obj, name: "1", type: "updated", oldValue: 9 }, 380 { object: obj, name: "1", type: "updated", oldValue: 9 },
369 { object: obj, name: "1", type: "deleted", oldValue: 10 }, 381 { object: obj, name: "1", type: "deleted", oldValue: 10 },
370 { object: obj, name: "1", type: "new" }, 382 { object: obj, name: "1", type: "new" },
371 ]); 383 ]);
372 384
373 385
374 // Test all kinds of objects generically. 386 // Test all kinds of objects generically.
375 function TestObserveConfigurable(obj, prop) { 387 function TestObserveConfigurable(obj, prop) {
376 reset(); 388 reset();
377 obj[prop] = 1; 389 obj[prop] = 1;
378 Object.observe(obj, observer.callback); 390 Object.observe(obj, observer.callback);
379 obj[prop] = 2; 391 obj[prop] = 2;
380 obj[prop] = 3; 392 obj[prop] = 3;
381 delete obj[prop]; 393 delete obj[prop];
382 obj[prop] = 4; 394 obj[prop] = 4;
383 obj[prop] = 4; // ignored 395 obj[prop] = 4; // ignored
384 obj[prop] = 5; 396 obj[prop] = 5;
385 Object.defineProperty(obj, prop, {value: 6}); 397 Object.defineProperty(obj, prop, {value: 6});
386 Object.defineProperty(obj, prop, {writable: false}); 398 Object.defineProperty(obj, prop, {writable: false});
387 obj[prop] = 7; // ignored 399 obj[prop] = 7; // ignored
388 Object.defineProperty(obj, prop, {value: 8}); 400 Object.defineProperty(obj, prop, {value: 8});
389 Object.defineProperty(obj, prop, {value: 7, writable: true}); 401 Object.defineProperty(obj, prop, {value: 7, writable: true});
390 Object.defineProperty(obj, prop, {get: function() {}}); 402 Object.defineProperty(obj, prop, {get: function() {}});
391 Object.defineProperty(obj, prop, {get: function() {}}); 403 Object.defineProperty(obj, prop, {get: frozenFunction});
404 Object.defineProperty(obj, prop, {get: frozenFunction}); // ignored
405 Object.defineProperty(obj, prop, {get: frozenFunction, set: frozenFunction});
406 Object.defineProperty(obj, prop, {set: frozenFunction}); // ignored
407 Object.defineProperty(obj, prop, {get: undefined, set: frozenFunction});
392 delete obj[prop]; 408 delete obj[prop];
393 delete obj[prop]; 409 delete obj[prop];
394 Object.defineProperty(obj, prop, {get: function() {}, configurable: true}); 410 Object.defineProperty(obj, prop, {get: function() {}, configurable: true});
395 Object.defineProperty(obj, prop, {value: 9, writable: true}); 411 Object.defineProperty(obj, prop, {value: 9, writable: true});
396 obj[prop] = 10; 412 obj[prop] = 10;
397 delete obj[prop]; 413 delete obj[prop];
398 Object.defineProperty(obj, prop, {value: 11, configurable: true}); 414 Object.defineProperty(obj, prop, {value: 11, configurable: true});
399 Object.deliverChangeRecords(observer.callback); 415 Object.deliverChangeRecords(observer.callback);
400 observer.assertCallbackRecords([ 416 observer.assertCallbackRecords([
401 { object: obj, name: prop, type: "updated", oldValue: 1 }, 417 { object: obj, name: prop, type: "updated", oldValue: 1 },
402 { object: obj, name: prop, type: "updated", oldValue: 2 }, 418 { object: obj, name: prop, type: "updated", oldValue: 2 },
403 { object: obj, name: prop, type: "deleted", oldValue: 3 }, 419 { object: obj, name: prop, type: "deleted", oldValue: 3 },
404 { object: obj, name: prop, type: "new" }, 420 { object: obj, name: prop, type: "new" },
405 { object: obj, name: prop, type: "updated", oldValue: 4 }, 421 { object: obj, name: prop, type: "updated", oldValue: 4 },
406 { object: obj, name: prop, type: "updated", oldValue: 5 }, 422 { object: obj, name: prop, type: "updated", oldValue: 5 },
407 { object: obj, name: prop, type: "reconfigured", oldValue: 6 }, 423 { object: obj, name: prop, type: "reconfigured", oldValue: 6 },
408 { object: obj, name: prop, type: "updated", oldValue: 6 }, 424 { object: obj, name: prop, type: "updated", oldValue: 6 },
409 { object: obj, name: prop, type: "reconfigured", oldValue: 8 }, 425 { object: obj, name: prop, type: "reconfigured", oldValue: 8 },
410 { object: obj, name: prop, type: "reconfigured", oldValue: 7 }, 426 { object: obj, name: prop, type: "reconfigured", oldValue: 7 },
411 { object: obj, name: prop, type: "reconfigured" }, 427 { object: obj, name: prop, type: "reconfigured" },
428 { object: obj, name: prop, type: "reconfigured" },
429 { object: obj, name: prop, type: "reconfigured" },
412 { object: obj, name: prop, type: "deleted" }, 430 { object: obj, name: prop, type: "deleted" },
413 { object: obj, name: prop, type: "new" }, 431 { object: obj, name: prop, type: "new" },
414 { object: obj, name: prop, type: "reconfigured" }, 432 { object: obj, name: prop, type: "reconfigured" },
415 { object: obj, name: prop, type: "updated", oldValue: 9 }, 433 { object: obj, name: prop, type: "updated", oldValue: 9 },
416 { object: obj, name: prop, type: "deleted", oldValue: 10 }, 434 { object: obj, name: prop, type: "deleted", oldValue: 10 },
417 { object: obj, name: prop, type: "new" }, 435 { object: obj, name: prop, type: "new" },
418 ]); 436 ]);
419 Object.unobserve(obj, observer.callback); 437 Object.unobserve(obj, observer.callback);
420 delete obj[prop]; 438 delete obj[prop];
421 } 439 }
422 440
423 function TestObserveNonConfigurable(obj, prop) { 441 function TestObserveNonConfigurable(obj, prop) {
424 reset(); 442 reset();
425 obj[prop] = 1; 443 obj[prop] = 1;
426 Object.observe(obj, observer.callback); 444 Object.observe(obj, observer.callback);
427 obj[prop] = 4; 445 obj[prop] = 4;
428 obj[prop] = 4; // ignored 446 obj[prop] = 4; // ignored
429 obj[prop] = 5; 447 obj[prop] = 5;
430 Object.defineProperty(obj, prop, {value: 6}); 448 Object.defineProperty(obj, prop, {value: 6});
431 Object.defineProperty(obj, prop, {value: 6}); // ignored 449 Object.defineProperty(obj, prop, {value: 6}); // ignored
450 Object.defineProperty(obj, prop, {value: 7});
451 Object.defineProperty(obj, prop, {enumerable: true}); // ignored
432 Object.defineProperty(obj, prop, {writable: false}); 452 Object.defineProperty(obj, prop, {writable: false});
433 obj[prop] = 7; // ignored 453 obj[prop] = 7; // ignored
454 Object.defineProperty(obj, prop, {get: function() {}}); // ignored
adamk 2012/11/21 16:24:32 This one confuses me, why is it ignored?
rossberg 2012/11/21 16:57:03 Because the object is not configurable. ;)
434 Object.deliverChangeRecords(observer.callback); 455 Object.deliverChangeRecords(observer.callback);
435 observer.assertCallbackRecords([ 456 observer.assertCallbackRecords([
436 { object: obj, name: prop, type: "updated", oldValue: 1 }, 457 { object: obj, name: prop, type: "updated", oldValue: 1 },
437 { object: obj, name: prop, type: "updated", oldValue: 4 }, 458 { object: obj, name: prop, type: "updated", oldValue: 4 },
438 { object: obj, name: prop, type: "updated", oldValue: 5 }, 459 { object: obj, name: prop, type: "updated", oldValue: 5 },
439 { object: obj, name: prop, type: "reconfigured", oldValue: 6 }, 460 { object: obj, name: prop, type: "updated", oldValue: 6 },
461 { object: obj, name: prop, type: "reconfigured", oldValue: 7 },
440 ]); 462 ]);
441 Object.unobserve(obj, observer.callback); 463 Object.unobserve(obj, observer.callback);
442 } 464 }
443 465
444 function createProxy(create, x) { 466 function createProxy(create, x) {
445 var handler = { 467 var handler = {
446 getPropertyDescriptor: function(k) { 468 getPropertyDescriptor: function(k) {
447 return Object.getOwnPropertyDescriptor(this.target, k); 469 return Object.getOwnPropertyDescriptor(this.target, k);
448 }, 470 },
449 getOwnPropertyDescriptor: function(k) { 471 getOwnPropertyDescriptor: function(k) {
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 Object.observe(dummy, observer.callback); 791 Object.observe(dummy, observer.callback);
770 Object.unobserve(dummy, observer.callback); 792 Object.unobserve(dummy, observer.callback);
771 var array = [0]; 793 var array = [0];
772 Object.observe(array, observer.callback); 794 Object.observe(array, observer.callback);
773 array.splice(0, 1); 795 array.splice(0, 1);
774 Object.deliverChangeRecords(observer.callback); 796 Object.deliverChangeRecords(observer.callback);
775 observer.assertCallbackRecords([ 797 observer.assertCallbackRecords([
776 { object: array, name: '0', type: 'deleted', oldValue: 0 }, 798 { object: array, name: '0', type: 'deleted', oldValue: 0 },
777 { object: array, name: 'length', type: 'updated', oldValue: 1}, 799 { object: array, name: 'length', type: 'updated', oldValue: 1},
778 ]); 800 ]);
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698