diff options
author | hebert.christopherj@chromium.org <hebert.christopherj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-26 02:18:15 +0000 |
---|---|---|
committer | hebert.christopherj@chromium.org <hebert.christopherj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-26 02:18:15 +0000 |
commit | 3c6d186fa7157754045bcea6206a4e0109ad2e73 (patch) | |
tree | 5d0a7737f4d97f39680313f1b1c3b1d014dabdb2 /tools/json_schema_compiler/model.py | |
parent | 38b3db9f0a4cce1f77b4bbd9b965338c8a8c349b (diff) | |
download | chromium_src-3c6d186fa7157754045bcea6206a4e0109ad2e73.zip chromium_src-3c6d186fa7157754045bcea6206a4e0109ad2e73.tar.gz chromium_src-3c6d186fa7157754045bcea6206a4e0109ad2e73.tar.bz2 |
JSON Schema Compiler supports functions as PropertyTypes.
Before, the compiler raised an exception when a function was used as a property,
which happens whenever a function is passed as a parameter.
The solution presented here is to create a bool has_<function_name> to allow
the hand-written C++ code to know whether or not the function was passed in.
BUG=138850
TEST=function_as_parameter
Review URL: https://chromiumcodereview.appspot.com/10824002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148480 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/json_schema_compiler/model.py')
-rw-r--r-- | tools/json_schema_compiler/model.py | 13 |
1 files changed, 3 insertions, 10 deletions
diff --git a/tools/json_schema_compiler/model.py b/tools/json_schema_compiler/model.py index 5453e11..2351ecd 100644 --- a/tools/json_schema_compiler/model.py +++ b/tools/json_schema_compiler/model.py @@ -212,6 +212,8 @@ class Property(object): # self.properties will already have some value from |_AddProperties|. self.properties.update(type_.properties) self.functions = type_.functions + elif json_type == 'function': + self.type_ = PropertyType.FUNCTION elif json_type == 'binary': self.type_ = PropertyType.BINARY else: @@ -293,6 +295,7 @@ class PropertyType(object): REF = _Info(False, "REF") CHOICES = _Info(False, "CHOICES") OBJECT = _Info(False, "OBJECT") + FUNCTION = _Info(False, "FUNCTION") BINARY = _Info(False, "BINARY") ANY = _Info(False, "ANY") ADDITIONAL_PROPERTIES = _Info(False, "ADDITIONAL_PROPERTIES") @@ -350,16 +353,6 @@ def _AddProperties(model, json, from_json=False, from_client=False): """ model.properties = {} for name, property_json in json.get('properties', {}).items(): - # TODO(calamity): support functions (callbacks) as properties. The model - # doesn't support it yet because the h/cc generators don't -- this is - # because we'd need to hook it into a base::Callback or something. - # - # However, pragmatically it's not necessary to support them anyway, since - # the instances of functions-on-properties in the extension APIs are all - # handled in pure Javascript on the render process (and .: never reach - # C++ let alone the browser). - if property_json.get('type') == 'function': - continue model.properties[name] = Property( model, name, |