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 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
493 } else { | 493 } else { |
494 if (success) | 494 if (success) |
495 *success = false; | 495 *success = false; |
496 throwTypeError("Invalid Array element type", isolate); | 496 throwTypeError("Invalid Array element type", isolate); |
497 return Vector<RefPtr<T> >(); | 497 return Vector<RefPtr<T> >(); |
498 } | 498 } |
499 } | 499 } |
500 return result; | 500 return result; |
501 } | 501 } |
502 | 502 |
503 template <class T, class V8T> | |
504 WillBeHeapVector<RefPtrWillBeMember<T> > toRefPtrWillBeMemberNativeArrayUnch ecked(v8::Local<v8::Value> v8Value, uint32_t length, v8::Isolate* isolate, bool* success = 0) | |
haraken
2014/02/21 10:47:05
Instead of adding a method for WillBeHeapVector<Re
keishi
2014/02/26 06:14:59
If I prepare two versions of toRefPtrNativeArray()
| |
505 { | |
506 WillBeHeapVector<RefPtrWillBeMember<T> > result; | |
507 result.reserveInitialCapacity(length); | |
508 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); | |
509 for (uint32_t i = 0; i < length; ++i) { | |
510 v8::Handle<v8::Value> element = object->Get(i); | |
511 | |
512 if (V8T::hasInstance(element, isolate)) { | |
513 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::C ast(element); | |
514 result.uncheckedAppend(V8T::toNative(elementObject)); | |
515 } else { | |
516 if (success) | |
517 *success = false; | |
518 throwTypeError("Invalid Array element type", isolate); | |
519 return WillBeHeapVector<RefPtrWillBeMember<T> >(); | |
520 } | |
521 } | |
522 return result; | |
523 } | |
524 | |
503 v8::Handle<v8::Value> toV8Sequence(v8::Handle<v8::Value>, uint32_t& length, v8::Isolate*); | 525 v8::Handle<v8::Value> toV8Sequence(v8::Handle<v8::Value>, uint32_t& length, v8::Isolate*); |
504 | 526 |
505 template <class T, class V8T> | 527 template <class T, class V8T> |
506 Vector<RefPtr<T> > toRefPtrNativeArray(v8::Handle<v8::Value> value, int argu mentIndex, v8::Isolate* isolate, bool* success = 0) | 528 Vector<RefPtr<T> > toRefPtrNativeArray(v8::Handle<v8::Value> value, int argu mentIndex, v8::Isolate* isolate, bool* success = 0) |
507 { | 529 { |
508 if (success) | 530 if (success) |
509 *success = true; | 531 *success = true; |
510 | 532 |
511 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); | 533 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); |
512 uint32_t length = 0; | 534 uint32_t length = 0; |
513 if (value->IsArray()) { | 535 if (value->IsArray()) { |
514 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); | 536 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); |
515 } else if (toV8Sequence(value, length, isolate).IsEmpty()) { | 537 } else if (toV8Sequence(value, length, isolate).IsEmpty()) { |
516 throwTypeError(ExceptionMessages::notAnArrayTypeArgumentOrValue(argu mentIndex), isolate); | 538 throwTypeError(ExceptionMessages::notAnArrayTypeArgumentOrValue(argu mentIndex), isolate); |
517 return Vector<RefPtr<T> >(); | 539 return Vector<RefPtr<T> >(); |
518 } | 540 } |
519 | 541 |
520 return toRefPtrNativeArrayUnchecked<T, V8T>(v8Value, length, isolate, su ccess); | 542 return toRefPtrNativeArrayUnchecked<T, V8T>(v8Value, length, isolate, su ccess); |
521 } | 543 } |
522 | 544 |
523 template <class T, class V8T> | 545 template <class T, class V8T> |
546 WillBeHeapVector<RefPtrWillBeMember<T> > toRefPtrWillBeMemberNativeArray(v8: :Handle<v8::Value> value, int argumentIndex, v8::Isolate* isolate, bool* success = 0) | |
haraken
2014/02/21 10:47:05
Ditto. You can add a method for HeapVector<Member>
| |
547 { | |
548 if (success) | |
549 *success = true; | |
550 | |
551 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); | |
552 uint32_t length = 0; | |
553 if (value->IsArray()) { | |
554 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); | |
555 } else if (toV8Sequence(value, length, isolate).IsEmpty()) { | |
556 throwTypeError(ExceptionMessages::notAnArrayTypeArgumentOrValue(argu mentIndex), isolate); | |
557 return WillBeHeapVector<RefPtrWillBeMember<T> >(); | |
558 } | |
559 | |
560 return toRefPtrWillBeMemberNativeArrayUnchecked<T, V8T>(v8Value, length, isolate, success); | |
561 } | |
562 | |
563 template <class T, class V8T> | |
524 Vector<RefPtr<T> > toRefPtrNativeArray(v8::Handle<v8::Value> value, const St ring& propertyName, v8::Isolate* isolate, bool* success = 0) | 564 Vector<RefPtr<T> > toRefPtrNativeArray(v8::Handle<v8::Value> value, const St ring& propertyName, v8::Isolate* isolate, bool* success = 0) |
525 { | 565 { |
526 if (success) | 566 if (success) |
527 *success = true; | 567 *success = true; |
528 | 568 |
529 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); | 569 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); |
530 uint32_t length = 0; | 570 uint32_t length = 0; |
531 if (value->IsArray()) { | 571 if (value->IsArray()) { |
532 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); | 572 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); |
533 } else if (toV8Sequence(value, length, isolate).IsEmpty()) { | 573 } else if (toV8Sequence(value, length, isolate).IsEmpty()) { |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
715 m_isolate->ClearInterrupt(); | 755 m_isolate->ClearInterrupt(); |
716 } | 756 } |
717 | 757 |
718 private: | 758 private: |
719 v8::Isolate* m_isolate; | 759 v8::Isolate* m_isolate; |
720 }; | 760 }; |
721 | 761 |
722 } // namespace WebCore | 762 } // namespace WebCore |
723 | 763 |
724 #endif // V8Binding_h | 764 #endif // V8Binding_h |
OLD | NEW |