Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(395)

Side by Side Diff: Source/bindings/v8/V8Binding.h

Issue 173363002: Move mediastream module to oilpan transition types (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 { 469 {
470 return value; 470 return value;
471 } 471 }
472 }; 472 };
473 473
474 // Converts a JavaScript value to an array as per the Web IDL specification: 474 // Converts a JavaScript value to an array as per the Web IDL specification:
475 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-array 475 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-array
476 template <class T, class V8T> 476 template <class T, class V8T>
477 Vector<RefPtr<T> > toRefPtrNativeArrayUnchecked(v8::Local<v8::Value> v8Value , uint32_t length, v8::Isolate* isolate, bool* success = 0) 477 Vector<RefPtr<T> > toRefPtrNativeArrayUnchecked(v8::Local<v8::Value> v8Value , uint32_t length, v8::Isolate* isolate, bool* success = 0)
478 { 478 {
479 Vector<RefPtr<T> > result; 479 Vector<RefPtr<T> > result;
haraken 2014/02/27 15:32:43 Would you add: if (success) *success = true
480 result.reserveInitialCapacity(length); 480 result.reserveInitialCapacity(length);
481 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); 481 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value);
482 for (uint32_t i = 0; i < length; ++i) { 482 for (uint32_t i = 0; i < length; ++i) {
483 v8::Handle<v8::Value> element = object->Get(i); 483 v8::Handle<v8::Value> element = object->Get(i);
484 484
485 if (V8T::hasInstance(element, isolate)) { 485 if (V8T::hasInstance(element, isolate)) {
486 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::C ast(element); 486 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::C ast(element);
487 result.uncheckedAppend(V8T::toNative(elementObject)); 487 result.uncheckedAppend(V8T::toNative(elementObject));
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 HeapVector<Member<T> > toMemberNativeArrayUnchecked(v8::Local<v8::Value> v8V alue, uint32_t length, v8::Isolate* isolate, bool* success = 0)
500 {
501 HeapVector<Member<T> > result;
haraken 2014/02/27 15:32:43 Ditto.
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 HeapVector<Member<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 HeapVector<Member<T> > toMemberNativeArray(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 HeapVector<Member<T> >();
553 }
554
555 return toMemberNativeArrayUnchecked<T, V8T>(v8Value, length, isolate, su ccess);
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698