Skip to content

Instantly share code, notes, and snippets.

View jorendorff's full-sized avatar

Jason Orendorff jorendorff

View GitHub Profile
JSCLASS_GLOBAL_FLAGS
<- a few in js/src/shell (don't care)
<- a few in js/src/jsapi-tests (don't care)
<- "global" (startupcache/test/TestStartupCache.cpp:417; don't care)
<- "JSDGlobal" (js/jsd/jsd_high.c; don't care)
<- "jdummy" (jsapi.cpp JS_EnterCrossCompartmentCallScript; only used by JSD I think; don't care)
<- "IndexedDBTransactionThreadGlobal" (dom/indexedDB/IDBObjectStore.cpp:2476; don't care)
used in ThreadLocalJSRuntime::Init. Gets its own runtime and compartment.
diff --git a/js/src/jscntxt.h b/js/src/jscntxt.h
--- a/js/src/jscntxt.h
+++ b/js/src/jscntxt.h
@@ -178,16 +178,23 @@ struct ConservativeGCData
}
#endif
bool hasStackToScan() const {
return !!nativeStackTop;
}
@jorendorff
jorendorff / gist:2422704
Created April 19, 2012 18:09
EvaluateNonCompileAndGo, finally
diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -843,17 +843,32 @@ Evaluate(JSContext *cx, unsigned argc, j
return false;
if ((JS_GetClass(thisobj)->flags & JSCLASS_IS_GLOBAL) != JSCLASS_IS_GLOBAL) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_UNEXPECTED_TYPE,
"this-value passed to evaluate()", "not a global object");
return false;
/*
* This is a JavaScript Scratchpad.
*
* Enter some JavaScript, then Right Click or choose from the Execute Menu:
* 1. Run to evaluate the selected text,
* 2. Inspect to bring up an Object Inspector on the result, or,
* 3. Display to insert the result in a comment after the selection.
*/
function wrap(val) {
Components.utils.import("resource://gre/modules/AddonManager.jsm", null); //Getting Info of all addons & their URLS...
AddonManager.getAllAddons(function(addons) {
var s = '';
for (var addon of addons) {
if (addon.type == 'extension')
s += addon.getResourceURI().spec + '\n';
}
alert(s);
});
Components.utils.import("resource://gre/modules/AddonManager.jsm");
AddonManager.getAllAddons(function(addons) {
var s = addons.length + " addons\n=====\n";
for (var i = 0; i < addons.length; i++) {
var addon = addons[i];
s += addon.type + " " + addon.name + "\n";
}
alert(s);
});
@jorendorff
jorendorff / gist:2662282
Created May 11, 2012 20:40 — forked from anonymous/gist:2661058
Ziggurat for Firefox
// This is the code that goes with this screencast: https://www.youtube.com/watch?v=mT-6IQB4vi4
var win = gBrowser.selectedBrowser.contentWindow;
var doc = win.document;
var output = doc.createElement("div");
output.id = "output";
doc.body.appendChild(output);
var style = doc.createElement("style");
style.innerHTML = "div#output { margin-top: 10em; white-space: pre; } div#output span { padding: 0.6em; margin: 0 0.6em; border: 1px solid rgba(0, 0, 0, 0.8); border-radius: 0.2em; box-shadow: 1px 1px 1px rgba(0, 0, 0, 0.4); position: relative; bottom: 1em; background-color: #ff5454; } div#output span > span { background-color: #ffa054; } div#output span > span > span { background-color: #ffff54; } div#output span > span > span > span { background-color: #8cd446; } div#output span > span > span > span > span { background-color: #45d2b0; } div#output span > span > span > span > span > span { background-color: #438ccb; } div#output span > span > span > span > span > span > span { background-color: #8c3fc0; } div#o
diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -824,22 +824,22 @@ Evaluate(JSContext *cx, unsigned argc, j
"evaluate");
return false;
}
if (!JSVAL_IS_STRING(argv[0]) || (argc == 2 && JSVAL_IS_PRIMITIVE(argv[1]))) {
JS_ReportErrorNumber(cx, my_GetErrorMessage, NULL, JSSMSG_INVALID_ARGS, "evaluate");
return false;
@jorendorff
jorendorff / breakpoint.js
Created May 22, 2012 13:32
Debugger.Breakpoint object
Debugger.Breakpoint = function Breakpoint(dbg, url, line, handler) {
this._dbg = dbg;
this.url = url;
this.line = line;
this.onHit = handler;
this._scripts = null;
this.enabled = true;
};
Debugger.Breakpoint.prototype.hit = function hit(frame) {
return this.onHit(frame);
diff --git a/js/src/jsopcode.cpp b/js/src/jsopcode.cpp
--- a/js/src/jsopcode.cpp
+++ b/js/src/jsopcode.cpp
@@ -1045,72 +1045,71 @@ struct DecompiledOpcode
: text(NULL), parent(NULL), parentOffset(-1), parenthesized(false)
{}
};
struct JSPrinter
{