Changeset 14632 for trunk/FACT++/src/InterpreterV8.cc
- Timestamp:
- 11/17/12 01:24:15 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/InterpreterV8.cc
r14631 r14632 27 27 v8::Handle<v8::FunctionTemplate> InterpreterV8::fTemplateLocal; 28 28 v8::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; 31 31 32 32 … … 147 147 const HandleScope handle_scope; 148 148 149 f GlobalContext->Enter();149 func->CreationContext()->Enter(); 150 150 151 151 TryCatch exception; … … 301 301 if (rc.index>-256 && !date.IsEmpty()) 302 302 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()));305 303 306 304 return handle_scope.Close(obj->NewInstance()); … … 679 677 HandleScope handle_scope; 680 678 679 //if (!args.IsConstructCall()) 680 // return Constructor(fTemplateDatabase, args); 681 681 682 Database *db = new Database(*String::Utf8Value(args[0])); 682 683 fDatabases.push_back(db); 683 684 684 685 Handle<Object> This = args.This(); 685 if (!args.IsConstructCall())686 This = fTemplateDatabase->PrototypeTemplate()->NewInstance();687 if (This.IsEmpty())688 return Undefined();689 690 686 This->Set(String::New("user"), String::New(db->user.c_str()), ReadOnly); 691 687 This->Set(String::New("server"), String::New(db->server.c_str()), ReadOnly); … … 756 752 } 757 753 758 args. Holder()->Set(String::New("isOpen"), Boolean::New(false), ReadOnly);754 args.This()->Set(String::New("isOpen"), Boolean::New(false), ReadOnly); 759 755 760 756 return handle_scope.Close(Boolean::New(JsUnsubscribe(*str))); … … 999 995 const HandleScope handle_scope; 1000 996 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(); 1006 1000 1007 1001 const Handle<String> onchange = String::New("onchange"); … … 1040 1034 } 1041 1035 1042 Handle<Value> InterpreterV8::OnChangeSet(Local<String> prop, Local< Value> value, const AccessorInfo &)1036 Handle<Value> InterpreterV8::OnChangeSet(Local<String> prop, Local<Value> value, const AccessorInfo &) 1043 1037 { 1044 1038 // Returns the value if the setter intercepts the request. Otherwise, returns an empty handle. … … 1053 1047 1054 1048 if (value->IsFunction()) 1055 fStateCallbacks[server] = Persistent< Value>::New(value);1049 fStateCallbacks[server] = Persistent<Object>::New(value->ToObject()); 1056 1050 1057 1051 return Handle<Value>(); … … 1074 1068 } 1075 1069 1076 if (it->second.IsEmpty() || !it->second->IsFunction()) 1077 return; 1070 it->second->CreationContext()->Enter(); 1078 1071 1079 1072 const HandleScope handle_scope; 1080 1081 fGlobalContext->Enter();1082 1073 1083 1074 // ------------------------------------------------------------------- … … 1101 1092 1102 1093 Handle<Value> args[] = { obj->NewInstance() }; 1103 Handle<Function> fun = Handle<Function> ::Cast(it->second);1094 Handle<Function> fun = Handle<Function>(Function::Cast(*it->second)); 1104 1095 fun->Call(fun, 1, args); 1105 1096 … … 1355 1346 // ---------------------------- 1356 1347 1357 Handle<Object> This = args.This();1358 1348 if (!args.IsConstructCall()) 1359 This = fTemplateMoon->PrototypeTemplate()->NewInstance(); 1360 if (This.IsEmpty()) 1361 return Undefined(); 1349 return Constructor(args); 1362 1350 1363 1351 Handle<Function> function = … … 1366 1354 return Undefined(); 1367 1355 1356 Handle<Object> This = args.This(); 1368 1357 This->Set(String::New("ra"), Number::New(equ.ra/15), ReadOnly); 1369 1358 This->Set(String::New("dec"), Number::New(equ.dec), ReadOnly); … … 1392 1381 HandleScope handle_scope; 1393 1382 1394 Handle<Object> This = args.This();1395 1383 if (!args.IsConstructCall()) 1396 This = fTemplateSky->PrototypeTemplate()->NewInstance(); 1397 if (This.IsEmpty()) 1398 return Undefined(); 1384 return Constructor(args); 1399 1385 1400 1386 Handle<Function> function = … … 1403 1389 return Undefined(); 1404 1390 1391 Handle<Object> This = args.This(); 1405 1392 This->Set(String::New("ra"), Number::New(ra), ReadOnly); 1406 1393 This->Set(String::New("dec"), Number::New(dec), ReadOnly); … … 1420 1407 return ThrowException(String::New("Third argument must be a Date.")); 1421 1408 1422 1423 1409 const double zd = args[0]->NumberValue(); 1424 1410 const double az = args[1]->NumberValue(); … … 1431 1417 HandleScope handle_scope; 1432 1418 1433 Handle<Object> This = args.This();1434 1419 if (!args.IsConstructCall()) 1435 This = fTemplateLocal->PrototypeTemplate()->NewInstance(); 1436 if (This.IsEmpty()) 1437 return Undefined(); 1420 return Constructor(args); 1438 1421 1439 1422 Handle<Function> function = … … 1442 1425 return Undefined(); 1443 1426 1427 Handle<Object> This = args.This(); 1444 1428 This->Set(String::New("zd"), Number::New(zd), ReadOnly); 1445 1429 This->Set(String::New("az"), Number::New(az), ReadOnly); … … 1600 1584 // CORE 1601 1585 // ========================================================================== 1586 1587 Handle<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 1602 1597 1603 1598 void InterpreterV8::AddFormatToGlobal() const … … 1706 1701 global->Set(String::New("Database"), db, ReadOnly); 1707 1702 1708 fTemplateDatabase = db;1709 1710 1703 #ifdef HAVE_NOVA 1711 1704 Handle<FunctionTemplate> sky = FunctionTemplate::New(ConstructorSky); … … 1725 1718 fTemplateLocal = loc; 1726 1719 fTemplateSky = sky; 1727 fTemplateMoon = moon;1728 1720 #endif 1729 1721 1730 1722 // Persistent 1731 fGlobalContext = Context::New(NULL, global);1732 if ( fGlobalContext.IsEmpty())1723 Persistent<Context> context = Context::New(NULL, global); 1724 if (context.IsEmpty()) 1733 1725 { 1734 1726 //printf("Error creating context\n"); … … 1736 1728 } 1737 1729 1738 Context::Scope scope( fGlobalContext);1730 Context::Scope scope(context); 1739 1731 1740 1732 Handle<Array> args = Array::New(map.size()); 1741 1733 for (auto it=map.begin(); it!=map.end(); it++) 1742 1734 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); 1745 1737 1746 1738 //V8::ResumeProfiler(); … … 1812 1804 fStates.clear(); 1813 1805 1814 fGlobalContext.Dispose();1806 context.Dispose(); 1815 1807 1816 1808 JsEnd(filename);
Note:
See TracChangeset
for help on using the changeset viewer.