Changeset 128249 in webkit


Ignore:
Timestamp:
Sep 11, 2012 5:41:06 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Add new JSDependentRetained that allows keeping a JSObject alive as long as another is alive
https://bugs.webkit.org/show_bug.cgi?id=96034

Patch by Elliott Sprehn <esprehn@chromium.org> on 2012-09-11
Reviewed by Geoffrey Garen.

Add new JSDependentRetained (with the same API as V8DependentRetained) that allows keeping
a JSObject alive as long as another is alive. This is useful for keeping callbacks on
wrappers without keeping strong references into the JS heap in C++ which can result in
cycles that create memory leaks.

No new tests needed, this will be used to fix MutationObservers and UndoManager which will have tests.

  • GNUmakefile.list.am:
  • WebCore.vcproj/WebCore.vcproj:
  • WebCore.xcodeproj/project.pbxproj:
  • bindings/js/JSDependentRetained.h: Added.

(WebCore):
(JSDependentRetained):
(WebCore::JSDependentRetained::JSDependentRetained):
(WebCore::JSDependentRetained::~JSDependentRetained):
(WebCore::JSDependentRetained::get): Get the JSObject value.
(WebCore::JSDependentRetained::isEmpty): Check if the value is still alive.
(WebCore::JSDependentRetained::retain): Sets the owner of the object, should only be used once.
(WebCore::JSDependentRetained::release):

  • bindings/v8/V8DependentRetained.h:

(WebCore::V8DependentRetained::V8DependentRetained):
(WebCore::V8DependentRetained::retain): Added this method so the API for JSC and V8 are identical.

Location:
trunk/Source/WebCore
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r128248 r128249  
     12012-09-11  Elliott Sprehn  <esprehn@chromium.org>
     2
     3        Add new JSDependentRetained that allows keeping a JSObject alive as long as another is alive
     4        https://bugs.webkit.org/show_bug.cgi?id=96034
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        Add new JSDependentRetained (with the same API as V8DependentRetained) that allows keeping
     9        a JSObject alive as long as another is alive. This is useful for keeping callbacks on
     10        wrappers without keeping strong references into the JS heap in C++ which can result in
     11        cycles that create memory leaks.
     12
     13        No new tests needed, this will be used to fix MutationObservers and UndoManager which will have tests.
     14
     15        * GNUmakefile.list.am:
     16        * WebCore.vcproj/WebCore.vcproj:
     17        * WebCore.xcodeproj/project.pbxproj:
     18        * bindings/js/JSDependentRetained.h: Added.
     19        (WebCore):
     20        (JSDependentRetained):
     21        (WebCore::JSDependentRetained::JSDependentRetained):
     22        (WebCore::JSDependentRetained::~JSDependentRetained):
     23        (WebCore::JSDependentRetained::get): Get the JSObject value.
     24        (WebCore::JSDependentRetained::isEmpty): Check if the value is still alive.
     25        (WebCore::JSDependentRetained::retain): Sets the owner of the object, should only be used once.
     26        (WebCore::JSDependentRetained::release):
     27        * bindings/v8/V8DependentRetained.h:
     28        (WebCore::V8DependentRetained::V8DependentRetained):
     29        (WebCore::V8DependentRetained::retain): Added this method so the API for JSC and V8 are identical.
     30
    1312012-09-11  Alec Flett  <alecflett@chromium.org>
    232
  • trunk/Source/WebCore/GNUmakefile.list.am

    r128231 r128249  
    22392239        Source/WebCore/bindings/js/JSCustomXPathNSResolver.cpp \
    22402240        Source/WebCore/bindings/js/JSCustomXPathNSResolver.h \
     2241        Source/WebCore/bindings/js/JSDependentRetained.h \
    22412242        Source/WebCore/bindings/js/JSDictionary.cpp \
    22422243        Source/WebCore/bindings/js/JSDictionary.h \
  • trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj

    r128153 r128249  
    6592765927                                </File>
    6592865928                                <File
     65929                                        RelativePath="..\bindings\js\JSDependentRetained.h"
     65930                                        >
     65931                                </File>
     65932                                <File
    6592965933                                        RelativePath="..\bindings\js\JSDedicatedWorkerContextCustom.cpp"
    6593065934                                        >
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r128165 r128249  
    65496549                FE6FD48E0F676E9300092873 /* JSCoordinates.h in Headers */ = {isa = PBXBuildFile; fileRef = FE6FD48C0F676E9300092873 /* JSCoordinates.h */; };
    65506550                FE700DD10F92D81A008E2BFE /* JSCoordinatesCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FE700DD00F92D81A008E2BFE /* JSCoordinatesCustom.cpp */; };
     6551                FFD86E7815F9583600047233 /* JSDependentRetained.h in Headers */ = {isa = PBXBuildFile; fileRef = FFD86E7715F9583600047233 /* JSDependentRetained.h */; };
    65516552                FE80D7AB0E9C1ED2000D6F75 /* JSGeolocationCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FE80D7A60E9C1ED2000D6F75 /* JSGeolocationCustom.cpp */; };
    65526553                FE80DA630E9C4703000D6F75 /* JSGeolocation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FE80DA5F0E9C4703000D6F75 /* JSGeolocation.cpp */; };
     
    1398913990                FE6FD48C0F676E9300092873 /* JSCoordinates.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSCoordinates.h; sourceTree = "<group>"; };
    1399013991                FE700DD00F92D81A008E2BFE /* JSCoordinatesCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSCoordinatesCustom.cpp; sourceTree = "<group>"; };
     13992                FFD86E7715F9583600047233 /* JSDependentRetained.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDependentRetained.h; sourceTree = "<group>"; };
    1399113993                FE80D7A60E9C1ED2000D6F75 /* JSGeolocationCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSGeolocationCustom.cpp; sourceTree = "<group>"; };
    1399213994                FE80DA5F0E9C4703000D6F75 /* JSGeolocation.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSGeolocation.cpp; sourceTree = "<group>"; };
     
    2019620198                                1C81BA030E97348300266E07 /* JavaScriptCallFrame.cpp */,
    2019720199                                1C81BA040E97348300266E07 /* JavaScriptCallFrame.h */,
     20200                                FFD86E7715F9583600047233 /* JSDependentRetained.h */,
    2019820201                                BCE438A1140C0DBF005E437E /* JSDictionary.cpp */,
    2019920202                                BCE4389B140B1BA7005E437E /* JSDictionary.h */,
     
    2387723880                                4162A4581011464700DFF3ED /* JSDedicatedWorkerContext.h in Headers */,
    2387823881                                FDA15ED212B03F94003A583A /* JSDelayNode.h in Headers */,
     23882                                FFD86E7815F9583600047233 /* JSDependentRetained.h in Headers */,
    2387923883                                31FB1A66120A5D3F00DC02A0 /* JSDeviceMotionEvent.h in Headers */,
    2388023884                                59A86008119DAFA100DEF1EF /* JSDeviceOrientationEvent.h in Headers */,
  • trunk/Source/WebCore/bindings/v8/V8DependentRetained.h

    r127718 r128249  
    11/*
    2  * Copyright (C) 2012 Google Inc. All rights reserved.
     2 * Copyright (C) 2012 Google Inc. All Rights Reserved.
     3 * Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
    5  * modification, are permitted provided that the following conditions are
    6  * met:
     6 * modification, are permitted provided that the following conditions
     7 * are met:
     8 * 1. Redistributions of source code must retain the above copyright
     9 *    notice, this list of conditions and the following disclaimer.
     10 * 2. Redistributions in binary form must reproduce the above copyright
     11 *    notice, this list of conditions and the following disclaimer in the
     12 *    documentation and/or other materials provided with the distribution.
    713 *
    8  *     * Redistributions of source code must retain the above copyright
    9  * notice, this list of conditions and the following disclaimer.
    10  *     * Redistributions in binary form must reproduce the above
    11  * copyright notice, this list of conditions and the following disclaimer
    12  * in the documentation and/or other materials provided with the
    13  * distribution.
    14  *     * Neither the name of Google Inc. nor the names of its
    15  * contributors may be used to endorse or promote products derived from
    16  * this software without specific prior written permission.
    17  *
    18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
     15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     17 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
     18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
     22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    2723 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    2824 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     
    4541public:
    4642    V8DependentRetained(v8::Handle<v8::Object> owner, v8::Handle<v8::Object> value)
    47         : m_owner(owner)
    48         , m_value(value)
     43        : m_value(value)
    4944        , m_propertyName(createPropertyName())
    5045    {
    51         ASSERT(!m_owner.IsEmpty());
    52         ASSERT(!m_value.IsEmpty());
    53         owner->SetHiddenValue(m_propertyName.get(), value);
    54         m_owner.get().MakeWeak(this, &V8DependentRetained::ownerWeakCallback);
     46        ASSERT(!m_value.isEmpty());
    5547        m_value.get().MakeWeak(this, &V8DependentRetained::valueWeakCallback);
     48        if (!owner.IsEmpty())
     49            retain(owner);
    5650    }
    5751
     
    7165    }
    7266
    73     // FIXME: We might add an explicit retain(v8::Handle<v8::Object>) method to allow
    74     // creating one of these and choosing the owner later. Such behavior is required
    75     // in JSC, but not in v8 right now.
     67    void retain(v8::Handle<v8::Object> owner)
     68    {
     69        ASSERT(m_owner.isEmpty() && !owner.IsEmpty());
     70        ASSERT(!m_value.isEmpty());
     71        owner->SetHiddenValue(m_propertyName.get(), get());
     72        m_owner = owner;
     73        m_owner.get().MakeWeak(this, &V8DependentRetained::ownerWeakCallback);
     74    }
    7675
    7776private:
Note: See TracChangeset for help on using the changeset viewer.