Re: Web scripting key does not work

aglee <[email protected]> Wed, 20 Oct 2010 14:53:55 +0000 (GMT)
Newsgroups gmane.comp.macosx.devel
Message-ID <[email protected]>
I tried the same thing in our WebView and got

[<MyClass 0x4cea90> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key foo.

I suspect you can't use dot notation in JavaScript to access Objective-C properties, because window.myObject.foo would be ambiguous -- is its value the property value, or is it the *function* that retrieves the property value?  To illustrate, if in the JavaScript I do alert(window.myObject.foo), the alert message is:

function foo() {
    [native code]
}

I played with this a while back but I don't remember what the docs said.

--Andy


On Oct 20, 2010, at 09:18 AM, Christiaan Hofman <[email protected]> wrote:

I am trying to make a key for an object available to javascript in a webview. I have been able to successfully do this for calling methods on the object, but exposing the key does not work. I have followed all the prescriptions in the documentation:

- Implemented -webView:didClearWindowObject:forFrame: in the WebFrameLoadDelegate

- (void)webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)windowObject forFrame:(WebFrame *)frame {
[windowObject setValue:[FOO sharedInstance] forKey:@"foo"];
}

- Implemented +isKeyExcludedFromWebScript: on the class (Foo) for the exposed object, returning NO for the (KVC compliant) key I want to expose.

+ (BOOL)isKeyExcludedFromWebScript:(const char *)name {
return strcmp(name, "bar") != 0;
}

Now when I try to set the key of the object in a JavaScript function on a page loaded in my webview (window.foo.bar = true), the KVC compliant setter is never called, and nothing happens. As I said, calling a function for an exposed selector from JavaScript does work, the method is properly called.

Is this a bug, or has webkit stopped supporting this, or is there something else I forgot?

thanks,
Christiaan

_______________________________________________
MacOSX-dev mailing list
[email protected]
http://www.omnigroup.com/mailman/listinfo/macosx-dev