/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- * vim: set ts=8 sts=2 et sw=2 tw=80: * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Generate 'usage' and 'help' properties for the given object. // JS_DefineFunctionsWithHelp will define individual function objects with both // of those properties (eg getpid.usage = "getpid()" and getpid.help = "return // the process id"). This function will generate strings for an "interface // object", eg os.file, which contains some number of functions. // // .usage will be set to "<name> - interface object". // // .help will be set to a newline-separated list of functions that have either // 'help' or 'usage' properties. Functions are described with their usage // strings, if they have them, else with just their names. // bool GenerateInterfaceHelp(JSContext* cx, HandleObject obj, constchar* name) {
RootedIdVector idv(cx); if (!GetPropertyKeys(cx, obj, JSITER_OWNONLY | JSITER_HIDDEN, &idv)) { returnfalse;
}
JSStringBuilder buf(cx); int numEntries = 0; for (size_t i = 0; i < idv.length(); i++) {
RootedId id(cx, idv[i]);
RootedValue v(cx); if (!JS_GetPropertyById(cx, obj, id, &v)) { returnfalse;
} if (!v.isObject()) { continue;
}
RootedObject prop(cx, &v.toObject());
RootedValue usage(cx);
RootedValue help(cx); if (!JS_GetProperty(cx, prop, "usage", &usage)) { returnfalse;
} if (!JS_GetProperty(cx, prop, "help", &help)) { returnfalse;
} if (!usage.isString() && !help.isString()) { continue;
}
if (numEntries && !buf.append("\n")) { returnfalse;
}
numEntries++;
if (!buf.append(" ")) { returnfalse;
}
if (!buf.append(usage.isString() ? usage.toString() : id.toString())) { returnfalse;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.