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

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

Issue 242223004: Rename macros TONATIVE_BOOL* and TOSTRING_BOOL to *_DEFAULT (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix comment Created 6 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 | Annotate | Revision Log
« no previous file with comments | « Source/bindings/v8/V8Binding.h ('k') | Source/bindings/v8/V8BindingMacros.h » ('j') | 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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 return static_cast<T>(result); 199 return static_cast<T>(result);
200 if (configuration == EnforceRange) { 200 if (configuration == EnforceRange) {
201 exceptionState.throwTypeError("Value is outside the '" + String(type Name) + "' value range."); 201 exceptionState.throwTypeError("Value is outside the '" + String(type Name) + "' value range.");
202 return 0; 202 return 0;
203 } 203 }
204 result %= LimitsTrait::numberOfValues; 204 result %= LimitsTrait::numberOfValues;
205 return static_cast<T>(result > LimitsTrait::maxValue ? result - LimitsTr ait::numberOfValues : result); 205 return static_cast<T>(result > LimitsTrait::maxValue ? result - LimitsTr ait::numberOfValues : result);
206 } 206 }
207 207
208 // Can the value be converted to a number? 208 // Can the value be converted to a number?
209 TONATIVE_BOOL_EXCEPTIONSTATE(v8::Local<v8::Number>, numberObject, value->ToN umber(), exceptionState, 0); 209 TONATIVE_DEFAULT_EXCEPTIONSTATE(v8::Local<v8::Number>, numberObject, value-> ToNumber(), exceptionState, 0);
210 if (numberObject.IsEmpty()) { 210 if (numberObject.IsEmpty()) {
211 exceptionState.throwTypeError("Not convertible to a number value (of typ e '" + String(typeName) + "'."); 211 exceptionState.throwTypeError("Not convertible to a number value (of typ e '" + String(typeName) + "'.");
212 return 0; 212 return 0;
213 } 213 }
214 214
215 if (configuration == EnforceRange) 215 if (configuration == EnforceRange)
216 return enforceRange(numberObject->Value(), LimitsTrait::minValue, Limits Trait::maxValue, typeName, exceptionState); 216 return enforceRange(numberObject->Value(), LimitsTrait::minValue, Limits Trait::maxValue, typeName, exceptionState);
217 217
218 double numberValue = numberObject->Value(); 218 double numberValue = numberObject->Value();
219 if (std::isnan(numberValue) || std::isinf(numberValue) || !numberValue) 219 if (std::isnan(numberValue) || std::isinf(numberValue) || !numberValue)
(...skipping 16 matching lines...) Expand all
236 if (result >= 0 && result <= LimitsTrait::maxValue) 236 if (result >= 0 && result <= LimitsTrait::maxValue)
237 return static_cast<T>(result); 237 return static_cast<T>(result);
238 if (configuration == EnforceRange) { 238 if (configuration == EnforceRange) {
239 exceptionState.throwTypeError("Value is outside the '" + String(type Name) + "' value range."); 239 exceptionState.throwTypeError("Value is outside the '" + String(type Name) + "' value range.");
240 return 0; 240 return 0;
241 } 241 }
242 return static_cast<T>(result); 242 return static_cast<T>(result);
243 } 243 }
244 244
245 // Can the value be converted to a number? 245 // Can the value be converted to a number?
246 TONATIVE_BOOL_EXCEPTIONSTATE(v8::Local<v8::Number>, numberObject, value->ToN umber(), exceptionState, 0); 246 TONATIVE_DEFAULT_EXCEPTIONSTATE(v8::Local<v8::Number>, numberObject, value-> ToNumber(), exceptionState, 0);
247 if (numberObject.IsEmpty()) { 247 if (numberObject.IsEmpty()) {
248 exceptionState.throwTypeError("Not convertible to a number value (of typ e '" + String(typeName) + "'."); 248 exceptionState.throwTypeError("Not convertible to a number value (of typ e '" + String(typeName) + "'.");
249 return 0; 249 return 0;
250 } 250 }
251 251
252 if (configuration == EnforceRange) 252 if (configuration == EnforceRange)
253 return enforceRange(numberObject->Value(), 0, LimitsTrait::maxValue, typ eName, exceptionState); 253 return enforceRange(numberObject->Value(), 0, LimitsTrait::maxValue, typ eName, exceptionState);
254 254
255 // Does the value convert to nan or to an infinity? 255 // Does the value convert to nan or to an infinity?
256 double numberValue = numberObject->Value(); 256 double numberValue = numberObject->Value();
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 return toUInt16(value, NormalConversion, exceptionState); 308 return toUInt16(value, NormalConversion, exceptionState);
309 } 309 }
310 310
311 int32_t toInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf iguration, ExceptionState& exceptionState) 311 int32_t toInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf iguration, ExceptionState& exceptionState)
312 { 312 {
313 // Fast case. The value is already a 32-bit integer. 313 // Fast case. The value is already a 32-bit integer.
314 if (value->IsInt32()) 314 if (value->IsInt32())
315 return value->Int32Value(); 315 return value->Int32Value();
316 316
317 // Can the value be converted to a number? 317 // Can the value be converted to a number?
318 TONATIVE_BOOL_EXCEPTIONSTATE(v8::Local<v8::Number>, numberObject, value->ToN umber(), exceptionState, 0); 318 TONATIVE_DEFAULT_EXCEPTIONSTATE(v8::Local<v8::Number>, numberObject, value-> ToNumber(), exceptionState, 0);
319 if (numberObject.IsEmpty()) { 319 if (numberObject.IsEmpty()) {
320 exceptionState.throwTypeError("Not convertible to a number value (of typ e 'long'.)"); 320 exceptionState.throwTypeError("Not convertible to a number value (of typ e 'long'.)");
321 return 0; 321 return 0;
322 } 322 }
323 323
324 if (configuration == EnforceRange) 324 if (configuration == EnforceRange)
325 return enforceRange(numberObject->Value(), kMinInt32, kMaxInt32, "long", exceptionState); 325 return enforceRange(numberObject->Value(), kMinInt32, kMaxInt32, "long", exceptionState);
326 326
327 // Does the value convert to nan or to an infinity? 327 // Does the value convert to nan or to an infinity?
328 double numberValue = numberObject->Value(); 328 double numberValue = numberObject->Value();
329 if (std::isnan(numberValue) || std::isinf(numberValue)) 329 if (std::isnan(numberValue) || std::isinf(numberValue))
330 return 0; 330 return 0;
331 331
332 if (configuration == Clamp) 332 if (configuration == Clamp)
333 return clampTo<int32_t>(numberObject->Value()); 333 return clampTo<int32_t>(numberObject->Value());
334 334
335 TONATIVE_BOOL_EXCEPTIONSTATE(int32_t, result, numberObject->Int32Value(), ex ceptionState, 0); 335 TONATIVE_DEFAULT_EXCEPTIONSTATE(int32_t, result, numberObject->Int32Value(), exceptionState, 0);
336 return result; 336 return result;
337 } 337 }
338 338
339 int32_t toInt32(v8::Handle<v8::Value> value) 339 int32_t toInt32(v8::Handle<v8::Value> value)
340 { 340 {
341 NonThrowableExceptionState exceptionState; 341 NonThrowableExceptionState exceptionState;
342 return toInt32(value, NormalConversion, exceptionState); 342 return toInt32(value, NormalConversion, exceptionState);
343 } 343 }
344 344
345 uint32_t toUInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration co nfiguration, ExceptionState& exceptionState) 345 uint32_t toUInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration co nfiguration, ExceptionState& exceptionState)
346 { 346 {
347 // Fast case. The value is already a 32-bit unsigned integer. 347 // Fast case. The value is already a 32-bit unsigned integer.
348 if (value->IsUint32()) 348 if (value->IsUint32())
349 return value->Uint32Value(); 349 return value->Uint32Value();
350 350
351 // Fast case. The value is a 32-bit signed integer - possibly positive? 351 // Fast case. The value is a 32-bit signed integer - possibly positive?
352 if (value->IsInt32()) { 352 if (value->IsInt32()) {
353 int32_t result = value->Int32Value(); 353 int32_t result = value->Int32Value();
354 if (result >= 0) 354 if (result >= 0)
355 return result; 355 return result;
356 if (configuration == EnforceRange) { 356 if (configuration == EnforceRange) {
357 exceptionState.throwTypeError("Value is outside the 'unsigned long' value range."); 357 exceptionState.throwTypeError("Value is outside the 'unsigned long' value range.");
358 return 0; 358 return 0;
359 } 359 }
360 return result; 360 return result;
361 } 361 }
362 362
363 // Can the value be converted to a number? 363 // Can the value be converted to a number?
364 TONATIVE_BOOL_EXCEPTIONSTATE(v8::Local<v8::Number>, numberObject, value->ToN umber(), exceptionState, 0); 364 TONATIVE_DEFAULT_EXCEPTIONSTATE(v8::Local<v8::Number>, numberObject, value-> ToNumber(), exceptionState, 0);
365 if (numberObject.IsEmpty()) { 365 if (numberObject.IsEmpty()) {
366 exceptionState.throwTypeError("Not convertible to a number value (of typ e 'unsigned long'.)"); 366 exceptionState.throwTypeError("Not convertible to a number value (of typ e 'unsigned long'.)");
367 return 0; 367 return 0;
368 } 368 }
369 369
370 if (configuration == EnforceRange) 370 if (configuration == EnforceRange)
371 return enforceRange(numberObject->Value(), 0, kMaxUInt32, "unsigned long ", exceptionState); 371 return enforceRange(numberObject->Value(), 0, kMaxUInt32, "unsigned long ", exceptionState);
372 372
373 // Does the value convert to nan or to an infinity? 373 // Does the value convert to nan or to an infinity?
374 double numberValue = numberObject->Value(); 374 double numberValue = numberObject->Value();
375 if (std::isnan(numberValue) || std::isinf(numberValue)) 375 if (std::isnan(numberValue) || std::isinf(numberValue))
376 return 0; 376 return 0;
377 377
378 if (configuration == Clamp) 378 if (configuration == Clamp)
379 return clampTo<uint32_t>(numberObject->Value()); 379 return clampTo<uint32_t>(numberObject->Value());
380 380
381 TONATIVE_BOOL(uint32_t, result, numberObject->Uint32Value(), 0); 381 TONATIVE_DEFAULT(uint32_t, result, numberObject->Uint32Value(), 0);
382 return result; 382 return result;
383 } 383 }
384 384
385 uint32_t toUInt32(v8::Handle<v8::Value> value) 385 uint32_t toUInt32(v8::Handle<v8::Value> value)
386 { 386 {
387 NonThrowableExceptionState exceptionState; 387 NonThrowableExceptionState exceptionState;
388 return toUInt32(value, NormalConversion, exceptionState); 388 return toUInt32(value, NormalConversion, exceptionState);
389 } 389 }
390 390
391 int64_t toInt64(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf iguration, ExceptionState& exceptionState) 391 int64_t toInt64(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf iguration, ExceptionState& exceptionState)
392 { 392 {
393 // Fast case. The value is a 32-bit integer. 393 // Fast case. The value is a 32-bit integer.
394 if (value->IsInt32()) 394 if (value->IsInt32())
395 return value->Int32Value(); 395 return value->Int32Value();
396 396
397 // Can the value be converted to a number? 397 // Can the value be converted to a number?
398 TONATIVE_BOOL_EXCEPTIONSTATE(v8::Local<v8::Number>, numberObject, value->ToN umber(), exceptionState, 0); 398 TONATIVE_DEFAULT_EXCEPTIONSTATE(v8::Local<v8::Number>, numberObject, value-> ToNumber(), exceptionState, 0);
399 if (numberObject.IsEmpty()) { 399 if (numberObject.IsEmpty()) {
400 exceptionState.throwTypeError("Not convertible to a number value (of typ e 'long long'.)"); 400 exceptionState.throwTypeError("Not convertible to a number value (of typ e 'long long'.)");
401 return 0; 401 return 0;
402 } 402 }
403 403
404 double x = numberObject->Value(); 404 double x = numberObject->Value();
405 405
406 if (configuration == EnforceRange) 406 if (configuration == EnforceRange)
407 return enforceRange(x, -kJSMaxInteger, kJSMaxInteger, "long long", excep tionState); 407 return enforceRange(x, -kJSMaxInteger, kJSMaxInteger, "long long", excep tionState);
408 408
(...skipping 25 matching lines...) Expand all
434 if (result >= 0) 434 if (result >= 0)
435 return result; 435 return result;
436 if (configuration == EnforceRange) { 436 if (configuration == EnforceRange) {
437 exceptionState.throwTypeError("Value is outside the 'unsigned long l ong' value range."); 437 exceptionState.throwTypeError("Value is outside the 'unsigned long l ong' value range.");
438 return 0; 438 return 0;
439 } 439 }
440 return result; 440 return result;
441 } 441 }
442 442
443 // Can the value be converted to a number? 443 // Can the value be converted to a number?
444 TONATIVE_BOOL_EXCEPTIONSTATE(v8::Local<v8::Number>, numberObject, value->ToN umber(), exceptionState, 0); 444 TONATIVE_DEFAULT_EXCEPTIONSTATE(v8::Local<v8::Number>, numberObject, value-> ToNumber(), exceptionState, 0);
445 if (numberObject.IsEmpty()) { 445 if (numberObject.IsEmpty()) {
446 exceptionState.throwTypeError("Not convertible to a number value (of typ e 'unsigned long long'.)"); 446 exceptionState.throwTypeError("Not convertible to a number value (of typ e 'unsigned long long'.)");
447 return 0; 447 return 0;
448 } 448 }
449 449
450 double x = numberObject->Value(); 450 double x = numberObject->Value();
451 451
452 if (configuration == EnforceRange) 452 if (configuration == EnforceRange)
453 return enforceRange(x, 0, kJSMaxInteger, "unsigned long long", exception State); 453 return enforceRange(x, 0, kJSMaxInteger, "unsigned long long", exception State);
454 454
455 // Does the value convert to nan or to an infinity? 455 // Does the value convert to nan or to an infinity?
456 if (std::isnan(x) || std::isinf(x)) 456 if (std::isnan(x) || std::isinf(x))
457 return 0; 457 return 0;
458 458
459 // NaNs and +/-Infinity should be 0, otherwise modulo 2^64. 459 // NaNs and +/-Infinity should be 0, otherwise modulo 2^64.
460 unsigned long long integer; 460 unsigned long long integer;
461 doubleToInteger(x, integer); 461 doubleToInteger(x, integer);
462 return integer; 462 return integer;
463 } 463 }
464 464
465 uint64_t toUInt64(v8::Handle<v8::Value> value) 465 uint64_t toUInt64(v8::Handle<v8::Value> value)
466 { 466 {
467 NonThrowableExceptionState exceptionState; 467 NonThrowableExceptionState exceptionState;
468 return toUInt64(value, NormalConversion, exceptionState); 468 return toUInt64(value, NormalConversion, exceptionState);
469 } 469 }
470 470
471 float toFloat(v8::Handle<v8::Value> value, ExceptionState& exceptionState) 471 float toFloat(v8::Handle<v8::Value> value, ExceptionState& exceptionState)
472 { 472 {
473 TONATIVE_BOOL_EXCEPTIONSTATE(v8::Local<v8::Number>, numberObject, value->ToN umber(), exceptionState, 0); 473 TONATIVE_DEFAULT_EXCEPTIONSTATE(v8::Local<v8::Number>, numberObject, value-> ToNumber(), exceptionState, 0);
474 return numberObject->NumberValue(); 474 return numberObject->NumberValue();
475 } 475 }
476 476
477 PassRefPtrWillBeRawPtr<XPathNSResolver> toXPathNSResolver(v8::Handle<v8::Value> value, v8::Isolate* isolate) 477 PassRefPtrWillBeRawPtr<XPathNSResolver> toXPathNSResolver(v8::Handle<v8::Value> value, v8::Isolate* isolate)
478 { 478 {
479 RefPtrWillBeRawPtr<XPathNSResolver> resolver = nullptr; 479 RefPtrWillBeRawPtr<XPathNSResolver> resolver = nullptr;
480 if (V8XPathNSResolver::hasInstance(value, isolate)) 480 if (V8XPathNSResolver::hasInstance(value, isolate))
481 resolver = V8XPathNSResolver::toNative(v8::Handle<v8::Object>::Cast(valu e)); 481 resolver = V8XPathNSResolver::toNative(v8::Handle<v8::Object>::Cast(valu e));
482 else if (value->IsObject()) 482 else if (value->IsObject())
483 resolver = V8CustomXPathNSResolver::create(value->ToObject(), isolate); 483 resolver = V8CustomXPathNSResolver::create(value->ToObject(), isolate);
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 } 671 }
672 672
673 V8ExecutionScope::V8ExecutionScope(v8::Isolate* isolate) 673 V8ExecutionScope::V8ExecutionScope(v8::Isolate* isolate)
674 : m_handleScope(isolate) 674 : m_handleScope(isolate)
675 , m_contextScope(v8::Context::New(isolate)) 675 , m_contextScope(v8::Context::New(isolate))
676 , m_scriptState(NewScriptState::create(isolate->GetCurrentContext(), DOMWrap perWorld::create())) 676 , m_scriptState(NewScriptState::create(isolate->GetCurrentContext(), DOMWrap perWorld::create()))
677 { 677 {
678 } 678 }
679 679
680 } // namespace WebCore 680 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/bindings/v8/V8Binding.h ('k') | Source/bindings/v8/V8BindingMacros.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698