Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: src/uri.js

Issue 292173011: Harden a few builtins (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: refactored Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/promise.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 "use strict"; 5 "use strict";
6 6
7 // This file relies on the fact that the following declaration has been made 7 // This file relies on the fact that the following declaration has been made
8 // in runtime.js: 8 // in runtime.js:
9 // var $Array = global.Array; 9 // var $Array = global.Array;
10 10
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 function URIHexCharsToCharCode(highChar, lowChar) { 76 function URIHexCharsToCharCode(highChar, lowChar) {
77 var highCode = HexValueOf(highChar); 77 var highCode = HexValueOf(highChar);
78 var lowCode = HexValueOf(lowChar); 78 var lowCode = HexValueOf(lowChar);
79 if (highCode == -1 || lowCode == -1) { 79 if (highCode == -1 || lowCode == -1) {
80 throw new $URIError("URI malformed"); 80 throw new $URIError("URI malformed");
81 } 81 }
82 return (highCode << 4) | lowCode; 82 return (highCode << 4) | lowCode;
83 } 83 }
84 84
85 85
86 function URIDecodeOctets(octets, result, index) { 86 // Users of this macro must ensure that OCTETS is an array and RESULT is a
87 if (!IS_STRING(result)) throw new $URIError("Internal error"); 87 // sufficiently long two-byte sequential string.
88 // INDEX will be modified as characters are added to RESULT.
89 macro URI_DECODE_OCTETS(OCTETS, RESULT, INDEX)
rossberg 2014/05/21 14:30:15 Let's at least add a comment that explains why thi
88 var value; 90 var value;
89 var o0 = octets[0]; 91 var o0 = OCTETS[0];
90 if (o0 < 0x80) { 92 if (o0 < 0x80) {
91 value = o0; 93 value = o0;
92 } else if (o0 < 0xc2) { 94 } else if (o0 < 0xc2) {
93 throw new $URIError("URI malformed"); 95 throw new $URIError("URI malformed");
94 } else { 96 } else {
95 var o1 = octets[1]; 97 var o1 = OCTETS[1];
96 if (o0 < 0xe0) { 98 if (o0 < 0xe0) {
97 var a = o0 & 0x1f; 99 var a = o0 & 0x1f;
98 if ((o1 < 0x80) || (o1 > 0xbf)) { 100 if ((o1 < 0x80) || (o1 > 0xbf)) {
99 throw new $URIError("URI malformed"); 101 throw new $URIError("URI malformed");
100 } 102 }
101 var b = o1 & 0x3f; 103 var b = o1 & 0x3f;
102 value = (a << 6) + b; 104 value = (a << 6) + b;
103 if (value < 0x80 || value > 0x7ff) { 105 if (value < 0x80 || value > 0x7ff) {
104 throw new $URIError("URI malformed"); 106 throw new $URIError("URI malformed");
105 } 107 }
106 } else { 108 } else {
107 var o2 = octets[2]; 109 var o2 = OCTETS[2];
108 if (o0 < 0xf0) { 110 if (o0 < 0xf0) {
109 var a = o0 & 0x0f; 111 var a = o0 & 0x0f;
110 if ((o1 < 0x80) || (o1 > 0xbf)) { 112 if ((o1 < 0x80) || (o1 > 0xbf)) {
111 throw new $URIError("URI malformed"); 113 throw new $URIError("URI malformed");
112 } 114 }
113 var b = o1 & 0x3f; 115 var b = o1 & 0x3f;
114 if ((o2 < 0x80) || (o2 > 0xbf)) { 116 if ((o2 < 0x80) || (o2 > 0xbf)) {
115 throw new $URIError("URI malformed"); 117 throw new $URIError("URI malformed");
116 } 118 }
117 var c = o2 & 0x3f; 119 var c = o2 & 0x3f;
118 value = (a << 12) + (b << 6) + c; 120 value = (a << 12) + (b << 6) + c;
119 if ((value < 0x800) || (value > 0xffff)) { 121 if ((value < 0x800) || (value > 0xffff)) {
120 throw new $URIError("URI malformed"); 122 throw new $URIError("URI malformed");
121 } 123 }
122 } else { 124 } else {
123 var o3 = octets[3]; 125 var o3 = OCTETS[3];
124 if (o0 < 0xf8) { 126 if (o0 < 0xf8) {
125 var a = (o0 & 0x07); 127 var a = (o0 & 0x07);
126 if ((o1 < 0x80) || (o1 > 0xbf)) { 128 if ((o1 < 0x80) || (o1 > 0xbf)) {
127 throw new $URIError("URI malformed"); 129 throw new $URIError("URI malformed");
128 } 130 }
129 var b = (o1 & 0x3f); 131 var b = (o1 & 0x3f);
130 if ((o2 < 0x80) || (o2 > 0xbf)) { 132 if ((o2 < 0x80) || (o2 > 0xbf)) {
131 throw new $URIError("URI malformed"); 133 throw new $URIError("URI malformed");
132 } 134 }
133 var c = (o2 & 0x3f); 135 var c = (o2 & 0x3f);
134 if ((o3 < 0x80) || (o3 > 0xbf)) { 136 if ((o3 < 0x80) || (o3 > 0xbf)) {
135 throw new $URIError("URI malformed"); 137 throw new $URIError("URI malformed");
136 } 138 }
137 var d = (o3 & 0x3f); 139 var d = (o3 & 0x3f);
138 value = (a << 18) + (b << 12) + (c << 6) + d; 140 value = (a << 18) + (b << 12) + (c << 6) + d;
139 if ((value < 0x10000) || (value > 0x10ffff)) { 141 if ((value < 0x10000) || (value > 0x10ffff)) {
140 throw new $URIError("URI malformed"); 142 throw new $URIError("URI malformed");
141 } 143 }
142 } else { 144 } else {
143 throw new $URIError("URI malformed"); 145 throw new $URIError("URI malformed");
144 } 146 }
145 } 147 }
146 } 148 }
147 } 149 }
148 if (0xD800 <= value && value <= 0xDFFF) { 150 if (0xD800 <= value && value <= 0xDFFF) {
149 throw new $URIError("URI malformed"); 151 throw new $URIError("URI malformed");
150 } 152 }
151 if (value < 0x10000) { 153 if (value < 0x10000) {
152 if (index < 0 || index >= result.length) { 154 %_TwoByteSeqStringSetChar(RESULT, INDEX++, value);
153 throw new $URIError("Internal error");
154 }
155 %_TwoByteSeqStringSetChar(result, index++, value);
156 return index;
157 } else { 155 } else {
158 if (index < 0 || index >= result.length - 1) { 156 %_TwoByteSeqStringSetChar(RESULT, INDEX++, (value >> 10) + 0xd7c0);
159 throw new $URIError("Internal error"); 157 %_TwoByteSeqStringSetChar(RESULT, INDEX++, (value & 0x3ff) + 0xdc00);
160 }
161 %_TwoByteSeqStringSetChar(result, index++, (value >> 10) + 0xd7c0);
162 %_TwoByteSeqStringSetChar(result, index++, (value & 0x3ff) + 0xdc00);
163 return index;
164 } 158 }
165 } 159 endmacro
166 160
167 161
168 // ECMA-262, section 15.1.3 162 // ECMA-262, section 15.1.3
169 function Encode(uri, unescape) { 163 function Encode(uri, unescape) {
170 var uriLength = uri.length; 164 var uriLength = uri.length;
171 var array = new InternalArray(uriLength); 165 var array = new InternalArray(uriLength);
172 var index = 0; 166 var index = 0;
173 for (var k = 0; k < uriLength; k++) { 167 for (var k = 0; k < uriLength; k++) {
174 var cc1 = uri.charCodeAt(k); 168 var cc1 = uri.charCodeAt(k);
175 if (unescape(cc1)) { 169 if (unescape(cc1)) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 while (((cc << ++n) & 0x80) != 0) { } 235 while (((cc << ++n) & 0x80) != 0) { }
242 if (n == 1 || n > 4) throw new $URIError("URI malformed"); 236 if (n == 1 || n > 4) throw new $URIError("URI malformed");
243 var octets = new $Array(n); 237 var octets = new $Array(n);
244 octets[0] = cc; 238 octets[0] = cc;
245 if (k + 3 * (n - 1) >= uriLength) throw new $URIError("URI malformed"); 239 if (k + 3 * (n - 1) >= uriLength) throw new $URIError("URI malformed");
246 for (var i = 1; i < n; i++) { 240 for (var i = 1; i < n; i++) {
247 if (uri.charAt(++k) != '%') throw new $URIError("URI malformed"); 241 if (uri.charAt(++k) != '%') throw new $URIError("URI malformed");
248 octets[i] = URIHexCharsToCharCode(uri.charCodeAt(++k), 242 octets[i] = URIHexCharsToCharCode(uri.charCodeAt(++k),
249 uri.charCodeAt(++k)); 243 uri.charCodeAt(++k));
250 } 244 }
251 index = URIDecodeOctets(octets, two_byte, index); 245 URI_DECODE_OCTETS(octets, two_byte, index);
252 } else if (reserved(cc)) { 246 } else if (reserved(cc)) {
253 %_TwoByteSeqStringSetChar(two_byte, index++, 37); // '%'. 247 %_TwoByteSeqStringSetChar(two_byte, index++, 37); // '%'.
254 %_TwoByteSeqStringSetChar(two_byte, index++, uri.charCodeAt(k - 1)); 248 %_TwoByteSeqStringSetChar(two_byte, index++, uri.charCodeAt(k - 1));
255 %_TwoByteSeqStringSetChar(two_byte, index++, uri.charCodeAt(k)); 249 %_TwoByteSeqStringSetChar(two_byte, index++, uri.charCodeAt(k));
256 } else { 250 } else {
257 %_TwoByteSeqStringSetChar(two_byte, index++, cc); 251 %_TwoByteSeqStringSetChar(two_byte, index++, cc);
258 } 252 }
259 } else { 253 } else {
260 %_TwoByteSeqStringSetChar(two_byte, index++, code); 254 %_TwoByteSeqStringSetChar(two_byte, index++, code);
261 } 255 }
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 "escape", URIEscapeJS, 428 "escape", URIEscapeJS,
435 "unescape", URIUnescapeJS, 429 "unescape", URIUnescapeJS,
436 "decodeURI", URIDecode, 430 "decodeURI", URIDecode,
437 "decodeURIComponent", URIDecodeComponent, 431 "decodeURIComponent", URIDecodeComponent,
438 "encodeURI", URIEncode, 432 "encodeURI", URIEncode,
439 "encodeURIComponent", URIEncodeComponent 433 "encodeURIComponent", URIEncodeComponent
440 )); 434 ));
441 } 435 }
442 436
443 SetUpUri(); 437 SetUpUri();
OLDNEW
« no previous file with comments | « src/promise.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698