At first instance both look similar. But the problem what I am facing is , In spidermonkey we can create one scope inside another . But if scopes are referred as contexts in V8 then we should be able to create one context inside another. But going by the documents, it is not possible to create one context inside another.
I can achieve this if i can create one object inside another and give names to the objects. Or else if I can create scope chain in single context. Eg. If we want to create a variable in object b which is in object a i can write the same in Javascript as follows: var a = new Object(); a.b = new Object(); a.b.c = 10; How can I do the same thing using V8 APIs? Regards, Manoj kumar On Aug 7, 1:20 pm, Søren Gjesse <[email protected]> wrote: > I think what you are referring to as scopes are what is called contexts in > V8. Each context is basically a definition of a global object, and > using Context::Scope > (or Context::Enter() and Context::Exit()) you can control which context is > used when calling into JavaScript. In Chromium each frame has a separate > context. > Regards, > Søren > > On Fri, Aug 7, 2009 at 09:51, Manoj Kumar <[email protected]> wrote: > > > By naming a scope I mean to say that whether we can define a name for > > a scope. For example there are two scope scope1 and scope2 and i want > > to create scope2 inside scope1,how can i do that. Also whether it is > > possible to name these scopes. > > > As in other jsengines like spidermonkey we can have different names > > for different scope by creating a new object inside other and defining > > a property (name) for the same.Is there some API in V8 which functions > > the same way. I have gone through the test programs but i was not able > > to find any such tests. > > > eg. If there are two scopes "session" and "application". and each have > > one JS variable sess1 and app1 respectively. I can access sess1 and > > app1 irrespective of the scope that i currently am using session.sess1 > > or application.app1.Also if application is created inside the session > > then we can access app1 using session.application.app1. > > > On Aug 7, 11:53 am, Søren Gjesse <[email protected]> wrote: > > > I am not sure what you mean with *suppose I have pushed a scope named > > > "session" through v8 api*, but I suggest you take a look at the API tests > > > (test/cctest/test-api-cc) where most ways of using the API is tested. > > Also I > > > suggest that you check for exceptions after script->Run() by either > > checking > > > for an empty handle on return or use a TryCatch construct from the API. > > Also > > > remember to set up a HandleScope before using handles. > > > > Regards, > > > Søren > > > > On Fri, Aug 7, 2009 at 07:31, Manoj Kumar <[email protected]> > > wrote: > > > > > Hi Anders, > > > > First of all thank you for link. > > > > Now, I have a question about creating object using v8 api. My question > > > > is that I want to create a object by using V8 APIs and access it > > > > through javascript code. e.g suppose I have pushed a scope named > > > > "session" through v8 api means session should be an javascript object. > > > > Now we compile and execute a js script like: > > > > > const char *jsCode = "var a = 5; var b = session.a;" > > > > Pesistent<Context> context = Context::New(); > > > > Context::Scope context_scope(context); > > > > Handle<String> source = String::New(jsCode); > > > > Handle<Script> script = Script::Compile(source); > > > > Handle<Value> result = script->Run(); > > > > > Next I want to get the value of "b" using my code: > > > > Context::Scope context_scope(context); > > > > Handle<String> source = String::New("b"); > > > > Handle<Value> result; > > > > Handle<Script> script = Script::Compile(source); > > > > Handle<Value> result = script->Run(); > > > > if(result->IsInt32()) > > > > fprintf(stderr, "Value of b = %d\n", result->Int32Value > > > > ()); > > > > > Please help me for doing above thing. If possible, please provide me > > > > sample code. > > > > > Thanks, > > > > Manoj --~--~---------~--~----~------------~-------~--~----~ v8-dev mailing list [email protected] http://groups.google.com/group/v8-dev -~----------~----~----~----~------~----~------~--~---
