1
0
Fork 0
mirror of https://github.com/teampoltergeist/poltergeist.git synced 2022-11-09 12:05:00 -05:00

Don't blow up when evaluate_script is called with a cyclic structure.

This commit is contained in:
Jon Leighton 2012-09-01 18:20:06 +01:00
parent 80905e0140
commit 7218290098
4 changed files with 37 additions and 9 deletions

View file

@ -194,6 +194,9 @@ makes debugging easier). Running `rake autocompile` will watch the
enables `:hover` effects etc to trigger before the click happens,
which can affect the click in some cases. [Issue #120]
* Don't blow up when `evaluate_script` is called with a cyclic
structure.
### 0.7.0 ###
#### Features ####

View file

@ -14,11 +14,17 @@ class PoltergeistAgent
{ error: { message: error.toString(), stack: error.stack } }
@stringify: (object) ->
JSON.stringify object, (key, value) ->
if Array.isArray(this[key])
return this[key]
try
JSON.stringify object, (key, value) ->
if Array.isArray(this[key])
return this[key]
else
return value
catch error
if error instanceof TypeError
'"(cyclic structure)"'
else
return value
throw error
pushWindow: (new_window) ->
@windows.push(new_window)

View file

@ -25,13 +25,21 @@ PoltergeistAgent = (function() {
};
PoltergeistAgent.stringify = function(object) {
return JSON.stringify(object, function(key, value) {
if (Array.isArray(this[key])) {
return this[key];
try {
return JSON.stringify(object, function(key, value) {
if (Array.isArray(this[key])) {
return this[key];
} else {
return value;
}
});
} catch (error) {
if (error instanceof TypeError) {
return '"(cyclic structure)"';
} else {
return value;
throw error;
}
});
}
};
PoltergeistAgent.prototype.pushWindow = function(new_window) {

View file

@ -293,5 +293,16 @@ describe Capybara::Session do
@session.status_code.should == 402
end
end
it 'ignores cyclic structure errors in evaluate_script' do
code = <<-CODE
(function() {
var a = {}
a.a = a
return a
})()
CODE
@session.evaluate_script(code).should == "(cyclic structure)"
end
end
end