Handle<Value> GeometryFactory::GetSRID(const Arguments& args) { HandleScope scope; GeometryFactory *factory = ObjectWrap::Unwrap<GeometryFactory>(args.This()); return scope.Close(Integer::New(factory->_factory->getSRID())); }
Handle<Value> tick(const Arguments& args) { HandleScope scope; render(); return scope.Close(Undefined()); }
Handle<Value> hello(const Arguments& args) { HandleScope scope; return scope.Close(String::New("world")); }
Handle<Value> Window::Fullscreen(const Arguments& args) { HandleScope scope; NativeWindow *window = ObjectWrap::Unwrap<NativeWindow>(args.This()); window->Fullscreen(); return scope.Close(args.This()); }
Handle<Value> SublineStringMatcherJs::extractMatchingSublines(const Arguments& args) { HandleScope scope; SublineStringMatcherJs* smJs = ObjectWrap::Unwrap<SublineStringMatcherJs>(args.This()); SublineStringMatcherPtr sm = smJs->getSublineStringMatcher(); OsmMapJs* mapJs = ObjectWrap::Unwrap<OsmMapJs>(args[0]->ToObject()); ElementJs* e1Js = ObjectWrap::Unwrap<ElementJs>(args[1]->ToObject()); ElementJs* e2Js = ObjectWrap::Unwrap<ElementJs>(args[2]->ToObject()); ConstOsmMapPtr m = mapJs->getConstMap(); ConstElementPtr e1 = e1Js->getConstElement(); ConstElementPtr e2 = e2Js->getConstElement(); Handle<Value> result; try { WaySublineMatchString match = sm->findMatch(m, e1, e2); if (match.isEmpty()) { return Undefined(); } // convert match into elements in a new map. set<ElementId> eids; eids.insert(e1->getElementId()); eids.insert(e2->getElementId()); OsmMapPtr copiedMap(new OsmMap(m->getProjection())); CopySubsetOp(m, eids).apply(copiedMap); WaySublineMatchString copiedMatch(match, copiedMap); // split the shared line based on the matching subline ElementPtr match1, scraps1; ElementPtr match2, scraps2; WaySublineString string1 = copiedMatch.getSublineString1(); WaySublineString string2 = copiedMatch.getSublineString2(); try { MultiLineStringSplitter().split(copiedMap, string1, copiedMatch.getReverseVector1(), match1, scraps1); MultiLineStringSplitter().split(copiedMap, string2, copiedMatch.getReverseVector2(), match2, scraps2); } catch (const IllegalArgumentException& e) { // this is unusual print out some information useful to debugging. MapReprojector::reprojectToWgs84(copiedMap); LOG_WARN(OsmWriter::toString(copiedMap)); throw e; } if (!match1 || !match2) { result = Undefined(); } else { Handle<Object> obj = Object::New(); obj->Set(String::NewSymbol("map"), OsmMapJs::create(copiedMap)); obj->Set(String::NewSymbol("match1"), ElementJs::New(match1)); obj->Set(String::NewSymbol("match2"), ElementJs::New(match2)); result = obj; } } catch (const HootException& e) { return v8::ThrowException(HootExceptionJs::create(e)); } return scope.Close(result); }
static JSVAL sqlite_data_count(JSARGS args) { HandleScope scope; Local<External>wrap = Local<External>::Cast(args[0]); sqlite3_stmt *stmt = (sqlite3_stmt *)wrap->Value(); return scope.Close(Integer::New(sqlite3_data_count(stmt))); }
static JSVAL sqlite_errmsg16(JSARGS args) { HandleScope scope; Local<External>wrap = Local<External>::Cast(args[0]); sqlite3 *db = (sqlite3 *)wrap->Value(); return scope.Close(String::New((char *)sqlite3_errmsg16(db))); }
Handle<Value> NovaNode::GetDIM(const Arguments &) { HandleScope scope; return scope.Close(cvv8::CastToJS(DIM)); }
Handle<Value> getValueObjectWriteCount(const Arguments &args) { HandleScope scope; NdbRecordObject * nro = unwrapPointer<NdbRecordObject *>(args[0]->ToObject()); return scope.Close(Number::New(nro->getWriteCount())); }
Handle<Value> JSHandler::on(const Arguments& args) { HandleScope scope; if (args.Length() != 2 || !args[0]->IsString() || !args[1]->IsFunction()) { return ThrowException(Exception::TypeError(String::New("please provide an event name and callback function"))); } std::string callback_name = *String::Utf8Value(args[0]->ToString()); Local<Function> callback = Local<Function>::Cast(args[1]); if (callback->IsNull() || callback->IsUndefined()) { return ThrowException(Exception::TypeError(String::New("please provide a valid callback function for second arg"))); } JSHandler* handler = node::ObjectWrap::Unwrap<JSHandler>(args.This()); if (callback_name == "node") { if (!handler->node_cb.IsEmpty()) { handler->node_cb.Dispose(); } handler->node_cb = Persistent<Function>::New(callback); } else if (callback_name == "way") { if (!handler->way_cb.IsEmpty()) { handler->way_cb.Dispose(); } handler->way_cb = Persistent<Function>::New(callback); } else if (callback_name == "relation") { if (!handler->relation_cb.IsEmpty()) { handler->relation_cb.Dispose(); } handler->relation_cb = Persistent<Function>::New(callback); } else if (callback_name == "init") { if (!handler->init_cb.IsEmpty()) { handler->init_cb.Dispose(); } handler->init_cb = Persistent<Function>::New(callback); } else if (callback_name == "before_nodes") { if (!handler->before_nodes_cb.IsEmpty()) { handler->before_nodes_cb.Dispose(); } handler->before_nodes_cb = Persistent<Function>::New(callback); } else if (callback_name == "after_nodes") { if (!handler->after_nodes_cb.IsEmpty()) { handler->after_nodes_cb.Dispose(); } handler->after_nodes_cb = Persistent<Function>::New(callback); } else if (callback_name == "before_ways") { if (!handler->before_ways_cb.IsEmpty()) { handler->before_ways_cb.Dispose(); } handler->before_ways_cb = Persistent<Function>::New(callback); } else if (callback_name == "after_ways") { if (!handler->after_ways_cb.IsEmpty()) { handler->after_ways_cb.Dispose(); } handler->after_ways_cb = Persistent<Function>::New(callback); } else if (callback_name == "before_relations") { if (!handler->before_relations_cb.IsEmpty()) { handler->before_relations_cb.Dispose(); } handler->before_relations_cb = Persistent<Function>::New(callback); } else if (callback_name == "after_relations") { if (!handler->after_relations_cb.IsEmpty()) { handler->after_relations_cb.Dispose(); } handler->after_relations_cb = Persistent<Function>::New(callback); } else if (callback_name == "done") { if (!handler->done_cb.IsEmpty()) { handler->done_cb.Dispose(); } handler->done_cb = Persistent<Function>::New(callback); } return scope.Close(Undefined()); }
Handle<Value> NovaNode::GetSupportedEngines(const Arguments &) { HandleScope scope; return scope.Close(cvv8::CastToJS(Nova::Config::Inst()->GetSupportedEngines())); }
Handle<Value> WrappedScript::EvalMachine(const Arguments& args) { HandleScope scope; if (input_flag == compileCode && args.Length() < 1) { return ThrowException(Exception::TypeError(String::New("needs at least 'code' argument."))); } const int sandbox_index = input_flag == compileCode ? 1 : 0; if (context_flag == userContext && args.Length() < (sandbox_index + 1)) { return ThrowException(Exception::TypeError(String::New("needs a 'context' argument."))); } Local<String> code; if (input_flag == compileCode) code = args[0]->ToString(); Local<Object> sandbox; if (context_flag == newContext) { sandbox = args[sandbox_index]->IsObject() ? args[sandbox_index]->ToObject() : Object::New(); } else if (context_flag == userContext) { sandbox = args[sandbox_index]->ToObject(); } const int filename_index = sandbox_index + (context_flag == newContext ? 1 : 0); Local<String> filename = args.Length() > filename_index ? args[filename_index]->ToString() : String::New("evalmachine.<anonymous>"); const int display_error_index = args.Length() - 1; bool display_error = false; if (args.Length() > display_error_index && args[display_error_index]->IsBoolean() && args[display_error_index]->BooleanValue() == true) { display_error = true; } Persistent<Context> context; Local<Array> keys; unsigned int i; WrappedContext *nContext = NULL; Local<Object> contextArg; if (context_flag == newContext) { // Create the new context context = Context::New(); } else if (context_flag == userContext) { // Use the passed in context contextArg = args[sandbox_index]->ToObject(); nContext = NativeObject::Unwrap<WrappedContext>(contextArg); context = nContext->GetV8Context(); } // New and user context share code. DRY it up. if (context_flag == userContext || context_flag == newContext) { // Enter the context context->Enter(); // Call the initCallback, if it exists if (nContext) { Persistent<Function> initCallback = nContext->GetInitCallback(); if (!initCallback.IsEmpty()) { Handle<Value> callbackArgs[] = { contextArg, context->Global() }; initCallback->Call(contextArg, 2, callbackArgs); } } // Copy everything from the passed in sandbox (either the persistent // context for runInContext(), or the sandbox arg to runInNewContext()). keys = sandbox->GetPropertyNames(); for (i = 0; i < keys->Length(); i++) { Handle<String> key = keys->Get(Integer::New(i))->ToString(); Handle<Value> value = sandbox->Get(key); if (value == sandbox) { value = context->Global(); } context->Global()->Set(key, value); } } Handle<Value> result; Handle<Script> script; if (input_flag == compileCode) { // well, here WrappedScript::New would suffice in all cases, but maybe // Compile has a little better performance where possible script = output_flag == returnResult ? Script::Compile(code, filename) : Script::New(code, filename); if (script.IsEmpty()) { // Hack because I can't get a proper stacktrace on SyntaxError return Undefined(); } } else { WrappedScript *n_script = NativeObject::Unwrap<WrappedScript>(args.Holder()); if (!n_script) { return ThrowException(Exception::Error(String::New("Must be called as a method of Script."))); } else if (n_script->script_.IsEmpty()) { return ThrowException(Exception::Error(String::New("'this' must be a result of previous " "new Script(code) call."))); } script = n_script->script_; } if (output_flag == returnResult) { result = script->Run(); if (result.IsEmpty()) { if (context_flag == newContext) { context->DetachGlobal(); context->Exit(); context.Dispose(); } return Undefined(); } } else { WrappedScript *n_script = NativeObject::Unwrap<WrappedScript>(args.Holder()); if (!n_script) { return ThrowException(Exception::Error(String::New("Must be called as a method of Script."))); } n_script->script_ = Persistent<Script>::New(script); result = args.This(); } if (context_flag == userContext || context_flag == newContext) { // success! copy changes back onto the sandbox object. keys = context->Global()->GetPropertyNames(); for (i = 0; i < keys->Length(); i++) { Handle<String> key = keys->Get(Integer::New(i))->ToString(); Handle<Value> value = context->Global()->Get(key); if (value == context->Global()) { value = sandbox; } sandbox->Set(key, value); } } if (context_flag == newContext) { // Clean up, clean up, everybody everywhere! context->DetachGlobal(); context->Exit(); context.Dispose(); } else if (context_flag == userContext) { // Exit the passed in context. context->Exit(); } if (result->IsObject()) { Local<Context> creation = result->ToObject()->CreationContext(); } return result == args.This() ? result : scope.Close(result); }
Handle<Value> CharsetMap_recode_in(const Arguments &args) { HandleScope scope; DEBUG_MARKER(UDEB_DEBUG); REQUIRE_ARGS_LENGTH(5); JsValueConverter<CharsetMap *> converter(args.Holder()); CharsetMap * csmap = converter.toC(); int32_t lengths[2]; enum { SOURCE = 0 , DEST = 1 }; // for lengths[] int status = CharsetMap::RECODE_OK; int copyLen; Local<Object> NodeBuffer = args[2]->ToObject(); Local<String> sourceStr = args[0]->ToString(); int32_t cs_to = args[1]->Int32Value(); char * buffer = node::Buffer::Data(NodeBuffer); uint32_t offset = args[3]->Uint32Value(); lengths[DEST] = args[4]->Int32Value(); /* Source string length and charset */ int32_t cs_from = csmap->getUTF16CharsetNumber(); lengths[SOURCE] = sourceStr->Length(); /* Special case: if the destination is 2-byte unicode, just copy directly. sourceStr->Write(uint16_t * ...) might face alignment issues, so we use memcpy(). */ if(cs_to == cs_from) { if(lengths[DEST] >= lengths[SOURCE]) { copyLen = lengths[SOURCE]; } else { copyLen = lengths[DEST]; status = csmap->RECODE_BUFF_TOO_SMALL; } DEBUG_PRINT("recodeIn() optimized path UTF16 -> UTF16 using memcpy"); String::Value source(sourceStr); memcpy(buffer + offset, *source, copyLen); lengths[DEST] = copyLen; } /* Special case: if the destination is UTF-8, let V8 do the copying. copyLen will receive the length written in characters. The return value is the length written in bytes. */ else if(cs_to == csmap->getUTF8CharsetNumber()) { lengths[DEST] = sourceStr->WriteUtf8(buffer + offset, lengths[DEST], ©Len, 1); if(copyLen < sourceStr->Length()) { status = CharsetMap::RECODE_BUFF_TOO_SMALL; } DEBUG_PRINT("recodeIn() UTF16 -> UTF8 using v8 WriteUtf8(): %s", buffer + offset); } /* General case: use CharsetMap::recode() */ else { String::Value source(sourceStr); status = csmap->recode(lengths, cs_from, cs_to, *source, buffer + offset); DEBUG_PRINT("recodeIn() UTF16 -> X using recode(%c%c%c%c...): %s", (*source)[1], (*source)[3], (*source)[5], (*source)[7], buffer + offset); } /* Build the return value */ Local<Object> returnVal = Object::New(); returnVal->Set(String::NewSymbol("status"), Integer::New(status)); returnVal->Set(String::NewSymbol("lengthIn"), Integer::New(lengths[SOURCE])); returnVal->Set(String::NewSymbol("lengthOut"), Integer::New(lengths[DEST])); returnVal->Set(String::NewSymbol("charset"), args[1]); returnVal->Set(String::NewSymbol("offset"), Integer::New(offset)); return scope.Close(returnVal); }
Handle<Value> GeometryFactory::GetPrecisionModel(const Arguments& args) { HandleScope scope; GeometryFactory *factory = ObjectWrap::Unwrap<GeometryFactory>(args.This()); return scope.Close(PrecisionModel::New(factory->_factory->getPrecisionModel())); }
v8::Handle<v8::Value> Input_v8::Poll(const v8::Arguments &args) { HandleScope scope; Handle<Object> holder = args.Holder(); Input_v8 *input_v8 = ObjectWrap::Unwrap<Input_v8>(holder); if (NULL == input_v8) { return ThrowException(v8::Exception::ReferenceError(String::NewSymbol( "Input::poll(): NULL Holder." ))); } bool anyResults = input_v8->input->poll(); if (anyResults) { Input::PollResults &results = input_v8->input->results; Handle<Function> emitFunction = args.Holder()->Get( String::New("emit") ).As<Function>(); Handle<Value> argv[2]; if (results.keyDown.size() > 0) { argv[0] = String::New("keyDown"); for (unsigned int i = 0; i < results.keyDown.size(); i++) { argv[1] = Integer::New(results.keyDown[i].code); emitFunction->Call(holder, 2, argv); } } if (results.keyUp.size() > 0) { argv[0] = String::New("keyUp"); for (unsigned int i = 0; i < results.keyUp.size(); i++) { argv[1] = Integer::New(results.keyUp[i].code); emitFunction->Call(holder, 2, argv); } } // TODO: Joystick if (results.resize.width && results.resize.height) { argv[0] = String::New("resize"); Handle<Array> resize = Array::New(2); resize->Set(0, Integer::New(results.resize.width)); resize->Set(1, Integer::New(results.resize.height)); argv[1] = resize; emitFunction->Call(holder, 2, argv); } if (results.quit) { argv[0] = String::New("quit"); argv[1] = Boolean::New(true); emitFunction->Call(holder, 2, argv); } } return scope.Close(Boolean::New(anyResults)); }
Handle<Value> prepareForUpdate(const Arguments &args) { HandleScope scope; NdbRecordObject * nro = unwrapPointer<NdbRecordObject *>(args[0]->ToObject()); return scope.Close(nro->prepare()); }
Local<Value> c_runScript(const char* input) { HandleScope scope; Local<Value> value = Script::Compile(String::New(input))->Run(); return scope.Close(value); }
v8::Handle<v8::Value> DocumentCopyingContextDriver::CreateFormXObjectFromPDFPage(const v8::Arguments& args) { HandleScope scope; DocumentCopyingContextDriver* copyingContextDriver = ObjectWrap::Unwrap<DocumentCopyingContextDriver>(args.This()); if(!copyingContextDriver->CopyingContext) { ThrowException(Exception::TypeError(String::New("copying context object not initialized, create using pdfWriter.createPDFCopyingContext"))); return scope.Close(Undefined()); } if(args.Length() < 2 || args.Length() > 3 || !args[0]->IsNumber() || (!args[1]->IsNumber() && !args[1]->IsArray()) || (args.Length() == 3 && !args[2]->IsArray())) { ThrowException(Exception::TypeError(String::New("Wrong arguments. provide 2 or 3 arugments, where the first is a 0 based page index, and the second is a EPDFPageBox enumeration value or a 4 numbers array defining an box. a 3rd parameter may be provided to deisgnate the result form matrix"))); return scope.Close(Undefined()); } double matrixBuffer[6]; double* transformationMatrix = NULL; if(args.Length() == 3) { Handle<Object> matrixArray = args[2]->ToObject(); if(matrixArray->Get(v8::String::New("length"))->ToObject()->Uint32Value() != 6) { ThrowException(Exception::TypeError(String::New("matrix array should be 6 numbers long"))); return scope.Close(Undefined()); } for(int i=0;i<6;++i) matrixBuffer[i] = matrixArray->Get(i)->ToNumber()->Value(); transformationMatrix = matrixBuffer; } EStatusCodeAndObjectIDType result; if(args[0]->IsNumber()) { result = copyingContextDriver->CopyingContext->CreateFormXObjectFromPDFPage(args[0]->ToNumber()->Uint32Value(), (EPDFPageBox)args[1]->ToNumber()->Uint32Value(), transformationMatrix); } else { Handle<Object> boxArray = args[1]->ToObject(); if(boxArray->Get(v8::String::New("length"))->ToObject()->Uint32Value() != 4) { ThrowException(Exception::TypeError(String::New("box dimensions array should be 4 numbers long"))); return scope.Close(Undefined()); } PDFRectangle box(boxArray->Get(0)->ToNumber()->Value(), boxArray->Get(1)->ToNumber()->Value(), boxArray->Get(2)->ToNumber()->Value(), boxArray->Get(3)->ToNumber()->Value()); result = copyingContextDriver->CopyingContext->CreateFormXObjectFromPDFPage(args[0]->ToNumber()->Uint32Value(), box, transformationMatrix); } if(result.first != eSuccess) { ThrowException(Exception::Error(String::New("Unable to create form xobject from PDF page, parhaps the page index does not fit the total pages count"))); return scope.Close(Undefined()); } Local<Number> idValue = Number::New(result.second); return scope.Close(idValue); }
static JSVAL sqlite_extended_errcode(JSARGS args) { HandleScope scope; Local<External>wrap = Local<External>::Cast(args[0]); sqlite3 *db = (sqlite3 *)wrap->Value(); return scope.Close(Integer::New(sqlite3_extended_errcode(db))); }
Handle<Value> CreateEngine(const Arguments& args) { HandleScope scope; return scope.Close( Audio::AudioEngine::NewInstance(args) ); } // end CreateEngine()
Handle<Value> ImageView::encodeSync(const Arguments& args) { HandleScope scope; ImageView* im = ObjectWrap::Unwrap<ImageView>(args.This()); std::string format = "png"; palette_ptr palette; // accept custom format if (args.Length() >= 1) { if (!args[0]->IsString()) return ThrowException(Exception::TypeError( String::New("first arg, 'format' must be a string"))); format = TOSTR(args[0]); } // options hash if (args.Length() >= 2) { if (!args[1]->IsObject()) return ThrowException(Exception::TypeError( String::New("optional second arg must be an options object"))); Local<Object> options = args[1]->ToObject(); if (options->Has(String::New("palette"))) { Local<Value> format_opt = options->Get(String::New("palette")); if (!format_opt->IsObject()) return ThrowException(Exception::TypeError( String::New("'palette' must be an object"))); Local<Object> obj = format_opt->ToObject(); if (obj->IsNull() || obj->IsUndefined() || !Palette::constructor->HasInstance(obj)) return ThrowException(Exception::TypeError(String::New("mapnik.Palette expected as second arg"))); palette = ObjectWrap::Unwrap<Palette>(obj)->palette(); } } try { std::string s; if (palette.get()) { s = save_to_string(*(im->this_), format, *palette); } else { s = save_to_string(*(im->this_), format); } #if NODE_VERSION_AT_LEAST(0,3,0) node::Buffer *retbuf = Buffer::New((char*)s.data(),s.size()); #else node::Buffer *retbuf = Buffer::New(s.size()); memcpy(retbuf->data(), s.data(), s.size()); #endif return scope.Close(retbuf->handle_); } catch (std::exception & ex) { return ThrowException(Exception::Error( String::New(ex.what()))); } catch (...) { return ThrowException(Exception::Error( String::New("unknown exception happened when encoding image: please file bug report"))); } }
Handle<Value> Session::Authorize(const Arguments& args) { HandleScope scope; if (args.Length() < 1 || !args[0]->IsString()) { return ThrowException(Exception::Error(String::New( "Service URI string must be provided as first parameter."))); } if (args.Length() < 2 || !args[1]->IsInt32()) { return ThrowException(Exception::Error(String::New( "Integer correlation identifier must be provided " "as second parameter."))); } if (args.Length() > 2) { return ThrowException(Exception::Error(String::New( "Function expects at most two arguments."))); } Local<String> s = args[0]->ToString(); String::Utf8Value uriv(s); int cidi = args[1]->Int32Value(); Session* session = ObjectWrap::Unwrap<Session>(args.This()); BLPAPI_EXCEPTION_TRY blpapi::EventQueue tokenEventQueue; blpapi::CorrelationId tokenCid(static_cast<void*>(&tokenEventQueue)); session->d_session->generateToken(tokenCid, &tokenEventQueue); std::string token; blpapi::Event ev = tokenEventQueue.nextEvent(); if (blpapi::Event::TOKEN_STATUS == ev.eventType() || blpapi::Event::REQUEST_STATUS == ev.eventType()) { blpapi::MessageIterator msgIter(ev); while (msgIter.next()) { blpapi::Message msg = msgIter.message(); if ("TokenGenerationSuccess" == msg.messageType()) { token = msg.getElementAsString("token"); } else { std::stringstream ss; ss << "Failed to generate token: " << msg.getElement("reason"); std::string s = ss.str(); return ThrowException(Exception::Error(String::New( s.c_str()))); } } } if (0 == token.length()) { return ThrowException(Exception::Error(String::New( "Failed to get token."))); } blpapi::Service authService = session->d_session->getService(*uriv); blpapi::Request authRequest = authService.createAuthorizationRequest(); authRequest.set("token", token.c_str()); session->d_identity = session->d_session->createIdentity(); blpapi::CorrelationId cid(cidi); session->d_session->sendAuthorizationRequest(authRequest, &session->d_identity, cid); BLPAPI_EXCEPTION_CATCH_RETURN return scope.Close(Integer::New(cidi)); }
Handle<Value> Window::GetTopmost(Local<String> property, const AccessorInfo &info) { HandleScope scope; NativeWindow *window = ObjectWrap::Unwrap<NativeWindow>(info.Holder()); return scope.Close(Boolean::New(window->GetTopmost())); }
Handle<Value> Session::subscribe(const Arguments& args, bool resubscribe) { HandleScope scope; if (args.Length() < 1 || !args[0]->IsArray()) { return ThrowException(Exception::Error(String::New( "Array of subscription information must be provided."))); } if (args.Length() >= 2 && !args[1]->IsUndefined() && !args[1]->IsString()) { return ThrowException(Exception::Error(String::New( "Optional subscription label must be a string."))); } if (args.Length() > 2) { return ThrowException(Exception::Error(String::New( "Function expects at most two arguments."))); } blpapi::SubscriptionList sl; Local<Object> o = args[0]->ToObject(); for (std::size_t i = 0; i < Array::Cast(*(args[0]))->Length(); ++i) { Local<Value> v = o->Get(i); if (!v->IsObject()) { return ThrowException(Exception::Error(String::New( "Array elements must be objects " "containing subscription information."))); } Local<Object> io = v->ToObject(); // Process 'security' string Local<Value> iv = io->Get(String::New("security")); if (!iv->IsString()) { return ThrowException(Exception::Error(String::New( "Property 'security' must be a string."))); } String::Utf8Value secv(iv); if (0 == secv.length()) { return ThrowException(Exception::Error(String::New( "Property 'security' must be a string."))); } // Process 'fields' array iv = io->Get(String::New("fields")); if (!iv->IsArray()) { return ThrowException(Exception::Error(String::New( "Property 'fields' must be an array of strings."))); } std::string fields; formFields(&fields, iv->ToObject()); // Process 'options' array iv = io->Get(String::New("options")); if (!iv->IsUndefined() && !iv->IsNull() && !iv->IsObject()) { return ThrowException(Exception::Error(String::New( "Property 'options' must be an object containing " "whose keys and key values will be configured as " "options."))); } std::string options; formOptions(&options, iv); // Process 'correlation' int or string iv = io->Get(String::New("correlation")); if (!iv->IsInt32()) { return ThrowException(Exception::Error(String::New( "Property 'correlation' must be an integer."))); } int correlation = iv->Int32Value(); sl.add(*secv, fields.c_str(), options.c_str(), blpapi::CorrelationId(correlation)); } Session* session = ObjectWrap::Unwrap<Session>(args.This()); BLPAPI_EXCEPTION_TRY if (args.Length() == 2) { Local<String> s = args[1]->ToString(); String::Utf8Value labelv(s); if (resubscribe) session->d_session->resubscribe(sl, *labelv, labelv.length()); else session->d_session->subscribe(sl, *labelv, labelv.length()); } else { if (resubscribe) session->d_session->resubscribe(sl); else session->d_session->subscribe(sl); } BLPAPI_EXCEPTION_CATCH_RETURN return scope.Close(args.This()); }
// JOSH: NO-OP. This is here just to match the desktop equivalents Handle<Value> setWindowSize(const Arguments& args) { HandleScope scope; return scope.Close(Undefined()); }
Handle<Value> Session::Request(const Arguments& args) { HandleScope scope; if (args.Length() < 1 || !args[0]->IsString()) { return ThrowException(Exception::Error(String::New( "Service URI string must be provided as first parameter."))); } if (args.Length() < 2 || !args[1]->IsString()) { return ThrowException(Exception::Error(String::New( "String request name must be provided as second parameter."))); } if (args.Length() < 3 || !args[2]->IsObject()) { return ThrowException(Exception::Error(String::New( "Object containing request parameters must be provided " "as third parameter."))); } if (args.Length() < 4 || !args[3]->IsInt32()) { return ThrowException(Exception::Error(String::New( "Integer correlation identifier must be provided " "as fourth parameter."))); } if (args.Length() >= 5 && !args[4]->IsUndefined() && !args[4]->IsString()) { return ThrowException(Exception::Error(String::New( "Optional request label must be a string."))); } if (args.Length() > 5) { return ThrowException(Exception::Error(String::New( "Function expects at most five arguments."))); } int cidi = args[3]->Int32Value(); Session* session = ObjectWrap::Unwrap<Session>(args.This()); BLPAPI_EXCEPTION_TRY Local<String> uri = args[0]->ToString(); String::AsciiValue uriv(uri); blpapi::Service service = session->d_session->getService(*uriv); Local<String> name = args[1]->ToString(); String::Utf8Value namev(name); blpapi::Request request = service.createRequest(*namev); // Loop over object properties, appending/setting into the request. Local<Object> obj = args[2]->ToObject(); Local<Array> props = obj->GetPropertyNames(); for (std::size_t i = 0; i < props->Length(); ++i) { // Process the key. Local<Value> keyval = props->Get(i); Local<String> key = keyval->ToString(); String::Utf8Value keyv(key); // Process the value. // // The values present on the outer object are marshalled into the // blpapi::Request by setting values using 'set'. Arrays indicate // values which should be marshalled using 'append'. Local<Value> val = obj->Get(keyval); if (val->IsString()) { Local<String> s = val->ToString(); String::Utf8Value valv(s); request.set(*keyv, *valv); } else if (val->IsBoolean()) { request.set(*keyv, val->BooleanValue()); } else if (val->IsNumber()) { request.set(*keyv, val->NumberValue()); } else if (val->IsInt32()) { request.set(*keyv, val->Int32Value()); } else if (val->IsUint32()) { request.set(*keyv, static_cast<blpapi::Int64>(val->Uint32Value())); } else if (val->IsDate()) { blpapi::Datetime dt; mkdatetime(&dt, val); request.set(*keyv, dt); } else if (val->IsArray()) { // Arrays are marshalled into the blpapi::Request by appending // value types using the key of the array in the outer object. Local<Object> subarray = val->ToObject(); int jmax = Array::Cast(*val)->Length(); for (int j = 0; j < jmax; ++j) { Local<Value> subval = subarray->Get(j); // Only strings, booleans, and numbers are marshalled. if (subval->IsString()) { Local<String> s = subval->ToString(); String::Utf8Value subvalv(s); request.append(*keyv, *subvalv); } else if (subval->IsBoolean()) { request.append(*keyv, subval->BooleanValue()); } else if (subval->IsNumber()) { request.append(*keyv, subval->NumberValue()); } else if (subval->IsInt32()) { request.append(*keyv, subval->Int32Value()); } else if (subval->IsUint32()) { request.append(*keyv, static_cast<blpapi::Int64>(subval->Uint32Value())); } else if (subval->IsDate()) { blpapi::Datetime dt; mkdatetime(&dt, subval); request.append(*keyv, dt); } else { return ThrowException(Exception::Error(String::New( "Array contains invalid value type."))); } } } else { return ThrowException(Exception::Error(String::New( "Object contains invalid value type."))); } } blpapi::CorrelationId cid(cidi); if (args.Length() == 5) { String::Utf8Value labelv(args[4]->ToString()); session->d_session->sendRequest(request, session->d_identity, cid, 0, *labelv, labelv.length()); } else { session->d_session->sendRequest(request, session->d_identity, cid); } BLPAPI_EXCEPTION_CATCH_RETURN return scope.Close(Integer::New(cidi)); }
Handle<Value> setEventCallback(const Arguments& args) { HandleScope scope; eventCallbackSet = true; NODE_EVENT_CALLBACK = Persistent<Function>::New(Handle<Function>::Cast(args[0])); return scope.Close(Undefined()); }
Handle<Value> rs::Fetch(const v8::Arguments& args){ HandleScope scope; rs* _this = node::ObjectWrap::Unwrap<rs>(args.This()); std::vector<MetaData> metaData = _this->_rs->getColumnListMetaData(); int columnCount = metaData.size(); if ( columnCount > 0 ){ int32_t arrayIndex = 0; if ( _this->_rs->next() ){ Local<Object> js_field_obj = Object::New(); Local<String> pName; for ( int i = 0; i < columnCount; i++ ) { pName = V8STR(metaData[i].getString(MetaData::ATTR_NAME).c_str()); int pNum = i+1; switch ( metaData[i].getInt(MetaData::ATTR_DATA_TYPE) ){ case OCCI_SQLT_AFC : case OCCI_SQLT_VCS : case OCCI_SQLT_STR : case OCCI_SQLT_CHR : { std::string pVal = _this->_rs->getString(pNum); js_field_obj->Set( pName, V8STR(pVal.c_str()) ); } break; case OCCIFLOAT : case OCCI_SQLT_NUM : { double pVal = _this->_rs->getDouble(pNum); js_field_obj->Set( pName, v8::Number::New(pVal) ); } break; case OCCIINT : { int32_t pVal = _this->_rs->getInt(pNum); js_field_obj->Set( pName, v8::Integer::NewFromUnsigned(pVal) ); } break; case OCCI_SQLT_CLOB: { Clob lClob = _this->_rs->getClob(pNum); lClob.setCharSetForm(OCCI_SQLCS_NCHAR); if (lClob.isNull() ){ js_field_obj->Set( pName, String::New("") ); } else { lClob.open(OCCI_LOB_READONLY); const unsigned int BUFSIZE = 100000; unsigned char buffer[BUFSIZE]; unsigned int readAmt=BUFSIZE; unsigned int offset=1; memset(buffer,0,sizeof(buffer)); lClob.read(readAmt,buffer,BUFSIZE,offset); lClob.close(); js_field_obj->Set( pName, String::New((const char*)buffer) ); } } break; } } return scope.Close(js_field_obj); } } return scope.Close(False()); }
Handle<Value> NdbIndexScanOperation_Wrapper(NdbIndexScanOperation *op) { HandleScope scope; Local<Object> jsobj = NdbIndexScanOperationEnvelope.newWrapper(); wrapPointerInObject(op, NdbIndexScanOperationEnvelope, jsobj); return scope.Close(jsobj); }
Handle<Object> GetTableCall::buildDBColumn(const NdbDictionary::Column *col) { HandleScope scope; Local<Object> obj = NdbDictColumnEnv.newWrapper(); wrapPointerInObject(col, NdbDictColumnEnv, obj); NdbDictionary::Column::Type col_type = col->getType(); bool is_int = (col_type <= NDB_TYPE_BIGUNSIGNED); bool is_dec = ((col_type == NDB_TYPE_DECIMAL) || (col_type == NDB_TYPE_DECIMALUNSIGNED)); bool is_binary = ((col_type == NDB_TYPE_BLOB) || (col_type == NDB_TYPE_BINARY) || (col_type == NDB_TYPE_VARBINARY) || (col_type == NDB_TYPE_LONGVARBINARY)); bool is_char = ((col_type == NDB_TYPE_CHAR) || (col_type == NDB_TYPE_TEXT) || (col_type == NDB_TYPE_VARCHAR) || (col_type == NDB_TYPE_LONGVARCHAR)); /* Required Properties */ obj->Set(String::NewSymbol("name"), String::New(col->getName()), ReadOnly); obj->Set(String::NewSymbol("columnNumber"), v8::Int32::New(col->getColumnNo()), ReadOnly); obj->Set(String::NewSymbol("columnType"), getColumnType(col), ReadOnly); obj->Set(String::NewSymbol("isIntegral"), Boolean::New(is_int), ReadOnly); obj->Set(String::NewSymbol("isNullable"), Boolean::New(col->getNullable()), ReadOnly); obj->Set(String::NewSymbol("isInPrimaryKey"), Boolean::New(col->getPrimaryKey()), ReadOnly); obj->Set(String::NewSymbol("columnSpace"), v8::Int32::New(col->getSizeInBytes()), ReadOnly); /* Implementation-specific properties */ obj->Set(String::NewSymbol("ndbTypeId"), v8::Int32::New(static_cast<int>(col->getType())), ReadOnly); obj->Set(String::NewSymbol("ndbRawDefaultValue"), getDefaultValue(col), ReadOnly); /* Optional Properties, depending on columnType */ /* Group A: Numeric */ if(is_int || is_dec) { obj->Set(String::NewSymbol("isUnsigned"), getIntColumnUnsigned(col), ReadOnly); } if(is_int) { obj->Set(String::NewSymbol("intSize"), v8::Int32::New(col->getSizeInBytes()), ReadOnly); } if(is_dec) { obj->Set(String::NewSymbol("scale"), v8::Int32::New(col->getScale()), ReadOnly); obj->Set(String::NewSymbol("precision"), v8::Int32::New(col->getPrecision()), ReadOnly); } /* Group B: Non-numeric */ if(is_binary || is_char) { obj->Set(String::NewSymbol("length"), v8::Int32::New(col->getLength()), ReadOnly); obj->Set(String::NewSymbol("isBinary"), Boolean::New(is_binary), ReadOnly); if(is_char) { obj->Set(String::NewSymbol("charsetNumber"), Number::New(col->getCharsetNumber()), ReadOnly); // todo: charsetName } } return scope.Close(obj); }