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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 v8::Local<v8::Value> createMinimumArityTypeErrorForConstructor(v8::Isolate* isol
ate, const char* type, unsigned expected, unsigned provided) | 87 v8::Local<v8::Value> createMinimumArityTypeErrorForConstructor(v8::Isolate* isol
ate, const char* type, unsigned expected, unsigned provided) |
88 { | 88 { |
89 return V8ThrowException::createTypeError(isolate, ExceptionMessages::failedT
oConstruct(type, ExceptionMessages::notEnoughArguments(expected, provided))); | 89 return V8ThrowException::createTypeError(isolate, ExceptionMessages::failedT
oConstruct(type, ExceptionMessages::notEnoughArguments(expected, provided))); |
90 } | 90 } |
91 | 91 |
92 void setMinimumArityTypeError(ExceptionState& exceptionState, unsigned expected,
unsigned provided) | 92 void setMinimumArityTypeError(ExceptionState& exceptionState, unsigned expected,
unsigned provided) |
93 { | 93 { |
94 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(expected
, provided)); | 94 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(expected
, provided)); |
95 } | 95 } |
96 | 96 |
97 PassRefPtrWillBeRawPtr<NodeFilter> toNodeFilter(v8::Handle<v8::Value> callback,
v8::Handle<v8::Object> creationContext, ScriptState* scriptState) | 97 PassRefPtrWillBeRawPtr<NodeFilter> toNodeFilter(v8::Local<v8::Value> callback, v
8::Local<v8::Object> creationContext, ScriptState* scriptState) |
98 { | 98 { |
99 if (callback->IsNull()) | 99 if (callback->IsNull()) |
100 return nullptr; | 100 return nullptr; |
101 RefPtrWillBeRawPtr<NodeFilter> filter = NodeFilter::create(); | 101 RefPtrWillBeRawPtr<NodeFilter> filter = NodeFilter::create(); |
102 | 102 |
103 v8::Handle<v8::Object> filterWrapper = toV8(filter.get(), creationContext, s
criptState->isolate()).As<v8::Object>(); | 103 v8::Local<v8::Object> filterWrapper = toV8(filter.get(), creationContext, sc
riptState->isolate()).As<v8::Object>(); |
104 | 104 |
105 RefPtrWillBeRawPtr<NodeFilterCondition> condition = V8NodeFilterCondition::c
reate(callback, filterWrapper, scriptState); | 105 RefPtrWillBeRawPtr<NodeFilterCondition> condition = V8NodeFilterCondition::c
reate(callback, filterWrapper, scriptState); |
106 filter->setCondition(condition.release()); | 106 filter->setCondition(condition.release()); |
107 | 107 |
108 return filter.release(); | 108 return filter.release(); |
109 } | 109 } |
110 | 110 |
111 bool toBooleanSlow(v8::Isolate* isolate, v8::Local<v8::Value> value, ExceptionSt
ate& exceptionState) | 111 bool toBooleanSlow(v8::Isolate* isolate, v8::Local<v8::Value> value, ExceptionSt
ate& exceptionState) |
112 { | 112 { |
113 ASSERT(!value->IsBoolean()); | 113 ASSERT(!value->IsBoolean()); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 static const unsigned numberOfValues = 65536; // 2^16 | 161 static const unsigned numberOfValues = 65536; // 2^16 |
162 }; | 162 }; |
163 | 163 |
164 template <> | 164 template <> |
165 struct IntTypeLimits<uint16_t> { | 165 struct IntTypeLimits<uint16_t> { |
166 static const unsigned short maxValue = 65535; | 166 static const unsigned short maxValue = 65535; |
167 static const unsigned numberOfValues = 65536; // 2^16 | 167 static const unsigned numberOfValues = 65536; // 2^16 |
168 }; | 168 }; |
169 | 169 |
170 template <typename T> | 170 template <typename T> |
171 static inline T toSmallerInt(v8::Isolate* isolate, v8::Handle<v8::Value> value,
IntegerConversionConfiguration configuration, const char* typeName, ExceptionSta
te& exceptionState) | 171 static inline T toSmallerInt(v8::Isolate* isolate, v8::Local<v8::Value> value, I
ntegerConversionConfiguration configuration, const char* typeName, ExceptionStat
e& exceptionState) |
172 { | 172 { |
173 typedef IntTypeLimits<T> LimitsTrait; | 173 typedef IntTypeLimits<T> LimitsTrait; |
174 | 174 |
175 // Fast case. The value is already a 32-bit integer in the right range. | 175 // Fast case. The value is already a 32-bit integer in the right range. |
176 if (value->IsInt32()) { | 176 if (value->IsInt32()) { |
177 int32_t result = value.As<v8::Int32>()->Value(); | 177 int32_t result = value.As<v8::Int32>()->Value(); |
178 if (result >= LimitsTrait::minValue && result <= LimitsTrait::maxValue) | 178 if (result >= LimitsTrait::minValue && result <= LimitsTrait::maxValue) |
179 return static_cast<T>(result); | 179 return static_cast<T>(result); |
180 if (configuration == EnforceRange) { | 180 if (configuration == EnforceRange) { |
181 exceptionState.throwTypeError("Value is outside the '" + String(type
Name) + "' value range."); | 181 exceptionState.throwTypeError("Value is outside the '" + String(type
Name) + "' value range."); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 if (std::isinf(numberValue)) | 213 if (std::isinf(numberValue)) |
214 return 0; | 214 return 0; |
215 | 215 |
216 numberValue = numberValue < 0 ? -floor(fabs(numberValue)) : floor(fabs(numbe
rValue)); | 216 numberValue = numberValue < 0 ? -floor(fabs(numberValue)) : floor(fabs(numbe
rValue)); |
217 numberValue = fmod(numberValue, LimitsTrait::numberOfValues); | 217 numberValue = fmod(numberValue, LimitsTrait::numberOfValues); |
218 | 218 |
219 return static_cast<T>(numberValue > LimitsTrait::maxValue ? numberValue - Li
mitsTrait::numberOfValues : numberValue); | 219 return static_cast<T>(numberValue > LimitsTrait::maxValue ? numberValue - Li
mitsTrait::numberOfValues : numberValue); |
220 } | 220 } |
221 | 221 |
222 template <typename T> | 222 template <typename T> |
223 static inline T toSmallerUInt(v8::Isolate* isolate, v8::Handle<v8::Value> value,
IntegerConversionConfiguration configuration, const char* typeName, ExceptionSt
ate& exceptionState) | 223 static inline T toSmallerUInt(v8::Isolate* isolate, v8::Local<v8::Value> value,
IntegerConversionConfiguration configuration, const char* typeName, ExceptionSta
te& exceptionState) |
224 { | 224 { |
225 typedef IntTypeLimits<T> LimitsTrait; | 225 typedef IntTypeLimits<T> LimitsTrait; |
226 | 226 |
227 // Fast case. The value is a 32-bit signed integer - possibly positive? | 227 // Fast case. The value is a 32-bit signed integer - possibly positive? |
228 if (value->IsInt32()) { | 228 if (value->IsInt32()) { |
229 int32_t result = value.As<v8::Int32>()->Value(); | 229 int32_t result = value.As<v8::Int32>()->Value(); |
230 if (result >= 0 && result <= LimitsTrait::maxValue) | 230 if (result >= 0 && result <= LimitsTrait::maxValue) |
231 return static_cast<T>(result); | 231 return static_cast<T>(result); |
232 if (configuration == EnforceRange) { | 232 if (configuration == EnforceRange) { |
233 exceptionState.throwTypeError("Value is outside the '" + String(type
Name) + "' value range."); | 233 exceptionState.throwTypeError("Value is outside the '" + String(type
Name) + "' value range."); |
(...skipping 28 matching lines...) Expand all Loading... |
262 if (configuration == Clamp) | 262 if (configuration == Clamp) |
263 return clampTo<T>(numberValue); | 263 return clampTo<T>(numberValue); |
264 | 264 |
265 if (std::isinf(numberValue)) | 265 if (std::isinf(numberValue)) |
266 return 0; | 266 return 0; |
267 | 267 |
268 numberValue = numberValue < 0 ? -floor(fabs(numberValue)) : floor(fabs(numbe
rValue)); | 268 numberValue = numberValue < 0 ? -floor(fabs(numberValue)) : floor(fabs(numbe
rValue)); |
269 return static_cast<T>(fmod(numberValue, LimitsTrait::numberOfValues)); | 269 return static_cast<T>(fmod(numberValue, LimitsTrait::numberOfValues)); |
270 } | 270 } |
271 | 271 |
272 int8_t toInt8(v8::Isolate* isolate, v8::Handle<v8::Value> value, IntegerConversi
onConfiguration configuration, ExceptionState& exceptionState) | 272 int8_t toInt8(v8::Isolate* isolate, v8::Local<v8::Value> value, IntegerConversio
nConfiguration configuration, ExceptionState& exceptionState) |
273 { | 273 { |
274 return toSmallerInt<int8_t>(isolate, value, configuration, "byte", exception
State); | 274 return toSmallerInt<int8_t>(isolate, value, configuration, "byte", exception
State); |
275 } | 275 } |
276 | 276 |
277 uint8_t toUInt8(v8::Isolate* isolate, v8::Handle<v8::Value> value, IntegerConver
sionConfiguration configuration, ExceptionState& exceptionState) | 277 uint8_t toUInt8(v8::Isolate* isolate, v8::Local<v8::Value> value, IntegerConvers
ionConfiguration configuration, ExceptionState& exceptionState) |
278 { | 278 { |
279 return toSmallerUInt<uint8_t>(isolate, value, configuration, "octet", except
ionState); | 279 return toSmallerUInt<uint8_t>(isolate, value, configuration, "octet", except
ionState); |
280 } | 280 } |
281 | 281 |
282 int16_t toInt16(v8::Isolate* isolate, v8::Handle<v8::Value> value, IntegerConver
sionConfiguration configuration, ExceptionState& exceptionState) | 282 int16_t toInt16(v8::Isolate* isolate, v8::Local<v8::Value> value, IntegerConvers
ionConfiguration configuration, ExceptionState& exceptionState) |
283 { | 283 { |
284 return toSmallerInt<int16_t>(isolate, value, configuration, "short", excepti
onState); | 284 return toSmallerInt<int16_t>(isolate, value, configuration, "short", excepti
onState); |
285 } | 285 } |
286 | 286 |
287 uint16_t toUInt16(v8::Isolate* isolate, v8::Handle<v8::Value> value, IntegerConv
ersionConfiguration configuration, ExceptionState& exceptionState) | 287 uint16_t toUInt16(v8::Isolate* isolate, v8::Local<v8::Value> value, IntegerConve
rsionConfiguration configuration, ExceptionState& exceptionState) |
288 { | 288 { |
289 return toSmallerUInt<uint16_t>(isolate, value, configuration, "unsigned shor
t", exceptionState); | 289 return toSmallerUInt<uint16_t>(isolate, value, configuration, "unsigned shor
t", exceptionState); |
290 } | 290 } |
291 | 291 |
292 int32_t toInt32Slow(v8::Isolate* isolate, v8::Handle<v8::Value> value, IntegerCo
nversionConfiguration configuration, ExceptionState& exceptionState) | 292 int32_t toInt32Slow(v8::Isolate* isolate, v8::Local<v8::Value> value, IntegerCon
versionConfiguration configuration, ExceptionState& exceptionState) |
293 { | 293 { |
294 ASSERT(!value->IsInt32()); | 294 ASSERT(!value->IsInt32()); |
295 // Can the value be converted to a number? | 295 // Can the value be converted to a number? |
296 v8::TryCatch block(isolate); | 296 v8::TryCatch block(isolate); |
297 v8::Local<v8::Number> numberObject; | 297 v8::Local<v8::Number> numberObject; |
298 if (!v8Call(value->ToNumber(isolate->GetCurrentContext()), numberObject, blo
ck)) { | 298 if (!v8Call(value->ToNumber(isolate->GetCurrentContext()), numberObject, blo
ck)) { |
299 exceptionState.rethrowV8Exception(block.Exception()); | 299 exceptionState.rethrowV8Exception(block.Exception()); |
300 return 0; | 300 return 0; |
301 } | 301 } |
302 | 302 |
(...skipping 13 matching lines...) Expand all Loading... |
316 return 0; | 316 return 0; |
317 | 317 |
318 int32_t result; | 318 int32_t result; |
319 if (!v8Call(numberObject->Int32Value(isolate->GetCurrentContext()), result,
block)) { | 319 if (!v8Call(numberObject->Int32Value(isolate->GetCurrentContext()), result,
block)) { |
320 exceptionState.rethrowV8Exception(block.Exception()); | 320 exceptionState.rethrowV8Exception(block.Exception()); |
321 return 0; | 321 return 0; |
322 } | 322 } |
323 return result; | 323 return result; |
324 } | 324 } |
325 | 325 |
326 uint32_t toUInt32Slow(v8::Isolate* isolate, v8::Handle<v8::Value> value, Integer
ConversionConfiguration configuration, ExceptionState& exceptionState) | 326 uint32_t toUInt32Slow(v8::Isolate* isolate, v8::Local<v8::Value> value, IntegerC
onversionConfiguration configuration, ExceptionState& exceptionState) |
327 { | 327 { |
328 ASSERT(!value->IsUint32()); | 328 ASSERT(!value->IsUint32()); |
329 if (value->IsInt32()) { | 329 if (value->IsInt32()) { |
330 ASSERT(configuration != NormalConversion); | 330 ASSERT(configuration != NormalConversion); |
331 int32_t result = value.As<v8::Int32>()->Value(); | 331 int32_t result = value.As<v8::Int32>()->Value(); |
332 if (result >= 0) | 332 if (result >= 0) |
333 return result; | 333 return result; |
334 if (configuration == EnforceRange) { | 334 if (configuration == EnforceRange) { |
335 exceptionState.throwTypeError("Value is outside the 'unsigned long'
value range."); | 335 exceptionState.throwTypeError("Value is outside the 'unsigned long'
value range."); |
336 return 0; | 336 return 0; |
(...skipping 26 matching lines...) Expand all Loading... |
363 return 0; | 363 return 0; |
364 | 364 |
365 uint32_t result; | 365 uint32_t result; |
366 if (!v8Call(numberObject->Uint32Value(isolate->GetCurrentContext()), result,
block)) { | 366 if (!v8Call(numberObject->Uint32Value(isolate->GetCurrentContext()), result,
block)) { |
367 exceptionState.rethrowV8Exception(block.Exception()); | 367 exceptionState.rethrowV8Exception(block.Exception()); |
368 return 0; | 368 return 0; |
369 } | 369 } |
370 return result; | 370 return result; |
371 } | 371 } |
372 | 372 |
373 int64_t toInt64Slow(v8::Isolate* isolate, v8::Handle<v8::Value> value, IntegerCo
nversionConfiguration configuration, ExceptionState& exceptionState) | 373 int64_t toInt64Slow(v8::Isolate* isolate, v8::Local<v8::Value> value, IntegerCon
versionConfiguration configuration, ExceptionState& exceptionState) |
374 { | 374 { |
375 ASSERT(!value->IsInt32()); | 375 ASSERT(!value->IsInt32()); |
376 | 376 |
377 v8::Local<v8::Number> numberObject; | 377 v8::Local<v8::Number> numberObject; |
378 // Can the value be converted to a number? | 378 // Can the value be converted to a number? |
379 v8::TryCatch block(isolate); | 379 v8::TryCatch block(isolate); |
380 if (!v8Call(value->ToNumber(isolate->GetCurrentContext()), numberObject, blo
ck)) { | 380 if (!v8Call(value->ToNumber(isolate->GetCurrentContext()), numberObject, blo
ck)) { |
381 exceptionState.rethrowV8Exception(block.Exception()); | 381 exceptionState.rethrowV8Exception(block.Exception()); |
382 return 0; | 382 return 0; |
383 } | 383 } |
384 ASSERT(!numberObject.IsEmpty()); | 384 ASSERT(!numberObject.IsEmpty()); |
385 | 385 |
386 double numberValue = numberObject->Value(); | 386 double numberValue = numberObject->Value(); |
387 | 387 |
388 if (configuration == EnforceRange) | 388 if (configuration == EnforceRange) |
389 return enforceRange(numberValue, -kJSMaxInteger, kJSMaxInteger, "long lo
ng", exceptionState); | 389 return enforceRange(numberValue, -kJSMaxInteger, kJSMaxInteger, "long lo
ng", exceptionState); |
390 | 390 |
391 if (std::isnan(numberValue) || std::isinf(numberValue)) | 391 if (std::isnan(numberValue) || std::isinf(numberValue)) |
392 return 0; | 392 return 0; |
393 | 393 |
394 // NaNs and +/-Infinity should be 0, otherwise modulo 2^64. | 394 // NaNs and +/-Infinity should be 0, otherwise modulo 2^64. |
395 unsigned long long integer; | 395 unsigned long long integer; |
396 doubleToInteger(numberValue, integer); | 396 doubleToInteger(numberValue, integer); |
397 return integer; | 397 return integer; |
398 } | 398 } |
399 | 399 |
400 uint64_t toUInt64Slow(v8::Isolate* isolate, v8::Handle<v8::Value> value, Integer
ConversionConfiguration configuration, ExceptionState& exceptionState) | 400 uint64_t toUInt64Slow(v8::Isolate* isolate, v8::Local<v8::Value> value, IntegerC
onversionConfiguration configuration, ExceptionState& exceptionState) |
401 { | 401 { |
402 ASSERT(!value->IsUint32()); | 402 ASSERT(!value->IsUint32()); |
403 if (value->IsInt32()) { | 403 if (value->IsInt32()) { |
404 ASSERT(configuration != NormalConversion); | 404 ASSERT(configuration != NormalConversion); |
405 int32_t result = value.As<v8::Int32>()->Value(); | 405 int32_t result = value.As<v8::Int32>()->Value(); |
406 if (result >= 0) | 406 if (result >= 0) |
407 return result; | 407 return result; |
408 if (configuration == EnforceRange) { | 408 if (configuration == EnforceRange) { |
409 exceptionState.throwTypeError("Value is outside the 'unsigned long l
ong' value range."); | 409 exceptionState.throwTypeError("Value is outside the 'unsigned long l
ong' value range."); |
410 return 0; | 410 return 0; |
(...skipping 24 matching lines...) Expand all Loading... |
435 | 435 |
436 if (std::isinf(numberValue)) | 436 if (std::isinf(numberValue)) |
437 return 0; | 437 return 0; |
438 | 438 |
439 // NaNs and +/-Infinity should be 0, otherwise modulo 2^64. | 439 // NaNs and +/-Infinity should be 0, otherwise modulo 2^64. |
440 unsigned long long integer; | 440 unsigned long long integer; |
441 doubleToInteger(numberValue, integer); | 441 doubleToInteger(numberValue, integer); |
442 return integer; | 442 return integer; |
443 } | 443 } |
444 | 444 |
445 float toRestrictedFloat(v8::Isolate* isolate, v8::Handle<v8::Value> value, Excep
tionState& exceptionState) | 445 float toRestrictedFloat(v8::Isolate* isolate, v8::Local<v8::Value> value, Except
ionState& exceptionState) |
446 { | 446 { |
447 float numberValue = toFloat(isolate, value, exceptionState); | 447 float numberValue = toFloat(isolate, value, exceptionState); |
448 if (exceptionState.hadException()) | 448 if (exceptionState.hadException()) |
449 return 0; | 449 return 0; |
450 if (!std::isfinite(numberValue)) { | 450 if (!std::isfinite(numberValue)) { |
451 exceptionState.throwTypeError("The provided float value is non-finite.")
; | 451 exceptionState.throwTypeError("The provided float value is non-finite.")
; |
452 return 0; | 452 return 0; |
453 } | 453 } |
454 return numberValue; | 454 return numberValue; |
455 } | 455 } |
456 | 456 |
457 double toDoubleSlow(v8::Isolate* isolate, v8::Handle<v8::Value> value, Exception
State& exceptionState) | 457 double toDoubleSlow(v8::Isolate* isolate, v8::Local<v8::Value> value, ExceptionS
tate& exceptionState) |
458 { | 458 { |
459 ASSERT(!value->IsNumber()); | 459 ASSERT(!value->IsNumber()); |
460 v8::TryCatch block(isolate); | 460 v8::TryCatch block(isolate); |
461 double doubleValue; | 461 double doubleValue; |
462 if (!v8Call(value->NumberValue(isolate->GetCurrentContext()), doubleValue, b
lock)) { | 462 if (!v8Call(value->NumberValue(isolate->GetCurrentContext()), doubleValue, b
lock)) { |
463 exceptionState.rethrowV8Exception(block.Exception()); | 463 exceptionState.rethrowV8Exception(block.Exception()); |
464 return 0; | 464 return 0; |
465 } | 465 } |
466 return doubleValue; | 466 return doubleValue; |
467 } | 467 } |
468 | 468 |
469 double toRestrictedDouble(v8::Isolate* isolate, v8::Handle<v8::Value> value, Exc
eptionState& exceptionState) | 469 double toRestrictedDouble(v8::Isolate* isolate, v8::Local<v8::Value> value, Exce
ptionState& exceptionState) |
470 { | 470 { |
471 double numberValue = toDouble(isolate, value, exceptionState); | 471 double numberValue = toDouble(isolate, value, exceptionState); |
472 if (exceptionState.hadException()) | 472 if (exceptionState.hadException()) |
473 return 0; | 473 return 0; |
474 if (!std::isfinite(numberValue)) { | 474 if (!std::isfinite(numberValue)) { |
475 exceptionState.throwTypeError("The provided double value is non-finite."
); | 475 exceptionState.throwTypeError("The provided double value is non-finite."
); |
476 return 0; | 476 return 0; |
477 } | 477 } |
478 return numberValue; | 478 return numberValue; |
479 } | 479 } |
480 | 480 |
481 String toByteString(v8::Isolate* isolate, v8::Handle<v8::Value> value, Exception
State& exceptionState) | 481 String toByteString(v8::Isolate* isolate, v8::Local<v8::Value> value, ExceptionS
tate& exceptionState) |
482 { | 482 { |
483 // Handle null default value. | 483 // Handle null default value. |
484 if (value.IsEmpty()) | 484 if (value.IsEmpty()) |
485 return String(); | 485 return String(); |
486 | 486 |
487 // From the Web IDL spec: http://heycam.github.io/webidl/#es-ByteString | 487 // From the Web IDL spec: http://heycam.github.io/webidl/#es-ByteString |
488 if (value.IsEmpty()) | 488 if (value.IsEmpty()) |
489 return String(); | 489 return String(); |
490 | 490 |
491 // 1. Let x be ToString(v) | 491 // 1. Let x be ToString(v) |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 } | 610 } |
611 // 3. Set i to i+1. | 611 // 3. Set i to i+1. |
612 ++i; | 612 ++i; |
613 } | 613 } |
614 | 614 |
615 // 6. Return U. | 615 // 6. Return U. |
616 ASSERT(u.length() == string.length()); | 616 ASSERT(u.length() == string.length()); |
617 return u.toString(); | 617 return u.toString(); |
618 } | 618 } |
619 | 619 |
620 String toUSVString(v8::Isolate* isolate, v8::Handle<v8::Value> value, ExceptionS
tate& exceptionState) | 620 String toUSVString(v8::Isolate* isolate, v8::Local<v8::Value> value, ExceptionSt
ate& exceptionState) |
621 { | 621 { |
622 // http://heycam.github.io/webidl/#es-USVString | 622 // http://heycam.github.io/webidl/#es-USVString |
623 if (value.IsEmpty()) | 623 if (value.IsEmpty()) |
624 return String(); | 624 return String(); |
625 | 625 |
626 v8::Local<v8::String> stringObject; | 626 v8::Local<v8::String> stringObject; |
627 if (value->IsString()) { | 627 if (value->IsString()) { |
628 stringObject = value.As<v8::String>(); | 628 stringObject = value.As<v8::String>(); |
629 } else { | 629 } else { |
630 v8::TryCatch block(isolate); | 630 v8::TryCatch block(isolate); |
631 if (!v8Call(value->ToString(isolate->GetCurrentContext()), stringObject,
block)) { | 631 if (!v8Call(value->ToString(isolate->GetCurrentContext()), stringObject,
block)) { |
632 exceptionState.rethrowV8Exception(block.Exception()); | 632 exceptionState.rethrowV8Exception(block.Exception()); |
633 return String(); | 633 return String(); |
634 } | 634 } |
635 } | 635 } |
636 | 636 |
637 // USVString is identical to DOMString except that "convert a | 637 // USVString is identical to DOMString except that "convert a |
638 // DOMString to a sequence of Unicode characters" is used subsequently | 638 // DOMString to a sequence of Unicode characters" is used subsequently |
639 // when converting to an IDL value | 639 // when converting to an IDL value |
640 String x = toCoreString(stringObject); | 640 String x = toCoreString(stringObject); |
641 return replaceUnmatchedSurrogates(x); | 641 return replaceUnmatchedSurrogates(x); |
642 } | 642 } |
643 | 643 |
644 XPathNSResolver* toXPathNSResolver(ScriptState* scriptState, v8::Handle<v8::Valu
e> value) | 644 XPathNSResolver* toXPathNSResolver(ScriptState* scriptState, v8::Local<v8::Value
> value) |
645 { | 645 { |
646 XPathNSResolver* resolver = nullptr; | 646 XPathNSResolver* resolver = nullptr; |
647 if (V8XPathNSResolver::hasInstance(value, scriptState->isolate())) | 647 if (V8XPathNSResolver::hasInstance(value, scriptState->isolate())) |
648 resolver = V8XPathNSResolver::toImpl(v8::Handle<v8::Object>::Cast(value)
); | 648 resolver = V8XPathNSResolver::toImpl(v8::Local<v8::Object>::Cast(value))
; |
649 else if (value->IsObject()) | 649 else if (value->IsObject()) |
650 resolver = V8CustomXPathNSResolver::create(scriptState, value.As<v8::Obj
ect>()); | 650 resolver = V8CustomXPathNSResolver::create(scriptState, value.As<v8::Obj
ect>()); |
651 return resolver; | 651 return resolver; |
652 } | 652 } |
653 | 653 |
654 DOMWindow* toDOMWindow(v8::Isolate* isolate, v8::Handle<v8::Value> value) | 654 DOMWindow* toDOMWindow(v8::Isolate* isolate, v8::Local<v8::Value> value) |
655 { | 655 { |
656 if (value.IsEmpty() || !value->IsObject()) | 656 if (value.IsEmpty() || !value->IsObject()) |
657 return 0; | 657 return 0; |
658 | 658 |
659 v8::Handle<v8::Object> windowWrapper = V8Window::findInstanceInPrototypeChai
n(v8::Handle<v8::Object>::Cast(value), isolate); | 659 v8::Local<v8::Object> windowWrapper = V8Window::findInstanceInPrototypeChain
(v8::Local<v8::Object>::Cast(value), isolate); |
660 if (!windowWrapper.IsEmpty()) | 660 if (!windowWrapper.IsEmpty()) |
661 return V8Window::toImpl(windowWrapper); | 661 return V8Window::toImpl(windowWrapper); |
662 return 0; | 662 return 0; |
663 } | 663 } |
664 | 664 |
665 DOMWindow* toDOMWindow(v8::Handle<v8::Context> context) | 665 DOMWindow* toDOMWindow(v8::Local<v8::Context> context) |
666 { | 666 { |
667 if (context.IsEmpty()) | 667 if (context.IsEmpty()) |
668 return 0; | 668 return 0; |
669 return toDOMWindow(context->GetIsolate(), context->Global()); | 669 return toDOMWindow(context->GetIsolate(), context->Global()); |
670 } | 670 } |
671 | 671 |
672 LocalDOMWindow* enteredDOMWindow(v8::Isolate* isolate) | 672 LocalDOMWindow* enteredDOMWindow(v8::Isolate* isolate) |
673 { | 673 { |
674 LocalDOMWindow* window = toLocalDOMWindow(toDOMWindow(isolate->GetEnteredCon
text())); | 674 LocalDOMWindow* window = toLocalDOMWindow(toDOMWindow(isolate->GetEnteredCon
text())); |
675 if (!window) { | 675 if (!window) { |
676 // We don't always have an entered DOM window, for example during microt
ask callbacks from V8 | 676 // We don't always have an entered DOM window, for example during microt
ask callbacks from V8 |
677 // (where the entered context may be the DOM-in-JS context). In that cas
e, we fall back | 677 // (where the entered context may be the DOM-in-JS context). In that cas
e, we fall back |
678 // to the current context. | 678 // to the current context. |
679 window = currentDOMWindow(isolate); | 679 window = currentDOMWindow(isolate); |
680 ASSERT(window); | 680 ASSERT(window); |
681 } | 681 } |
682 return window; | 682 return window; |
683 } | 683 } |
684 | 684 |
685 LocalDOMWindow* currentDOMWindow(v8::Isolate* isolate) | 685 LocalDOMWindow* currentDOMWindow(v8::Isolate* isolate) |
686 { | 686 { |
687 return toLocalDOMWindow(toDOMWindow(isolate->GetCurrentContext())); | 687 return toLocalDOMWindow(toDOMWindow(isolate->GetCurrentContext())); |
688 } | 688 } |
689 | 689 |
690 LocalDOMWindow* callingDOMWindow(v8::Isolate* isolate) | 690 LocalDOMWindow* callingDOMWindow(v8::Isolate* isolate) |
691 { | 691 { |
692 v8::Handle<v8::Context> context = isolate->GetCallingContext(); | 692 v8::Local<v8::Context> context = isolate->GetCallingContext(); |
693 if (context.IsEmpty()) { | 693 if (context.IsEmpty()) { |
694 // Unfortunately, when processing script from a plugin, we might not | 694 // Unfortunately, when processing script from a plugin, we might not |
695 // have a calling context. In those cases, we fall back to the | 695 // have a calling context. In those cases, we fall back to the |
696 // entered context. | 696 // entered context. |
697 context = isolate->GetEnteredContext(); | 697 context = isolate->GetEnteredContext(); |
698 } | 698 } |
699 return toLocalDOMWindow(toDOMWindow(context)); | 699 return toLocalDOMWindow(toDOMWindow(context)); |
700 } | 700 } |
701 | 701 |
702 ExecutionContext* toExecutionContext(v8::Handle<v8::Context> context) | 702 ExecutionContext* toExecutionContext(v8::Local<v8::Context> context) |
703 { | 703 { |
704 if (context.IsEmpty()) | 704 if (context.IsEmpty()) |
705 return 0; | 705 return 0; |
706 v8::Handle<v8::Object> global = context->Global(); | 706 v8::Local<v8::Object> global = context->Global(); |
707 v8::Handle<v8::Object> windowWrapper = V8Window::findInstanceInPrototypeChai
n(global, context->GetIsolate()); | 707 v8::Local<v8::Object> windowWrapper = V8Window::findInstanceInPrototypeChain
(global, context->GetIsolate()); |
708 if (!windowWrapper.IsEmpty()) | 708 if (!windowWrapper.IsEmpty()) |
709 return V8Window::toImpl(windowWrapper)->executionContext(); | 709 return V8Window::toImpl(windowWrapper)->executionContext(); |
710 v8::Handle<v8::Object> workerWrapper = V8WorkerGlobalScope::findInstanceInPr
ototypeChain(global, context->GetIsolate()); | 710 v8::Local<v8::Object> workerWrapper = V8WorkerGlobalScope::findInstanceInPro
totypeChain(global, context->GetIsolate()); |
711 if (!workerWrapper.IsEmpty()) | 711 if (!workerWrapper.IsEmpty()) |
712 return V8WorkerGlobalScope::toImpl(workerWrapper)->executionContext(); | 712 return V8WorkerGlobalScope::toImpl(workerWrapper)->executionContext(); |
713 // FIXME: Is this line of code reachable? | 713 // FIXME: Is this line of code reachable? |
714 return 0; | 714 return 0; |
715 } | 715 } |
716 | 716 |
717 ExecutionContext* currentExecutionContext(v8::Isolate* isolate) | 717 ExecutionContext* currentExecutionContext(v8::Isolate* isolate) |
718 { | 718 { |
719 return toExecutionContext(isolate->GetCurrentContext()); | 719 return toExecutionContext(isolate->GetCurrentContext()); |
720 } | 720 } |
721 | 721 |
722 ExecutionContext* callingExecutionContext(v8::Isolate* isolate) | 722 ExecutionContext* callingExecutionContext(v8::Isolate* isolate) |
723 { | 723 { |
724 v8::Handle<v8::Context> context = isolate->GetCallingContext(); | 724 v8::Local<v8::Context> context = isolate->GetCallingContext(); |
725 if (context.IsEmpty()) { | 725 if (context.IsEmpty()) { |
726 // Unfortunately, when processing script from a plugin, we might not | 726 // Unfortunately, when processing script from a plugin, we might not |
727 // have a calling context. In those cases, we fall back to the | 727 // have a calling context. In those cases, we fall back to the |
728 // entered context. | 728 // entered context. |
729 context = isolate->GetEnteredContext(); | 729 context = isolate->GetEnteredContext(); |
730 } | 730 } |
731 return toExecutionContext(context); | 731 return toExecutionContext(context); |
732 } | 732 } |
733 | 733 |
734 Frame* toFrameIfNotDetached(v8::Handle<v8::Context> context) | 734 Frame* toFrameIfNotDetached(v8::Local<v8::Context> context) |
735 { | 735 { |
736 DOMWindow* window = toDOMWindow(context); | 736 DOMWindow* window = toDOMWindow(context); |
737 if (window && window->isCurrentlyDisplayedInFrame()) | 737 if (window && window->isCurrentlyDisplayedInFrame()) |
738 return window->frame(); | 738 return window->frame(); |
739 // We return 0 here because |context| is detached from the Frame. If we | 739 // We return 0 here because |context| is detached from the Frame. If we |
740 // did return |frame| we could get in trouble because the frame could be | 740 // did return |frame| we could get in trouble because the frame could be |
741 // navigated to another security origin. | 741 // navigated to another security origin. |
742 return nullptr; | 742 return nullptr; |
743 } | 743 } |
744 | 744 |
745 EventTarget* toEventTarget(v8::Isolate* isolate, v8::Handle<v8::Value> value) | 745 EventTarget* toEventTarget(v8::Isolate* isolate, v8::Local<v8::Value> value) |
746 { | 746 { |
747 // We need to handle a DOMWindow specially, because a DOMWindow wrapper | 747 // We need to handle a DOMWindow specially, because a DOMWindow wrapper |
748 // exists on a prototype chain of v8Value. | 748 // exists on a prototype chain of v8Value. |
749 if (DOMWindow* window = toDOMWindow(isolate, value)) | 749 if (DOMWindow* window = toDOMWindow(isolate, value)) |
750 return static_cast<EventTarget*>(window); | 750 return static_cast<EventTarget*>(window); |
751 if (V8EventTarget::hasInstance(value, isolate)) { | 751 if (V8EventTarget::hasInstance(value, isolate)) { |
752 v8::Local<v8::Object> object = v8::Handle<v8::Object>::Cast(value); | 752 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(value); |
753 return toWrapperTypeInfo(object)->toEventTarget(object); | 753 return toWrapperTypeInfo(object)->toEventTarget(object); |
754 } | 754 } |
755 return 0; | 755 return 0; |
756 } | 756 } |
757 | 757 |
758 v8::Local<v8::Context> toV8Context(ExecutionContext* context, DOMWrapperWorld& w
orld) | 758 v8::Local<v8::Context> toV8Context(ExecutionContext* context, DOMWrapperWorld& w
orld) |
759 { | 759 { |
760 ASSERT(context); | 760 ASSERT(context); |
761 if (context->isDocument()) { | 761 if (context->isDocument()) { |
762 if (LocalFrame* frame = toDocument(context)->frame()) | 762 if (LocalFrame* frame = toDocument(context)->frame()) |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
800 | 800 |
801 bool isValidEnum(const Vector<String>& values, const char** validValues, size_t
length, const String& enumName, ExceptionState& exceptionState) | 801 bool isValidEnum(const Vector<String>& values, const char** validValues, size_t
length, const String& enumName, ExceptionState& exceptionState) |
802 { | 802 { |
803 for (auto value : values) { | 803 for (auto value : values) { |
804 if (!isValidEnum(value, validValues, length, enumName, exceptionState)) | 804 if (!isValidEnum(value, validValues, length, enumName, exceptionState)) |
805 return false; | 805 return false; |
806 } | 806 } |
807 return true; | 807 return true; |
808 } | 808 } |
809 | 809 |
810 v8::Handle<v8::Function> getBoundFunction(v8::Handle<v8::Function> function) | 810 v8::Local<v8::Function> getBoundFunction(v8::Local<v8::Function> function) |
811 { | 811 { |
812 v8::Handle<v8::Value> boundFunction = function->GetBoundFunction(); | 812 v8::Local<v8::Value> boundFunction = function->GetBoundFunction(); |
813 return boundFunction->IsFunction() ? v8::Handle<v8::Function>::Cast(boundFun
ction) : function; | 813 return boundFunction->IsFunction() ? v8::Local<v8::Function>::Cast(boundFunc
tion) : function; |
814 } | 814 } |
815 | 815 |
816 void addHiddenValueToArray(v8::Isolate* isolate, v8::Handle<v8::Object> object,
v8::Local<v8::Value> value, int arrayIndex) | 816 void addHiddenValueToArray(v8::Isolate* isolate, v8::Local<v8::Object> object, v
8::Local<v8::Value> value, int arrayIndex) |
817 { | 817 { |
818 ASSERT(!value.IsEmpty()); | 818 ASSERT(!value.IsEmpty()); |
819 v8::Local<v8::Value> arrayValue = object->GetInternalField(arrayIndex); | 819 v8::Local<v8::Value> arrayValue = object->GetInternalField(arrayIndex); |
820 if (arrayValue->IsNull() || arrayValue->IsUndefined()) { | 820 if (arrayValue->IsNull() || arrayValue->IsUndefined()) { |
821 arrayValue = v8::Array::New(isolate); | 821 arrayValue = v8::Array::New(isolate); |
822 object->SetInternalField(arrayIndex, arrayValue); | 822 object->SetInternalField(arrayIndex, arrayValue); |
823 } | 823 } |
824 | 824 |
825 v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(arrayValue); | 825 v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(arrayValue); |
826 array->Set(v8::Integer::New(isolate, array->Length()), value); | 826 array->Set(v8::Integer::New(isolate, array->Length()), value); |
827 } | 827 } |
828 | 828 |
829 void removeHiddenValueFromArray(v8::Isolate* isolate, v8::Handle<v8::Object> obj
ect, v8::Local<v8::Value> value, int arrayIndex) | 829 void removeHiddenValueFromArray(v8::Isolate* isolate, v8::Local<v8::Object> obje
ct, v8::Local<v8::Value> value, int arrayIndex) |
830 { | 830 { |
831 v8::Local<v8::Value> arrayValue = object->GetInternalField(arrayIndex); | 831 v8::Local<v8::Value> arrayValue = object->GetInternalField(arrayIndex); |
832 if (!arrayValue->IsArray()) | 832 if (!arrayValue->IsArray()) |
833 return; | 833 return; |
834 v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(arrayValue); | 834 v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(arrayValue); |
835 for (int i = array->Length() - 1; i >= 0; --i) { | 835 for (int i = array->Length() - 1; i >= 0; --i) { |
836 v8::Local<v8::Value> item; | 836 v8::Local<v8::Value> item; |
837 if (!array->Get(isolate->GetCurrentContext(), i).ToLocal(&item)) | 837 if (!array->Get(isolate->GetCurrentContext(), i).ToLocal(&item)) |
838 return; | 838 return; |
839 if (item->StrictEquals(value)) { | 839 if (item->StrictEquals(value)) { |
840 array->Delete(isolate->GetCurrentContext(), i); | 840 array->Delete(isolate->GetCurrentContext(), i); |
841 return; | 841 return; |
842 } | 842 } |
843 } | 843 } |
844 } | 844 } |
845 | 845 |
846 void moveEventListenerToNewWrapper(v8::Isolate* isolate, v8::Handle<v8::Object>
object, EventListener* oldValue, v8::Local<v8::Value> newValue, int arrayIndex) | 846 void moveEventListenerToNewWrapper(v8::Isolate* isolate, v8::Local<v8::Object> o
bject, EventListener* oldValue, v8::Local<v8::Value> newValue, int arrayIndex) |
847 { | 847 { |
848 if (oldValue) { | 848 if (oldValue) { |
849 V8AbstractEventListener* oldListener = V8AbstractEventListener::cast(old
Value); | 849 V8AbstractEventListener* oldListener = V8AbstractEventListener::cast(old
Value); |
850 if (oldListener) { | 850 if (oldListener) { |
851 v8::Local<v8::Object> oldListenerObject = oldListener->getExistingLi
stenerObject(); | 851 v8::Local<v8::Object> oldListenerObject = oldListener->getExistingLi
stenerObject(); |
852 if (!oldListenerObject.IsEmpty()) | 852 if (!oldListenerObject.IsEmpty()) |
853 removeHiddenValueFromArray(isolate, object, oldListenerObject, a
rrayIndex); | 853 removeHiddenValueFromArray(isolate, object, oldListenerObject, a
rrayIndex); |
854 } | 854 } |
855 } | 855 } |
856 // Non-callable input is treated as null and ignored | 856 // Non-callable input is treated as null and ignored |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
933 } | 933 } |
934 ASSERT_NOT_REACHED(); | 934 ASSERT_NOT_REACHED(); |
935 return nullptr; | 935 return nullptr; |
936 } | 936 } |
937 | 937 |
938 void DevToolsFunctionInfo::ensureInitialized() const | 938 void DevToolsFunctionInfo::ensureInitialized() const |
939 { | 939 { |
940 if (m_function.IsEmpty()) | 940 if (m_function.IsEmpty()) |
941 return; | 941 return; |
942 | 942 |
943 v8::Handle<v8::Function> originalFunction = getBoundFunction(m_function); | 943 v8::Local<v8::Function> originalFunction = getBoundFunction(m_function); |
944 m_scriptId = originalFunction->ScriptId(); | 944 m_scriptId = originalFunction->ScriptId(); |
945 v8::ScriptOrigin origin = originalFunction->GetScriptOrigin(); | 945 v8::ScriptOrigin origin = originalFunction->GetScriptOrigin(); |
946 if (!origin.ResourceName().IsEmpty()) { | 946 if (!origin.ResourceName().IsEmpty()) { |
947 V8StringResource<> stringResource(origin.ResourceName()); | 947 V8StringResource<> stringResource(origin.ResourceName()); |
948 stringResource.prepare(); | 948 stringResource.prepare(); |
949 m_resourceName = stringResource; | 949 m_resourceName = stringResource; |
950 m_lineNumber = originalFunction->GetScriptLineNumber() + 1; | 950 m_lineNumber = originalFunction->GetScriptLineNumber() + 1; |
951 } | 951 } |
952 if (m_resourceName.isEmpty()) { | 952 if (m_resourceName.isEmpty()) { |
953 m_resourceName = "undefined"; | 953 m_resourceName = "undefined"; |
(...skipping 14 matching lines...) Expand all Loading... |
968 ensureInitialized(); | 968 ensureInitialized(); |
969 return m_lineNumber; | 969 return m_lineNumber; |
970 } | 970 } |
971 | 971 |
972 String DevToolsFunctionInfo::resourceName() const | 972 String DevToolsFunctionInfo::resourceName() const |
973 { | 973 { |
974 ensureInitialized(); | 974 ensureInitialized(); |
975 return m_resourceName; | 975 return m_resourceName; |
976 } | 976 } |
977 | 977 |
978 PassRefPtr<TraceEvent::ConvertableToTraceFormat> devToolsTraceEventData(v8::Isol
ate* isolate, ExecutionContext* context, v8::Handle<v8::Function> function) | 978 PassRefPtr<TraceEvent::ConvertableToTraceFormat> devToolsTraceEventData(v8::Isol
ate* isolate, ExecutionContext* context, v8::Local<v8::Function> function) |
979 { | 979 { |
980 DevToolsFunctionInfo info(function); | 980 DevToolsFunctionInfo info(function); |
981 return InspectorFunctionCallEvent::data(context, info.scriptId(), info.resou
rceName(), info.lineNumber()); | 981 return InspectorFunctionCallEvent::data(context, info.scriptId(), info.resou
rceName(), info.lineNumber()); |
982 } | 982 } |
983 | 983 |
984 void v8ConstructorAttributeGetter(v8::Local<v8::Name> propertyName, const v8::Pr
opertyCallbackInfo<v8::Value>& info) | 984 void v8ConstructorAttributeGetter(v8::Local<v8::Name> propertyName, const v8::Pr
opertyCallbackInfo<v8::Value>& info) |
985 { | 985 { |
986 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMGetter"); | 986 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMGetter"); |
987 v8::Local<v8::Value> data = info.Data(); | 987 v8::Local<v8::Value> data = info.Data(); |
988 ASSERT(data->IsExternal()); | 988 ASSERT(data->IsExternal()); |
989 V8PerContextData* perContextData = V8PerContextData::from(info.Holder()->Cre
ationContext()); | 989 V8PerContextData* perContextData = V8PerContextData::from(info.Holder()->Cre
ationContext()); |
990 if (!perContextData) | 990 if (!perContextData) |
991 return; | 991 return; |
992 v8SetReturnValue(info, perContextData->constructorForType(WrapperTypeInfo::u
nwrap(data))); | 992 v8SetReturnValue(info, perContextData->constructorForType(WrapperTypeInfo::u
nwrap(data))); |
993 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); | 993 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); |
994 } | 994 } |
995 | 995 |
996 } // namespace blink | 996 } // namespace blink |
OLD | NEW |