Tracker: Bugs

5 Cannot read property "prototype" - Scriptaculous 1.6.4 - ID: 1576162
Last Update: Comment added ( mguillem )

I tried upgrading my app to use the latest version of
Script.aculo.us,
but it spits out the following error:

C:\Source\temp\appfuse\test\web\web-tests.xml:28: Canoo
Webtest: R_1393.
Test failed.
Test step invoke
(C:\Source\temp\appfuse\test\web\login.xml:1: )
named "get Login Page" failed with
message "Step[invoke "get Login Page" (1/6)]: Script
error loading
page executing webtest at: invok
e TypeError: Cannot read property "prototype" from null
(http://localhost:9234/appfuse/scripts/prototype.js#1320)

Line 1320 is:

copy(Form.Methods, HTMLFormElement.prototype);

The full method is:

Element.addMethods = function(methods) {
Object.extend(Element.Methods, methods || {});

function copy(methods, destination) {
var cache = Element.extend.cache;
for (var property in methods) {
var value = methods[property];
destination[property] = cache.findOrStore(value);
}
}

if (typeof HTMLElement != 'undefined') {
copy(Element.Methods, HTMLElement.prototype);
copy(Form.Methods, HTMLFormElement.prototype);
[HTMLInputElement, HTMLTextAreaElement,
HTMLSelectElement].each(function(klass) {
copy(Form.Element.Methods, klass.prototype);
});
_nativeExtensions = true;
}
}

Also posted to Canoo WebTest mailing list, but got no
response:

http://www.nabble.com/Issues-with-build1393-and-1416-with-Script.aculo.us-1
.6.4-tf2412243.html

The version of HtmlUnit that WebTest uses is 1.9.


Matt Raible ( mraible ) - 2006-10-12 19:48

5

Closed

Fixed

Marc Guillemot

None

1.8

Public


Comments ( 10 )

Date: 2007-06-05 09:43
Sender: mguillemProject Admin

I close this issue because latest version from head definitely works with
prototype (especially <Cannot read property "prototype".> is fixed).

@vguna
Please open a new issue with the necessary detailed information if you
still have problems.


Date: 2007-03-31 09:53
Sender: vguna

Hi.

Tried it with the latest SVN version. Still same error msg and line number
#334.



Date: 2007-03-30 07:21
Sender: mguillemProject Admin

Can you give a try to the latest source from SVN? Recent changes allow (at
least some) prototype features to work.


Date: 2007-02-20 09:57
Sender: vguna

I've tried the SVN version of htmlunit together with canoo. Now it dies
with:

Test step steps (webtest\usecases\register.xml:13: ) null failed with
message "Step[clickLink "Call the registration dialog" (3/40)]: Script
error loading page executing webtest at: clickLink Wrapped
com.gargoylesoftware.htmlunit.ScriptException: [object Error]
(http://localhost:8080/schoolfellows/js/scriptaculous/prototype.js#334)
(event for HtmlAnchor[<a href="#"
onclick="clear_linklistform();document.forms['linklistform'].elements['linklistform:_link_hidden_'].value='linklistform:_id32:_id34';if(document.forms['linklistform'].onsubmit){var
result=document.forms['linklistform'].onsubmit(); if( (typeof result ==
'undefined') || result )
{document.forms['linklistform'].submit();}}else{document.forms['linklistform'].submit();}return
false;" id="linklistform:_id32:_id34" title="Register">]#1)
Source code:
function () {
[native code, arity=0]
}
"

On the page, where the link resides, there's no prototype.js included. But
on the page that is called after the click.

I took a look at code fragment that causes the error: if (e !=
$break) throw e;

var Enumerable = {
each: function(iterator) {
var index = 0;
try {
this._each(function(value) {
try {
iterator(value, index++);
} catch (e) {
if (e != $continue) throw e;
}
});
} catch (e) {
if (e != $break) throw e;
}
return this;
},

Since I'm not too deep into JS I don't know what happens there exactly and
why it could fail.
I'm using it in a JSF app with myfaces, tomahawk and shale.

Any hints?

regards,
Veit



Date: 2007-02-19 09:30
Sender: mguillemProject Admin

Current status (with the latest sources from SVN): 4 prototype unit tests
work with htmlunit whereas 8 stil don't work. Among these 8, 2 are
currently blocked by Rhino issues. The other require further
investigation.
This information concerns only the unit tests of prototype, this doesn't
say how many of prototype (resp. script.aculo.us) work currently with
latest htmlunit sources as I guess that it depends from the usage of these
libraries made by your application.
If you have concrete cases and are ready to contribute, we're really
interested particularly because none of the htmlunit committers currently
need these features for a "real live" application.


Date: 2007-02-17 11:16
Sender: vguna

Hi.

Any news on this? I've got the same problem with Script.aculo.us 1.7 and
Canno Webtest snapshot (=html unit 1.10).

regards,
Veit



Date: 2006-11-13 10:22
Sender: mguillemProject Admin

Logged In: YES
user_id=402164

gpolya, you're workaround is interesting. Best would be to
fix the problem in htmlunit itself.
Daniel Gredler already sent me a patch to make htmlunit DOM
Level 2 HTML API conform js class names. I (or he) will
apply it soon. Nevertheless it seems it is just a part of
the solution.

Btw, as you seem to already have a good understanding of
htmlunit, if you provide some patches showing that you're
able to contribute to htmlunit's development, I would be
glad to propose you as committer.


Date: 2006-11-13 09:50
Sender: gpolya

Logged In: YES
user_id=1642385

After taking a close look at the HtmlUnit source code, I
found a better solution. Instead of commenting the
offending lines out we can provide the missing javascript
classes by using the following ScriptPreProcessor:

<code>
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;

import com.gargoylesoftware.htmlunit.ScriptPreProcessor;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.javascript.host.Form;
import com.gargoylesoftware.htmlunit.javascript.host.Input;
import com.gargoylesoftware.htmlunit.javascript.host.Select;
import com.gargoylesoftware.htmlunit.javascript.host.Textarea;


/**
* <a href="http://prototype.conio.net">Prototype 1.5.0</a>
uses classes of the
* DOM Level 2 HTML API, which htmlunit 1.10 does not
support. This java script
* pre-processor adds the classes that are needed, when
prototype.js is loaded.
* The implementations of the classes do not cover 100% of
the API, but are close
* enough for testing.
*/
public class PrototypeJSPreProcessor implements
ScriptPreProcessor {

public static class HTMLFormElement extends Form {
public String getClassName() {
return "HTMLFormElement";
}
}

public static class HTMLInputElement extends Input {
public String getClassName() {
return "HTMLInputElement";
}
}

public static class HTMLTextAreaElement extends Textarea {
public String getClassName() {
return "HTMLTextAreaElement";
}
}

public static class HTMLSelectElement extends Select {
public String getClassName() {
return "HTMLSelectElement";
}
}

/**
* Defines the classes <code>HTMLFormElement</code>,
<code>HTMLInputElement</code>,
* <code>HTMLTextAreaElement</code>, and
<code>HTMLSelectElement</code>
* when prototype.js is loaded.
*
* @see
com.gargoylesoftware.htmlunit.ScriptPreProcessor#preProcess(com.gargoylesoftware.htmlunit.html.HtmlPage,
java.lang.String, java.lang.String,
com.gargoylesoftware.htmlunit.html.HtmlElement)
*/
public String preProcess(HtmlPage page, String scriptCode,
String scriptName, HtmlElement element) {
if(scriptName.endsWith("prototype.js")) {
try {
Scriptable window =
(Scriptable)page.getEnclosingWindow().getScriptObject();
ScriptableObject.defineClass(window,
HTMLFormElement.class);
ScriptableObject.defineClass(window,
HTMLInputElement.class);
ScriptableObject.defineClass(window,
HTMLTextAreaElement.class);
ScriptableObject.defineClass(window,
HTMLSelectElement.class);
} catch(Exception e) {
throw new RuntimeException(e);
}
}
return scriptCode;
}

}
</code>

The reason Prototype 1.5.0 (or Scriptaculous 1.6.4) is not
working is the following: Prototype uses classes of the DOM
Level 2 HTML API which HtmlUnit so far doesn't provide.
Prototype actually checks for the API by checking if the
class HTMLElement exists. If HTMLElement exists, it assumes
the API is present. This is in my opinion a bug in
Prototype. Coincidentally HTMLElement exists in HTMLUnit,
but not as part of the DOM Level 2 HTML API. This, however,
is in my opinion a bug in HtmlUnit.


Date: 2006-11-13 09:45
Sender: mguillemProject Admin

Logged In: YES
user_id=402164

We will try to integrate Prototype's unit test to be run
with htmlunit to ensure that htmlunit is "Prototype
compatible" (idea from Daniel Gredler).


Date: 2006-11-10 17:15
Sender: gpolya

Logged In: YES
user_id=1642385

You can just comment the offending lines out. You don't need
to actually change the prototype.js itself; you can use a
script pre-processor to do that:

<code>
WebClient webClient = new WebClient();

// This is needed as htmlunit 1.10 cannot handle
prototype 1.5.0_rc1
webClient.setScriptPreProcessor(new ScriptPreProcessor() {
public String preProcess(HtmlPage page, String
scriptCode, String scriptName, HtmlElement element) {
if(scriptName.endsWith("prototype.js")) {
// comment the couple of lines out htmlunit can't
handle
scriptCode =
scriptCode.replaceFirst("copy\\(Element\\.Methods,
HTMLElement\\.prototype\\);", "/*copy(Element.Methods,
HTMLElement.prototype);");
scriptCode =
scriptCode.replaceFirst("_nativeExtensions = true;",
"_nativeExtensions = true;*/");
}
return scriptCode;
}
});
</code>

I'm not a prototype expert, so I can't really say if that
has some nasty side effects. But I didn't have any problems
after making this change. I used HtmlUnit 1.10 and Prototype
1.5.0_rc1 directly without WebTest or Scriptaculous.


Comments have been closed for this artifact.

Attached File

No Files Currently Attached

Changes ( 4 )

Field Old Value Date By
status_id Open 2007-06-05 09:43 mguillem
resolution_id None 2007-06-05 09:43 mguillem
assigned_to nobody 2007-06-05 09:43 mguillem
close_date - 2007-06-05 09:43 mguillem