| OLD | NEW |
| 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 Loading... |
| 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 filter->setCondition(condition.release()); | 136 filter->setCondition(condition.release()); |
| 136 | 137 |
| 137 return filter.release(); | 138 return filter.release(); |
| 138 } | 139 } |
| 139 | 140 |
| 140 const int32_t kMaxInt32 = 0x7fffffff; | 141 const int32_t kMaxInt32 = 0x7fffffff; |
| 141 const int32_t kMinInt32 = -kMaxInt32 - 1; | 142 const int32_t kMinInt32 = -kMaxInt32 - 1; |
| 142 const uint32_t kMaxUInt32 = 0xffffffff; | 143 const uint32_t kMaxUInt32 = 0xffffffff; |
| 143 const int64_t kJSMaxInteger = 0x20000000000000LL - 1; // 2^53 - 1, maximum integ
er exactly representable in ECMAScript. | 144 const int64_t kJSMaxInteger = 0x20000000000000LL - 1; // 2^53 - 1, maximum integ
er exactly representable in ECMAScript. |
| 144 | 145 |
| 145 static double enforceRange(double x, double minimum, double maximum, bool& ok) | 146 static double enforceRange(double x, double minimum, double maximum, const char*
typeName, ExceptionState& exceptionState) |
| 146 { | 147 { |
| 147 if (std::isnan(x) || std::isinf(x)) { | 148 if (std::isnan(x) || std::isinf(x)) { |
| 148 ok = false; | 149 exceptionState.throwTypeError("Value is" + String(std::isinf(x) ? " infi
nite and" : "") + " not of type '" + String(typeName) + "'."); |
| 149 return 0; | 150 return 0; |
| 150 } | 151 } |
| 151 x = trunc(x); | 152 x = trunc(x); |
| 152 if (x < minimum || x > maximum) { | 153 if (x < minimum || x > maximum) { |
| 153 ok = false; | 154 exceptionState.throwTypeError("Value is outside the '" + String(typeName
) + "' value range."); |
| 154 return 0; | 155 return 0; |
| 155 } | 156 } |
| 156 return x; | 157 return x; |
| 157 } | 158 } |
| 158 | 159 |
| 159 template <typename T> | 160 template <typename T> |
| 160 struct IntTypeLimits { | 161 struct IntTypeLimits { |
| 161 }; | 162 }; |
| 162 | 163 |
| 163 template <> | 164 template <> |
| (...skipping 16 matching lines...) Expand all Loading... |
| 180 static const unsigned numberOfValues = 65536; // 2^16 | 181 static const unsigned numberOfValues = 65536; // 2^16 |
| 181 }; | 182 }; |
| 182 | 183 |
| 183 template <> | 184 template <> |
| 184 struct IntTypeLimits<uint16_t> { | 185 struct IntTypeLimits<uint16_t> { |
| 185 static const unsigned short maxValue = 65535; | 186 static const unsigned short maxValue = 65535; |
| 186 static const unsigned numberOfValues = 65536; // 2^16 | 187 static const unsigned numberOfValues = 65536; // 2^16 |
| 187 }; | 188 }; |
| 188 | 189 |
| 189 template <typename T> | 190 template <typename T> |
| 190 static inline T toSmallerInt(v8::Handle<v8::Value> value, IntegerConversionConfi
guration configuration, bool& ok) | 191 static inline T toSmallerInt(v8::Handle<v8::Value> value, IntegerConversionConfi
guration configuration, const char* typeName, ExceptionState& exceptionState) |
| 191 { | 192 { |
| 192 typedef IntTypeLimits<T> LimitsTrait; | 193 typedef IntTypeLimits<T> LimitsTrait; |
| 193 ok = true; | |
| 194 | 194 |
| 195 // Fast case. The value is already a 32-bit integer in the right range. | 195 // Fast case. The value is already a 32-bit integer in the right range. |
| 196 if (value->IsInt32()) { | 196 if (value->IsInt32()) { |
| 197 int32_t result = value->Int32Value(); | 197 int32_t result = value->Int32Value(); |
| 198 if (result >= LimitsTrait::minValue && result <= LimitsTrait::maxValue) | 198 if (result >= LimitsTrait::minValue && result <= LimitsTrait::maxValue) |
| 199 return static_cast<T>(result); | 199 return static_cast<T>(result); |
| 200 if (configuration == EnforceRange) { | 200 if (configuration == EnforceRange) { |
| 201 ok = false; | 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 v8::Local<v8::Number> numberObject = value->ToNumber(); | 209 V8TRYCATCH_EXCEPTION_RETURN(v8::Local<v8::Number>, numberObject, value->ToNu
mber(), exceptionState, 0); |
| 210 if (numberObject.IsEmpty()) { | 210 if (numberObject.IsEmpty()) { |
| 211 ok = false; | 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, ok); | 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) |
| 220 return 0; | 220 return 0; |
| 221 | 221 |
| 222 numberValue = numberValue < 0 ? -floor(fabs(numberValue)) : floor(fabs(numbe
rValue)); | 222 numberValue = numberValue < 0 ? -floor(fabs(numberValue)) : floor(fabs(numbe
rValue)); |
| 223 numberValue = fmod(numberValue, LimitsTrait::numberOfValues); | 223 numberValue = fmod(numberValue, LimitsTrait::numberOfValues); |
| 224 | 224 |
| 225 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); |
| 226 } | 226 } |
| 227 | 227 |
| 228 template <typename T> | 228 template <typename T> |
| 229 static inline T toSmallerUInt(v8::Handle<v8::Value> value, IntegerConversionConf
iguration configuration, bool& ok) | 229 static inline T toSmallerUInt(v8::Handle<v8::Value> value, IntegerConversionConf
iguration configuration, const char* typeName, ExceptionState& exceptionState) |
| 230 { | 230 { |
| 231 typedef IntTypeLimits<T> LimitsTrait; | 231 typedef IntTypeLimits<T> LimitsTrait; |
| 232 ok = true; | |
| 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 ok = false; | 239 exceptionState.throwTypeError("Value is outside the '" + String(type
Name) + "' value range."); |
| 241 return 0; | 240 return 0; |
| 242 } | 241 } |
| 243 return static_cast<T>(result); | 242 return static_cast<T>(result); |
| 244 } | 243 } |
| 245 | 244 |
| 246 // Can the value be converted to a number? | 245 // Can the value be converted to a number? |
| 247 v8::Local<v8::Number> numberObject = value->ToNumber(); | 246 V8TRYCATCH_EXCEPTION_RETURN(v8::Local<v8::Number>, numberObject, value->ToNu
mber(), exceptionState, 0); |
| 248 if (numberObject.IsEmpty()) { | 247 if (numberObject.IsEmpty()) { |
| 249 ok = false; | 248 exceptionState.throwTypeError("Not convertible to a number value (of typ
e '" + String(typeName) + "'."); |
| 250 return 0; | 249 return 0; |
| 251 } | 250 } |
| 252 | 251 |
| 253 if (configuration == EnforceRange) | 252 if (configuration == EnforceRange) |
| 254 return enforceRange(numberObject->Value(), 0, LimitsTrait::maxValue, ok)
; | 253 return enforceRange(numberObject->Value(), 0, LimitsTrait::maxValue, typ
eName, exceptionState); |
| 255 | 254 |
| 256 // Does the value convert to nan or to an infinity? | 255 // Does the value convert to nan or to an infinity? |
| 257 double numberValue = numberObject->Value(); | 256 double numberValue = numberObject->Value(); |
| 258 if (std::isnan(numberValue) || std::isinf(numberValue) || !numberValue) | 257 if (std::isnan(numberValue) || std::isinf(numberValue) || !numberValue) |
| 259 return 0; | 258 return 0; |
| 260 | 259 |
| 261 if (configuration == Clamp) | 260 if (configuration == Clamp) |
| 262 return clampTo<T>(numberObject->Value()); | 261 return clampTo<T>(numberObject->Value()); |
| 263 | 262 |
| 264 numberValue = numberValue < 0 ? -floor(fabs(numberValue)) : floor(fabs(numbe
rValue)); | 263 numberValue = numberValue < 0 ? -floor(fabs(numberValue)) : floor(fabs(numbe
rValue)); |
| 265 return static_cast<T>(fmod(numberValue, LimitsTrait::numberOfValues)); | 264 return static_cast<T>(fmod(numberValue, LimitsTrait::numberOfValues)); |
| 266 } | 265 } |
| 267 | 266 |
| 268 int8_t toInt8(v8::Handle<v8::Value> value, IntegerConversionConfiguration config
uration, bool& ok) | 267 int8_t toInt8(v8::Handle<v8::Value> value, IntegerConversionConfiguration config
uration, ExceptionState& exceptionState) |
| 269 { | 268 { |
| 270 return toSmallerInt<int8_t>(value, configuration, ok); | 269 return toSmallerInt<int8_t>(value, configuration, "byte", exceptionState); |
| 271 } | 270 } |
| 272 | 271 |
| 273 uint8_t toUInt8(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf
iguration, bool& ok) | 272 int8_t toInt8(v8::Handle<v8::Value> value) |
| 274 { | 273 { |
| 275 return toSmallerUInt<uint8_t>(value, configuration, ok); | 274 NonThrowableExceptionState exceptionState; |
| 275 return toInt8(value, NormalConversion, exceptionState); |
| 276 } | 276 } |
| 277 | 277 |
| 278 int16_t toInt16(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf
iguration, bool& ok) | 278 uint8_t toUInt8(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf
iguration, ExceptionState& exceptionState) |
| 279 { | 279 { |
| 280 return toSmallerInt<int16_t>(value, configuration, ok); | 280 return toSmallerUInt<uint8_t>(value, configuration, "octet", exceptionState)
; |
| 281 } | 281 } |
| 282 | 282 |
| 283 uint16_t toUInt16(v8::Handle<v8::Value> value, IntegerConversionConfiguration co
nfiguration, bool& ok) | 283 uint8_t toUInt8(v8::Handle<v8::Value> value) |
| 284 { | 284 { |
| 285 return toSmallerUInt<uint16_t>(value, configuration, ok); | 285 NonThrowableExceptionState exceptionState; |
| 286 return toUInt8(value, NormalConversion, exceptionState); |
| 286 } | 287 } |
| 287 | 288 |
| 288 int32_t toInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf
iguration, bool& ok) | 289 int16_t toInt16(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf
iguration, ExceptionState& exceptionState) |
| 289 { | 290 { |
| 290 ok = true; | 291 return toSmallerInt<int16_t>(value, configuration, "short", exceptionState); |
| 292 } |
| 291 | 293 |
| 294 int16_t toInt16(v8::Handle<v8::Value> value) |
| 295 { |
| 296 NonThrowableExceptionState exceptionState; |
| 297 return toInt16(value, NormalConversion, exceptionState); |
| 298 } |
| 299 |
| 300 uint16_t toUInt16(v8::Handle<v8::Value> value, IntegerConversionConfiguration co
nfiguration, ExceptionState& exceptionState) |
| 301 { |
| 302 return toSmallerUInt<uint16_t>(value, configuration, "unsigned short", excep
tionState); |
| 303 } |
| 304 |
| 305 uint16_t toUInt16(v8::Handle<v8::Value> value) |
| 306 { |
| 307 NonThrowableExceptionState exceptionState; |
| 308 return toUInt16(value, NormalConversion, exceptionState); |
| 309 } |
| 310 |
| 311 int32_t toInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf
iguration, ExceptionState& exceptionState) |
| 312 { |
| 292 // Fast case. The value is already a 32-bit integer. | 313 // Fast case. The value is already a 32-bit integer. |
| 293 if (value->IsInt32()) | 314 if (value->IsInt32()) |
| 294 return value->Int32Value(); | 315 return value->Int32Value(); |
| 295 | 316 |
| 296 // Can the value be converted to a number? | 317 // Can the value be converted to a number? |
| 297 ok = false; | 318 V8TRYCATCH_EXCEPTION_RETURN(v8::Local<v8::Number>, numberObject, value->ToNu
mber(), exceptionState, 0); |
| 298 V8TRYCATCH_RETURN(v8::Local<v8::Number>, numberObject, value->ToNumber(), 0)
; | |
| 299 if (numberObject.IsEmpty()) { | 319 if (numberObject.IsEmpty()) { |
| 320 exceptionState.throwTypeError("Not convertible to a number value (of typ
e 'long'.)"); |
| 300 return 0; | 321 return 0; |
| 301 } | 322 } |
| 302 ok = true; | |
| 303 | 323 |
| 304 if (configuration == EnforceRange) | 324 if (configuration == EnforceRange) |
| 305 return enforceRange(numberObject->Value(), kMinInt32, kMaxInt32, ok); | 325 return enforceRange(numberObject->Value(), kMinInt32, kMaxInt32, "long",
exceptionState); |
| 306 | 326 |
| 307 // Does the value convert to nan or to an infinity? | 327 // Does the value convert to nan or to an infinity? |
| 308 double numberValue = numberObject->Value(); | 328 double numberValue = numberObject->Value(); |
| 309 if (std::isnan(numberValue) || std::isinf(numberValue)) | 329 if (std::isnan(numberValue) || std::isinf(numberValue)) |
| 310 return 0; | 330 return 0; |
| 311 | 331 |
| 312 if (configuration == Clamp) | 332 if (configuration == Clamp) |
| 313 return clampTo<int32_t>(numberObject->Value()); | 333 return clampTo<int32_t>(numberObject->Value()); |
| 314 | 334 |
| 315 V8TRYCATCH_RETURN(int32_t, result, numberObject->Int32Value(), 0); | 335 V8TRYCATCH_EXCEPTION_RETURN(int32_t, result, numberObject->Int32Value(), exc
eptionState, 0); |
| 316 return result; | 336 return result; |
| 317 } | 337 } |
| 318 | 338 |
| 319 uint32_t toUInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration co
nfiguration, bool& ok) | 339 int32_t toInt32(v8::Handle<v8::Value> value) |
| 320 { | 340 { |
| 321 ok = true; | 341 NonThrowableExceptionState exceptionState; |
| 342 return toInt32(value, NormalConversion, exceptionState); |
| 343 } |
| 322 | 344 |
| 345 uint32_t toUInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration co
nfiguration, ExceptionState& exceptionState) |
| 346 { |
| 323 // Fast case. The value is already a 32-bit unsigned integer. | 347 // Fast case. The value is already a 32-bit unsigned integer. |
| 324 if (value->IsUint32()) | 348 if (value->IsUint32()) |
| 325 return value->Uint32Value(); | 349 return value->Uint32Value(); |
| 326 | 350 |
| 327 // 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? |
| 328 if (value->IsInt32()) { | 352 if (value->IsInt32()) { |
| 329 int32_t result = value->Int32Value(); | 353 int32_t result = value->Int32Value(); |
| 330 if (result >= 0) | 354 if (result >= 0) |
| 331 return result; | 355 return result; |
| 332 if (configuration == EnforceRange) { | 356 if (configuration == EnforceRange) { |
| 333 ok = false; | 357 exceptionState.throwTypeError("Value is outside the 'unsigned long'
value range."); |
| 334 return 0; | 358 return 0; |
| 335 } | 359 } |
| 336 return result; | 360 return result; |
| 337 } | 361 } |
| 338 | 362 |
| 339 // Can the value be converted to a number? | 363 // Can the value be converted to a number? |
| 340 ok = false; | 364 V8TRYCATCH_EXCEPTION_RETURN(v8::Local<v8::Number>, numberObject, value->ToNu
mber(), exceptionState, 0); |
| 341 V8TRYCATCH_RETURN(v8::Local<v8::Number>, numberObject, value->ToNumber(), 0)
; | |
| 342 if (numberObject.IsEmpty()) { | 365 if (numberObject.IsEmpty()) { |
| 366 exceptionState.throwTypeError("Not convertible to a number value (of typ
e 'unsigned long'.)"); |
| 343 return 0; | 367 return 0; |
| 344 } | 368 } |
| 345 ok = true; | |
| 346 | 369 |
| 347 if (configuration == EnforceRange) | 370 if (configuration == EnforceRange) |
| 348 return enforceRange(numberObject->Value(), 0, kMaxUInt32, ok); | 371 return enforceRange(numberObject->Value(), 0, kMaxUInt32, "unsigned long
", exceptionState); |
| 349 | 372 |
| 350 // Does the value convert to nan or to an infinity? | 373 // Does the value convert to nan or to an infinity? |
| 351 double numberValue = numberObject->Value(); | 374 double numberValue = numberObject->Value(); |
| 352 if (std::isnan(numberValue) || std::isinf(numberValue)) | 375 if (std::isnan(numberValue) || std::isinf(numberValue)) |
| 353 return 0; | 376 return 0; |
| 354 | 377 |
| 355 if (configuration == Clamp) | 378 if (configuration == Clamp) |
| 356 return clampTo<uint32_t>(numberObject->Value()); | 379 return clampTo<uint32_t>(numberObject->Value()); |
| 357 | 380 |
| 358 V8TRYCATCH_RETURN(uint32_t, result, numberObject->Uint32Value(), 0); | 381 V8TRYCATCH_RETURN(uint32_t, result, numberObject->Uint32Value(), 0); |
| 359 return result; | 382 return result; |
| 360 } | 383 } |
| 361 | 384 |
| 362 int64_t toInt64(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf
iguration, bool& ok) | 385 uint32_t toUInt32(v8::Handle<v8::Value> value) |
| 363 { | 386 { |
| 364 ok = true; | 387 NonThrowableExceptionState exceptionState; |
| 388 return toUInt32(value, NormalConversion, exceptionState); |
| 389 } |
| 365 | 390 |
| 391 int64_t toInt64(v8::Handle<v8::Value> value, IntegerConversionConfiguration conf
iguration, ExceptionState& exceptionState) |
| 392 { |
| 366 // Fast case. The value is a 32-bit integer. | 393 // Fast case. The value is a 32-bit integer. |
| 367 if (value->IsInt32()) | 394 if (value->IsInt32()) |
| 368 return value->Int32Value(); | 395 return value->Int32Value(); |
| 369 | 396 |
| 370 // Can the value be converted to a number? | 397 // Can the value be converted to a number? |
| 371 v8::Local<v8::Number> numberObject = value->ToNumber(); | 398 V8TRYCATCH_EXCEPTION_RETURN(v8::Local<v8::Number>, numberObject, value->ToNu
mber(), exceptionState, 0); |
| 372 if (numberObject.IsEmpty()) { | 399 if (numberObject.IsEmpty()) { |
| 373 ok = false; | 400 exceptionState.throwTypeError("Not convertible to a number value (of typ
e 'long long'.)"); |
| 374 return 0; | 401 return 0; |
| 375 } | 402 } |
| 376 | 403 |
| 377 double x = numberObject->Value(); | 404 double x = numberObject->Value(); |
| 378 | 405 |
| 379 if (configuration == EnforceRange) | 406 if (configuration == EnforceRange) |
| 380 return enforceRange(x, -kJSMaxInteger, kJSMaxInteger, ok); | 407 return enforceRange(x, -kJSMaxInteger, kJSMaxInteger, "long long", excep
tionState); |
| 381 | 408 |
| 382 // Does the value convert to nan or to an infinity? | 409 // Does the value convert to nan or to an infinity? |
| 383 if (std::isnan(x) || std::isinf(x)) | 410 if (std::isnan(x) || std::isinf(x)) |
| 384 return 0; | 411 return 0; |
| 385 | 412 |
| 386 // NaNs and +/-Infinity should be 0, otherwise modulo 2^64. | 413 // NaNs and +/-Infinity should be 0, otherwise modulo 2^64. |
| 387 unsigned long long integer; | 414 unsigned long long integer; |
| 388 doubleToInteger(x, integer); | 415 doubleToInteger(x, integer); |
| 389 return integer; | 416 return integer; |
| 390 } | 417 } |
| 391 | 418 |
| 392 uint64_t toUInt64(v8::Handle<v8::Value> value, IntegerConversionConfiguration co
nfiguration, bool& ok) | 419 int64_t toInt64(v8::Handle<v8::Value> value) |
| 393 { | 420 { |
| 394 ok = true; | 421 NonThrowableExceptionState exceptionState; |
| 422 return toInt64(value, NormalConversion, exceptionState); |
| 423 } |
| 395 | 424 |
| 425 uint64_t toUInt64(v8::Handle<v8::Value> value, IntegerConversionConfiguration co
nfiguration, ExceptionState& exceptionState) |
| 426 { |
| 396 // Fast case. The value is a 32-bit unsigned integer. | 427 // Fast case. The value is a 32-bit unsigned integer. |
| 397 if (value->IsUint32()) | 428 if (value->IsUint32()) |
| 398 return value->Uint32Value(); | 429 return value->Uint32Value(); |
| 399 | 430 |
| 400 // Fast case. The value is a 32-bit integer. | 431 // Fast case. The value is a 32-bit integer. |
| 401 if (value->IsInt32()) { | 432 if (value->IsInt32()) { |
| 402 int32_t result = value->Int32Value(); | 433 int32_t result = value->Int32Value(); |
| 403 if (result >= 0) | 434 if (result >= 0) |
| 404 return result; | 435 return result; |
| 405 if (configuration == EnforceRange) { | 436 if (configuration == EnforceRange) { |
| 406 ok = false; | 437 exceptionState.throwTypeError("Value is outside the 'unsigned long l
ong' value range."); |
| 407 return 0; | 438 return 0; |
| 408 } | 439 } |
| 409 return result; | 440 return result; |
| 410 } | 441 } |
| 411 | 442 |
| 412 // Can the value be converted to a number? | 443 // Can the value be converted to a number? |
| 413 v8::Local<v8::Number> numberObject = value->ToNumber(); | 444 V8TRYCATCH_EXCEPTION_RETURN(v8::Local<v8::Number>, numberObject, value->ToNu
mber(), exceptionState, 0); |
| 414 if (numberObject.IsEmpty()) { | 445 if (numberObject.IsEmpty()) { |
| 415 ok = false; | 446 exceptionState.throwTypeError("Not convertible to a number value (of typ
e 'unsigned long long'.)"); |
| 416 return 0; | 447 return 0; |
| 417 } | 448 } |
| 418 | 449 |
| 419 double x = numberObject->Value(); | 450 double x = numberObject->Value(); |
| 420 | 451 |
| 421 if (configuration == EnforceRange) | 452 if (configuration == EnforceRange) |
| 422 return enforceRange(x, 0, kJSMaxInteger, ok); | 453 return enforceRange(x, 0, kJSMaxInteger, "unsigned long long", exception
State); |
| 423 | 454 |
| 424 // Does the value convert to nan or to an infinity? | 455 // Does the value convert to nan or to an infinity? |
| 425 if (std::isnan(x) || std::isinf(x)) | 456 if (std::isnan(x) || std::isinf(x)) |
| 426 return 0; | 457 return 0; |
| 427 | 458 |
| 428 // NaNs and +/-Infinity should be 0, otherwise modulo 2^64. | 459 // NaNs and +/-Infinity should be 0, otherwise modulo 2^64. |
| 429 unsigned long long integer; | 460 unsigned long long integer; |
| 430 doubleToInteger(x, integer); | 461 doubleToInteger(x, integer); |
| 431 return integer; | 462 return integer; |
| 432 } | 463 } |
| 433 | 464 |
| 465 uint64_t toUInt64(v8::Handle<v8::Value> value) |
| 466 { |
| 467 NonThrowableExceptionState exceptionState; |
| 468 return toUInt64(value, NormalConversion, exceptionState); |
| 469 } |
| 470 |
| 471 float toFloat(v8::Handle<v8::Value> value, ExceptionState& exceptionState) |
| 472 { |
| 473 V8TRYCATCH_EXCEPTION_RETURN(v8::Local<v8::Number>, numberObject, value->ToNu
mber(), exceptionState, 0); |
| 474 return numberObject->NumberValue(); |
| 475 } |
| 476 |
| 434 v8::Handle<v8::FunctionTemplate> createRawTemplate(v8::Isolate* isolate) | 477 v8::Handle<v8::FunctionTemplate> createRawTemplate(v8::Isolate* isolate) |
| 435 { | 478 { |
| 436 v8::EscapableHandleScope scope(isolate); | 479 v8::EscapableHandleScope scope(isolate); |
| 437 v8::Local<v8::FunctionTemplate> result = v8::FunctionTemplate::New(isolate,
V8ObjectConstructor::isValidConstructorMode); | 480 v8::Local<v8::FunctionTemplate> result = v8::FunctionTemplate::New(isolate,
V8ObjectConstructor::isValidConstructorMode); |
| 438 return scope.Escape(result); | 481 return scope.Escape(result); |
| 439 } | 482 } |
| 440 | 483 |
| 441 PassRefPtr<XPathNSResolver> toXPathNSResolver(v8::Handle<v8::Value> value, v8::I
solate* isolate) | 484 PassRefPtr<XPathNSResolver> toXPathNSResolver(v8::Handle<v8::Value> value, v8::I
solate* isolate) |
| 442 { | 485 { |
| 443 RefPtr<XPathNSResolver> resolver; | 486 RefPtr<XPathNSResolver> resolver; |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 return mainThreadIsolate(); | 682 return mainThreadIsolate(); |
| 640 return v8::Isolate::GetCurrent(); | 683 return v8::Isolate::GetCurrent(); |
| 641 } | 684 } |
| 642 | 685 |
| 643 v8::Isolate* toIsolate(Frame* frame) | 686 v8::Isolate* toIsolate(Frame* frame) |
| 644 { | 687 { |
| 645 return frame->script().isolate(); | 688 return frame->script().isolate(); |
| 646 } | 689 } |
| 647 | 690 |
| 648 } // namespace WebCore | 691 } // namespace WebCore |
| OLD | NEW |