diff options
author | kalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-16 01:22:54 +0000 |
---|---|---|
committer | kalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-16 01:22:54 +0000 |
commit | dcd4d20dabd4e21de94ee6f0208db81fcd9071d2 (patch) | |
tree | 848c21e36797a3f26444b08aa924e9771199aae8 /content/public/renderer | |
parent | 61d6e608a4d9a5355e66ac9a6ba59743f650262b (diff) | |
download | chromium_src-dcd4d20dabd4e21de94ee6f0208db81fcd9071d2.zip chromium_src-dcd4d20dabd4e21de94ee6f0208db81fcd9071d2.tar.gz chromium_src-dcd4d20dabd4e21de94ee6f0208db81fcd9071d2.tar.bz2 |
Revert 157025 - Make V8ValueConverter.FromV8Value be more consistent with JSON.stringify: don't
serialize undefined as null, don't serialize functions as objects, omit values
from objects when they don't serialize, and insert null into arrays when they
don't serialize.
It is now possible for FromV8Value to return NULL; previously it would return
Value::CreateNullValue on failure.
This is needed for the Storage API, where we promise that the values that are
passed in are serialized as JSON, yet the value conversion doesn't work in a
way that allows it.
However, the null-stripping behavior needs to be configurable so that existing
extension APIs (which only expect null/undefined to appear for optional values)
still work.
BUG=145081
Review URL: https://codereview.chromium.org/10890002
TBR=kalman@chromium.org
Review URL: https://codereview.chromium.org/10911327
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@157031 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/public/renderer')
-rw-r--r-- | content/public/renderer/v8_value_converter.h | 49 |
1 files changed, 16 insertions, 33 deletions
diff --git a/content/public/renderer/v8_value_converter.h b/content/public/renderer/v8_value_converter.h index b71b32d..be45ea9 100644 --- a/content/public/renderer/v8_value_converter.h +++ b/content/public/renderer/v8_value_converter.h @@ -28,48 +28,31 @@ class CONTENT_EXPORT V8ValueConverter { virtual ~V8ValueConverter() {} - // If true, Date objects are converted into DoubleValues with the number of - // seconds since Unix epoch. - // - // Otherwise they are converted into DictionaryValues with whatever additional - // properties has been set on them. - virtual void SetDateAllowed(bool val) = 0; + // Use the following setters to support additional types other than the + // default ones. + virtual bool GetUndefinedAllowed() const = 0; + virtual void SetUndefinedAllowed(bool val) = 0; - // If true, RegExp objects are converted into StringValues with the regular - // expression between / and /, for example "/ab?c/". - // - // Otherwise they are converted into DictionaryValues with whatever additional - // properties has been set on them. - virtual void SetRegExpAllowed(bool val) = 0; + virtual bool GetDateAllowed() const = 0; + virtual void SetDateAllowed(bool val) = 0; - // If true, Function objects are converted into DictionaryValues with whatever - // additional properties has been set on them. - // - // Otherwise they are treated as unsupported, see FromV8Value. - virtual void SetFunctionAllowed(bool val) = 0; + virtual bool GetRegexpAllowed() const = 0; + virtual void SetRegexpAllowed(bool val) = 0; - // If true, null values are stripped from objects. This is often useful when - // converting arguments to extension APIs. + // Gets/sets whether to treat undefined or null in objects as nonexistent. + virtual bool GetStripNullFromObjects() const = 0; virtual void SetStripNullFromObjects(bool val) = 0; - // Converts a base::Value to a v8::Value. - // - // Unsupported types are replaced with null. If an array or object throws - // while setting a value, that property or item is skipped, leaving a hole in - // the case of arrays. + // Converts Value to v8::Value. Unsupported types are replaced with null. + // If an array or object throws while setting a value, that property or item + // is skipped, leaving a hole in the case of arrays. virtual v8::Handle<v8::Value> ToV8Value( const base::Value* value, v8::Handle<v8::Context> context) const = 0; - // Converts a v8::Value to base::Value. - // - // Unsupported types (unless explicitly configured) are not converted, so - // this method may return NULL -- the exception is when converting arrays, - // where unsupported types are converted to Value(TYPE_NULL). - // - // Likewise, if an object throws while converting a property it will not be - // converted, whereas if an array throws while converting an item it will be - // converted to Value(TYPE_NULL). + // Converts v8::Value to Value. Unsupported types are replaced with null. + // If an array or object throws while getting a value, that property or item + // is replaced with null. virtual base::Value* FromV8Value(v8::Handle<v8::Value> value, v8::Handle<v8::Context> context) const = 0; }; |