Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_PUBLIC_RENDERER_V8_VALUE_CONVERTER_H_ | 5 #ifndef CONTENT_PUBLIC_RENDERER_V8_VALUE_CONVERTER_H_ |
| 6 #define CONTENT_PUBLIC_RENDERER_V8_VALUE_CONVERTER_H_ | 6 #define CONTENT_PUBLIC_RENDERER_V8_VALUE_CONVERTER_H_ |
| 7 | 7 |
| 8 #include "content/common/content_export.h" | 8 #include "content/common/content_export.h" |
| 9 #include "v8/include/v8.h" | 9 #include "v8/include/v8.h" |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 // The JSON types (null, boolean, string, number, array, and object) as well as | 21 // The JSON types (null, boolean, string, number, array, and object) as well as |
| 22 // binary values are supported. For binary values, we convert to WebKit | 22 // binary values are supported. For binary values, we convert to WebKit |
| 23 // ArrayBuffers, and support converting from an ArrayBuffer or any of the | 23 // ArrayBuffers, and support converting from an ArrayBuffer or any of the |
| 24 // ArrayBufferView subclasses (Uint8Array, etc.). | 24 // ArrayBufferView subclasses (Uint8Array, etc.). |
| 25 class CONTENT_EXPORT V8ValueConverter { | 25 class CONTENT_EXPORT V8ValueConverter { |
| 26 public: | 26 public: |
| 27 static V8ValueConverter* create(); | 27 static V8ValueConverter* create(); |
| 28 | 28 |
| 29 virtual ~V8ValueConverter() {} | 29 virtual ~V8ValueConverter() {} |
| 30 | 30 |
| 31 // Use the following setters to support additional types other than the | 31 // If true, Date objects are converted into DoubleValues with the number of |
| 32 // default ones. | 32 // seconds since Unix epoch. |
|
koz (OOO until 15th September)
2012/09/14 02:05:44
Good job on adding comments.
| |
| 33 virtual bool GetUndefinedAllowed() const = 0; | 33 // |
| 34 virtual void SetUndefinedAllowed(bool val) = 0; | 34 // Otherwise they are converted into DictionaryValues with whatever additional |
| 35 | 35 // properties has been set on them. |
| 36 virtual bool GetDateAllowed() const = 0; | |
| 37 virtual void SetDateAllowed(bool val) = 0; | 36 virtual void SetDateAllowed(bool val) = 0; |
| 38 | 37 |
| 39 virtual bool GetRegexpAllowed() const = 0; | 38 // If true, RegExp objects are converted into StringValues with the regular |
| 40 virtual void SetRegexpAllowed(bool val) = 0; | 39 // expression between / and /, for example "/ab?c/". |
| 40 // | |
| 41 // Otherwise they are converted into DictionaryValues with whatever additional | |
| 42 // properties has been set on them. | |
| 43 virtual void SetRegExpAllowed(bool val) = 0; | |
| 41 | 44 |
| 42 // Gets/sets whether to treat undefined or null in objects as nonexistent. | 45 // If true, Function objects are converted into DictionaryValues with whatever |
| 43 virtual bool GetStripNullFromObjects() const = 0; | 46 // additional properties has been set on them. |
|
koz (OOO until 15th September)
2012/09/14 02:05:44
"Otherwise they are omitted from dictionaries and
not at google - send to devlin
2012/09/15 06:24:24
Done.
| |
| 47 virtual void SetFunctionAllowed(bool val) = 0; | |
| 48 | |
| 49 // If true, null values are stripped from objects. This is often useful when | |
| 50 // converting arguments to extension APIs. | |
| 44 virtual void SetStripNullFromObjects(bool val) = 0; | 51 virtual void SetStripNullFromObjects(bool val) = 0; |
| 45 | 52 |
| 46 // Converts Value to v8::Value. Unsupported types are replaced with null. | 53 // Converts a base::Value to a v8::Value. |
| 47 // If an array or object throws while setting a value, that property or item | 54 // |
| 48 // is skipped, leaving a hole in the case of arrays. | 55 // Unsupported types are replaced with null. If an array or object throws |
| 56 // while setting a value, that property or item is skipped, leaving a hole in | |
| 57 // the case of arrays. | |
| 49 virtual v8::Handle<v8::Value> ToV8Value( | 58 virtual v8::Handle<v8::Value> ToV8Value( |
| 50 const base::Value* value, | 59 const base::Value* value, |
| 51 v8::Handle<v8::Context> context) const = 0; | 60 v8::Handle<v8::Context> context) const = 0; |
| 52 | 61 |
| 53 // Converts v8::Value to Value. Unsupported types are replaced with null. | 62 // Converts a v8::Value to base::Value. |
| 54 // If an array or object throws while getting a value, that property or item | 63 // |
| 55 // is replaced with null. | 64 // Unsupported types (unless explicitly configured) are not converted, so |
| 65 // this method may return NULL -- the exception is when converting arrays, | |
| 66 // where unsupported types are converted to Value(TYPE_NULL). | |
| 67 // | |
| 68 // Likewise, if an object throws while converting a property it will not be | |
| 69 // converted, whereas if an array throws while converting an item it will be | |
| 70 // converted to Value(TYPE_NULL). | |
| 56 virtual base::Value* FromV8Value(v8::Handle<v8::Value> value, | 71 virtual base::Value* FromV8Value(v8::Handle<v8::Value> value, |
| 57 v8::Handle<v8::Context> context) const = 0; | 72 v8::Handle<v8::Context> context) const = 0; |
| 58 }; | 73 }; |
| 59 | 74 |
| 60 } // namespace content | 75 } // namespace content |
| 61 | 76 |
| 62 #endif // CONTENT_PUBLIC_RENDERER_V8_VALUE_CONVERTER_H_ | 77 #endif // CONTENT_PUBLIC_RENDERER_V8_VALUE_CONVERTER_H_ |
| OLD | NEW |