| 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 453 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  464 }; |  464 }; | 
|  465  |  465  | 
|  466 template<> |  466 template<> | 
|  467 struct NativeValueTraits<v8::Handle<v8::Value> > { |  467 struct NativeValueTraits<v8::Handle<v8::Value> > { | 
|  468     static inline v8::Handle<v8::Value> nativeValue(const v8::Handle<v8::Value>&
      value, v8::Isolate* isolate) |  468     static inline v8::Handle<v8::Value> nativeValue(const v8::Handle<v8::Value>&
      value, v8::Isolate* isolate) | 
|  469     { |  469     { | 
|  470         return value; |  470         return value; | 
|  471     } |  471     } | 
|  472 }; |  472 }; | 
|  473  |  473  | 
 |  474 v8::Handle<v8::Value> toV8Sequence(v8::Handle<v8::Value>, uint32_t& length, v8::
     Isolate*); | 
 |  475  | 
|  474 // Converts a JavaScript value to an array as per the Web IDL specification: |  476 // 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 |  477 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-array | 
|  476 template <class T, class V8T> |  478 template <class T, class V8T> | 
|  477 Vector<RefPtr<T> > toRefPtrNativeArrayUnchecked(v8::Local<v8::Value> v8Value, ui
     nt32_t length, v8::Isolate* isolate, bool* success = 0) |  479 Vector<RefPtr<T> > toRefPtrNativeArrayUnchecked(v8::Local<v8::Value> v8Value, ui
     nt32_t length, v8::Isolate* isolate, bool* success = 0) | 
|  478 { |  480 { | 
|  479     Vector<RefPtr<T> > result; |  481     Vector<RefPtr<T> > result; | 
|  480     result.reserveInitialCapacity(length); |  482     result.reserveInitialCapacity(length); | 
|  481     v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); |  483     v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); | 
|  482     for (uint32_t i = 0; i < length; ++i) { |  484     for (uint32_t i = 0; i < length; ++i) { | 
|  483         v8::Handle<v8::Value> element = object->Get(i); |  485         v8::Handle<v8::Value> element = object->Get(i); | 
|  484         if (V8T::hasInstance(element, isolate)) { |  486         if (V8T::hasInstance(element, isolate)) { | 
|  485             v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::Cast(
     element); |  487             v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::Cast(
     element); | 
|  486             result.uncheckedAppend(V8T::toNative(elementObject)); |  488             result.uncheckedAppend(V8T::toNative(elementObject)); | 
|  487         } else { |  489         } else { | 
|  488             if (success) |  490             if (success) | 
|  489                 *success = false; |  491                 *success = false; | 
|  490             throwTypeError("Invalid Array element type", isolate); |  492             throwTypeError("Invalid Array element type", isolate); | 
|  491             return Vector<RefPtr<T> >(); |  493             return Vector<RefPtr<T> >(); | 
|  492         } |  494         } | 
|  493     } |  495     } | 
|  494     return result; |  496     return result; | 
|  495 } |  497 } | 
|  496  |  498  | 
|  497 v8::Handle<v8::Value> toV8Sequence(v8::Handle<v8::Value>, uint32_t& length, v8::
     Isolate*); |  | 
|  498  |  | 
|  499 template <class T, class V8T> |  499 template <class T, class V8T> | 
|  500 Vector<RefPtr<T> > toRefPtrNativeArray(v8::Handle<v8::Value> value, int argument
     Index, v8::Isolate* isolate, bool* success = 0) |  500 Vector<RefPtr<T> > toRefPtrNativeArray(v8::Handle<v8::Value> value, int argument
     Index, v8::Isolate* isolate, bool* success = 0) | 
|  501 { |  501 { | 
|  502     if (success) |  502     if (success) | 
|  503         *success = true; |  503         *success = true; | 
|  504  |  504  | 
|  505     v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); |  505     v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); | 
|  506     uint32_t length = 0; |  506     uint32_t length = 0; | 
|  507     if (value->IsArray()) { |  507     if (value->IsArray()) { | 
|  508         length = v8::Local<v8::Array>::Cast(v8Value)->Length(); |  508         length = v8::Local<v8::Array>::Cast(v8Value)->Length(); | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
|  523     uint32_t length = 0; |  523     uint32_t length = 0; | 
|  524     if (value->IsArray()) { |  524     if (value->IsArray()) { | 
|  525         length = v8::Local<v8::Array>::Cast(v8Value)->Length(); |  525         length = v8::Local<v8::Array>::Cast(v8Value)->Length(); | 
|  526     } else if (toV8Sequence(value, length, isolate).IsEmpty()) { |  526     } else if (toV8Sequence(value, length, isolate).IsEmpty()) { | 
|  527         throwTypeError(ExceptionMessages::notASequenceTypeProperty(propertyName)
     , isolate); |  527         throwTypeError(ExceptionMessages::notASequenceTypeProperty(propertyName)
     , isolate); | 
|  528         return Vector<RefPtr<T> >(); |  528         return Vector<RefPtr<T> >(); | 
|  529     } |  529     } | 
|  530     return toRefPtrNativeArrayUnchecked<T, V8T>(v8Value, length, isolate, succes
     s); |  530     return toRefPtrNativeArrayUnchecked<T, V8T>(v8Value, length, isolate, succes
     s); | 
|  531 } |  531 } | 
|  532  |  532  | 
 |  533 template <class T, class V8T> | 
 |  534 HeapVector<Member<T> > toMemberNativeArray(v8::Handle<v8::Value> value, int argu
     mentIndex, v8::Isolate* isolate, bool* success = 0) | 
 |  535 { | 
 |  536     if (success) | 
 |  537         *success = true; | 
 |  538  | 
 |  539     v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); | 
 |  540     uint32_t length = 0; | 
 |  541     if (value->IsArray()) { | 
 |  542         length = v8::Local<v8::Array>::Cast(v8Value)->Length(); | 
 |  543     } else if (toV8Sequence(value, length, isolate).IsEmpty()) { | 
 |  544         throwTypeError(ExceptionMessages::notAnArrayTypeArgumentOrValue(argument
     Index), isolate); | 
 |  545         return HeapVector<Member<T> >(); | 
 |  546     } | 
 |  547  | 
 |  548     HeapVector<Member<T> > result; | 
 |  549     result.reserveInitialCapacity(length); | 
 |  550     v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); | 
 |  551     for (uint32_t i = 0; i < length; ++i) { | 
 |  552         v8::Handle<v8::Value> element = object->Get(i); | 
 |  553         if (V8T::hasInstance(element, isolate)) { | 
 |  554             v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::Cast(
     element); | 
 |  555             result.uncheckedAppend(V8T::toNative(elementObject)); | 
 |  556         } else { | 
 |  557             if (success) | 
 |  558                 *success = false; | 
 |  559             throwTypeError("Invalid Array element type", isolate); | 
 |  560             return HeapVector<Member<T> >(); | 
 |  561         } | 
 |  562     } | 
 |  563     return result; | 
 |  564 } | 
 |  565  | 
|  533 // Converts a JavaScript value to an array as per the Web IDL specification: |  566 // Converts a JavaScript value to an array as per the Web IDL specification: | 
|  534 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-array |  567 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-array | 
|  535 template <class T> |  568 template <class T> | 
|  536 Vector<T> toNativeArray(v8::Handle<v8::Value> value, int argumentIndex, v8::Isol
     ate* isolate) |  569 Vector<T> toNativeArray(v8::Handle<v8::Value> value, int argumentIndex, v8::Isol
     ate* isolate) | 
|  537 { |  570 { | 
|  538     v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); |  571     v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); | 
|  539     uint32_t length = 0; |  572     uint32_t length = 0; | 
|  540     if (value->IsArray()) { |  573     if (value->IsArray()) { | 
|  541         length = v8::Local<v8::Array>::Cast(v8Value)->Length(); |  574         length = v8::Local<v8::Array>::Cast(v8Value)->Length(); | 
|  542     } else if (toV8Sequence(value, length, isolate).IsEmpty()) { |  575     } else if (toV8Sequence(value, length, isolate).IsEmpty()) { | 
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  720     v8::HandleScope m_handleScope; |  753     v8::HandleScope m_handleScope; | 
|  721     v8::Handle<v8::Context> m_context; |  754     v8::Handle<v8::Context> m_context; | 
|  722     v8::Context::Scope m_contextScope; |  755     v8::Context::Scope m_contextScope; | 
|  723     RefPtr<DOMWrapperWorld> m_world; |  756     RefPtr<DOMWrapperWorld> m_world; | 
|  724     OwnPtr<V8PerContextData> m_perContextData; |  757     OwnPtr<V8PerContextData> m_perContextData; | 
|  725 }; |  758 }; | 
|  726  |  759  | 
|  727 } // namespace WebCore |  760 } // namespace WebCore | 
|  728  |  761  | 
|  729 #endif // V8Binding_h |  762 #endif // V8Binding_h | 
| OLD | NEW |