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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 | 47 |
48 | 48 |
49 StringCache::~StringCache() | 49 StringCache::~StringCache() |
50 { | 50 { |
51 // The MapType::Dispose callback calls StringCache::InvalidateLastString, | 51 // The MapType::Dispose callback calls StringCache::InvalidateLastString, |
52 // which will only work while the destructor has not yet finished. Thus, | 52 // which will only work while the destructor has not yet finished. Thus, |
53 // we need to clear the map before the destructor has completed. | 53 // we need to clear the map before the destructor has completed. |
54 m_stringCache.Clear(); | 54 m_stringCache.Clear(); |
55 } | 55 } |
56 | 56 |
57 static v8::Local<v8::String> makeExternalString(const String& string, v8::Isolat
e* isolate) | 57 static v8::Local<v8::String> makeExternalString(v8::Isolate* isolate, const Stri
ng& string) |
58 { | 58 { |
59 if (string.is8Bit()) { | 59 if (string.is8Bit()) { |
60 WebCoreStringResource8* stringResource = new WebCoreStringResource8(stri
ng); | 60 WebCoreStringResource8* stringResource = new WebCoreStringResource8(stri
ng); |
61 v8::Local<v8::String> newString; | 61 v8::Local<v8::String> newString; |
62 if (!v8::String::NewExternalOneByte(isolate, stringResource).ToLocal(&ne
wString)) { | 62 if (!v8::String::NewExternalOneByte(isolate, stringResource).ToLocal(&ne
wString)) { |
63 delete stringResource; | 63 delete stringResource; |
64 return v8::String::Empty(isolate); | 64 return v8::String::Empty(isolate); |
65 } | 65 } |
66 return newString; | 66 return newString; |
67 } | 67 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 } | 106 } |
107 | 107 |
108 returnValue.Set(createStringAndInsertIntoCache(returnValue.GetIsolate(), str
ingImpl)); | 108 returnValue.Set(createStringAndInsertIntoCache(returnValue.GetIsolate(), str
ingImpl)); |
109 } | 109 } |
110 | 110 |
111 v8::Local<v8::String> StringCache::createStringAndInsertIntoCache(v8::Isolate* i
solate, StringImpl* stringImpl) | 111 v8::Local<v8::String> StringCache::createStringAndInsertIntoCache(v8::Isolate* i
solate, StringImpl* stringImpl) |
112 { | 112 { |
113 ASSERT(!m_stringCache.Contains(stringImpl)); | 113 ASSERT(!m_stringCache.Contains(stringImpl)); |
114 ASSERT(stringImpl->length()); | 114 ASSERT(stringImpl->length()); |
115 | 115 |
116 v8::Local<v8::String> newString = makeExternalString(String(stringImpl), iso
late); | 116 v8::Local<v8::String> newString = makeExternalString(isolate, String(stringI
mpl)); |
117 ASSERT(!newString.IsEmpty()); | 117 ASSERT(!newString.IsEmpty()); |
118 ASSERT(newString->Length()); | 118 ASSERT(newString->Length()); |
119 | 119 |
120 v8::UniquePersistent<v8::String> wrapper(isolate, newString); | 120 v8::UniquePersistent<v8::String> wrapper(isolate, newString); |
121 | 121 |
122 stringImpl->ref(); | 122 stringImpl->ref(); |
123 wrapper.MarkIndependent(); | 123 wrapper.MarkIndependent(); |
124 m_stringCache.Set(stringImpl, wrapper.Pass(), &m_lastV8String); | 124 m_stringCache.Set(stringImpl, wrapper.Pass(), &m_lastV8String); |
125 m_lastStringImpl = stringImpl; | 125 m_lastStringImpl = stringImpl; |
126 | 126 |
127 return newString; | 127 return newString; |
128 } | 128 } |
129 | 129 |
130 void StringCache::InvalidateLastString() | 130 void StringCache::InvalidateLastString() |
131 { | 131 { |
132 m_lastStringImpl = nullptr; | 132 m_lastStringImpl = nullptr; |
133 m_lastV8String.Reset(); | 133 m_lastV8String.Reset(); |
134 } | 134 } |
135 | 135 |
136 } // namespace blink | 136 } // namespace blink |
OLD | NEW |