Discussion:
[Caja] Syntax error when following example code
j***@lifelink.com
2017-08-23 14:23:48 UTC
Permalink
I'm following the "Running Plain Javascript" example in the documentation.

Instead of referencing an external URL, I'm passing in a javascript string:

caja.load(undefined, undefined, function(frame) {
frame.code('return function f(x) { return 1; }', 'application/javascript')
.run();
});

I'm getting:

*Uncaught SyntaxError: Failed to parse program: SyntaxError: Unexpected
token (1:15) in source: "return function f(x) { return 1; }" at line: -1*

The API reference documentation appears to be broken or moved, so I'm
having trouble digging into the exact issue.

Any ideas?

Thanks, Justin
--
---
You received this message because you are subscribed to the Google Groups "Google Caja Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-caja-discuss+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Mark Miller
2017-08-23 15:52:25 UTC
Permalink
What happens if you remove the "return"?
Post by j***@lifelink.com
I'm following the "Running Plain Javascript" example in the documentation.
caja.load(undefined, undefined, function(frame) {
frame.code('return function f(x) { return 1; }',
'application/javascript')
.run();
});
*Uncaught SyntaxError: Failed to parse program: SyntaxError: Unexpected
token (1:15) in source: "return function f(x) { return 1; }" at line: -1*
The API reference documentation appears to be broken or moved, so I'm
having trouble digging into the exact issue.
Any ideas?
Thanks, Justin
--
---
You received this message because you are subscribed to the Google Groups
"Google Caja Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
Cheers,
--MarkM
--
---
You received this message because you are subscribed to the Google Groups "Google Caja Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-caja-discuss+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Mike Stay
2017-08-23 15:55:57 UTC
Permalink
There's no index.html in
https://github.com/google/caja/tree/master/doc/cajajs
and the developer page still points at the old site.

Here's a recentish version of the API I found on archive.org.
http://web.archive.org/web/20150428055114/http://google-caja.googlecode.com/svn/doc/cajajs/index.html
Post by Mark Miller
What happens if you remove the "return"?
Post by j***@lifelink.com
I'm following the "Running Plain Javascript" example in the documentation.
caja.load(undefined, undefined, function(frame) {
frame.code('return function f(x) { return 1; }',
'application/javascript')
.run();
});
Uncaught SyntaxError: Failed to parse program: SyntaxError: Unexpected
token (1:15) in source: "return function f(x) { return 1; }" at line: -1
The API reference documentation appears to be broken or moved, so I'm
having trouble digging into the exact issue.
Any ideas?
Thanks, Justin
--
---
You received this message because you are subscribed to the Google Groups
"Google Caja Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
Cheers,
--MarkM
--
---
You received this message because you are subscribed to the Google Groups
"Google Caja Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
Mike Stay - ***@gmail.com
http://www.cs.auckland.ac.nz/~mike
http://reperiendi.wordpress.com
--
---
You received this message because you are subscribed to the Google Groups "Google Caja Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-caja-discuss+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Mike Stay
2017-08-23 17:20:27 UTC
Permalink
In particular, there's this snippet:
-------------------
Running guest JavaScript from content

The following code in a host page:

/* host page code */
caja.initialize({ cajaServer: 'http://caja.appspot.com' });
caja.load(
undefined, // no DOM access
undefined, // no network access
function(frame) {
frame.code(
'http://example.com/default.js', // dummy URL
'application/javascript',
'(x + y);') // input source code
.api({ x: 3, y: 4 })
.run(function(result) {
alert(result);
});
});

will run the provided source, pass it the supplied values of x and y,
and alert the result of the computation, which would be the number 7.
-------------------

so it looks like what you need to do is move the source code parameter
to the end, make sure it's a valid program, and give it a dummy URL in
the first slot.
Post by Mike Stay
There's no index.html in
https://github.com/google/caja/tree/master/doc/cajajs
and the developer page still points at the old site.
Here's a recentish version of the API I found on archive.org.
http://web.archive.org/web/20150428055114/http://google-caja.googlecode.com/svn/doc/cajajs/index.html
Post by Mark Miller
What happens if you remove the "return"?
Post by j***@lifelink.com
I'm following the "Running Plain Javascript" example in the documentation.
caja.load(undefined, undefined, function(frame) {
frame.code('return function f(x) { return 1; }',
'application/javascript')
.run();
});
Uncaught SyntaxError: Failed to parse program: SyntaxError: Unexpected
token (1:15) in source: "return function f(x) { return 1; }" at line: -1
The API reference documentation appears to be broken or moved, so I'm
having trouble digging into the exact issue.
Any ideas?
Thanks, Justin
--
---
You received this message because you are subscribed to the Google Groups
"Google Caja Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
Cheers,
--MarkM
--
---
You received this message because you are subscribed to the Google Groups
"Google Caja Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
http://www.cs.auckland.ac.nz/~mike
http://reperiendi.wordpress.com
--
Mike Stay - ***@gmail.com
http://www.cs.auckland.ac.nz/~mike
http://reperiendi.wordpress.com
--
---
You received this message because you are subscribed to the Google Groups "Google Caja Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-caja-discuss+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...