summaryrefslogtreecommitdiffstats
path: root/js/src/shell/jsshell.cpp
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /js/src/shell/jsshell.cpp
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/shell/jsshell.cpp')
-rw-r--r--js/src/shell/jsshell.cpp74
1 files changed, 74 insertions, 0 deletions
diff --git a/js/src/shell/jsshell.cpp b/js/src/shell/jsshell.cpp
new file mode 100644
index 000000000..7f8e53b9a
--- /dev/null
+++ b/js/src/shell/jsshell.cpp
@@ -0,0 +1,74 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ * vim: set ts=8 sts=4 et sw=4 tw=99:
+ * 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/. */
+
+// jsshell.cpp - Utilities for the JS shell
+
+#include "shell/jsshell.h"
+
+#include "jsapi.h"
+#include "jsfriendapi.h"
+
+#include "vm/StringBuffer.h"
+
+using namespace JS;
+
+namespace js {
+namespace shell {
+
+bool
+GenerateInterfaceHelp(JSContext* cx, HandleObject obj, const char* name)
+{
+ AutoIdVector idv(cx);
+ if (!GetPropertyKeys(cx, obj, JSITER_OWNONLY | JSITER_HIDDEN, &idv))
+ return false;
+
+ StringBuffer buf(cx);
+ if (!buf.append(' '))
+ return false;
+
+ for (size_t i = 0; i < idv.length(); i++) {
+ RootedValue v(cx);
+ RootedId id(cx, idv[i]);
+ if (!JS_GetPropertyById(cx, obj, id, &v))
+ return false;
+ if (!v.isObject())
+ continue;
+ bool hasHelp = false;
+ RootedObject prop(cx, &v.toObject());
+ if (!JS_GetProperty(cx, prop, "usage", &v))
+ return false;
+ if (v.isString())
+ hasHelp = true;
+ if (!JS_GetProperty(cx, prop, "help", &v))
+ return false;
+ if (v.isString())
+ hasHelp = true;
+ if (hasHelp) {
+ if (!buf.append(' ') ||
+ !buf.append(name, strlen(name)) ||
+ !buf.append('.') ||
+ !buf.append(JSID_TO_FLAT_STRING(id)))
+ {
+ return false;
+ }
+ }
+ }
+
+ RootedString s(cx, buf.finishString());
+ if (!s || !JS_DefineProperty(cx, obj, "help", s, 0))
+ return false;
+
+ if (!buf.append(name, strlen(name)) || !buf.append(" - interface object", 20))
+ return false;
+ s = buf.finishString();
+ if (!s || !JS_DefineProperty(cx, obj, "usage", s, 0))
+ return false;
+
+ return true;
+}
+
+} // namespace shell
+} // namespace js