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:
parent
80905e0140
commit
7218290098
4 changed files with 37 additions and 9 deletions
|
@ -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 ####
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue