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

Side by Side Diff: content/public/renderer/v8_value_converter.h

Issue 10890002: Make V8ValueConverter.FromV8Value behave similarly to JSON.stringify (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ignore -> omit Created 8 years, 3 months 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
OLDNEW
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 12 matching lines...) Expand all
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 // Use the following setters to support additional types other than the
32 // default ones. 32 // default ones.
33 virtual bool GetUndefinedAllowed() const = 0; 33
34 virtual void SetUndefinedAllowed(bool val) = 0; 34 enum UndefinedValueBehavior {
35 // Treat undefined values as errors. This is the default behavior.
36 TREAT_AS_ERROR,
not at google - send to devlin 2012/09/11 11:50:11 The existence of "treat as error" only makes if tr
koz (OOO until 15th September) 2012/09/12 02:08:28 As discussed, seeing as this logs errors to STDERR
37
38 // Treat undefined values as inconvertible and omit them from the result.
39 OMIT,
40
41 // Convert undefined values to null.
42 CONVERT_TO_NULL
43 };
44 virtual UndefinedValueBehavior GetUndefinedValueBehavior() const = 0;
45 virtual void SetUndefinedValueBehavior(UndefinedValueBehavior val) = 0;
35 46
36 virtual bool GetDateAllowed() const = 0; 47 virtual bool GetDateAllowed() const = 0;
37 virtual void SetDateAllowed(bool val) = 0; 48 virtual void SetDateAllowed(bool val) = 0;
38 49
39 virtual bool GetRegexpAllowed() const = 0; 50 virtual bool GetRegexpAllowed() const = 0;
40 virtual void SetRegexpAllowed(bool val) = 0; 51 virtual void SetRegexpAllowed(bool val) = 0;
41 52
42 // Gets/sets whether to treat undefined or null in objects as nonexistent. 53 // Gets/sets whether to treat undefined or null in objects as nonexistent.
43 virtual bool GetStripNullFromObjects() const = 0; 54 virtual bool GetStripNullFromObjects() const = 0;
44 virtual void SetStripNullFromObjects(bool val) = 0; 55 virtual void SetStripNullFromObjects(bool val) = 0;
45 56
46 // Converts Value to v8::Value. Unsupported types are replaced with null. 57 // Converts a base::Value to a v8::Value.
47 // If an array or object throws while setting a value, that property or item 58 //
48 // is skipped, leaving a hole in the case of arrays. 59 // Unsupported types are replaced with null. If an array or object throws
60 // while setting a value, that property or item is skipped, leaving a hole in
61 // the case of arrays.
49 virtual v8::Handle<v8::Value> ToV8Value( 62 virtual v8::Handle<v8::Value> ToV8Value(
50 const base::Value* value, 63 const base::Value* value,
51 v8::Handle<v8::Context> context) const = 0; 64 v8::Handle<v8::Context> context) const = 0;
52 65
53 // Converts v8::Value to Value. Unsupported types are replaced with null. 66 // Converts a v8::Value to base::Value.
54 // If an array or object throws while getting a value, that property or item 67 //
55 // is replaced with null. 68 // Unsupported types (unless explicitly configured) are not converted, so
69 // this method may return NULL -- the exception is when converting arrays,
70 // where unsupported types are converted to Value(TYPE_NULL).
koz (OOO until 15th September) 2012/09/12 02:08:28 where unsupported types -> where elements that hav
71 //
72 // Likewise, if an object throws while converting a property it will not be
73 // converted, whereas if an array throws while converting an item it will be
koz (OOO until 15th September) 2012/09/12 02:08:28 Perhaps better phrased as: If an object throws wh
74 // converted to Value(TYPE_NULL).
56 virtual base::Value* FromV8Value(v8::Handle<v8::Value> value, 75 virtual base::Value* FromV8Value(v8::Handle<v8::Value> value,
57 v8::Handle<v8::Context> context) const = 0; 76 v8::Handle<v8::Context> context) const = 0;
58 }; 77 };
59 78
60 } // namespace content 79 } // namespace content
61 80
62 #endif // CONTENT_PUBLIC_RENDERER_V8_VALUE_CONVERTER_H_ 81 #endif // CONTENT_PUBLIC_RENDERER_V8_VALUE_CONVERTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698