void ModuleInterfaces::LoadModule(const v8::FunctionCallbackInfo<v8::Value>& args) { // Filename if (args.Length() != 1) { args.GetReturnValue().SetUndefined(); return; // invalid arguments } // Find Library in lib paths v8::String::Utf8Value Filename(args[0]); FILE* file; if (fopen_s(&file, *Filename, "rb")) { args.GetReturnValue().SetUndefined(); return; // Couldnt find/open the file } fseek(file, 0, SEEK_END); int size = ftell(file); rewind(file); char* result = new char[size + 1]; result[size] = '\0'; int read = static_cast<int>(fread_s(result, size, 1, size, file)); fclose(file); args.GetReturnValue().Set(v8::String::NewFromUtf8(args.GetIsolate(), result)); }
void PreludeScript::log_callback(const v8::FunctionCallbackInfo<v8::Value>& args) { if (args.Length() != 1) { args.GetReturnValue().Set( v8::Isolate::GetCurrent()->ThrowException( v8::Exception::Error(v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), "The 'log' handler expects 1 argument")))); return; } if (args[0].IsEmpty()) { args.GetReturnValue().Set(v8::Isolate::GetCurrent()->ThrowException( v8::Exception::Error(v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), "The 'log' handler argument cannot be empty")))); return; } // TODO: do we need to check argument data type? v8::Handle<v8::External> data = args.Data().As<v8::External>(); PreludeScript *prelude = reinterpret_cast<PreludeScript *>(data->Value()); //TODO: make sure correct value type passed v8::String::Value message(args[0].As<v8::String>()); prelude->log_handler(*message); args.GetReturnValue().Set(v8::Undefined(v8::Isolate::GetCurrent())); return; };
void _zipOpenFileBase64(const v8::FunctionCallbackInfo<v8::Value>& args) { if (args.Length() < 1) { args.GetReturnValue().Set(v8::Null(v8::Isolate::GetCurrent())); return; } CNativeControl* pNative = unwrap_nativeobject(args.This()); bool bIsOpen = pNative->m_oZipWorker.OpenBase64(to_cstringA(args[0])); if (!bIsOpen) { args.GetReturnValue().Set(v8::Null(v8::Isolate::GetCurrent())); return; } v8::Local<v8::Object> obj = v8::Object::New(v8::Isolate::GetCurrent()); for (std::vector<std::wstring>::iterator i = pNative->m_oZipWorker.m_arFiles.begin(); i != pNative->m_oZipWorker.m_arFiles.end(); i++) { std::string sFile = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(*i); v8::Local<v8::String> _k = v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), sFile.c_str(), v8::String::kNormalString, -1); v8::Local<v8::String> _v = v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), sFile.c_str(), v8::String::kNormalString, -1); obj->Set(_k, _v); } args.GetReturnValue().Set(obj); }
void TNodeJsFIn::New(const v8::FunctionCallbackInfo<v8::Value>& Args) { v8::Isolate* Isolate = v8::Isolate::GetCurrent(); v8::HandleScope HandleScope(Isolate); if (Args.IsConstructCall()) { EAssertR(Args.Length() == 1 && Args[0]->IsString(), "Expected a file path."); TStr FNm(*v8::String::Utf8Value(Args[0]->ToString())); EAssertR(TFile::Exists(FNm), "File does not exist."); TNodeJsFIn* JsFIn = new TNodeJsFIn(FNm); v8::Local<v8::Object> Instance = Args.This(); v8::Handle<v8::String> key = v8::String::NewFromUtf8(Isolate, "class"); v8::Handle<v8::String> value = v8::String::NewFromUtf8(Isolate, ClassId.CStr()); Instance->SetHiddenValue(key, value); JsFIn->Wrap(Instance); Args.GetReturnValue().Set(Instance); } else { const int Argc = 1; v8::Local<v8::Value> Argv[Argc] = { Args[0] }; v8::Local<v8::Function> cons = v8::Local<v8::Function>::New(Isolate, constructor); v8::Local<v8::Object> Instance = cons->NewInstance(Argc, Argv); Args.GetReturnValue().Set(Instance); } }
/* Evaluate a prepared statement stepSuccessCode expected success code from switch_core_db_step() return true if step return expected success code, false otherwise */ void FSCoreDB::StepEx(const v8::FunctionCallbackInfo<Value>& info, int stepSuccessCode) { HandleScope handle_scope(info.GetIsolate()); info.GetReturnValue().Set(false); if (!_db) { info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Database is not connected")); return; } if (_stmt) { int running = 1; while (running < 5000) { int result = switch_core_db_step(_stmt); if (result == stepSuccessCode) { info.GetReturnValue().Set(true); break; } else if (result == SWITCH_CORE_DB_BUSY) { running++; switch_cond_next(); /* wait a bit before retrying */ continue; } if (switch_core_db_finalize(_stmt) != SWITCH_CORE_DB_OK) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error %s\n", switch_core_db_errmsg(_db)); } _stmt = NULL; break; } } }
void BookWrap::Lookup(const v8::FunctionCallbackInfo<v8::Value>& args) { Isolate* isolate = args.GetIsolate(); HandleScope scope(isolate); if (args.Length() == 1) { if (args[0]->IsString()) { const String::Utf8Value s(args[0]->ToString()); Book* b = ObjectWrap::Unwrap<BookWrap>(args.This())->m_book; try { Person* p = b->lookup(*s); Local<Object> obj = PersonWrap::NewInstance(); PersonWrap* pw = ObjectWrap::Unwrap<PersonWrap>(obj); pw->m_person = p; args.GetReturnValue().Set(obj); } catch (...) { isolate->ThrowException(Exception::RangeError(String::NewFromUtf8(isolate, "Not found"))); args.GetReturnValue().SetUndefined(); } } else { isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "String expected"))); args.GetReturnValue().SetUndefined(); } } else { isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "One argument expected"))); args.GetReturnValue().SetUndefined(); } }
// // Response to create object from javascript's new() // void SVMPredict::New(const v8::FunctionCallbackInfo<v8::Value>& args) { #if defined(PROCESS_DEBUG) log("is called."); #endif //Creating temporary handles so we use a handle scope v8::Isolate* isolate = args.GetIsolate();//v8::Isolate::GetCurrent(); v8::EscapableHandleScope scope(isolate); if (args.IsConstructCall()) { SVMPredict* svmpredict_instance = new SVMPredict(isolate); //set private variables // Wrap c++ object as a Javascript object svmpredict_instance->Wrap(args.Holder()); args.GetReturnValue().Set(args.Holder()); } else { const int argc = 1; v8::Local<v8::Value> argv[argc] = { args[0] }; v8::Local<v8::Function> func = v8::Local<v8::Function>::New(isolate, constructor_); //return scope.Close(func->NewInstance(argc, argv)); //scope.Close(func->NewInstance(argc, argv)); args.GetReturnValue().Set(func->NewInstance(argc, argv)); } //Constructor function return a Javascript object //which is a wrapper for our C++ object, //This is the expected behavior when calling a constructor //function with the new operator in Javascript. //return args.This(); };
void Susi::JS::Engine::RegisterProcessor(const v8::FunctionCallbackInfo<v8::Value>& args) { if (args.Length() < 2) return; Handle<Value> callbackValue = args[1]; if(callbackValue->IsFunction()){ Handle<Value> topicValue = args[0]; std::string topic{Susi::JS::Engine::convertFromJS(topicValue).toString()}; std::shared_ptr<Persistent<Function>> jsCallback{new Persistent<Function>(Isolate::GetCurrent(),Handle<Function>::Cast(callbackValue))}; Susi::Events::Processor callback = [jsCallback](Susi::Events::EventPtr event){ Local<Function> func = Local<Function>::New(Isolate::GetCurrent(),*jsCallback); Handle<Value> callbackArguments[1]; callbackArguments[0] = Susi::JS::Engine::convertFromCPP(event->toAny()); TryCatch trycatch; auto res = func->Call(func,1,callbackArguments); if (res.IsEmpty()) { Handle<Value> exception = trycatch.Exception(); String::Utf8Value exception_str(exception); std::cout<<*exception_str<<std::endl; } }; long id = Susi::JS::engine->susi_client.subscribe(topic,callback); args.GetReturnValue().Set((double)id); }else{ args.GetReturnValue().Set(false); } }
// // Called to load a svm model file // void SVMPredict::loadSVMModel(const v8::FunctionCallbackInfo<v8::Value>& args){ //v8::Isolate* isolate = v8::Isolate::GetCurrent(); //v8::HandleScope scope(isolate); //bool ok; SVMPredict* svmPredict_instance = node::ObjectWrap::Unwrap<SVMPredict>(args.Holder()); if (args.Length() != 1) { args.GetIsolate()->ThrowException( v8::String::NewFromUtf8(args.GetIsolate(),"Bad parameters")); return; //ThrowError("Wrong number of arguments!"); //args.GetReturnValue().Set(v8::Undefined()); //scope.Close(v8::Undefined()); } if (!args[0]->IsString()) { args.GetIsolate()->ThrowException( v8::String::NewFromUtf8(args.GetIsolate(),"Wrong argument type!")); return; //ThrowError("Wrong arguments!"); //scope.Close(v8::Undefined()); } v8::String::Utf8Value File(args[0]); //std::string modelfile = FromV8<std::string>(args[0],&ok); std::string modelfile = *File; if ( !svmPredict_instance->load_svm_model(modelfile)){ ThrowError(("Failed to load the SVM model file!"+modelfile).c_str()); args.GetReturnValue().Set(false); }else{ svmPredict_instance->isModelLoaded = true; svmPredict_instance->predict_probability = (svm_check_probability_model(svmPredict_instance->model)==0) ? false: true; args.GetReturnValue().Set(true); } };
void ServiceRegistryWrapper::findByName(const v8::FunctionCallbackInfo<v8::Value>& args) { Poco::OSP::ServiceRegistry* pServiceRegistry = Poco::JS::Core::Wrapper::unwrapNative<Poco::OSP::ServiceRegistry>(args); try { if (args.Length() == 1) { std::string serviceName = toString(args[0]); Poco::OSP::ServiceRef::Ptr pServiceRef = pServiceRegistry->findByName(serviceName); if (pServiceRef) { ServiceRefWrapper wrapper; v8::Persistent<v8::Object> serviceRefObject(args.GetIsolate(), wrapper.wrapNativePersistent(args.GetIsolate(), pServiceRef)); args.GetReturnValue().Set(serviceRefObject); return; } args.GetReturnValue().Set(v8::Null(args.GetIsolate())); } else { returnException(args, std::string("bad arguments - service name required")); } } catch (Poco::Exception& exc) { returnException(args, exc); } }
void TNodeJsFOut::New(const v8::FunctionCallbackInfo<v8::Value>& Args) { v8::Isolate* Isolate = v8::Isolate::GetCurrent(); v8::EscapableHandleScope HandleScope(Isolate); if (Args.IsConstructCall()) { EAssertR(Args.Length() >= 1 && Args[0]->IsString(), "Expected file path."); TStr FNm(*v8::String::Utf8Value(Args[0]->ToString())); bool AppendP = Args.Length() >= 2 && Args[1]->IsBoolean() && Args[1]->BooleanValue(); TNodeJsFOut* JsFOut = new TNodeJsFOut(FNm, AppendP); v8::Local<v8::Object> Instance = Args.This(); JsFOut->Wrap(Instance); Args.GetReturnValue().Set(Instance); } else { const int Argc = 1; v8::Local<v8::Value> Argv[Argc] = { Args[0] }; v8::Local<v8::Function> cons = v8::Local<v8::Function>::New(Isolate, constructor); cons->NewInstance(Argc, Argv); v8::Local<v8::Object> Instance = cons->NewInstance(Argc, Argv); Args.GetReturnValue().Set(Instance); } }
void _GetFontArrayBuffer(const v8::FunctionCallbackInfo<v8::Value>& args) { if (args.Length() < 1) { args.GetReturnValue().Set(v8::Undefined(v8::Isolate::GetCurrent())); return; } CNativeControl* pNative = unwrap_nativeobject(args.This()); BYTE* pData = NULL; DWORD len = 0; std::wstring strDir = pNative->m_strFontsDirectory; #if 0 if (strDir.length() != 0) { strDir += L"/"; strDir += to_cstring(args[0]); } else #endif // TODO: // по идее файлы могут совпадать по имени, но лежать в разных директориях. // и поэтому в AllFonts.js надо бы писать пути полные. // пока оставим по-старому std::wstring sFind = to_cstring(args[0]); bool bIsFullFilePath = (std::wstring::npos != sFind.find('\\') || std::wstring::npos != sFind.find('/')); if (bIsFullFilePath) { bIsFullFilePath = NSFile::CFileBinary::Exists(sFind); } if (!bIsFullFilePath) { std::map<std::wstring, std::wstring>::iterator pair = pNative->m_map_fonts.find(sFind); if (pair != pNative->m_map_fonts.end()) strDir = pair->second; else strDir = pNative->m_sDefaultFont; } else { strDir = sFind; } pNative->getFileData(strDir, pData, len); v8::Local<v8::ArrayBuffer> _buffer = v8::ArrayBuffer::New(v8::Isolate::GetCurrent(), (void*)pData, (size_t)len); v8::Local<v8::Uint8Array> _array = v8::Uint8Array::New(_buffer, 0, (size_t)len); args.GetReturnValue().Set(_array); }
void JSVideoFrame::JSGetSimpleContext(const v8::FunctionCallbackInfo<v8::Value>& args) { v8::HandleScope scope(args.GetIsolate()); // Ignore the arguments (as we're currently called directly from GetContext) JSVideoFrame* self = UnwrapSelf<JSVideoFrame>(args.This()); JSSimpleRenderingContext* renderingContext = self->GetSimpleContext(); if (renderingContext == NULL) { args.GetReturnValue().SetNull(); } else { v8::Handle<v8::Object> inst = renderingContext->GetInstance(args.GetIsolate()); args.GetReturnValue().Set(inst); } }
void IMessageDlg::_getValue(const v8::FunctionCallbackInfo<v8::Value>& args) { Isolate* isolate = args.GetIsolate(); IMessageDlg* imd = ObjectWrap::Unwrap<IMessageDlg>(args.Holder()); if (imd != NULL) { if (imd->hwnd != NULL) { char* sRet = IupGetAttribute(imd->hwnd,"BUTTONRESPONSE"); args.GetReturnValue().Set(String::NewFromUtf8(isolate,sRet)); } else { args.GetReturnValue().Set(String::NewFromUtf8(isolate,"")); } } else { args.GetReturnValue().Set(String::NewFromUtf8(isolate,"")); } }
/** readValue: * read a value of a given type from the buffer * Note: uint64 and int64 will be returned as doubles as JS does not support 64bit integers, the rest will be returned as 32bit integers * * @param string type * value type to be read: uint64, int64/sint64, uint32, int32/sint32, uint16, int16/sint16, uint8/byte, int8/sint8/char * * @return object * read value */ void CJSBuffer::FxReadValue(const v8::FunctionCallbackInfo<v8::Value> &args) { v8::HandleScope HandleScope(v8::Isolate::GetCurrent()); CJSBuffer* jBuffer = GetJSObject<CJSBuffer>(args.Holder()); CBufferObj* pBuffer = jBuffer->m_pBuffer; if (args.Length() < 1) { args.GetIsolate()->ThrowException(v8::String::NewFromOneByte(v8::Isolate::GetCurrent(), (uint8_t*)"Invalid Argument")); return; } BUFFER_TRY wstring Type = CJSEngine::GetWStr(args[0]); if(CompareStr(Type, L"uint64")) args.GetReturnValue().Set(v8::Number::New(v8::Isolate::GetCurrent(), pBuffer->ReadValue<uint64>())); else if(CompareStr(Type, L"int64") || CompareStr(Type, L"sint64")) args.GetReturnValue().Set(v8::Number::New(v8::Isolate::GetCurrent(), pBuffer->ReadValue<sint64>())); else if(CompareStr(Type, L"uint32")) args.GetReturnValue().Set(v8::Uint32::New(v8::Isolate::GetCurrent(), pBuffer->ReadValue<uint32>())); else if(CompareStr(Type, L"int32") || CompareStr(Type, L"sint32")) args.GetReturnValue().Set(v8::Int32::New(v8::Isolate::GetCurrent(), pBuffer->ReadValue<sint32>())); else if(CompareStr(Type, L"uint16")) args.GetReturnValue().Set(v8::Uint32::New(v8::Isolate::GetCurrent(), pBuffer->ReadValue<uint16>())); else if(CompareStr(Type, L"int16") || CompareStr(Type, L"sint16")) args.GetReturnValue().Set(v8::Int32::New(v8::Isolate::GetCurrent(), pBuffer->ReadValue<sint16>())); else if(CompareStr(Type, L"uint8") || CompareStr(Type, L"byte")) args.GetReturnValue().Set(v8::Uint32::New(v8::Isolate::GetCurrent(), pBuffer->ReadValue<uint8>())); else if(CompareStr(Type, L"int8") || CompareStr(Type, L"sint8") || CompareStr(Type, L"char")) args.GetReturnValue().Set(v8::Int32::New(v8::Isolate::GetCurrent(), pBuffer->ReadValue<sint8>())); else args.GetIsolate()->ThrowException(v8::String::NewFromOneByte(v8::Isolate::GetCurrent(), (uint8_t*)"Invalid Argument")); BUFFER_CATCH }
void _CheckNextChange(const v8::FunctionCallbackInfo<v8::Value>& args) { CNativeControl* pNative = unwrap_nativeobject(args.This()); pNative->m_nCurrentChangesNumber++; if (-1 != pNative->m_nMaxChangesNumber) { if (pNative->m_nCurrentChangesNumber >= pNative->m_nMaxChangesNumber) { args.GetReturnValue().Set(v8::Boolean::New(v8::Isolate::GetCurrent(), false)); return; } } args.GetReturnValue().Set(v8::Boolean::New(v8::Isolate::GetCurrent(), true)); }
static void newObject(const v8::FunctionCallbackInfo<v8::Value> & args) { if (args.IsConstructCall()) { MethodMan call(args); if (args.Length() != 2) { call.throwException("Wrong number of arguments"); return; } // the first parameter is a Cluster object, let's unwrap it to get access to the underlying handle auto obj = call.checkedArgObject(0); if (!obj.second) { call.throwException("Invalid parameter supplied to object"); return; } auto str = call.checkedArgString(1); if (!str.second) { call.throwException("Expected a string as an argument"); return; } v8::String::Utf8Value utf8str(str.first); // get access to the underlying handle Cluster * c = ObjectWrap::Unwrap<Cluster>(obj.first); Object * b = new Object(*c, *utf8str); b->Wrap(args.This()); args.GetReturnValue().Set(args.This()); } else { v8::Isolate* isolate = v8::Isolate::GetCurrent(); // Invoked as plain function `MyObject(...)`, turn into construct call. const int argc = 2; v8::Local<v8::Value> argv[argc] = { args[0], args[1] }; v8::Local<v8::Function> cons = v8::Local<v8::Function>::New(isolate, constructor); args.GetReturnValue().Set(cons->NewInstance(argc, argv)); } }
void SessionWrapper::construct(const v8::FunctionCallbackInfo<v8::Value>& args) { std::string connector; std::string connectionString; if (args.Length() == 2) { connector = toString(args[0]); connectionString = toString(args[1]); } else { returnException(args, std::string("bad arguments: connector and connection string required")); return; } SessionHolder* pSessionHolder = 0; try { pSessionHolder = new SessionHolder(connector, connectionString); SessionWrapper wrapper; v8::Persistent<v8::Object>& sessionObject(wrapper.wrapNativePersistent(args.GetIsolate(), pSessionHolder)); args.GetReturnValue().Set(sessionObject); } catch (Poco::Exception& exc) { delete pSessionHolder; returnException(args, exc); } }
void JsSIPMessageObjectFactory::InternalSipMessage::toString( const v8::FunctionCallbackInfo<v8::Value>& info) { std::ostringstream stream; stream << m_msg; info.GetReturnValue().Set(v8::String::New(stream.str().c_str())); }
static void FXJSE_V8ProxyCallback_getPropertyNames( const v8::FunctionCallbackInfo<v8::Value>& info) { v8::Local<v8::Object> hChainObj = info.This()->GetPrototype().As<v8::Object>(); v8::Local<v8::Value> hChainPropertyNames = hChainObj->GetPropertyNames(); info.GetReturnValue().Set(hChainPropertyNames); }
static void FXJSE_DynPropGetterAdapter_MethodCallback( const v8::FunctionCallbackInfo<v8::Value>& info) { v8::Local<v8::Object> hCallBackInfo = info.Data().As<v8::Object>(); FXJSE_CLASS* lpClass = static_cast<FXJSE_CLASS*>( hCallBackInfo->GetAlignedPointerFromInternalField(0)); v8::Local<v8::String> hPropName = hCallBackInfo->GetInternalField(1).As<v8::String>(); ASSERT(lpClass && !hPropName.IsEmpty()); v8::String::Utf8Value szPropName(hPropName); CFX_ByteStringC szFxPropName = *szPropName; CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate()); lpThisValue->ForceSetValue(info.This()); CFXJSE_Value* lpRetValue = CFXJSE_Value::Create(info.GetIsolate()); CFXJSE_ArgumentsImpl impl = {&info, lpRetValue}; lpClass->dynMethodCall(reinterpret_cast<FXJSE_HOBJECT>(lpThisValue), szFxPropName, reinterpret_cast<CFXJSE_Arguments&>(impl)); if (!lpRetValue->DirectGetValue().IsEmpty()) { info.GetReturnValue().Set(lpRetValue->DirectGetValue()); } delete lpRetValue; lpRetValue = nullptr; delete lpThisValue; lpThisValue = nullptr; }
/// <summary> /// Attach to existing process /// </summary> /// <param name="pid">Process ID</param> /// <param name="access">Access mask</param> /// <returns>Status code</returns> /// BLACKBONE_API NTSTATUS Attach(DWORD pid, DWORD access = DEFAULT_ACCESS_P); void ProcessWrap::Attach(const v8::FunctionCallbackInfo<v8::Value>& args) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::HandleScope scope(isolate); if (args.Length() == 0 || args.Length() > 2) { isolate->ThrowException(v8::Exception::TypeError( v8::String::NewFromUtf8(isolate, "Wrong number of arguments"))); return; } ProcessWrap* obj = ObjectWrap::Unwrap<ProcessWrap>(args.Holder()); NTSTATUS status = STATUS_INVALID_PARAMETER; if (args.Length() == 1 && args[0]->IsInt32()) { status = obj->_proc.Attach(args[0]->Int32Value()); } else if (args.Length() == 2 && args[0]->IsInt32() && args[1]->IsInt32()) { status = obj->_proc.Attach(args[0]->Int32Value(), args[1]->Int32Value()); } else { isolate->ThrowException(v8::Exception::TypeError( v8::String::NewFromUtf8(isolate, "Wrong type of arguments"))); return; } args.GetReturnValue().Set(v8::Number::New(isolate, status)); }
void _ms_writestring2(const v8::FunctionCallbackInfo<v8::Value>& args) { CMemoryStream* pNative = unwrap_memorystream(args.This()); v8::String::Value data(args[0]); pNative->WriteString2((wchar_t*)*data, data.length()); args.GetReturnValue().Set(v8::Undefined(v8::Isolate::GetCurrent())); }
// The callback that is invoked by v8 whenever the JavaScript 'setTimeout' // function is called. // // JS: setTimeout(on_timeout, 500); void Global::SetTimeout(const v8::FunctionCallbackInfo<v8::Value>& args) { if (args.Length() != 2) { args.GetIsolate()->ThrowException( v8::String::NewFromUtf8( args.GetIsolate(), "Error: 2 arguments required.")); return; } // Pull out the first arg, make sure it's a function. if (!args[0]->IsFunction()) { printf("Not a function passed to setTimeout.\n"); return; } Handle<Function> timeoutFn = Handle<Function>::Cast(args[0]); double delay = args[1]->NumberValue(); int32_t id = gGlobal->getNextTimerID(); gGlobal->fTimeouts[id].Reset(gGlobal->fIsolate, timeoutFn); // Create an SkEvent and add it with the right delay. SkEvent* evt = new SkEvent(); evt->setTargetProc(Global::TimeOutProc); evt->setFast32(id); evt->postDelay(delay); args.GetReturnValue().Set(Integer::New(gGlobal->fIsolate, id)); }
void V8AudioContext::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& args) { Document* document = currentDocument(); RefPtr<AudioContext> audioContext; if (!args.Length()) { // Constructor for default AudioContext which talks to audio hardware. audioContext = AudioContext::create(document); if (!audioContext.get()) { throwError(v8SyntaxError, "audio resources unavailable for AudioContext construction", args.GetIsolate()); return; } } else { // Constructor for offline (render-target) AudioContext which renders into an AudioBuffer. // new AudioContext(in unsigned long numberOfChannels, in unsigned long numberOfFrames, in float sampleRate); document->addConsoleMessage(JSMessageSource, WarningMessageLevel, "Deprecated AudioContext constructor: use OfflineAudioContext instead"); V8OfflineAudioContext::constructorCallback(args); return; } if (!audioContext.get()) { throwError(v8SyntaxError, "Error creating AudioContext", args.GetIsolate()); return; } // Transform the holder into a wrapper object for the audio context. v8::Handle<v8::Object> wrapper = args.Holder(); V8DOMWrapper::associateObjectWithWrapper<V8AudioContext>(audioContext.release(), &info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent); args.GetReturnValue().Set(wrapper); }
static void get_hello(const v8::FunctionCallbackInfo<v8::Value>& args) { v8::HandleScope scope(v8::Isolate::GetCurrent()); MyLib::Message msg("hello"); std::string msg_string = msg.get(); args.GetReturnValue().Set(v8::String::New(msg_string.c_str())); }
void ImageWrapper::NewImage( const v8::FunctionCallbackInfo< v8::Value >& args) { v8::Isolate* isolate = args.GetIsolate(); v8::HandleScope handleScope( isolate); if(!args.IsConstructCall()) { DALI_SCRIPT_EXCEPTION( isolate, "Image constructor called without 'new'"); return; } // find out the callee function name...e.g. BufferImage, ResourceImage v8::Local<v8::Function> callee = args.Callee(); v8::Local<v8::Value> v8String = callee->GetName(); std::string typeName = V8Utils::v8StringToStdString( v8String ); ImageType imageType = GetImageType( typeName ); if( imageType == UNKNOWN_IMAGE_TYPE ) { DALI_SCRIPT_EXCEPTION( isolate, "unknown image type"); return; } Image image = (ImageApiLookup[imageType].constructor)( args ); if( ! image ) { // a v8 exception will have been thrown by the constructor return; } v8::Local<v8::Object> localObject = WrapImage( isolate, image, imageType ); args.GetReturnValue().Set( localObject ); }
void CJSKadID::FxToString(const v8::FunctionCallbackInfo<v8::Value> &args) { v8::HandleScope HandleScope(v8::Isolate::GetCurrent()); CJSKadID* jKadID = GetJSObject<CJSKadID>(args.Holder()); args.GetReturnValue().Set(v8::String::NewFromTwoByte(v8::Isolate::GetCurrent(), V8STR(jKadID->m_pKadID->m_Value.ToHex().c_str()))); }
void ServiceRegistryWrapper::createListener(const v8::FunctionCallbackInfo<v8::Value>& args) { v8::HandleScope handleScope(args.GetIsolate()); Poco::OSP::ServiceRegistry* pServiceRegistry = Poco::JS::Core::Wrapper::unwrapNative<Poco::OSP::ServiceRegistry>(args); try { if (args.Length() == 3 && args[1]->IsFunction() && args[2]->IsFunction()) { std::string query = toString(args[0]); ServiceListenerWrapper wrapper; ServiceListenerHolder::Ptr pHolder = new ServiceListenerHolder( args.GetIsolate(), Poco::JS::Core::JSExecutor::current(), *pServiceRegistry, query, args[1].As<v8::Function>(), args[2].As<v8::Function>()); v8::Persistent<v8::Object>& serviceListenerObject(wrapper.wrapNativePersistent(args.GetIsolate(), pHolder)); v8::Local<v8::Object> localListenerObject = v8::Local<v8::Object>::New(args.GetIsolate(), serviceListenerObject); args.GetReturnValue().Set(localListenerObject); } else { returnException(args, std::string("bad arguments - service query, registered callback and unregistered callback required")); } } catch (Poco::Exception& exc) { returnException(args, exc); } }
void ServiceRegistryWrapper::find(const v8::FunctionCallbackInfo<v8::Value>& args) { Poco::OSP::ServiceRegistry* pServiceRegistry = Poco::JS::Core::Wrapper::unwrapNative<Poco::OSP::ServiceRegistry>(args); try { if (args.Length() == 1) { ServiceRefWrapper wrapper; std::string serviceQuery = toString(args[0]); std::vector<Poco::OSP::ServiceRef::Ptr> services; v8::Local<v8::Array> result = v8::Array::New(args.GetIsolate()); int i = 0; if (pServiceRegistry->find(serviceQuery, services)) { for (std::vector<Poco::OSP::ServiceRef::Ptr>::iterator it = services.begin(); it != services.end(); ++it) { v8::Persistent<v8::Object>& serviceRefObject(wrapper.wrapNativePersistent(args.GetIsolate(), *it)); v8::Local<v8::Object> localServiceRefObject = v8::Local<v8::Object>::New(args.GetIsolate(), serviceRefObject); result->Set(i++, localServiceRefObject); } } args.GetReturnValue().Set(result); } else { returnException(args, std::string("bad arguments - service query required")); } } catch (Poco::Exception& exc) { returnException(args, exc); } }