summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorgdk@chromium.org <gdk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-17 00:59:24 +0000
committergdk@chromium.org <gdk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-17 00:59:24 +0000
commited6feceb9c91fe25e17a75327628bfd40b1f1442 (patch)
tree49bac128ac8d0540ed78f26b48b4da5dcead2446 /tools
parent87be1009c787e56f738fb7cf9d91d731e3f0af86 (diff)
downloadchromium_src-ed6feceb9c91fe25e17a75327628bfd40b1f1442.zip
chromium_src-ed6feceb9c91fe25e17a75327628bfd40b1f1442.tar.gz
chromium_src-ed6feceb9c91fe25e17a75327628bfd40b1f1442.tar.bz2
Improve handling of ArrayBuffers in composite objects.
Improves json_schema_compiler's understanding of what an ArrayBuffer should be stored as in the native generated code. This change also improves the validation of ArrayBuffer fields in argument objects. BUG=133178 TEST=none Review URL: https://chromiumcodereview.appspot.com/10560027 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@142621 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools')
-rw-r--r--tools/json_schema_compiler/cc_generator.py2
-rw-r--r--tools/json_schema_compiler/cpp_type_generator.py7
-rw-r--r--tools/json_schema_compiler/idl_schema.py9
3 files changed, 13 insertions, 5 deletions
diff --git a/tools/json_schema_compiler/cc_generator.py b/tools/json_schema_compiler/cc_generator.py
index 7b3e902..3bba684 100644
--- a/tools/json_schema_compiler/cc_generator.py
+++ b/tools/json_schema_compiler/cc_generator.py
@@ -345,6 +345,8 @@ class CCGenerator(object):
return '%s.DeepCopy()' % var
elif prop.type_ == PropertyType.ENUM:
return 'CreateEnumValue(%s).release()' % var
+ elif prop.type_ == PropertyType.BINARY:
+ return '%s->DeepCopy()' % var
elif self._IsArrayOrArrayRef(prop):
return '%s.release()' % self._util_cc_helper.CreateValueFromArray(
self._cpp_type_generator.GetReferencedProperty(prop), var,
diff --git a/tools/json_schema_compiler/cpp_type_generator.py b/tools/json_schema_compiler/cpp_type_generator.py
index 1a1821d..1de8d16 100644
--- a/tools/json_schema_compiler/cpp_type_generator.py
+++ b/tools/json_schema_compiler/cpp_type_generator.py
@@ -119,6 +119,7 @@ class CppTypeGenerator(object):
optional.
"""
cpp_type = None
+ force_wrapping = False
if prop.type_ == PropertyType.REF:
dependency_namespace = self._ResolveTypeNamespace(prop.ref_type)
if not dependency_namespace:
@@ -156,13 +157,17 @@ class CppTypeGenerator(object):
cpp_type = cpp_type % self.GetType(
prop.item_type, pad_for_generics=True)
elif prop.type_ == PropertyType.BINARY:
+ # Since base::BinaryValue's are immutable, we wrap them in a scoped_ptr to
+ # allow them to be modified after the fact.
+ force_wrapping = True
cpp_type = 'base::BinaryValue'
else:
raise NotImplementedError(prop.type_)
# Enums aren't wrapped because C++ won't allow it. Optional enums have a
# NONE value generated instead.
- if wrap_optional and prop.optional and prop.type_ != PropertyType.ENUM:
+ if force_wrapping or (wrap_optional and prop.optional and prop.type_ !=
+ PropertyType.ENUM):
cpp_type = 'scoped_ptr<%s> ' % cpp_type
if pad_for_generics:
return cpp_type
diff --git a/tools/json_schema_compiler/idl_schema.py b/tools/json_schema_compiler/idl_schema.py
index d65746a..28f2a3b 100644
--- a/tools/json_schema_compiler/idl_schema.py
+++ b/tools/json_schema_compiler/idl_schema.py
@@ -190,16 +190,17 @@ class Typeref(object):
properties['type'] = 'integer'
elif self.typeref == 'any':
properties['type'] = 'any'
- elif self.typeref == 'ArrayBuffer' or self.typeref == 'object':
+ elif self.typeref == 'object':
properties['type'] = 'object'
if 'additionalProperties' not in properties:
properties['additionalProperties'] = {}
properties['additionalProperties']['type'] = 'any'
instance_of = self.parent.GetProperty('instanceOf')
- if self.typeref == 'ArrayBuffer':
- properties['isInstanceOf'] = 'ArrayBuffer'
- elif instance_of:
+ if instance_of:
properties['isInstanceOf'] = instance_of
+ elif self.typeref == 'ArrayBuffer':
+ properties['type'] = 'binary'
+ properties['isInstanceOf'] = 'ArrayBuffer'
elif self.typeref is None:
properties['type'] = 'function'
else: