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

Side by Side Diff: src/regexp-delay.js

Issue 13088: Follow jsc in throwing an exception when using test or exec on a... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 12 years 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/messages.js ('k') | test/mjsunit/mjsunit.js » ('j') | 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 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 if (matchIndices.length != 0) { 156 if (matchIndices.length != 0) {
157 regExpCaptures = matchIndices[matchIndices.length - 1]; 157 regExpCaptures = matchIndices[matchIndices.length - 1];
158 regExpSubject = regExpInput = string; 158 regExpSubject = regExpInput = string;
159 } 159 }
160 return matchIndices; 160 return matchIndices;
161 } 161 }
162 162
163 163
164 function RegExpExec(string) { 164 function RegExpExec(string) {
165 if (%_ArgumentsLength() == 0) { 165 if (%_ArgumentsLength() == 0) {
166 if (IS_UNDEFINED(regExpInput)) {
167 throw MakeError('no_input_to_regexp', [this]);
168 }
166 string = regExpInput; 169 string = regExpInput;
167 } 170 }
168 var s = ToString(string); 171 var s = ToString(string);
169 var length = s.length; 172 var length = s.length;
170 var lastIndex = this.lastIndex; 173 var lastIndex = this.lastIndex;
171 var i = this.global ? TO_INTEGER(lastIndex) : 0; 174 var i = this.global ? TO_INTEGER(lastIndex) : 0;
172 175
173 if (i < 0 || i > s.length) { 176 if (i < 0 || i > s.length) {
174 this.lastIndex = 0; 177 this.lastIndex = 0;
175 return null; 178 return null;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 279
277 280
278 // Properties of the builtins object for recording the result of the last 281 // Properties of the builtins object for recording the result of the last
279 // regexp match. The property regExpCaptures is the matchIndices array of the 282 // regexp match. The property regExpCaptures is the matchIndices array of the
280 // last successful regexp match (an array of start/end index pairs for the 283 // last successful regexp match (an array of start/end index pairs for the
281 // match and all the captured substrings), the invariant is that there is at 284 // match and all the captured substrings), the invariant is that there is at
282 // least two elements. The property regExpSubject is the subject string for 285 // least two elements. The property regExpSubject is the subject string for
283 // the last successful match. 286 // the last successful match.
284 var regExpCaptures = [0, 0]; 287 var regExpCaptures = [0, 0];
285 var regExpSubject = ''; 288 var regExpSubject = '';
286 var regExpInput = ""; 289 var regExpInput;
287 290
288 // ------------------------------------------------------------------- 291 // -------------------------------------------------------------------
289 292
290 function SetupRegExp() { 293 function SetupRegExp() {
291 %FunctionSetInstanceClassName($RegExp, 'RegExp'); 294 %FunctionSetInstanceClassName($RegExp, 'RegExp');
292 %FunctionSetPrototype($RegExp, new $Object()); 295 %FunctionSetPrototype($RegExp, new $Object());
293 %SetProperty($RegExp.prototype, 'constructor', $RegExp, DONT_ENUM); 296 %SetProperty($RegExp.prototype, 'constructor', $RegExp, DONT_ENUM);
294 %SetCode($RegExp, RegExpConstructor); 297 %SetCode($RegExp, RegExpConstructor);
295 298
296 InstallFunctions($RegExp.prototype, DONT_ENUM, $Array( 299 InstallFunctions($RegExp.prototype, DONT_ENUM, $Array(
297 "exec", RegExpExec, 300 "exec", RegExpExec,
298 "test", RegExpTest, 301 "test", RegExpTest,
299 "toString", RegExpToString, 302 "toString", RegExpToString,
300 "compile", CompileRegExp 303 "compile", CompileRegExp
301 )); 304 ));
302 305
303 // The spec says nothing about the length of exec and test, but 306 // The spec says nothing about the length of exec and test, but
304 // SpiderMonkey and KJS have length equal to 0. 307 // SpiderMonkey and KJS have length equal to 0.
305 %FunctionSetLength($RegExp.prototype.exec, 0); 308 %FunctionSetLength($RegExp.prototype.exec, 0);
306 %FunctionSetLength($RegExp.prototype.test, 0); 309 %FunctionSetLength($RegExp.prototype.test, 0);
307 // The length of compile is 1 in SpiderMonkey. 310 // The length of compile is 1 in SpiderMonkey.
308 %FunctionSetLength($RegExp.prototype.compile, 1); 311 %FunctionSetLength($RegExp.prototype.compile, 1);
309 312
310 // The properties input, $input, and $_ are aliases for each other. When this 313 // The properties input, $input, and $_ are aliases for each other. When this
311 // value is set in SpiderMonkey, the value it is set to is coerced to a 314 // value is set the value it is set to is coerced to a string.
312 // string. We mimic that behavior with a slight difference: in SpiderMonkey
313 // the value of the expression 'RegExp.input = null' (for instance) is the
314 // string "null" (ie, the value after coercion), while in V8 it is the value
315 // null (ie, the value before coercion).
316 // Getter and setter for the input. 315 // Getter and setter for the input.
317 function RegExpGetInput() { return regExpInput; } 316 function RegExpGetInput() {
317 return IS_UNDEFINED(regExpInput) ? "" : regExpInput;
318 }
318 function RegExpSetInput(string) { regExpInput = ToString(string); } 319 function RegExpSetInput(string) { regExpInput = ToString(string); }
319 320
320 %DefineAccessor($RegExp, 'input', GETTER, RegExpGetInput, DONT_DELETE); 321 %DefineAccessor($RegExp, 'input', GETTER, RegExpGetInput, DONT_DELETE);
321 %DefineAccessor($RegExp, 'input', SETTER, RegExpSetInput, DONT_DELETE); 322 %DefineAccessor($RegExp, 'input', SETTER, RegExpSetInput, DONT_DELETE);
322 %DefineAccessor($RegExp, '$_', GETTER, RegExpGetInput, DONT_ENUM | DONT_DELETE ); 323 %DefineAccessor($RegExp, '$_', GETTER, RegExpGetInput, DONT_ENUM | DONT_DELETE );
323 %DefineAccessor($RegExp, '$_', SETTER, RegExpSetInput, DONT_ENUM | DONT_DELETE ); 324 %DefineAccessor($RegExp, '$_', SETTER, RegExpSetInput, DONT_ENUM | DONT_DELETE );
324 %DefineAccessor($RegExp, '$input', GETTER, RegExpGetInput, DONT_ENUM | DONT_DE LETE); 325 %DefineAccessor($RegExp, '$input', GETTER, RegExpGetInput, DONT_ENUM | DONT_DE LETE);
325 %DefineAccessor($RegExp, '$input', SETTER, RegExpSetInput, DONT_ENUM | DONT_DE LETE); 326 %DefineAccessor($RegExp, '$input', SETTER, RegExpSetInput, DONT_ENUM | DONT_DE LETE);
326 327
327 // The properties multiline and $* are aliases for each other. When this 328 // The properties multiline and $* are aliases for each other. When this
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 %DefineAccessor($RegExp, "$'", SETTER, NoOpSetter, DONT_ENUM | DONT_DELETE); 365 %DefineAccessor($RegExp, "$'", SETTER, NoOpSetter, DONT_ENUM | DONT_DELETE);
365 366
366 for (var i = 1; i < 10; ++i) { 367 for (var i = 1; i < 10; ++i) {
367 %DefineAccessor($RegExp, '$' + i, GETTER, RegExpMakeCaptureGetter(i), DONT_D ELETE); 368 %DefineAccessor($RegExp, '$' + i, GETTER, RegExpMakeCaptureGetter(i), DONT_D ELETE);
368 %DefineAccessor($RegExp, '$' + i, SETTER, NoOpSetter, DONT_DELETE); 369 %DefineAccessor($RegExp, '$' + i, SETTER, NoOpSetter, DONT_DELETE);
369 } 370 }
370 } 371 }
371 372
372 373
373 SetupRegExp(); 374 SetupRegExp();
OLDNEW
« no previous file with comments | « src/messages.js ('k') | test/mjsunit/mjsunit.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698