| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "wtf/text/WTFString.h" | 32 #include "wtf/text/WTFString.h" |
| 33 | 33 |
| 34 namespace WebCore { | 34 namespace WebCore { |
| 35 | 35 |
| 36 class ExternalStringVisitor; | 36 class ExternalStringVisitor; |
| 37 | 37 |
| 38 // WebCoreStringResource is a helper class for v8ExternalString. It is used | 38 // WebCoreStringResource is a helper class for v8ExternalString. It is used |
| 39 // to manage the life-cycle of the underlying buffer of the external string. | 39 // to manage the life-cycle of the underlying buffer of the external string. |
| 40 class WebCoreStringResourceBase { | 40 class WebCoreStringResourceBase { |
| 41 public: | 41 public: |
| 42 static WebCoreStringResourceBase* toWebCoreStringResourceBase(v8::Handle<v8:
:String>); | |
| 43 | |
| 44 explicit WebCoreStringResourceBase(const String& string) | 42 explicit WebCoreStringResourceBase(const String& string) |
| 45 : m_plainString(string) | 43 : m_plainString(string) |
| 46 { | 44 { |
| 47 #ifndef NDEBUG | 45 #ifndef NDEBUG |
| 48 m_threadId = WTF::currentThread(); | 46 m_threadId = WTF::currentThread(); |
| 49 #endif | 47 #endif |
| 50 ASSERT(!string.isNull()); | 48 ASSERT(!string.isNull()); |
| 51 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(memoryC
onsumption(string)); | 49 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(memoryC
onsumption(string)); |
| 52 } | 50 } |
| 53 | 51 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 82 #endif | 80 #endif |
| 83 if (m_atomicString.isNull()) { | 81 if (m_atomicString.isNull()) { |
| 84 m_atomicString = AtomicString(m_plainString); | 82 m_atomicString = AtomicString(m_plainString); |
| 85 ASSERT(!m_atomicString.isNull()); | 83 ASSERT(!m_atomicString.isNull()); |
| 86 if (m_plainString.impl() != m_atomicString.impl()) | 84 if (m_plainString.impl() != m_atomicString.impl()) |
| 87 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory
(memoryConsumption(m_atomicString.string())); | 85 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory
(memoryConsumption(m_atomicString.string())); |
| 88 } | 86 } |
| 89 return m_atomicString; | 87 return m_atomicString; |
| 90 } | 88 } |
| 91 | 89 |
| 92 void visitStrings(ExternalStringVisitor*); | |
| 93 | |
| 94 protected: | 90 protected: |
| 95 // A shallow copy of the string. Keeps the string buffer alive until the V8
engine garbage collects it. | 91 // A shallow copy of the string. Keeps the string buffer alive until the V8
engine garbage collects it. |
| 96 String m_plainString; | 92 String m_plainString; |
| 97 // If this string is atomic or has been made atomic earlier the | 93 // If this string is atomic or has been made atomic earlier the |
| 98 // atomic string is held here. In the case where the string starts | 94 // atomic string is held here. In the case where the string starts |
| 99 // off non-atomic and becomes atomic later it is necessary to keep | 95 // off non-atomic and becomes atomic later it is necessary to keep |
| 100 // the original string alive because v8 may keep derived pointers | 96 // the original string alive because v8 may keep derived pointers |
| 101 // into that string. | 97 // into that string. |
| 102 AtomicString m_atomicString; | 98 AtomicString m_atomicString; |
| 103 | 99 |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 if (m_v8Object.IsEmpty() || m_v8Object->IsNull() || m_v8Object->IsUndefined(
)) { | 244 if (m_v8Object.IsEmpty() || m_v8Object->IsNull() || m_v8Object->IsUndefined(
)) { |
| 249 setString(String()); | 245 setString(String()); |
| 250 return true; | 246 return true; |
| 251 } | 247 } |
| 252 return prepareBase(); | 248 return prepareBase(); |
| 253 } | 249 } |
| 254 | 250 |
| 255 } // namespace WebCore | 251 } // namespace WebCore |
| 256 | 252 |
| 257 #endif // V8StringResource_h | 253 #endif // V8StringResource_h |
| OLD | NEW |