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

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

Issue 74533003: Add Perl IDL support for method parameter type sequence<Dictionary> (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Review changes Created 7 years, 1 month 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
« no previous file with comments | « Source/bindings/v8/Dictionary.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 15 matching lines...) Expand all
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32 #ifndef V8Binding_h 32 #ifndef V8Binding_h
33 #define V8Binding_h 33 #define V8Binding_h
34 34
35 #include "bindings/v8/DOMWrapperWorld.h" 35 #include "bindings/v8/DOMWrapperWorld.h"
36 #include "bindings/v8/Dictionary.h"
36 #include "bindings/v8/ExceptionMessages.h" 37 #include "bindings/v8/ExceptionMessages.h"
37 #include "bindings/v8/V8BindingMacros.h" 38 #include "bindings/v8/V8BindingMacros.h"
38 #include "bindings/v8/V8PerIsolateData.h" 39 #include "bindings/v8/V8PerIsolateData.h"
39 #include "bindings/v8/V8StringResource.h" 40 #include "bindings/v8/V8StringResource.h"
40 #include "bindings/v8/V8ThrowException.h" 41 #include "bindings/v8/V8ThrowException.h"
41 #include "bindings/v8/V8ValueCache.h" 42 #include "bindings/v8/V8ValueCache.h"
42 #include "wtf/MathExtras.h" 43 #include "wtf/MathExtras.h"
43 #include "wtf/text/AtomicString.h" 44 #include "wtf/text/AtomicString.h"
44 #include <v8.h> 45 #include <v8.h>
45 46
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 424
424 WrapperWorldType worldType(v8::Isolate*); 425 WrapperWorldType worldType(v8::Isolate*);
425 WrapperWorldType worldTypeInMainThread(v8::Isolate*); 426 WrapperWorldType worldTypeInMainThread(v8::Isolate*);
426 427
427 DOMWrapperWorld* isolatedWorldForIsolate(v8::Isolate*); 428 DOMWrapperWorld* isolatedWorldForIsolate(v8::Isolate*);
428 429
429 template<class T> struct NativeValueTraits; 430 template<class T> struct NativeValueTraits;
430 431
431 template<> 432 template<>
432 struct NativeValueTraits<String> { 433 struct NativeValueTraits<String> {
433 static inline String nativeValue(const v8::Handle<v8::Value>& value) 434 static inline String nativeValue(const v8::Handle<v8::Value>& value, v8: :Isolate* isolate)
434 { 435 {
435 V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<>, stringVal ue, value, String()); 436 V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<>, stringVal ue, value, String());
436 return stringValue; 437 return stringValue;
437 } 438 }
438 }; 439 };
439 440
440 template<> 441 template<>
441 struct NativeValueTraits<unsigned> { 442 struct NativeValueTraits<unsigned> {
442 static inline unsigned nativeValue(const v8::Handle<v8::Value>& value) 443 static inline unsigned nativeValue(const v8::Handle<v8::Value>& value, v 8::Isolate* isolate)
443 { 444 {
444 return toUInt32(value); 445 return toUInt32(value);
445 } 446 }
446 }; 447 };
447 448
448 template<> 449 template<>
449 struct NativeValueTraits<float> { 450 struct NativeValueTraits<float> {
450 static inline float nativeValue(const v8::Handle<v8::Value>& value) 451 static inline float nativeValue(const v8::Handle<v8::Value>& value, v8:: Isolate* isolate)
451 { 452 {
452 return static_cast<float>(value->NumberValue()); 453 return static_cast<float>(value->NumberValue());
453 } 454 }
454 }; 455 };
455 456
456 template<> 457 template<>
457 struct NativeValueTraits<double> { 458 struct NativeValueTraits<double> {
458 static inline double nativeValue(const v8::Handle<v8::Value>& value) 459 static inline double nativeValue(const v8::Handle<v8::Value>& value, v8: :Isolate* isolate)
459 { 460 {
460 return static_cast<double>(value->NumberValue()); 461 return static_cast<double>(value->NumberValue());
461 } 462 }
462 }; 463 };
463 464
464 template<> 465 template<>
465 struct NativeValueTraits<v8::Handle<v8::Value> > { 466 struct NativeValueTraits<v8::Handle<v8::Value> > {
466 static inline v8::Handle<v8::Value> nativeValue(const v8::Handle<v8::Val ue>& value) 467 static inline v8::Handle<v8::Value> nativeValue(const v8::Handle<v8::Val ue>& value, v8::Isolate* isolate)
467 { 468 {
468 return value; 469 return value;
469 } 470 }
470 }; 471 };
471 472
473 template<>
474 struct NativeValueTraits<Dictionary> {
475 static inline Dictionary nativeValue(const v8::Handle<v8::Value>& value, v8::Isolate* isolate)
476 {
477 return Dictionary(value, isolate);
478 }
479 };
480
472 // Converts a JavaScript value to an array as per the Web IDL specification: 481 // Converts a JavaScript value to an array as per the Web IDL specification:
473 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-array 482 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-array
474 template <class T, class V8T> 483 template <class T, class V8T>
475 Vector<RefPtr<T> > toRefPtrNativeArrayUnchecked(v8::Local<v8::Value> v8Value , uint32_t length, v8::Isolate* isolate, bool* success = 0) 484 Vector<RefPtr<T> > toRefPtrNativeArrayUnchecked(v8::Local<v8::Value> v8Value , uint32_t length, v8::Isolate* isolate, bool* success = 0)
476 { 485 {
477 Vector<RefPtr<T> > result; 486 Vector<RefPtr<T> > result;
478 result.reserveInitialCapacity(length); 487 result.reserveInitialCapacity(length);
479 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); 488 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value);
480 for (uint32_t i = 0; i < length; ++i) { 489 for (uint32_t i = 0; i < length; ++i) {
481 v8::Handle<v8::Value> element = object->Get(i); 490 v8::Handle<v8::Value> element = object->Get(i);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 } else if (toV8Sequence(value, length, isolate).IsEmpty()) { 550 } else if (toV8Sequence(value, length, isolate).IsEmpty()) {
542 throwTypeError(ExceptionMessages::notAnArrayTypeArgumentOrValue(argu mentIndex), isolate); 551 throwTypeError(ExceptionMessages::notAnArrayTypeArgumentOrValue(argu mentIndex), isolate);
543 return Vector<T>(); 552 return Vector<T>();
544 } 553 }
545 554
546 Vector<T> result; 555 Vector<T> result;
547 result.reserveInitialCapacity(length); 556 result.reserveInitialCapacity(length);
548 typedef NativeValueTraits<T> TraitsType; 557 typedef NativeValueTraits<T> TraitsType;
549 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); 558 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value);
550 for (uint32_t i = 0; i < length; ++i) 559 for (uint32_t i = 0; i < length; ++i)
551 result.uncheckedAppend(TraitsType::nativeValue(object->Get(i))); 560 result.uncheckedAppend(TraitsType::nativeValue(object->Get(i), isola te));
552 return result; 561 return result;
553 } 562 }
554 563
555 template <class T> 564 template <class T>
556 Vector<T> toNativeArguments(const v8::FunctionCallbackInfo<v8::Value>& info, int startIndex) 565 Vector<T> toNativeArguments(const v8::FunctionCallbackInfo<v8::Value>& info, int startIndex)
557 { 566 {
558 ASSERT(startIndex <= info.Length()); 567 ASSERT(startIndex <= info.Length());
559 Vector<T> result; 568 Vector<T> result;
560 typedef NativeValueTraits<T> TraitsType; 569 typedef NativeValueTraits<T> TraitsType;
561 int length = info.Length(); 570 int length = info.Length();
562 result.reserveInitialCapacity(length); 571 result.reserveInitialCapacity(length);
563 for (int i = startIndex; i < length; ++i) 572 for (int i = startIndex; i < length; ++i)
564 result.uncheckedAppend(TraitsType::nativeValue(info[i])); 573 result.uncheckedAppend(TraitsType::nativeValue(info[i], info.GetIsol ate()));
565 return result; 574 return result;
566 } 575 }
567 576
568 // Validates that the passed object is a sequence type per WebIDL spec 577 // Validates that the passed object is a sequence type per WebIDL spec
569 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-sequence 578 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-sequence
570 inline v8::Handle<v8::Value> toV8Sequence(v8::Handle<v8::Value> value, uint3 2_t& length, v8::Isolate* isolate) 579 inline v8::Handle<v8::Value> toV8Sequence(v8::Handle<v8::Value> value, uint3 2_t& length, v8::Isolate* isolate)
571 { 580 {
572 // Attempt converting to a sequence if the value is not already an array but is 581 // Attempt converting to a sequence if the value is not already an array but is
573 // any kind of object except for a native Date object or a native RegExp object. 582 // any kind of object except for a native Date object or a native RegExp object.
574 ASSERT(!value->IsArray()); 583 ASSERT(!value->IsArray());
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 721
713 v8::Isolate* mainThreadIsolate(); 722 v8::Isolate* mainThreadIsolate();
714 v8::Isolate* toIsolate(ExecutionContext*); 723 v8::Isolate* toIsolate(ExecutionContext*);
715 v8::Isolate* toIsolate(Frame*); 724 v8::Isolate* toIsolate(Frame*);
716 725
717 // Can only be called by blink::initialize 726 // Can only be called by blink::initialize
718 void setMainThreadIsolate(v8::Isolate*); 727 void setMainThreadIsolate(v8::Isolate*);
719 } // namespace WebCore 728 } // namespace WebCore
720 729
721 #endif // V8Binding_h 730 #endif // V8Binding_h
OLDNEW
« no previous file with comments | « Source/bindings/v8/Dictionary.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698