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

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

Issue 121113004: Improve handling of failed integer type conversions. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase Created 6 years, 11 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/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 19 matching lines...) Expand all
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "bindings/v8/V8Binding.h" 32 #include "bindings/v8/V8Binding.h"
33 33
34 #include "V8Element.h" 34 #include "V8Element.h"
35 #include "V8NodeFilter.h" 35 #include "V8NodeFilter.h"
36 #include "V8Window.h" 36 #include "V8Window.h"
37 #include "V8WorkerGlobalScope.h" 37 #include "V8WorkerGlobalScope.h"
38 #include "V8XPathNSResolver.h" 38 #include "V8XPathNSResolver.h"
39 #include "bindings/v8/ScriptController.h" 39 #include "bindings/v8/ScriptController.h"
40 #include "bindings/v8/V8BindingMacros.h"
40 #include "bindings/v8/V8NodeFilterCondition.h" 41 #include "bindings/v8/V8NodeFilterCondition.h"
41 #include "bindings/v8/V8ObjectConstructor.h" 42 #include "bindings/v8/V8ObjectConstructor.h"
42 #include "bindings/v8/V8WindowShell.h" 43 #include "bindings/v8/V8WindowShell.h"
43 #include "bindings/v8/WorkerScriptController.h" 44 #include "bindings/v8/WorkerScriptController.h"
44 #include "bindings/v8/custom/V8CustomXPathNSResolver.h" 45 #include "bindings/v8/custom/V8CustomXPathNSResolver.h"
45 #include "core/dom/Element.h" 46 #include "core/dom/Element.h"
46 #include "core/dom/NodeFilter.h" 47 #include "core/dom/NodeFilter.h"
47 #include "core/dom/QualifiedName.h" 48 #include "core/dom/QualifiedName.h"
48 #include "core/inspector/BindingVisitors.h" 49 #include "core/inspector/BindingVisitors.h"
49 #include "core/loader/FrameLoader.h" 50 #include "core/loader/FrameLoader.h"
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 if (windowWrapper.IsEmpty()) 148 if (windowWrapper.IsEmpty())
148 return 0; 149 return 0;
149 return V8Window::toNative(windowWrapper); 150 return V8Window::toNative(windowWrapper);
150 } 151 }
151 152
152 const int32_t kMaxInt32 = 0x7fffffff; 153 const int32_t kMaxInt32 = 0x7fffffff;
153 const int32_t kMinInt32 = -kMaxInt32 - 1; 154 const int32_t kMinInt32 = -kMaxInt32 - 1;
154 const uint32_t kMaxUInt32 = 0xffffffff; 155 const uint32_t kMaxUInt32 = 0xffffffff;
155 const int64_t kJSMaxInteger = 0x20000000000000LL - 1; // 2^53 - 1, maximum integ er exactly representable in ECMAScript. 156 const int64_t kJSMaxInteger = 0x20000000000000LL - 1; // 2^53 - 1, maximum integ er exactly representable in ECMAScript.
156 157
157 static double enforceRange(double x, double minimum, double maximum, bool& ok) 158 static double enforceRange(double x, double minimum, double maximum, const char* typeName, ExceptionState& exceptionState)
158 { 159 {
159 if (std::isnan(x) || std::isinf(x)) { 160 if (std::isnan(x) || std::isinf(x)) {
160 ok = false; 161 exceptionState.throwTypeError("Value is" + String(std::isinf(x) ? " infi nite and" : "") + " not of type '" + String(typeName) + "'.");
161 return 0; 162 return 0;
162 } 163 }
163 x = trunc(x); 164 x = trunc(x);
164 if (x < minimum || x > maximum) { 165 if (x < minimum || x > maximum) {
165 ok = false; 166 exceptionState.throwTypeError("Value is outside the '" + String(typeName ) + "' value range.");
166 return 0; 167 return 0;
167 } 168 }
168 return x; 169 return x;
169 } 170 }
170 171
171 template <typename T> 172 template <typename T>
172 struct IntTypeLimits { 173 struct IntTypeLimits {
173 }; 174 };
174 175
175 template <> 176 template <>
(...skipping 16 matching lines...) Expand all
192 static const unsigned numberOfValues = 65536; // 2^16 193 static const unsigned numberOfValues = 65536; // 2^16
193 }; 194 };
194 195
195 template <> 196 template <>
196 struct IntTypeLimits<uint16_t> { 197 struct IntTypeLimits<uint16_t> {
197 static const unsigned short maxValue = 65535; 198 static const unsigned short maxValue = 65535;
198 static const unsigned numberOfValues = 65536; // 2^16 199 static const unsigned numberOfValues = 65536; // 2^16
199 }; 200 };
200 201
201 template <typename T> 202 template <typename T>
202 static inline T toSmallerInt(v8::Handle<v8::Value> value, IntegerConversionConfi guration configuration, bool& ok) 203 static inline T toSmallerInt(v8::Handle<v8::Value> value, IntegerConversionConfi guration configuration, const char* typeName, ExceptionState& exceptionState)
203 { 204 {
204 typedef IntTypeLimits<T> LimitsTrait; 205 typedef IntTypeLimits<T> LimitsTrait;
205 ok = true;
206 206
207 // Fast case. The value is already a 32-bit integer in the right range. 207 // Fast case. The value is already a 32-bit integer in the right range.
208 if (value->IsInt32()) { 208 if (value->IsInt32()) {
209 int32_t result = value->Int32Value(); 209 int32_t result = value->Int32Value();
210 if (result >= LimitsTrait::minValue && result <= LimitsTrait::maxValue) 210 if (result >= LimitsTrait::minValue && result <= LimitsTrait::maxValue)
211 return static_cast<T>(result); 211 return static_cast<T>(result);
212 if (configuration == EnforceRange) { 212 if (configuration == EnforceRange) {
213 ok = false; 213 exceptionState.throwTypeError("Value is outside the '" + String(type Name) + "' value range.");
214 return 0; 214 return 0;
215 } 215 }
216 result %= LimitsTrait::numberOfValues; 216 result %= LimitsTrait::numberOfValues;
217 return static_cast<T>(result > LimitsTrait::maxValue ? result - LimitsTr ait::numberOfValues : result); 217 return static_cast<T>(result > LimitsTrait::maxValue ? result - LimitsTr ait::numberOfValues : result);
218 } 218 }
219 219
220 // Can the value be converted to a number? 220 // Can the value be converted to a number?
221 v8::Local<v8::Number> numberObject = value->ToNumber(); 221 V8TRYCATCH_EXCEPTION_RETURN(v8::Local<v8::Number>, numberObject, value->ToNu mber(), exceptionState, 0);
222 if (numberObject.IsEmpty()) { 222 if (numberObject.IsEmpty()) {
223 ok = false; 223 exceptionState.throwTypeError("Not convertible to a number value (of typ e '" + String(typeName) + "'.");
224 return 0; 224 return 0;
225 } 225 }
226 226
227 if (configuration == EnforceRange) 227 if (configuration == EnforceRange)
228 return enforceRange(numberObject->Value(), LimitsTrait::minValue, Limits Trait::maxValue, ok); 228 return enforceRange(numberObject->Value(), LimitsTrait::minValue, Limits Trait::maxValue, typeName, exceptionState);
229 229
230 double numberValue = numberObject->Value(); 230 double numberValue = numberObject->Value();
231 if (std::isnan(numberValue) || std::isinf(numberValue) || !numberValue) 231 if (std::isnan(numberValue) || std::isinf(numberValue) || !numberValue)
232 return 0; 232 return 0;
233 233
234 numberValue = numberValue < 0 ? -floor(fabs(numberValue)) : floor(fabs(numbe rValue)); 234 numberValue = numberValue < 0 ? -floor(fabs(numberValue)) : floor(fabs(numbe rValue));
235 numberValue = fmod(numberValue, LimitsTrait::numberOfValues); 235 numberValue = fmod(numberValue, LimitsTrait::numberOfValues);
236 236
237 return static_cast<T>(numberValue > LimitsTrait::maxValue ? numberValue - Li mitsTrait::numberOfValues : numberValue); 237 return static_cast<T>(numberValue > LimitsTrait::maxValue ? numberValue - Li mitsTrait::numberOfValues : numberValue);
238 } 238 }
239 239
240 template <typename T> 240 template <typename T>
241 static inline T toSmallerUInt(v8::Handle<v8::Value> value, IntegerConversionConf iguration configuration, bool& ok) 241 static inline T toSmallerUInt(v8::Handle<v8::Value> value, IntegerConversionConf iguration configuration, const char* typeName, ExceptionState& exceptionState)
242 { 242 {
243 typedef IntTypeLimits<T> LimitsTrait; 243 typedef IntTypeLimits<T> LimitsTrait;
244 ok = true;
245 244
246 // Fast case. The value is a 32-bit signed integer - possibly positive? 245 // Fast case. The value is a 32-bit signed integer - possibly positive?
247 if (value->IsInt32()) { 246 if (value->IsInt32()) {
248 int32_t result = value->Int32Value(); 247 int32_t result = value->Int32Value();
249 if (result >= 0 && result <= LimitsTrait::maxValue) 248 if (result >= 0 && result <= LimitsTrait::maxValue)
250 return static_cast<T>(result); 249 return static_cast<T>(result);
251 if (configuration == EnforceRange) { 250 if (configuration == EnforceRange) {
252 ok = false; 251 exceptionState.throwTypeError("Value is outside the '" + String(type Name) + "' value range.");
253 return 0; 252 return 0;
254 } 253 }
255 return static_cast<T>(result); 254 return static_cast<T>(result);
256 } 255 }
257 256
258 // Can the value be converted to a number? 257 // Can the value be converted to a number?
259 v8::Local<v8::Number> numberObject = value->ToNumber(); 258 V8TRYCATCH_EXCEPTION_RETURN(v8::Local<v8::Number>, numberObject, value->ToNu mber(), exceptionState, 0);
260 if (numberObject.IsEmpty()) { 259 if (numberObject.IsEmpty()) {
261 ok = false; 260 exceptionState.throwTypeError("Not convertible to a number value (of typ e '" + String(typeName) + "'.");
262 return 0; 261 return 0;
263 } 262 }
264 263
265 if (configuration == EnforceRange) 264 if (configuration == EnforceRange)
266 return enforceRange(numberObject->Value(), 0, LimitsTrait::maxValue, ok) ; 265 return enforceRange(numberObject->Value(), 0, LimitsTrait::maxValue, typ eName, exceptionState);
267 266
268 // Does the value convert to nan or to an infinity? 267 // Does the value convert to nan or to an infinity?
269 double numberValue = numberObject->Value(); 268 double numberValue = numberObject->Value();
270 if (std::isnan(numberValue) || std::isinf(numberValue) || !numberValue) 269 if (std::isnan(numberValue) || std::isinf(numberValue) || !numberValue)
271 return 0; 270 return 0;
272 271
273 if (configuration == Clamp) 272 if (configuration == Clamp)
274 return clampTo<T>(numberObject->Value()); 273 return clampTo<T>(numberObject->Value());
275 274
276 numberValue = numberValue < 0 ? -floor(fabs(numberValue)) : floor(fabs(numbe rValue)); 275 numberValue = numberValue < 0 ? -floor(fabs(numberValue)) : floor(fabs(numbe rValue));
277 return static_cast<T>(fmod(numberValue, LimitsTrait::numberOfValues)); 276 return static_cast<T>(fmod(numberValue, LimitsTrait::numberOfValues));
278 } 277 }
279 278
280 int8_t toInt8(v8::Handle<v8::Value> value, IntegerConversionConfiguration config uration, bool& ok) 279 int8_t toInt8(v8::Handle<v8::Value> value, IntegerConversionConfiguration config uration, ExceptionState& exceptionState)
281 { 280 {
282 return toSmallerInt<int8_t>(value, configuration, ok); 281 return toSmallerInt<int8_t>(value, configuration, "byte", exceptionState);
283 } 282 }
284 283
285 uint8_t toUInt8(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf iguration, bool& ok) 284 int8_t toInt8(v8::Handle<v8::Value> value)
286 { 285 {
287 return toSmallerUInt<uint8_t>(value, configuration, ok); 286 NonThrowableExceptionState exceptionState;
287 return toInt8(value, NormalConversion, exceptionState);
288 } 288 }
289 289
290 int16_t toInt16(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf iguration, bool& ok) 290 uint8_t toUInt8(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf iguration, ExceptionState& exceptionState)
291 { 291 {
292 return toSmallerInt<int16_t>(value, configuration, ok); 292 return toSmallerUInt<uint8_t>(value, configuration, "octet", exceptionState) ;
293 } 293 }
294 294
295 uint16_t toUInt16(v8::Handle<v8::Value> value, IntegerConversionConfiguration co nfiguration, bool& ok) 295 uint8_t toUInt8(v8::Handle<v8::Value> value)
296 { 296 {
297 return toSmallerUInt<uint16_t>(value, configuration, ok); 297 NonThrowableExceptionState exceptionState;
298 return toUInt8(value, NormalConversion, exceptionState);
298 } 299 }
299 300
300 int32_t toInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf iguration, bool& ok) 301 int16_t toInt16(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf iguration, ExceptionState& exceptionState)
301 { 302 {
302 ok = true; 303 return toSmallerInt<int16_t>(value, configuration, "short", exceptionState);
304 }
303 305
306 int16_t toInt16(v8::Handle<v8::Value> value)
307 {
308 NonThrowableExceptionState exceptionState;
309 return toInt16(value, NormalConversion, exceptionState);
310 }
311
312 uint16_t toUInt16(v8::Handle<v8::Value> value, IntegerConversionConfiguration co nfiguration, ExceptionState& exceptionState)
313 {
314 return toSmallerUInt<uint16_t>(value, configuration, "unsigned short", excep tionState);
315 }
316
317 uint16_t toUInt16(v8::Handle<v8::Value> value)
318 {
319 NonThrowableExceptionState exceptionState;
320 return toUInt16(value, NormalConversion, exceptionState);
321 }
322
323 int32_t toInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf iguration, ExceptionState& exceptionState)
324 {
304 // Fast case. The value is already a 32-bit integer. 325 // Fast case. The value is already a 32-bit integer.
305 if (value->IsInt32()) 326 if (value->IsInt32())
306 return value->Int32Value(); 327 return value->Int32Value();
307 328
308 // Can the value be converted to a number? 329 // Can the value be converted to a number?
309 ok = false; 330 V8TRYCATCH_EXCEPTION_RETURN(v8::Local<v8::Number>, numberObject, value->ToNu mber(), exceptionState, 0);
310 V8TRYCATCH_RETURN(v8::Local<v8::Number>, numberObject, value->ToNumber(), 0) ;
311 if (numberObject.IsEmpty()) { 331 if (numberObject.IsEmpty()) {
332 exceptionState.throwTypeError("Not convertible to a number value (of typ e 'long'.)");
312 return 0; 333 return 0;
313 } 334 }
314 ok = true;
315 335
316 if (configuration == EnforceRange) 336 if (configuration == EnforceRange)
317 return enforceRange(numberObject->Value(), kMinInt32, kMaxInt32, ok); 337 return enforceRange(numberObject->Value(), kMinInt32, kMaxInt32, "long", exceptionState);
318 338
319 // Does the value convert to nan or to an infinity? 339 // Does the value convert to nan or to an infinity?
320 double numberValue = numberObject->Value(); 340 double numberValue = numberObject->Value();
321 if (std::isnan(numberValue) || std::isinf(numberValue)) 341 if (std::isnan(numberValue) || std::isinf(numberValue))
322 return 0; 342 return 0;
323 343
324 if (configuration == Clamp) 344 if (configuration == Clamp)
325 return clampTo<int32_t>(numberObject->Value()); 345 return clampTo<int32_t>(numberObject->Value());
326 346
327 V8TRYCATCH_RETURN(int32_t, result, numberObject->Int32Value(), 0); 347 V8TRYCATCH_EXCEPTION_RETURN(int32_t, result, numberObject->Int32Value(), exc eptionState, 0);
328 return result; 348 return result;
329 } 349 }
330 350
331 uint32_t toUInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration co nfiguration, bool& ok) 351 int32_t toInt32(v8::Handle<v8::Value> value)
332 { 352 {
333 ok = true; 353 NonThrowableExceptionState exceptionState;
354 return toInt32(value, NormalConversion, exceptionState);
355 }
334 356
357 uint32_t toUInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration co nfiguration, ExceptionState& exceptionState)
358 {
335 // Fast case. The value is already a 32-bit unsigned integer. 359 // Fast case. The value is already a 32-bit unsigned integer.
336 if (value->IsUint32()) 360 if (value->IsUint32())
337 return value->Uint32Value(); 361 return value->Uint32Value();
338 362
339 // Fast case. The value is a 32-bit signed integer - possibly positive? 363 // Fast case. The value is a 32-bit signed integer - possibly positive?
340 if (value->IsInt32()) { 364 if (value->IsInt32()) {
341 int32_t result = value->Int32Value(); 365 int32_t result = value->Int32Value();
342 if (result >= 0) 366 if (result >= 0)
343 return result; 367 return result;
344 if (configuration == EnforceRange) { 368 if (configuration == EnforceRange) {
345 ok = false; 369 exceptionState.throwTypeError("Value is outside the 'unsigned long' value range.");
346 return 0; 370 return 0;
347 } 371 }
348 return result; 372 return result;
349 } 373 }
350 374
351 // Can the value be converted to a number? 375 // Can the value be converted to a number?
352 ok = false; 376 V8TRYCATCH_EXCEPTION_RETURN(v8::Local<v8::Number>, numberObject, value->ToNu mber(), exceptionState, 0);
353 V8TRYCATCH_RETURN(v8::Local<v8::Number>, numberObject, value->ToNumber(), 0) ;
354 if (numberObject.IsEmpty()) { 377 if (numberObject.IsEmpty()) {
378 exceptionState.throwTypeError("Not convertible to a number value (of typ e 'unsigned long'.)");
355 return 0; 379 return 0;
356 } 380 }
357 ok = true;
358 381
359 if (configuration == EnforceRange) 382 if (configuration == EnforceRange)
360 return enforceRange(numberObject->Value(), 0, kMaxUInt32, ok); 383 return enforceRange(numberObject->Value(), 0, kMaxUInt32, "unsigned long ", exceptionState);
361 384
362 // Does the value convert to nan or to an infinity? 385 // Does the value convert to nan or to an infinity?
363 double numberValue = numberObject->Value(); 386 double numberValue = numberObject->Value();
364 if (std::isnan(numberValue) || std::isinf(numberValue)) 387 if (std::isnan(numberValue) || std::isinf(numberValue))
365 return 0; 388 return 0;
366 389
367 if (configuration == Clamp) 390 if (configuration == Clamp)
368 return clampTo<uint32_t>(numberObject->Value()); 391 return clampTo<uint32_t>(numberObject->Value());
369 392
370 V8TRYCATCH_RETURN(uint32_t, result, numberObject->Uint32Value(), 0); 393 V8TRYCATCH_RETURN(uint32_t, result, numberObject->Uint32Value(), 0);
371 return result; 394 return result;
372 } 395 }
373 396
374 int64_t toInt64(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf iguration, bool& ok) 397 uint32_t toUInt32(v8::Handle<v8::Value> value)
375 { 398 {
376 ok = true; 399 NonThrowableExceptionState exceptionState;
400 return toUInt32(value, NormalConversion, exceptionState);
401 }
377 402
403 int64_t toInt64(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf iguration, ExceptionState& exceptionState)
404 {
378 // Fast case. The value is a 32-bit integer. 405 // Fast case. The value is a 32-bit integer.
379 if (value->IsInt32()) 406 if (value->IsInt32())
380 return value->Int32Value(); 407 return value->Int32Value();
381 408
382 // Can the value be converted to a number? 409 // Can the value be converted to a number?
383 v8::Local<v8::Number> numberObject = value->ToNumber(); 410 V8TRYCATCH_EXCEPTION_RETURN(v8::Local<v8::Number>, numberObject, value->ToNu mber(), exceptionState, 0);
384 if (numberObject.IsEmpty()) { 411 if (numberObject.IsEmpty()) {
385 ok = false; 412 exceptionState.throwTypeError("Not convertible to a number value (of typ e 'long long'.)");
386 return 0; 413 return 0;
387 } 414 }
388 415
389 double x = numberObject->Value(); 416 double x = numberObject->Value();
390 417
391 if (configuration == EnforceRange) 418 if (configuration == EnforceRange)
392 return enforceRange(x, -kJSMaxInteger, kJSMaxInteger, ok); 419 return enforceRange(x, -kJSMaxInteger, kJSMaxInteger, "long long", excep tionState);
393 420
394 // Does the value convert to nan or to an infinity? 421 // Does the value convert to nan or to an infinity?
395 if (std::isnan(x) || std::isinf(x)) 422 if (std::isnan(x) || std::isinf(x))
396 return 0; 423 return 0;
397 424
398 // NaNs and +/-Infinity should be 0, otherwise modulo 2^64. 425 // NaNs and +/-Infinity should be 0, otherwise modulo 2^64.
399 unsigned long long integer; 426 unsigned long long integer;
400 doubleToInteger(x, integer); 427 doubleToInteger(x, integer);
401 return integer; 428 return integer;
402 } 429 }
403 430
404 uint64_t toUInt64(v8::Handle<v8::Value> value, IntegerConversionConfiguration co nfiguration, bool& ok) 431 int64_t toInt64(v8::Handle<v8::Value> value)
405 { 432 {
406 ok = true; 433 NonThrowableExceptionState exceptionState;
434 return toInt64(value, NormalConversion, exceptionState);
435 }
407 436
437 uint64_t toUInt64(v8::Handle<v8::Value> value, IntegerConversionConfiguration co nfiguration, ExceptionState& exceptionState)
438 {
408 // Fast case. The value is a 32-bit unsigned integer. 439 // Fast case. The value is a 32-bit unsigned integer.
409 if (value->IsUint32()) 440 if (value->IsUint32())
410 return value->Uint32Value(); 441 return value->Uint32Value();
411 442
412 // Fast case. The value is a 32-bit integer. 443 // Fast case. The value is a 32-bit integer.
413 if (value->IsInt32()) { 444 if (value->IsInt32()) {
414 int32_t result = value->Int32Value(); 445 int32_t result = value->Int32Value();
415 if (result >= 0) 446 if (result >= 0)
416 return result; 447 return result;
417 if (configuration == EnforceRange) { 448 if (configuration == EnforceRange) {
418 ok = false; 449 exceptionState.throwTypeError("Value is outside the 'unsigned long l ong' value range.");
419 return 0; 450 return 0;
420 } 451 }
421 return result; 452 return result;
422 } 453 }
423 454
424 // Can the value be converted to a number? 455 // Can the value be converted to a number?
425 v8::Local<v8::Number> numberObject = value->ToNumber(); 456 V8TRYCATCH_EXCEPTION_RETURN(v8::Local<v8::Number>, numberObject, value->ToNu mber(), exceptionState, 0);
426 if (numberObject.IsEmpty()) { 457 if (numberObject.IsEmpty()) {
427 ok = false; 458 exceptionState.throwTypeError("Not convertible to a number value (of typ e 'unsigned long long'.)");
428 return 0; 459 return 0;
429 } 460 }
430 461
431 double x = numberObject->Value(); 462 double x = numberObject->Value();
432 463
433 if (configuration == EnforceRange) 464 if (configuration == EnforceRange)
434 return enforceRange(x, 0, kJSMaxInteger, ok); 465 return enforceRange(x, 0, kJSMaxInteger, "unsigned long long", exception State);
435 466
436 // Does the value convert to nan or to an infinity? 467 // Does the value convert to nan or to an infinity?
437 if (std::isnan(x) || std::isinf(x)) 468 if (std::isnan(x) || std::isinf(x))
438 return 0; 469 return 0;
439 470
440 // NaNs and +/-Infinity should be 0, otherwise modulo 2^64. 471 // NaNs and +/-Infinity should be 0, otherwise modulo 2^64.
441 unsigned long long integer; 472 unsigned long long integer;
442 doubleToInteger(x, integer); 473 doubleToInteger(x, integer);
443 return integer; 474 return integer;
444 } 475 }
445 476
477 uint64_t toUInt64(v8::Handle<v8::Value> value)
478 {
479 NonThrowableExceptionState exceptionState;
480 return toUInt64(value, NormalConversion, exceptionState);
481 }
482
483 float toFloat(v8::Handle<v8::Value> value, ExceptionState& exceptionState)
484 {
485 V8TRYCATCH_EXCEPTION_RETURN(v8::Local<v8::Number>, numberObject, value->ToNu mber(), exceptionState, 0);
486 return numberObject->NumberValue();
487 }
488
446 PassRefPtr<XPathNSResolver> toXPathNSResolver(v8::Handle<v8::Value> value, v8::I solate* isolate) 489 PassRefPtr<XPathNSResolver> toXPathNSResolver(v8::Handle<v8::Value> value, v8::I solate* isolate)
447 { 490 {
448 RefPtr<XPathNSResolver> resolver; 491 RefPtr<XPathNSResolver> resolver;
449 if (V8XPathNSResolver::hasInstance(value, isolate, worldType(isolate))) 492 if (V8XPathNSResolver::hasInstance(value, isolate, worldType(isolate)))
450 resolver = V8XPathNSResolver::toNative(v8::Handle<v8::Object>::Cast(valu e)); 493 resolver = V8XPathNSResolver::toNative(v8::Handle<v8::Object>::Cast(valu e));
451 else if (value->IsObject()) 494 else if (value->IsObject())
452 resolver = V8CustomXPathNSResolver::create(value->ToObject(), isolate); 495 resolver = V8CustomXPathNSResolver::create(value->ToObject(), isolate);
453 return resolver; 496 return resolver;
454 } 497 }
455 498
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 return mainThreadIsolate(); 687 return mainThreadIsolate();
645 return v8::Isolate::GetCurrent(); 688 return v8::Isolate::GetCurrent();
646 } 689 }
647 690
648 v8::Isolate* toIsolate(Frame* frame) 691 v8::Isolate* toIsolate(Frame* frame)
649 { 692 {
650 return frame->script().isolate(); 693 return frame->script().isolate();
651 } 694 }
652 695
653 } // namespace WebCore 696 } // 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