| 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 743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 } else { | 754 } else { |
| 755 exceptionState.throwTypeError("Invalid Array element type"); | 755 exceptionState.throwTypeError("Invalid Array element type"); |
| 756 return VectorType(); | 756 return VectorType(); |
| 757 } | 757 } |
| 758 } | 758 } |
| 759 return result; | 759 return result; |
| 760 } | 760 } |
| 761 | 761 |
| 762 // Converts a JavaScript value to an array as per the Web IDL specification: | 762 // Converts a JavaScript value to an array as per the Web IDL specification: |
| 763 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-array | 763 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-array |
| 764 template <typename VectorType> | 764 template <typename VectorType, |
| 765 typename ValueType = typename VectorType::ValueType> |
| 765 VectorType toImplArray(v8::Local<v8::Value> value, | 766 VectorType toImplArray(v8::Local<v8::Value> value, |
| 766 int argumentIndex, | 767 int argumentIndex, |
| 767 v8::Isolate* isolate, | 768 v8::Isolate* isolate, |
| 768 ExceptionState& exceptionState) { | 769 ExceptionState& exceptionState) { |
| 769 typedef typename VectorType::ValueType ValueType; | |
| 770 typedef NativeValueTraits<ValueType> TraitsType; | 770 typedef NativeValueTraits<ValueType> TraitsType; |
| 771 | 771 |
| 772 uint32_t length = 0; | 772 uint32_t length = 0; |
| 773 if (value->IsArray()) { | 773 if (value->IsArray()) { |
| 774 length = v8::Local<v8::Array>::Cast(value)->Length(); | 774 length = v8::Local<v8::Array>::Cast(value)->Length(); |
| 775 } else if (!toV8Sequence(value, length, isolate, exceptionState)) { | 775 } else if (!toV8Sequence(value, length, isolate, exceptionState)) { |
| 776 if (!exceptionState.hadException()) | 776 if (!exceptionState.hadException()) |
| 777 exceptionState.throwTypeError( | 777 exceptionState.throwTypeError( |
| 778 ExceptionMessages::notAnArrayTypeArgumentOrValue(argumentIndex)); | 778 ExceptionMessages::notAnArrayTypeArgumentOrValue(argumentIndex)); |
| 779 return VectorType(); | 779 return VectorType(); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 896 if (!v8Call(lengthValue->Uint32Value(isolate->GetCurrentContext()), | 896 if (!v8Call(lengthValue->Uint32Value(isolate->GetCurrentContext()), |
| 897 sequenceLength, block)) { | 897 sequenceLength, block)) { |
| 898 exceptionState.rethrowV8Exception(block.Exception()); | 898 exceptionState.rethrowV8Exception(block.Exception()); |
| 899 return false; | 899 return false; |
| 900 } | 900 } |
| 901 | 901 |
| 902 length = sequenceLength; | 902 length = sequenceLength; |
| 903 return true; | 903 return true; |
| 904 } | 904 } |
| 905 | 905 |
| 906 // TODO(rakuco): remove the specializations below (and consequently the |
| 907 // non-IDLBase version of NativeValueTraitsBase) once we manage to convert all |
| 908 // uses of NativeValueTraits to types that derive from IDLBase or for generated |
| 909 // IDL interfaces/dictionaries/unions. |
| 906 template <> | 910 template <> |
| 907 struct NativeValueTraits<String> { | 911 struct NativeValueTraits<String> { |
| 908 static inline String nativeValue(v8::Isolate* isolate, | 912 static inline String nativeValue(v8::Isolate* isolate, |
| 909 v8::Local<v8::Value> value, | 913 v8::Local<v8::Value> value, |
| 910 ExceptionState& exceptionState) { | 914 ExceptionState& exceptionState) { |
| 911 V8StringResource<> stringValue(value); | 915 V8StringResource<> stringValue(value); |
| 912 if (!stringValue.prepare(exceptionState)) | 916 if (!stringValue.prepare(exceptionState)) |
| 913 return String(); | 917 return String(); |
| 914 return stringValue; | 918 return stringValue; |
| 915 } | 919 } |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1160 // If the argument isn't an object, this will crash. | 1164 // If the argument isn't an object, this will crash. |
| 1161 CORE_EXPORT v8::Local<v8::Value> freezeV8Object(v8::Local<v8::Value>, | 1165 CORE_EXPORT v8::Local<v8::Value> freezeV8Object(v8::Local<v8::Value>, |
| 1162 v8::Isolate*); | 1166 v8::Isolate*); |
| 1163 | 1167 |
| 1164 CORE_EXPORT v8::Local<v8::Value> fromJSONString(v8::Isolate*, | 1168 CORE_EXPORT v8::Local<v8::Value> fromJSONString(v8::Isolate*, |
| 1165 const String& stringifiedJSON, | 1169 const String& stringifiedJSON, |
| 1166 ExceptionState&); | 1170 ExceptionState&); |
| 1167 } // namespace blink | 1171 } // namespace blink |
| 1168 | 1172 |
| 1169 #endif // V8Binding_h | 1173 #endif // V8Binding_h |
| OLD | NEW |