summaryrefslogtreecommitdiffstats
path: root/V8Binding/v8/src/string.js
diff options
context:
space:
mode:
Diffstat (limited to 'V8Binding/v8/src/string.js')
-rw-r--r--V8Binding/v8/src/string.js54
1 files changed, 26 insertions, 28 deletions
diff --git a/V8Binding/v8/src/string.js b/V8Binding/v8/src/string.js
index df1f393..6164eb8 100644
--- a/V8Binding/v8/src/string.js
+++ b/V8Binding/v8/src/string.js
@@ -35,7 +35,7 @@
// Set the String function and constructor.
%SetCode($String, function(x) {
var value = %_ArgumentsLength() == 0 ? '' : ToString(x);
- if (%IsConstructCall()) {
+ if (%_IsConstructCall()) {
%_SetValueOf(this, value);
} else {
return value;
@@ -46,7 +46,7 @@
// ECMA-262 section 15.5.4.2
function StringToString() {
- if (!IS_STRING(this) && !%HasStringClass(this))
+ if (!IS_STRING(this) && !IS_STRING_WRAPPER(this))
throw new $TypeError('String.prototype.toString is not generic');
return %_ValueOf(this);
}
@@ -54,7 +54,7 @@ function StringToString() {
// ECMA-262 section 15.5.4.3
function StringValueOf() {
- if (!IS_STRING(this) && !%HasStringClass(this))
+ if (!IS_STRING(this) && !IS_STRING_WRAPPER(this))
throw new $TypeError('String.prototype.valueOf is not generic');
return %_ValueOf(this);
}
@@ -370,10 +370,10 @@ function addCaptureString(builder, matchInfo, index) {
// 'abcd'.replace(/(.)/g, function() { return RegExp.$1; }
// should be 'abcd' and not 'dddd' (or anything else).
function StringReplaceRegExpWithFunction(subject, regexp, replace) {
- var result = new ReplaceResultBuilder(subject);
var lastMatchInfo = DoRegExpExec(regexp, subject, 0);
if (IS_NULL(lastMatchInfo)) return subject;
+ var result = new ReplaceResultBuilder(subject);
// There's at least one match. If the regexp is global, we have to loop
// over all matches. The loop is not in C++ code here like the one in
// RegExp.prototype.exec, because of the interleaved function application.
@@ -498,10 +498,8 @@ function StringSlice(start, end) {
// ECMA-262 section 15.5.4.14
function StringSplit(separator, limit) {
var subject = ToString(this);
- var result = [];
- var lim = (limit === void 0) ? 0xffffffff : ToUint32(limit);
-
- if (lim === 0) return result;
+ limit = (limit === void 0) ? 0xffffffff : ToUint32(limit);
+ if (limit === 0) return [];
// ECMA-262 says that if separator is undefined, the result should
// be an array of size 1 containing the entire string. SpiderMonkey
@@ -509,28 +507,31 @@ function StringSplit(separator, limit) {
// undefined is explicitly given, they convert it to a string and
// use that. We do as SpiderMonkey and KJS.
if (%_ArgumentsLength() === 0) {
- result[result.length] = subject;
- return result;
+ return [subject];
}
var length = subject.length;
- var currentIndex = 0;
- var startIndex = 0;
-
- var sep;
if (IS_REGEXP(separator)) {
- sep = separator;
- %_Log('regexp', 'regexp-split,%0S,%1r', [subject, sep]);
+ %_Log('regexp', 'regexp-split,%0S,%1r', [subject, separator]);
} else {
- sep = ToString(separator);
+ separator = ToString(separator);
+ // If the separator string is empty then return the elements in the subject.
+ if (separator.length == 0) {
+ var result = $Array(length);
+ for (var i = 0; i < length; i++) result[i] = subject[i];
+ return result;
+ }
}
if (length === 0) {
- if (splitMatch(sep, subject, 0, 0) != null) return result;
- result[result.length] = subject;
- return result;
+ if (splitMatch(separator, subject, 0, 0) != null) return [];
+ return [subject];
}
+ var currentIndex = 0;
+ var startIndex = 0;
+ var result = [];
+
while (true) {
if (startIndex === length) {
@@ -538,7 +539,7 @@ function StringSplit(separator, limit) {
return result;
}
- var lastMatchInfo = splitMatch(sep, subject, currentIndex, startIndex);
+ var lastMatchInfo = splitMatch(separator, subject, currentIndex, startIndex);
if (IS_NULL(lastMatchInfo)) {
result[result.length] = subject.slice(currentIndex, length);
@@ -553,21 +554,18 @@ function StringSplit(separator, limit) {
continue;
}
- result[result.length] =
- SubString(subject, currentIndex, lastMatchInfo[CAPTURE0]);
- if (result.length === lim) return result;
+ result[result.length] = SubString(subject, currentIndex, lastMatchInfo[CAPTURE0]);
+ if (result.length === limit) return result;
for (var i = 2; i < NUMBER_OF_CAPTURES(lastMatchInfo); i += 2) {
var start = lastMatchInfo[CAPTURE(i)];
var end = lastMatchInfo[CAPTURE(i + 1)];
if (start != -1 && end != -1) {
- result[result.length] = SubString(subject,
- lastMatchInfo[CAPTURE(i)],
- lastMatchInfo[CAPTURE(i + 1)]);
+ result[result.length] = SubString(subject, start, end);
} else {
result[result.length] = void 0;
}
- if (result.length === lim) return result;
+ if (result.length === limit) return result;
}
startIndex = currentIndex = endIndex;