Permalink
Browse files

JavascriptCore: updated documentation about how to register an initia…

…lized module.
  • Loading branch information...
1 parent 1df7ca7 commit 5d307b2cbfc9e2caa06805df425161617868bea8 @oliver---- oliver---- committed May 27, 2014
Showing with 21 additions and 3 deletions.
  1. +21 −3 Doc/Manual/Javascript.html
View
@@ -223,13 +223,21 @@
<pre>
#import "appDelegate.h"
-extern bool example_initialize(JSGlobalContextRef context);
+extern bool example_initialize(JSGlobalContextRef context, JSObjectRef* exports);
@implementation ExampleAppDelegate
@synthesize webView;
+- (void)addGlobalObject:(JSContextRef) context:(NSString *)objectName:(JSObjectRef) theObject {
+ JSObjectRef global = JSContextGetGlobalObject(context);
+ JSStringRef objectJSName = JSStringCreateWithCFString( (CFStringRef) objectName )
+ if ( objectJSName != NULL ) {
+ JSObjectSetProperty(context, global, objectJSName, theObject, kJSPropertyAttributeReadOnly, NULL);
+ JSStringRelease( objectJSName );
+ }
+}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
@@ -240,7 +248,11 @@
WebFrame *webframe = [webView mainFrame];
JSGlobalContextRef context = [webframe globalContext];
- example_initialize(context);
+ JSObjectRef example;
+ example_initialize(context, &amp;example);
+ [self addGlobalObject:context:@"example":example]
+
+ JSObjectSetProperty(context, global, JSStringRef propertyName, example, JSPropertyAttributes attributes, NULL);
[ [webView mainFrame] loadRequest:
[NSURLRequest requestWithURL: [NSURL URLWithString:url] ]
@@ -273,7 +285,13 @@
WebKitWebView *webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
WebFrame *webframe = webkit_web_view_get_main_frame(webView);
JSGlobalContextRef context = webkit_web_frame_get_global_context(webFrame);
- example_initialize(context);
+ JSObjectRef global = JSContextGetGlobalObject(context);
+
+ JSObjectRef exampleModule;
+ example_initialize(context, &amp;exampleModule);
+ JSStringRef jsName = JSStringCreateWithUTF8CString("example");
+ JSObjectSetProperty(context, global, jsName, exampleModule, kJSPropertyAttributeReadOnly, NULL);
+ JSStringRelease(jsName);
...

0 comments on commit 5d307b2

Please sign in to comment.