jQuery in Caja

8 views
Skip to first unread message

Matthew Wild

unread,
Mar 18, 2009, 5:46:36 PM3/18/09
to Google Caja Discuss
Hi all,

I'm fairly new to using Caja, but have managed to get to grips with
most of the concepts.

We are looking to embed third-party plugins/gadgets into our site.
Ideally we would like to provide jQuery to gadget developers, and am
wondering about the current status of jQuery in Caja at the moment.

With testing here I have been unable to get the latest stock jQuery to
work when cajoled, it produces errors like "Not found: $" or "Not
settable: $". However the older jQuery in the Caja SVN repository
experimental/ section appears to work. I'm not sure if it works simply
by virtue of being an older version, or because it has been patched to
work.

I'm currently stuck with the jQuery star rating plugin not working, it
throws an error I haven't come across before:

[Exception... "'TypeError: Cannot read property "elem" from undefined'
when calling method: [nsIDOMEventListener::handleEvent]" nsresult:
"0x8057001c (NS_ERROR_XPC_JS_THREW_JS_OBJECT)" location: "<unknown>"
data: no]

It is without location information or a stack trace, but happens only
when clicking on the ratings icons.

Suggestions on where to begin debugging would be appreciated. I tried
the "sidebyside" renderer without success, receiving this unhandled
exception:

Command: $ ./pristine/google-caja-read-only/bin/cajole_html -i
jquery.html -a -r sidebyside

java.lang.IndexOutOfBoundsException: Index: 5, Size: 5
at java.util.ArrayList.rangeCheck(ArrayList.java:571)
at java.util.ArrayList.get(ArrayList.java:349)
at
com.google.caja.render.SourceSnippetRenderer.addEvidenceForCurrentMark
(SourceSnippetRenderer.java:243)
at com.google.caja.render.SourceSnippetRenderer.processCurrentMark
(SourceSnippetRenderer.java:225)
at com.google.caja.render.SourceSnippetRenderer.noMoreTokens
(SourceSnippetRenderer.java:196)
at com.google.caja.plugin.PluginCompilerMain.writeFileNonDebug
(PluginCompilerMain.java:243)
at com.google.caja.plugin.PluginCompilerMain.writeFile
(PluginCompilerMain.java:212)
at com.google.caja.plugin.PluginCompilerMain.run
(PluginCompilerMain.java:125)
at com.google.caja.plugin.PluginCompilerMain.main
(PluginCompilerMain.java:329)

I'm using the latest code from SVN. Is this my mistake, or a bug?

If you know of any other information that might help diagnose the
issue, do let me know.

Regards,
Matthew.

Mike Stay

unread,
Mar 18, 2009, 6:32:05 PM3/18/09
to google-ca...@googlegroups.com
On Wed, Mar 18, 2009 at 2:46 PM, Matthew Wild <MWi...@gmail.com> wrote:
>
> Hi all,
>
> I'm fairly new to using Caja, but have managed to get to grips with
> most of the concepts.
>
> We are looking to embed third-party plugins/gadgets into our site.
> Ideally we would like to provide jQuery to gadget developers, and am
> wondering about the current status of jQuery in Caja at the moment.

I've been working on getting jquery to work with caja, and I just got
a jquery gadget working with caja yesterday. There are two changes
submitted to jquery itself (4251, 4270) and one more that needs to go
into caja.

> I'm currently stuck with the jQuery star rating plugin not working, it
> throws an error I haven't come across before:
>
> [Exception... "'TypeError: Cannot read property "elem" from undefined'
> when calling method: [nsIDOMEventListener::handleEvent]" nsresult:
> "0x8057001c (NS_ERROR_XPC_JS_THREW_JS_OBJECT)" location: "<unknown>"
> data: no]
>
> It is without location information or a stack trace, but happens only
> when clicking on the ratings icons.

The jquery library regularly assumes that the entire DOM is
implemented and does not check return values to see if they are
objects on which it can read properties; in this case, some method
returned undefined and it tried to read the property "elem" on it.

If you can send us jquery.html, we can have a look and see what's
causing the error--that may be a new bug in the cajoler.

--
Mike Stay - meta...@gmail.com
http://math.ucr.edu/~mike
http://reperiendi.wordpress.com

Matthew Wild

unread,
Mar 20, 2009, 9:02:23 AM3/20/09
to google-ca...@googlegroups.com
Hi,

On Wed, Mar 18, 2009 at 10:32 PM, Mike Stay <meta...@gmail.com> wrote:
>
> On Wed, Mar 18, 2009 at 2:46 PM, Matthew Wild <MWi...@gmail.com> wrote:
>>
>> Hi all,
>>
>> I'm fairly new to using Caja, but have managed to get to grips with
>> most of the concepts.
>>
>> We are looking to embed third-party plugins/gadgets into our site.
>> Ideally we would like to provide jQuery to gadget developers, and am
>> wondering about the current status of jQuery in Caja at the moment.
>
> I've been working on getting jquery to work with caja, and I just got
> a jquery gadget working with caja yesterday.  There are two changes
> submitted to jquery itself (4251, 4270) and one more that needs to go
> into caja.
>

I'm guessing 4251/4270 refer to jQuery changesets/revisions?

>> I'm currently stuck with the jQuery star rating plugin not working, it
>> throws an error I haven't come across before:
>>
>> [Exception... "'TypeError: Cannot read property "elem" from undefined'
>> when calling method: [nsIDOMEventListener::handleEvent]" nsresult:
>> "0x8057001c (NS_ERROR_XPC_JS_THREW_JS_OBJECT)" location: "<unknown>"
>> data: no]
>>
>> It is without location information or a stack trace, but happens only
>> when clicking on the ratings icons.
>
> The jquery library regularly assumes that the entire DOM is
> implemented and does not check return values to see if they are
> objects on which it can read properties; in this case, some method
> returned undefined and it tried to read the property "elem" on it.
>

So I guess this is also a problem in my code. I'll check it over.

>> Suggestions on where to begin debugging would be appreciated. I tried
>> the "sidebyside" renderer without success, receiving this unhandled
>> exception:
>>
>> Command: $ ./pristine/google-caja-read-only/bin/cajole_html -i
>> jquery.html -a -r sidebyside
>>
>> java.lang.IndexOutOfBoundsException: Index: 5, Size: 5
>>        at java.util.ArrayList.rangeCheck(ArrayList.java:571)
>>        at java.util.ArrayList.get(ArrayList.java:349)
>>        at
>> com.google.caja.render.SourceSnippetRenderer.addEvidenceForCurrentMark
>> (SourceSnippetRenderer.java:243)
>>        at com.google.caja.render.SourceSnippetRenderer.processCurrentMark
>> (SourceSnippetRenderer.java:225)
>>        at com.google.caja.render.SourceSnippetRenderer.noMoreTokens
>> (SourceSnippetRenderer.java:196)
>>        at com.google.caja.plugin.PluginCompilerMain.writeFileNonDebug
>> (PluginCompilerMain.java:243)
>>        at com.google.caja.plugin.PluginCompilerMain.writeFile
>> (PluginCompilerMain.java:212)
>>        at com.google.caja.plugin.PluginCompilerMain.run
>> (PluginCompilerMain.java:125)
>>        at com.google.caja.plugin.PluginCompilerMain.main
>> (PluginCompilerMain.java:329)
>>
>> I'm using the latest code from SVN. Is this my mistake, or a bug?
>>

> If you can send us jquery.html, we can have a look and see what's
> causing the error--that may be a new bug in the cajoler.
>

I trimmed it right down to just this line:

<script type="text/javascript" src="jquery.js"></script>

and jquery.js in the same folder, version 1.2.6 from the Caja
experimental/jquery/tests/ folder.

I still get the traceback, although the index in
"java.lang.IndexOutOfBoundsException: Index: 1, Size: 1" decreased
with each line I removed (it essentially stays in step with the number
of lines in the file).

I have uploaded the exact files I am using to:
http://matthewwild.co.uk/uploads/jquery-caja-fail.tar.gz (unpacks
jquery.html and jquery.js into the current directory)

Hope this helps,
Matthew.

Mike Stay

unread,
Mar 20, 2009, 7:32:39 PM3/20/09
to google-ca...@googlegroups.com
On Fri, Mar 20, 2009 at 6:02 AM, Matthew Wild <mwi...@gmail.com> wrote:
> I'm guessing 4251/4270 refer to jQuery changesets/revisions?

Yes, on the latest revision of jQuery 1.3.2

> and jquery.js in the same folder, version 1.2.6 from the Caja

Oh! That version is horribly out of date, sorry! Find attached a
patch for the latest version of jQuery (6292) [this includes the
patches mentioned above].

Cajole the index page in the test folder:
google-caja/bin/cajole_html -i index.html -o index.js -a
Included in the patch is hostpage.html that hosts the cajoled output, index.js.

Also attached is a stopgap patch for FileSystemEnvironment.java. At
the moment (in trunk) you're only allowed to link to files under the
same directory. This patch allows you to link to arbitrary URLs. If
you want to rewrite those URLs to use your proxy or something, then
change this file. Eventually we'll have a config file for this.

fsediff
jqdiff

Matthew Wild

unread,
Mar 23, 2009, 11:09:06 AM3/23/09
to google-ca...@googlegroups.com
Hi Mike,

Thanks. When building the index.html for jQuery, I get:

WARNING: index.html:14+33 - 36: failed to load external url
../dist/jquery.js

I added || uristr.startsWith("../") [also tried file://] to the
condition in FileSystemEnvironment.java, but it seemed to make no
difference. I suspect I'm looking in the wrong place.

Anyhow, I copied jquery.js to the test/ directory, and fixed
index.html for this. Next cajole_html failed with:

ERROR: testsuite.css:50+11 - 15: css property opacity has bad
value: ==>auto<==

I commented out the <link> line from index.html and cajole_html
succeeded (with some LINT/WARNING messages about folding tags).

Loading up the hostpage.html in Firefox caused Firefox to lock up. No
idea how to debug that one. Eventually I managed to get the page
loaded, and was greeted with nothing but these errors in Firebug:
http://matthewwild.co.uk/uploads/jquery-cajoled-test-errors.png

Changing course I decided to try the new cajoled jquery with my simple
test gadget. Everything works fine until I load it up in Firefox,
where it throws: "not found: $".

I have collected together what I hope to be all the files and
dependencies into this tarball, should you wish to have a look:
http://matthewwild.co.uk/uploads/caja-jquery-not-found.tar.gz

Hopefully I'm missing something simple.

Also, attempting to use -r sidebyside on jquery.html still triggers an
exception (see previous email).

Many thanks for your help so far!
Matthew.

Mike Stay

unread,
Mar 24, 2009, 11:49:28 AM3/24/09
to google-ca...@googlegroups.com
Hi--I spent a while yesterday working on this. Turns out that "svn
diff" won't give you differences in external dependencies (like qunit/
under test/) so there were bits missing from the patch I sent you.
Also, when I updated both jquery and caja, something stopped working.
I won't be working on it today--I'm moving house--but I'll probably
have it all working for you by the end of Wednesday.

--

Matthew Wild

unread,
Mar 24, 2009, 12:52:07 PM3/24/09
to google-ca...@googlegroups.com
Hi,

On Tue, Mar 24, 2009 at 3:49 PM, Mike Stay <meta...@gmail.com> wrote:
>
> Hi--I spent a while yesterday working on this.  Turns out that "svn
> diff" won't give you differences in external dependencies (like qunit/
> under test/) so there were bits missing from the patch I sent you.
> Also, when I updated both jquery and caja, something stopped working.

That's the way it tends to go in computing. :)

> I won't be working on it today--I'm moving house--but I'll probably
> have it all working for you by the end of Wednesday.
>

Likewise, so I know how it is.

Many thanks for your help, I'll be standing by.
Matthew.

Mike Stay

unread,
Mar 25, 2009, 6:59:08 PM3/25/09
to google-ca...@googlegroups.com
OK, here's what I've got. Save the attached patch files to /tmp

cd ~/caja/svn-changes
mkdir fresh
cd fresh
svn checkout http://google-caja.googlecode.com/svn/trunk/ google-caja
cd google-caja
patch -p0 < /tmp/fsediff
ant
ant testbed

cd ~/jquery
svn co http://jqueryjs.googlecode.com/svn/trunk .
cd jquery
patch -p0 < /tmp/jqdiff
make
cd test
ln -s ~/caja/svn-changes/fresh/google-caja/ant-www/testbed caja
ln -s ../dist/jquery.js
~/caja/svn-changes/fresh/google-caja/bin/cajole_html -i index.html -o
index.js -a -r sidebyside

Now browse to ~/jquery/jquery/test/hostpage.html to see the jquery tests.

This will take a *long* time (minutes) to render completely, and locks
up the browser thread in the meantime. But it eventually finishes, so
just let it go.

fsediff
jqdiff
Reply all
Reply to author
Forward
0 new messages