diff options
Diffstat (limited to 'tools/json_schema_compiler')
-rw-r--r-- | tools/json_schema_compiler/cc_generator.py | 2 | ||||
-rw-r--r-- | tools/json_schema_compiler/cpp_type_generator.py | 7 | ||||
-rw-r--r-- | tools/json_schema_compiler/idl_schema.py | 9 |
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: |