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

Proposed by Marcus Tomlinson on 2016-02-04
Status: Merged
Approved by: Marcus Tomlinson on 2016-02-09
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) 2016-02-04 Approve on 2016-02-09
PS Jenkins bot (community) continuous-integration Approve on 2016-02-04
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.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/bindings/src/common.cc'
2--- src/bindings/src/common.cc 2015-12-09 07:22:06 +0000
3+++ src/bindings/src/common.cc 2016-02-04 10:18:11 +0000
4@@ -17,6 +17,7 @@
5 */
6
7 #include "common.h"
8+#include "variant.h"
9
10 v8::Local<v8::Value> unity::scopesjs::from_variant(
11 const unity::scopes::Variant& variant) {
12@@ -73,6 +74,13 @@
13 v8::Local<v8::Value> value) {
14 try
15 {
16+ // Check first that the value recieved is not already a Variant
17+ auto variant = v8cpp::from_v8<::Variant>(v8::Isolate::GetCurrent(), value);
18+ return variant.variant();
19+ }
20+ catch (std::exception const&) {}
21+ try
22+ {
23 // Check first that the value recieved is not already a unity::scopes::Variant
24 return v8cpp::from_v8<unity::scopes::Variant>(v8::Isolate::GetCurrent(), value);
25 }
26@@ -94,6 +102,19 @@
27 v = Variant(value->ToBoolean()->Value());
28 } else if (value->IsNumber()) {
29 v = Variant(value->NumberValue());
30+ } else if (value->IsArray()) {
31+ v8::Handle<v8::Object> o = v8::Handle<v8::Object>::Cast(value);
32+
33+ VariantArray va;
34+
35+ for (size_t i = 0;
36+ i < o->Get(v8::String::NewFromUtf8(
37+ v8::Isolate::GetCurrent(), "length"))->ToObject()->Uint32Value();
38+ ++i) {
39+ va.push_back(to_variant(o->Get(i)));
40+ }
41+
42+ v = va;
43 } else if (value->IsObject()) {
44 v8::Handle<v8::Object> o = v8::Handle<v8::Object>::Cast(value);
45
46@@ -108,19 +129,6 @@
47 }
48
49 v = vm;
50- } else if (value->IsArray()) {
51- v8::Handle<v8::Object> o = v8::Handle<v8::Object>::Cast(value);
52-
53- VariantArray va;
54-
55- for (size_t i = 0;
56- i < o->Get(v8::String::NewFromUtf8(
57- v8::Isolate::GetCurrent(), "length"))->ToObject()->Uint32Value();
58- ++i) {
59- va.push_back(to_variant(o->Get(i)));
60- }
61-
62- v = va;
63 }
64
65 return v;
66
67=== modified file 'src/bindings/src/preview-widget.cc'
68--- src/bindings/src/preview-widget.cc 2015-12-10 09:43:59 +0000
69+++ src/bindings/src/preview-widget.cc 2016-02-04 10:18:11 +0000
70@@ -86,7 +86,24 @@
71 unity::scopes::Variant v =
72 unity::scopesjs::to_variant(args[1]);
73
74- if (v.which() == unity::scopes::Variant::Dict) {
75+ if (v.which() == unity::scopes::Variant::Array) {
76+ unity::scopes::VariantArray va = v.get_array();
77+
78+ for (auto &d : va) {
79+ if (d.which() == unity::scopes::Variant::Dict) {
80+ unity::scopes::VariantMap vm = d.get_dict();
81+ std::vector<std::pair<std::string, unity::scopes::Variant>> t;
82+
83+ for (auto &c : vm) {
84+ t.push_back({c.first, c.second});
85+ }
86+
87+ vb.add_tuple(t);
88+ }
89+ }
90+ preview_widget_->add_attribute_value(key, vb.end());
91+ }
92+ else if (v.which() == unity::scopes::Variant::Dict) {
93 unity::scopes::VariantMap vm = v.get_dict();
94 std::vector<std::pair<std::string, unity::scopes::Variant>> t;
95
96
97=== modified file 'src/bindings/src/variant.cc'
98--- src/bindings/src/variant.cc 2015-12-09 07:22:06 +0000
99+++ src/bindings/src/variant.cc 2016-02-04 10:18:11 +0000
100@@ -104,3 +104,7 @@
101 return variant_string_from_type(variant_->which());
102 }
103
104+unity::scopes::Variant Variant::variant() const
105+{
106+ return * variant_;
107+}
108
109=== modified file 'src/bindings/src/variant.h'
110--- src/bindings/src/variant.h 2015-12-09 07:22:06 +0000
111+++ src/bindings/src/variant.h 2016-02-04 10:18:11 +0000
112@@ -46,6 +46,8 @@
113 bool is_null() const;
114 std::string which();
115
116+ unity::scopes::Variant variant() const;
117+
118 private:
119 std::shared_ptr<unity::scopes::Variant> variant_;
120 };

Subscribers

People subscribed via source and target branches

to all changes: