Skip to content

Instantly share code, notes, and snippets.

@praeclarum
Created October 26, 2011 23:27
Show Gist options
  • Save praeclarum/1318327 to your computer and use it in GitHub Desktop.
Save praeclarum/1318327 to your computer and use it in GitHub Desktop.
Parses V8 source code to look for JavaScript globals
console.log("<!DOCTYPE html>");
console.log("<html>");
console.log("<head>");
console.log("<title>JavaScript Reference</title>");
console.log("</head>");
console.log("<body>");
var fs = require("fs");
var FILES = ["apinatives.js",
"array.js",
"d8.js",
"date.js",
"debug-debugger.js",
"json.js",
"liveedit-debugger.js",
"math.js",
"messages.js",
"mirror-debugger.js",
"proxy.js",
"regexp.js",
"runtime.js",
"string.js",
"uri.js",
"v8natives.js",
"weakmap.js"];
function get() {
var srcdir = "C:\\Projects\\Junk\\v8\\src";
var files = FILES
.map(function (f) { return { name: f, code: fs.readFileSync(srcdir + "\\" + f, "utf-8") }; })
var objectMembers = {};
var funParams = {};
files.forEach(function (file) {
var lines = file.code.split(/\n/);
var activeObject;
var activeObjectIsClass;
lines.forEach(function (line) {
var m;
if (m = line.match(/^\s*Install.*?\(([^,]+?),/)) {
activeObject = m[1].match(/^\$/) ? m[1].replace("$", "") : "global";
activeObjectIsClass = m[1].match(/\.prototype/) ? false : true;
if (!activeObjectIsClass) {
activeObject = activeObject.replace(".prototype", "");
}
if (!(activeObject in objectMembers)) {
objectMembers[activeObject] = [];
}
}
else if (activeObject && (m = line.match(/^\s*"([^"]+)",\s*([A-Z][a-zA-Z0-9]+)/))) {
var member = {
name: m[1],
params: funParams[m[2]],
static: activeObjectIsClass,
};
objectMembers[activeObject].push(member);
}
else if (activeObject && (m = line.match(/^\s*"([^"]+)",\s*getFunction.*?\(.*?,\s*([A-Z][a-zA-Z0-9]+)/))) {
var member = {
name: m[1],
params: funParams[m[2]],
static: activeObjectIsClass,
};
objectMembers[activeObject].push(member);
}
else if (m = line.match(/^\s*function\s*([A-Z][a-zA-Z0-9]+)\(([^\)]*)\)/)) {
funParams[m[1]] = m[2];
}
});
});
console.log("<script>var DATA = " + JSON.stringify(objectMembers, null, null) + ";</script>");
var objnames = Object.keys(objectMembers)
.sort();
objnames.forEach(function (objname) {
var members = objectMembers[objname];
if (members.length === 0) return;
console.log("<section>");
console.log("<h1>" + objname + "</h1>");
console.log("<ul>");
members
.sort(function(x, y) {
if (x.static && !y.static) return -1;
else if (!x.static && y.static) return 1;
else {
var a = x.name, b = y.name; if (a < b) return -1; else if (a === b) return 0; else return 1;
}
})
.forEach (function (member) {
console.log("<li>" + (member.static ? "+ " : "- ") + member.name + "(" + member.params + ")" + "</li>");
});
console.log("</ul>");
console.log("</section>");
});
}
get();
console.log("</body>");
console.log("</html>");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment