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

Side by Side Diff: Source/bindings/core/v8/V8Binding.cpp

Issue 947123002: [bindings] Split toUInt32 into faster inline and non-inline slower path. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Patch for landing Created 5 years, 10 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
« no previous file with comments | « Source/bindings/core/v8/V8Binding.h ('k') | 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) 2006, 2007, 2008, 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008, 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 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 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 344
345 return numberObject->Int32Value(); 345 return numberObject->Int32Value();
346 } 346 }
347 347
348 int32_t toInt32(v8::Handle<v8::Value> value) 348 int32_t toInt32(v8::Handle<v8::Value> value)
349 { 349 {
350 NonThrowableExceptionState exceptionState; 350 NonThrowableExceptionState exceptionState;
351 return toInt32(value, NormalConversion, exceptionState); 351 return toInt32(value, NormalConversion, exceptionState);
352 } 352 }
353 353
354 uint32_t toUInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration co nfiguration, ExceptionState& exceptionState) 354 uint32_t toUInt32Slow(v8::Handle<v8::Value> value, IntegerConversionConfiguratio n configuration, ExceptionState& exceptionState)
355 { 355 {
356 // Fast case. The value is already a 32-bit unsigned integer. 356 ASSERT(!value->IsUint32());
357 if (value->IsUint32())
358 return value->Uint32Value();
359
360 // Fast case. The value is a 32-bit signed integer - possibly positive?
361 if (value->IsInt32()) { 357 if (value->IsInt32()) {
358 ASSERT(configuration != NormalConversion);
362 int32_t result = value->Int32Value(); 359 int32_t result = value->Int32Value();
363 if (result >= 0) 360 if (result >= 0)
364 return result; 361 return result;
365 if (configuration == EnforceRange) { 362 if (configuration == EnforceRange) {
366 exceptionState.throwTypeError("Value is outside the 'unsigned long' value range."); 363 exceptionState.throwTypeError("Value is outside the 'unsigned long' value range.");
367 return 0; 364 return 0;
368 } 365 }
369 if (configuration == Clamp) 366 ASSERT(configuration == Clamp);
370 return clampTo<uint32_t>(result); 367 return clampTo<uint32_t>(result);
371 return result;
372 } 368 }
373 369
374 v8::Local<v8::Number> numberObject; 370 v8::Isolate* isolate = v8::Isolate::GetCurrent();
375 if (value->IsNumber()) { 371 // Can the value be converted to a number?
376 numberObject = value.As<v8::Number>(); 372 v8::TryCatch block(isolate);
377 } else { 373 v8::Local<v8::Number> numberObject = value->ToNumber(isolate);
378 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 374 if (block.HasCaught()) {
379 // Can the value be converted to a number? 375 exceptionState.rethrowV8Exception(block.Exception());
380 v8::TryCatch block(isolate); 376 return 0;
381 numberObject = value->ToNumber(isolate);
382 if (block.HasCaught()) {
383 exceptionState.rethrowV8Exception(block.Exception());
384 return 0;
385 }
386 } 377 }
387 ASSERT(!numberObject.IsEmpty()); 378 ASSERT(!numberObject.IsEmpty());
388 379
389 if (configuration == EnforceRange) 380 if (configuration == EnforceRange)
390 return enforceRange(numberObject->Value(), 0, kMaxUInt32, "unsigned long ", exceptionState); 381 return enforceRange(numberObject->Value(), 0, kMaxUInt32, "unsigned long ", exceptionState);
391 382
392 double numberValue = numberObject->Value(); 383 double numberValue = numberObject->Value();
393 384
394 if (std::isnan(numberValue)) 385 if (std::isnan(numberValue))
395 return 0; 386 return 0;
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after
1086 attributes->append(value); 1077 attributes->append(value);
1087 } 1078 }
1088 1079
1089 AttributesWithSideEffectOnGet::AttributeSet* AttributesWithSideEffectOnGet::attr ibutesWithSideEffectOnGet() 1080 AttributesWithSideEffectOnGet::AttributeSet* AttributesWithSideEffectOnGet::attr ibutesWithSideEffectOnGet()
1090 { 1081 {
1091 DEFINE_STATIC_LOCAL(AttributeSet, attributes, ()); 1082 DEFINE_STATIC_LOCAL(AttributeSet, attributes, ());
1092 return &attributes; 1083 return &attributes;
1093 } 1084 }
1094 1085
1095 } // namespace blink 1086 } // namespace blink
OLDNEW
« no previous file with comments | « Source/bindings/core/v8/V8Binding.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698