Status: Unconfirmed Owner: [EMAIL PROTECTED] Labels: Type-Bug Pri-2 OS-All Area-Misc
New issue 4924 by marshall.law: Patch for CppBoundClass http://code.google.com/p/chromium/issues/detail?id=4924 After extending CppBoundClass to expose C++ APIs to Javascript, I found a few limitations in it's design: 1) You can't (easily) expose a secondary instance of a CppBoundClass to javascript as a member variable. 2) Retrieving attributes from passed-in Javascript objects is not pleasant (who wants to use NPAPI? ;) 3) There's no way to expose a getter/setter with custom semantics (i.e.. being bounds to a Function pointer, not just a member field in the Class) I've solved #1 and #2 by exposing a number of protected static function helpers and exposing a two new instance methods: ToNPObject() (useful for result->Set()), and CppVariantToCppBoundClass(variant) which you can cast your specific CppBoundClass extension. Just an example of the things you can do with this patch: class JsObject : public CppBoundClass { public: JsObject() { BindMethod("hello", &JsObject::hello); } void print(const CppArgumentList &args, CppVariant *result) { printf("[%s] %s\n", GetStringProperty(args[0], "time"), GetStringProperty(args[0], "message")); } void util() { } }; class BindingExample : public CppBoundClass { public: BindingExample() { JsObject *jsObject = new JsObject; object.Set(jsObject->ToNPObject()); BindProperty("object" &object); BindMethod("util", &BindingExample::util); } void util(const CppArgumentList &args, CppVariant *result) { JsObject *object = static_cast<JsObject*>(CppVariantToCppBoundClass(args[0])); object->util(); } CppVariant object; }; // the instance of BindingExample is bound as "example" example.object.print({time: new Date().toString(), message: "Hello World"}); example.util(example.object); I still haven't solved #3 above, but I'm hoping this patch will get the wheels rolling =) Attachments: cpp_bound_class_patch.txt 8.3 KB -- You received this message because you are listed in the owner or CC fields of this issue, or because you starred this issue. You may adjust your issue notification preferences at: http://code.google.com/hosting/settings --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Chromium-bugs" group. To post to this group, send email to chromium-bugs@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/chromium-bugs?hl=en -~----------~----~----~----~------~----~------~--~---