Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Passing JSValueRefAndContextRef from one context to another
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Corey  
View profile  
 More options Sep 30 2011, 7:11 pm
From: Corey <probablyco...@gmail.com>
Date: Fri, 30 Sep 2011 16:11:31 -0700 (PDT)
Local: Fri, Sep 30 2011 7:11 pm
Subject: Passing JSValueRefAndContextRef from one context to another
If I have two JSCocoa instances (JS1 and JS2) is it possible to send
JSValueRefAndContextRef's from JS1 to JS2?

For example, can I pass a function from JS1 to JS2. Everything I've
read seems to indicate no, but I'm hoping I missed something!

Thanks,
Corey


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Patrick Geiller  
View profile  
 More options Oct 2 2011, 4:26 am
From: Patrick Geiller <parman...@gmail.com>
Date: Sun, 2 Oct 2011 10:26:54 +0200
Local: Sun, Oct 2 2011 4:26 am
Subject: Re: Passing JSValueRefAndContextRef from one context to another

> If I have two JSCocoa instances (JS1 and JS2) is it possible to send
> JSValueRefAndContextRef's from JS1 to JS2?

> For example, can I pass a function from JS1 to JS2. Everything I've
> read seems to indicate no, but I'm hoping I missed something!

There is a bridge to pass values from context to context, and a test that manipulates a WebView (which has its own context) from the existing JSCocoa test context.

ObjC part In JSCocoaController.m :
JSValueRef valueFromExternalContext(JSContextRef externalCtx, JSValueRef value, JSContextRef ctx)
JSValueRef valueToExternalContext(JSContextRef ctx, JSValueRef value, JSContextRef externalCtx)
JSValueRef boxedValueFromExternalContext(JSContextRef externalCtx, JSValueRef value, JSContextRef ctx)

JS part in Tests/35 webview.js. The test creates a Javascript WebView subclass and then manipulates its external javascript context :

                - (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
                {
                        // Global context is frame's window object
                        var w = sender.mainFrame.globalContext
                        ...
                        w.document.body.firstChild.nextSibling.style.backgroundColor = 'lime'
                        // Add a function to the external context
                        w['eval']('function addMe(a, b) { return a+b}')
                ...

The bridge does not let functions pass from context to context, because they might be closures. You can do this manually by using eval.

-Patrick


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »