Make the runtime entry for setting/changing accessors "atomic".
Previously, there were 1 or 2 calls to the runtime when accessors were changed
or set. This doesn't really work well with property attributes, leading to some
hacks and complicates things even further when trying to share maps in presence
of accessors. Therefore, the runtime entry now takes the full triple (getter,
setter, attributes), where the getter and/or the setter can be null in case they
shouldn't be changed.
For now, we do basically the same on the native side as we did before on the
JavaScript side, but this will change in future CLs, the current CL is already
large enough.
Note that object literals with a getter and a setter for the same property still
do 2 calls, but this is a little bit more tricky to fix and will be handled in a
separate CL.
Review URL: https://chromiumcodereview.appspot.com/9616016
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@10956 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2012-03-07 13:24:44 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
2014-04-29 06:42:26 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-04-11 12:15:25 +00:00
|
|
|
// This file relies on the fact that the following declaration has been made
|
|
|
|
// in runtime.js:
|
|
|
|
// var $Object = global.Object;
|
|
|
|
// var $Array = global.Array;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-02-20 13:48:24 +00:00
|
|
|
var $RegExp = global.RegExp;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-04-11 12:15:25 +00:00
|
|
|
// -------------------------------------------------------------------
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// A recursive descent parser for Patterns according to the grammar of
|
|
|
|
// ECMA-262 15.10.1, with deviations noted below.
|
2010-12-17 11:57:10 +00:00
|
|
|
function DoConstructRegExp(object, pattern, flags) {
|
2008-07-03 15:10:15 +00:00
|
|
|
// RegExp : Called as constructor; see ECMA-262, section 15.10.4.
|
|
|
|
if (IS_REGEXP(pattern)) {
|
|
|
|
if (!IS_UNDEFINED(flags)) {
|
|
|
|
throw MakeTypeError('regexp_flags', []);
|
|
|
|
}
|
|
|
|
flags = (pattern.global ? 'g' : '')
|
|
|
|
+ (pattern.ignoreCase ? 'i' : '')
|
|
|
|
+ (pattern.multiline ? 'm' : '');
|
|
|
|
pattern = pattern.source;
|
|
|
|
}
|
|
|
|
|
|
|
|
pattern = IS_UNDEFINED(pattern) ? '' : ToString(pattern);
|
|
|
|
flags = IS_UNDEFINED(flags) ? '' : ToString(flags);
|
|
|
|
|
|
|
|
var global = false;
|
|
|
|
var ignoreCase = false;
|
|
|
|
var multiline = false;
|
|
|
|
for (var i = 0; i < flags.length; i++) {
|
2011-01-28 10:33:10 +00:00
|
|
|
var c = %_CallFunction(flags, i, StringCharAt);
|
2008-07-03 15:10:15 +00:00
|
|
|
switch (c) {
|
|
|
|
case 'g':
|
2011-08-19 11:02:41 +00:00
|
|
|
if (global) {
|
|
|
|
throw MakeSyntaxError("invalid_regexp_flags", [flags]);
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
global = true;
|
|
|
|
break;
|
|
|
|
case 'i':
|
2011-08-19 11:02:41 +00:00
|
|
|
if (ignoreCase) {
|
|
|
|
throw MakeSyntaxError("invalid_regexp_flags", [flags]);
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
ignoreCase = true;
|
|
|
|
break;
|
|
|
|
case 'm':
|
2011-08-19 11:02:41 +00:00
|
|
|
if (multiline) {
|
|
|
|
throw MakeSyntaxError("invalid_regexp_flags", [flags]);
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
multiline = true;
|
|
|
|
break;
|
|
|
|
default:
|
2011-08-19 11:02:41 +00:00
|
|
|
throw MakeSyntaxError("invalid_regexp_flags", [flags]);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-26 14:19:47 +00:00
|
|
|
%RegExpInitializeObject(object, pattern, global, ignoreCase, multiline);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Call internal function to compile the pattern.
|
|
|
|
%RegExpCompile(object, pattern, flags);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
function RegExpConstructor(pattern, flags) {
|
2009-06-29 08:14:06 +00:00
|
|
|
if (%_IsConstructCall()) {
|
2010-12-17 11:57:10 +00:00
|
|
|
DoConstructRegExp(this, pattern, flags);
|
2008-07-03 15:10:15 +00:00
|
|
|
} else {
|
|
|
|
// RegExp : Called as function; see ECMA-262, section 15.10.3.1.
|
|
|
|
if (IS_REGEXP(pattern) && IS_UNDEFINED(flags)) {
|
|
|
|
return pattern;
|
|
|
|
}
|
|
|
|
return new $RegExp(pattern, flags);
|
|
|
|
}
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Deprecated RegExp.prototype.compile method. We behave like the constructor
|
|
|
|
// were called again. In SpiderMonkey, this method returns the regexp object.
|
2009-03-11 14:00:55 +00:00
|
|
|
// In JSC, it returns undefined. For compatibility with JSC, we match their
|
2008-07-03 15:10:15 +00:00
|
|
|
// behavior.
|
2011-09-26 08:42:01 +00:00
|
|
|
function RegExpCompile(pattern, flags) {
|
2009-03-11 14:00:55 +00:00
|
|
|
// Both JSC and SpiderMonkey treat a missing pattern argument as the
|
2008-07-03 15:10:15 +00:00
|
|
|
// empty subject string, and an actual undefined value passed as the
|
2009-03-11 14:00:55 +00:00
|
|
|
// pattern as the string 'undefined'. Note that JSC is inconsistent
|
2008-07-03 15:10:15 +00:00
|
|
|
// here, treating undefined values differently in
|
|
|
|
// RegExp.prototype.compile and in the constructor, where they are
|
2009-03-11 14:00:55 +00:00
|
|
|
// the empty string. For compatibility with JSC, we match their
|
2008-07-03 15:10:15 +00:00
|
|
|
// behavior.
|
2011-09-26 08:42:01 +00:00
|
|
|
if (this == $RegExp.prototype) {
|
|
|
|
// We don't allow recompiling RegExp.prototype.
|
|
|
|
throw MakeTypeError('incompatible_method_receiver',
|
|
|
|
['RegExp.prototype.compile', this]);
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
if (IS_UNDEFINED(pattern) && %_ArgumentsLength() != 0) {
|
2010-12-17 11:57:10 +00:00
|
|
|
DoConstructRegExp(this, 'undefined', flags);
|
2008-07-03 15:10:15 +00:00
|
|
|
} else {
|
2010-12-17 11:57:10 +00:00
|
|
|
DoConstructRegExp(this, pattern, flags);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function DoRegExpExec(regexp, string, index) {
|
2010-04-21 08:33:04 +00:00
|
|
|
var result = %_RegExpExec(regexp, string, index, lastMatchInfo);
|
|
|
|
if (result !== null) lastMatchInfoOverride = null;
|
|
|
|
return result;
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-04-13 09:31:03 +00:00
|
|
|
function BuildResultFromMatchInfo(lastMatchInfo, s) {
|
|
|
|
var numResults = NUMBER_OF_CAPTURES(lastMatchInfo) >> 1;
|
2010-12-13 12:19:10 +00:00
|
|
|
var start = lastMatchInfo[CAPTURE0];
|
|
|
|
var end = lastMatchInfo[CAPTURE1];
|
|
|
|
var result = %_RegExpConstructResult(numResults, start, s);
|
2013-02-20 14:29:40 +00:00
|
|
|
result[0] = %_SubString(s, start, end);
|
2010-12-13 12:19:10 +00:00
|
|
|
var j = REGEXP_FIRST_CAPTURE + 2;
|
|
|
|
for (var i = 1; i < numResults; i++) {
|
|
|
|
start = lastMatchInfo[j++];
|
2012-09-14 12:01:12 +00:00
|
|
|
if (start != -1) {
|
|
|
|
end = lastMatchInfo[j];
|
2013-02-20 14:29:40 +00:00
|
|
|
result[i] = %_SubString(s, start, end);
|
2010-04-13 09:31:03 +00:00
|
|
|
}
|
2012-09-14 12:01:12 +00:00
|
|
|
j++;
|
2010-04-13 09:31:03 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function RegExpExecNoTests(regexp, string, start) {
|
|
|
|
// Must be called with RegExp, string and positive integer as arguments.
|
2010-12-17 11:57:10 +00:00
|
|
|
var matchInfo = %_RegExpExec(regexp, string, start, lastMatchInfo);
|
2010-04-13 09:31:03 +00:00
|
|
|
if (matchInfo !== null) {
|
2010-12-17 11:57:10 +00:00
|
|
|
lastMatchInfoOverride = null;
|
|
|
|
return BuildResultFromMatchInfo(matchInfo, string);
|
2010-04-13 09:31:03 +00:00
|
|
|
}
|
2012-12-05 12:32:25 +00:00
|
|
|
regexp.lastIndex = 0;
|
2010-12-17 11:57:10 +00:00
|
|
|
return null;
|
2010-04-13 09:31:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
function RegExpExec(string) {
|
2010-03-17 10:23:06 +00:00
|
|
|
if (!IS_REGEXP(this)) {
|
|
|
|
throw MakeTypeError('incompatible_method_receiver',
|
|
|
|
['RegExp.prototype.exec', this]);
|
|
|
|
}
|
|
|
|
|
2010-12-13 12:19:10 +00:00
|
|
|
string = TO_STRING_INLINE(string);
|
2010-11-02 13:37:59 +00:00
|
|
|
var lastIndex = this.lastIndex;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-10-14 12:54:00 +00:00
|
|
|
// Conversion is required by the ES5 specification (RegExp.prototype.exec
|
|
|
|
// algorithm, step 5) even if the value is discarded for non-global RegExps.
|
|
|
|
var i = TO_INTEGER(lastIndex);
|
2010-11-02 13:37:59 +00:00
|
|
|
|
|
|
|
var global = this.global;
|
2010-10-14 12:54:00 +00:00
|
|
|
if (global) {
|
2010-12-13 12:19:10 +00:00
|
|
|
if (i < 0 || i > string.length) {
|
2010-10-14 12:54:00 +00:00
|
|
|
this.lastIndex = 0;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
i = 0;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2009-03-11 14:00:55 +00:00
|
|
|
// matchIndices is either null or the lastMatchInfo array.
|
2010-12-13 12:19:10 +00:00
|
|
|
var matchIndices = %_RegExpExec(this, string, i, lastMatchInfo);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-10-17 10:02:45 +00:00
|
|
|
if (IS_NULL(matchIndices)) {
|
2012-12-05 12:32:25 +00:00
|
|
|
this.lastIndex = 0;
|
2010-11-02 13:37:59 +00:00
|
|
|
return null;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2010-10-14 12:54:00 +00:00
|
|
|
|
|
|
|
// Successful match.
|
2010-04-21 08:33:04 +00:00
|
|
|
lastMatchInfoOverride = null;
|
2010-10-14 12:54:00 +00:00
|
|
|
if (global) {
|
2010-03-10 12:21:00 +00:00
|
|
|
this.lastIndex = lastMatchInfo[CAPTURE1];
|
|
|
|
}
|
2010-12-13 12:19:10 +00:00
|
|
|
return BuildResultFromMatchInfo(matchIndices, string);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2010-06-04 11:58:40 +00:00
|
|
|
// One-element cache for the simplified test regexp.
|
|
|
|
var regexp_key;
|
|
|
|
var regexp_val;
|
|
|
|
|
2009-03-11 14:00:55 +00:00
|
|
|
// Section 15.10.6.3 doesn't actually make sense, but the intention seems to be
|
2009-03-13 10:22:38 +00:00
|
|
|
// that test is defined in terms of String.prototype.exec. However, it probably
|
|
|
|
// means the original value of String.prototype.exec, which is what everybody
|
|
|
|
// else implements.
|
2008-07-03 15:10:15 +00:00
|
|
|
function RegExpTest(string) {
|
2009-03-11 14:00:55 +00:00
|
|
|
if (!IS_REGEXP(this)) {
|
2010-02-26 15:46:57 +00:00
|
|
|
throw MakeTypeError('incompatible_method_receiver',
|
2009-03-11 14:00:55 +00:00
|
|
|
['RegExp.prototype.test', this]);
|
|
|
|
}
|
2010-12-13 12:19:10 +00:00
|
|
|
string = TO_STRING_INLINE(string);
|
2010-10-14 12:54:00 +00:00
|
|
|
|
2010-11-02 13:37:59 +00:00
|
|
|
var lastIndex = this.lastIndex;
|
|
|
|
|
2010-10-14 12:54:00 +00:00
|
|
|
// Conversion is required by the ES5 specification (RegExp.prototype.exec
|
|
|
|
// algorithm, step 5) even if the value is discarded for non-global RegExps.
|
|
|
|
var i = TO_INTEGER(lastIndex);
|
2011-07-05 06:19:53 +00:00
|
|
|
|
2010-11-11 08:47:30 +00:00
|
|
|
if (this.global) {
|
2010-12-13 12:19:10 +00:00
|
|
|
if (i < 0 || i > string.length) {
|
2010-10-14 12:54:00 +00:00
|
|
|
this.lastIndex = 0;
|
|
|
|
return false;
|
|
|
|
}
|
2010-11-11 08:47:30 +00:00
|
|
|
// matchIndices is either null or the lastMatchInfo array.
|
2010-12-13 12:19:10 +00:00
|
|
|
var matchIndices = %_RegExpExec(this, string, i, lastMatchInfo);
|
2013-10-17 10:02:45 +00:00
|
|
|
if (IS_NULL(matchIndices)) {
|
2010-11-11 08:47:30 +00:00
|
|
|
this.lastIndex = 0;
|
|
|
|
return false;
|
2010-06-04 11:58:40 +00:00
|
|
|
}
|
2010-11-11 08:47:30 +00:00
|
|
|
lastMatchInfoOverride = null;
|
|
|
|
this.lastIndex = lastMatchInfo[CAPTURE1];
|
2011-07-05 06:19:53 +00:00
|
|
|
return true;
|
2010-11-11 08:47:30 +00:00
|
|
|
} else {
|
|
|
|
// Non-global regexp.
|
2011-07-05 06:19:53 +00:00
|
|
|
// Remove irrelevant preceeding '.*' in a non-global test regexp.
|
|
|
|
// The expression checks whether this.source starts with '.*' and
|
2010-11-11 08:47:30 +00:00
|
|
|
// that the third char is not a '?'.
|
2012-03-15 17:21:42 +00:00
|
|
|
var regexp = this;
|
|
|
|
if (%_StringCharCodeAt(regexp.source, 0) == 46 && // '.'
|
|
|
|
%_StringCharCodeAt(regexp.source, 1) == 42 && // '*'
|
|
|
|
%_StringCharCodeAt(regexp.source, 2) != 63) { // '?'
|
|
|
|
regexp = TrimRegExp(regexp);
|
2011-07-05 06:19:53 +00:00
|
|
|
}
|
2010-11-11 08:47:30 +00:00
|
|
|
// matchIndices is either null or the lastMatchInfo array.
|
2012-03-15 17:21:42 +00:00
|
|
|
var matchIndices = %_RegExpExec(regexp, string, 0, lastMatchInfo);
|
2013-10-17 10:02:45 +00:00
|
|
|
if (IS_NULL(matchIndices)) {
|
2012-12-05 12:32:25 +00:00
|
|
|
this.lastIndex = 0;
|
|
|
|
return false;
|
|
|
|
}
|
2010-11-11 08:47:30 +00:00
|
|
|
lastMatchInfoOverride = null;
|
|
|
|
return true;
|
2010-10-14 12:54:00 +00:00
|
|
|
}
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-03-15 17:21:42 +00:00
|
|
|
function TrimRegExp(regexp) {
|
|
|
|
if (!%_ObjectEquals(regexp_key, regexp)) {
|
|
|
|
regexp_key = regexp;
|
|
|
|
regexp_val =
|
2013-02-20 14:29:40 +00:00
|
|
|
new $RegExp(%_SubString(regexp.source, 2, regexp.source.length),
|
2012-03-15 17:21:42 +00:00
|
|
|
(regexp.ignoreCase ? regexp.multiline ? "im" : "i"
|
|
|
|
: regexp.multiline ? "m" : ""));
|
|
|
|
}
|
|
|
|
return regexp_val;
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
function RegExpToString() {
|
2012-05-23 20:48:08 +00:00
|
|
|
if (!IS_REGEXP(this)) {
|
|
|
|
throw MakeTypeError('incompatible_method_receiver',
|
|
|
|
['RegExp.prototype.toString', this]);
|
|
|
|
}
|
2012-04-23 13:59:43 +00:00
|
|
|
var result = '/' + this.source + '/';
|
2010-10-14 12:54:00 +00:00
|
|
|
if (this.global) result += 'g';
|
|
|
|
if (this.ignoreCase) result += 'i';
|
|
|
|
if (this.multiline) result += 'm';
|
2008-07-03 15:10:15 +00:00
|
|
|
return result;
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Getters for the static properties lastMatch, lastParen, leftContext, and
|
|
|
|
// rightContext of the RegExp constructor. The properties are computed based
|
|
|
|
// on the captures array of the last successful match and the subject string
|
|
|
|
// of the last successful match.
|
|
|
|
function RegExpGetLastMatch() {
|
2010-04-21 08:33:04 +00:00
|
|
|
if (lastMatchInfoOverride !== null) {
|
2012-04-13 11:03:22 +00:00
|
|
|
return OVERRIDE_MATCH(lastMatchInfoOverride);
|
2010-04-21 08:33:04 +00:00
|
|
|
}
|
2009-03-11 14:00:55 +00:00
|
|
|
var regExpSubject = LAST_SUBJECT(lastMatchInfo);
|
2013-02-20 14:29:40 +00:00
|
|
|
return %_SubString(regExpSubject,
|
|
|
|
lastMatchInfo[CAPTURE0],
|
|
|
|
lastMatchInfo[CAPTURE1]);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
function RegExpGetLastParen() {
|
2010-03-25 12:57:58 +00:00
|
|
|
if (lastMatchInfoOverride) {
|
|
|
|
var override = lastMatchInfoOverride;
|
2010-03-30 07:15:23 +00:00
|
|
|
if (override.length <= 3) return '';
|
2010-03-25 12:57:58 +00:00
|
|
|
return override[override.length - 3];
|
|
|
|
}
|
2009-03-11 14:00:55 +00:00
|
|
|
var length = NUMBER_OF_CAPTURES(lastMatchInfo);
|
|
|
|
if (length <= 2) return ''; // There were no captures.
|
2008-07-03 15:10:15 +00:00
|
|
|
// We match the SpiderMonkey behavior: return the substring defined by the
|
|
|
|
// last pair (after the first pair) of elements of the capture array even if
|
|
|
|
// it is empty.
|
2009-03-11 14:00:55 +00:00
|
|
|
var regExpSubject = LAST_SUBJECT(lastMatchInfo);
|
|
|
|
var start = lastMatchInfo[CAPTURE(length - 2)];
|
|
|
|
var end = lastMatchInfo[CAPTURE(length - 1)];
|
|
|
|
if (start != -1 && end != -1) {
|
2013-02-20 14:29:40 +00:00
|
|
|
return %_SubString(regExpSubject, start, end);
|
2009-03-11 14:00:55 +00:00
|
|
|
}
|
|
|
|
return "";
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
function RegExpGetLeftContext() {
|
2010-03-25 12:57:58 +00:00
|
|
|
var start_index;
|
|
|
|
var subject;
|
|
|
|
if (!lastMatchInfoOverride) {
|
|
|
|
start_index = lastMatchInfo[CAPTURE0];
|
|
|
|
subject = LAST_SUBJECT(lastMatchInfo);
|
|
|
|
} else {
|
|
|
|
var override = lastMatchInfoOverride;
|
2012-04-13 11:03:22 +00:00
|
|
|
start_index = OVERRIDE_POS(override);
|
|
|
|
subject = OVERRIDE_SUBJECT(override);
|
2010-03-25 12:57:58 +00:00
|
|
|
}
|
2013-02-20 14:29:40 +00:00
|
|
|
return %_SubString(subject, 0, start_index);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
function RegExpGetRightContext() {
|
2010-03-25 12:57:58 +00:00
|
|
|
var start_index;
|
|
|
|
var subject;
|
|
|
|
if (!lastMatchInfoOverride) {
|
|
|
|
start_index = lastMatchInfo[CAPTURE1];
|
|
|
|
subject = LAST_SUBJECT(lastMatchInfo);
|
|
|
|
} else {
|
|
|
|
var override = lastMatchInfoOverride;
|
2012-04-13 11:03:22 +00:00
|
|
|
subject = OVERRIDE_SUBJECT(override);
|
|
|
|
var match = OVERRIDE_MATCH(override);
|
|
|
|
start_index = OVERRIDE_POS(override) + match.length;
|
2010-03-25 12:57:58 +00:00
|
|
|
}
|
2013-02-20 14:29:40 +00:00
|
|
|
return %_SubString(subject, start_index, subject.length);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// The properties $1..$9 are the first nine capturing substrings of the last
|
|
|
|
// successful match, or ''. The function RegExpMakeCaptureGetter will be
|
2009-03-17 12:44:20 +00:00
|
|
|
// called with indices from 1 to 9.
|
2008-07-03 15:10:15 +00:00
|
|
|
function RegExpMakeCaptureGetter(n) {
|
|
|
|
return function() {
|
2010-03-25 12:57:58 +00:00
|
|
|
if (lastMatchInfoOverride) {
|
2012-04-13 11:03:22 +00:00
|
|
|
if (n < lastMatchInfoOverride.length - 2) {
|
|
|
|
return OVERRIDE_CAPTURE(lastMatchInfoOverride, n);
|
|
|
|
}
|
2010-03-25 12:57:58 +00:00
|
|
|
return '';
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
var index = n * 2;
|
2009-03-11 14:00:55 +00:00
|
|
|
if (index >= NUMBER_OF_CAPTURES(lastMatchInfo)) return '';
|
|
|
|
var matchStart = lastMatchInfo[CAPTURE(index)];
|
|
|
|
var matchEnd = lastMatchInfo[CAPTURE(index + 1)];
|
2008-07-03 15:10:15 +00:00
|
|
|
if (matchStart == -1 || matchEnd == -1) return '';
|
2013-02-20 14:29:40 +00:00
|
|
|
return %_SubString(LAST_SUBJECT(lastMatchInfo), matchStart, matchEnd);
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2009-03-11 14:00:55 +00:00
|
|
|
// Property of the builtins object for recording the result of the last
|
|
|
|
// regexp match. The property lastMatchInfo includes the matchIndices
|
|
|
|
// array of the last successful regexp match (an array of start/end index
|
|
|
|
// pairs for the match and all the captured substrings), the invariant is
|
|
|
|
// that there are at least two capture indeces. The array also contains
|
|
|
|
// the subject string for the last successful match.
|
2013-02-15 15:20:05 +00:00
|
|
|
var lastMatchInfo = new InternalPackedArray(
|
2009-03-11 14:00:55 +00:00
|
|
|
2, // REGEXP_NUMBER_OF_CAPTURES
|
|
|
|
"", // Last subject.
|
2013-10-17 10:02:45 +00:00
|
|
|
UNDEFINED, // Last input - settable with RegExpSetInput.
|
2009-03-17 12:44:20 +00:00
|
|
|
0, // REGEXP_FIRST_CAPTURE + 0
|
2011-03-03 11:49:03 +00:00
|
|
|
0 // REGEXP_FIRST_CAPTURE + 1
|
|
|
|
);
|
2008-10-03 07:14:31 +00:00
|
|
|
|
2010-03-25 12:57:58 +00:00
|
|
|
// Override last match info with an array of actual substrings.
|
|
|
|
// Used internally by replace regexp with function.
|
2010-03-30 07:15:23 +00:00
|
|
|
// The array has the format of an "apply" argument for a replacement
|
|
|
|
// function.
|
2010-03-25 12:57:58 +00:00
|
|
|
var lastMatchInfoOverride = null;
|
|
|
|
|
2008-10-03 07:14:31 +00:00
|
|
|
// -------------------------------------------------------------------
|
|
|
|
|
2011-09-05 07:30:35 +00:00
|
|
|
function SetUpRegExp() {
|
|
|
|
%CheckIsBootstrapping();
|
2008-10-03 07:14:31 +00:00
|
|
|
%FunctionSetInstanceClassName($RegExp, 'RegExp');
|
2008-10-03 12:14:29 +00:00
|
|
|
%SetProperty($RegExp.prototype, 'constructor', $RegExp, DONT_ENUM);
|
2008-10-03 07:14:31 +00:00
|
|
|
%SetCode($RegExp, RegExpConstructor);
|
|
|
|
|
|
|
|
InstallFunctions($RegExp.prototype, DONT_ENUM, $Array(
|
|
|
|
"exec", RegExpExec,
|
|
|
|
"test", RegExpTest,
|
|
|
|
"toString", RegExpToString,
|
2011-09-26 08:42:01 +00:00
|
|
|
"compile", RegExpCompile
|
2008-10-03 07:14:31 +00:00
|
|
|
));
|
|
|
|
|
|
|
|
// The length of compile is 1 in SpiderMonkey.
|
|
|
|
%FunctionSetLength($RegExp.prototype.compile, 1);
|
|
|
|
|
|
|
|
// The properties input, $input, and $_ are aliases for each other. When this
|
2010-03-30 07:15:23 +00:00
|
|
|
// value is set the value it is set to is coerced to a string.
|
2008-10-03 07:14:31 +00:00
|
|
|
// Getter and setter for the input.
|
2012-02-20 13:48:24 +00:00
|
|
|
var RegExpGetInput = function() {
|
2009-03-11 14:00:55 +00:00
|
|
|
var regExpInput = LAST_INPUT(lastMatchInfo);
|
2008-12-03 12:47:21 +00:00
|
|
|
return IS_UNDEFINED(regExpInput) ? "" : regExpInput;
|
2012-02-20 13:48:24 +00:00
|
|
|
};
|
|
|
|
var RegExpSetInput = function(string) {
|
2009-03-17 12:44:20 +00:00
|
|
|
LAST_INPUT(lastMatchInfo) = ToString(string);
|
2012-02-20 13:48:24 +00:00
|
|
|
};
|
2008-10-03 07:14:31 +00:00
|
|
|
|
2012-05-25 12:32:02 +00:00
|
|
|
%OptimizeObjectForAddingMultipleProperties($RegExp, 22);
|
Make the runtime entry for setting/changing accessors "atomic".
Previously, there were 1 or 2 calls to the runtime when accessors were changed
or set. This doesn't really work well with property attributes, leading to some
hacks and complicates things even further when trying to share maps in presence
of accessors. Therefore, the runtime entry now takes the full triple (getter,
setter, attributes), where the getter and/or the setter can be null in case they
shouldn't be changed.
For now, we do basically the same on the native side as we did before on the
JavaScript side, but this will change in future CLs, the current CL is already
large enough.
Note that object literals with a getter and a setter for the same property still
do 2 calls, but this is a little bit more tricky to fix and will be handled in a
separate CL.
Review URL: https://chromiumcodereview.appspot.com/9616016
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@10956 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2012-03-07 13:24:44 +00:00
|
|
|
%DefineOrRedefineAccessorProperty($RegExp, 'input', RegExpGetInput,
|
|
|
|
RegExpSetInput, DONT_DELETE);
|
|
|
|
%DefineOrRedefineAccessorProperty($RegExp, '$_', RegExpGetInput,
|
|
|
|
RegExpSetInput, DONT_ENUM | DONT_DELETE);
|
|
|
|
%DefineOrRedefineAccessorProperty($RegExp, '$input', RegExpGetInput,
|
|
|
|
RegExpSetInput, DONT_ENUM | DONT_DELETE);
|
2008-10-03 07:14:31 +00:00
|
|
|
|
|
|
|
// The properties multiline and $* are aliases for each other. When this
|
|
|
|
// value is set in SpiderMonkey, the value it is set to is coerced to a
|
|
|
|
// boolean. We mimic that behavior with a slight difference: in SpiderMonkey
|
|
|
|
// the value of the expression 'RegExp.multiline = null' (for instance) is the
|
2012-01-16 12:38:59 +00:00
|
|
|
// boolean false (i.e., the value after coercion), while in V8 it is the value
|
|
|
|
// null (i.e., the value before coercion).
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Getter and setter for multiline.
|
|
|
|
var multiline = false;
|
2012-02-20 13:48:24 +00:00
|
|
|
var RegExpGetMultiline = function() { return multiline; };
|
|
|
|
var RegExpSetMultiline = function(flag) { multiline = flag ? true : false; };
|
2008-07-03 15:10:15 +00:00
|
|
|
|
Make the runtime entry for setting/changing accessors "atomic".
Previously, there were 1 or 2 calls to the runtime when accessors were changed
or set. This doesn't really work well with property attributes, leading to some
hacks and complicates things even further when trying to share maps in presence
of accessors. Therefore, the runtime entry now takes the full triple (getter,
setter, attributes), where the getter and/or the setter can be null in case they
shouldn't be changed.
For now, we do basically the same on the native side as we did before on the
JavaScript side, but this will change in future CLs, the current CL is already
large enough.
Note that object literals with a getter and a setter for the same property still
do 2 calls, but this is a little bit more tricky to fix and will be handled in a
separate CL.
Review URL: https://chromiumcodereview.appspot.com/9616016
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@10956 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2012-03-07 13:24:44 +00:00
|
|
|
%DefineOrRedefineAccessorProperty($RegExp, 'multiline', RegExpGetMultiline,
|
2012-02-21 12:47:27 +00:00
|
|
|
RegExpSetMultiline, DONT_DELETE);
|
Make the runtime entry for setting/changing accessors "atomic".
Previously, there were 1 or 2 calls to the runtime when accessors were changed
or set. This doesn't really work well with property attributes, leading to some
hacks and complicates things even further when trying to share maps in presence
of accessors. Therefore, the runtime entry now takes the full triple (getter,
setter, attributes), where the getter and/or the setter can be null in case they
shouldn't be changed.
For now, we do basically the same on the native side as we did before on the
JavaScript side, but this will change in future CLs, the current CL is already
large enough.
Note that object literals with a getter and a setter for the same property still
do 2 calls, but this is a little bit more tricky to fix and will be handled in a
separate CL.
Review URL: https://chromiumcodereview.appspot.com/9616016
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@10956 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2012-03-07 13:24:44 +00:00
|
|
|
%DefineOrRedefineAccessorProperty($RegExp, '$*', RegExpGetMultiline,
|
|
|
|
RegExpSetMultiline,
|
2012-02-21 12:47:27 +00:00
|
|
|
DONT_ENUM | DONT_DELETE);
|
2008-10-03 07:14:31 +00:00
|
|
|
|
|
|
|
|
2012-02-20 13:48:24 +00:00
|
|
|
var NoOpSetter = function(ignored) {};
|
2008-10-03 07:14:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Static properties set by a successful match.
|
Make the runtime entry for setting/changing accessors "atomic".
Previously, there were 1 or 2 calls to the runtime when accessors were changed
or set. This doesn't really work well with property attributes, leading to some
hacks and complicates things even further when trying to share maps in presence
of accessors. Therefore, the runtime entry now takes the full triple (getter,
setter, attributes), where the getter and/or the setter can be null in case they
shouldn't be changed.
For now, we do basically the same on the native side as we did before on the
JavaScript side, but this will change in future CLs, the current CL is already
large enough.
Note that object literals with a getter and a setter for the same property still
do 2 calls, but this is a little bit more tricky to fix and will be handled in a
separate CL.
Review URL: https://chromiumcodereview.appspot.com/9616016
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@10956 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2012-03-07 13:24:44 +00:00
|
|
|
%DefineOrRedefineAccessorProperty($RegExp, 'lastMatch', RegExpGetLastMatch,
|
|
|
|
NoOpSetter, DONT_DELETE);
|
|
|
|
%DefineOrRedefineAccessorProperty($RegExp, '$&', RegExpGetLastMatch,
|
|
|
|
NoOpSetter, DONT_ENUM | DONT_DELETE);
|
|
|
|
%DefineOrRedefineAccessorProperty($RegExp, 'lastParen', RegExpGetLastParen,
|
|
|
|
NoOpSetter, DONT_DELETE);
|
|
|
|
%DefineOrRedefineAccessorProperty($RegExp, '$+', RegExpGetLastParen,
|
|
|
|
NoOpSetter, DONT_ENUM | DONT_DELETE);
|
|
|
|
%DefineOrRedefineAccessorProperty($RegExp, 'leftContext',
|
|
|
|
RegExpGetLeftContext, NoOpSetter,
|
2012-02-21 12:47:27 +00:00
|
|
|
DONT_DELETE);
|
Make the runtime entry for setting/changing accessors "atomic".
Previously, there were 1 or 2 calls to the runtime when accessors were changed
or set. This doesn't really work well with property attributes, leading to some
hacks and complicates things even further when trying to share maps in presence
of accessors. Therefore, the runtime entry now takes the full triple (getter,
setter, attributes), where the getter and/or the setter can be null in case they
shouldn't be changed.
For now, we do basically the same on the native side as we did before on the
JavaScript side, but this will change in future CLs, the current CL is already
large enough.
Note that object literals with a getter and a setter for the same property still
do 2 calls, but this is a little bit more tricky to fix and will be handled in a
separate CL.
Review URL: https://chromiumcodereview.appspot.com/9616016
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@10956 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2012-03-07 13:24:44 +00:00
|
|
|
%DefineOrRedefineAccessorProperty($RegExp, '$`', RegExpGetLeftContext,
|
|
|
|
NoOpSetter, DONT_ENUM | DONT_DELETE);
|
|
|
|
%DefineOrRedefineAccessorProperty($RegExp, 'rightContext',
|
|
|
|
RegExpGetRightContext, NoOpSetter,
|
2012-02-21 12:47:27 +00:00
|
|
|
DONT_DELETE);
|
Make the runtime entry for setting/changing accessors "atomic".
Previously, there were 1 or 2 calls to the runtime when accessors were changed
or set. This doesn't really work well with property attributes, leading to some
hacks and complicates things even further when trying to share maps in presence
of accessors. Therefore, the runtime entry now takes the full triple (getter,
setter, attributes), where the getter and/or the setter can be null in case they
shouldn't be changed.
For now, we do basically the same on the native side as we did before on the
JavaScript side, but this will change in future CLs, the current CL is already
large enough.
Note that object literals with a getter and a setter for the same property still
do 2 calls, but this is a little bit more tricky to fix and will be handled in a
separate CL.
Review URL: https://chromiumcodereview.appspot.com/9616016
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@10956 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2012-03-07 13:24:44 +00:00
|
|
|
%DefineOrRedefineAccessorProperty($RegExp, "$'", RegExpGetRightContext,
|
|
|
|
NoOpSetter, DONT_ENUM | DONT_DELETE);
|
2008-10-03 07:14:31 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
for (var i = 1; i < 10; ++i) {
|
Make the runtime entry for setting/changing accessors "atomic".
Previously, there were 1 or 2 calls to the runtime when accessors were changed
or set. This doesn't really work well with property attributes, leading to some
hacks and complicates things even further when trying to share maps in presence
of accessors. Therefore, the runtime entry now takes the full triple (getter,
setter, attributes), where the getter and/or the setter can be null in case they
shouldn't be changed.
For now, we do basically the same on the native side as we did before on the
JavaScript side, but this will change in future CLs, the current CL is already
large enough.
Note that object literals with a getter and a setter for the same property still
do 2 calls, but this is a little bit more tricky to fix and will be handled in a
separate CL.
Review URL: https://chromiumcodereview.appspot.com/9616016
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@10956 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2012-03-07 13:24:44 +00:00
|
|
|
%DefineOrRedefineAccessorProperty($RegExp, '$' + i,
|
|
|
|
RegExpMakeCaptureGetter(i), NoOpSetter,
|
2012-02-21 12:47:27 +00:00
|
|
|
DONT_DELETE);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2012-05-25 12:32:02 +00:00
|
|
|
%ToFastProperties($RegExp);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
|
|
|
|
2011-09-05 07:30:35 +00:00
|
|
|
SetUpRegExp();
|