| 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 26 matching lines...) Expand all Loading... |
| 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 USING_FAST_MALLOC(WebCoreStringResourceBase); | 41 USING_FAST_MALLOC(WebCoreStringResourceBase); |
| 42 WTF_MAKE_NONCOPYABLE(WebCoreStringResourceBase); | 42 WTF_MAKE_NONCOPYABLE(WebCoreStringResourceBase); |
| 43 | 43 |
| 44 public: | 44 public: |
| 45 explicit WebCoreStringResourceBase(const String& string) | 45 explicit WebCoreStringResourceBase(const String& string) |
| 46 : m_plainString(string) { | 46 : m_plainString(string) { |
| 47 #if ENABLE(ASSERT) | 47 #if DCHECK_IS_ON() |
| 48 m_threadId = WTF::currentThread(); | 48 m_threadId = WTF::currentThread(); |
| 49 #endif | 49 #endif |
| 50 ASSERT(!string.isNull()); | 50 ASSERT(!string.isNull()); |
| 51 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory( | 51 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory( |
| 52 string.charactersSizeInBytes()); | 52 string.charactersSizeInBytes()); |
| 53 } | 53 } |
| 54 | 54 |
| 55 explicit WebCoreStringResourceBase(const AtomicString& string) | 55 explicit WebCoreStringResourceBase(const AtomicString& string) |
| 56 : m_plainString(string.getString()), m_atomicString(string) { | 56 : m_plainString(string.getString()), m_atomicString(string) { |
| 57 #if ENABLE(ASSERT) | 57 #if DCHECK_IS_ON() |
| 58 m_threadId = WTF::currentThread(); | 58 m_threadId = WTF::currentThread(); |
| 59 #endif | 59 #endif |
| 60 ASSERT(!string.isNull()); | 60 ASSERT(!string.isNull()); |
| 61 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory( | 61 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory( |
| 62 string.charactersSizeInBytes()); | 62 string.charactersSizeInBytes()); |
| 63 } | 63 } |
| 64 | 64 |
| 65 virtual ~WebCoreStringResourceBase() { | 65 virtual ~WebCoreStringResourceBase() { |
| 66 #if ENABLE(ASSERT) | 66 #if DCHECK_IS_ON() |
| 67 ASSERT(m_threadId == WTF::currentThread()); | 67 ASSERT(m_threadId == WTF::currentThread()); |
| 68 #endif | 68 #endif |
| 69 int64_t reducedExternalMemory = m_plainString.charactersSizeInBytes(); | 69 int64_t reducedExternalMemory = m_plainString.charactersSizeInBytes(); |
| 70 if (m_plainString.impl() != m_atomicString.impl() && | 70 if (m_plainString.impl() != m_atomicString.impl() && |
| 71 !m_atomicString.isNull()) | 71 !m_atomicString.isNull()) |
| 72 reducedExternalMemory += m_atomicString.charactersSizeInBytes(); | 72 reducedExternalMemory += m_atomicString.charactersSizeInBytes(); |
| 73 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory( | 73 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory( |
| 74 -reducedExternalMemory); | 74 -reducedExternalMemory); |
| 75 } | 75 } |
| 76 | 76 |
| 77 const String& webcoreString() { return m_plainString; } | 77 const String& webcoreString() { return m_plainString; } |
| 78 | 78 |
| 79 const AtomicString& getAtomicString() { | 79 const AtomicString& getAtomicString() { |
| 80 #if ENABLE(ASSERT) | 80 #if DCHECK_IS_ON() |
| 81 ASSERT(m_threadId == WTF::currentThread()); | 81 ASSERT(m_threadId == WTF::currentThread()); |
| 82 #endif | 82 #endif |
| 83 if (m_atomicString.isNull()) { | 83 if (m_atomicString.isNull()) { |
| 84 m_atomicString = AtomicString(m_plainString); | 84 m_atomicString = AtomicString(m_plainString); |
| 85 ASSERT(!m_atomicString.isNull()); | 85 ASSERT(!m_atomicString.isNull()); |
| 86 if (m_plainString.impl() != m_atomicString.impl()) | 86 if (m_plainString.impl() != m_atomicString.impl()) |
| 87 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory( | 87 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory( |
| 88 m_atomicString.charactersSizeInBytes()); | 88 m_atomicString.charactersSizeInBytes()); |
| 89 } | 89 } |
| 90 return m_atomicString; | 90 return m_atomicString; |
| 91 } | 91 } |
| 92 | 92 |
| 93 protected: | 93 protected: |
| 94 // A shallow copy of the string. Keeps the string buffer alive until the V8 | 94 // A shallow copy of the string. Keeps the string buffer alive until the V8 |
| 95 // engine garbage collects it. | 95 // engine garbage collects it. |
| 96 String m_plainString; | 96 String m_plainString; |
| 97 // If this string is atomic or has been made atomic earlier the | 97 // 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 | 98 // 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 | 99 // off non-atomic and becomes atomic later it is necessary to keep |
| 100 // the original string alive because v8 may keep derived pointers | 100 // the original string alive because v8 may keep derived pointers |
| 101 // into that string. | 101 // into that string. |
| 102 AtomicString m_atomicString; | 102 AtomicString m_atomicString; |
| 103 | 103 |
| 104 private: | 104 private: |
| 105 #if ENABLE(ASSERT) | 105 #if DCHECK_IS_ON() |
| 106 WTF::ThreadIdentifier m_threadId; | 106 WTF::ThreadIdentifier m_threadId; |
| 107 #endif | 107 #endif |
| 108 }; | 108 }; |
| 109 | 109 |
| 110 class WebCoreStringResource16 final | 110 class WebCoreStringResource16 final |
| 111 : public WebCoreStringResourceBase, | 111 : public WebCoreStringResourceBase, |
| 112 public v8::String::ExternalStringResource { | 112 public v8::String::ExternalStringResource { |
| 113 WTF_MAKE_NONCOPYABLE(WebCoreStringResource16); | 113 WTF_MAKE_NONCOPYABLE(WebCoreStringResource16); |
| 114 | 114 |
| 115 public: | 115 public: |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 | 301 |
| 302 template <> | 302 template <> |
| 303 inline String | 303 inline String |
| 304 V8StringResource<TreatNullAndUndefinedAsNullString>::fallbackString() const { | 304 V8StringResource<TreatNullAndUndefinedAsNullString>::fallbackString() const { |
| 305 return String(); | 305 return String(); |
| 306 } | 306 } |
| 307 | 307 |
| 308 } // namespace blink | 308 } // namespace blink |
| 309 | 309 |
| 310 #endif // V8StringResource_h | 310 #endif // V8StringResource_h |
| OLD | NEW |