本文整理汇总了C++中ESV函数的典型用法代码示例。如果您正苦于以下问题:C++ ESV函数的具体用法?C++ ESV怎么用?C++ ESV使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ESV函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: lastIndexOf
/*
Search for an item using strict equality "===". This call searches from
the end of the array for the specified element.
@return Returns the items index into the array if found, otherwise -1.
function lastIndexOf(element: Object, fromIndex: Number = 0): Number
*/
static EjsNumber *lastArrayIndexOf(Ejs *ejs, EjsArray *ap, int argc, EjsObj **argv)
{
EjsObj *element;
int i, start;
assert(argc == 1 || argc == 2);
element = argv[0];
start = ((argc == 2) ? (int) ((EjsNumber*) argv[1])->value : ap->length - 1);
if (start < 0) {
start += ap->length;
}
if (start >= ap->length) {
start = ap->length - 1;
}
if (start < 0) {
return ESV(minusOne);
}
for (i = start; i >= 0; i--) {
if (compareArrayElement(ejs, ap->data[i], element)) {
return ejsCreateNumber(ejs, i);
}
}
return ESV(minusOne);
}
示例2: length
/*
Set the length. TODO - what does this do?
public override function set length(value: int): void
*/
static EjsObj *setLength(Ejs *ejs, EjsXML *xml, int argc, EjsObj **argv)
{
int length;
assert(ejsIsXML(ejs, xml));
if (argc != 1) {
ejsThrowArgError(ejs, "usage: obj.length = value");
return 0;
}
length = ejsVarToInteger(ejs, argv[0]);
if (length < ap->length) {
for (i = length; i < ap->length; i++) {
if (ejsSetProperty(ejs, ap, i, ESV(undefined)) < 0) {
// TODO - DIAG
return 0;
}
}
} else if (length > ap->length) {
if (ejsSetProperty(ejs, ap, length - 1, ESV(undefined)) < 0) {
// TODO - DIAG
return 0;
}
}
ap->length = length;
return 0;
}
示例3: switch
static EjsAny *invokeNamespaceOperator(Ejs *ejs, EjsNamespace *lhs, int opCode, EjsNamespace *rhs)
{
bool boolResult;
switch (opCode) {
case EJS_OP_COMPARE_EQ:
if (!ejsIsDefined(ejs, rhs)) {
return ((opCode == EJS_OP_COMPARE_EQ) ? ESV(false): ESV(true));
}
boolResult = ejsCompareString(ejs, lhs->value, rhs->value) == 0;
break;
case EJS_OP_COMPARE_STRICTLY_EQ:
boolResult = lhs == rhs;
break;
case EJS_OP_COMPARE_NE:
if (!ejsIsDefined(ejs, rhs)) {
return ((opCode == EJS_OP_COMPARE_EQ) ? ESV(false): ESV(true));
}
boolResult = !(ejsCompareString(ejs, lhs->value, rhs->value) == 0);
break;
case EJS_OP_COMPARE_STRICTLY_NE:
boolResult = !(lhs == rhs);
break;
default:
ejsThrowTypeError(ejs, "Operation is not valid on this type");
return 0;
}
return ejsCreateBoolean(ejs, boolResult);
}
示例4: waitForMessage
/*
function waitForMessage(timeout: Number = -1): Boolean
*/
static EjsBoolean *workerWaitForMessage(Ejs *ejs, EjsWorker *worker, int argc, EjsObj **argv)
{
MprTicks mark, remaining;
int timeout;
timeout = (argc > 0) ? ejsGetInt(ejs, argv[0]): MAXINT;
if (timeout < 0) {
timeout = MAXINT;
}
mark = mprGetTicks();
remaining = timeout;
worker->gotMessage = 0;
do {
mprWaitForEvent(ejs->dispatcher, (int) remaining);
remaining = mprGetRemainingTicks(mark, timeout);
} while (!worker->gotMessage && remaining > 0 && !ejs->exception);
if (worker->gotMessage) {
worker->gotMessage = 0;
return ESV(true);
} else {
return ESV(true);
}
}
示例5: send
/*
function send(...content): Number
*/
static EjsNumber *ws_send(Ejs *ejs, EjsWebSocket *ws, int argc, EjsObj **argv)
{
EjsArray *args;
EjsByteArray *ba;
EjsAny *arg;
ssize nbytes;
int i;
args = (EjsArray*) argv[0];
if (ws->conn->state < HTTP_STATE_PARSED && !waitForHttpState(ws, HTTP_STATE_PARSED, -1, 1)) {
return ESV(null);
}
nbytes = 0;
for (i = 0; i < args->length; i++) {
if ((arg = ejsGetProperty(ejs, args, i)) != 0) {
if (ejsIs(ejs, arg, ByteArray)) {
ba = (EjsByteArray*) arg;
nbytes = ejsGetByteArrayAvailableData(ba);
nbytes = httpSendBlock(ws->conn, WS_MSG_BINARY, (cchar*) &ba->value[ba->readPosition], nbytes, HTTP_BLOCK);
} else {
nbytes = httpSend(ws->conn, ejsToMulti(ejs, arg));
}
if (nbytes < 0) {
return ESV(null);
}
}
}
return ejsCreateNumber(ejs, (MprNumber) nbytes);
}
示例6: verifyIssuer
/*
function get verifyIssuer(): Boolean
*/
static EjsBoolean *http_verifyIssuer(Ejs *ejs, EjsHttp *hp, int argc, EjsObj **argv)
{
if (!hp->ssl) {
hp->ssl = mprCreateSsl(0);
}
return hp->ssl->verifyIssuer ? ESV(true) : ESV(false);
}
示例7: run
/*
static function run(timeout: Number = -1, oneEvent: Boolean = false): Boolean
*/
static EjsObj *app_run(Ejs *ejs, EjsObj *unused, int argc, EjsObj **argv)
{
MprTicks mark, remaining;
int64 dispatcherMark;
int rc, oneEvent, timeout;
timeout = (argc > 0) ? ejsGetInt(ejs, argv[0]) : MAXINT;
oneEvent = (argc > 1) ? ejsGetInt(ejs, argv[1]) : 0;
if (ejs->hosted) {
return ESV(true);
}
if (timeout < 0) {
timeout = MAXINT;
}
mark = mprGetTicks();
remaining = timeout;
dispatcherMark = mprGetEventMark(ejs->dispatcher);
do {
rc = mprWaitForEvent(ejs->dispatcher, remaining, dispatcherMark);
remaining = mprGetRemainingTicks(mark, timeout);
dispatcherMark = mprGetEventMark(ejs->dispatcher);
} while (!ejs->exception && !oneEvent && !ejs->exiting && remaining > 0 && !mprIsStopping());
return (rc == 0) ? ESV(true) : ESV(false);
}
示例8: WebSocket
/*
function WebSocket(uri: Uri, protocols = null, options)
options = {
certificate: Path,
verify: Boolean,
}
*/
static EjsWebSocket *wsConstructor(Ejs *ejs, EjsWebSocket *ws, int argc, EjsObj **argv)
{
EjsAny *certificate;
bool verify;
assert(ejsIsPot(ejs, ws));
ejsLoadHttpService(ejs);
ws->ejs = ejs;
verify = 0;
ws->uri = httpUriToString(((EjsUri*) argv[0])->uri, 0);
if (argc >= 2) {
if (ejsIs(ejs, argv[1], Array)) {
ws->protocols = sclone((ejsToString(ejs, argv[1]))->value);
} else if (ejsIs(ejs, argv[1], String)) {
ws->protocols = sclone(((EjsString*) argv[1])->value);
} else {
ws->protocols = sclone("chat");
}
} else {
ws->protocols = sclone("chat");
}
if (*ws->protocols == '\0') {
ejsThrowArgError(ejs, "Bad protocol");
return 0;
}
if (argc >= 3) {
ws->frames = ejsGetPropertyByName(ejs, argv[2], EN("frames")) == ESV(true);
verify = ejsGetPropertyByName(ejs, argv[2], EN("verify")) == ESV(true);
if ((certificate = ejsGetPropertyByName(ejs, argv[2], EN("certificate"))) != 0) {
ws->certFile = ejsToMulti(ejs, argv[0]);
}
}
if ((ws->conn = httpCreateConn(MPR->httpService, NULL, ejs->dispatcher)) == 0) {
ejsThrowMemoryError(ejs);
return 0;
}
httpSetAsync(ws->conn, 1);
httpPrepClientConn(ws->conn, 0);
httpSetConnNotifier(ws->conn, webSocketNotify);
httpSetWebSocketProtocols(ws->conn, ws->protocols);
httpSetConnContext(ws->conn, ws);
if (sstarts(ws->uri, "wss")) {
ws->ssl = mprCreateSsl(0);
mprVerifySslIssuer(ws->ssl, verify);
mprVerifySslPeer(ws->ssl, verify);
#if FUTURE
if (!hp->caFile) {
//MOB - Some define for this.
hp->caFile = mprJoinPath(mprGetAppDir(), "http-ca.crt");
}
mprSetSslCaFile(hp->ssl, hp->caFile);
mprSetSslCaFile(hp->ssl, mprJoinPath(mprGetAppDir(), "http-ca.crt"));
#endif
}
startWebSocketRequest(ejs, ws);
return ws;
}
示例9: join
/*
static function join(workers: Object = null, timeout: Number = -1): Boolean
*/
static EjsObj *workerJoin(Ejs *ejs, EjsWorker *unused, int argc, EjsObj **argv)
{
EjsObj *workers;
int timeout;
workers = (argc > 0) ? argv[0] : NULL;
timeout = (argc == 2) ? ejsGetInt(ejs, argv[1]) : MAXINT;
return (join(ejs, workers, timeout) == 0) ? ESV(true): ESV(false);
}
示例10: return
/*
Cast the object operand to a primitive type
*/
static EjsObj *xlCast(Ejs *ejs, EjsXML *vp, EjsType *type)
{
MprBuf *buf;
EjsObj *result;
EjsXML *elt, *item;
int next;
if (type == ESV(XML)) {
return (EjsObj*) vp;
}
switch (type->sid) {
case S_Object:
case S_Boolean:
return (EjsObj*) ejsCreateBoolean(ejs, 1);
case S_Number:
result = xlCast(ejs, vp, ESV(String));
result = (EjsObj*) ejsToNumber(ejs, result);
return result;
case S_String:
buf = mprCreateBuf(MPR_BUFSIZE, -1);
if (mprGetListLength(vp->elements) == 1) {
elt = mprGetFirstItem(vp->elements);
if (elt->kind == EJS_XML_ELEMENT) {
if (elt->elements == 0) {
return (EjsObj*) ESV(empty);
}
if (elt->elements && mprGetListLength(elt->elements) == 1) {
// TODO - what about PI and comments?
item = mprGetFirstItem(elt->elements);
if (item->kind == EJS_XML_TEXT) {
return (EjsObj*) item->value;
}
}
}
}
for (next = 0; (elt = mprGetNextItem(vp->elements, &next)) != 0; ) {
if (ejsXMLToBuf(ejs, buf, elt, -1) < 0) {
return 0;
}
if (next < vp->elements->length) {
mprPutStringToBuf(buf, " ");
}
}
return (EjsObj*) ejsCreateStringFromAsc(ejs, (char*) buf->start);
default:
ejsThrowTypeError(ejs, "Cannot cast to this type");
return 0;
}
}
示例11: wait
/*
Wait for a request to complete. Timeout is in msec. Timeout < 0 means use default inactivity and request timeouts.
Timeout of zero means no timeout.
function wait(timeout: Number = -1): Boolean
*/
static EjsBoolean *http_wait(Ejs *ejs, EjsHttp *hp, int argc, EjsObj **argv)
{
MprTicks timeout;
timeout = (argc >= 1) ? ejsGetInt(ejs, argv[0]) : -1;
if (timeout == 0) {
timeout = MPR_MAX_TIMEOUT;
}
if (!waitForState(hp, HTTP_STATE_FINALIZED, timeout, 0)) {
return ESV(false);
}
return ESV(true);
}
示例12: response
/*
function get response(): String
*/
static EjsString *http_response(Ejs *ejs, EjsHttp *hp, int argc, EjsObj **argv)
{
EjsAny *response;
if (hp->responseCache) {
return hp->responseCache;
}
if ((response = http_readString(ejs, hp, argc, argv)) == ESV(null)) {
return ESV(empty);
}
hp->responseCache = (EjsString*) response;
return hp->responseCache;
}
示例13: sendBlock
/*
function sendBlock(content, options): Number
*/
static EjsNumber *ws_sendBlock(Ejs *ejs, EjsWebSocket *ws, int argc, EjsObj **argv)
{
EjsByteArray *ba;
EjsAny *content, *vp;
ssize nbytes;
cchar *str;
int last, mode, type, flags;
assert(argc == 2);
if (ws->conn->state < HTTP_STATE_PARSED && !waitForHttpState(ws, HTTP_STATE_PARSED, -1, 1)) {
return ESV(null);
}
content = argv[0];
last = ejsGetPropertyByName(ejs, argv[1], EN("last")) != ESV(false);
if ((vp = ejsGetPropertyByName(ejs, argv[1], EN("mode"))) != 0) {
mode = (int) ejsGetNumber(ejs, vp);
if (mode != HTTP_BUFFER && mode != HTTP_BLOCK && mode != HTTP_NON_BLOCK) {
ejsThrowArgError(ejs, "Bad message mode");
return 0;
}
} else {
mode = HTTP_BUFFER;
}
if ((vp = ejsGetPropertyByName(ejs, argv[1], EN("type"))) != 0) {
type = (int) ejsGetNumber(ejs, vp);
if (type != WS_MSG_CONT && type != WS_MSG_TEXT && type != WS_MSG_BINARY) {
ejsThrowArgError(ejs, "Bad message type");
return 0;
}
} else {
type = WS_MSG_TEXT;
}
flags = mode;
if (!last) {
flags |= HTTP_MORE;
}
if (ejsIs(ejs, content, ByteArray)) {
ba = (EjsByteArray*) content;
nbytes = ejsGetByteArrayAvailableData(ba);
nbytes = httpSendBlock(ws->conn, type, (cchar*) &ba->value[ba->readPosition], nbytes, flags);
} else {
str = ejsToMulti(ejs, content);
nbytes = httpSendBlock(ws->conn, type, str, slen(str), flags);
}
if (nbytes < 0) {
ejsThrowIOError(ejs, "Cannot send block");
return 0;
}
return ejsCreateNumber(ejs, (MprNumber) nbytes);
}
示例14: switch
static EjsAny *invokeNullOperator(Ejs *ejs, EjsObj *lhs, int opcode, EjsObj *rhs)
{
EjsObj *result;
if (rhs == 0 || TYPE(lhs) != TYPE(rhs)) {
if ((result = coerceNullOperands(ejs, lhs, opcode, rhs)) != 0) {
return result;
}
}
/*
Types now match. Both left and right types are both "null"
*/
switch (opcode) {
/*
NOTE: strict eq is the same as eq
*/
case EJS_OP_COMPARE_EQ: case EJS_OP_COMPARE_STRICTLY_EQ:
case EJS_OP_COMPARE_LE: case EJS_OP_COMPARE_GE:
case EJS_OP_COMPARE_UNDEFINED:
case EJS_OP_COMPARE_NOT_ZERO:
case EJS_OP_COMPARE_NULL:
return ESV(true);
case EJS_OP_COMPARE_NE: case EJS_OP_COMPARE_STRICTLY_NE:
case EJS_OP_COMPARE_LT: case EJS_OP_COMPARE_GT:
case EJS_OP_COMPARE_FALSE:
case EJS_OP_COMPARE_TRUE:
case EJS_OP_COMPARE_ZERO:
return ESV(false);
/*
Unary operators
*/
case EJS_OP_LOGICAL_NOT: case EJS_OP_NOT: case EJS_OP_NEG:
return ESV(one);
/*
Binary operators. Reinvoke with left = zero
*/
case EJS_OP_ADD: case EJS_OP_AND: case EJS_OP_DIV: case EJS_OP_MUL: case EJS_OP_OR: case EJS_OP_REM:
case EJS_OP_SHL: case EJS_OP_SHR: case EJS_OP_SUB: case EJS_OP_USHR: case EJS_OP_XOR:
return ejsInvokeOperator(ejs, ESV(zero), opcode, rhs);
default:
ejsThrowTypeError(ejs, "Opcode %d not implemented for type %@", opcode, TYPE(lhs)->qname.name);
return 0;
}
}
示例15: assert
static EjsBoolean *regex_test(Ejs *ejs, EjsRegExp *rp, int argc, EjsObj **argv)
{
EjsString *str;
int count;
str = (EjsString*) argv[0];
assert(rp->compiled);
count = pcre_exec(rp->compiled, NULL, str->value, (int) str->length, rp->endLastMatch, 0, 0, 0);
if (count < 0) {
rp->endLastMatch = 0;
return ESV(false);
}
return ESV(true);
}