void VJSGlobalClass::do_ProgressIndicator(VJSParms_callStaticFunction& ioParms, VJSGlobalObject *inContext) { VString sessiontile; VString windowtile, userinfo; bool caninterrupt = false; Real maxvalue = -1; VError err = VE_OK; if (ioParms.IsNumberParam(1)) ioParms.GetRealParam(1, &maxvalue); else err = vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_NUMBER, "1"); if (err == VE_OK ) { if (ioParms.IsStringParam(2)) ioParms.GetStringParam(2, sessiontile); else err = vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_STRING, "2"); } caninterrupt = ioParms.GetBoolParam( 3, L"Can Interrupt", "Cannot Interrupt"); //VProgressIndicator* progress = inContext->GetRuntimeDelegate()->CreateProgressIndicator( windowtile); if (err == VE_OK) { VProgressIndicator* progress = new VProgressIndicator(); if (progress != NULL) { if (ioParms.CountParams() >= 4) { if (ioParms.IsStringParam(4)) { ioParms.GetStringParam(4, windowtile); progress->SetTitle(windowtile); } else vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_STRING, "4"); } if (ioParms.CountParams() >= 5) { if (ioParms.IsStringParam(5)) { ioParms.GetStringParam(5, userinfo); progress->SetUserInfo(userinfo); } else vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_STRING, "5"); } progress->BeginSession((sLONG8)maxvalue, sessiontile, caninterrupt); } ioParms.ReturnValue(VJSProgressIndicator::CreateInstance(ioParms.GetContextRef(), progress)); ReleaseRefCountable( &progress); } else ioParms.ReturnNullValue(); }
void VJSImage::_thumbnail(XBOX::VJSParms_callStaticFunction& ioParms, VJSPictureContainer* inPict) { bool ok = true; if (!ioParms.IsNumberParam(1)) { ok = false; vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_NUMBER, "1"); } if (!ioParms.IsNumberParam(2)) { ok = false; vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_NUMBER, "2"); } VPicture* pic = inPict->GetPict(); if (pic != nil && ok) { sLONG w = 0, h = 0, mode = 0; ioParms.GetLongParam(1, &w); ioParms.GetLongParam(2, &h); ioParms.GetLongParam(3, &mode); if (w == 0) w = 300; if (h == 0) h = 300; if (mode == 0) mode = 4; VPicture* thumb = pic->BuildThumbnail(w, h, (PictureMosaic)mode); if (thumb != nil) { VPictureCodecFactoryRef fact; VPicture* thumb2 = new VPicture(); VError err = fact->Encode(*thumb, L".jpg", *thumb2, nil); if (err == VE_OK) { /* VJSPictureContainer* pictContains = new VJSPictureContainer(thumb2, true, ioParms.GetContextRef()); ioParms.ReturnValue(VJSImage::CreateInstance(ioParms.GetContextRef(), pictContains)); pictContains->Release(); */ ioParms.ReturnVValue(*thumb2); delete thumb2; } else { delete thumb2; ioParms.ReturnNullValue(); } delete thumb; } else ioParms.ReturnNullValue(); } else ioParms.ReturnNullValue(); }
VError VZipComponent::CompressStream(VStream* inStreamToCompress, EZipCompressionLevel inCompressionLevel, VStream* outCompressedStream ) { if(!testAssert(inStreamToCompress != NULL)) return VE_INVALID_PARAMETER; if(!testAssert(outCompressedStream != NULL)) return VE_INVALID_PARAMETER; if(!testAssert( ( (inStreamToCompress -> GetSize()) - (inStreamToCompress -> GetPos()) ) > 0)) return VE_STREAM_EOF; VError errorToReturn = VE_OK; if (!inStreamToCompress->IsReading()){ errorToReturn = vThrowError(VE_STREAM_NOT_OPENED); } if(errorToReturn == VE_OK){ if(!outCompressedStream->IsWriting()) errorToReturn = vThrowError(VE_STREAM_NOT_OPENED); } if(errorToReturn == VE_OK){ // The stream to compress is put in a buffer before calling CompressMemoryBlock sLONG8 streamToCompressSize = (inStreamToCompress -> GetSize()) - (inStreamToCompress -> GetPos()); Bytef * bufferToCompress = (Bytef *) malloc(streamToCompressSize * sizeof(Bytef)); if(bufferToCompress == NULL){ errorToReturn = VE_MEMORY_FULL; } if (errorToReturn == VE_OK){ errorToReturn = inStreamToCompress -> GetData(bufferToCompress, streamToCompressSize); if (errorToReturn != VE_OK){ errorToReturn = vThrowError(VE_STREAM_CANNOT_READ); } if (errorToReturn == VE_OK){ errorToReturn = CompressMemoryBlock(bufferToCompress, streamToCompressSize, inCompressionLevel, outCompressedStream); } free (bufferToCompress); // YT 23-Nov-2009 - Fix memory leaks } } return errorToReturn; }
VError VJSONWriter::StringifyArray( const VJSONArray *inArray, VString& outString) { VError err = VE_OK; if (inArray == NULL) { outString = VJSONValue::sUndefinedString; } else if (inArray->IsEmpty()) { outString = "[]"; } else { IncrementLevel(); VectorOfVString array; size_t count = inArray->GetCount(); try { array.resize( count); } catch(...) { err = vThrowError( VE_MEMORY_FULL); } VectorOfVString::iterator j = array.begin(); for( size_t i = 0 ; (i < count) && (err == VE_OK) ; ++i, ++j) { err = StringifyValue( (*inArray)[i], *j); InsertIndentString( *j); } DecrementLevel(); if (err == VE_OK) { array.front().Insert( '[', 1); AppendIndentString( array.back()); array.back().AppendUniChar( ']'); err = outString.Join( array, ',') ? VE_OK : vThrowError( VE_STRING_ALLOC_FAILED); } } return err; }
void VJSStream::do_BinaryStream(VJSParms_callStaticFunction& ioParms) { VFile* file = ioParms.RetainFileParam( 1); bool forwrite = ioParms.GetBoolParam( 2, L"Write", L"Read"); if (file != NULL) { VError err = VE_OK; if (forwrite) { if (!file->Exists()) err = file->Create(); } VFileStream* stream = new VFileStream(file); if (err == VE_OK) { if (forwrite) err = stream->OpenWriting(); else err = stream->OpenReading(); } if (err == VE_OK) { ioParms.ReturnValue(VJSStream::CreateInstance(ioParms.GetContextRef(), stream)); } else { delete stream; } } else vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_FILE, "1"); ReleaseRefCountable( &file); }
const XBOX::VValueBag* VJSPictureContainer::RetainMetaBag() { #if !VERSION_LINUX if (fMetaBag == NULL) { if (fPict != NULL) { const VPictureData* picdata = fPict->RetainNthPictData(1); if (picdata != NULL) { fMetaBag = picdata->RetainMetadatas(); picdata->Release(); } } } return RetainRefCountable(fMetaBag); #else // Postponed Linux Implementation ! vThrowError(VE_UNIMPLEMENTED); xbox_assert(false); return NULL; #endif }
void VProcess::Run() { VTask *mainTask = VTask::GetMain(); if (!testAssert( (mainTask != NULL) && mainTask->IsCurrent() && (mainTask->GetState() == TS_RUNNING) )) return; if (!fInitCalled) fInitOK = Init(); if (fInitOK) { vFlushErrors(); StartMessaging(); DoRun(); DoQuit(); mainTask->Kill(); StopMessaging(); } else { vThrowError(VE_CANNOT_INITIALIZE_APPLICATION, "VApplication::DoInit failed"); } }
void VJSImage::_save(XBOX::VJSParms_callStaticFunction& ioParms, VJSPictureContainer* inPict) { VPictureCodecFactoryRef fact; const VPictureCodec* encoder = nil; bool ok = false; VPicture* pic = inPict->GetPict(); if (pic != nil) { VFile* file = ioParms.RetainFileParam(1); if (file != nil) { VString mimetype; ioParms.GetStringParam(2, mimetype); if (mimetype.IsEmpty()) { VString extension; file->GetExtension(extension); if (extension.IsEmpty()) extension = L"pic"; encoder = fact->RetainEncoderForExtension(extension); } else encoder = fact->RetainEncoderByIdentifier(mimetype); if (encoder != nil) { VError err = VE_OK; if (file->Exists()) err = file->Delete(); if (err == VE_OK) { VValueBag *pictureSettings = nil; VValueBag *bagMetas = (VValueBag*)inPict->RetainMetaBag(); if (bagMetas != nil) { pictureSettings = new VValueBag(); ImageEncoding::stWriter settingsWriter(pictureSettings); VValueBag *bagRetained = settingsWriter.CreateOrRetainMetadatas( bagMetas); if (bagRetained) bagRetained->Release(); } err=encoder->Encode(*pic, pictureSettings, *file); QuickReleaseRefCountable(bagMetas); QuickReleaseRefCountable(pictureSettings); if (err == VE_OK) ok = true; } encoder->Release(); } file->Release(); } else vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_FILE, "1"); } ioParms.ReturnBool(ok); }
VError VJSONCloner::CloneObject( const VJSONObject *inObject, VJSONValue& outValue) { VError err = VE_OK; if (inObject == NULL) { outValue.SetUndefined(); } else { try { VJSONValue value; std::pair<MapOfValueByObject::iterator,bool> i = fClonedObjects.insert( MapOfValueByObject::value_type( inObject, value)); if (i.second) { // not already cloned err = inObject->Clone( i.first->second, *this); } outValue = i.first->second; } catch(...) { outValue.SetUndefined(); err = vThrowError( VE_MEMORY_FULL); } } return err; }
void VJSGlobalClass::do_XmlToJSON(VJSParms_callStaticFunction& ioParms, VJSGlobalObject*) { VString xml; VString json, root; bool simpleJSON = false; ioParms.GetStringParam( 1, xml); if ( ioParms.CountParams() >= 2) { VString s; if (ioParms.IsStringParam(2)) { ioParms.GetStringParam(2, s); if(s== "json-bag") { simpleJSON = true; root="bag"; if(ioParms.CountParams() >= 3) { if (ioParms.IsStringParam(3)) ioParms.GetStringParam(3, root); else vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_STRING, "3"); } } } else vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_STRING, "2"); } if (simpleJSON) { XBOX::VValueBag *bag = new XBOX::VValueBag; VError err = LoadBagFromXML( xml, root, *bag); if(err == VE_OK) bag->GetJSONString(json); ReleaseRefCountable( &bag); } else { VString errorMessage; sLONG lineNumber; VError err = VXMLJsonUtility::XMLToJson(xml, json, errorMessage, lineNumber); } ioParms.ReturnString(json); }
VError VZipComponent::ExpandStream(VStream* inCompressedStream, VStream* outExpandedStream ) { if(!testAssert(inCompressedStream != NULL)) return VE_INVALID_PARAMETER; if(!testAssert(outExpandedStream != NULL)) return VE_INVALID_PARAMETER; if(!testAssert( ( (inCompressedStream -> GetSize()) - (inCompressedStream -> GetPos()) ) > 0)) return VE_STREAM_EOF; VError errorToReturn = VE_OK; if (!inCompressedStream->IsReading()){ errorToReturn = vThrowError(VE_STREAM_NOT_OPENED); } if(errorToReturn == VE_OK){ if (!outExpandedStream -> IsWriting()) errorToReturn = vThrowError(VE_STREAM_NOT_OPENED); } if(errorToReturn == VE_OK){ // The stream to expand is put in a buffer before calling ExpandMemoryBlock sLONG8 streamToExpandSize = (inCompressedStream -> GetSize()) - (inCompressedStream -> GetPos()) ; Bytef * compressedBuffer = (Bytef *) malloc(streamToExpandSize * sizeof(Bytef)); if(compressedBuffer == NULL){ errorToReturn = vThrowError(VE_MEMORY_FULL); } if(errorToReturn == VE_OK){ errorToReturn = inCompressedStream -> GetData(compressedBuffer, streamToExpandSize); if (errorToReturn != VE_OK){ errorToReturn = vThrowError(VE_STREAM_CANNOT_READ); } if(errorToReturn == VE_OK) errorToReturn = ExpandMemoryBlock(compressedBuffer, streamToExpandSize, outExpandedStream); } } return errorToReturn; }
void VJSGlobalClass::do_JSONToXml(VJSParms_callStaticFunction& ioParms, VJSGlobalObject*) { VString xml; VString json, root; bool simpleJSON = false; ioParms.GetStringParam( 1, json); if ( ioParms.CountParams() >= 2) { VString s; if (ioParms.IsStringParam(2)) { ioParms.GetStringParam(2, s); if(s== "json-bag") { simpleJSON = true; root="bag"; if(ioParms.CountParams() >= 3) { if (ioParms.IsStringParam(3)) ioParms.GetStringParam(3, root); else vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_STRING, "3"); } } } else vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_STRING, "2"); } if (simpleJSON) { XBOX::VValueBag *bag = new XBOX::VValueBag; bag->FromJSONString(json); xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"; bag->DumpXML( xml, root, false); ReleaseRefCountable( &bag); } else { VError err = VXMLJsonUtility::JsonToXML(json, xml); } ioParms.ReturnString(xml); }
void VJSStream::_PutString(VJSParms_callStaticFunction& ioParms, VStream* inStream) { VString s; if (ioParms.IsStringParam(1)) { ioParms.GetStringParam(1, s); VError err = s.WriteToStream(inStream); } else vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_STRING, "1"); }
void VJSStream::_PutReal(VJSParms_callStaticFunction& ioParms, VStream* inStream) { Real r = 0; if (ioParms.IsNumberParam(1)) { ioParms.GetRealParam(1, &r); VError err = inStream->PutReal(r); } else vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_NUMBER, "1"); }
void VJSGlobalClass::do_SaveText(VJSParms_callStaticFunction& ioParms, VJSGlobalObject*) { VString s; if (ioParms.IsStringParam(1)) { if (ioParms.GetStringParam(1, s)) { VFile* file = ioParms.RetainFileParam(2); if (file != nil) { VError err = VE_OK; if (file->Exists()) err = file->Delete(); if (err == VE_OK) err = file->Create(); if (err == VE_OK) { CharSet defaultCharSet = VTC_UTF_8; sLONG xcharset = 0; if (ioParms.GetLongParam(3, &xcharset) && xcharset != 0) defaultCharSet = (CharSet)xcharset; VFileStream inp(file); err = inp.OpenWriting(); if (err == VE_OK) { inp.SetCharSet(defaultCharSet); inp.PutText(s); inp.CloseWriting(); } } } else vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_FILE, "2"); } } else vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_STRING, "1"); }
void VJSGlobalClass::do_Require(VJSParms_callStaticFunction& ioParms, VJSGlobalObject *inGlobalObject) { xbox_assert(inGlobalObject != NULL); XBOX::VString className; if (ioParms.CountParams() != 1 || !ioParms.IsStringParam(1) || !ioParms.GetStringParam(1, className)) vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_STRING, "1"); else ioParms.ReturnValue(inGlobalObject->Require(ioParms.GetContext(), className)); }
VError AttributReg::Register(uLONG id, sLONG attribut) { VError err; CoupleAttributID CCID; err=VE_OK; if (id<10000) { if (((sLONG)id+1)>ar1.GetCount()) { if (ar1.AddNSpaces(id+1-ar1.GetCount(),true)) { ar1[id].ID=id; ar1[id].attribut=attribut; } else err=vThrowError(memfull); } else { ar1[id].ID=id; ar1[id].attribut=attribut; } } else { CCID.ID=id; CCID.attribut=attribut; if (!ar2.Add(CCID)) err=vThrowError(memfull); } if (err != VE_OK) err=vThrowError(VE_DB4D_CANNOTREGISTERCODE); return(err); }
VError CodeReg::Register(uLONG id, void* Code) { VError err; CoupleCodeID CCID; err=VE_OK; if (id<10000) { if (((sLONG)id+1)>ar1.GetCount()) { if (ar1.AddNSpaces((id+1)-ar1.GetCount(),true)) { ar1[id].ID=id; ar1[id].Code=Code; } else err=vThrowError(memfull); } else { ar1[id].ID=id; ar1[id].Code=Code; } } else { CCID.ID=id; CCID.Code=Code; if (!ar2.Add(CCID)) err=vThrowError(memfull); } if (err != VE_OK) err=vThrowError(VE_DB4D_CANNOTREGISTERCODE); return(err); }
void VJSGlobalClass::do_LoadText(VJSParms_callStaticFunction& ioParms, VJSGlobalObject*) { bool okloaded = false; VFile* file = ioParms.RetainFileParam(1); if (file != nil) { if (file->Exists()) { VFileStream inp(file); VError err = inp.OpenReading(); if (err == VE_OK) { CharSet defaultCharSet = VTC_UTF_8; sLONG xcharset = 0; if (ioParms.GetLongParam(2, &xcharset) && xcharset != 0) defaultCharSet = (CharSet)xcharset; inp.GuessCharSetFromLeadingBytes(defaultCharSet ); inp.SetCarriageReturnMode( eCRM_NATIVE ); VString s; err = inp.GetText(s); if (err == VE_OK) { ioParms.ReturnString(s); okloaded = true; } inp.CloseReading(); } } file->Release(); } else vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_FILE, "1"); if (!okloaded) ioParms.ReturnNullValue(); }
void VJSPictureContainer::SetMetaInfo(JS4D::ValueRef inMetaInfo, JS4D::ContextRef inContext) { #if !VERSION_LINUX if (fMetaInfoIsValid) { JS4D::UnprotectValue(fContext, fMetaInfo); } JS4D::ProtectValue(inContext, inMetaInfo); fMetaInfo = inMetaInfo; fContext = inContext; fMetaInfoIsValid = true; #else // Postponed Linux Implementation ! vThrowError(VE_UNIMPLEMENTED); xbox_assert(false); #endif }
VError VJSONArray::GetString( VString& outString) const { VError err = VE_OK; if (fVector.empty()) { outString.Clear(); } else { VectorOfVString array; array.resize( fVector.size()); VectorOfVString::iterator j = array.begin(); for( VectorType::const_iterator i = fVector.begin() ; (i != fVector.end()) && (err == VE_OK) ; ++i, ++j) { err = i->GetString( *j); } err = outString.Join( array, ',') ? VE_OK : vThrowError( VE_STRING_ALLOC_FAILED); } return err; }
VError VJSONBinaryWriter::StreamObject(const VJSONObject *inObject, VMemoryBuffer<>& outBuff) { if (inObject == NULL) // should it happen { sWORD nullobj = -2; outBuff.AddData(&nullobj, 2); return VE_OK; } if (std::find( fStack.begin(), fStack.end(), inObject) != fStack.end()) { return vThrowError( VE_JSON_STRINGIFY_CIRCULAR); } VError err = VE_OK; fStack.push_back( inObject); //if (!inObject->doStream( outBuff, *this, &err)) { for (VJSONPropertyConstOrderedIterator i(inObject); i.IsValid() && (err == VE_OK); ++i) { const VString& name = i.GetName(); sWORD len = (sWORD)name.GetLength(); outBuff.AddData(&len, 2); if (len > 0) { outBuff.AddData(name.GetCPointer(), (sLONG)len * 2); err = StreamValue(i.GetValue(), outBuff); } } sWORD endobj = -1; outBuff.AddData(&endobj, 2); } fStack.pop_back(); return err; }
void VJSGlobalClass::do_SyncEvent(VJSParms_callStaticFunction& ioParms, VJSGlobalObject*) { VString s; bool okresult = false; if (ioParms.IsStringParam(1)) { ioParms.GetStringParam(1, s); if (!s.IsEmpty()) { jsSyncEvent* sync = jsSyncEvent::RetainSyncEvent(s); if (sync != nil) { okresult = true; ioParms.ReturnValue(VJSSyncEvent::CreateInstance(ioParms.GetContextRef(), sync)); sync->Release(); } } } else vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_STRING, "1"); if (!okresult) ioParms.ReturnNullValue(); }
void VJSGlobalClass::do_include( VJSParms_callStaticFunction& inParms, VJSGlobalObject *inGlobalObject) { // EvaluateScript() uses NULL (this is default) as inThisObject argument. // This works fine currently, but would it be better (if any problem) to pass global (application) object instead? // See WAK0074064. VFile* file = inParms.RetainFileParam(1, false); if (file != NULL) { bool newlyRegistered = inGlobalObject->RegisterIncludedFile( file); // sc 15/06/2010 the file must be registered if (inParms.GetBoolParam(2,"refresh","auto") || newlyRegistered) { inParms.GetContext().EvaluateScript( file, NULL, inParms.GetExceptionRefPointer()); } file->Release(); } else { VString pathname; if (inParms.IsStringParam(1) && inParms.GetStringParam( 1, pathname)) { VFolder* folder = inGlobalObject->GetRuntimeDelegate()->RetainScriptsFolder(); if (folder != NULL) { file = new VFile( *folder, pathname, FPS_POSIX); bool newlyRegistered = inGlobalObject->RegisterIncludedFile( file); // sc 15/06/2010 the file must be registered if (inParms.GetBoolParam(2,"refresh","auto") || newlyRegistered) { inParms.GetContext().EvaluateScript( file, NULL, inParms.GetExceptionRefPointer()); } ReleaseRefCountable( &file); } ReleaseRefCountable( &folder); } else vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_FILE, "1"); } }
void VJSGlobalClass::do_GetURLPath(VJSParms_callStaticFunction& ioParms, VJSGlobalObject*) { VString s; if (ioParms.IsStringParam(1)) { if (ioParms.GetStringParam(1, s)) { VFullURL url(s); VJSArray result(ioParms.GetContextRef()); const VString* next = url.NextPart(); while (next != NULL) { VJSValue elem(ioParms.GetContextRef()); elem.SetString(*next); result.PushValue(elem); next = url.NextPart(); } ioParms.ReturnValue(result); } } else vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_STRING, "1"); }
void VJSGlobalClass::do_AtomicSection(VJSParms_callStaticFunction& ioParms, VJSGlobalObject*) { VString s; bool okresult = false; if (ioParms.IsStringParam(1)) { ioParms.GetStringParam(1, s); if (!s.IsEmpty()) { jsAtomicSection* atomsec = jsAtomicSection::RetainAtomicSection(s); if (atomsec != nil) { okresult = true; ioParms.ReturnValue(VJSAtomicSection::CreateInstance(ioParms.GetContextRef(), atomsec)); atomsec->Release(); } } } else vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_STRING, "1"); if (!okresult) ioParms.ReturnNullValue(); }
VError VValueBag::AddElement(const IBaggable* inObject) { VError err = VE_OK; if (inObject != NULL) { VValueBag* bag = new VValueBag; if (bag != NULL) { VStr31 kind; err = inObject->SaveToBag(*bag, kind); if (err == VE_OK) AddElement(kind, bag); bag->Release(); } else { err = vThrowError(VE_MEMORY_FULL); } } return err; }
void VJSGlobalClass::do_loadImage(VJSParms_callStaticFunction& ioParms, VJSGlobalObject*) { bool okloaded = false; #if !VERSION_LINUX // Postponed Linux Implementation ! VFile* file = ioParms.RetainFileParam(1); if (file != nil) { if (file->Exists()) { XBOX::VPicture* pict = new XBOX::VPicture(*file, false); /* VJSPictureContainer* pictContains = new VJSPictureContainer(pict, true, ioParms.GetContextRef()); ioParms.ReturnValue(VJSImage::CreateInstance(ioParms.GetContextRef(), pictContains)); pictContains->Release(); */ if (pict != NULL) { okloaded = true; ioParms.ReturnVValue(*pict); delete pict; } } file->Release(); } else vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_FILE, "1"); #endif if (!okloaded) ioParms.ReturnNullValue(); }
void VJSGlobalClass::do_GetURLQuery(VJSParms_callStaticFunction& ioParms, VJSGlobalObject*) { VString s; if (ioParms.IsStringParam(1) && ioParms.GetStringParam(1, s)) { VFullURL url(s); VJSObject result(ioParms.GetContextRef()); result.MakeEmpty(); const VValueBag& values = url.GetValues(); VIndex nbvalues = values.GetAttributesCount(); for (VIndex i = 1; i <= nbvalues; i++) { VString attName; const VValueSingle* cv = values.GetNthAttribute(i, &attName); if (cv != nil) { result.SetProperty(attName, cv); } } ioParms.ReturnValue(result); } else vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_STRING, "1"); }
VError VJSONWriter::StringifyObject( const VJSONObject *inObject, VString& outString) { if (inObject == NULL) { outString = VJSONValue::sUndefinedString; return VE_OK; } if (std::find( fStack.begin(), fStack.end(), inObject) != fStack.end()) { return vThrowError( VE_JSON_STRINGIFY_CIRCULAR); } VError err = VE_OK; fStack.push_back( inObject); if (!inObject->DoStringify( outString, *this, &err)) { if (inObject->fMap.empty()) { outString = "{}"; } else { IncrementLevel(); VectorOfVString array; array.resize( inObject->fMap.size()); VectorOfVString::iterator j = array.begin(); for( VJSONPropertyConstIterator i( inObject) ; i.IsValid() && (err == VE_OK) ; ++i, ++j) { err = i.GetName().GetJSONString( *j, GetOptions()); if (err == VE_OK) { InsertIndentString( *j); VString value; err = StringifyValue( i.GetValue(), value); if (err == VE_OK) { j->AppendUniChar( ':'); j->AppendString( value); } } } DecrementLevel(); if (err == VE_OK) { array.front().Insert( '{', 1); AppendIndentString( array.back()); array.back().AppendUniChar( '}'); err = outString.Join( array, ',') ? VE_OK : vThrowError( VE_STRING_ALLOC_FAILED); } } } fStack.pop_back(); return err; }