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 // 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 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 301 | 301 |
| 302 var changeRecord = { | 302 var changeRecord = { |
| 303 type: 'splice', | 303 type: 'splice', |
| 304 object: array, | 304 object: array, |
| 305 index: index, | 305 index: index, |
| 306 removed: removed, | 306 removed: removed, |
| 307 addedCount: addedCount | 307 addedCount: addedCount |
| 308 }; | 308 }; |
| 309 | 309 |
| 310 changeRecord.removed.length = deleteCount; | 310 changeRecord.removed.length = deleteCount; |
| 311 // TODO(rafaelw): This breaks spec-compliance. Re-enable when freezing isn't | 311 ObjectFreeze(changeRecord); |
| 312 // slow. | 312 ObjectFreeze(changeRecord.removed); |
|
adamk
2013/05/23 21:12:39
I'd leave this out for now, as it basically double
rafaelw
2013/05/23 22:53:18
I went back and tried as hard as I could to create
adamk
2013/05/23 22:55:49
Sounds good to me, thanks for doing the footwork t
| |
| 313 // ObjectFreeze(changeRecord); | |
| 314 // ObjectFreeze(changeRecord.removed); | |
| 315 EnqueueChangeRecord(changeRecord, objectInfo.changeObservers); | 313 EnqueueChangeRecord(changeRecord, objectInfo.changeObservers); |
| 316 } | 314 } |
| 317 | 315 |
| 318 function NotifyChange(type, object, name, oldValue) { | 316 function NotifyChange(type, object, name, oldValue) { |
| 319 var objectInfo = objectInfoMap.get(object); | 317 var objectInfo = objectInfoMap.get(object); |
| 320 if (objectInfo.changeObservers.length === 0) | 318 if (objectInfo.changeObservers.length === 0) |
| 321 return; | 319 return; |
| 322 | 320 |
| 323 var changeRecord = (arguments.length < 4) ? | 321 var changeRecord = (arguments.length < 4) ? |
| 324 { type: type, object: object, name: name } : | 322 { type: type, object: object, name: name } : |
| 325 { type: type, object: object, name: name, oldValue: oldValue }; | 323 { type: type, object: object, name: name, oldValue: oldValue }; |
| 326 // TODO(rafaelw): This breaks spec-compliance. Re-enable when freezing isn't | 324 ObjectFreeze(changeRecord); |
| 327 // slow. | |
| 328 // ObjectFreeze(changeRecord); | |
| 329 EnqueueChangeRecord(changeRecord, objectInfo.changeObservers); | 325 EnqueueChangeRecord(changeRecord, objectInfo.changeObservers); |
| 330 } | 326 } |
| 331 | 327 |
| 332 var notifierPrototype = {}; | 328 var notifierPrototype = {}; |
| 333 | 329 |
| 334 function ObjectNotifierNotify(changeRecord) { | 330 function ObjectNotifierNotify(changeRecord) { |
| 335 if (!IS_SPEC_OBJECT(this)) | 331 if (!IS_SPEC_OBJECT(this)) |
| 336 throw MakeTypeError("called_on_non_object", ["notify"]); | 332 throw MakeTypeError("called_on_non_object", ["notify"]); |
| 337 | 333 |
| 338 var target = notifierTargetMap.get(this); | 334 var target = notifierTargetMap.get(this); |
| 339 if (IS_UNDEFINED(target)) | 335 if (IS_UNDEFINED(target)) |
| 340 throw MakeTypeError("observe_notify_non_notifier"); | 336 throw MakeTypeError("observe_notify_non_notifier"); |
| 341 if (!IS_STRING(changeRecord.type)) | 337 if (!IS_STRING(changeRecord.type)) |
| 342 throw MakeTypeError("observe_type_non_string"); | 338 throw MakeTypeError("observe_type_non_string"); |
| 343 | 339 |
| 344 var objectInfo = objectInfoMap.get(target); | 340 var objectInfo = objectInfoMap.get(target); |
| 345 if (IS_UNDEFINED(objectInfo) || objectInfo.changeObservers.length === 0) | 341 if (IS_UNDEFINED(objectInfo) || objectInfo.changeObservers.length === 0) |
| 346 return; | 342 return; |
| 347 | 343 |
| 348 var newRecord = { object: target }; | 344 var newRecord = { object: target }; |
| 349 for (var prop in changeRecord) { | 345 for (var prop in changeRecord) { |
| 350 if (prop === 'object') continue; | 346 if (prop === 'object') continue; |
| 351 %DefineOrRedefineDataProperty(newRecord, prop, changeRecord[prop], | 347 %DefineOrRedefineDataProperty(newRecord, prop, changeRecord[prop], |
| 352 READ_ONLY + DONT_DELETE); | 348 READ_ONLY + DONT_DELETE); |
| 353 } | 349 } |
| 354 // TODO(rafaelw): This breaks spec-compliance. Re-enable when freezing isn't | 350 ObjectFreeze(newRecord); |
| 355 // slow. | |
| 356 // ObjectFreeze(newRecord); | |
| 357 | 351 |
| 358 EnqueueChangeRecord(newRecord, objectInfo.changeObservers); | 352 EnqueueChangeRecord(newRecord, objectInfo.changeObservers); |
| 359 } | 353 } |
| 360 | 354 |
| 361 function ObjectNotifierPerformChange(changeType, changeFn, receiver) { | 355 function ObjectNotifierPerformChange(changeType, changeFn, receiver) { |
| 362 if (!IS_SPEC_OBJECT(this)) | 356 if (!IS_SPEC_OBJECT(this)) |
| 363 throw MakeTypeError("called_on_non_object", ["performChange"]); | 357 throw MakeTypeError("called_on_non_object", ["performChange"]); |
| 364 | 358 |
| 365 var target = notifierTargetMap.get(this); | 359 var target = notifierTargetMap.get(this); |
| 366 if (IS_UNDEFINED(target)) | 360 if (IS_UNDEFINED(target)) |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 453 "observe", ArrayObserve, | 447 "observe", ArrayObserve, |
| 454 "unobserve", ArrayUnobserve | 448 "unobserve", ArrayUnobserve |
| 455 )); | 449 )); |
| 456 InstallFunctions(notifierPrototype, DONT_ENUM, $Array( | 450 InstallFunctions(notifierPrototype, DONT_ENUM, $Array( |
| 457 "notify", ObjectNotifierNotify, | 451 "notify", ObjectNotifierNotify, |
| 458 "performChange", ObjectNotifierPerformChange | 452 "performChange", ObjectNotifierPerformChange |
| 459 )); | 453 )); |
| 460 } | 454 } |
| 461 | 455 |
| 462 SetupObjectObserve(); | 456 SetupObjectObserve(); |
| OLD | NEW |