Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/V8StringResource.h

Issue 2817533003: Replace ASSERT, RELEASE_ASSERT, and ASSERT_NOT_REACHED in bindings (Closed)
Patch Set: fixed dcheck build error Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 29 matching lines...) Expand all
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 : plain_string_(string) { 46 : plain_string_(string) {
47 #if DCHECK_IS_ON() 47 #if DCHECK_IS_ON()
48 thread_id_ = WTF::CurrentThread(); 48 thread_id_ = WTF::CurrentThread();
49 #endif 49 #endif
50 ASSERT(!string.IsNull()); 50 DCHECK(!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 : plain_string_(string.GetString()), atomic_string_(string) { 56 : plain_string_(string.GetString()), atomic_string_(string) {
57 #if DCHECK_IS_ON() 57 #if DCHECK_IS_ON()
58 thread_id_ = WTF::CurrentThread(); 58 thread_id_ = WTF::CurrentThread();
59 #endif 59 #endif
60 ASSERT(!string.IsNull()); 60 DCHECK(!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 DCHECK_IS_ON() 66 #if DCHECK_IS_ON()
67 ASSERT(thread_id_ == WTF::CurrentThread()); 67 DCHECK_EQ(thread_id_, WTF::CurrentThread());
68 #endif 68 #endif
69 int64_t reduced_external_memory = plain_string_.CharactersSizeInBytes(); 69 int64_t reduced_external_memory = plain_string_.CharactersSizeInBytes();
70 if (plain_string_.Impl() != atomic_string_.Impl() && 70 if (plain_string_.Impl() != atomic_string_.Impl() &&
71 !atomic_string_.IsNull()) 71 !atomic_string_.IsNull())
72 reduced_external_memory += atomic_string_.CharactersSizeInBytes(); 72 reduced_external_memory += atomic_string_.CharactersSizeInBytes();
73 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory( 73 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(
74 -reduced_external_memory); 74 -reduced_external_memory);
75 } 75 }
76 76
77 const String& WebcoreString() { return plain_string_; } 77 const String& WebcoreString() { return plain_string_; }
78 78
79 const AtomicString& GetAtomicString() { 79 const AtomicString& GetAtomicString() {
80 #if DCHECK_IS_ON() 80 #if DCHECK_IS_ON()
81 ASSERT(thread_id_ == WTF::CurrentThread()); 81 DCHECK_EQ(thread_id_, WTF::CurrentThread());
82 #endif 82 #endif
83 if (atomic_string_.IsNull()) { 83 if (atomic_string_.IsNull()) {
84 atomic_string_ = AtomicString(plain_string_); 84 atomic_string_ = AtomicString(plain_string_);
85 ASSERT(!atomic_string_.IsNull()); 85 DCHECK(!atomic_string_.IsNull());
86 if (plain_string_.Impl() != atomic_string_.Impl()) 86 if (plain_string_.Impl() != atomic_string_.Impl())
87 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory( 87 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(
88 atomic_string_.CharactersSizeInBytes()); 88 atomic_string_.CharactersSizeInBytes());
89 } 89 }
90 return atomic_string_; 90 return atomic_string_;
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.
(...skipping 12 matching lines...) Expand all
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:
116 explicit WebCoreStringResource16(const String& string) 116 explicit WebCoreStringResource16(const String& string)
117 : WebCoreStringResourceBase(string) { 117 : WebCoreStringResourceBase(string) {
118 ASSERT(!string.Is8Bit()); 118 DCHECK(!string.Is8Bit());
119 } 119 }
120 120
121 explicit WebCoreStringResource16(const AtomicString& string) 121 explicit WebCoreStringResource16(const AtomicString& string)
122 : WebCoreStringResourceBase(string) { 122 : WebCoreStringResourceBase(string) {
123 ASSERT(!string.Is8Bit()); 123 DCHECK(!string.Is8Bit());
124 } 124 }
125 125
126 size_t length() const override { return plain_string_.Impl()->length(); } 126 size_t length() const override { return plain_string_.Impl()->length(); }
127 const uint16_t* data() const override { 127 const uint16_t* data() const override {
128 return reinterpret_cast<const uint16_t*>( 128 return reinterpret_cast<const uint16_t*>(
129 plain_string_.Impl()->Characters16()); 129 plain_string_.Impl()->Characters16());
130 } 130 }
131 }; 131 };
132 132
133 class WebCoreStringResource8 final 133 class WebCoreStringResource8 final
134 : public WebCoreStringResourceBase, 134 : public WebCoreStringResourceBase,
135 public v8::String::ExternalOneByteStringResource { 135 public v8::String::ExternalOneByteStringResource {
136 WTF_MAKE_NONCOPYABLE(WebCoreStringResource8); 136 WTF_MAKE_NONCOPYABLE(WebCoreStringResource8);
137 137
138 public: 138 public:
139 explicit WebCoreStringResource8(const String& string) 139 explicit WebCoreStringResource8(const String& string)
140 : WebCoreStringResourceBase(string) { 140 : WebCoreStringResourceBase(string) {
141 ASSERT(string.Is8Bit()); 141 DCHECK(string.Is8Bit());
142 } 142 }
143 143
144 explicit WebCoreStringResource8(const AtomicString& string) 144 explicit WebCoreStringResource8(const AtomicString& string)
145 : WebCoreStringResourceBase(string) { 145 : WebCoreStringResourceBase(string) {
146 ASSERT(string.Is8Bit()); 146 DCHECK(string.Is8Bit());
147 } 147 }
148 148
149 size_t length() const override { return plain_string_.Impl()->length(); } 149 size_t length() const override { return plain_string_.Impl()->length(); }
150 const char* data() const override { 150 const char* data() const override {
151 return reinterpret_cast<const char*>(plain_string_.Impl()->Characters8()); 151 return reinterpret_cast<const char*>(plain_string_.Impl()->Characters8());
152 } 152 }
153 }; 153 };
154 154
155 enum ExternalMode { kExternalize, kDoNotExternalize }; 155 enum ExternalMode { kExternalize, kDoNotExternalize };
156 156
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 String string_; 262 String string_;
263 }; 263 };
264 264
265 template <> 265 template <>
266 inline bool V8StringResource<kDefaultMode>::IsValid() const { 266 inline bool V8StringResource<kDefaultMode>::IsValid() const {
267 return true; 267 return true;
268 } 268 }
269 269
270 template <> 270 template <>
271 inline String V8StringResource<kDefaultMode>::FallbackString() const { 271 inline String V8StringResource<kDefaultMode>::FallbackString() const {
272 ASSERT_NOT_REACHED(); 272 NOTREACHED();
273 return String(); 273 return String();
274 } 274 }
275 275
276 template <> 276 template <>
277 inline bool V8StringResource<kTreatNullAsEmptyString>::IsValid() const { 277 inline bool V8StringResource<kTreatNullAsEmptyString>::IsValid() const {
278 return !v8_object_->IsNull(); 278 return !v8_object_->IsNull();
279 } 279 }
280 280
281 template <> 281 template <>
282 inline String V8StringResource<kTreatNullAsEmptyString>::FallbackString() 282 inline String V8StringResource<kTreatNullAsEmptyString>::FallbackString()
(...skipping 19 matching lines...) Expand all
302 302
303 template <> 303 template <>
304 inline String 304 inline String
305 V8StringResource<kTreatNullAndUndefinedAsNullString>::FallbackString() const { 305 V8StringResource<kTreatNullAndUndefinedAsNullString>::FallbackString() const {
306 return String(); 306 return String();
307 } 307 }
308 308
309 } // namespace blink 309 } // namespace blink
310 310
311 #endif // V8StringResource_h 311 #endif // V8StringResource_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698