Syntax error when following example code

32 views
Skip to first unread message

jwi...@lifelink.com

unread,
Aug 23, 2017, 11:29:30 AM8/23/17
to Google Caja Discuss
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

Mark Miller

unread,
Aug 23, 2017, 11:52:47 AM8/23/17
to Google Caja Discuss
What happens if you remove the "return"?


--

---
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+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
  Cheers,
  --MarkM

Mike Stay

unread,
Aug 23, 2017, 11:55:59 AM8/23/17
to Google Caja Discuss
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

On Wed, Aug 23, 2017 at 9:52 AM, Mark Miller <eri...@gmail.com> wrote:
> What happens if you remove the "return"?
>
>
> On Wed, Aug 23, 2017 at 7:23 AM, <jwi...@lifelink.com> wrote:
>>
>> 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-dis...@googlegroups.com.
>> 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-dis...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Mike Stay - meta...@gmail.com
http://www.cs.auckland.ac.nz/~mike
http://reperiendi.wordpress.com

Mike Stay

unread,
Aug 23, 2017, 1:20:29 PM8/23/17
to Google Caja Discuss
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.
Reply all
Reply to author
Forward
0 new messages