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

Side by Side Diff: Source/bindings/v8/custom/V8CSSStyleDeclarationCustom.cpp

Issue 98793002: Get rid of extra NULL check when indexing CSSStyleDeclaration (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007-2011 Google Inc. All rights reserved. 2 * Copyright (C) 2007-2011 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 } 79 }
80 return false; 80 return false;
81 } 81 }
82 82
83 struct CSSPropertyInfo { 83 struct CSSPropertyInfo {
84 unsigned propID: 30; // CSSPropertyID 84 unsigned propID: 30; // CSSPropertyID
85 unsigned nameWithDash: 1; 85 unsigned nameWithDash: 1;
86 unsigned nameWithCssPrefix: 1; 86 unsigned nameWithCssPrefix: 1;
87 }; 87 };
88 88
89 static inline void countCssPropertyInfoUsage(const CSSPropertyInfo& propInfo)
90 {
91 if (propInfo.nameWithDash)
92 UseCounter::count(activeDOMWindow(), UseCounter::CSSStyleDeclarationProp ertyName);
93 if (propInfo.propID == CSSPropertyFloat && !propInfo.nameWithCssPrefix)
94 UseCounter::count(activeDOMWindow(), UseCounter::CSSStyleDeclarationFloa tPropertyName);
95 }
96
89 // When getting properties on CSSStyleDeclarations, the name used from 97 // When getting properties on CSSStyleDeclarations, the name used from
90 // Javascript and the actual name of the property are not the same, so 98 // Javascript and the actual name of the property are not the same, so
91 // we have to do the following translation. The translation turns upper 99 // we have to do the following translation. The translation turns upper
92 // case characters into lower case characters and inserts dashes to 100 // case characters into lower case characters and inserts dashes to
93 // separate words. 101 // separate words.
94 // 102 //
95 // Example: 'backgroundPositionY' -> 'background-position-y' 103 // Example: 'backgroundPositionY' -> 'background-position-y'
96 // 104 //
97 // Also, certain prefixes such as 'css-' are stripped. 105 // Also, certain prefixes such as 'css-' are stripped.
98 static CSSPropertyInfo* cssPropertyInfo(v8::Handle<v8::String> v8PropertyName) 106 static CSSPropertyInfo* cssPropertyInfo(v8::Handle<v8::String> v8PropertyName)
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 String propName = builder.toString(); 148 String propName = builder.toString();
141 CSSPropertyID propertyID = cssPropertyID(propName); 149 CSSPropertyID propertyID = cssPropertyID(propName);
142 if (propertyID && RuntimeCSSEnabled::isCSSPropertyEnabled(propertyID)) { 150 if (propertyID && RuntimeCSSEnabled::isCSSPropertyEnabled(propertyID)) {
143 propInfo = new CSSPropertyInfo(); 151 propInfo = new CSSPropertyInfo();
144 propInfo->propID = propertyID; 152 propInfo->propID = propertyID;
145 propInfo->nameWithDash = hasSeenDash; 153 propInfo->nameWithDash = hasSeenDash;
146 propInfo->nameWithCssPrefix = hasSeenCssPrefix; 154 propInfo->nameWithCssPrefix = hasSeenCssPrefix;
147 map.add(propertyName, propInfo); 155 map.add(propertyName, propInfo);
148 } 156 }
149 } 157 }
150
151 if (propInfo) {
152 if (propInfo->nameWithDash)
153 UseCounter::count(activeDOMWindow(), UseCounter::CSSStyleDeclaration PropertyName);
154 if (propInfo->propID == CSSPropertyFloat && !propInfo->nameWithCssPrefix )
155 UseCounter::count(activeDOMWindow(), UseCounter::CSSStyleDeclaration FloatPropertyName);
156 }
157
158 return propInfo; 158 return propInfo;
159 } 159 }
160 160
161 void V8CSSStyleDeclaration::namedPropertyEnumeratorCustom(const v8::PropertyCall backInfo<v8::Array>& info) 161 void V8CSSStyleDeclaration::namedPropertyEnumeratorCustom(const v8::PropertyCall backInfo<v8::Array>& info)
162 { 162 {
163 typedef Vector<String, numCSSProperties - 1> PreAllocatedPropertyVector; 163 typedef Vector<String, numCSSProperties - 1> PreAllocatedPropertyVector;
164 DEFINE_STATIC_LOCAL(PreAllocatedPropertyVector, propertyNames, ()); 164 DEFINE_STATIC_LOCAL(PreAllocatedPropertyVector, propertyNames, ());
165 static unsigned propertyNamesLength = 0; 165 static unsigned propertyNamesLength = 0;
166 166
167 if (propertyNames.isEmpty()) { 167 if (propertyNames.isEmpty()) {
(...skipping 13 matching lines...) Expand all
181 properties->Set(v8::Integer::New(i, info.GetIsolate()), v8String(key, in fo.GetIsolate())); 181 properties->Set(v8::Integer::New(i, info.GetIsolate()), v8String(key, in fo.GetIsolate()));
182 } 182 }
183 183
184 v8SetReturnValue(info, properties); 184 v8SetReturnValue(info, properties);
185 } 185 }
186 186
187 void V8CSSStyleDeclaration::namedPropertyQueryCustom(v8::Local<v8::String> v8Nam e, const v8::PropertyCallbackInfo<v8::Integer>& info) 187 void V8CSSStyleDeclaration::namedPropertyQueryCustom(v8::Local<v8::String> v8Nam e, const v8::PropertyCallbackInfo<v8::Integer>& info)
188 { 188 {
189 // NOTE: cssPropertyInfo lookups incur several mallocs. 189 // NOTE: cssPropertyInfo lookups incur several mallocs.
190 // Successful lookups have the same cost the first time, but are cached. 190 // Successful lookups have the same cost the first time, but are cached.
191 if (cssPropertyInfo(v8Name)) { 191 if (CSSPropertyInfo* propInfo = cssPropertyInfo(v8Name)) {
192 countCssPropertyInfoUsage(*propInfo);
192 v8SetReturnValueInt(info, 0); 193 v8SetReturnValueInt(info, 0);
193 return; 194 return;
194 } 195 }
195 } 196 }
196 197
197 void V8CSSStyleDeclaration::namedPropertyGetterCustom(v8::Local<v8::String> name , const v8::PropertyCallbackInfo<v8::Value>& info) 198 void V8CSSStyleDeclaration::namedPropertyGetterCustom(v8::Local<v8::String> name , const v8::PropertyCallbackInfo<v8::Value>& info)
198 { 199 {
199 // First look for API defined attributes on the style declaration object. 200 // First look for API defined attributes on the style declaration object.
200 if (info.Holder()->HasRealNamedCallbackProperty(name)) 201 if (info.Holder()->HasRealNamedCallbackProperty(name))
201 return; 202 return;
202 203
203 // Search the style declaration. 204 // Search the style declaration.
204 CSSPropertyInfo* propInfo = cssPropertyInfo(name); 205 CSSPropertyInfo* propInfo = cssPropertyInfo(name);
205 206
206 // Do not handle non-property names. 207 // Do not handle non-property names.
207 if (!propInfo) 208 if (!propInfo)
208 return; 209 return;
209 210
211 countCssPropertyInfoUsage(*propInfo);
210 CSSStyleDeclaration* imp = V8CSSStyleDeclaration::toNative(info.Holder()); 212 CSSStyleDeclaration* imp = V8CSSStyleDeclaration::toNative(info.Holder());
211 RefPtr<CSSValue> cssValue = imp->getPropertyCSSValueInternal(static_cast<CSS PropertyID>(propInfo->propID)); 213 RefPtr<CSSValue> cssValue = imp->getPropertyCSSValueInternal(static_cast<CSS PropertyID>(propInfo->propID));
212 if (cssValue) { 214 if (cssValue) {
213 v8SetReturnValueStringOrNull(info, cssValue->cssText(), info.GetIsolate( )); 215 v8SetReturnValueStringOrNull(info, cssValue->cssText(), info.GetIsolate( ));
214 return; 216 return;
215 } 217 }
216 218
217 String result = imp->getPropertyValueInternal(static_cast<CSSPropertyID>(pro pInfo->propID)); 219 String result = imp->getPropertyValueInternal(static_cast<CSSPropertyID>(pro pInfo->propID));
218 if (result.isNull()) 220 if (result.isNull())
219 result = ""; // convert null to empty string. 221 result = ""; // convert null to empty string.
220 222
221 v8SetReturnValueString(info, result, info.GetIsolate()); 223 v8SetReturnValueString(info, result, info.GetIsolate());
222 } 224 }
223 225
224 void V8CSSStyleDeclaration::namedPropertySetterCustom(v8::Local<v8::String> name , v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) 226 void V8CSSStyleDeclaration::namedPropertySetterCustom(v8::Local<v8::String> name , v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info)
225 { 227 {
226 CSSStyleDeclaration* imp = V8CSSStyleDeclaration::toNative(info.Holder()); 228 CSSStyleDeclaration* imp = V8CSSStyleDeclaration::toNative(info.Holder());
227 CSSPropertyInfo* propInfo = cssPropertyInfo(name); 229 CSSPropertyInfo* propInfo = cssPropertyInfo(name);
228 if (!propInfo) 230 if (!propInfo)
229 return; 231 return;
230 232
233 countCssPropertyInfoUsage(*propInfo);
231 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithNullCheck>, proper tyValue, value); 234 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithNullCheck>, proper tyValue, value);
232 ExceptionState exceptionState(info.Holder(), info.GetIsolate()); 235 ExceptionState exceptionState(info.Holder(), info.GetIsolate());
233 imp->setPropertyInternal(static_cast<CSSPropertyID>(propInfo->propID), prope rtyValue, false, exceptionState); 236 imp->setPropertyInternal(static_cast<CSSPropertyID>(propInfo->propID), prope rtyValue, false, exceptionState);
234 237
235 if (exceptionState.throwIfNeeded()) 238 if (exceptionState.throwIfNeeded())
236 return; 239 return;
237 240
238 v8SetReturnValue(info, value); 241 v8SetReturnValue(info, value);
239 } 242 }
240 243
241 } // namespace WebCore 244 } // namespace WebCore
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698