How to use "a.b()" with multiple instance of JSCocoaController?

20 views
Skip to first unread message

benny

unread,
Mar 17, 2011, 10:25:41 PM3/17/11
to JSCocoa
Dear Helper.

I'm trying to use JSCocoa in the iPhone. And the usage is like this;

============================================================
<Common.js>
function func_common()
{
log("Im func_common")
}

<Specifilc.js>
function test()
{
log("Im test - calling func_common with . notation")
theCommon.func_common();
}
============================================================

To make it work, I've tried to code like this

<xxxViewController.m>

- (IBAction) test_jscocoa
{

id jsCommon = [JSCocoaController sharedController];
id path = [[NSBundle mainBundle] pathForResource:@"Common"
ofType:@"js"];
[jsCommon evalJSFile:path];

//
id jsSpecific = [[JSCocoaController alloc] init];
id path2 = [[NSBundle mainBundle] pathForResource:@"Specific"
ofType:@"js"];
[jsSpecific evalJSFile:path2];

[jsSpecific setObject:jsCommon withName:@"theCommon"];

//
[jsSpecific callFunction:@"test"];

}

============================================================

But I got the error like this;

2011-03-18 10:59:48.500 SampleJSCocoa[671:207] Im test - calling
func_common with . notation
2011-03-18 10:59:48.501 SampleJSCocoa[671:207] JSException: TypeError:
Result of expression 'theCommon.func_common' [undefined] is not a
function. on line 17 of /Users/eshysis/Library/Application Support/
iPhone Simulator/4.2/Applications/514EC8B3-DF66-4D47-AFE7-ACE2C2A0546D/
SampleJSCocoa.app/Specific.js

============================================================

I think that the basic/critical problem is on 'setObject' method.
-> [jsSpecific setObject:jsCommon withName:@"theCommon"];
Which object should be setObject ?

ie. Some js files can be in defferent instance of JSCocoa . And one
instace of js wants to access them with . notation in the js file.
What should I do to make the '.' notation in a js file ?

Thanks in advance.

Benny.

Patrick Geiller

unread,
Mar 18, 2011, 2:14:18 AM3/18/11
to jsc...@googlegroups.com
> I'm trying to use JSCocoa in the iPhone. And the usage is like this;

Note that JSCocoa uses JavascriptCore, which is a private framework on the iPhone. The app store licenses prohibits this, your app might be rejected.


> ie. Some js files can be in defferent instance of JSCocoa . And one
> instace of js wants to access them with . notation in the js file.
> What should I do to make the '.' notation in a js file ?

Patch JSCocoa to have it use an instance variable (add BOOL useAutoCall in JSCocoa's class definition in JSCocoaController.h) instead of the current global one.

-Patrick

benny

unread,
Mar 18, 2011, 6:29:07 AM3/18/11
to JSCocoa
Dear Geiller.
Thank you for your response.

> Note that JSCocoa uses JavascriptCore, which is a private framework on the iPhone. The app store licenses prohibits this, your app might be rejected.

But you've mentioned like this;
------------------------------------------------
(http://groups.google.com/group/jscocoa/browse_thread/thread/
a528b2d5a8a0b9be/76fa21404eb16eef?lnk=gst&q=license#76fa21404eb16eef)
>> They did relax the rules recently : http://www.appleinsider.com/articles/10/06/11/apple_relaxes_ios_sdk_t...
>> ... and JSCocoa uses the iPhone's JavascriptCore library. Maybe it could go through, or will someday. But just to be safe, don't depend on JSCocoa.
>> -Patrick
------------------------------------------------
I want to keep the hope that JSCocoa will be allowed.
Anyway, do you have an alternative of JSCocoa?


btw,
> Patch JSCocoa to have it use an instance variable (add BOOL useAutoCall in JSCocoa's class definition in JSCocoaController.h) instead of the current global one.

I used the most recent patch, "parmanoir-jscocoa-3008d25.zip". There
is 'useAutoCall' in JSCocoaController.h.
It's hard to understand your recommendation to use 'a.b()' notation in
a js.
I think that I failed to explain my problem.

What I want is;
The usage "theCommon.func_common(); " is an obligation of mine. (not
'()', '.' is what I want)
The a.b() notation must be acceptable on my-building-app.
Can you advice to accomplish it?

Best Regards.
- Benny.

benny

unread,
Mar 18, 2011, 6:55:25 AM3/18/11
to JSCocoa
Patrick

It seems that the . operation is working. No error!

But nothing happen!
That means 'theCommon.func_common' or 'theCommon.func_common()' does
not work.
Can you help this?

Best regards.
- Benny


Patrick Geiller

unread,
Mar 18, 2011, 8:40:06 AM3/18/11
to jsc...@googlegroups.com
> I want to keep the hope that JSCocoa will be allowed.

Since the license prohibits it, don't stake your app on it.

> Anyway, do you have an alternative of JSCocoa?

Someone suggested to bundle your own copy of JavascriptCore with your app. (Meaning downloading the Javascriptcore source, compiling it yourself, and including it as library in your project)
This would satisfy the app store requirement of "no private framework, no downloaded code".

> I used the most recent patch, "parmanoir-jscocoa-3008d25.zip". There
> is 'useAutoCall' in JSCocoaController.h.
> It's hard to understand your recommendation to use 'a.b()' notation in
> a js.
> I think that I failed to explain my problem.
>
> What I want is;
> The usage "theCommon.func_common(); " is an obligation of mine. (not
> '()', '.' is what I want)
> The a.b() notation must be acceptable on my-building-app.
> Can you advice to accomplish it?

[jsSpecific setUseAutoCall:NO];
This will apply to all jscocoa instances. If you want instance specific behaviour (what I understood from your first question), then you have to add an instance variable :

@interface JSCocoaController : NSObject {

JSGlobalContextRef ctx;
BOOL ownsContext;
id _delegate;

BOOL useAutoCall; // <----------------- add this for instance specific behaviour

> But nothing happen!
> That means 'theCommon.func_common' or 'theCommon.func_common()' does
> not work.
> Can you help this?

Why do you want multiple instances in the first place ? Why jsCommon and jsSpecific ?


-Patrick

benny

unread,
Mar 22, 2011, 6:32:13 AM3/22/11
to JSCocoa
Good day Patrick.

> Why do you want multiple instances in the first place ? Why jsCommon and jsSpecific ?

- I still want multiple instances.
- Because of it's an necessity from my customers.
- They use .js files with such / these manners.
1. One .js has the codes and variables - it's called as Common or
Global js.
2. Other which is called as local js, calls the function of Common.
3. ie. "theCommon.function" calling method is used by my customer.
- I think that '.' operation is the solution.
- So still I'm looking for the How.


Dear author of "Multiple JSCocoa instances" in "parmanoir-
jscocoa-3008d25"
It does not run and not work.
Would you fix the problem of it?

I've tried to solve it like these;
1. 64bit -> 32 bit from "Get Info"
2. Add "jslint-jscocoa.js" into the project.
3. And move it to "Copy Bundle resource" from Targets.
Then it can be run. But does not work.



Another favor to Patrick.
Could I send my sample source to you to check up my problem?
Or where can I post my sample source to be check up?

Best regards
- Benny

benny

unread,
Mar 27, 2011, 10:26:49 PM3/27/11
to JSCocoa
Dear Everybody.

In this thread, there's such guide.
> Since the license prohibits it, don't stake your app on it.

When I search in AppStore with such keywords, HTML or javascript,
I can find some interesting apps which have a script-capable.
And I can get Opera browser in AppStore, also.

I think that we can publish our JSCocoa-apps.

Yours faithfully
- Benny

Patrick Geiller

unread,
Apr 6, 2011, 7:41:23 PM4/6/11
to jsc...@googlegroups.com
> Dear author of "Multiple JSCocoa instances" in "parmanoir-
> jscocoa-3008d25"
> It does not run and not work.
> Would you fix the problem of it?

Hi Benny,

I don't have time right now. Try to find a way to go with a single instance.

> When I search in AppStore with such keywords, HTML or javascript,
> I can find some interesting apps which have a script-capable.
> And I can get Opera browser in AppStore, also.

The app store accepts script libraries that are packaged in your app. Right now JSCocoa uses JavascriptCore which is private on the iPhone. If you want to bundle your own copy of JavascriptCore with your app, it might work. But once again, don't stake your app on it.

-Patrick

송정현

unread,
Jul 20, 2011, 12:15:48 AM7/20/11
to jsc...@googlegroups.com
Hi. Patrick and everybody. 
It's long time ~ 
During so far, I've been with Lua. 
I think that Lua can be a  substitute of Javascript in iOS. 


Although I'm very sorry to mention Lua in JS group, but it's my status.
And I wanna close this thread.

Regards~
-Benny


2011/4/7 Patrick Geiller <parm...@gmail.com>
Reply all
Reply to author
Forward
0 new messages