• adamk@chromium.org's avatar
    [Object.observe] Lazily allocate callbackInfo structure · fab9f4e1
    adamk@chromium.org authored
    This patch allows callbacks to lazily allocate the InternalArray which is used to store pendingChangeRecords. This moves some of the expense of observation to the case where changes actually occurred.
    
    When there are no pendingChangeRecords, the callbackInfo structure is a number which is the callbacks priority. Whenever a changeRecord is enqueued to the callback, it "normalizes" to be an InternalArray with a priority property. Immediately before its changeRecords are delivered, it returns to its optimized state.
    
    ---
    Note: Naming confusion resolved:
    
    This patch corrects some naming confusion in object-observe.js. Previously, we used the terms "callback" and "observer" to mean roughly the same thing, and overloaded the term "observer" to be both the callback itself and the *registration* on a object to observe (which now includes an accept map).
    
    This patch resolves this confusion:
    
    "object" (objectInfo, objectInfoMap): This refers to the observed object and its structures
    
    "callback" (callbackInfo, callbackInfoMap): This refers to the callback to whom change records may be delivered
    
    "observer" (objectInfo.changeObservers): This refers to a registration to observe a given object by a given callback with the specified accept list.
    ---
    
    R=rossberg@chromium.org
    
    Review URL: https://codereview.chromium.org/19132002
    
    Patch from Rafael Weinstein <rafaelw@chromium.org>.
    
    git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15682 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
    fab9f4e1
object-observe.js 13.3 KB