envjs 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +25 -102
- data/lib/envjs/env.js +135 -16
- data/lib/envjs/runtime.rb +13 -3
- data/test/base64.js +80 -0
- data/test/call-load-test.js.smp +14 -0
- data/test/data.js +45 -0
- data/test/scope.html +19 -0
- data/test/scope.rb +24 -0
- metadata +12 -6
data/README
CHANGED
@@ -1,113 +1,36 @@
|
|
1
|
-
env.js
|
2
|
-
Developed by John Resig (http://ejohn.org)
|
1
|
+
This is a fork of the env.js project (http://github.com/thatcher/env-js/). See that link for env.js details.
|
3
2
|
|
4
|
-
|
5
|
-
Chris Thatcher (http://github.com/thatcher)
|
3
|
+
This fork is based on the Johnson Ruby gem (http://github.com/jbarnette/johnson). It should become obsolete when the Johnson support has been reintegrated into the master repo.
|
6
4
|
|
7
|
-
|
8
|
-
http://github.com/jeresig/env-js/
|
9
|
-
http://github.com/thatcher/env-js/
|
5
|
+
For now, you can install the envjs gem by installing Johnson:
|
10
6
|
|
11
|
-
|
12
|
-
http://groups.google.com/group/envjs
|
7
|
+
gem install johnson --prerelease
|
13
8
|
|
14
|
-
|
15
|
-
http://envjs.lighthouseapp.com/projects/21590-envjs/
|
9
|
+
(You'll need to manually install any prerequisites it asks for) and then installing the envjs gem with
|
16
10
|
|
17
|
-
|
18
|
-
http://runcoderun.com/thatcher/env-js
|
11
|
+
gem install envjs
|
19
12
|
|
20
|
-
|
21
|
-
http://ejohn.org/projects/bringing-the-browser-to-the-server/
|
13
|
+
The envjs gem provides the envjsrb command, which functions as an extended version of the Johnson javascript shell. For example:
|
22
14
|
|
23
|
-
|
24
|
-
|
15
|
+
mbp:env-js smparkes$ envjsrb
|
16
|
+
js> this
|
17
|
+
=> [object Window 0]
|
18
|
+
js> window.location
|
19
|
+
=> about:blank
|
20
|
+
js> document.innerHTML
|
21
|
+
=> "<html><head><title></title></head><body></body></html>"
|
22
|
+
js>
|
25
23
|
|
26
|
-
|
24
|
+
It's also possible to embed the envjs interpreter similar to the way it's done in Johnson, e.g.,
|
27
25
|
|
28
|
-
|
26
|
+
require 'rubygems' # if necessary
|
27
|
+
require 'johnson/tramonkey'
|
28
|
+
require 'envjs/runtime'
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
envjs = Johnson::Runtime.new
|
31
|
+
envjs.extend Envjs::Runtime
|
32
|
+
window = envjs.evaluate("window")
|
33
|
+
puts window.location.to_s # == "about:blank"
|
34
|
+
puts window.document.innerHTML # == "<html><head><title></title></head><body></body></html>"
|
33
35
|
|
34
|
-
|
35
|
-
* Checkout qunit: "git submodule update --init"
|
36
|
-
* run "ant test"
|
37
|
-
|
38
|
-
Java command line:
|
39
|
-
|
40
|
-
env.rhino.js can be run either with a "generic" version of the Rhino
|
41
|
-
library (js.jar), or with the repackaged/extended version of Rhino
|
42
|
-
supplied with env.js (env-js.jar). If your application uses multiple
|
43
|
-
windows, frames, or iframes, or if it depends on precise adherence to
|
44
|
-
JavaScript object scoping in event handlers, you will have to use
|
45
|
-
env-js.jar. Simple applications may be able to run with the generic
|
46
|
-
version of Rhino.
|
47
|
-
|
48
|
-
The command line used for testing env.js can be found in build.xml,
|
49
|
-
although the general form is:
|
50
|
-
java -jar [jar file] [javascript file]
|
51
|
-
Where "jar file" is either "dist/env-js.jar", "rhino/js.jar", or your
|
52
|
-
local path to a different version of the Rhino js.jar file. The
|
53
|
-
"javascript file" is the path to the JavaScript you wish to execute.
|
54
|
-
|
55
|
-
Installing:
|
56
|
-
1) Include the proper env.js file for your platform.
|
57
|
-
load('env.rhino.js'); //if in a Rhino script
|
58
|
-
|
59
|
-
2) Tell env.js to load an HTML file from your file system that it should model:
|
60
|
-
Envjs("some/file.html");
|
61
|
-
or
|
62
|
-
var someWindow = window.open("some/file.html");
|
63
|
-
or
|
64
|
-
window.location = "some/file.html";
|
65
|
-
|
66
|
-
Optionally you can turn on/off settings by passing an options object:
|
67
|
-
Envjs("some/file.html", {log: function(msg){ console.debug(msg) }});
|
68
|
-
|
69
|
-
3) Optionally trigger "document ready" events in one of these ways:
|
70
|
-
|
71
|
-
4) Start processing of window(s)' event queue:
|
72
|
-
Envjs.wait();
|
73
|
-
|
74
|
-
All together, the steps could be:
|
75
|
-
|
76
|
-
a) simplest method:
|
77
|
-
load('env.rhino.js');
|
78
|
-
Envjs("some/file.html");
|
79
|
-
Envjs.wait();
|
80
|
-
|
81
|
-
b) jQuery ready method:
|
82
|
-
load('env.rhino.js');
|
83
|
-
load('jquery-1.3.2.js');
|
84
|
-
Envjs("some/file.html");
|
85
|
-
load('some-code-that-sets-up-jquery-onready-behaviors.js')
|
86
|
-
jQuery.ready();
|
87
|
-
Envjs.wait();
|
88
|
-
|
89
|
-
c) Other JavaScript frameworks have their own methods of setup, but the general pattern is:
|
90
|
-
// step 1: load env.js
|
91
|
-
// optionally: load your framework(s)
|
92
|
-
// step 2: tell env.js the base DOM to model
|
93
|
-
// optionally: run any setup code for your framework(s0
|
94
|
-
// step 3: tell the framework that the document is loaded
|
95
|
-
// step 4: Envjs.wait();
|
96
|
-
|
97
|
-
Note that env.js is currently limited to loading a single HTML page
|
98
|
-
from the original window. If you are going to load multiple pages in
|
99
|
-
succession into the same window, load the first into a new window
|
100
|
-
object using window.open().
|
101
|
-
|
102
|
-
Testing jQuery Compatibility:
|
103
|
-
* run ./bin/test-jquery.sh 1.3.2
|
104
|
-
* run ./bin/test-jquery.sh 1.3.1
|
105
|
-
* run ./bin/test-jquery.sh 1.2.6
|
106
|
-
* Checks out the given jQuery tag from Subversion into test/vendor/jQuery/[version],
|
107
|
-
moves dist/env.rhino.js into the correct location in their tree, and runs the test suites.
|
108
|
-
|
109
|
-
Changes with new timer code:
|
110
|
-
|
111
|
-
Previously with envjs, you could call Java's thread sleep() method to delay execution. This was mostly used in test suites. This may no
|
112
|
-
longer work the same since it will inhibit all events from firing. You can now use the Envjs.wait(milliseconds) call to achieve an
|
113
|
-
effect similar to calling sleep().
|
36
|
+
Comments to http://groups.google.com/group/envjs or #envjs on freenode.
|
data/lib/envjs/env.js
CHANGED
@@ -37,10 +37,11 @@
|
|
37
37
|
|
38
38
|
( master.window_index === undefined ) && ( master.window_index = 0 );
|
39
39
|
|
40
|
-
$platform.init_window = function(
|
40
|
+
$platform.init_window = function(inner) {
|
41
41
|
var index = master.window_index++;
|
42
|
-
|
43
|
-
return "[object Window "+index+"]";
|
42
|
+
inner.toString = function(){
|
43
|
+
// return "[object Window "+index+"]";
|
44
|
+
return "[object Window]";
|
44
45
|
};
|
45
46
|
};
|
46
47
|
|
@@ -51,10 +52,10 @@
|
|
51
52
|
var swap_script_window = ( $master.first_script_window.window === proxy );
|
52
53
|
if(!proxy){
|
53
54
|
proxy = $platform.new_split_global_outer();
|
54
|
-
// $master.print("np",proxy);
|
55
55
|
}
|
56
56
|
$master.proxy = proxy;
|
57
57
|
new_window = $platform.new_split_global_inner(proxy,undefined);
|
58
|
+
new_window.$inner = new_window;
|
58
59
|
if(swap_script_window) {
|
59
60
|
$master.first_script_window = new_window;
|
60
61
|
}
|
@@ -69,6 +70,9 @@
|
|
69
70
|
$master.load(f,new_window);
|
70
71
|
}
|
71
72
|
};
|
73
|
+
new_window.evaluate = function(string){
|
74
|
+
return $master.evaluate.call(string,new_window);
|
75
|
+
};
|
72
76
|
return [ proxy, new_window ];
|
73
77
|
};
|
74
78
|
|
@@ -79,13 +83,18 @@
|
|
79
83
|
var options = this.$options;
|
80
84
|
delete this.$options;
|
81
85
|
$env.$master = $master;
|
82
|
-
$
|
86
|
+
var $inner = this.$inner;
|
87
|
+
delete this.$inner;
|
88
|
+
$env.init_window.call($inner,$inner,options);
|
83
89
|
};
|
84
90
|
|
85
|
-
$env.init_window = function(options){
|
91
|
+
$env.init_window = function(inner,options){
|
92
|
+
var $inner = inner;
|
93
|
+
var $w = this;
|
94
|
+
|
86
95
|
options = options || {};
|
87
96
|
|
88
|
-
$platform.init_window(
|
97
|
+
$platform.init_window($w);
|
89
98
|
|
90
99
|
var print = $master.print;
|
91
100
|
|
@@ -98,10 +107,8 @@
|
|
98
107
|
}
|
99
108
|
// print("setx",this);
|
100
109
|
// print("setx",this.window);
|
101
|
-
|
102
|
-
|
103
|
-
// print("$$w",$w);
|
104
|
-
// print("$$w",$w === this);
|
110
|
+
|
111
|
+
// print("$$w",$w,this,$w.isInner,this.isInner,$w === this);
|
105
112
|
$env.log = function(msg, level){
|
106
113
|
debug(' '+ (level?level:'LOG') + ':\t['+ new Date()+"] {ENVJS} "+msg);
|
107
114
|
};
|
@@ -111,7 +118,7 @@ $env.location = function(path, base){
|
|
111
118
|
if ( path == "about:blank" ) {
|
112
119
|
return path;
|
113
120
|
}
|
114
|
-
var protocol = new RegExp('(^file\:|^http\:|^https
|
121
|
+
var protocol = new RegExp('(^file\:|^http\:|^https\:|data:)');
|
115
122
|
var m = protocol.exec(path);
|
116
123
|
if(m&&m.length>1){
|
117
124
|
var url = Ruby.URI.parse(path);
|
@@ -424,16 +431,20 @@ $env.lineSource = function(e){
|
|
424
431
|
|
425
432
|
$env.loadInlineScript = function(script){
|
426
433
|
var original_script_window = $master.first_script_window;
|
434
|
+
// debug("lis",original_script_window,original_script_window.isInner);
|
435
|
+
// debug("XX",window,window.isInner);
|
427
436
|
if ( !$master.first_script_window ) {
|
428
437
|
$master.first_script_window = window;
|
429
438
|
}
|
439
|
+
// debug("lix",$master.first_script_window,$master.first_script_window.isInner,$w,$w.isInner);
|
430
440
|
try {
|
431
|
-
$master.evaluate(script.text,$
|
441
|
+
$master.evaluate(script.text,$inner);
|
432
442
|
} catch(e) {
|
433
443
|
$env.error("error evaluating script: "+script.text);
|
434
444
|
$env.error(e);
|
435
445
|
}
|
436
446
|
$master.first_script_window = original_script_window;
|
447
|
+
// debug("lis",original_script_window,original_script_window.isInner);
|
437
448
|
};
|
438
449
|
|
439
450
|
$env.writeToTempFile = function(text, suffix){
|
@@ -484,7 +495,7 @@ $env.__eval__ = function(script,scope){
|
|
484
495
|
if ( !$master.first_script_window ) {
|
485
496
|
$master.first_script_window = window;
|
486
497
|
}
|
487
|
-
var result = $master.evaluate(script,$
|
498
|
+
var result = $master.evaluate(script,$inner)(original,scopes);
|
488
499
|
$master.first_script_window = original_script_window;
|
489
500
|
return result;
|
490
501
|
}catch(e){
|
@@ -854,7 +865,87 @@ print("TT");
|
|
854
865
|
setScope($env.loadLocalScript, scopes.local_load);
|
855
866
|
}
|
856
867
|
|
857
|
-
})($env)
|
868
|
+
})($env);// This code was written by Tyler Akins and has been placed in the
|
869
|
+
// public domain. It would be nice if you left this header intact.
|
870
|
+
// Base64 code from Tyler Akins -- http://rumkin.com
|
871
|
+
|
872
|
+
var Base64 = (function () {
|
873
|
+
var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
874
|
+
|
875
|
+
var obj = {
|
876
|
+
/**
|
877
|
+
* Encodes a string in base64
|
878
|
+
* @param {String} input The string to encode in base64.
|
879
|
+
*/
|
880
|
+
encode: function (input) {
|
881
|
+
var output = "";
|
882
|
+
var chr1, chr2, chr3;
|
883
|
+
var enc1, enc2, enc3, enc4;
|
884
|
+
var i = 0;
|
885
|
+
|
886
|
+
do {
|
887
|
+
chr1 = input.charCodeAt(i++);
|
888
|
+
chr2 = input.charCodeAt(i++);
|
889
|
+
chr3 = input.charCodeAt(i++);
|
890
|
+
|
891
|
+
enc1 = chr1 >> 2;
|
892
|
+
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
|
893
|
+
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
|
894
|
+
enc4 = chr3 & 63;
|
895
|
+
|
896
|
+
if (isNaN(chr2)) {
|
897
|
+
enc3 = enc4 = 64;
|
898
|
+
} else if (isNaN(chr3)) {
|
899
|
+
enc4 = 64;
|
900
|
+
}
|
901
|
+
|
902
|
+
output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) +
|
903
|
+
keyStr.charAt(enc3) + keyStr.charAt(enc4);
|
904
|
+
} while (i < input.length);
|
905
|
+
|
906
|
+
return output;
|
907
|
+
},
|
908
|
+
|
909
|
+
/**
|
910
|
+
* Decodes a base64 string.
|
911
|
+
* @param {String} input The string to decode.
|
912
|
+
*/
|
913
|
+
decode: function (input) {
|
914
|
+
var output = "";
|
915
|
+
var chr1, chr2, chr3;
|
916
|
+
var enc1, enc2, enc3, enc4;
|
917
|
+
var i = 0;
|
918
|
+
|
919
|
+
// remove all characters that are not A-Z, a-z, 0-9, +, /, or =
|
920
|
+
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
|
921
|
+
|
922
|
+
do {
|
923
|
+
enc1 = keyStr.indexOf(input.charAt(i++));
|
924
|
+
enc2 = keyStr.indexOf(input.charAt(i++));
|
925
|
+
enc3 = keyStr.indexOf(input.charAt(i++));
|
926
|
+
enc4 = keyStr.indexOf(input.charAt(i++));
|
927
|
+
|
928
|
+
chr1 = (enc1 << 2) | (enc2 >> 4);
|
929
|
+
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
|
930
|
+
chr3 = ((enc3 & 3) << 6) | enc4;
|
931
|
+
|
932
|
+
output = output + String.fromCharCode(chr1);
|
933
|
+
|
934
|
+
if (enc3 != 64) {
|
935
|
+
output = output + String.fromCharCode(chr2);
|
936
|
+
}
|
937
|
+
if (enc4 != 64) {
|
938
|
+
output = output + String.fromCharCode(chr3);
|
939
|
+
}
|
940
|
+
} while (i < input.length);
|
941
|
+
|
942
|
+
return output;
|
943
|
+
}
|
944
|
+
};
|
945
|
+
|
946
|
+
return obj;
|
947
|
+
})();
|
948
|
+
/*
|
858
949
|
* window.js
|
859
950
|
* - this file will be wrapped in a closure providing the window object as $w
|
860
951
|
*/
|
@@ -5185,6 +5276,33 @@ __extend__(DOMDocument.prototype, {
|
|
5185
5276
|
},
|
5186
5277
|
status: 200
|
5187
5278
|
});
|
5279
|
+
} else if (url.indexOf("data:") === 0) {
|
5280
|
+
url = url.slice(5);
|
5281
|
+
var fields = url.split(",");
|
5282
|
+
var content = fields[1];
|
5283
|
+
var fields = fields[0].split(";");
|
5284
|
+
if(fields[1] === "base64" || (fields[1] && fields[1].indexOf("charset=") === 0 && fields[2] === "base64" ) ) {
|
5285
|
+
content = Base64.decode(content);
|
5286
|
+
} else {
|
5287
|
+
content = unescape(content);
|
5288
|
+
}
|
5289
|
+
if(fields[0] === "text/html") {
|
5290
|
+
} else if(fields[0] === "image/png") {
|
5291
|
+
throw new Error("png");
|
5292
|
+
} else {
|
5293
|
+
content = "<html><head><title></title></head><body>"+content+"</body></html>";
|
5294
|
+
}
|
5295
|
+
xhr = ({
|
5296
|
+
open: function(){},
|
5297
|
+
send: function(){
|
5298
|
+
var self = this;
|
5299
|
+
setTimeout(function(){
|
5300
|
+
self.responseText = content;
|
5301
|
+
self.onreadystatechange();
|
5302
|
+
},0);
|
5303
|
+
},
|
5304
|
+
status: 200
|
5305
|
+
});
|
5188
5306
|
} else {
|
5189
5307
|
xhr = new XMLHttpRequest();
|
5190
5308
|
}
|
@@ -21542,7 +21660,8 @@ Html5Parser();
|
|
21542
21660
|
})(); // close function definition begun in 'intro.js'
|
21543
21661
|
|
21544
21662
|
// Initial window setup
|
21545
|
-
$env.init
|
21663
|
+
var init = $env.init;
|
21664
|
+
init();
|
21546
21665
|
|
21547
21666
|
})();
|
21548
21667
|
|
data/lib/envjs/runtime.rb
CHANGED
@@ -197,6 +197,8 @@ EOJS
|
|
197
197
|
|
198
198
|
if uri.scheme == "file"
|
199
199
|
uri_s = uri.path
|
200
|
+
elsif uri.scheme == "data"
|
201
|
+
raise "implement 0"
|
200
202
|
end
|
201
203
|
|
202
204
|
v = open(uri_s).read.gsub(/\A#!.*$/, '')
|
@@ -224,6 +226,8 @@ EOJS
|
|
224
226
|
|
225
227
|
if uri.scheme == "file"
|
226
228
|
super uri.path
|
229
|
+
elsif uri.scheme == "data"
|
230
|
+
raise "implement 1"
|
227
231
|
else
|
228
232
|
raise "hell 1"
|
229
233
|
end
|
@@ -268,10 +272,15 @@ EOJS
|
|
268
272
|
|
269
273
|
master.first_script_window = window
|
270
274
|
|
275
|
+
window["$inner"] = inner
|
271
276
|
window["$master"] = master
|
272
277
|
window["$options"] = evaluate("new Object");
|
273
278
|
window["$options"].proxy = outer
|
274
279
|
|
280
|
+
window.evaluate = lambda { |s|
|
281
|
+
return master.evaluate.call(s,window);
|
282
|
+
}
|
283
|
+
|
275
284
|
window.load = lambda { |*files|
|
276
285
|
files.each do |f|
|
277
286
|
master.load.call f, window
|
@@ -292,23 +301,24 @@ EOJS
|
|
292
301
|
scripts = {}
|
293
302
|
|
294
303
|
( class << self; self; end ).send :define_method, :become_first_script_window do
|
295
|
-
# p "heh", inner, master.first_script_window
|
304
|
+
# p "heh ++++++++++++++++++++++++++++", inner, master.first_script_window
|
296
305
|
inner = master.first_script_window
|
297
306
|
end
|
298
307
|
|
299
308
|
( class << self; self; end ).send :define_method, :evaluate do |*args|
|
300
309
|
( script, file, line, global, scope, fn ) = *args
|
301
|
-
# print "eval in " + script[0,50].inspect + (scope ? scope.
|
310
|
+
# print "eval in " + script[0,50].inspect + scope.inspect + " " + ( scope ? scope.isInner.inspect : "none" ) + "\n"
|
302
311
|
global = nil
|
303
312
|
scope ||= inner
|
304
313
|
if fn
|
305
314
|
compiled_script = scripts[fn]
|
306
315
|
end
|
307
|
-
# compiled_script = compile(script, file, line, global)
|
308
316
|
compiled_script ||= compile(script, file, line, global)
|
317
|
+
# compiled_script = compile(script, file, line, global)
|
309
318
|
if fn && !scripts[fn]
|
310
319
|
scripts[fn] = compiled_script
|
311
320
|
end
|
321
|
+
# p "?", script
|
312
322
|
evaluate_compiled_script(compiled_script,scope)
|
313
323
|
end
|
314
324
|
|
data/test/base64.js
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
// This code was written by Tyler Akins and has been placed in the
|
2
|
+
// public domain. It would be nice if you left this header intact.
|
3
|
+
// Base64 code from Tyler Akins -- http://rumkin.com
|
4
|
+
|
5
|
+
var Base64 = (function () {
|
6
|
+
var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
7
|
+
|
8
|
+
var obj = {
|
9
|
+
/**
|
10
|
+
* Encodes a string in base64
|
11
|
+
* @param {String} input The string to encode in base64.
|
12
|
+
*/
|
13
|
+
encode: function (input) {
|
14
|
+
var output = "";
|
15
|
+
var chr1, chr2, chr3;
|
16
|
+
var enc1, enc2, enc3, enc4;
|
17
|
+
var i = 0;
|
18
|
+
|
19
|
+
do {
|
20
|
+
chr1 = input.charCodeAt(i++);
|
21
|
+
chr2 = input.charCodeAt(i++);
|
22
|
+
chr3 = input.charCodeAt(i++);
|
23
|
+
|
24
|
+
enc1 = chr1 >> 2;
|
25
|
+
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
|
26
|
+
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
|
27
|
+
enc4 = chr3 & 63;
|
28
|
+
|
29
|
+
if (isNaN(chr2)) {
|
30
|
+
enc3 = enc4 = 64;
|
31
|
+
} else if (isNaN(chr3)) {
|
32
|
+
enc4 = 64;
|
33
|
+
}
|
34
|
+
|
35
|
+
output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) +
|
36
|
+
keyStr.charAt(enc3) + keyStr.charAt(enc4);
|
37
|
+
} while (i < input.length);
|
38
|
+
|
39
|
+
return output;
|
40
|
+
},
|
41
|
+
|
42
|
+
/**
|
43
|
+
* Decodes a base64 string.
|
44
|
+
* @param {String} input The string to decode.
|
45
|
+
*/
|
46
|
+
decode: function (input) {
|
47
|
+
var output = "";
|
48
|
+
var chr1, chr2, chr3;
|
49
|
+
var enc1, enc2, enc3, enc4;
|
50
|
+
var i = 0;
|
51
|
+
|
52
|
+
// remove all characters that are not A-Z, a-z, 0-9, +, /, or =
|
53
|
+
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
|
54
|
+
|
55
|
+
do {
|
56
|
+
enc1 = keyStr.indexOf(input.charAt(i++));
|
57
|
+
enc2 = keyStr.indexOf(input.charAt(i++));
|
58
|
+
enc3 = keyStr.indexOf(input.charAt(i++));
|
59
|
+
enc4 = keyStr.indexOf(input.charAt(i++));
|
60
|
+
|
61
|
+
chr1 = (enc1 << 2) | (enc2 >> 4);
|
62
|
+
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
|
63
|
+
chr3 = ((enc3 & 3) << 6) | enc4;
|
64
|
+
|
65
|
+
output = output + String.fromCharCode(chr1);
|
66
|
+
|
67
|
+
if (enc3 != 64) {
|
68
|
+
output = output + String.fromCharCode(chr2);
|
69
|
+
}
|
70
|
+
if (enc4 != 64) {
|
71
|
+
output = output + String.fromCharCode(chr3);
|
72
|
+
}
|
73
|
+
} while (i < input.length);
|
74
|
+
|
75
|
+
return output;
|
76
|
+
}
|
77
|
+
};
|
78
|
+
|
79
|
+
return obj;
|
80
|
+
})();
|
@@ -0,0 +1,14 @@
|
|
1
|
+
window.location = "test/index.html";
|
2
|
+
window.load("test/qunit.js");
|
3
|
+
|
4
|
+
test("'index.html' loaded correctly via 'Envjs()' call", function(){
|
5
|
+
expect(1);
|
6
|
+
try{ ok(document.getElementById('body').id == "body",
|
7
|
+
"'index.html' page content available");
|
8
|
+
}catch(e){print(e);}
|
9
|
+
});
|
10
|
+
|
11
|
+
test("window.location= following Envjs() initialization flagged as error",
|
12
|
+
function(){
|
13
|
+
expect(0);
|
14
|
+
});
|
data/test/data.js
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
#!/usr/bin/env envjsrb
|
2
|
+
load('base64.js');
|
3
|
+
inner = "<head><title>Hello, World from a data uri!</title></head><body></body>";
|
4
|
+
doc = "<html>"+inner+"</html>";
|
5
|
+
url_escaped = "data:text/html,"+escape(doc);
|
6
|
+
base64 = "data:text/html;base64,"+Base64.encode(doc);
|
7
|
+
debug(url_escaped);
|
8
|
+
window.location = "about:blank";
|
9
|
+
Envjs.wait();
|
10
|
+
window.location = url_escaped;
|
11
|
+
Envjs.wait();
|
12
|
+
debug(window.document.documentElement.innerHTML);
|
13
|
+
if(window.document.documentElement.innerHTML != inner){
|
14
|
+
debug(window.document.documentElement.innerHTML);
|
15
|
+
debug(inner);
|
16
|
+
throw new Error(window.document.documentElement.innerHTML);
|
17
|
+
}
|
18
|
+
debug(base64);
|
19
|
+
window.location = "about:blank";
|
20
|
+
Envjs.wait();
|
21
|
+
window.location = base64;
|
22
|
+
Envjs.wait();
|
23
|
+
debug(window.document.documentElement.innerHTML);
|
24
|
+
if(window.document.documentElement.innerHTML != inner){
|
25
|
+
throw new Error("b"+window.document.documentElement.innerHTML);
|
26
|
+
}
|
27
|
+
window.location = "about:blank";
|
28
|
+
Envjs.wait();
|
29
|
+
window.location = "data:,"+escape("Hello, World from a data uri!");
|
30
|
+
Envjs.wait();
|
31
|
+
debug(window.location+"");
|
32
|
+
debug(window.document.documentElement.innerHTML);
|
33
|
+
inner = "<head><title></title></head><body>Hello, World from a data uri!</body>";
|
34
|
+
if(window.document.documentElement.innerHTML != inner){
|
35
|
+
throw new Error("c"+window.document.documentElement.innerHTML);
|
36
|
+
}
|
37
|
+
|
38
|
+
/* not implemented yet ...
|
39
|
+
w = open("about:blank");
|
40
|
+
w.foo = 10;
|
41
|
+
debug(w.foo);
|
42
|
+
uri = "data:text/javascript;base64,"+"foo = 20;";
|
43
|
+
w.load(uri);
|
44
|
+
debug(w.foo);
|
45
|
+
*/
|
data/test/scope.html
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<title>
|
4
|
+
</title>
|
5
|
+
<script>
|
6
|
+
var foo = 10;
|
7
|
+
if(foo!=10) {
|
8
|
+
throw new Error("scope problem occured");
|
9
|
+
}
|
10
|
+
</script>
|
11
|
+
<script>
|
12
|
+
if(foo!=10) {
|
13
|
+
throw new Error("scope problem occured");
|
14
|
+
}
|
15
|
+
</script>
|
16
|
+
</head>
|
17
|
+
<body>
|
18
|
+
</body>
|
19
|
+
</html>
|
data/test/scope.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'johnson/tracemonkey'
|
4
|
+
require 'envjs/runtime'
|
5
|
+
|
6
|
+
require 'nanotest'
|
7
|
+
include Nanotest
|
8
|
+
|
9
|
+
rt = Johnson::Runtime.new
|
10
|
+
rt.extend(Envjs::Runtime)
|
11
|
+
|
12
|
+
rt.evaluate("var foo = 10");
|
13
|
+
assert { rt.evaluate("foo") == 10 }
|
14
|
+
|
15
|
+
rt.evaluate('window.location = "http://example.com"')
|
16
|
+
assert { 'Example Web Page' == rt.evaluate('window.document.title') }
|
17
|
+
assert { 'Example Web Page' == rt.evaluate('this.document.title') }
|
18
|
+
assert { 'Example Web Page' == rt.evaluate('document.title') }
|
19
|
+
|
20
|
+
rt.evaluate('window.location = "http://montrealrb.org"')
|
21
|
+
assert { 'Montreal.rb' == rt.evaluate('window.document.title') }
|
22
|
+
assert { 'Montreal.rb' == rt.evaluate('this.document.title') }
|
23
|
+
|
24
|
+
assert { 'Example Web Page' == rt.evaluate('document.title') }
|
metadata
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: envjs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Resig
|
8
8
|
- Chris Thatcher
|
9
|
+
- Steven Parkes
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
13
|
|
13
|
-
date: 2010-02-
|
14
|
+
date: 2010-02-09 00:00:00 -08:00
|
14
15
|
default_executable: envjsrb
|
15
16
|
dependencies:
|
16
17
|
- !ruby/object:Gem::Dependency
|
@@ -21,7 +22,7 @@ dependencies:
|
|
21
22
|
requirements:
|
22
23
|
- - ">="
|
23
24
|
- !ruby/object:Gem::Version
|
24
|
-
version: 2.0.0.
|
25
|
+
version: 2.0.0.pre1
|
25
26
|
version:
|
26
27
|
description: Browser environment for javascript interpreters
|
27
28
|
email: smparkes@smparkes.net
|
@@ -49,7 +50,10 @@ files:
|
|
49
50
|
- lib/envjs/options.rb
|
50
51
|
- lib/envjs/runtime.rb
|
51
52
|
- lib/envjs/tempfile.rb
|
53
|
+
- test/base64.js
|
52
54
|
- test/call-load-test.js
|
55
|
+
- test/call-load-test.js.smp
|
56
|
+
- test/data.js
|
53
57
|
- test/debug.js
|
54
58
|
- test/firebug/errorIcon.png
|
55
59
|
- test/firebug/firebug.css
|
@@ -90,6 +94,8 @@ files:
|
|
90
94
|
- test/qunit.js
|
91
95
|
- test/qunit/qunit/qunit.css
|
92
96
|
- test/qunit/qunit/qunit.js
|
97
|
+
- test/scope.html
|
98
|
+
- test/scope.rb
|
93
99
|
- test/specs/dist/env.spec.js
|
94
100
|
- test/specs/envjs.spec.css
|
95
101
|
- test/specs/parser/html.js
|
@@ -133,7 +139,7 @@ files:
|
|
133
139
|
- test/vendor/prototype-1.6.0.3.js
|
134
140
|
- README
|
135
141
|
has_rdoc: true
|
136
|
-
homepage: http://github.com/
|
142
|
+
homepage: http://github.com/smparkes/env-js
|
137
143
|
licenses: []
|
138
144
|
|
139
145
|
post_install_message:
|
@@ -160,5 +166,5 @@ rubygems_version: 1.3.5
|
|
160
166
|
signing_key:
|
161
167
|
specification_version: 3
|
162
168
|
summary: Browser environment for javascript interpreters
|
163
|
-
test_files:
|
164
|
-
|
169
|
+
test_files:
|
170
|
+
- test/scope.rb
|