source: webkit/trunk/JavaScriptCore/runtime/SymbolTable.h@ 62677

Last change on this file since 62677 was 61324, checked in by Darin Adler, 15 years ago

2010-06-17 Darin Adler <Darin Adler>

Reviewed by Sam Weinig.

Use adoptRef and create functions in more code paths
https://bugs.webkit.org/show_bug.cgi?id=40760

  • API/JSClassRef.h: Removed unneeded include of RefCounted.h.
  • API/JSWeakObjectMapRefPrivate.cpp: Ditto.
  • bytecode/CodeBlock.h: (JSC::FunctionCodeBlock::FunctionCodeBlock): Use the SharedSymbolTable::create function instead of calling new directly.
  • runtime/SymbolTable.h: Added a create function to the SharedSymbolTable class and made the constructor private.

2010-06-17 Darin Adler <Darin Adler>

Reviewed by Sam Weinig.

Use adoptRef and create functions in more code paths
https://bugs.webkit.org/show_bug.cgi?id=40760

  • Plugins/Hosted/NetscapePluginInstanceProxy.h: Made create no longer be an inline function.
  • Plugins/Hosted/NetscapePluginInstanceProxy.mm: (WebKit::NetscapePluginInstanceProxy::NetscapePluginInstanceProxy): Moved the call to addPluginInstance out of here. (WebKit::NetscapePluginInstanceProxy::create): Move it in here. This makes sure we call adoptRef on the new proxy before any caller calls ref on it.

2010-06-17 Darin Adler <Darin Adler>

Reviewed by Sam Weinig.

Use adoptRef and create functions in more code paths
https://bugs.webkit.org/show_bug.cgi?id=40760

This helps prepare for an assertion that fires if you ref or destroy an
object before calling adoptRef on it. That will help us catch mistakes
that can lead to storage leaks.

  • WebCore.base.exp: Updated export now that Frame::create is not an inline function.
  • css/CSSInitialValue.h: (WebCore::CSSInitialValue::createExplicit): Use create. (WebCore::CSSInitialValue::createImplicit): Ditto. (WebCore::CSSInitialValue::create): Added.
  • css/CSSPrimitiveValue.cpp: (WebCore::CSSPrimitiveValue::createUncachedIdentifier): Added. (WebCore::CSSPrimitiveValue::createUncachedColor): Added. (WebCore::CSSPrimitiveValue::createUncached): Added. (WebCore::CSSPrimitiveValue::createIdentifier): Use createUncachedIdentifier instead of using new directly. (WebCore::CSSPrimitiveValue::createColor): Use createUncachedColor instead of using new directly. (WebCore::CSSPrimitiveValue::create): Use createdUncached instead of using new directly.
  • css/CSSPrimitiveValue.h: Declare the new functions above.
  • css/CSSStyleSelector.cpp: (WebCore::loadFullDefaultStyle): Deref simpleDefaultStyleSheet instead of explicitly deleting it.
  • loader/SubresourceLoader.cpp: (WebCore::SubresourceLoader::SubresourceLoader): Move the call to addSubresourceLoader out of here. (WebCore::SubresourceLoader::create): Move it in here. This makes it so we don't ref the loader before finishing its creation and calling adoptRef.
  • page/Frame.cpp: (WebCore::Frame::Frame): Move the call to setMainFrame out of here. Also refactor the code so an assertion is easier to read. (WebCore::Frame::create): Move the call to setMainFrame in here. This makes it so we don't ref the frame before finishing its creation and calling adoptRef.
  • page/Frame.h: Made the create function non-inline.
  • platform/text/BidiContext.cpp: (WebCore::BidiContext::createUncached): Added. (WebCore::BidiContext::create): Call createUncached instead of callling new directly.
  • platform/text/BidiContext.h: Declare createUncached.
  • rendering/RenderSVGResourceFilter.cpp: (WebCore::RenderSVGResourceFilter::buildPrimitives): Use PassRefPtr and RefPtr instead of OwnPtr. And use the create function instead of new.
  • rendering/RenderSVGResourceFilter.h: Ditto.
  • rendering/SVGRenderTreeAsText.cpp: (WebCore::writeSVGResourceContainer): Ditto.
  • storage/StorageAreaImpl.cpp: (WebCore::StorageAreaImpl::StorageAreaImpl): Move the code that calls StorageAreaSync::create out of here. (WebCore::StorageAreaImpl::create): Move it in here. This makes it so we don't ref the storage area before finishing its creation and calling adoptRef.
  • svg/SVGPaint.cpp: (WebCore::SVGPaint::defaultFill): Use create instead of new. (WebCore::SVGPaint::defaultStroke): Ditto.
  • svg/graphics/filters/SVGFilterBuilder.h: Made the constructor private and added a create function since this is a reference counted object and should not be constructed directly.

2010-06-17 Darin Adler <Darin Adler>

Reviewed by Sam Weinig.

Use adoptRef and create functions in more code paths
https://bugs.webkit.org/show_bug.cgi?id=40760

  • DumpRenderTree/DumpRenderTree.h: Change gLayoutTestController to a RefPtr.
  • DumpRenderTree/LayoutTestController.cpp: (LayoutTestController::create): Added.
  • DumpRenderTree/LayoutTestController.h: Declare the create function.
  • DumpRenderTree/chromium/TestShell.cpp: (TestShell::TestShell): Use create instead of new.
  • DumpRenderTree/chromium/TestShell.h: Use RefPtr instead of OwnPtr.
  • DumpRenderTree/gtk/DumpRenderTree.cpp: (runTest): Use RefPtr and create instead of OwnPtr and new.
  • DumpRenderTree/mac/DumpRenderTree.mm: (runTest): Use RefPtr and create instead of OwnPtr and new.
  • DumpRenderTree/qt/DumpRenderTreeQt.cpp: (WebCore::DumpRenderTree::DumpRenderTree): Use create and releaseRef instead of new.
  • DumpRenderTree/win/DumpRenderTree.cpp: (runTest): Use RefPtr and create instead of OwnPtr and new.
  • DumpRenderTree/wx/DumpRenderTreeWx.cpp: (runTest): Use RefPtr and create instead of OwnPtr and new. (MyApp::OnInit): Removed unneeded code to delete the layout test controller. This is done during each test.
  • Property svn:eol-style set to native
File size: 4.4 KB
Line 
1/*
2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
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.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifndef SymbolTable_h
30#define SymbolTable_h
31
32#include "JSObject.h"
33#include "UString.h"
34#include <wtf/AlwaysInline.h>
35
36namespace JSC {
37
38 static ALWAYS_INLINE int missingSymbolMarker() { return std::numeric_limits<int>::max(); }
39
40 // The bit twiddling in this class assumes that every register index is a
41 // reasonably small positive or negative number, and therefore has its high
42 // four bits all set or all unset.
43
44 struct SymbolTableEntry {
45 SymbolTableEntry()
46 : m_bits(0)
47 {
48 }
49
50 SymbolTableEntry(int index)
51 {
52 ASSERT(isValidIndex(index));
53 pack(index, false, false);
54 }
55
56 SymbolTableEntry(int index, unsigned attributes)
57 {
58 ASSERT(isValidIndex(index));
59 pack(index, attributes & ReadOnly, attributes & DontEnum);
60 }
61
62 bool isNull() const
63 {
64 return !m_bits;
65 }
66
67 int getIndex() const
68 {
69 return m_bits >> FlagBits;
70 }
71
72 unsigned getAttributes() const
73 {
74 unsigned attributes = 0;
75 if (m_bits & ReadOnlyFlag)
76 attributes |= ReadOnly;
77 if (m_bits & DontEnumFlag)
78 attributes |= DontEnum;
79 return attributes;
80 }
81
82 void setAttributes(unsigned attributes)
83 {
84 pack(getIndex(), attributes & ReadOnly, attributes & DontEnum);
85 }
86
87 bool isReadOnly() const
88 {
89 return m_bits & ReadOnlyFlag;
90 }
91
92 private:
93 static const unsigned ReadOnlyFlag = 0x1;
94 static const unsigned DontEnumFlag = 0x2;
95 static const unsigned NotNullFlag = 0x4;
96 static const unsigned FlagBits = 3;
97
98 void pack(int index, bool readOnly, bool dontEnum)
99 {
100 m_bits = (index << FlagBits) | NotNullFlag;
101 if (readOnly)
102 m_bits |= ReadOnlyFlag;
103 if (dontEnum)
104 m_bits |= DontEnumFlag;
105 }
106
107 bool isValidIndex(int index)
108 {
109 return ((index << FlagBits) >> FlagBits) == index;
110 }
111
112 int m_bits;
113 };
114
115 struct SymbolTableIndexHashTraits {
116 typedef SymbolTableEntry TraitType;
117 static SymbolTableEntry emptyValue() { return SymbolTableEntry(); }
118 static const bool emptyValueIsZero = true;
119 static const bool needsDestruction = false;
120 };
121
122 typedef HashMap<RefPtr<UString::Rep>, SymbolTableEntry, IdentifierRepHash, HashTraits<RefPtr<UString::Rep> >, SymbolTableIndexHashTraits> SymbolTable;
123
124 class SharedSymbolTable : public SymbolTable, public RefCounted<SharedSymbolTable> {
125 public:
126 static PassRefPtr<SharedSymbolTable> create() { return adoptRef(new SharedSymbolTable); }
127 private:
128 SharedSymbolTable() { }
129 };
130
131} // namespace JSC
132
133#endif // SymbolTable_h
Note: See TracBrowser for help on using the repository browser.