Changeset 14555
- Timestamp:
- 11/03/12 19:20:55 (12 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/InterpreterV8.cc
r14548 r14555 312 312 313 313 Handle<ObjectTemplate> obj = ObjectTemplate::New(); 314 obj->Set(String::New("time"), date);315 314 obj->Set(String::New("index"), rc.index<=-256?Undefined():Integer::New(rc.index), ReadOnly); 316 315 obj->Set(String::New("name"), rc.index<=-256?Undefined():String::New(rc.name.c_str()), ReadOnly); 316 if (rc.index>-256) 317 obj->Set(String::New("time"), date); 317 318 //obj->Set(String::New("toString"), String::New(("[Object state "+string(*str)+":"+to_string(rc.index)+"]").c_str())); 318 319 … … 663 664 } 664 665 666 args.Holder()->Set(String::New("isOpen"), Boolean::New(false), ReadOnly); 667 665 668 return Boolean::New(JsUnsubscribe(*str)); 666 669 } … … 781 784 return; 782 785 786 Locker locker; 787 783 788 const auto it = fReverseMap.find(service); 784 789 if (it==fReverseMap.end()) 785 790 return; 786 791 787 Locker locker;788 789 792 const HandleScope handle_scope; 790 793 … … 835 838 } 836 839 840 Handle<Value> InterpreterV8::OnChangeSet(Local<String> prop, Local< Value > value, const AccessorInfo &info) 841 { 842 const HandleScope handle_scope; 843 844 // Returns the value if the setter intercepts the request. Otherwise, returns an empty handle. 845 const string server = *String::Utf8Value(prop); 846 auto it = fStateCallbacks.find(server); 847 848 if (it!=fStateCallbacks.end()) 849 { 850 it->second.Dispose(); 851 fStateCallbacks.erase(it); 852 } 853 854 if (value->IsFunction()) 855 fStateCallbacks[server] = Persistent<Value>::New(value); 856 857 return Handle<Value>(); 858 } 859 860 861 void InterpreterV8::JsHandleState(const std::string &server, const State &state) 862 { 863 if (fThreadId<0) 864 return; 865 866 Locker locker; 867 868 auto it = fStateCallbacks.find(server); 869 if (it==fStateCallbacks.end()) 870 { 871 it = fStateCallbacks.find("*"); 872 if (it==fStateCallbacks.end()) 873 return; 874 } 875 876 const HandleScope handle_scope; 877 878 if (it->second.IsEmpty() || !it->second->IsFunction()) 879 return; 880 881 // ------------------------------------------------------------------- 882 // We are not in a context... we need to get into one for Array::New 883 884 Persistent<Context> context = Context::New(); 885 if (context.IsEmpty()) 886 return; 887 888 const Context::Scope scope(context); 889 890 // ------------------------------------------------------------------- 891 892 TryCatch exception; 893 894 // It is important to catch the exception thrown 895 // by Date::New in case of thread termination! 896 Local<Value> date = Date::New(state.time.JavaDate()); 897 898 if (!exception.HasCaught()) 899 { 900 Handle<ObjectTemplate> obj = ObjectTemplate::New(); 901 obj->Set(String::New("index"), state.index<=-256?Undefined():Integer::New(state.index), ReadOnly); 902 obj->Set(String::New("name"), state.index<=-256?Undefined():String::New(state.name.c_str()), ReadOnly); 903 obj->Set(String::New("server"), String::New(server.c_str()), ReadOnly); 904 if (state.index>-256) 905 obj->Set(String::New("time"), date); 906 907 Handle<Value> args[] = { obj->NewInstance() }; 908 909 Handle<Function> fun = Handle<Function>::Cast(it->second); 910 fun->Call(fun, 1, args); 911 } 912 913 if (exception.HasCaught()) 914 ReportException(&exception); 915 916 context.Dispose(); 917 918 if (exception.HasCaught()) 919 V8::TerminateExecution(fThreadId); 920 } 921 837 922 /* 838 923 void Cleanup( Persistent<Value> object, void *parameter ) … … 861 946 862 947 Handle<ObjectTemplate> tem = ObjectTemplate::New(); 863 tem->Set(String::New("get"), FunctionTemplate::New(WrapGetData), ReadOnly); 864 tem->Set(String::New("close"), FunctionTemplate::New(WrapClose), ReadOnly); 865 tem->Set(String::New("name"), String::New(*str), ReadOnly); 948 tem->Set(String::New("get"), FunctionTemplate::New(WrapGetData), ReadOnly); 949 tem->Set(String::New("close"), FunctionTemplate::New(WrapClose), ReadOnly); 950 tem->Set(String::New("name"), String::New(*str), ReadOnly); 951 tem->Set(String::New("isOpen"), Boolean::New(true)); 866 952 tem->SetInternalFieldCount(1); 867 953 //tem->Set(String::New("toString"), String::New(("[object Dim "+string(*str)+"]").c_str()), ReadOnly); … … 900 986 dim->Set(String::New("database"), FunctionTemplate::New(WrapDatabase), ReadOnly); 901 987 988 Handle<ObjectTemplate> onchange = ObjectTemplate::New(); 989 onchange->SetNamedPropertyHandler(OnChangeGet, WrapOnChangeSet); 990 dim->Set(v8::String::New("onchange"), onchange); 991 902 992 Handle<ObjectTemplate> global = ObjectTemplate::New(); 903 993 global->Set(String::New("dim"), dim, ReadOnly); … … 943 1033 //context->Exit(); 944 1034 1035 for (auto it=fStateCallbacks.begin(); it!=fStateCallbacks.end(); it++) 1036 it->second.Dispose(); 1037 fStateCallbacks.clear(); 1038 945 1039 for (auto it=fReverseMap.begin(); it!=fReverseMap.end(); it++) 946 1040 it->second.Dispose(); … … 973 1067 974 1068 #endif 975 976 /*977 #0 0x00007ffff5ae0e62 in ?? () from /usr/lib/libv8.so.3.7.12.22978 #1 0x00007ffff5ae1969 in ?? () from /usr/lib/libv8.so.3.7.12.22979 #2 0x00007ffff5af1976 in v8::V8::Dispose() () from /usr/lib/libv8.so.3.7.12.22980 #3 0x0000000000426459 in RemoteControl<Console>::~RemoteControl() ()981 #4 0x00007ffff51e9901 in __run_exit_handlers (status=3, listp=0x7ffff5566688, run_list_atexi982 #5 0x00007ffff51e9985 in __GI_exit (status=<optimized out>) at exit.c:100983 #6 0x00000000004374db in DimErrorRedirecter::exitHandler(int) ()984 #7 0x00007ffff66bce72 in exit_user_routine () from /home/fact/FACT++.in-run-fad-loss/.libs/l985 #8 0x00007ffff6477387 in recv_dns_dis_rout () from /home/fact/FACT++.in-run-fad-loss/.libs/l986 #9 0x00007ffff647b79f in ast_read_h () from /home/fact/FACT++.in-run-fad-loss/.libs/libDim.s987 #10 0x00007ffff647f388 in do_read () from /home/fact/FACT++.in-run-fad-loss/.libs/libDim.so988 #11 0x00007ffff647ff32 in tcpip_task () from /home/fact/FACT++.in-run-fad-loss/.libs/libDim.s989 #12 0x00007ffff6482c57 in dim_tcpip_thread () from /home/fact/FACT++.in-run-fad-loss/.libs/li990 #13 0x00007ffff7bc4e9a in start_thread (arg=0x7ffff13be700) at pthread_create.c:308991 #14 0x00007ffff52a1cbd in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:112992 */ -
trunk/FACT++/src/InterpreterV8.h
r14549 r14555 15 15 16 16 class Database; 17 #include<iostream> 17 18 18 class InterpreterV8 19 19 { … … 29 29 // subscription exists for that object) 30 30 std::map<std::string, v8::Persistent<v8::Object>> fReverseMap; 31 32 // Lookup table for the callbacks in cases of state changes 33 std::map<std::string, v8::Persistent<v8::Value>> fStateCallbacks; 31 34 32 35 #ifdef HAVE_SQL … … 57 60 v8::Handle<v8::Value> FuncDbQuery(const v8::Arguments &args); 58 61 v8::Handle<v8::Value> FuncDbClose(const v8::Arguments &args); 62 v8::Handle<v8::Value> OnChangeSet(v8::Local<v8::String>, v8::Local<v8::Value>, const v8::AccessorInfo &); 59 63 60 64 static v8::Handle<v8::Value> FuncVersion(const v8::Arguments&); … … 75 79 static v8::Handle<v8::Value> WrapDbQuery(const v8::Arguments &args) { if (This) return This->FuncDbQuery(args); else return v8::Undefined(); } 76 80 static v8::Handle<v8::Value> WrapDbClose(const v8::Arguments &args) { if (This) return This->FuncDbClose(args); else return v8::Undefined(); } 81 static v8::Handle<v8::Value> WrapOnChangeSet(v8::Local<v8::String> prop, v8::Local<v8::Value> value, const v8::AccessorInfo &info) 82 { 83 if (This) return This->OnChangeSet(prop, value, info); else return v8::Undefined(); 84 } 85 86 static v8::Handle<v8::Value> OnChangeGet(v8::Local<v8::String>, const v8::AccessorInfo &) 87 { 88 return v8::Handle<v8::Value>(); 89 } 77 90 78 91 static v8::Handle<v8::Value> Convert(char type, const char* &ptr); … … 113 126 114 127 void JsHandleEvent(const EventImp &, uint64_t, const std::string &); 128 void JsHandleState(const std::string &, const State &); 115 129 116 130 bool JsRun(const std::string &, const std::map<std::string,std::string> & = std::map<std::string,std::string>());
Note:
See TracChangeset
for help on using the changeset viewer.