On Mon, Jul 6, 2009 at 3:43 PM, 胡 波<h3282...@yahoo.com.cn> wrote: > Thank you for your answer! > > I think that our idea may be different.I want to extend subobject "widget" > to "window"object in webkit .because I want to add some application to > widget object,and make it inherited from the window object. > > can you help me ? thank you!!
Sorry, I wasn't aware WebKit had a widget property of the window object. If you are asking how do you extend the widget object that already belongs to the window object then you need to: 1. Retrieve a reference to the window object, I think you may need to use KJS::Window::retrieveWindow 2. Convert the object retrieved in step 1 (KJS::Window object) to a JSObjectRef using JSObjectRef winRef = toRef(window); 3. Use the JavaScriptCore function JSObjectGetProperty on the window object to retrieve the widget JSObjectRef object. 4. Once you have the widget JSObjectRef, then I assume you can add new methods or properties to it. Maybe someone else who knows more about this, or understands your request better, may be able to help you. > --- 09年7月6日,周一, Jack Wootton <jackwoot...@gmail.com> 写道: > > 发件人: Jack Wootton <jackwoot...@gmail.com> > 主题: Re: [webkit-dev] how to extend the javascript native object? > 收件人: "胡 波" <h3282...@yahoo.com.cn> > 抄送: webkit-dev@lists.webkit.org > 日期: 2009年7月6日,周一,下午5:22 > > On Sat, Jul 4, 2009 at 4:52 PM, 胡 波<h3282...@yahoo.com.cn> wrote: >> Thank you very much! >> >> I understand your steps,But I do not understand the implement process! In >> the samples you provide with me , I do not find the .cpp file. I want to >> get >> a sample for windows.Can you help me? >> >> my aim:"widget" object is the same the "history" object,for >> example,to:"widget" object: window.widget.(property/method),:to :"history" >> object,window.history.back(); >> >> thank you! >> > > In the JSPong example I linked, the first thing to look at should > probably be PongAI.js. Since this gives you an idea of what is being > achieved. Then read the ReadMe.txt to get an overview of the different > classes involved. You could then have a look at JSShape.m is where the > "ball" class is constructed and it's properties are associated with > Objective C implementation (by adding static values to the class > definition). > > There is one oddity though, I do not understand why NSObject is > inherited from, since I thought use of the JavaScriptCore API meant > that developers didn't have to inherit from classes in this > manner...that the API did this for them. Maybe someone on this > mailing list can help clarify this? > > > > >> --- 09年7月4日,周六, Jack Wootton <jackwoot...@gmail.com> 写道: >> >> 发件人: Jack Wootton jackwoot...@gmail.com >> 主题: Re: [webkit-dev] how to extend the javascript native object? >> 收件人: "胡 波" <h3282...@yahoo.com.cn> >> 抄送: webkit-dev@lists.webkit.org >> 日期: 2009年7月4日,周六,上午12:26 >> >> To add, it maybe useful to look at the following files in the >> JavaScriptCore (Although, personally I didn't find them particularly >> easy to understand.) >> >> JavaScriptCore\API\testapi.c >> testapi.js >> >> >> There are also some example programs that do what you want to do, only >> with different objects. >> >> JSPong: http://developer.apple.com/SampleCode/JSPong/index.html >> >> JSInterpreter: >> http://developer.apple.com/samplecode/JSInterpreter/index.html >> >> More programs can be found here: >> >> http://developer.apple.com/SampleCode/Cocoa/idxInternetWeb-date.html >> >> >> >> 2009/7/3 Jack Wootton <jackwoot...@gmail.com>: >>> Are you saying you wan to add a 'widget' property to the Window >>> object? If so, then the JavaScriptCore API has methods that will >>> help you: >>> >>> Here is the API: >>> >>> >>> >>> http://gemma.apple.com/documentation/Carbon/Reference/WebKit_JavaScriptCore_Ref/index.html#//apple_ref/doc/framework/javascriptcore_fw >>> >>> If this is what you wish to do, then the following is a rough guide of >>> what you need to do: >>> >>> 1. Create an empty class definition, you can create an empty class >>> definition using kJSClassDefinitionEmpty. >>> 2. Use the class definition with the JSCoreAPI method "JSClassCreate" >>> to create your class. >>> 3. Use your new class with JSObjectMake to create your new JSObject >>> (this will be your widget object). >>> 4 Use JSObjectSetProperty to add your new JSObject as a property of >>> the Window object. >>> >>> >>> On Fri, Jul 3, 2009 at 4:51 PM, 胡 波<h3282...@yahoo.com.cn> wrote: >>>> I want to extend the javascript native object,such as widget >>>> object,and >>>> make it inherit window object. That is to say,when the widget object is >>>> extended, and we can use it by the window.widget.(method/property) in >>>> the >>>> html document? >>>> ________________________________ >>>> 好玩贺卡等你发,邮箱贺卡全新上线! >>>> _______________________________________________ >>>> webkit-dev mailing list >>>> webkit-dev@lists.webkit.org >>>> http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev >>>> >>>> >>> >>> >>> >>> -- >>> Regards >>> Jack >>> >> >> >> >> -- >> Regards >> Jack >> >> ________________________________ >> 好玩贺卡等你发,邮箱贺卡全新上线! > > > > -- > Regards > Jack > > ________________________________ > 好玩贺卡等你发,邮箱贺卡全新上线! -- Regards Jack _______________________________________________ webkit-dev mailing list webkit-dev@lists.webkit.org http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev