Chromium Code Reviews| 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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 static const unsigned numberOfValues = 65536; // 2^16 | 157 static const unsigned numberOfValues = 65536; // 2^16 |
| 158 }; | 158 }; |
| 159 | 159 |
| 160 template <typename T> | 160 template <typename T> |
| 161 static inline T toSmallerInt(v8::Isolate* isolate, v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, const char* typeName, ExceptionSta te& exceptionState) | 161 static inline T toSmallerInt(v8::Isolate* isolate, v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, const char* typeName, ExceptionSta te& exceptionState) |
| 162 { | 162 { |
| 163 typedef IntTypeLimits<T> LimitsTrait; | 163 typedef IntTypeLimits<T> LimitsTrait; |
| 164 | 164 |
| 165 // Fast case. The value is already a 32-bit integer in the right range. | 165 // Fast case. The value is already a 32-bit integer in the right range. |
| 166 if (value->IsInt32()) { | 166 if (value->IsInt32()) { |
| 167 int32_t result = value->Int32Value(); | 167 int32_t result = value.As<v8::Int32>()->Value(); |
| 168 if (result >= LimitsTrait::minValue && result <= LimitsTrait::maxValue) | 168 if (result >= LimitsTrait::minValue && result <= LimitsTrait::maxValue) |
| 169 return static_cast<T>(result); | 169 return static_cast<T>(result); |
| 170 if (configuration == EnforceRange) { | 170 if (configuration == EnforceRange) { |
| 171 exceptionState.throwTypeError("Value is outside the '" + String(type Name) + "' value range."); | 171 exceptionState.throwTypeError("Value is outside the '" + String(type Name) + "' value range."); |
| 172 return 0; | 172 return 0; |
| 173 } | 173 } |
| 174 if (configuration == Clamp) | 174 if (configuration == Clamp) |
| 175 return clampTo<T>(result); | 175 return clampTo<T>(result); |
| 176 result %= LimitsTrait::numberOfValues; | 176 result %= LimitsTrait::numberOfValues; |
| 177 return static_cast<T>(result > LimitsTrait::maxValue ? result - LimitsTr ait::numberOfValues : result); | 177 return static_cast<T>(result > LimitsTrait::maxValue ? result - LimitsTr ait::numberOfValues : result); |
| 178 } | 178 } |
| 179 | 179 |
| 180 v8::Local<v8::Number> numberObject; | 180 v8::Local<v8::Number> numberObject; |
| 181 if (value->IsNumber()) { | 181 if (value->IsNumber()) { |
| 182 numberObject = value.As<v8::Number>(); | 182 numberObject = value.As<v8::Number>(); |
| 183 } else { | 183 } else { |
| 184 // Can the value be converted to a number? | 184 // Can the value be converted to a number? |
| 185 v8::TryCatch block(isolate); | 185 v8::TryCatch block(isolate); |
| 186 numberObject = value->ToNumber(isolate); | 186 if (!v8Call(value->ToNumber(isolate->GetCurrentContext()), numberObject, block)) { |
| 187 if (block.HasCaught()) { | |
| 188 exceptionState.rethrowV8Exception(block.Exception()); | 187 exceptionState.rethrowV8Exception(block.Exception()); |
| 189 return 0; | 188 return 0; |
| 190 } | 189 } |
| 191 } | 190 } |
| 192 ASSERT(!numberObject.IsEmpty()); | 191 ASSERT(!numberObject.IsEmpty()); |
| 193 | 192 |
| 194 if (configuration == EnforceRange) | 193 if (configuration == EnforceRange) |
| 195 return enforceRange(numberObject->Value(), LimitsTrait::minValue, Limits Trait::maxValue, typeName, exceptionState); | 194 return enforceRange(numberObject->Value(), LimitsTrait::minValue, Limits Trait::maxValue, typeName, exceptionState); |
| 196 | 195 |
| 197 double numberValue = numberObject->Value(); | 196 double numberValue = numberObject->Value(); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 210 return static_cast<T>(numberValue > LimitsTrait::maxValue ? numberValue - Li mitsTrait::numberOfValues : numberValue); | 209 return static_cast<T>(numberValue > LimitsTrait::maxValue ? numberValue - Li mitsTrait::numberOfValues : numberValue); |
| 211 } | 210 } |
| 212 | 211 |
| 213 template <typename T> | 212 template <typename T> |
| 214 static inline T toSmallerUInt(v8::Isolate* isolate, v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, const char* typeName, ExceptionSt ate& exceptionState) | 213 static inline T toSmallerUInt(v8::Isolate* isolate, v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, const char* typeName, ExceptionSt ate& exceptionState) |
| 215 { | 214 { |
| 216 typedef IntTypeLimits<T> LimitsTrait; | 215 typedef IntTypeLimits<T> LimitsTrait; |
| 217 | 216 |
| 218 // Fast case. The value is a 32-bit signed integer - possibly positive? | 217 // Fast case. The value is a 32-bit signed integer - possibly positive? |
| 219 if (value->IsInt32()) { | 218 if (value->IsInt32()) { |
| 220 int32_t result = value->Int32Value(); | 219 int32_t result = value.As<v8::Int32>()->Value(); |
| 221 if (result >= 0 && result <= LimitsTrait::maxValue) | 220 if (result >= 0 && result <= LimitsTrait::maxValue) |
| 222 return static_cast<T>(result); | 221 return static_cast<T>(result); |
| 223 if (configuration == EnforceRange) { | 222 if (configuration == EnforceRange) { |
| 224 exceptionState.throwTypeError("Value is outside the '" + String(type Name) + "' value range."); | 223 exceptionState.throwTypeError("Value is outside the '" + String(type Name) + "' value range."); |
| 225 return 0; | 224 return 0; |
| 226 } | 225 } |
| 227 if (configuration == Clamp) | 226 if (configuration == Clamp) |
| 228 return clampTo<T>(result); | 227 return clampTo<T>(result); |
| 229 return static_cast<T>(result); | 228 return static_cast<T>(result); |
| 230 } | 229 } |
| 231 | 230 |
| 232 v8::Local<v8::Number> numberObject; | 231 v8::Local<v8::Number> numberObject; |
| 233 if (value->IsNumber()) { | 232 if (value->IsNumber()) { |
| 234 numberObject = value.As<v8::Number>(); | 233 numberObject = value.As<v8::Number>(); |
| 235 } else { | 234 } else { |
| 236 // Can the value be converted to a number? | 235 // Can the value be converted to a number? |
| 237 v8::TryCatch block(isolate); | 236 v8::TryCatch block(isolate); |
| 238 numberObject = value->ToNumber(isolate); | 237 if (!v8Call(value->ToNumber(isolate->GetCurrentContext()), numberObject, block)) { |
| 239 if (block.HasCaught()) { | |
| 240 exceptionState.rethrowV8Exception(block.Exception()); | 238 exceptionState.rethrowV8Exception(block.Exception()); |
| 241 return 0; | 239 return 0; |
| 242 } | 240 } |
| 243 } | 241 } |
| 244 ASSERT(!numberObject.IsEmpty()); | 242 ASSERT(!numberObject.IsEmpty()); |
| 245 | 243 |
| 246 if (configuration == EnforceRange) | 244 if (configuration == EnforceRange) |
| 247 return enforceRange(numberObject->Value(), 0, LimitsTrait::maxValue, typ eName, exceptionState); | 245 return enforceRange(numberObject->Value(), 0, LimitsTrait::maxValue, typ eName, exceptionState); |
| 248 | 246 |
| 249 double numberValue = numberObject->Value(); | 247 double numberValue = numberObject->Value(); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 279 uint16_t toUInt16(v8::Isolate* isolate, v8::Handle<v8::Value> value, IntegerConv ersionConfiguration configuration, ExceptionState& exceptionState) | 277 uint16_t toUInt16(v8::Isolate* isolate, v8::Handle<v8::Value> value, IntegerConv ersionConfiguration configuration, ExceptionState& exceptionState) |
| 280 { | 278 { |
| 281 return toSmallerUInt<uint16_t>(isolate, value, configuration, "unsigned shor t", exceptionState); | 279 return toSmallerUInt<uint16_t>(isolate, value, configuration, "unsigned shor t", exceptionState); |
| 282 } | 280 } |
| 283 | 281 |
| 284 int32_t toInt32Slow(v8::Isolate* isolate, v8::Handle<v8::Value> value, IntegerCo nversionConfiguration configuration, ExceptionState& exceptionState) | 282 int32_t toInt32Slow(v8::Isolate* isolate, v8::Handle<v8::Value> value, IntegerCo nversionConfiguration configuration, ExceptionState& exceptionState) |
| 285 { | 283 { |
| 286 ASSERT(!value->IsInt32()); | 284 ASSERT(!value->IsInt32()); |
| 287 // Can the value be converted to a number? | 285 // Can the value be converted to a number? |
| 288 v8::TryCatch block(isolate); | 286 v8::TryCatch block(isolate); |
| 289 v8::Local<v8::Number> numberObject = value->ToNumber(isolate); | 287 v8::Local<v8::Number> numberObject; |
| 290 if (block.HasCaught()) { | 288 if (!v8Call(value->ToNumber(isolate->GetCurrentContext()), numberObject, blo ck)) { |
| 291 exceptionState.rethrowV8Exception(block.Exception()); | 289 exceptionState.rethrowV8Exception(block.Exception()); |
| 292 return 0; | 290 return 0; |
| 293 } | 291 } |
| 294 | 292 |
| 295 ASSERT(!numberObject.IsEmpty()); | 293 ASSERT(!numberObject.IsEmpty()); |
| 296 | 294 |
| 297 double numberValue = numberObject->Value(); | 295 double numberValue = numberObject->Value(); |
| 298 if (configuration == EnforceRange) | 296 if (configuration == EnforceRange) |
| 299 return enforceRange(numberValue, kMinInt32, kMaxInt32, "long", exception State); | 297 return enforceRange(numberValue, kMinInt32, kMaxInt32, "long", exception State); |
| 300 | 298 |
| 301 if (std::isnan(numberValue)) | 299 if (std::isnan(numberValue)) |
| 302 return 0; | 300 return 0; |
| 303 | 301 |
| 304 if (configuration == Clamp) | 302 if (configuration == Clamp) |
| 305 return clampTo<int32_t>(numberValue); | 303 return clampTo<int32_t>(numberValue); |
| 306 | 304 |
| 307 if (std::isinf(numberValue)) | 305 if (std::isinf(numberValue)) |
| 308 return 0; | 306 return 0; |
| 309 | 307 |
| 310 return numberObject->Int32Value(); | 308 int32_t result; |
| 309 if (!v8Call(numberObject->Int32Value(isolate->GetCurrentContext()), result, block)) { | |
| 310 exceptionState.rethrowV8Exception(block.Exception()); | |
|
Jens Widell
2015/03/25 11:11:15
Technically, this call can't fail, since numberObj
haraken
2015/03/25 11:53:44
In practice this call won't fail, but conceptually
| |
| 311 return 0; | |
| 312 } | |
| 313 return result; | |
| 311 } | 314 } |
| 312 | 315 |
| 313 uint32_t toUInt32Slow(v8::Isolate* isolate, v8::Handle<v8::Value> value, Integer ConversionConfiguration configuration, ExceptionState& exceptionState) | 316 uint32_t toUInt32Slow(v8::Isolate* isolate, v8::Handle<v8::Value> value, Integer ConversionConfiguration configuration, ExceptionState& exceptionState) |
| 314 { | 317 { |
| 315 ASSERT(!value->IsUint32()); | 318 ASSERT(!value->IsUint32()); |
| 316 if (value->IsInt32()) { | 319 if (value->IsInt32()) { |
| 317 ASSERT(configuration != NormalConversion); | 320 ASSERT(configuration != NormalConversion); |
| 318 int32_t result = value->Int32Value(); | 321 int32_t result = value.As<v8::Int32>()->Value(); |
| 319 if (result >= 0) | 322 if (result >= 0) |
| 320 return result; | 323 return result; |
| 321 if (configuration == EnforceRange) { | 324 if (configuration == EnforceRange) { |
| 322 exceptionState.throwTypeError("Value is outside the 'unsigned long' value range."); | 325 exceptionState.throwTypeError("Value is outside the 'unsigned long' value range."); |
| 323 return 0; | 326 return 0; |
| 324 } | 327 } |
| 325 ASSERT(configuration == Clamp); | 328 ASSERT(configuration == Clamp); |
| 326 return clampTo<uint32_t>(result); | 329 return clampTo<uint32_t>(result); |
| 327 } | 330 } |
| 328 | 331 |
| 329 // Can the value be converted to a number? | 332 // Can the value be converted to a number? |
| 330 v8::TryCatch block(isolate); | 333 v8::TryCatch block(isolate); |
| 331 v8::Local<v8::Number> numberObject = value->ToNumber(isolate); | 334 v8::Local<v8::Number> numberObject; |
| 332 if (block.HasCaught()) { | 335 if (!v8Call(value->ToNumber(isolate->GetCurrentContext()), numberObject, blo ck)) { |
| 333 exceptionState.rethrowV8Exception(block.Exception()); | 336 exceptionState.rethrowV8Exception(block.Exception()); |
| 334 return 0; | 337 return 0; |
| 335 } | 338 } |
| 336 ASSERT(!numberObject.IsEmpty()); | 339 ASSERT(!numberObject.IsEmpty()); |
| 337 | 340 |
| 338 if (configuration == EnforceRange) | 341 if (configuration == EnforceRange) |
| 339 return enforceRange(numberObject->Value(), 0, kMaxUInt32, "unsigned long ", exceptionState); | 342 return enforceRange(numberObject->Value(), 0, kMaxUInt32, "unsigned long ", exceptionState); |
| 340 | 343 |
| 341 double numberValue = numberObject->Value(); | 344 double numberValue = numberObject->Value(); |
| 342 | 345 |
| 343 if (std::isnan(numberValue)) | 346 if (std::isnan(numberValue)) |
| 344 return 0; | 347 return 0; |
| 345 | 348 |
| 346 if (configuration == Clamp) | 349 if (configuration == Clamp) |
| 347 return clampTo<uint32_t>(numberValue); | 350 return clampTo<uint32_t>(numberValue); |
| 348 | 351 |
| 349 if (std::isinf(numberValue)) | 352 if (std::isinf(numberValue)) |
| 350 return 0; | 353 return 0; |
| 351 | 354 |
| 352 return numberObject->Uint32Value(); | 355 uint32_t result; |
| 356 if (!v8Call(numberObject->Uint32Value(isolate->GetCurrentContext()), result, block)) { | |
| 357 exceptionState.rethrowV8Exception(block.Exception()); | |
|
Jens Widell
2015/03/25 11:11:15
Same here.
| |
| 358 return 0; | |
| 359 } | |
| 360 return result; | |
| 353 } | 361 } |
| 354 | 362 |
| 355 int64_t toInt64Slow(v8::Isolate* isolate, v8::Handle<v8::Value> value, IntegerCo nversionConfiguration configuration, ExceptionState& exceptionState) | 363 int64_t toInt64Slow(v8::Isolate* isolate, v8::Handle<v8::Value> value, IntegerCo nversionConfiguration configuration, ExceptionState& exceptionState) |
| 356 { | 364 { |
| 357 ASSERT(!value->IsInt32()); | 365 ASSERT(!value->IsInt32()); |
| 358 | 366 |
| 359 v8::Local<v8::Number> numberObject; | 367 v8::Local<v8::Number> numberObject; |
| 360 // Can the value be converted to a number? | 368 // Can the value be converted to a number? |
| 361 v8::TryCatch block(isolate); | 369 v8::TryCatch block(isolate); |
| 362 numberObject = value->ToNumber(isolate); | 370 if (!v8Call(value->ToNumber(isolate->GetCurrentContext()), numberObject, blo ck)) { |
| 363 if (block.HasCaught()) { | |
| 364 exceptionState.rethrowV8Exception(block.Exception()); | 371 exceptionState.rethrowV8Exception(block.Exception()); |
| 365 return 0; | 372 return 0; |
| 366 } | 373 } |
| 367 ASSERT(!numberObject.IsEmpty()); | 374 ASSERT(!numberObject.IsEmpty()); |
| 368 | 375 |
| 369 double numberValue = numberObject->Value(); | 376 double numberValue = numberObject->Value(); |
| 370 | 377 |
| 371 if (configuration == EnforceRange) | 378 if (configuration == EnforceRange) |
| 372 return enforceRange(numberValue, -kJSMaxInteger, kJSMaxInteger, "long lo ng", exceptionState); | 379 return enforceRange(numberValue, -kJSMaxInteger, kJSMaxInteger, "long lo ng", exceptionState); |
| 373 | 380 |
| 374 if (std::isnan(numberValue) || std::isinf(numberValue)) | 381 if (std::isnan(numberValue) || std::isinf(numberValue)) |
| 375 return 0; | 382 return 0; |
| 376 | 383 |
| 377 // NaNs and +/-Infinity should be 0, otherwise modulo 2^64. | 384 // NaNs and +/-Infinity should be 0, otherwise modulo 2^64. |
| 378 unsigned long long integer; | 385 unsigned long long integer; |
| 379 doubleToInteger(numberValue, integer); | 386 doubleToInteger(numberValue, integer); |
| 380 return integer; | 387 return integer; |
| 381 } | 388 } |
| 382 | 389 |
| 383 uint64_t toUInt64Slow(v8::Isolate* isolate, v8::Handle<v8::Value> value, Integer ConversionConfiguration configuration, ExceptionState& exceptionState) | 390 uint64_t toUInt64Slow(v8::Isolate* isolate, v8::Handle<v8::Value> value, Integer ConversionConfiguration configuration, ExceptionState& exceptionState) |
| 384 { | 391 { |
| 385 ASSERT(!value->IsUint32()); | 392 ASSERT(!value->IsUint32()); |
| 386 if (value->IsInt32()) { | 393 if (value->IsInt32()) { |
| 387 ASSERT(configuration != NormalConversion); | 394 ASSERT(configuration != NormalConversion); |
| 388 int32_t result = value->Int32Value(); | 395 int32_t result = value.As<v8::Int32>()->Value(); |
| 389 if (result >= 0) | 396 if (result >= 0) |
| 390 return result; | 397 return result; |
| 391 if (configuration == EnforceRange) { | 398 if (configuration == EnforceRange) { |
| 392 exceptionState.throwTypeError("Value is outside the 'unsigned long l ong' value range."); | 399 exceptionState.throwTypeError("Value is outside the 'unsigned long l ong' value range."); |
| 393 return 0; | 400 return 0; |
| 394 } | 401 } |
| 395 ASSERT(configuration == Clamp); | 402 ASSERT(configuration == Clamp); |
| 396 return clampTo<uint64_t>(result); | 403 return clampTo<uint64_t>(result); |
| 397 } | 404 } |
| 398 | 405 |
| 399 v8::Local<v8::Number> numberObject; | 406 v8::Local<v8::Number> numberObject; |
| 400 // Can the value be converted to a number? | 407 // Can the value be converted to a number? |
| 401 v8::TryCatch block(isolate); | 408 v8::TryCatch block(isolate); |
| 402 numberObject = value->ToNumber(isolate); | 409 if (!v8Call(value->ToNumber(isolate->GetCurrentContext()), numberObject, blo ck)) { |
| 403 if (block.HasCaught()) { | |
| 404 exceptionState.rethrowV8Exception(block.Exception()); | 410 exceptionState.rethrowV8Exception(block.Exception()); |
| 405 return 0; | 411 return 0; |
| 406 } | 412 } |
| 407 ASSERT(!numberObject.IsEmpty()); | 413 ASSERT(!numberObject.IsEmpty()); |
| 408 | 414 |
| 409 double numberValue = numberObject->Value(); | 415 double numberValue = numberObject->Value(); |
| 410 | 416 |
| 411 if (configuration == EnforceRange) | 417 if (configuration == EnforceRange) |
| 412 return enforceRange(numberValue, 0, kJSMaxInteger, "unsigned long long", exceptionState); | 418 return enforceRange(numberValue, 0, kJSMaxInteger, "unsigned long long", exceptionState); |
| 413 | 419 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 435 exceptionState.throwTypeError("The provided float value is non-finite.") ; | 441 exceptionState.throwTypeError("The provided float value is non-finite.") ; |
| 436 return 0; | 442 return 0; |
| 437 } | 443 } |
| 438 return numberValue; | 444 return numberValue; |
| 439 } | 445 } |
| 440 | 446 |
| 441 double toDoubleSlow(v8::Isolate* isolate, v8::Handle<v8::Value> value, Exception State& exceptionState) | 447 double toDoubleSlow(v8::Isolate* isolate, v8::Handle<v8::Value> value, Exception State& exceptionState) |
| 442 { | 448 { |
| 443 ASSERT(!value->IsNumber()); | 449 ASSERT(!value->IsNumber()); |
| 444 v8::TryCatch block(isolate); | 450 v8::TryCatch block(isolate); |
| 445 double doubleValue = value->NumberValue(); | 451 double doubleValue; |
| 446 if (block.HasCaught()) { | 452 if (!v8Call(value->NumberValue(isolate->GetCurrentContext()), doubleValue, b lock)) { |
| 447 exceptionState.rethrowV8Exception(block.Exception()); | 453 exceptionState.rethrowV8Exception(block.Exception()); |
| 448 return 0; | 454 return 0; |
| 449 } | 455 } |
| 450 return doubleValue; | 456 return doubleValue; |
| 451 } | 457 } |
| 452 | 458 |
| 453 double toRestrictedDouble(v8::Isolate* isolate, v8::Handle<v8::Value> value, Exc eptionState& exceptionState) | 459 double toRestrictedDouble(v8::Isolate* isolate, v8::Handle<v8::Value> value, Exc eptionState& exceptionState) |
| 454 { | 460 { |
| 455 double numberValue = toDouble(isolate, value, exceptionState); | 461 double numberValue = toDouble(isolate, value, exceptionState); |
| 456 if (exceptionState.hadException()) | 462 if (exceptionState.hadException()) |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 471 // From the Web IDL spec: http://heycam.github.io/webidl/#es-ByteString | 477 // From the Web IDL spec: http://heycam.github.io/webidl/#es-ByteString |
| 472 if (value.IsEmpty()) | 478 if (value.IsEmpty()) |
| 473 return String(); | 479 return String(); |
| 474 | 480 |
| 475 // 1. Let x be ToString(v) | 481 // 1. Let x be ToString(v) |
| 476 v8::Local<v8::String> stringObject; | 482 v8::Local<v8::String> stringObject; |
| 477 if (value->IsString()) { | 483 if (value->IsString()) { |
| 478 stringObject = value.As<v8::String>(); | 484 stringObject = value.As<v8::String>(); |
| 479 } else { | 485 } else { |
| 480 v8::TryCatch block(isolate); | 486 v8::TryCatch block(isolate); |
| 481 stringObject = value->ToString(isolate); | 487 if (!v8Call(value->ToString(isolate->GetCurrentContext()), stringObject, block)) { |
| 482 if (block.HasCaught()) { | |
| 483 exceptionState.rethrowV8Exception(block.Exception()); | 488 exceptionState.rethrowV8Exception(block.Exception()); |
| 484 return String(); | 489 return String(); |
| 485 } | 490 } |
| 486 } | 491 } |
| 487 | 492 |
| 488 String x = toCoreString(stringObject); | 493 String x = toCoreString(stringObject); |
| 489 | 494 |
| 490 // 2. If the value of any element of x is greater than 255, then throw a Typ eError. | 495 // 2. If the value of any element of x is greater than 255, then throw a Typ eError. |
| 491 if (!x.containsOnlyLatin1()) { | 496 if (!x.containsOnlyLatin1()) { |
| 492 exceptionState.throwTypeError("Value is not a valid ByteString."); | 497 exceptionState.throwTypeError("Value is not a valid ByteString."); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 606 { | 611 { |
| 607 // http://heycam.github.io/webidl/#es-USVString | 612 // http://heycam.github.io/webidl/#es-USVString |
| 608 if (value.IsEmpty()) | 613 if (value.IsEmpty()) |
| 609 return String(); | 614 return String(); |
| 610 | 615 |
| 611 v8::Local<v8::String> stringObject; | 616 v8::Local<v8::String> stringObject; |
| 612 if (value->IsString()) { | 617 if (value->IsString()) { |
| 613 stringObject = value.As<v8::String>(); | 618 stringObject = value.As<v8::String>(); |
| 614 } else { | 619 } else { |
| 615 v8::TryCatch block(isolate); | 620 v8::TryCatch block(isolate); |
| 616 stringObject = value->ToString(isolate); | 621 if (!v8Call(value->ToString(isolate->GetCurrentContext()), stringObject, block)) { |
| 617 if (block.HasCaught()) { | |
| 618 exceptionState.rethrowV8Exception(block.Exception()); | 622 exceptionState.rethrowV8Exception(block.Exception()); |
| 619 return String(); | 623 return String(); |
| 620 } | 624 } |
| 621 } | 625 } |
| 622 | 626 |
| 623 // USVString is identical to DOMString except that "convert a | 627 // USVString is identical to DOMString except that "convert a |
| 624 // DOMString to a sequence of Unicode characters" is used subsequently | 628 // DOMString to a sequence of Unicode characters" is used subsequently |
| 625 // when converting to an IDL value | 629 // when converting to an IDL value |
| 626 String x = toCoreString(stringObject); | 630 String x = toCoreString(stringObject); |
| 627 return replaceUnmatchedSurrogates(x); | 631 return replaceUnmatchedSurrogates(x); |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 943 v8::Local<v8::Value> data = info.Data(); | 947 v8::Local<v8::Value> data = info.Data(); |
| 944 ASSERT(data->IsExternal()); | 948 ASSERT(data->IsExternal()); |
| 945 V8PerContextData* perContextData = V8PerContextData::from(info.Holder()->Cre ationContext()); | 949 V8PerContextData* perContextData = V8PerContextData::from(info.Holder()->Cre ationContext()); |
| 946 if (!perContextData) | 950 if (!perContextData) |
| 947 return; | 951 return; |
| 948 v8SetReturnValue(info, perContextData->constructorForType(WrapperTypeInfo::u nwrap(data))); | 952 v8SetReturnValue(info, perContextData->constructorForType(WrapperTypeInfo::u nwrap(data))); |
| 949 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); | 953 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); |
| 950 } | 954 } |
| 951 | 955 |
| 952 } // namespace blink | 956 } // namespace blink |
| OLD | NEW |