lib/capybara/poltergeist/client/agent.coffee in poltergeist-1.13.0 vs lib/capybara/poltergeist/client/agent.coffee in poltergeist-1.14.0
- old
+ new
@@ -55,10 +55,30 @@
this.get(id).removeAttribute('_poltergeist_selected')
clearLocalStorage: ->
localStorage?.clear()
+ wrapResults: (result, page_id)->
+ @_visitedObjects ||= [];
+ switch
+ when result in @_visitedObjects
+ '(cyclic structure)'
+ when Array.isArray(result) || (result instanceof NodeList)
+ @wrapResults(res, page_id) for res in result
+ when result && result.nodeType == 1 && result['tagName']
+ {'ELEMENT': { id: @register(result), page_id: page_id } };
+ when not result?
+ undefined
+ when typeof result == 'object'
+ @_visitedObjects.push(result);
+ obj = {}
+ obj[key] = @wrapResults(val, page_id) for own key, val of result
+ @_visitedObjects.pop();
+ obj
+ else
+ result
+
class PoltergeistAgent.ObsoleteNode
toString: -> "PoltergeistAgent.ObsoleteNode"
class PoltergeistAgent.InvalidSelector
toString: -> "PoltergeistAgent.InvalidSelector"
@@ -87,10 +107,10 @@
find: (method, selector) ->
@agent.find(method, selector, @element)
isObsolete: ->
obsolete = (element) =>
- if (parent = element.parentNode)?
+ if (parent = element?.parentNode)?
if parent == document
return false
else
obsolete parent
else