Changeset 14632 for trunk/FACT++


Ignore:
Timestamp:
11/17/12 01:24:15 (12 years ago)
Author:
tbretz
Message:
Removed fGlobalcontext, using the one bound in which th function/object was created instead; removed obsolte handles to FunctionTemplates, using the callee object instead.
Location:
trunk/FACT++/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/InterpreterV8.cc

    r14631 r14632  
    2727v8::Handle<v8::FunctionTemplate> InterpreterV8::fTemplateLocal;
    2828v8::Handle<v8::FunctionTemplate> InterpreterV8::fTemplateSky;
    29 v8::Handle<v8::FunctionTemplate> InterpreterV8::fTemplateMoon;
    30 v8::Handle<v8::FunctionTemplate> InterpreterV8::fTemplateDatabase;
     29//v8::Handle<v8::FunctionTemplate> InterpreterV8::fTemplateMoon;
     30//v8::Handle<v8::FunctionTemplate> InterpreterV8::fTemplateDatabase;
    3131
    3232
     
    147147    const HandleScope handle_scope;
    148148
    149     fGlobalContext->Enter();
     149    func->CreationContext()->Enter();
    150150
    151151    TryCatch exception;
     
    301301    if (rc.index>-256 && !date.IsEmpty())
    302302        obj->Set(String::New("time"),  date);
    303 
    304     //obj->Set(String::New("toString"),  String::New(("[Object state "+string(*str)+":"+to_string(rc.index)+"]").c_str()));
    305303
    306304    return handle_scope.Close(obj->NewInstance());
     
    679677        HandleScope handle_scope;
    680678
     679        //if (!args.IsConstructCall())
     680        //    return Constructor(fTemplateDatabase, args);
     681
    681682        Database *db = new Database(*String::Utf8Value(args[0]));
    682683        fDatabases.push_back(db);
    683684
    684685        Handle<Object> This = args.This();
    685         if (!args.IsConstructCall())
    686             This = fTemplateDatabase->PrototypeTemplate()->NewInstance();
    687         if (This.IsEmpty())
    688             return Undefined();
    689 
    690686        This->Set(String::New("user"),     String::New(db->user.c_str()), ReadOnly);
    691687        This->Set(String::New("server"),   String::New(db->server.c_str()), ReadOnly);
     
    756752    }
    757753
    758     args.Holder()->Set(String::New("isOpen"), Boolean::New(false), ReadOnly);
     754    args.This()->Set(String::New("isOpen"), Boolean::New(false), ReadOnly);
    759755
    760756    return handle_scope.Close(Boolean::New(JsUnsubscribe(*str)));
     
    999995    const HandleScope handle_scope;
    1000996
    1001     fGlobalContext->Enter();
    1002 
    1003     Handle<Object> obj = it->second;
    1004     if (obj.IsEmpty())
    1005         return;
     997    Persistent<Object> obj = it->second;
     998
     999    obj->CreationContext()->Enter();
    10061000
    10071001    const Handle<String> onchange = String::New("onchange");
     
    10401034}
    10411035
    1042 Handle<Value> InterpreterV8::OnChangeSet(Local<String> prop, Local< Value > value, const AccessorInfo &)
     1036Handle<Value> InterpreterV8::OnChangeSet(Local<String> prop, Local<Value> value, const AccessorInfo &)
    10431037{
    10441038    // Returns the value if the setter intercepts the request. Otherwise, returns an empty handle.
     
    10531047
    10541048    if (value->IsFunction())
    1055         fStateCallbacks[server] = Persistent<Value>::New(value);
     1049        fStateCallbacks[server] = Persistent<Object>::New(value->ToObject());
    10561050
    10571051    return Handle<Value>();
     
    10741068    }
    10751069
    1076     if (it->second.IsEmpty() || !it->second->IsFunction())
    1077         return;
     1070    it->second->CreationContext()->Enter();
    10781071
    10791072    const HandleScope handle_scope;
    1080 
    1081     fGlobalContext->Enter();
    10821073
    10831074    // -------------------------------------------------------------------
     
    11011092
    11021093    Handle<Value> args[] = { obj->NewInstance() };
    1103     Handle<Function> fun = Handle<Function>::Cast(it->second);
     1094    Handle<Function> fun = Handle<Function>(Function::Cast(*it->second));
    11041095    fun->Call(fun, 1, args);
    11051096
     
    13551346    // ----------------------------
    13561347
    1357     Handle<Object> This = args.This();
    13581348    if (!args.IsConstructCall())
    1359         This = fTemplateMoon->PrototypeTemplate()->NewInstance();
    1360     if (This.IsEmpty())
    1361         return Undefined();
     1349        return Constructor(args);
    13621350
    13631351    Handle<Function> function =
     
    13661354        return Undefined();
    13671355
     1356    Handle<Object> This = args.This();
    13681357    This->Set(String::New("ra"),      Number::New(equ.ra/15),  ReadOnly);
    13691358    This->Set(String::New("dec"),     Number::New(equ.dec),    ReadOnly);
     
    13921381    HandleScope handle_scope;
    13931382
    1394     Handle<Object> This = args.This();
    13951383    if (!args.IsConstructCall())
    1396         This = fTemplateSky->PrototypeTemplate()->NewInstance();
    1397     if (This.IsEmpty())
    1398         return Undefined();
     1384        return Constructor(args);
    13991385
    14001386    Handle<Function> function =
     
    14031389        return Undefined();
    14041390
     1391    Handle<Object> This = args.This();
    14051392    This->Set(String::New("ra"),      Number::New(ra),  ReadOnly);
    14061393    This->Set(String::New("dec"),     Number::New(dec), ReadOnly);
     
    14201407        return ThrowException(String::New("Third argument must be a Date."));
    14211408
    1422 
    14231409    const double zd = args[0]->NumberValue();
    14241410    const double az = args[1]->NumberValue();
     
    14311417    HandleScope handle_scope;
    14321418
    1433     Handle<Object> This = args.This();
    14341419    if (!args.IsConstructCall())
    1435         This = fTemplateLocal->PrototypeTemplate()->NewInstance();
    1436     if (This.IsEmpty())
    1437         return Undefined();
     1420        return Constructor(args);
    14381421
    14391422    Handle<Function> function =
     
    14421425        return Undefined();
    14431426
     1427    Handle<Object> This = args.This();
    14441428    This->Set(String::New("zd"),    Number::New(zd), ReadOnly);
    14451429    This->Set(String::New("az"),    Number::New(az), ReadOnly);
     
    16001584//                                  CORE
    16011585// ==========================================================================
     1586
     1587Handle<Value> InterpreterV8::Constructor(/*Handle<FunctionTemplate> T,*/ const Arguments &args)
     1588{
     1589    Handle<Value> argv[args.Length()];
     1590
     1591    for (int i=0; i<args.Length(); i++)
     1592        argv[i] = args[i];
     1593
     1594    return args.Callee()->NewInstance(args.Length(), argv);
     1595}
     1596
    16021597
    16031598void InterpreterV8::AddFormatToGlobal() const
     
    17061701    global->Set(String::New("Database"), db, ReadOnly);
    17071702
    1708     fTemplateDatabase = db;
    1709 
    17101703#ifdef HAVE_NOVA
    17111704    Handle<FunctionTemplate> sky = FunctionTemplate::New(ConstructorSky);
     
    17251718    fTemplateLocal = loc;
    17261719    fTemplateSky   = sky;
    1727     fTemplateMoon  = moon;
    17281720#endif
    17291721
    17301722    // Persistent
    1731     fGlobalContext = Context::New(NULL, global);
    1732     if (fGlobalContext.IsEmpty())
     1723    Persistent<Context> context = Context::New(NULL, global);
     1724    if (context.IsEmpty())
    17331725    {
    17341726        //printf("Error creating context\n");
     
    17361728    }
    17371729
    1738     Context::Scope scope(fGlobalContext);
     1730    Context::Scope scope(context);
    17391731
    17401732    Handle<Array> args = Array::New(map.size());
    17411733    for (auto it=map.begin(); it!=map.end(); it++)
    17421734        args->Set(String::New(it->first.c_str()), String::New(it->second.c_str()));
    1743     fGlobalContext->Global()->Set(String::New("$"),   args, ReadOnly);
    1744     fGlobalContext->Global()->Set(String::New("arg"), args, ReadOnly);
     1735    context->Global()->Set(String::New("$"),   args, ReadOnly);
     1736    context->Global()->Set(String::New("arg"), args, ReadOnly);
    17451737
    17461738    //V8::ResumeProfiler();
     
    18121804    fStates.clear();
    18131805
    1814     fGlobalContext.Dispose();
     1806    context.Dispose();
    18151807
    18161808    JsEnd(filename);
  • trunk/FACT++/src/InterpreterV8.h

    r14629 r14632  
    2727    std::set<int> fThreadIds;
    2828
    29     v8::Persistent<v8::Context> fGlobalContext;
    30 
    3129    // A loookup table which allows to indentify the
    3230    // the JavaScript object corrsponding to the
     
    3634
    3735    // Lookup table for the callbacks in cases of state changes
    38     std::map<std::string, v8::Persistent<v8::Value>> fStateCallbacks;
     36    std::map<std::string, v8::Persistent<v8::Object>> fStateCallbacks;
    3937
    4038    // List of all timeout threads
     
    4644    static v8::Handle<v8::FunctionTemplate> fTemplateLocal;
    4745    static v8::Handle<v8::FunctionTemplate> fTemplateSky;
    48     static v8::Handle<v8::FunctionTemplate> fTemplateMoon;
    49     static v8::Handle<v8::FunctionTemplate> fTemplateDatabase;
     46    //static v8::Handle<v8::FunctionTemplate> fTemplateMoon;
     47    //static v8::Handle<v8::FunctionTemplate> fTemplateDatabase;
    5048
    5149#ifdef HAVE_SQL
     
    8886
    8987    static double GetDataMember(const v8::Arguments &args, const char *name);
     88    static v8::Handle<v8::Value> Constructor(const v8::Arguments &args);
    9089
    9190    static v8::Handle<v8::Value> LocalToString(const v8::Arguments &args);
Note: See TracChangeset for help on using the changeset viewer.