JSValueRef JSCExecutor::nativeTerminateWorker( JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) { if (argumentCount != 1) { *exception = createErrorString(ctx, "Got wrong number of args"); return JSValueMakeUndefined(ctx); } double workerDouble = JSValueToNumber(ctx, arguments[0], exception); if (workerDouble != workerDouble) { *exception = createErrorString(ctx, "Got invalid worker id"); return JSValueMakeUndefined(ctx); } JSCExecutor *executor; try { executor = s_globalContextRefToJSCExecutor.at(JSContextGetGlobalContext(ctx)); } catch (std::out_of_range& e) { *exception = createErrorString(ctx, "Global JS context didn't map to a valid executor"); return JSValueMakeUndefined(ctx); } executor->terminateOwnedWebWorker((int) workerDouble); return JSValueMakeUndefined(ctx); }
JSValueRef JSCExecutor::nativeFlushQueueImmediate( JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) { if (argumentCount != 1) { *exception = createErrorString(ctx, "Got wrong number of args"); return JSValueMakeUndefined(ctx); } JSCExecutor *executor; try { executor = s_globalContextRefToJSCExecutor.at(JSContextGetGlobalContext(ctx)); } catch (std::out_of_range& e) { *exception = createErrorString(ctx, "Global JS context didn't map to a valid executor"); return JSValueMakeUndefined(ctx); } std::string resStr = Value(ctx, arguments[0]).toJSONString(); executor->flushQueueImmediate(resStr); return JSValueMakeUndefined(ctx); }
JSValueRef JSCExecutor::nativeStartWorker( JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) { if (argumentCount != 3) { *exception = createErrorString(ctx, "Got wrong number of args"); return JSValueMakeUndefined(ctx); } std::string scriptFile = Value(ctx, arguments[0]).toString().str(); JSValueRef worker = arguments[1]; JSValueRef globalObj = arguments[2]; JSCExecutor *executor; try { executor = s_globalContextRefToJSCExecutor.at(JSContextGetGlobalContext(ctx)); } catch (std::out_of_range& e) { *exception = createErrorString(ctx, "Global JS context didn't map to a valid executor"); return JSValueMakeUndefined(ctx); } int workerId = executor->addWebWorker(scriptFile, worker, globalObj); return JSValueMakeNumber(ctx, workerId); }
GLECSVDataStatus GLECSVData::readCellString(GLEBYTE quote) { unsigned int cellSize = 1; unsigned int cellPos = lastCharPos(); initWritePos(); while (true) { GLEBYTE ch = readChar(); writeChar(ch); cellSize++; if (ch == 0) { m_error.errorCode = GLECSVErrorUnterminatedString; m_error.errorLine = m_lines; m_error.errorColumn = getUTF8Column(cellPos); createErrorString("unterminated string"); return GLECSVDataStatusEOF; } else if (isEol(ch)) { m_error.errorCode = GLECSVErrorUnterminatedString; m_error.errorLine = m_lines; m_error.errorColumn = getUTF8Column(cellPos); createErrorString("unterminated string"); return readNewline(ch); } else if (ch == quote) { GLEBYTE ch = readChar(); if (ch != quote) { writeChar(ch); createCell(cellSize, cellPos); return skipSpacesAndFirstDelim(ch); } } } return GLECSVDataStatusOK; }
/** * Parses the given input stream and returns a DOM Document. * A NULL pointer will be returned if errors occurred */ nsresult txDriver::parse(istream& aInputStream, const nsAString& aUri) { mErrorString.Truncate(); if (!aInputStream) { mErrorString.AppendLiteral("unable to parse xml: invalid or unopen stream encountered."); return NS_ERROR_FAILURE; } static const XML_Memory_Handling_Suite memsuite = { (void *(*)(size_t))PR_Malloc, (void *(*)(void *, size_t))PR_Realloc, PR_Free }; static const PRUnichar expatSeparator = kExpatSeparatorChar; mExpatParser = XML_ParserCreate_MM(nsnull, &memsuite, &expatSeparator); if (!mExpatParser) { return NS_ERROR_OUT_OF_MEMORY; } XML_SetReturnNSTriplet(mExpatParser, XML_TRUE); XML_SetUserData(mExpatParser, this); XML_SetElementHandler(mExpatParser, startElement, endElement); XML_SetCharacterDataHandler(mExpatParser, charData); #ifdef XML_DTD XML_SetParamEntityParsing(mExpatParser, XML_PARAM_ENTITY_PARSING_ALWAYS); #endif XML_SetExternalEntityRefHandler(mExpatParser, externalEntityRefHandler); XML_SetExternalEntityRefHandlerArg(mExpatParser, this); XML_SetBase(mExpatParser, (const XML_Char*)(PromiseFlatString(aUri).get())); const int bufferSize = 1024; char buf[bufferSize]; PRBool done; int success; mRV = NS_OK; do { aInputStream.read(buf, bufferSize); done = aInputStream.eof(); success = XML_Parse(mExpatParser, buf, aInputStream.gcount(), done); // mRV is set in onDoneCompiling in case of an error if (!success || NS_FAILED(mRV)) { createErrorString(); done = MB_TRUE; } } while (!done); aInputStream.clear(); // clean up XML_ParserFree(mExpatParser); mCompiler->doneLoading(); if (!success) { return NS_ERROR_FAILURE; } return mRV; }
JSValueRef JSCExecutor::nativeCallSyncHook( JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) { if (argumentCount != 3) { *exception = createErrorString(ctx, "Got wrong number of args for callSyncHook"); return JSValueMakeUndefined(ctx); } unsigned int moduleId = Value(ctx, arguments[0]).asUnsignedInteger(); unsigned int methodId = Value(ctx, arguments[1]).asUnsignedInteger(); std::string argsJson = Value(ctx, arguments[2]).toJSONString(); JSCExecutor *executor; try { executor = s_globalContextRefToJSCExecutor.at(JSContextGetGlobalContext(ctx)); } catch (std::out_of_range& e) { *exception = createErrorString(ctx, "Global JS context didn't map to a valid executor"); return JSValueMakeUndefined(ctx); } try { MethodCallResult result = executor->m_bridge->callSerializableNativeHook( moduleId, methodId, argsJson); if (result.isUndefined) { return JSValueMakeUndefined(ctx); } return Value::fromJSON(ctx, String(folly::toJson(result.result).c_str())); } catch (...) { *exception = translatePendingCppExceptionToJSError(ctx, "nativeCallSyncHook"); return JSValueMakeUndefined(ctx); } }
int txXMLParser::ExternalEntityRef(const XML_Char *aContext, const XML_Char *aBase, const XML_Char *aSystemId, const XML_Char *aPublicId) { if (aPublicId) { // not supported, this is "http://some.site.net/foo.dtd" stuff return XML_ERROR_EXTERNAL_ENTITY_HANDLING; } nsAutoString absUrl; URIUtils::resolveHref(nsDependentString((PRUnichar*)aSystemId), nsDependentString((PRUnichar*)aBase), absUrl); istream* extInput = URIUtils::getInputStream(absUrl, mErrorString); if (!extInput) { return XML_ERROR_EXTERNAL_ENTITY_HANDLING; } XML_Parser parent = mExpatParser; mExpatParser = XML_ExternalEntityParserCreate(mExpatParser, aContext, nsnull); if (!mExpatParser) { mExpatParser = parent; delete extInput; return XML_ERROR_EXTERNAL_ENTITY_HANDLING; } XML_SetBase(mExpatParser, absUrl.get()); const int bufSize = 1024; char buffer[bufSize]; int result; PRBool done; do { extInput->read(buffer, bufSize); done = extInput->eof(); if (!(result = XML_Parse(mExpatParser, buffer, extInput->gcount(), done))) { createErrorString(); mErrorString.Append(PRUnichar('\n')); done = MB_TRUE; } } while (!done); delete extInput; XML_ParserFree(mExpatParser); mExpatParser = parent; return result; }
unsigned int GLECSVData::validateIdenticalNumberOfColumns() { bool found = false; unsigned int dataColumns = 0; for (unsigned int row = 0; row < getNbLines(); ++row) { if (!found) { found = true; dataColumns = getNbColumns(row); } else { if (m_error.errorCode == GLECSVErrorNone && getNbColumns(row) != dataColumns) { m_error.errorCode = GLECSVErrorInconsistentNrColumns; m_error.errorLine = row; m_error.errorColumn = 0; ostringstream err; err << "inconsistent number of columns " << getNbColumns(row) << " <> " << dataColumns; createErrorString(err.str()); return dataColumns; } } } return dataColumns; }
/** * Parses the given input stream and returns a DOM Document. * A NULL pointer will be returned if errors occurred */ nsresult txXMLParser::parse(istream& aInputStream, const nsAString& aUri, txXPathNode** aResultDoc) { mErrorString.Truncate(); *aResultDoc = nsnull; if (!aInputStream) { mErrorString.AppendLiteral("unable to parse xml: invalid or unopen stream encountered."); return NS_ERROR_FAILURE; } static const XML_Memory_Handling_Suite memsuite = { (void *(*)(size_t))PR_Malloc, (void *(*)(void *, size_t))PR_Realloc, PR_Free }; static const PRUnichar expatSeparator = kExpatSeparatorChar; mExpatParser = XML_ParserCreate_MM(nsnull, &memsuite, &expatSeparator); if (!mExpatParser) { return NS_ERROR_OUT_OF_MEMORY; } mDocument = new Document(); if (!mDocument) { XML_ParserFree(mExpatParser); return NS_ERROR_OUT_OF_MEMORY; } mDocument->documentBaseURI = aUri; mCurrentNode = mDocument; XML_SetReturnNSTriplet(mExpatParser, XML_TRUE); XML_SetUserData(mExpatParser, this); XML_SetElementHandler(mExpatParser, startElement, endElement); XML_SetCharacterDataHandler(mExpatParser, charData); XML_SetProcessingInstructionHandler(mExpatParser, piHandler); XML_SetCommentHandler(mExpatParser, commentHandler); #ifdef XML_DTD XML_SetParamEntityParsing(mExpatParser, XML_PARAM_ENTITY_PARSING_ALWAYS); #endif XML_SetExternalEntityRefHandler(mExpatParser, externalEntityRefHandler); XML_SetExternalEntityRefHandlerArg(mExpatParser, this); XML_SetBase(mExpatParser, (const XML_Char*)(PromiseFlatString(aUri).get())); const int bufferSize = 1024; char buf[bufferSize]; PRBool done; do { aInputStream.read(buf, bufferSize); done = aInputStream.eof(); if (!XML_Parse(mExpatParser, buf, aInputStream.gcount(), done)) { createErrorString(); done = MB_TRUE; delete mDocument; mDocument = nsnull; } } while (!done); aInputStream.clear(); // clean up XML_ParserFree(mExpatParser); // ownership to the caller *aResultDoc = txXPathNativeNode::createXPathNode(mDocument); mDocument = nsnull; return *aResultDoc ? NS_OK : NS_ERROR_OUT_OF_MEMORY; }