INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK. Returns the JavaScript object that corresponds to this node, lazily initializing a new one if necessary. The logic of when and where the JavaScript object is created needs a cleanup: f
()
| 887 | * @return the JavaScript object that corresponds to this node |
| 888 | */ |
| 889 | @SuppressWarnings("unchecked") |
| 890 | public <T extends HtmlUnitScriptable> T getScriptableObject() { |
| 891 | if (scriptObject_ == null) { |
| 892 | final SgmlPage page = getPage(); |
| 893 | if (this == page) { |
| 894 | final StringBuilder msg = new StringBuilder("No script object associated with the Page."); |
| 895 | // because this is a strange case we like to provide as much info as possible |
| 896 | msg.append(" class: '") |
| 897 | .append(page.getClass().getName()) |
| 898 | .append('\''); |
| 899 | try { |
| 900 | msg.append(" url: '") |
| 901 | .append(page.getUrl()).append("' content: ") |
| 902 | .append(page.getWebResponse().getContentAsString()); |
| 903 | } |
| 904 | catch (final Exception e) { |
| 905 | // ok bad luck with detail |
| 906 | msg.append(" no details: '").append(e).append('\''); |
| 907 | } |
| 908 | throw new IllegalStateException(msg.toString()); |
| 909 | } |
| 910 | scriptObject_ = page.getScriptableObject().makeScriptableFor(this); |
| 911 | } |
| 912 | return (T) scriptObject_; |
| 913 | } |
| 914 | |
| 915 | /** |
| 916 | * {@inheritDoc} |
no test coverage detected