diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-09-12 12:32:48 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-09-12 12:32:48 -0700 |
commit | 29776fb77b125e56f0dcb6a6fd3c5cb28e0b46e7 (patch) | |
tree | 9f9d97a099419f9e11bc5682067e0441f9e013f9 | |
parent | b37876be6ebf3da38b657e413c80fc6d69560b76 (diff) |
initial xhr support in reproduceriter shell
-rwxr-xr-x | tools/reproduceriter.py | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/tools/reproduceriter.py b/tools/reproduceriter.py index 6696915d..8b78e2d6 100755 --- a/tools/reproduceriter.py +++ b/tools/reproduceriter.py @@ -93,6 +93,8 @@ out_dir = sys.argv[2] first_js = sys.argv[3] window_location = sys.argv[4] if len(sys.argv) >= 5 else '' +dirs_to_drop = 0 if not os.path.dirname(first_js) else len(os.path.dirname(first_js).split('/')) + if os.path.exists(out_dir): shutil.rmtree(out_dir) assert os.path.exists(os.path.join(in_dir, first_js)) @@ -125,6 +127,9 @@ open(os.path.join(out_dir, first_js), 'w').write(''' // environment for shell if (typeof nagivator == 'undefined') { +''' + #open(os.path.dirname(__file__) + os.path.sep + 'dom.js').read() + +''' +///* var window = { location: { toString: function() { @@ -178,11 +183,46 @@ if (typeof nagivator == 'undefined') { }; }, }; +//*/ + var alert = function(x) { + print(x); + }; var performance = { now: function() { return Date.now(); }, }; + var XMLHttpRequest = function() { + return { + open: function(mode, path, async) { + if (path[0] == '/') path = path.substring(1); + for (var i = 0; i < %d; i++) { + path = '../' + path; // go back to root dir if first_js is in a subdir + } + this.mode = mode; + this.path = path; + this.async = async; + }, + send: function() { + if (!this.async) { + this.doSend(); + } else { + var that = this; + window.setTimeout(function() { + that.doSend(); + if (that.onload) that.onload(); + }, 0); + } + }, + doSend: function() { + if (this.responseType == 'arraybuffer') { + this.response = read(this.path, 'binary'); + } else { + this.responseText = read(this.path); + } + }, + }; + }; } var Recorder = (function() { @@ -397,7 +437,7 @@ var Recorder = (function() { recorder.replaying = replaying; return recorder; })(); -''' % (window_location, window_location.split('?')[-1]) + open(os.path.join(in_dir, first_js)).read() + ''' +''' % (window_location, window_location.split('?')[-1], dirs_to_drop) + open(os.path.join(in_dir, first_js)).read() + ''' if (typeof nagivator == 'undefined') { window.runEventLoop(); } |