Changeset 126159 in webkit
- Timestamp:
- Aug 21, 2012 8:25:47 AM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r126157 r126159 1 2012-08-21 Sheriff Bot <webkit.review.bot@gmail.com> 2 3 Unreviewed, rolling out r126150. 4 http://trac.webkit.org/changeset/126150 5 https://bugs.webkit.org/show_bug.cgi?id=94605 6 7 Breaks 73 layout tests on chromium.webkit builder (Requested 8 by pfeldman on #webkit). 9 10 * UseV8.cmake: 11 * WebCore.gypi: 12 * bindings/v8/V8Binding.cpp: 13 (StringTraits): 14 (WebCore): 15 (WebCore::v8StringToWebCoreString): 16 (WebCore::int32ToWebCoreStringFast): 17 (WebCore::int32ToWebCoreString): 18 * bindings/v8/V8Binding.h: 19 (WebCore): 20 (V8ParameterBase): 21 (WebCore::V8ParameterBase::operator String): 22 (WebCore::V8ParameterBase::operator AtomicString): 23 (WebCore::V8ParameterBase::V8ParameterBase): 24 (WebCore::V8ParameterBase::prepareBase): 25 (WebCore::V8ParameterBase::object): 26 (WebCore::V8ParameterBase::setString): 27 (WebCore::V8ParameterBase::toString): 28 (WebCore::::prepare): 29 * bindings/v8/V8StringResource.cpp: Removed. 30 * bindings/v8/V8StringResource.h: Removed. 31 1 32 2012-08-21 Philippe Normand <pnormand@igalia.com> 2 33 -
trunk/Source/WebCore/UseV8.cmake
r126150 r126159 146 146 bindings/v8/custom/V8SQLTransactionSyncCustom.cpp 147 147 bindings/v8/custom/V8StorageCustom.cpp 148 bindings/v8/custom/V8StringResource.cpp149 148 bindings/v8/custom/V8StyleSheetCustom.cpp 150 149 bindings/v8/custom/V8StyleSheetListCustom.cpp -
trunk/Source/WebCore/WebCore.gypi
r126150 r126159 2289 2289 'bindings/v8/V8RecursionScope.cpp', 2290 2290 'bindings/v8/V8RecursionScope.h', 2291 'bindings/v8/V8StringResource.cpp',2292 'bindings/v8/V8StringResource.h',2293 2291 'bindings/v8/V8ThrowException.cpp', 2294 2292 'bindings/v8/V8ThrowException.h', -
trunk/Source/WebCore/bindings/v8/V8Binding.cpp
r126150 r126159 205 205 } 206 206 207 template <class S> struct StringTraits 208 { 209 static S fromStringResource(WebCoreStringResource* resource); 210 211 static S fromV8String(v8::Handle<v8::String> v8String, int length); 212 }; 213 214 template<> 215 struct StringTraits<String> 216 { 217 static String fromStringResource(WebCoreStringResource* resource) 218 { 219 return resource->webcoreString(); 220 } 221 222 static String fromV8String(v8::Handle<v8::String> v8String, int length) 223 { 224 ASSERT(v8String->Length() == length); 225 // NOTE: as of now, String(const UChar*, int) performs String::createUninitialized 226 // anyway, so no need to optimize like we do for AtomicString below. 227 UChar* buffer; 228 String result = String::createUninitialized(length, buffer); 229 v8String->Write(reinterpret_cast<uint16_t*>(buffer), 0, length); 230 return result; 231 } 232 }; 233 234 template<> 235 struct StringTraits<AtomicString> 236 { 237 static AtomicString fromStringResource(WebCoreStringResource* resource) 238 { 239 return resource->atomicString(); 240 } 241 242 static AtomicString fromV8String(v8::Handle<v8::String> v8String, int length) 243 { 244 ASSERT(v8String->Length() == length); 245 static const int inlineBufferSize = 16; 246 if (length <= inlineBufferSize) { 247 UChar inlineBuffer[inlineBufferSize]; 248 v8String->Write(reinterpret_cast<uint16_t*>(inlineBuffer), 0, length); 249 return AtomicString(inlineBuffer, length); 250 } 251 UChar* buffer; 252 String tmp = String::createUninitialized(length, buffer); 253 v8String->Write(reinterpret_cast<uint16_t*>(buffer), 0, length); 254 return AtomicString(tmp); 255 } 256 }; 257 258 template <typename StringType> 259 StringType v8StringToWebCoreString(v8::Handle<v8::String> v8String, ExternalMode external) 260 { 261 WebCoreStringResource* stringResource = WebCoreStringResource::toStringResource(v8String); 262 if (stringResource) 263 return StringTraits<StringType>::fromStringResource(stringResource); 264 265 int length = v8String->Length(); 266 if (!length) { 267 // Avoid trying to morph empty strings, as they do not have enough room to contain the external reference. 268 return StringImpl::empty(); 269 } 270 271 StringType result(StringTraits<StringType>::fromV8String(v8String, length)); 272 273 if (external == Externalize && v8String->CanMakeExternal()) { 274 stringResource = new WebCoreStringResource(result); 275 if (!v8String->MakeExternal(stringResource)) { 276 // In case of a failure delete the external resource as it was not used. 277 delete stringResource; 278 } 279 } 280 return result; 281 } 282 283 // Explicitly instantiate the above template with the expected parameterizations, 284 // to ensure the compiler generates the code; otherwise link errors can result in GCC 4.4. 285 template String v8StringToWebCoreString<String>(v8::Handle<v8::String>, ExternalMode); 286 template AtomicString v8StringToWebCoreString<AtomicString>(v8::Handle<v8::String>, ExternalMode); 287 288 // Fast but non thread-safe version. 289 String int32ToWebCoreStringFast(int value) 290 { 291 // Caching of small strings below is not thread safe: newly constructed AtomicString 292 // are not safely published. 293 ASSERT(isMainThread()); 294 295 // Most numbers used are <= 100. Even if they aren't used there's very little cost in using the space. 296 const int kLowNumbers = 100; 297 DEFINE_STATIC_LOCAL(Vector<AtomicString>, lowNumbers, (kLowNumbers + 1)); 298 String webCoreString; 299 if (0 <= value && value <= kLowNumbers) { 300 webCoreString = lowNumbers[value]; 301 if (!webCoreString) { 302 AtomicString valueString = AtomicString(String::number(value)); 303 lowNumbers[value] = valueString; 304 webCoreString = valueString; 305 } 306 } else 307 webCoreString = String::number(value); 308 return webCoreString; 309 } 310 311 String int32ToWebCoreString(int value) 312 { 313 // If we are on the main thread (this should always true for non-workers), call the faster one. 314 if (isMainThread()) 315 return int32ToWebCoreStringFast(value); 316 return String::number(value); 317 } 318 207 319 v8::Persistent<v8::FunctionTemplate> createRawTemplate() 208 320 { -
trunk/Source/WebCore/bindings/v8/V8Binding.h
r126150 r126159 42 42 #include "V8PerIsolateData.h" 43 43 #include "V8Proxy.h" 44 #include "V8StringResource.h"45 44 #include "V8ThrowException.h" 46 45 #include "V8ValueCache.h" … … 77 76 return isolate ? v8::Null(isolate) : v8::Null(); 78 77 } 78 79 enum ExternalMode { 80 Externalize, 81 DoNotExternalize 82 }; 83 84 template <typename StringType> 85 StringType v8StringToWebCoreString(v8::Handle<v8::String>, ExternalMode); 79 86 80 87 // Convert v8 types to a WTF::String. If the V8 string is not already … … 358 365 v8::Persistent<v8::FunctionTemplate> getToStringTemplate(); 359 366 367 String int32ToWebCoreString(int value); 368 360 369 PassRefPtr<DOMStringList> toDOMStringList(v8::Handle<v8::Value>); 361 370 … … 376 385 void crashIfV8IsDead(); 377 386 387 class V8ParameterBase { 388 public: 389 operator String() { return toString<String>(); } 390 operator AtomicString() { return toString<AtomicString>(); } 391 392 protected: 393 V8ParameterBase(v8::Local<v8::Value> object) : m_v8Object(object), m_mode(Externalize), m_string() { } 394 395 bool prepareBase() 396 { 397 if (m_v8Object.IsEmpty()) 398 return true; 399 400 if (LIKELY(m_v8Object->IsString())) 401 return true; 402 403 if (LIKELY(m_v8Object->IsInt32())) { 404 setString(int32ToWebCoreString(m_v8Object->Int32Value())); 405 return true; 406 } 407 408 m_mode = DoNotExternalize; 409 v8::TryCatch block; 410 m_v8Object = m_v8Object->ToString(); 411 // Handle the case where an exception is thrown as part of invoking toString on the object. 412 if (block.HasCaught()) { 413 block.ReThrow(); 414 return false; 415 } 416 return true; 417 } 418 419 v8::Local<v8::Value> object() { return m_v8Object; } 420 421 void setString(const String& string) 422 { 423 m_string = string; 424 m_v8Object.Clear(); // To signal that String is ready. 425 } 426 427 private: 428 v8::Local<v8::Value> m_v8Object; 429 ExternalMode m_mode; 430 String m_string; 431 432 template <class StringType> 433 StringType toString() 434 { 435 if (LIKELY(!m_v8Object.IsEmpty())) 436 return v8StringToWebCoreString<StringType>(m_v8Object.As<v8::String>(), m_mode); 437 438 return StringType(m_string); 439 } 440 }; 441 442 // V8Parameter is an adapter class that converts V8 values to Strings 443 // or AtomicStrings as appropriate, using multiple typecast operators. 444 enum V8ParameterMode { 445 DefaultMode, 446 WithNullCheck, 447 WithUndefinedOrNullCheck 448 }; 449 template <V8ParameterMode MODE = DefaultMode> 450 class V8Parameter: public V8ParameterBase { 451 public: 452 V8Parameter(v8::Local<v8::Value> object) : V8ParameterBase(object) { } 453 V8Parameter(v8::Local<v8::Value> object, bool) : V8ParameterBase(object) { prepare(); } 454 455 bool prepare(); 456 }; 457 458 template<> inline bool V8Parameter<DefaultMode>::prepare() 459 { 460 return V8ParameterBase::prepareBase(); 461 } 462 463 template<> inline bool V8Parameter<WithNullCheck>::prepare() 464 { 465 if (object().IsEmpty() || object()->IsNull()) { 466 setString(String()); 467 return true; 468 } 469 470 return V8ParameterBase::prepareBase(); 471 } 472 473 template<> inline bool V8Parameter<WithUndefinedOrNullCheck>::prepare() 474 { 475 if (object().IsEmpty() || object()->IsNull() || object()->IsUndefined()) { 476 setString(String()); 477 return true; 478 } 479 480 return V8ParameterBase::prepareBase(); 481 } 482 378 483 } // namespace WebCore 379 484
Note: See TracChangeset
for help on using the changeset viewer.