| 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 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 return ObjectUnobserve(object, callback); | 268 return ObjectUnobserve(object, callback); |
| 269 } | 269 } |
| 270 | 270 |
| 271 function EnqueueToCallback(callback, changeRecord) { | 271 function EnqueueToCallback(callback, changeRecord) { |
| 272 var callbackInfo = NormalizeCallbackInfo(callback); | 272 var callbackInfo = NormalizeCallbackInfo(callback); |
| 273 observationState.pendingObservers[callbackInfo.priority] = callback; | 273 observationState.pendingObservers[callbackInfo.priority] = callback; |
| 274 callbackInfo.push(changeRecord); | 274 callbackInfo.push(changeRecord); |
| 275 %SetObserverDeliveryPending(); | 275 %SetObserverDeliveryPending(); |
| 276 } | 276 } |
| 277 | 277 |
| 278 function EnqueueChangeRecord(changeRecord, observers) { | 278 function EnqueueChangeRecord(changeRecord, observers, skipAccessCheck) { |
| 279 // TODO(rossberg): adjust once there is a story for symbols vs proxies. | 279 // TODO(rossberg): adjust once there is a story for symbols vs proxies. |
| 280 if (IS_SYMBOL(changeRecord.name)) return; | 280 if (IS_SYMBOL(changeRecord.name)) return; |
| 281 | 281 |
| 282 var object = changeRecord.object; |
| 283 var needsAccessCheck = !skipAccessCheck && %IsAccessCheckNeeded(object); |
| 282 for (var i = 0; i < observers.length; i++) { | 284 for (var i = 0; i < observers.length; i++) { |
| 283 var observer = observers[i]; | 285 var observer = observers[i]; |
| 284 if (IS_UNDEFINED(observer.accept[changeRecord.type])) | 286 if (IS_UNDEFINED(observer.accept[changeRecord.type])) |
| 285 continue; | 287 continue; |
| 286 | 288 |
| 289 if (needsAccessCheck && |
| 290 // Drop all splice records on the floor for access-checked objects |
| 291 (changeRecord.type == 'splice' || |
| 292 !%GetAccessAllowedForObserver( |
| 293 observer.callback, object, changeRecord.name))) { |
| 294 continue; |
| 295 } |
| 296 |
| 287 EnqueueToCallback(observer.callback, changeRecord); | 297 EnqueueToCallback(observer.callback, changeRecord); |
| 288 } | 298 } |
| 289 } | 299 } |
| 290 | 300 |
| 291 function BeginPerformSplice(array) { | 301 function BeginPerformSplice(array) { |
| 292 var objectInfo = objectInfoMap.get(array); | 302 var objectInfo = objectInfoMap.get(array); |
| 293 if (!IS_UNDEFINED(objectInfo)) | 303 if (!IS_UNDEFINED(objectInfo)) |
| 294 BeginPerformChange(objectInfo, 'splice'); | 304 BeginPerformChange(objectInfo, 'splice'); |
| 295 } | 305 } |
| 296 | 306 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 return; | 357 return; |
| 348 | 358 |
| 349 var newRecord = { object: target }; | 359 var newRecord = { object: target }; |
| 350 for (var prop in changeRecord) { | 360 for (var prop in changeRecord) { |
| 351 if (prop === 'object') continue; | 361 if (prop === 'object') continue; |
| 352 %DefineOrRedefineDataProperty(newRecord, prop, changeRecord[prop], | 362 %DefineOrRedefineDataProperty(newRecord, prop, changeRecord[prop], |
| 353 READ_ONLY + DONT_DELETE); | 363 READ_ONLY + DONT_DELETE); |
| 354 } | 364 } |
| 355 ObjectFreeze(newRecord); | 365 ObjectFreeze(newRecord); |
| 356 | 366 |
| 357 EnqueueChangeRecord(newRecord, objectInfo.changeObservers); | 367 EnqueueChangeRecord(newRecord, objectInfo.changeObservers, |
| 368 true /* skip access check */); |
| 358 } | 369 } |
| 359 | 370 |
| 360 function ObjectNotifierPerformChange(changeType, changeFn, receiver) { | 371 function ObjectNotifierPerformChange(changeType, changeFn, receiver) { |
| 361 if (!IS_SPEC_OBJECT(this)) | 372 if (!IS_SPEC_OBJECT(this)) |
| 362 throw MakeTypeError("called_on_non_object", ["performChange"]); | 373 throw MakeTypeError("called_on_non_object", ["performChange"]); |
| 363 | 374 |
| 364 var target = notifierTargetMap.get(this); | 375 var target = notifierTargetMap.get(this); |
| 365 if (IS_UNDEFINED(target)) | 376 if (IS_UNDEFINED(target)) |
| 366 throw MakeTypeError("observe_notify_non_notifier"); | 377 throw MakeTypeError("observe_notify_non_notifier"); |
| 367 if (!IS_STRING(changeType)) | 378 if (!IS_STRING(changeType)) |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 "observe", ArrayObserve, | 467 "observe", ArrayObserve, |
| 457 "unobserve", ArrayUnobserve | 468 "unobserve", ArrayUnobserve |
| 458 )); | 469 )); |
| 459 InstallFunctions(notifierPrototype, DONT_ENUM, $Array( | 470 InstallFunctions(notifierPrototype, DONT_ENUM, $Array( |
| 460 "notify", ObjectNotifierNotify, | 471 "notify", ObjectNotifierNotify, |
| 461 "performChange", ObjectNotifierPerformChange | 472 "performChange", ObjectNotifierPerformChange |
| 462 )); | 473 )); |
| 463 } | 474 } |
| 464 | 475 |
| 465 SetupObjectObserve(); | 476 SetupObjectObserve(); |
| OLD | NEW |