Merge lp:~marcustomlinson/unity-js-scopes/lp-1541720 into lp:unity-js-scopes

Proposed by Marcus Tomlinson
Status: Merged
Approved by: Marcus Tomlinson
Approved revision: 126
Merged at revision: 127
Proposed branch: lp:~marcustomlinson/unity-js-scopes/lp-1541720
Merge into: lp:unity-js-scopes
Diff against target: 120 lines (+45/-14)
4 files modified
src/bindings/src/common.cc (+21/-13)
src/bindings/src/preview-widget.cc (+18/-1)
src/bindings/src/variant.cc (+4/-0)
src/bindings/src/variant.h (+2/-0)
To merge this branch: bzr merge lp:~marcustomlinson/unity-js-scopes/lp-1541720
Reviewer Review Type Date Requested Status
Alexandre Abreu (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+285032@code.launchpad.net

Commit message

* Check if the value given to unity::scopesjs::to_variant() is not already a bound Variant type.
* Do array check before object check in unity::scopesjs::to_variant() (arrays are also objects).
* Handle array of dicts when recieving object variants in PreviewWidget::add_attribute_value().

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alexandre Abreu (abreu-alexandre) wrote :

Good stuff, +1

review: Approve
Revision history for this message
Marcus Tomlinson (marcustomlinson) wrote :

Top approving

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/bindings/src/common.cc'
--- src/bindings/src/common.cc 2015-12-09 07:22:06 +0000
+++ src/bindings/src/common.cc 2016-02-04 10:18:11 +0000
@@ -17,6 +17,7 @@
17 */17 */
1818
19#include "common.h"19#include "common.h"
20#include "variant.h"
2021
21v8::Local<v8::Value> unity::scopesjs::from_variant(22v8::Local<v8::Value> unity::scopesjs::from_variant(
22 const unity::scopes::Variant& variant) {23 const unity::scopes::Variant& variant) {
@@ -73,6 +74,13 @@
73 v8::Local<v8::Value> value) {74 v8::Local<v8::Value> value) {
74 try75 try
75 {76 {
77 // Check first that the value recieved is not already a Variant
78 auto variant = v8cpp::from_v8<::Variant>(v8::Isolate::GetCurrent(), value);
79 return variant.variant();
80 }
81 catch (std::exception const&) {}
82 try
83 {
76 // Check first that the value recieved is not already a unity::scopes::Variant84 // Check first that the value recieved is not already a unity::scopes::Variant
77 return v8cpp::from_v8<unity::scopes::Variant>(v8::Isolate::GetCurrent(), value);85 return v8cpp::from_v8<unity::scopes::Variant>(v8::Isolate::GetCurrent(), value);
78 }86 }
@@ -94,6 +102,19 @@
94 v = Variant(value->ToBoolean()->Value());102 v = Variant(value->ToBoolean()->Value());
95 } else if (value->IsNumber()) {103 } else if (value->IsNumber()) {
96 v = Variant(value->NumberValue());104 v = Variant(value->NumberValue());
105 } else if (value->IsArray()) {
106 v8::Handle<v8::Object> o = v8::Handle<v8::Object>::Cast(value);
107
108 VariantArray va;
109
110 for (size_t i = 0;
111 i < o->Get(v8::String::NewFromUtf8(
112 v8::Isolate::GetCurrent(), "length"))->ToObject()->Uint32Value();
113 ++i) {
114 va.push_back(to_variant(o->Get(i)));
115 }
116
117 v = va;
97 } else if (value->IsObject()) {118 } else if (value->IsObject()) {
98 v8::Handle<v8::Object> o = v8::Handle<v8::Object>::Cast(value);119 v8::Handle<v8::Object> o = v8::Handle<v8::Object>::Cast(value);
99120
@@ -108,19 +129,6 @@
108 }129 }
109130
110 v = vm;131 v = vm;
111 } else if (value->IsArray()) {
112 v8::Handle<v8::Object> o = v8::Handle<v8::Object>::Cast(value);
113
114 VariantArray va;
115
116 for (size_t i = 0;
117 i < o->Get(v8::String::NewFromUtf8(
118 v8::Isolate::GetCurrent(), "length"))->ToObject()->Uint32Value();
119 ++i) {
120 va.push_back(to_variant(o->Get(i)));
121 }
122
123 v = va;
124 }132 }
125133
126 return v;134 return v;
127135
=== modified file 'src/bindings/src/preview-widget.cc'
--- src/bindings/src/preview-widget.cc 2015-12-10 09:43:59 +0000
+++ src/bindings/src/preview-widget.cc 2016-02-04 10:18:11 +0000
@@ -86,7 +86,24 @@
86 unity::scopes::Variant v =86 unity::scopes::Variant v =
87 unity::scopesjs::to_variant(args[1]);87 unity::scopesjs::to_variant(args[1]);
8888
89 if (v.which() == unity::scopes::Variant::Dict) {89 if (v.which() == unity::scopes::Variant::Array) {
90 unity::scopes::VariantArray va = v.get_array();
91
92 for (auto &d : va) {
93 if (d.which() == unity::scopes::Variant::Dict) {
94 unity::scopes::VariantMap vm = d.get_dict();
95 std::vector<std::pair<std::string, unity::scopes::Variant>> t;
96
97 for (auto &c : vm) {
98 t.push_back({c.first, c.second});
99 }
100
101 vb.add_tuple(t);
102 }
103 }
104 preview_widget_->add_attribute_value(key, vb.end());
105 }
106 else if (v.which() == unity::scopes::Variant::Dict) {
90 unity::scopes::VariantMap vm = v.get_dict();107 unity::scopes::VariantMap vm = v.get_dict();
91 std::vector<std::pair<std::string, unity::scopes::Variant>> t;108 std::vector<std::pair<std::string, unity::scopes::Variant>> t;
92109
93110
=== modified file 'src/bindings/src/variant.cc'
--- src/bindings/src/variant.cc 2015-12-09 07:22:06 +0000
+++ src/bindings/src/variant.cc 2016-02-04 10:18:11 +0000
@@ -104,3 +104,7 @@
104 return variant_string_from_type(variant_->which());104 return variant_string_from_type(variant_->which());
105}105}
106106
107unity::scopes::Variant Variant::variant() const
108{
109 return * variant_;
110}
107111
=== modified file 'src/bindings/src/variant.h'
--- src/bindings/src/variant.h 2015-12-09 07:22:06 +0000
+++ src/bindings/src/variant.h 2016-02-04 10:18:11 +0000
@@ -46,6 +46,8 @@
46 bool is_null() const;46 bool is_null() const;
47 std::string which();47 std::string which();
4848
49 unity::scopes::Variant variant() const;
50
49 private:51 private:
50 std::shared_ptr<unity::scopes::Variant> variant_;52 std::shared_ptr<unity::scopes::Variant> variant_;
51};53};

Subscribers

People subscribed via source and target branches

to all changes: