| 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 13 matching lines...) Expand all Loading... |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #ifndef V8StringResource_h | 26 #ifndef V8StringResource_h |
| 27 #define V8StringResource_h | 27 #define V8StringResource_h |
| 28 | 28 |
| 29 #include "bindings/core/v8/ExceptionState.h" | 29 #include "bindings/core/v8/ExceptionState.h" |
| 30 #include "core/CoreExport.h" | 30 #include "core/CoreExport.h" |
| 31 #include "wtf/Allocator.h" | 31 #include "wtf/Allocator.h" |
| 32 #include "wtf/Threading.h" | 32 #include "wtf/Threading.h" |
| 33 #include "wtf/text/AtomicString.h" | 33 #include "wtf/text/AtomicString.h" |
| 34 #include "wtf/text/CompressableString.h" |
| 34 #include <v8.h> | 35 #include <v8.h> |
| 35 | 36 |
| 36 namespace blink { | 37 namespace blink { |
| 37 | 38 |
| 38 // WebCoreStringResource is a helper class for v8ExternalString. It is used | 39 // WebCoreStringResource is a helper class for v8ExternalString. It is used |
| 39 // to manage the life-cycle of the underlying buffer of the external string. | 40 // to manage the life-cycle of the underlying buffer of the external string. |
| 40 class WebCoreStringResourceBase { | 41 class WebCoreStringResourceBase { |
| 41 WTF_MAKE_FAST_ALLOCATED(WebCoreStringResourceBase); | 42 WTF_MAKE_FAST_ALLOCATED(WebCoreStringResourceBase); |
| 42 WTF_MAKE_NONCOPYABLE(WebCoreStringResourceBase); | 43 WTF_MAKE_NONCOPYABLE(WebCoreStringResourceBase); |
| 43 public: | 44 public: |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 ASSERT(string.is8Bit()); | 147 ASSERT(string.is8Bit()); |
| 147 } | 148 } |
| 148 | 149 |
| 149 size_t length() const override { return m_plainString.impl()->length(); } | 150 size_t length() const override { return m_plainString.impl()->length(); } |
| 150 const char* data() const override | 151 const char* data() const override |
| 151 { | 152 { |
| 152 return reinterpret_cast<const char*>(m_plainString.impl()->characters8()
); | 153 return reinterpret_cast<const char*>(m_plainString.impl()->characters8()
); |
| 153 } | 154 } |
| 154 }; | 155 }; |
| 155 | 156 |
| 157 class WebCoreCompressableStringResource16 final : public v8::String::ExternalStr
ingResource { |
| 158 WTF_MAKE_NONCOPYABLE(WebCoreCompressableStringResource16); |
| 159 public: |
| 160 explicit WebCoreCompressableStringResource16(RefPtrWillBeRawPtr<Compressable
String> string) |
| 161 : m_string(string) |
| 162 { |
| 163 ASSERT(m_string); |
| 164 ASSERT(!m_string->is8Bit()); |
| 165 } |
| 166 |
| 167 size_t length() const override |
| 168 { |
| 169 return m_string->length(); |
| 170 } |
| 171 |
| 172 const uint16_t* data() const override |
| 173 { |
| 174 return reinterpret_cast<const uint16_t*>(m_string->toString().characters
16()); |
| 175 } |
| 176 |
| 177 private: |
| 178 RefPtrWillBeMember<CompressableString> m_string; |
| 179 }; |
| 180 |
| 181 class WebCoreCompressableStringResource8 final : public v8::String::ExternalOneB
yteStringResource { |
| 182 WTF_MAKE_NONCOPYABLE(WebCoreCompressableStringResource8); |
| 183 public: |
| 184 explicit WebCoreCompressableStringResource8(RefPtrWillBeRawPtr<CompressableS
tring> string) |
| 185 : m_string(string) |
| 186 { |
| 187 ASSERT(m_string); |
| 188 ASSERT(m_string->is8Bit()); |
| 189 } |
| 190 |
| 191 size_t length() const override |
| 192 { |
| 193 return m_string->length(); |
| 194 } |
| 195 |
| 196 const char* data() const override |
| 197 { |
| 198 return reinterpret_cast<const char*>(m_string->toString().characters8())
; |
| 199 } |
| 200 |
| 201 private: |
| 202 RefPtrWillBeMember<CompressableString> m_string; |
| 203 }; |
| 204 |
| 156 enum ExternalMode { | 205 enum ExternalMode { |
| 157 Externalize, | 206 Externalize, |
| 158 DoNotExternalize | 207 DoNotExternalize |
| 159 }; | 208 }; |
| 160 | 209 |
| 161 template <typename StringType> | 210 template <typename StringType> |
| 162 CORE_EXPORT StringType v8StringToWebCoreString(v8::Local<v8::String>, ExternalMo
de); | 211 CORE_EXPORT StringType v8StringToWebCoreString(v8::Local<v8::String>, ExternalMo
de); |
| 163 CORE_EXPORT String int32ToWebCoreString(int value); | 212 CORE_EXPORT String int32ToWebCoreString(int value); |
| 164 | 213 |
| 165 // V8StringResource is an adapter class that converts V8 values to Strings | 214 // V8StringResource is an adapter class that converts V8 values to Strings |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 } | 369 } |
| 321 | 370 |
| 322 template<> inline String V8StringResource<TreatNullAndUndefinedAsNullString>::fa
llbackString() const | 371 template<> inline String V8StringResource<TreatNullAndUndefinedAsNullString>::fa
llbackString() const |
| 323 { | 372 { |
| 324 return String(); | 373 return String(); |
| 325 } | 374 } |
| 326 | 375 |
| 327 } // namespace blink | 376 } // namespace blink |
| 328 | 377 |
| 329 #endif // V8StringResource_h | 378 #endif // V8StringResource_h |
| OLD | NEW |