From d6fd5d929dfa651c2dad5e6568d24e78affc85c3 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Wed, 6 Oct 2010 23:28:42 -0400 Subject: [PATCH 1/3] Use JSON.parse rather than eval to parse strings. --HG-- extra : transplant_source : %7B%40A%81%9F3%F4N%A7%0A%C37%A5%3D%D0%B9d%80%14%FE --- common/content/commands.js | 2 +- common/content/javascript.js | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/common/content/commands.js b/common/content/commands.js index ecb8751d..014fa7fd 100644 --- a/common/content/commands.js +++ b/common/content/commands.js @@ -917,7 +917,7 @@ const Commands = Module("commands", { if ((res = re2.exec(str))) arg += keepQuotes ? res[0] : res[2].replace(/\\(.)/g, "$1"); else if ((res = /^(")((?:[^\\"]|\\.)*)("?)/.exec(str))) - arg += keepQuotes ? res[0] : window.eval(res[0] + (res[3] ? "" : '"')); + arg += keepQuotes ? res[0] : JSON.parse(res[0] + (res[3] ? "" : '"')); else if ((res = /^(')((?:[^']|'')*)('?)/.exec(str))) arg += keepQuotes ? res[0] : res[2].replace("''", "'", "g"); else diff --git a/common/content/javascript.js b/common/content/javascript.js index 8c6c492f..c5c6cd19 100644 --- a/common/content/javascript.js +++ b/common/content/javascript.js @@ -478,9 +478,7 @@ const JavaScript = Module("javascript", { // The top of the stack is the sting we're completing. // Wrap it in its delimiters and eval it to process escape sequences. let string = this._str.substring(this._get(-1).offset + 1, this._lastIdx); - // This is definitely a properly quoted string. - // Just eval it normally. - string = window.eval(this._last + string + this._last); + string = JSON.parse(this._last + string + this._last); // Is this an object accessor? if (this._get(-2).char == "[") { // Are we inside of []? From 1c62294ef61e8e2ff383d0d8d11bdc794b995c77 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Thu, 7 Oct 2010 23:18:09 -0400 Subject: [PATCH 2/3] Some minor fixes, and add ctypes support to iter(). --HG-- extra : transplant_source : %8A%D5.%EC.%9A%CC%94%D3%AA%03ARn%D5%A0d%DF%FBj --- common/content/dactyl.js | 8 ++++---- common/content/io.js | 16 +++++++++------- common/content/javascript.js | 23 ++++++++++++----------- common/modules/base.jsm | 21 ++++++++++++++++++++- 4 files changed, 45 insertions(+), 23 deletions(-) diff --git a/common/content/dactyl.js b/common/content/dactyl.js index 73853241..2e65371c 100644 --- a/common/content/dactyl.js +++ b/common/content/dactyl.js @@ -25,16 +25,16 @@ const FailedAssertion = Class("FailedAssertion", Error, { } }); -deprecated.seen = { "chrome://dactyl/content/javascript.js": true }; -function deprecated(reason, fn) +function deprecated(reason, fn) update( function deprecatedMethod() { let frame = Components.stack.caller; - if (!set.add(deprecated.seen, frame.filename)) + if (!set.add(deprecatedMethod.seen, frame.filename)) dactyl.echoerr(frame.filename + ":" + frame.lineNumber + ": " + (this.className || this.constructor.className) + "." + fn.name + " is deprecated: " + reason); return fn.apply(this, arguments); - } + }, + { seen: { "chrome://dactyl/content/javascript.js": true } }); const Dactyl = Module("dactyl", { init: function () { diff --git a/common/content/io.js b/common/content/io.js index 6660ecac..efab3aa7 100644 --- a/common/content/io.js +++ b/common/content/io.js @@ -345,13 +345,15 @@ lookup: dactyl.helpInitialized = false; } catch (e) { - if (isString(e)) - e = { message: e }; - let err = new Error(); - for (let [k, v] in Iterator(e)) - err[k] = v; - err.echoerr = <>{file.path}:{e.lineNumber}: {e}; - throw err; + if (e.fileName) + try { + e.fileName = e.fileName.replace(/^(chrome|resource):.*? -> /, ""); + if (e.fileName == uri.spec) + e.fileName = filename; + e.echoerr = <>{e.fileName}:{e.lineNumber}: {e} + } + catch (e) {} + throw e; } } else if (/\.css$/.test(filename)) diff --git a/common/content/javascript.js b/common/content/javascript.js index c5c6cd19..c0d30380 100644 --- a/common/content/javascript.js +++ b/common/content/javascript.js @@ -358,8 +358,6 @@ const JavaScript = Module("javascript", { } let args = { - completer: compl, - anchored: true, filter: last == null ? key : string, last: last, prefix: last != null ? key : "" @@ -369,39 +367,42 @@ const JavaScript = Module("javascript", { // TODO: Make this a generic completion helper function. for (let [, obj] in Iterator(objects)) this.context.fork(obj[1], this._top.offset, this, this._fill, - update({}, args, { + update({ obj: obj[0], - name: obj[1] - })); + name: obj[1], + anchored: true, + completer: compl + }, args)); if (orig) return; for (let [, obj] in Iterator(objects)) this.context.fork(obj[1] + "/prototypes", this._top.offset, this, this._fill, - update({}, args, { + update({ obj: obj[0], name: obj[1] + " (prototypes)", + anchored: true, completer: function (a, b) compl(a, b, true) - })); + }, args)); for (let [, obj] in Iterator(objects)) this.context.fork(obj[1] + "/substrings", this._top.offset, this, this._fill, - update({}, args, { + update({ obj: obj[0], name: obj[1] + " (substrings)", anchored: false, completer: compl - })); + }, args)); for (let [, obj] in Iterator(objects)) this.context.fork(obj[1] + "/prototypes/substrings", this._top.offset, this, this._fill, - update({}, args, { + update({ obj: obj[0], name: obj[1] + " (prototype substrings)", anchored: false, completer: function (a, b) compl(a, b, true) - })); + }, args)); }, _getKey: function () { diff --git a/common/modules/base.jsm b/common/modules/base.jsm index 33635641..9b360ba8 100644 --- a/common/modules/base.jsm +++ b/common/modules/base.jsm @@ -10,6 +10,11 @@ const Cr = Components.results; const Cu = Components.utils; Cu.import("resource://gre/modules/XPCOMUtils.jsm"); +try { + var ctypes; + Components.utils.import("resource://gre/modules/ctypes.jsm"); +} +catch (e) {} let objproto = Object.prototype; let hasOwnProperty = objproto.hasOwnProperty; @@ -149,7 +154,7 @@ defineModule("base", { exports: [ "Cc", "Ci", "Class", "Cr", "Cu", "Module", "Object", "Runnable", "Struct", "StructBase", "Timer", "UTF8", "XPCOM", "XPCOMUtils", "array", - "call", "callable", "curry", "debuggerProperties", "defineModule", + "call", "callable", "ctypes", "curry", "debuggerProperties", "defineModule", "endModule", "forEach", "isArray", "isGenerator", "isinstance", "isObject", "isString", "isSubclass", "iter", "iterAll", "keys", "memoize", "properties", "requiresMainThread", "set", "update", "values" @@ -356,6 +361,20 @@ set.remove = function (set, key) { * @returns {Generator} */ function iter(obj) { + if (ctypes && obj instanceof ctypes.CData) { + while (obj.constructor instanceof ctypes.PointerType) + obj = obj.contents; + if (obj.constructor instanceof ctypes.ArrayType) + return array.iterItems(obj); + if (obj.constructor instanceof ctypes.StructType) + return (function () { + for (let prop in values(obj.constructor.fields)) + let ([name, type] = Iterator(prop).next()) { + yield [name, obj[name]]; + } + })(); + obj = {}; + } if (isinstance(obj, [Ci.nsIDOMHTMLCollection, Ci.nsIDOMNodeList])) return array.iterItems(obj); if (obj instanceof Ci.nsIDOMNamedNodeMap) From 655a48384b41c11db028024f4a31a471f59f5e1a Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Thu, 7 Oct 2010 23:35:53 -0400 Subject: [PATCH 3/3] Just use with (window) in userEval. Adding it to the prototype chain causes too much trouble. --HG-- extra : transplant_source : %040%D8%7E%06m%B1%04D%9E%C0wN%BF%8F%EEo%D9%14%F5 --- common/content/dactyl-overlay.js | 3 ++- common/content/dactyl.js | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/common/content/dactyl-overlay.js b/common/content/dactyl-overlay.js index 93b054b1..676a403d 100644 --- a/common/content/dactyl-overlay.js +++ b/common/content/dactyl-overlay.js @@ -18,7 +18,8 @@ __proto__: jsmodules, get content() window.content, jsmodules: jsmodules, - newContext: newContext + newContext: newContext, + window: window }; modules.modules = modules; diff --git a/common/content/dactyl.js b/common/content/dactyl.js index 2e65371c..6895a6a4 100644 --- a/common/content/dactyl.js +++ b/common/content/dactyl.js @@ -294,7 +294,7 @@ const Dactyl = Module("dactyl", { if (!context) context = userContext; - return Cu.evalInSandbox(str, context, "1.8", fileName, lineNumber); + return Cu.evalInSandbox("with (window) {" + str + "}", context, "1.8", fileName, lineNumber); }, /** @@ -1876,7 +1876,6 @@ const Dactyl = Module("dactyl", { }; }, load: function () { - jsmodules.__proto__ = window; dactyl.triggerObserver("load"); dactyl.log("All modules loaded", 3);