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

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

Issue 1013643002: [bindings] Make sure v8::Isolate is being passed to toXXX() conversion routines as argument. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 9 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') | Source/bindings/core/v8/V8BindingTest.cpp » ('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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 static const unsigned numberOfValues = 65536; // 2^16 166 static const unsigned numberOfValues = 65536; // 2^16
167 }; 167 };
168 168
169 template <> 169 template <>
170 struct IntTypeLimits<uint16_t> { 170 struct IntTypeLimits<uint16_t> {
171 static const unsigned short maxValue = 65535; 171 static const unsigned short maxValue = 65535;
172 static const unsigned numberOfValues = 65536; // 2^16 172 static const unsigned numberOfValues = 65536; // 2^16
173 }; 173 };
174 174
175 template <typename T> 175 template <typename T>
176 static inline T toSmallerInt(v8::Handle<v8::Value> value, IntegerConversionConfi guration configuration, const char* typeName, ExceptionState& exceptionState) 176 static inline T toSmallerInt(v8::Isolate* isolate, v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, const char* typeName, ExceptionSta te& exceptionState)
177 { 177 {
178 typedef IntTypeLimits<T> LimitsTrait; 178 typedef IntTypeLimits<T> LimitsTrait;
179 179
180 // Fast case. The value is already a 32-bit integer in the right range. 180 // Fast case. The value is already a 32-bit integer in the right range.
181 if (value->IsInt32()) { 181 if (value->IsInt32()) {
182 int32_t result = value->Int32Value(); 182 int32_t result = value->Int32Value();
183 if (result >= LimitsTrait::minValue && result <= LimitsTrait::maxValue) 183 if (result >= LimitsTrait::minValue && result <= LimitsTrait::maxValue)
184 return static_cast<T>(result); 184 return static_cast<T>(result);
185 if (configuration == EnforceRange) { 185 if (configuration == EnforceRange) {
186 exceptionState.throwTypeError("Value is outside the '" + String(type Name) + "' value range."); 186 exceptionState.throwTypeError("Value is outside the '" + String(type Name) + "' value range.");
187 return 0; 187 return 0;
188 } 188 }
189 if (configuration == Clamp) 189 if (configuration == Clamp)
190 return clampTo<T>(result); 190 return clampTo<T>(result);
191 result %= LimitsTrait::numberOfValues; 191 result %= LimitsTrait::numberOfValues;
192 return static_cast<T>(result > LimitsTrait::maxValue ? result - LimitsTr ait::numberOfValues : result); 192 return static_cast<T>(result > LimitsTrait::maxValue ? result - LimitsTr ait::numberOfValues : result);
193 } 193 }
194 194
195 v8::Local<v8::Number> numberObject; 195 v8::Local<v8::Number> numberObject;
196 if (value->IsNumber()) { 196 if (value->IsNumber()) {
197 numberObject = value.As<v8::Number>(); 197 numberObject = value.As<v8::Number>();
198 } else { 198 } else {
199 v8::Isolate* isolate = v8::Isolate::GetCurrent();
200 // Can the value be converted to a number? 199 // Can the value be converted to a number?
201 v8::TryCatch block(isolate); 200 v8::TryCatch block(isolate);
202 numberObject = value->ToNumber(isolate); 201 numberObject = value->ToNumber(isolate);
203 if (block.HasCaught()) { 202 if (block.HasCaught()) {
204 exceptionState.rethrowV8Exception(block.Exception()); 203 exceptionState.rethrowV8Exception(block.Exception());
205 return 0; 204 return 0;
206 } 205 }
207 } 206 }
208 ASSERT(!numberObject.IsEmpty()); 207 ASSERT(!numberObject.IsEmpty());
209 208
(...skipping 10 matching lines...) Expand all
220 if (std::isinf(numberValue)) 219 if (std::isinf(numberValue))
221 return 0; 220 return 0;
222 221
223 numberValue = numberValue < 0 ? -floor(fabs(numberValue)) : floor(fabs(numbe rValue)); 222 numberValue = numberValue < 0 ? -floor(fabs(numberValue)) : floor(fabs(numbe rValue));
224 numberValue = fmod(numberValue, LimitsTrait::numberOfValues); 223 numberValue = fmod(numberValue, LimitsTrait::numberOfValues);
225 224
226 return static_cast<T>(numberValue > LimitsTrait::maxValue ? numberValue - Li mitsTrait::numberOfValues : numberValue); 225 return static_cast<T>(numberValue > LimitsTrait::maxValue ? numberValue - Li mitsTrait::numberOfValues : numberValue);
227 } 226 }
228 227
229 template <typename T> 228 template <typename T>
230 static inline T toSmallerUInt(v8::Handle<v8::Value> value, IntegerConversionConf iguration configuration, const char* typeName, ExceptionState& exceptionState) 229 static inline T toSmallerUInt(v8::Isolate* isolate, v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, const char* typeName, ExceptionSt ate& exceptionState)
231 { 230 {
232 typedef IntTypeLimits<T> LimitsTrait; 231 typedef IntTypeLimits<T> LimitsTrait;
233 232
234 // Fast case. The value is a 32-bit signed integer - possibly positive? 233 // Fast case. The value is a 32-bit signed integer - possibly positive?
235 if (value->IsInt32()) { 234 if (value->IsInt32()) {
236 int32_t result = value->Int32Value(); 235 int32_t result = value->Int32Value();
237 if (result >= 0 && result <= LimitsTrait::maxValue) 236 if (result >= 0 && result <= LimitsTrait::maxValue)
238 return static_cast<T>(result); 237 return static_cast<T>(result);
239 if (configuration == EnforceRange) { 238 if (configuration == EnforceRange) {
240 exceptionState.throwTypeError("Value is outside the '" + String(type Name) + "' value range."); 239 exceptionState.throwTypeError("Value is outside the '" + String(type Name) + "' value range.");
241 return 0; 240 return 0;
242 } 241 }
243 if (configuration == Clamp) 242 if (configuration == Clamp)
244 return clampTo<T>(result); 243 return clampTo<T>(result);
245 return static_cast<T>(result); 244 return static_cast<T>(result);
246 } 245 }
247 246
248 v8::Local<v8::Number> numberObject; 247 v8::Local<v8::Number> numberObject;
249 if (value->IsNumber()) { 248 if (value->IsNumber()) {
250 numberObject = value.As<v8::Number>(); 249 numberObject = value.As<v8::Number>();
251 } else { 250 } else {
252 v8::Isolate* isolate = v8::Isolate::GetCurrent();
253 // Can the value be converted to a number? 251 // Can the value be converted to a number?
254 v8::TryCatch block(isolate); 252 v8::TryCatch block(isolate);
255 numberObject = value->ToNumber(isolate); 253 numberObject = value->ToNumber(isolate);
256 if (block.HasCaught()) { 254 if (block.HasCaught()) {
257 exceptionState.rethrowV8Exception(block.Exception()); 255 exceptionState.rethrowV8Exception(block.Exception());
258 return 0; 256 return 0;
259 } 257 }
260 } 258 }
261 ASSERT(!numberObject.IsEmpty()); 259 ASSERT(!numberObject.IsEmpty());
262 260
263 if (configuration == EnforceRange) 261 if (configuration == EnforceRange)
264 return enforceRange(numberObject->Value(), 0, LimitsTrait::maxValue, typ eName, exceptionState); 262 return enforceRange(numberObject->Value(), 0, LimitsTrait::maxValue, typ eName, exceptionState);
265 263
266 double numberValue = numberObject->Value(); 264 double numberValue = numberObject->Value();
267 265
268 if (std::isnan(numberValue) || !numberValue) 266 if (std::isnan(numberValue) || !numberValue)
269 return 0; 267 return 0;
270 268
271 if (configuration == Clamp) 269 if (configuration == Clamp)
272 return clampTo<T>(numberValue); 270 return clampTo<T>(numberValue);
273 271
274 if (std::isinf(numberValue)) 272 if (std::isinf(numberValue))
275 return 0; 273 return 0;
276 274
277 numberValue = numberValue < 0 ? -floor(fabs(numberValue)) : floor(fabs(numbe rValue)); 275 numberValue = numberValue < 0 ? -floor(fabs(numberValue)) : floor(fabs(numbe rValue));
278 return static_cast<T>(fmod(numberValue, LimitsTrait::numberOfValues)); 276 return static_cast<T>(fmod(numberValue, LimitsTrait::numberOfValues));
279 } 277 }
280 278
281 int8_t toInt8(v8::Handle<v8::Value> value, IntegerConversionConfiguration config uration, ExceptionState& exceptionState) 279 int8_t toInt8(v8::Isolate* isolate, v8::Handle<v8::Value> value, IntegerConversi onConfiguration configuration, ExceptionState& exceptionState)
282 { 280 {
283 return toSmallerInt<int8_t>(value, configuration, "byte", exceptionState); 281 return toSmallerInt<int8_t>(isolate, value, configuration, "byte", exception State);
284 } 282 }
285 283
286 int8_t toInt8(v8::Handle<v8::Value> value) 284 int8_t toInt8(v8::Isolate* isolate, v8::Handle<v8::Value> value)
287 { 285 {
288 NonThrowableExceptionState exceptionState; 286 NonThrowableExceptionState exceptionState;
289 return toInt8(value, NormalConversion, exceptionState); 287 return toInt8(isolate, value, NormalConversion, exceptionState);
290 } 288 }
291 289
292 uint8_t toUInt8(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf iguration, ExceptionState& exceptionState) 290 uint8_t toUInt8(v8::Isolate* isolate, v8::Handle<v8::Value> value, IntegerConver sionConfiguration configuration, ExceptionState& exceptionState)
293 { 291 {
294 return toSmallerUInt<uint8_t>(value, configuration, "octet", exceptionState) ; 292 return toSmallerUInt<uint8_t>(isolate, value, configuration, "octet", except ionState);
295 } 293 }
296 294
297 uint8_t toUInt8(v8::Handle<v8::Value> value) 295 uint8_t toUInt8(v8::Isolate* isolate, v8::Handle<v8::Value> value)
298 { 296 {
299 NonThrowableExceptionState exceptionState; 297 NonThrowableExceptionState exceptionState;
300 return toUInt8(value, NormalConversion, exceptionState); 298 return toUInt8(isolate, value, NormalConversion, exceptionState);
301 } 299 }
302 300
303 int16_t toInt16(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf iguration, ExceptionState& exceptionState) 301 int16_t toInt16(v8::Isolate* isolate, v8::Handle<v8::Value> value, IntegerConver sionConfiguration configuration, ExceptionState& exceptionState)
304 { 302 {
305 return toSmallerInt<int16_t>(value, configuration, "short", exceptionState); 303 return toSmallerInt<int16_t>(isolate, value, configuration, "short", excepti onState);
306 } 304 }
307 305
308 int16_t toInt16(v8::Handle<v8::Value> value) 306 int16_t toInt16(v8::Isolate* isolate, v8::Handle<v8::Value> value)
309 { 307 {
310 NonThrowableExceptionState exceptionState; 308 NonThrowableExceptionState exceptionState;
311 return toInt16(value, NormalConversion, exceptionState); 309 return toInt16(isolate, value, NormalConversion, exceptionState);
312 } 310 }
313 311
314 uint16_t toUInt16(v8::Handle<v8::Value> value, IntegerConversionConfiguration co nfiguration, ExceptionState& exceptionState) 312 uint16_t toUInt16(v8::Isolate* isolate, v8::Handle<v8::Value> value, IntegerConv ersionConfiguration configuration, ExceptionState& exceptionState)
315 { 313 {
316 return toSmallerUInt<uint16_t>(value, configuration, "unsigned short", excep tionState); 314 return toSmallerUInt<uint16_t>(isolate, value, configuration, "unsigned shor t", exceptionState);
317 } 315 }
318 316
319 uint16_t toUInt16(v8::Handle<v8::Value> value) 317 uint16_t toUInt16(v8::Isolate* isolate, v8::Handle<v8::Value> value)
320 { 318 {
321 NonThrowableExceptionState exceptionState; 319 NonThrowableExceptionState exceptionState;
322 return toUInt16(value, NormalConversion, exceptionState); 320 return toUInt16(isolate, value, NormalConversion, exceptionState);
323 } 321 }
324 322
325 int32_t toInt32Slow(v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, ExceptionState& exceptionState) 323 int32_t toInt32Slow(v8::Isolate* isolate, v8::Handle<v8::Value> value, IntegerCo nversionConfiguration configuration, ExceptionState& exceptionState)
326 { 324 {
327 ASSERT(!value->IsInt32()); 325 ASSERT(!value->IsInt32());
328 v8::Isolate* isolate = v8::Isolate::GetCurrent();
329 // Can the value be converted to a number? 326 // Can the value be converted to a number?
330 v8::TryCatch block(isolate); 327 v8::TryCatch block(isolate);
331 v8::Local<v8::Number> numberObject = value->ToNumber(isolate); 328 v8::Local<v8::Number> numberObject = value->ToNumber(isolate);
332 if (block.HasCaught()) { 329 if (block.HasCaught()) {
333 exceptionState.rethrowV8Exception(block.Exception()); 330 exceptionState.rethrowV8Exception(block.Exception());
334 return 0; 331 return 0;
335 } 332 }
336 333
337 ASSERT(!numberObject.IsEmpty()); 334 ASSERT(!numberObject.IsEmpty());
338 335
339 double numberValue = numberObject->Value(); 336 double numberValue = numberObject->Value();
340 if (configuration == EnforceRange) 337 if (configuration == EnforceRange)
341 return enforceRange(numberValue, kMinInt32, kMaxInt32, "long", exception State); 338 return enforceRange(numberValue, kMinInt32, kMaxInt32, "long", exception State);
342 339
343 if (std::isnan(numberValue)) 340 if (std::isnan(numberValue))
344 return 0; 341 return 0;
345 342
346 if (configuration == Clamp) 343 if (configuration == Clamp)
347 return clampTo<int32_t>(numberValue); 344 return clampTo<int32_t>(numberValue);
348 345
349 if (std::isinf(numberValue)) 346 if (std::isinf(numberValue))
350 return 0; 347 return 0;
351 348
352 return numberObject->Int32Value(); 349 return numberObject->Int32Value();
353 } 350 }
354 351
355 int32_t toInt32(v8::Handle<v8::Value> value) 352 int32_t toInt32(v8::Isolate* isolate, v8::Handle<v8::Value> value)
356 { 353 {
357 NonThrowableExceptionState exceptionState; 354 NonThrowableExceptionState exceptionState;
358 return toInt32(value, NormalConversion, exceptionState); 355 return toInt32(isolate, value, NormalConversion, exceptionState);
359 } 356 }
360 357
361 uint32_t toUInt32Slow(v8::Handle<v8::Value> value, IntegerConversionConfiguratio n configuration, ExceptionState& exceptionState) 358 uint32_t toUInt32Slow(v8::Isolate* isolate, v8::Handle<v8::Value> value, Integer ConversionConfiguration configuration, ExceptionState& exceptionState)
362 { 359 {
363 ASSERT(!value->IsUint32()); 360 ASSERT(!value->IsUint32());
364 if (value->IsInt32()) { 361 if (value->IsInt32()) {
365 ASSERT(configuration != NormalConversion); 362 ASSERT(configuration != NormalConversion);
366 int32_t result = value->Int32Value(); 363 int32_t result = value->Int32Value();
367 if (result >= 0) 364 if (result >= 0)
368 return result; 365 return result;
369 if (configuration == EnforceRange) { 366 if (configuration == EnforceRange) {
370 exceptionState.throwTypeError("Value is outside the 'unsigned long' value range."); 367 exceptionState.throwTypeError("Value is outside the 'unsigned long' value range.");
371 return 0; 368 return 0;
372 } 369 }
373 ASSERT(configuration == Clamp); 370 ASSERT(configuration == Clamp);
374 return clampTo<uint32_t>(result); 371 return clampTo<uint32_t>(result);
375 } 372 }
376 373
377 v8::Isolate* isolate = v8::Isolate::GetCurrent();
378 // Can the value be converted to a number? 374 // Can the value be converted to a number?
379 v8::TryCatch block(isolate); 375 v8::TryCatch block(isolate);
380 v8::Local<v8::Number> numberObject = value->ToNumber(isolate); 376 v8::Local<v8::Number> numberObject = value->ToNumber(isolate);
381 if (block.HasCaught()) { 377 if (block.HasCaught()) {
382 exceptionState.rethrowV8Exception(block.Exception()); 378 exceptionState.rethrowV8Exception(block.Exception());
383 return 0; 379 return 0;
384 } 380 }
385 ASSERT(!numberObject.IsEmpty()); 381 ASSERT(!numberObject.IsEmpty());
386 382
387 if (configuration == EnforceRange) 383 if (configuration == EnforceRange)
388 return enforceRange(numberObject->Value(), 0, kMaxUInt32, "unsigned long ", exceptionState); 384 return enforceRange(numberObject->Value(), 0, kMaxUInt32, "unsigned long ", exceptionState);
389 385
390 double numberValue = numberObject->Value(); 386 double numberValue = numberObject->Value();
391 387
392 if (std::isnan(numberValue)) 388 if (std::isnan(numberValue))
393 return 0; 389 return 0;
394 390
395 if (configuration == Clamp) 391 if (configuration == Clamp)
396 return clampTo<uint32_t>(numberValue); 392 return clampTo<uint32_t>(numberValue);
397 393
398 if (std::isinf(numberValue)) 394 if (std::isinf(numberValue))
399 return 0; 395 return 0;
400 396
401 return numberObject->Uint32Value(); 397 return numberObject->Uint32Value();
402 } 398 }
403 399
404 uint32_t toUInt32(v8::Handle<v8::Value> value) 400 uint32_t toUInt32(v8::Isolate* isolate, v8::Handle<v8::Value> value)
405 { 401 {
406 NonThrowableExceptionState exceptionState; 402 NonThrowableExceptionState exceptionState;
407 return toUInt32(value, NormalConversion, exceptionState); 403 return toUInt32(isolate, value, NormalConversion, exceptionState);
408 } 404 }
409 405
410 int64_t toInt64Slow(v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, ExceptionState& exceptionState) 406 int64_t toInt64Slow(v8::Isolate* isolate, v8::Handle<v8::Value> value, IntegerCo nversionConfiguration configuration, ExceptionState& exceptionState)
411 { 407 {
412 ASSERT(!value->IsInt32()); 408 ASSERT(!value->IsInt32());
413 409
414 v8::Local<v8::Number> numberObject; 410 v8::Local<v8::Number> numberObject;
415 v8::Isolate* isolate = v8::Isolate::GetCurrent();
416 // Can the value be converted to a number? 411 // Can the value be converted to a number?
417 v8::TryCatch block(isolate); 412 v8::TryCatch block(isolate);
418 numberObject = value->ToNumber(isolate); 413 numberObject = value->ToNumber(isolate);
419 if (block.HasCaught()) { 414 if (block.HasCaught()) {
420 exceptionState.rethrowV8Exception(block.Exception()); 415 exceptionState.rethrowV8Exception(block.Exception());
421 return 0; 416 return 0;
422 } 417 }
423 ASSERT(!numberObject.IsEmpty()); 418 ASSERT(!numberObject.IsEmpty());
424 419
425 double numberValue = numberObject->Value(); 420 double numberValue = numberObject->Value();
426 421
427 if (configuration == EnforceRange) 422 if (configuration == EnforceRange)
428 return enforceRange(numberValue, -kJSMaxInteger, kJSMaxInteger, "long lo ng", exceptionState); 423 return enforceRange(numberValue, -kJSMaxInteger, kJSMaxInteger, "long lo ng", exceptionState);
429 424
430 if (std::isnan(numberValue) || std::isinf(numberValue)) 425 if (std::isnan(numberValue) || std::isinf(numberValue))
431 return 0; 426 return 0;
432 427
433 // NaNs and +/-Infinity should be 0, otherwise modulo 2^64. 428 // NaNs and +/-Infinity should be 0, otherwise modulo 2^64.
434 unsigned long long integer; 429 unsigned long long integer;
435 doubleToInteger(numberValue, integer); 430 doubleToInteger(numberValue, integer);
436 return integer; 431 return integer;
437 } 432 }
438 433
439 int64_t toInt64(v8::Handle<v8::Value> value) 434 int64_t toInt64(v8::Isolate* isolate, v8::Handle<v8::Value> value)
440 { 435 {
441 NonThrowableExceptionState exceptionState; 436 NonThrowableExceptionState exceptionState;
442 return toInt64(value, NormalConversion, exceptionState); 437 return toInt64(isolate, value, NormalConversion, exceptionState);
443 } 438 }
444 439
445 uint64_t toUInt64Slow(v8::Handle<v8::Value> value, IntegerConversionConfiguratio n configuration, ExceptionState& exceptionState) 440 uint64_t toUInt64Slow(v8::Isolate* isolate, v8::Handle<v8::Value> value, Integer ConversionConfiguration configuration, ExceptionState& exceptionState)
446 { 441 {
447 ASSERT(!value->IsUint32()); 442 ASSERT(!value->IsUint32());
448 if (value->IsInt32()) { 443 if (value->IsInt32()) {
449 ASSERT(configuration != NormalConversion); 444 ASSERT(configuration != NormalConversion);
450 int32_t result = value->Int32Value(); 445 int32_t result = value->Int32Value();
451 if (result >= 0) 446 if (result >= 0)
452 return result; 447 return result;
453 if (configuration == EnforceRange) { 448 if (configuration == EnforceRange) {
454 exceptionState.throwTypeError("Value is outside the 'unsigned long l ong' value range."); 449 exceptionState.throwTypeError("Value is outside the 'unsigned long l ong' value range.");
455 return 0; 450 return 0;
456 } 451 }
457 ASSERT(configuration == Clamp); 452 ASSERT(configuration == Clamp);
458 return clampTo<uint64_t>(result); 453 return clampTo<uint64_t>(result);
459 } 454 }
460 455
461 v8::Local<v8::Number> numberObject; 456 v8::Local<v8::Number> numberObject;
462 v8::Isolate* isolate = v8::Isolate::GetCurrent();
463 // Can the value be converted to a number? 457 // Can the value be converted to a number?
464 v8::TryCatch block(isolate); 458 v8::TryCatch block(isolate);
465 numberObject = value->ToNumber(isolate); 459 numberObject = value->ToNumber(isolate);
466 if (block.HasCaught()) { 460 if (block.HasCaught()) {
467 exceptionState.rethrowV8Exception(block.Exception()); 461 exceptionState.rethrowV8Exception(block.Exception());
468 return 0; 462 return 0;
469 } 463 }
470 ASSERT(!numberObject.IsEmpty()); 464 ASSERT(!numberObject.IsEmpty());
471 465
472 double numberValue = numberObject->Value(); 466 double numberValue = numberObject->Value();
473 467
474 if (configuration == EnforceRange) 468 if (configuration == EnforceRange)
475 return enforceRange(numberValue, 0, kJSMaxInteger, "unsigned long long", exceptionState); 469 return enforceRange(numberValue, 0, kJSMaxInteger, "unsigned long long", exceptionState);
476 470
477 if (std::isnan(numberValue)) 471 if (std::isnan(numberValue))
478 return 0; 472 return 0;
479 473
480 if (configuration == Clamp) 474 if (configuration == Clamp)
481 return clampTo<uint64_t>(numberValue); 475 return clampTo<uint64_t>(numberValue);
482 476
483 if (std::isinf(numberValue)) 477 if (std::isinf(numberValue))
484 return 0; 478 return 0;
485 479
486 // NaNs and +/-Infinity should be 0, otherwise modulo 2^64. 480 // NaNs and +/-Infinity should be 0, otherwise modulo 2^64.
487 unsigned long long integer; 481 unsigned long long integer;
488 doubleToInteger(numberValue, integer); 482 doubleToInteger(numberValue, integer);
489 return integer; 483 return integer;
490 } 484 }
491 485
492 uint64_t toUInt64(v8::Handle<v8::Value> value) 486 uint64_t toUInt64(v8::Isolate* isolate, v8::Handle<v8::Value> value)
493 { 487 {
494 NonThrowableExceptionState exceptionState; 488 NonThrowableExceptionState exceptionState;
495 return toUInt64(value, NormalConversion, exceptionState); 489 return toUInt64(isolate, value, NormalConversion, exceptionState);
496 } 490 }
497 491
498 float toRestrictedFloat(v8::Handle<v8::Value> value, ExceptionState& exceptionSt ate) 492 float toRestrictedFloat(v8::Isolate* isolate, v8::Handle<v8::Value> value, Excep tionState& exceptionState)
499 { 493 {
500 float numberValue = toFloat(value, exceptionState); 494 float numberValue = toFloat(isolate, value, exceptionState);
501 if (exceptionState.hadException()) 495 if (exceptionState.hadException())
502 return 0; 496 return 0;
503 if (!std::isfinite(numberValue)) { 497 if (!std::isfinite(numberValue)) {
504 exceptionState.throwTypeError("The provided float value is non-finite.") ; 498 exceptionState.throwTypeError("The provided float value is non-finite.") ;
505 return 0; 499 return 0;
506 } 500 }
507 return numberValue; 501 return numberValue;
508 } 502 }
509 503
510 double toDoubleSlow(v8::Handle<v8::Value> value, ExceptionState& exceptionState) 504 double toDoubleSlow(v8::Isolate* isolate, v8::Handle<v8::Value> value, Exception State& exceptionState)
511 { 505 {
512 ASSERT(!value->IsNumber()); 506 ASSERT(!value->IsNumber());
513 v8::Isolate* isolate = v8::Isolate::GetCurrent();
514 v8::TryCatch block(isolate); 507 v8::TryCatch block(isolate);
515 double doubleValue = value->NumberValue(); 508 double doubleValue = value->NumberValue();
516 if (block.HasCaught()) { 509 if (block.HasCaught()) {
517 exceptionState.rethrowV8Exception(block.Exception()); 510 exceptionState.rethrowV8Exception(block.Exception());
518 return 0; 511 return 0;
519 } 512 }
520 return doubleValue; 513 return doubleValue;
521 } 514 }
522 515
523 double toRestrictedDouble(v8::Handle<v8::Value> value, ExceptionState& exception State) 516 double toRestrictedDouble(v8::Isolate* isolate, v8::Handle<v8::Value> value, Exc eptionState& exceptionState)
524 { 517 {
525 double numberValue = toDouble(value, exceptionState); 518 double numberValue = toDouble(isolate, value, exceptionState);
526 if (exceptionState.hadException()) 519 if (exceptionState.hadException())
527 return 0; 520 return 0;
528 if (!std::isfinite(numberValue)) { 521 if (!std::isfinite(numberValue)) {
529 exceptionState.throwTypeError("The provided double value is non-finite." ); 522 exceptionState.throwTypeError("The provided double value is non-finite." );
530 return 0; 523 return 0;
531 } 524 }
532 return numberValue; 525 return numberValue;
533 } 526 }
534 527
535 String toByteString(v8::Handle<v8::Value> value, ExceptionState& exceptionState) 528 String toByteString(v8::Isolate* isolate, v8::Handle<v8::Value> value, Exception State& exceptionState)
536 { 529 {
537 // Handle null default value. 530 // Handle null default value.
538 if (value.IsEmpty()) 531 if (value.IsEmpty())
539 return String(); 532 return String();
540 533
541 // From the Web IDL spec: http://heycam.github.io/webidl/#es-ByteString 534 // From the Web IDL spec: http://heycam.github.io/webidl/#es-ByteString
542 if (value.IsEmpty()) 535 if (value.IsEmpty())
543 return String(); 536 return String();
544 537
545 // 1. Let x be ToString(v) 538 // 1. Let x be ToString(v)
546 v8::Local<v8::String> stringObject; 539 v8::Local<v8::String> stringObject;
547 if (value->IsString()) { 540 if (value->IsString()) {
548 stringObject = value.As<v8::String>(); 541 stringObject = value.As<v8::String>();
549 } else { 542 } else {
550 v8::Isolate* isolate = v8::Isolate::GetCurrent();
551 v8::TryCatch block(isolate); 543 v8::TryCatch block(isolate);
552 stringObject = value->ToString(isolate); 544 stringObject = value->ToString(isolate);
553 if (block.HasCaught()) { 545 if (block.HasCaught()) {
554 exceptionState.rethrowV8Exception(block.Exception()); 546 exceptionState.rethrowV8Exception(block.Exception());
555 return String(); 547 return String();
556 } 548 }
557 } 549 }
558 550
559 String x = toCoreString(stringObject); 551 String x = toCoreString(stringObject);
560 552
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 } 658 }
667 // 3. Set i to i+1. 659 // 3. Set i to i+1.
668 ++i; 660 ++i;
669 } 661 }
670 662
671 // 6. Return U. 663 // 6. Return U.
672 ASSERT(u.length() == string.length()); 664 ASSERT(u.length() == string.length());
673 return u.toString(); 665 return u.toString();
674 } 666 }
675 667
676 String toUSVString(v8::Handle<v8::Value> value, ExceptionState& exceptionState) 668 String toUSVString(v8::Isolate* isolate, v8::Handle<v8::Value> value, ExceptionS tate& exceptionState)
677 { 669 {
678 // http://heycam.github.io/webidl/#es-USVString 670 // http://heycam.github.io/webidl/#es-USVString
679 if (value.IsEmpty()) 671 if (value.IsEmpty())
680 return String(); 672 return String();
681 673
682 v8::Local<v8::String> stringObject; 674 v8::Local<v8::String> stringObject;
683 if (value->IsString()) { 675 if (value->IsString()) {
684 stringObject = value.As<v8::String>(); 676 stringObject = value.As<v8::String>();
685 } else { 677 } else {
686 v8::Isolate* isolate = v8::Isolate::GetCurrent();
687 v8::TryCatch block(isolate); 678 v8::TryCatch block(isolate);
688 stringObject = value->ToString(isolate); 679 stringObject = value->ToString(isolate);
689 if (block.HasCaught()) { 680 if (block.HasCaught()) {
690 exceptionState.rethrowV8Exception(block.Exception()); 681 exceptionState.rethrowV8Exception(block.Exception());
691 return String(); 682 return String();
692 } 683 }
693 } 684 }
694 685
695 // USVString is identical to DOMString except that "convert a 686 // USVString is identical to DOMString except that "convert a
696 // DOMString to a sequence of Unicode characters" is used subsequently 687 // DOMString to a sequence of Unicode characters" is used subsequently
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
1034 { 1025 {
1035 v8ConstructorAttributeGetter(info); 1026 v8ConstructorAttributeGetter(info);
1036 } 1027 }
1037 1028
1038 void v8ConstructorAttributeGetterAsAccessor(const v8::FunctionCallbackInfo<v8::V alue>& info) 1029 void v8ConstructorAttributeGetterAsAccessor(const v8::FunctionCallbackInfo<v8::V alue>& info)
1039 { 1030 {
1040 v8ConstructorAttributeGetter(info); 1031 v8ConstructorAttributeGetter(info);
1041 } 1032 }
1042 1033
1043 } // namespace blink 1034 } // namespace blink
OLDNEW
« no previous file with comments | « Source/bindings/core/v8/V8Binding.h ('k') | Source/bindings/core/v8/V8BindingTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698