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 22 matching lines...) Expand all Loading... | |
33 #define V8Binding_h | 33 #define V8Binding_h |
34 | 34 |
35 #include "bindings/core/v8/DOMDataStore.h" | 35 #include "bindings/core/v8/DOMDataStore.h" |
36 #include "bindings/core/v8/DOMWrapperWorld.h" | 36 #include "bindings/core/v8/DOMWrapperWorld.h" |
37 #include "bindings/core/v8/ExceptionMessages.h" | 37 #include "bindings/core/v8/ExceptionMessages.h" |
38 #include "bindings/core/v8/ExceptionState.h" | 38 #include "bindings/core/v8/ExceptionState.h" |
39 #include "bindings/core/v8/NativeValueTraits.h" | 39 #include "bindings/core/v8/NativeValueTraits.h" |
40 #include "bindings/core/v8/ScriptState.h" | 40 #include "bindings/core/v8/ScriptState.h" |
41 #include "bindings/core/v8/ScriptValue.h" | 41 #include "bindings/core/v8/ScriptValue.h" |
42 #include "bindings/core/v8/ScriptWrappable.h" | 42 #include "bindings/core/v8/ScriptWrappable.h" |
43 #include "bindings/core/v8/SerializedScriptValue.h" | |
43 #include "bindings/core/v8/V8BindingMacros.h" | 44 #include "bindings/core/v8/V8BindingMacros.h" |
44 #include "bindings/core/v8/V8PerIsolateData.h" | 45 #include "bindings/core/v8/V8PerIsolateData.h" |
45 #include "bindings/core/v8/V8ScriptRunner.h" | 46 #include "bindings/core/v8/V8ScriptRunner.h" |
46 #include "bindings/core/v8/V8StringResource.h" | 47 #include "bindings/core/v8/V8StringResource.h" |
47 #include "bindings/core/v8/V8ThrowException.h" | 48 #include "bindings/core/v8/V8ThrowException.h" |
48 #include "bindings/core/v8/V8ValueCache.h" | 49 #include "bindings/core/v8/V8ValueCache.h" |
49 #include "core/CoreExport.h" | 50 #include "core/CoreExport.h" |
50 #include "platform/heap/Handle.h" | 51 #include "platform/heap/Handle.h" |
51 #include "v8/include/v8.h" | 52 #include "v8/include/v8.h" |
52 #include "wtf/text/AtomicString.h" | 53 #include "wtf/text/AtomicString.h" |
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
754 } else { | 755 } else { |
755 exceptionState.throwTypeError("Invalid Array element type"); | 756 exceptionState.throwTypeError("Invalid Array element type"); |
756 return VectorType(); | 757 return VectorType(); |
757 } | 758 } |
758 } | 759 } |
759 return result; | 760 return result; |
760 } | 761 } |
761 | 762 |
762 // Converts a JavaScript value to an array as per the Web IDL specification: | 763 // 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 | 764 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-array |
764 template <typename VectorType> | 765 template <typename VectorType, |
766 typename ValueType = typename VectorType::ValueType> | |
765 VectorType toImplArray(v8::Local<v8::Value> value, | 767 VectorType toImplArray(v8::Local<v8::Value> value, |
766 int argumentIndex, | 768 int argumentIndex, |
767 v8::Isolate* isolate, | 769 v8::Isolate* isolate, |
768 ExceptionState& exceptionState) { | 770 ExceptionState& exceptionState) { |
769 typedef typename VectorType::ValueType ValueType; | |
770 typedef NativeValueTraits<ValueType> TraitsType; | 771 typedef NativeValueTraits<ValueType> TraitsType; |
771 | 772 |
772 uint32_t length = 0; | 773 uint32_t length = 0; |
773 if (value->IsArray()) { | 774 if (value->IsArray()) { |
774 length = v8::Local<v8::Array>::Cast(value)->Length(); | 775 length = v8::Local<v8::Array>::Cast(value)->Length(); |
775 } else if (!toV8Sequence(value, length, isolate, exceptionState)) { | 776 } else if (!toV8Sequence(value, length, isolate, exceptionState)) { |
776 if (!exceptionState.hadException()) | 777 if (!exceptionState.hadException()) |
777 exceptionState.throwTypeError( | 778 exceptionState.throwTypeError( |
778 ExceptionMessages::notAnArrayTypeArgumentOrValue(argumentIndex)); | 779 ExceptionMessages::notAnArrayTypeArgumentOrValue(argumentIndex)); |
779 return VectorType(); | 780 return VectorType(); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
897 sequenceLength, block)) { | 898 sequenceLength, block)) { |
898 exceptionState.rethrowV8Exception(block.Exception()); | 899 exceptionState.rethrowV8Exception(block.Exception()); |
899 return false; | 900 return false; |
900 } | 901 } |
901 | 902 |
902 length = sequenceLength; | 903 length = sequenceLength; |
903 return true; | 904 return true; |
904 } | 905 } |
905 | 906 |
906 template <> | 907 template <> |
908 struct NativeValueTraits<SerializedScriptValue> | |
haraken
2017/03/06 19:10:29
Yeah, I'd prefer moving this to SerializedScriptVa
Raphael Kubo da Costa (rakuco)
2017/03/06 19:40:48
Done in patch v6 \o/
| |
909 : public NativeValueTraitsBase<SerializedScriptValue> { | |
910 CORE_EXPORT static inline PassRefPtr<SerializedScriptValue> nativeValue( | |
911 v8::Isolate* isolate, | |
912 v8::Local<v8::Value> value, | |
913 ExceptionState& exceptionState) { | |
914 return SerializedScriptValue::serialize(isolate, value, nullptr, nullptr, | |
915 exceptionState); | |
916 } | |
917 }; | |
918 | |
919 // TODO(rakuco): remove the specializations below (and consequently the | |
920 // non-IDLBase version of NativeValueTraitsBase) once we manage to convert all | |
921 // uses of NativeValueTraits to types that derive from IDLBase or for generated | |
922 // IDL interfaces/dictionaries/unions. | |
923 template <> | |
907 struct NativeValueTraits<String> { | 924 struct NativeValueTraits<String> { |
908 static inline String nativeValue(v8::Isolate* isolate, | 925 static inline String nativeValue(v8::Isolate* isolate, |
909 v8::Local<v8::Value> value, | 926 v8::Local<v8::Value> value, |
910 ExceptionState& exceptionState) { | 927 ExceptionState& exceptionState) { |
911 V8StringResource<> stringValue(value); | 928 V8StringResource<> stringValue(value); |
912 if (!stringValue.prepare(exceptionState)) | 929 if (!stringValue.prepare(exceptionState)) |
913 return String(); | 930 return String(); |
914 return stringValue; | 931 return stringValue; |
915 } | 932 } |
916 }; | 933 }; |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1160 // If the argument isn't an object, this will crash. | 1177 // If the argument isn't an object, this will crash. |
1161 CORE_EXPORT v8::Local<v8::Value> freezeV8Object(v8::Local<v8::Value>, | 1178 CORE_EXPORT v8::Local<v8::Value> freezeV8Object(v8::Local<v8::Value>, |
1162 v8::Isolate*); | 1179 v8::Isolate*); |
1163 | 1180 |
1164 CORE_EXPORT v8::Local<v8::Value> fromJSONString(v8::Isolate*, | 1181 CORE_EXPORT v8::Local<v8::Value> fromJSONString(v8::Isolate*, |
1165 const String& stringifiedJSON, | 1182 const String& stringifiedJSON, |
1166 ExceptionState&); | 1183 ExceptionState&); |
1167 } // namespace blink | 1184 } // namespace blink |
1168 | 1185 |
1169 #endif // V8Binding_h | 1186 #endif // V8Binding_h |
OLD | NEW |