envjs 0.3.7 → 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -82,10 +82,12 @@ get cookie(c){
82
82
  //case we must check our current location.protocol to make sure it's
83
83
  //https:
84
84
  var allcookies = [], i;
85
- return cookieString($cookies.temporary) + cookieString($cookies.persistent);
85
+ return cookieString.call(this, $cookies.temporary) +
86
+ cookieString.call(this, $cookies.persistent);
86
87
  }});
87
88
 
88
89
  var cookieString = function(cookies) {
90
+ var $w = this._parentWindow;
89
91
  var cookieString = "";
90
92
  for (var i in cookies) {
91
93
  // check if the cookie is in the current domain (if domain is set)
@@ -109,6 +109,7 @@ __extend__(HTMLElement.prototype, {
109
109
  },
110
110
  offsetLeft: 0,
111
111
  offsetRight: 0,
112
+ offsetTop: 0,
112
113
  get offsetParent(){
113
114
  /* TODO */
114
115
  return;
@@ -117,6 +118,7 @@ __extend__(HTMLElement.prototype, {
117
118
  /* TODO */
118
119
  return;
119
120
  },
121
+ scrollTop: 0,
120
122
  scrollHeight: 0,
121
123
  scrollWidth: 0,
122
124
  scrollLeft: 0,
@@ -456,7 +456,7 @@ var __param__= function( array, boundary ) {
456
456
  array[i].value.push(content);
457
457
  array[i].value = array[i].value.join("\r\n");
458
458
  }
459
- serialized.push('Content-Disposition: form-data; name="'+array[i].name+'"'+fn+'\r\n');
459
+ serialized.push('Content-Disposition: form-data; name="'+array[i].name+'"'+fn+'\r\n\r\n');
460
460
  serialized.push(array[i].value);
461
461
  serialized.push( "\r\n" );
462
462
  }
@@ -1,5 +1,5 @@
1
1
  $env.log = function(msg, level){
2
- debug(' '+ (level?level:'LOG') + ':\t['+ new Date()+"] {ENVJS} "+msg);
2
+ print(' '+ (level?level:'LOG') + ':\t['+ new Date()+"] {ENVJS} "+msg);
3
3
  };
4
4
 
5
5
  $env.location = function(path, base){
@@ -34,6 +34,9 @@ function __removeEventListener__(target, type, fn){
34
34
  target.uuid = $events.length;
35
35
  $events[target.uuid] = {};
36
36
  }
37
+ if (!$events[target.uiid]) {
38
+ return;
39
+ }
37
40
  if ( !$events[target.uuid][type] ){
38
41
  $events[target.uuid][type] = [];
39
42
  }
@@ -98,7 +101,8 @@ function __dispatchEvent__(target, event, bubbles){
98
101
  var skip = false;
99
102
 
100
103
  if (url[0] === "#") {
101
- // print("return anchor only");
104
+ window.location.hash = url;
105
+ // print("return anchor only: "+window.location);
102
106
  skip = true;
103
107
  }
104
108
 
@@ -10,11 +10,12 @@ $env.__url = function(url){
10
10
  };
11
11
 
12
12
  $w.__defineSetter__("location", function(url){
13
- if (false) {
14
- if (url[0] === "#") {
15
- // print("return anchor only");
13
+ if (url[0] === "#") {
14
+ window.location.hash = url;
15
+ // print("return anchor only: "+window.location.href);
16
16
  return;
17
- }
17
+ }
18
+ if (false) {
18
19
  var now = window.location.href.replace(/^file:\/\//,"").replace(/#.*/,"");
19
20
  var to = $master.first_script_window && $master.first_script_window.location.href;
20
21
  // var to = $env.location(url,window.location.href != "about:blank" ? window.location.href: undefined);
@@ -41,12 +41,20 @@ XMLHttpRequest.prototype = {
41
41
  }else{
42
42
  try {
43
43
  $debug("parsing response text into xml document");
44
- responseXML = $domparser.parseFromString(_this.responseText+"");
44
+ /* responseXML = $domparser.parseFromString(_this.responseText+""); */
45
+ responseXML =
46
+ document.implementation.createDocument().
47
+ loadXML(_this.responseText+"");
45
48
  return responseXML;
46
49
  } catch(e) {
47
50
  $error('response XML does not apear to be well formed xml', e);
51
+ /*
48
52
  responseXML = $domparser.parseFromString("<html>"+
49
53
  "<head/><body><p> parse error </p></body></html>");
54
+ */
55
+ responseXML =
56
+ document.implementation.createDocument().
57
+ loadXML("<html><head/><body><p> parse error </p></body></html>");
50
58
  return responseXML;
51
59
  }
52
60
  }
@@ -671,6 +671,7 @@ function TokenExpr(m) {
671
671
  }
672
672
 
673
673
  TokenExpr.prototype.evaluate = function() {
674
+ // print("0 "+arguments.callee+" "+this.value);
674
675
  return new StringValue(this.value);
675
676
  };
676
677
 
@@ -961,12 +962,14 @@ function NodeTestAny() {
961
962
  }
962
963
 
963
964
  NodeTestAny.prototype.evaluate = function(ctx) {
965
+ // print("0 "+arguments.callee);
964
966
  return this.value;
965
967
  };
966
968
 
967
969
  function NodeTestElementOrAttribute() {}
968
970
 
969
971
  NodeTestElementOrAttribute.prototype.evaluate = function(ctx) {
972
+ // print("0 "+arguments.callee);
970
973
  return new BooleanValue(
971
974
  ctx.node.nodeType == DOMNode.ELEMENT_NODE ||
972
975
  ctx.node.nodeType == DOMNode.ATTRIBUTE_NODE);
@@ -975,12 +978,14 @@ NodeTestElementOrAttribute.prototype.evaluate = function(ctx) {
975
978
  function NodeTestText() {}
976
979
 
977
980
  NodeTestText.prototype.evaluate = function(ctx) {
981
+ // print("0 "+arguments.callee);
978
982
  return new BooleanValue(ctx.node.nodeType == DOMNode.TEXT_NODE);
979
983
  }
980
984
 
981
985
  function NodeTestComment() {}
982
986
 
983
987
  NodeTestComment.prototype.evaluate = function(ctx) {
988
+ // print("0 "+arguments.callee);
984
989
  return new BooleanValue(ctx.node.nodeType == DOMNode.COMMENT_NODE);
985
990
  }
986
991
 
@@ -989,6 +994,7 @@ function NodeTestPI(target) {
989
994
  }
990
995
 
991
996
  NodeTestPI.prototype.evaluate = function(ctx) {
997
+ // print("0 "+arguments.callee);
992
998
  return new
993
999
  BooleanValue(ctx.node.nodeType == DOMNode.PROCESSING_INSTRUCTION_NODE &&
994
1000
  (!this.target || ctx.node.nodeName == this.target));
@@ -1000,6 +1006,7 @@ function NodeTestNC(nsprefix) {
1000
1006
  }
1001
1007
 
1002
1008
  NodeTestNC.prototype.evaluate = function(ctx) {
1009
+ // print("0 "+arguments.callee);
1003
1010
  var n = ctx.node;
1004
1011
  return new BooleanValue(this.regex.match(n.nodeName));
1005
1012
  }
@@ -1010,6 +1017,7 @@ function NodeTestName(name) {
1010
1017
  }
1011
1018
 
1012
1019
  NodeTestName.prototype.evaluate = function(ctx) {
1020
+ // print("0 !!! "+arguments.callee);
1013
1021
  var n = ctx.node;
1014
1022
  if (ctx.caseInsensitive || n instanceof HTMLElement) {
1015
1023
  if (n.nodeName.length != this.name.length) return new BooleanValue(false);
@@ -1024,6 +1032,7 @@ function PredicateExpr(expr) {
1024
1032
  }
1025
1033
 
1026
1034
  PredicateExpr.prototype.evaluate = function(ctx) {
1035
+ // print("0 "+arguments.callee);
1027
1036
  var v = this.expr.evaluate(ctx);
1028
1037
  if (v.type == 'number') {
1029
1038
  // NOTE(mesch): Internally, position is represented starting with
@@ -1045,9 +1054,11 @@ FunctionCallExpr.prototype.appendArg = function(arg) {
1045
1054
  };
1046
1055
 
1047
1056
  FunctionCallExpr.prototype.evaluate = function(ctx) {
1057
+ // print("0 "+arguments.callee+" "+this.name.value);
1048
1058
  var fn = '' + this.name.value;
1049
1059
  var f = this.xpathfunctions[fn];
1050
1060
  if (f) {
1061
+ // print("1 "+f);
1051
1062
  return f.call(this, ctx);
1052
1063
  } else {
1053
1064
  xpathLog('XPath NO SUCH FUNCTION ' + fn);
@@ -1121,6 +1132,9 @@ FunctionCallExpr.prototype.xpathfunctions = {
1121
1132
  if (n.length == 0) {
1122
1133
  return new StringValue('');
1123
1134
  } else {
1135
+ if (ctx.caseInsensitive || n[0] instanceof HTMLElement) {
1136
+ return new StringValue(n[0].nodeName.toLowerCase());
1137
+ }
1124
1138
  return new StringValue(n[0].nodeName);
1125
1139
  }
1126
1140
  },
@@ -1398,6 +1412,7 @@ function UnionExpr(expr1, expr2) {
1398
1412
  }
1399
1413
 
1400
1414
  UnionExpr.prototype.evaluate = function(ctx) {
1415
+ // print("0 "+arguments.callee);
1401
1416
  var nodes1 = this.expr1.evaluate(ctx).nodeSetValue();
1402
1417
  var nodes2 = this.expr2.evaluate(ctx).nodeSetValue();
1403
1418
  var I1 = nodes1.length;
@@ -1423,6 +1438,7 @@ function PathExpr(filter, rel) {
1423
1438
  }
1424
1439
 
1425
1440
  PathExpr.prototype.evaluate = function(ctx) {
1441
+ // print("0 "+arguments.callee);
1426
1442
  var nodes = this.filter.evaluate(ctx).nodeSetValue();
1427
1443
  var nodes1 = [];
1428
1444
  if (ctx.returnOnFirstMatch) {
@@ -1451,6 +1467,7 @@ function FilterExpr(expr, predicate) {
1451
1467
  }
1452
1468
 
1453
1469
  FilterExpr.prototype.evaluate = function(ctx) {
1470
+ // print("0 "+arguments.callee);
1454
1471
  // the filter expression should be evaluated in its entirety with no
1455
1472
  // optimization, as we can't backtrack to it after having moved on to
1456
1473
  // evaluating the relative location path. See the testReturnOnFirstMatch
@@ -1479,6 +1496,7 @@ function UnaryMinusExpr(expr) {
1479
1496
  }
1480
1497
 
1481
1498
  UnaryMinusExpr.prototype.evaluate = function(ctx) {
1499
+ // print("0 "+arguments.callee);
1482
1500
  return new NumberValue(-this.expr.evaluate(ctx).numberValue());
1483
1501
  };
1484
1502
 
@@ -1489,6 +1507,7 @@ function BinaryExpr(expr1, op, expr2) {
1489
1507
  }
1490
1508
 
1491
1509
  BinaryExpr.prototype.evaluate = function(ctx) {
1510
+ // print("0 "+arguments.callee);
1492
1511
  var ret;
1493
1512
  switch (this.op.value) {
1494
1513
  case 'or':
@@ -1653,6 +1672,7 @@ function LiteralExpr(value) {
1653
1672
  }
1654
1673
 
1655
1674
  LiteralExpr.prototype.evaluate = function(ctx) {
1675
+ // print("0 "+arguments.callee+" "+this.value);
1656
1676
  return new StringValue(this.value);
1657
1677
  };
1658
1678
 
@@ -1661,6 +1681,7 @@ function NumberExpr(value) {
1661
1681
  }
1662
1682
 
1663
1683
  NumberExpr.prototype.evaluate = function(ctx) {
1684
+ // print("0 "+arguments.callee);
1664
1685
  return new NumberValue(this.value);
1665
1686
  };
1666
1687
 
@@ -1669,6 +1690,7 @@ function VariableExpr(name) {
1669
1690
  }
1670
1691
 
1671
1692
  VariableExpr.prototype.evaluate = function(ctx) {
1693
+ // print("0 "+arguments.callee);
1672
1694
  return ctx.getVariable(this.name);
1673
1695
  }
1674
1696
 
@@ -18,6 +18,7 @@ window.addEventListener("load",function(){
18
18
  }
19
19
  load("test/unit/parser.js");
20
20
  load("test/unit/timer.js");
21
+ load("test/unit/form.js");
21
22
 
22
23
  print("Load complete. Running tests.");
23
24
  });
@@ -0,0 +1,40 @@
1
+ module("form");
2
+
3
+ test("__param__ without a boundary should do query string style uri encoding", function() {
4
+ serialized_params = $master.static.__param__([{ name: 'username', value: 'jresig' }, { name: 'password', value: 'letmein' }]);
5
+ ok((serialized_params == 'username=jresig&password=letmein'), 'params should be key=value and joined by &');
6
+ });
7
+
8
+ test("__param__ without a boundary should escape spaces in values as + not %20", function() {
9
+ serialized_params = $master.static.__param__([{ name: 'username', value: 'jresig' }, { name: 'password', value: 'let me in' }]);
10
+ ok((serialized_params == 'username=jresig&password=let+me+in'), 'params should have spaces escaped as + not %20');
11
+ });
12
+
13
+ test("__param__ with a boundary should start with a -- then the boundary and a \\r\\n newline", function() {
14
+ serialized_params = $master.static.__param__([{ name: 'username', value: 'jresig' }, { name: 'password', value: 'letmein' }], '--aboundary');
15
+ ok(serialized_params.match(/^----aboundary\r\n/), 'params should start with a -- then the boundary and \\r\\n');
16
+ });
17
+
18
+ test("__param__ with a boundary should end with the boundary then -- and a \\r\\n newline", function() {
19
+ serialized_params = $master.static.__param__([{ name: 'username', value: 'jresig' }, { name: 'password', value: 'letmein' }], '--aboundary');
20
+ ok(serialized_params.match(/--aboundary--\r\n$/), 'params should end with the boundary then -- and \\r\\n');
21
+ });
22
+
23
+ test("__param__ with a boundary should render each key and value with a header, two \\r\\n newlines and the value", function() {
24
+ serialized_params = $master.static.__param__([{ name: 'username', value: 'jresig' }, { name: 'password', value: 'letmein' }], '--aboundary');
25
+ ok(serialized_params.match(/Content-Disposition: form-data; name="username"\r\n\r\njresig\r\n/), 'username not properly encoded');
26
+ ok(serialized_params.match(/Content-Disposition: form-data; name="password"\r\n\r\nletmein\r\n/), 'password not properly encoded');
27
+ });
28
+
29
+ test("__param__ with a boundary should separate each key-value with --, the boundary and a \\r\\n newline", function() {
30
+ serialized_params = $master.static.__param__([{ name: 'username', value: 'jresig' }, { name: 'password', value: 'letmein' }], '--aboundary');
31
+ ok(serialized_params.match(/jresig\r\n----aboundary\r\nContent-Disposition: form-data; name="password"/), 'username and password not properly separated');
32
+ });
33
+
34
+ test("__param__ with a boundary should not render spaces in data as + or %20", function() {
35
+ serialized_params = $master.static.__param__([{ name: 'username', value: 'jresig' }, { name: 'password', value: 'let me in' }], '--aboundary');
36
+ ok(!serialized_params.match(/let+me+in/), 'spaces incorrectly encoded as +');
37
+ ok(!serialized_params.match(/let%20me%20in/), 'spaces incorrectly encoded as %20');
38
+ ok(serialized_params.match(/let me in/), 'spaces not left as spaces');
39
+ });
40
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: envjs
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 3
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 7
10
- version: 0.3.7
9
+ - 8
10
+ version: 0.3.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - John Resig
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2010-07-05 00:00:00 -07:00
20
+ date: 2010-09-14 00:00:00 -07:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
@@ -357,6 +357,7 @@ files:
357
357
  - test/unit/elementmembers.js
358
358
  - test/unit/events.js
359
359
  - test/unit/fixtures/external_script.js
360
+ - test/unit/form.js
360
361
  - test/unit/iframe.js
361
362
  - test/unit/insertion.js
362
363
  - test/unit/multi-window.js