OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * Copyright (C) 2012 Ericsson AB. All rights reserved. | 3 * Copyright (C) 2012 Ericsson AB. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 } else { | 488 } else { |
489 if (success) | 489 if (success) |
490 *success = false; | 490 *success = false; |
491 throwTypeError("Invalid Array element type", isolate); | 491 throwTypeError("Invalid Array element type", isolate); |
492 return Vector<RefPtr<T> >(); | 492 return Vector<RefPtr<T> >(); |
493 } | 493 } |
494 } | 494 } |
495 return result; | 495 return result; |
496 } | 496 } |
497 | 497 |
| 498 template <class T, class V8T> |
| 499 WillBeHeapVector<RefPtrWillBeMember<T> > toRefPtrWillBeMemberNativeArrayUnch
ecked(v8::Local<v8::Value> v8Value, uint32_t length, v8::Isolate* isolate, bool*
success = 0) |
| 500 { |
| 501 WillBeHeapVector<RefPtrWillBeMember<T> > result; |
| 502 result.reserveInitialCapacity(length); |
| 503 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); |
| 504 for (uint32_t i = 0; i < length; ++i) { |
| 505 v8::Handle<v8::Value> element = object->Get(i); |
| 506 |
| 507 if (V8T::hasInstance(element, isolate)) { |
| 508 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::C
ast(element); |
| 509 result.uncheckedAppend(V8T::toNative(elementObject)); |
| 510 } else { |
| 511 if (success) |
| 512 *success = false; |
| 513 throwTypeError("Invalid Array element type", isolate); |
| 514 return WillBeHeapVector<RefPtrWillBeMember<T> >(); |
| 515 } |
| 516 } |
| 517 return result; |
| 518 } |
| 519 |
498 v8::Handle<v8::Value> toV8Sequence(v8::Handle<v8::Value>, uint32_t& length,
v8::Isolate*); | 520 v8::Handle<v8::Value> toV8Sequence(v8::Handle<v8::Value>, uint32_t& length,
v8::Isolate*); |
499 | 521 |
500 template <class T, class V8T> | 522 template <class T, class V8T> |
501 Vector<RefPtr<T> > toRefPtrNativeArray(v8::Handle<v8::Value> value, int argu
mentIndex, v8::Isolate* isolate, bool* success = 0) | 523 Vector<RefPtr<T> > toRefPtrNativeArray(v8::Handle<v8::Value> value, int argu
mentIndex, v8::Isolate* isolate, bool* success = 0) |
502 { | 524 { |
503 if (success) | 525 if (success) |
504 *success = true; | 526 *success = true; |
505 | 527 |
506 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); | 528 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); |
507 uint32_t length = 0; | 529 uint32_t length = 0; |
508 if (value->IsArray()) { | 530 if (value->IsArray()) { |
509 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); | 531 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); |
510 } else if (toV8Sequence(value, length, isolate).IsEmpty()) { | 532 } else if (toV8Sequence(value, length, isolate).IsEmpty()) { |
511 throwTypeError(ExceptionMessages::notAnArrayTypeArgumentOrValue(argu
mentIndex), isolate); | 533 throwTypeError(ExceptionMessages::notAnArrayTypeArgumentOrValue(argu
mentIndex), isolate); |
512 return Vector<RefPtr<T> >(); | 534 return Vector<RefPtr<T> >(); |
513 } | 535 } |
514 | 536 |
515 return toRefPtrNativeArrayUnchecked<T, V8T>(v8Value, length, isolate, su
ccess); | 537 return toRefPtrNativeArrayUnchecked<T, V8T>(v8Value, length, isolate, su
ccess); |
516 } | 538 } |
517 | 539 |
518 template <class T, class V8T> | 540 template <class T, class V8T> |
| 541 WillBeHeapVector<RefPtrWillBeMember<T> > toRefPtrWillBeMemberNativeArray(v8:
:Handle<v8::Value> value, int argumentIndex, v8::Isolate* isolate, bool* success
= 0) |
| 542 { |
| 543 if (success) |
| 544 *success = true; |
| 545 |
| 546 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); |
| 547 uint32_t length = 0; |
| 548 if (value->IsArray()) { |
| 549 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); |
| 550 } else if (toV8Sequence(value, length, isolate).IsEmpty()) { |
| 551 throwTypeError(ExceptionMessages::notAnArrayTypeArgumentOrValue(argu
mentIndex), isolate); |
| 552 return WillBeHeapVector<RefPtrWillBeMember<T> >(); |
| 553 } |
| 554 |
| 555 return toRefPtrWillBeMemberNativeArrayUnchecked<T, V8T>(v8Value, length,
isolate, success); |
| 556 } |
| 557 |
| 558 template <class T, class V8T> |
519 Vector<RefPtr<T> > toRefPtrNativeArray(v8::Handle<v8::Value> value, const St
ring& propertyName, v8::Isolate* isolate, bool* success = 0) | 559 Vector<RefPtr<T> > toRefPtrNativeArray(v8::Handle<v8::Value> value, const St
ring& propertyName, v8::Isolate* isolate, bool* success = 0) |
520 { | 560 { |
521 if (success) | 561 if (success) |
522 *success = true; | 562 *success = true; |
523 | 563 |
524 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); | 564 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); |
525 uint32_t length = 0; | 565 uint32_t length = 0; |
526 if (value->IsArray()) { | 566 if (value->IsArray()) { |
527 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); | 567 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); |
528 } else if (toV8Sequence(value, length, isolate).IsEmpty()) { | 568 } else if (toV8Sequence(value, length, isolate).IsEmpty()) { |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 m_isolate->ClearInterrupt(); | 750 m_isolate->ClearInterrupt(); |
711 } | 751 } |
712 | 752 |
713 private: | 753 private: |
714 v8::Isolate* m_isolate; | 754 v8::Isolate* m_isolate; |
715 }; | 755 }; |
716 | 756 |
717 } // namespace WebCore | 757 } // namespace WebCore |
718 | 758 |
719 #endif // V8Binding_h | 759 #endif // V8Binding_h |
OLD | NEW |