Changeset 15139


Ignore:
Timestamp:
03/22/13 22:45:30 (9 years ago)
Author:
tbretz
Message:
Fixed a problem with the return value in the timeout function. The HandleScope was not properly closed. Just for sanity, I did that also for the Constructor calls in the Astronomy classes. Simplified the main loop in getData
File:
1 edited

Legend:

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

    r15138 r15139  
    148148    TryCatch exception;
    149149
    150     //const Handle<Script> sleep = Script::Compile(String::New("v8.sleep();"), String::New("internal"));
    151     //if (sleep.IsEmpty())
    152     //    return Undefined();
    153 
    154150    Handle<Function> func = Handle<Function>::Cast(args[1]);
    155151
     
    163159        const Handle<Value> rc = func->Call(func, args.Length()-2, argv);
    164160        if (!rc.IsEmpty() && !rc->IsUndefined())
    165             return rc;
     161            return handle_scope.Close(rc);
    166162
    167163        if (!null && Time()-t>=boost::posix_time::milliseconds(abs(timeout)))
    168164            break;
    169 
    170         // We cannot sleep directly because we have to give control back to
    171         // JavaScript ever now and then. This also allows us to catch
    172         // exceptions, either from the preemption or ConvertEvent
    173         //sleep->Run();
    174165
    175166        // Theoretically, the CPU usage can be reduced by maybe a factor
     
    12201211    HandleScope handle_scope;
    12211212
    1222     //const Handle<Script> sleep = Script::Compile(String::New("v8.sleep();"), String::New("internal"));
    1223     //if (sleep.IsEmpty())
    1224     //    return Undefined();
    1225 
    12261213    const Handle<String> data   = String::New("data");
    12271214    const Handle<String> object = String::New("obj");
     
    12441231
    12451232            // Protect against the return of an exception
    1246             if (!val.IsEmpty() && val->IsObject())
     1233            if (val->IsObject())
    12471234            {
    1248                 if (!named)
     1235                const Handle<Object> event = val->ToObject();
     1236                const Handle<Value>  obj   = event->Get(named?object:data);
     1237                if (!obj.IsEmpty())
    12491238                {
    1250                     const Handle<Object> event = val->ToObject();
    1251                     const Handle<Value>  obj   = event->Get(data);
    1252 
    1253                     // No names (no 'obj'), but 'data'
    1254                     if (!obj.IsEmpty() && !obj->IsUndefined())
    1255                         return handle_scope.Close(val);
    1256                 }
    1257                 else
    1258                 {
    1259                     const Handle<Object> event = val->ToObject();
    1260                     const Handle<Value>  obj   = event->Get(object);
    1261 
    1262                     if (!obj.IsEmpty() && obj->IsObject())
     1239                    if (!named)
     1240                    {
     1241                        // No names (no 'obj'), but 'data'
     1242                        if (!obj->IsUndefined())
     1243                            return handle_scope.Close(val);
     1244                    }
     1245                    else
    12631246                    {
    12641247                        // Has names and data was received?
    1265                         if (obj->ToObject()->GetOwnPropertyNames()->Length()>0)
     1248                        if (obj->IsObject() && obj->ToObject()->GetOwnPropertyNames()->Length()>0)
    12661249                            return handle_scope.Close(val);
    12671250                    }
     
    12751258        if (!null && Time()-t>=boost::posix_time::milliseconds(abs(timeout)))
    12761259            break;
    1277 
    1278         // We cannot sleep directly because we have to give control back to
    1279         // JavaScript ever now and then. This also allows us to catch
    1280         // exceptions, either from the preemption or ConvertEvent
    1281         //sleep->Run();
    12821260
    12831261        // Theoretically, the CPU usage can be reduced by maybe a factor
     
    16871665
    16881666    if (!args.IsConstructCall())
    1689         return Constructor(args);
     1667        return handle_scope.Close(Constructor(args));
    16901668
    16911669    Handle<Function> function =
     
    17221700
    17231701    if (!args.IsConstructCall())
    1724         return Constructor(args);
     1702        return handle_scope.Close(Constructor(args));
    17251703
    17261704    Handle<Function> function =
     
    17581736
    17591737    if (!args.IsConstructCall())
    1760         return Constructor(args);
     1738        return handle_scope.Close(Constructor(args));
    17611739
    17621740    Handle<Function> function =
Note: See TracChangeset for help on using the changeset viewer.