@@ -220,9 +220,9 @@ module Agents |
||
220 | 220 |
end |
221 | 221 |
|
222 | 222 |
def clean_nans(input) |
223 |
- if input.is_a?(Array) |
|
223 |
+ if input.is_a?(V8::Array) |
|
224 | 224 |
input.map {|v| clean_nans(v) } |
225 |
- elsif input.is_a?(Hash) |
|
225 |
+ elsif input.is_a?(V8::Object) |
|
226 | 226 |
input.inject({}) { |m, (k, v)| m[k] = clean_nans(v); m } |
227 | 227 |
elsif input.is_a?(Float) && input.nan? |
228 | 228 |
'NaN' |
@@ -132,7 +132,9 @@ describe Agents::JavaScriptAgent do |
||
132 | 132 |
expect(AgentLog.last.message).to match(/oh no/) |
133 | 133 |
expect(AgentLog.last.level).to eq(4) |
134 | 134 |
end |
135 |
+ end |
|
135 | 136 |
|
137 |
+ describe "getMemory" do |
|
136 | 138 |
it "won't store NaNs" do |
137 | 139 |
@agent.options['code'] = 'Agent.check = function() { this.memory("foo", NaN); };' |
138 | 140 |
@agent.save! |
@@ -141,6 +143,49 @@ describe Agents::JavaScriptAgent do |
||
141 | 143 |
@agent.save! |
142 | 144 |
expect { @agent.reload.memory }.not_to raise_error |
143 | 145 |
end |
146 |
+ |
|
147 |
+ it "it stores an Array" do |
|
148 |
+ @agent.options['code'] = 'Agent.check = function() { |
|
149 |
+ var arr = [1,2]; |
|
150 |
+ this.memory("foo", arr); |
|
151 |
+ };' |
|
152 |
+ @agent.save! |
|
153 |
+ @agent.check |
|
154 |
+ expect(@agent.memory['foo']).to eq([1,2]) |
|
155 |
+ @agent.save! |
|
156 |
+ expect { @agent.reload.memory }.not_to raise_error |
|
157 |
+ end |
|
158 |
+ |
|
159 |
+ it "it stores a Hash" do |
|
160 |
+ @agent.options['code'] = 'Agent.check = function() { |
|
161 |
+ var obj = {}; |
|
162 |
+ obj["one"] = 1; |
|
163 |
+ obj["two"] = [1,2]; |
|
164 |
+ this.memory("foo", obj); |
|
165 |
+ };' |
|
166 |
+ @agent.save! |
|
167 |
+ @agent.check |
|
168 |
+ expect(@agent.memory['foo']).to eq({"one"=>1, "two"=> [1,2]}) |
|
169 |
+ @agent.save! |
|
170 |
+ expect { @agent.reload.memory }.not_to raise_error |
|
171 |
+ end |
|
172 |
+ |
|
173 |
+ it "it stores a nested Hash" do |
|
174 |
+ @agent.options['code'] = 'Agent.check = function() { |
|
175 |
+ var u = {}; |
|
176 |
+ u["one"] = 1; |
|
177 |
+ u["two"] = 2; |
|
178 |
+ var obj = {}; |
|
179 |
+ obj["three"] = 3; |
|
180 |
+ obj["four"] = u; |
|
181 |
+ this.memory("foo", obj); |
|
182 |
+ };' |
|
183 |
+ @agent.save! |
|
184 |
+ @agent.check |
|
185 |
+ expect(@agent.memory['foo']).to eq({"three"=>3, "four"=>{"one"=>1, "two"=>2}}) |
|
186 |
+ @agent.save! |
|
187 |
+ expect { @agent.reload.memory }.not_to raise_error |
|
188 |
+ end |
|
144 | 189 |
end |
145 | 190 |
|
146 | 191 |
describe "creating events" do |