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

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

Issue 47703003: Make Object.freeze/seal/preventExtensions observable (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: whitespace Created 7 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
« src/objects.cc ('K') | « src/v8natives.js ('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 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 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 obj[''] = ''; 293 obj[''] = '';
294 obj[''] = ' '; 294 obj[''] = ' ';
295 delete obj['']; 295 delete obj[''];
296 Object.deliverChangeRecords(observer.callback); 296 Object.deliverChangeRecords(observer.callback);
297 observer.assertCallbackRecords([ 297 observer.assertCallbackRecords([
298 { object: obj, type: 'new', name: '' }, 298 { object: obj, type: 'new', name: '' },
299 { object: obj, type: 'updated', name: '', oldValue: '' }, 299 { object: obj, type: 'updated', name: '', oldValue: '' },
300 { object: obj, type: 'deleted', name: '', oldValue: ' ' }, 300 { object: obj, type: 'deleted', name: '', oldValue: ' ' },
301 ]); 301 ]);
302 302
303 // Object.preventExtensions
rossberg 2013/10/30 19:11:45 Cases you could add: - invoking preventExtensions
rafaelw 2013/10/30 23:00:30 Good catch. Note that we now exit early from JSObj
rossberg 2013/10/31 08:03:20 Can you add a similar test for seal and freeze?
rafaelw 2013/11/05 12:20:31 Done.
304 reset();
305 var obj = { foo: 'bar'};
306 Object.observe(obj, observer.callback);
307 obj.baz = 'bat';
308 Object.preventExtensions(obj);
309
310 Object.deliverChangeRecords(observer.callback);
311 observer.assertCallbackRecords([
312 { object: obj, type: 'new', name: 'baz' },
313 { object: obj, type: 'preventExtensions' },
314 ]);
315
316 // Object.freeze
317 reset();
318 var obj = { a: 'a' };
319 Object.defineProperty(obj, 'b', {
320 writable: false,
321 configurable: true,
322 value: 'b'
323 });
324 Object.defineProperty(obj, 'c', {
325 writable: true,
326 configurable: false,
327 value: 'c'
328 });
329 Object.defineProperty(obj, 'd', {
330 writable: false,
331 configurable: false,
332 value: 'd'
333 });
334 Object.observe(obj, observer.callback);
335 Object.freeze(obj);
336
337 Object.deliverChangeRecords(observer.callback);
338 observer.assertCallbackRecords([
339 { object: obj, type: 'reconfigured', name: 'a' },
340 { object: obj, type: 'reconfigured', name: 'b' },
341 { object: obj, type: 'reconfigured', name: 'c' },
342 { object: obj, type: 'preventExtensions' },
343 ]);
344
345 // Object.seal
346 reset();
347 var obj = { a: 'a' };
348 Object.defineProperty(obj, 'b', {
349 writable: false,
350 configurable: true,
351 value: 'b'
352 });
353 Object.defineProperty(obj, 'c', {
354 writable: true,
355 configurable: false,
356 value: 'c'
357 });
358 Object.defineProperty(obj, 'd', {
359 writable: false,
360 configurable: false,
361 value: 'd'
362 });
363 Object.observe(obj, observer.callback);
364 Object.seal(obj);
365
366 Object.deliverChangeRecords(observer.callback);
367 observer.assertCallbackRecords([
368 { object: obj, type: 'reconfigured', name: 'a' },
369 { object: obj, type: 'reconfigured', name: 'b' },
370 { object: obj, type: 'preventExtensions' },
371 ]);
372
303 // Observing a continuous stream of changes, while itermittantly unobserving. 373 // Observing a continuous stream of changes, while itermittantly unobserving.
304 reset(); 374 reset();
375 var obj = {};
305 Object.observe(obj, observer.callback); 376 Object.observe(obj, observer.callback);
306 Object.getNotifier(obj).notify({ 377 Object.getNotifier(obj).notify({
307 type: 'updated', 378 type: 'updated',
308 val: 1 379 val: 1
309 }); 380 });
310 381
311 Object.unobserve(obj, observer.callback); 382 Object.unobserve(obj, observer.callback);
312 Object.getNotifier(obj).notify({ 383 Object.getNotifier(obj).notify({
313 type: 'updated', 384 type: 'updated',
314 val: 2 385 val: 2
(...skipping 1314 matching lines...) Expand 10 before | Expand all | Expand 10 after
1629 for (var n1 = 0; n1 < 3; ++n1) 1700 for (var n1 = 0; n1 < 3; ++n1)
1630 for (var n2 = 0; n2 < 3; ++n2) 1701 for (var n2 = 0; n2 < 3; ++n2)
1631 for (var i in mutation) 1702 for (var i in mutation)
1632 TestFastElementsLength(mutation[i], b1 != 0, b2 != 0, 20*n1, 20*n2); 1703 TestFastElementsLength(mutation[i], b1 != 0, b2 != 0, 20*n1, 20*n2);
1633 1704
1634 for (var b1 = 0; b1 < 2; ++b1) 1705 for (var b1 = 0; b1 < 2; ++b1)
1635 for (var b2 = 0; b2 < 2; ++b2) 1706 for (var b2 = 0; b2 < 2; ++b2)
1636 for (var n = 0; n < 3; ++n) 1707 for (var n = 0; n < 3; ++n)
1637 for (var i in mutationByIncr) 1708 for (var i in mutationByIncr)
1638 TestFastElementsLength(mutationByIncr[i], b1 != 0, b2 != 0, 7*n, 7*n+1); 1709 TestFastElementsLength(mutationByIncr[i], b1 != 0, b2 != 0, 7*n, 7*n+1);
OLDNEW
« src/objects.cc ('K') | « src/v8natives.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698