summaryrefslogtreecommitdiff
path: root/deps/v8/src/js/string.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/src/js/string.js')
-rw-r--r--deps/v8/src/js/string.js403
1 files changed, 188 insertions, 215 deletions
diff --git a/deps/v8/src/js/string.js b/deps/v8/src/js/string.js
index a3a59d5fde..521afc2c42 100644
--- a/deps/v8/src/js/string.js
+++ b/deps/v8/src/js/string.js
@@ -4,6 +4,8 @@
(function(global, utils) {
+"use strict";
+
%CheckIsBootstrapping();
// -------------------------------------------------------------------
@@ -15,188 +17,179 @@ var searchSymbol = utils.ImportNow("search_symbol");
//-------------------------------------------------------------------
-// ES6 21.1.3.11.
-function StringMatchJS(pattern) {
- CHECK_OBJECT_COERCIBLE(this, "String.prototype.match");
-
- if (!IS_NULL_OR_UNDEFINED(pattern)) {
- var matcher = pattern[matchSymbol];
- if (!IS_UNDEFINED(matcher)) {
- return %_Call(matcher, pattern, this);
- }
- }
-
- var subject = TO_STRING(this);
-
- // Equivalent to RegExpCreate (ES#sec-regexpcreate)
- var regexp = %RegExpCreate(pattern);
- return regexp[matchSymbol](subject);
-}
-
-// ES6 21.1.3.15.
-function StringSearch(pattern) {
- CHECK_OBJECT_COERCIBLE(this, "String.prototype.search");
-
- if (!IS_NULL_OR_UNDEFINED(pattern)) {
- var searcher = pattern[searchSymbol];
- if (!IS_UNDEFINED(searcher)) {
- return %_Call(searcher, pattern, this);
- }
- }
-
- var subject = TO_STRING(this);
-
- // Equivalent to RegExpCreate (ES#sec-regexpcreate)
- var regexp = %RegExpCreate(pattern);
- return %_Call(regexp[searchSymbol], regexp, subject);
-}
-
-
-// ES6 draft, revision 26 (2014-07-18), section B.2.3.2.1
+// ES#sec-createhtml
function HtmlEscape(str) {
return %RegExpInternalReplace(/"/g, TO_STRING(str), """);
}
+// Set up the non-enumerable functions on the String prototype object.
+DEFINE_METHODS(
+ GlobalString.prototype,
+ {
+ /* ES#sec-string.prototype.match */
+ match(pattern) {
+ CHECK_OBJECT_COERCIBLE(this, "String.prototype.match");
+
+ if (!IS_NULL_OR_UNDEFINED(pattern)) {
+ var matcher = pattern[matchSymbol];
+ if (!IS_UNDEFINED(matcher)) {
+ return %_Call(matcher, pattern, this);
+ }
+ }
+
+ var subject = TO_STRING(this);
+
+ // Equivalent to RegExpCreate (ES#sec-regexpcreate)
+ var regexp = %RegExpCreate(pattern);
+ return regexp[matchSymbol](subject);
+ }
-// ES6 draft, revision 26 (2014-07-18), section B.2.3.2
-function StringAnchor(name) {
- CHECK_OBJECT_COERCIBLE(this, "String.prototype.anchor");
- return "<a name=\"" + HtmlEscape(name) + "\">" + TO_STRING(this) +
- "</a>";
-}
-
-
-// ES6 draft, revision 26 (2014-07-18), section B.2.3.3
-function StringBig() {
- CHECK_OBJECT_COERCIBLE(this, "String.prototype.big");
- return "<big>" + TO_STRING(this) + "</big>";
-}
-
-
-// ES6 draft, revision 26 (2014-07-18), section B.2.3.4
-function StringBlink() {
- CHECK_OBJECT_COERCIBLE(this, "String.prototype.blink");
- return "<blink>" + TO_STRING(this) + "</blink>";
-}
-
-
-// ES6 draft, revision 26 (2014-07-18), section B.2.3.5
-function StringBold() {
- CHECK_OBJECT_COERCIBLE(this, "String.prototype.bold");
- return "<b>" + TO_STRING(this) + "</b>";
-}
-
-
-// ES6 draft, revision 26 (2014-07-18), section B.2.3.6
-function StringFixed() {
- CHECK_OBJECT_COERCIBLE(this, "String.prototype.fixed");
- return "<tt>" + TO_STRING(this) + "</tt>";
-}
-
+ /* ES#sec-string.prototype.search */
+ search(pattern) {
+ CHECK_OBJECT_COERCIBLE(this, "String.prototype.search");
-// ES6 draft, revision 26 (2014-07-18), section B.2.3.7
-function StringFontcolor(color) {
- CHECK_OBJECT_COERCIBLE(this, "String.prototype.fontcolor");
- return "<font color=\"" + HtmlEscape(color) + "\">" + TO_STRING(this) +
- "</font>";
-}
+ if (!IS_NULL_OR_UNDEFINED(pattern)) {
+ var searcher = pattern[searchSymbol];
+ if (!IS_UNDEFINED(searcher)) {
+ return %_Call(searcher, pattern, this);
+ }
+ }
+ var subject = TO_STRING(this);
-// ES6 draft, revision 26 (2014-07-18), section B.2.3.8
-function StringFontsize(size) {
- CHECK_OBJECT_COERCIBLE(this, "String.prototype.fontsize");
- return "<font size=\"" + HtmlEscape(size) + "\">" + TO_STRING(this) +
- "</font>";
-}
-
+ // Equivalent to RegExpCreate (ES#sec-regexpcreate)
+ var regexp = %RegExpCreate(pattern);
+ return %_Call(regexp[searchSymbol], regexp, subject);
+ }
-// ES6 draft, revision 26 (2014-07-18), section B.2.3.9
-function StringItalics() {
- CHECK_OBJECT_COERCIBLE(this, "String.prototype.italics");
- return "<i>" + TO_STRING(this) + "</i>";
-}
+ /* ES#sec-string.prototype.anchor */
+ anchor(name) {
+ CHECK_OBJECT_COERCIBLE(this, "String.prototype.anchor");
+ return "<a name=\"" + HtmlEscape(name) + "\">" + TO_STRING(this) +
+ "</a>";
+ }
+ /* ES#sec-string.prototype.big */
+ big() {
+ CHECK_OBJECT_COERCIBLE(this, "String.prototype.big");
+ return "<big>" + TO_STRING(this) + "</big>";
+ }
-// ES6 draft, revision 26 (2014-07-18), section B.2.3.10
-function StringLink(s) {
- CHECK_OBJECT_COERCIBLE(this, "String.prototype.link");
- return "<a href=\"" + HtmlEscape(s) + "\">" + TO_STRING(this) + "</a>";
-}
+ /* ES#sec-string.prototype.blink */
+ blink() {
+ CHECK_OBJECT_COERCIBLE(this, "String.prototype.blink");
+ return "<blink>" + TO_STRING(this) + "</blink>";
+ }
+ /* ES#sec-string.prototype.bold */
+ bold() {
+ CHECK_OBJECT_COERCIBLE(this, "String.prototype.bold");
+ return "<b>" + TO_STRING(this) + "</b>";
+ }
-// ES6 draft, revision 26 (2014-07-18), section B.2.3.11
-function StringSmall() {
- CHECK_OBJECT_COERCIBLE(this, "String.prototype.small");
- return "<small>" + TO_STRING(this) + "</small>";
-}
+ /* ES#sec-string.prototype.fixed */
+ fixed() {
+ CHECK_OBJECT_COERCIBLE(this, "String.prototype.fixed");
+ return "<tt>" + TO_STRING(this) + "</tt>";
+ }
+ /* ES#sec-string.prototype.fontcolor */
+ fontcolor(color) {
+ CHECK_OBJECT_COERCIBLE(this, "String.prototype.fontcolor");
+ return "<font color=\"" + HtmlEscape(color) + "\">" + TO_STRING(this) +
+ "</font>";
+ }
-// ES6 draft, revision 26 (2014-07-18), section B.2.3.12
-function StringStrike() {
- CHECK_OBJECT_COERCIBLE(this, "String.prototype.strike");
- return "<strike>" + TO_STRING(this) + "</strike>";
-}
+ /* ES#sec-string.prototype.fontsize */
+ fontsize(size) {
+ CHECK_OBJECT_COERCIBLE(this, "String.prototype.fontsize");
+ return "<font size=\"" + HtmlEscape(size) + "\">" + TO_STRING(this) +
+ "</font>";
+ }
+ /* ES#sec-string.prototype.italics */
+ italics() {
+ CHECK_OBJECT_COERCIBLE(this, "String.prototype.italics");
+ return "<i>" + TO_STRING(this) + "</i>";
+ }
-// ES6 draft, revision 26 (2014-07-18), section B.2.3.13
-function StringSub() {
- CHECK_OBJECT_COERCIBLE(this, "String.prototype.sub");
- return "<sub>" + TO_STRING(this) + "</sub>";
-}
+ /* ES#sec-string.prototype.link */
+ link(s) {
+ CHECK_OBJECT_COERCIBLE(this, "String.prototype.link");
+ return "<a href=\"" + HtmlEscape(s) + "\">" + TO_STRING(this) + "</a>";
+ }
+ /* ES#sec-string.prototype.small */
+ small() {
+ CHECK_OBJECT_COERCIBLE(this, "String.prototype.small");
+ return "<small>" + TO_STRING(this) + "</small>";
+ }
-// ES6 draft, revision 26 (2014-07-18), section B.2.3.14
-function StringSup() {
- CHECK_OBJECT_COERCIBLE(this, "String.prototype.sup");
- return "<sup>" + TO_STRING(this) + "</sup>";
-}
+ /* ES#sec-string.prototype.strike */
+ strike() {
+ CHECK_OBJECT_COERCIBLE(this, "String.prototype.strike");
+ return "<strike>" + TO_STRING(this) + "</strike>";
+ }
-// ES6, section 21.1.3.13
-function StringRepeat(count) {
- CHECK_OBJECT_COERCIBLE(this, "String.prototype.repeat");
+ /* ES#sec-string.prototype.sub */
+ sub() {
+ CHECK_OBJECT_COERCIBLE(this, "String.prototype.sub");
+ return "<sub>" + TO_STRING(this) + "</sub>";
+ }
- var s = TO_STRING(this);
- var n = TO_INTEGER(count);
+ /* ES#sec-string.prototype.sup */
+ sup() {
+ CHECK_OBJECT_COERCIBLE(this, "String.prototype.sup");
+ return "<sup>" + TO_STRING(this) + "</sup>";
+ }
- if (n < 0 || n === INFINITY) throw %make_range_error(kInvalidCountValue);
+ /* ES#sec-string.prototype.repeat */
+ repeat(count) {
+ CHECK_OBJECT_COERCIBLE(this, "String.prototype.repeat");
- // Early return to allow an arbitrarily-large repeat of the empty string.
- if (s.length === 0) return "";
+ var s = TO_STRING(this);
+ var n = TO_INTEGER(count);
- // The maximum string length is stored in a smi, so a longer repeat
- // must result in a range error.
- if (n > %_MaxSmi()) throw %make_range_error(kInvalidStringLength);
+ if (n < 0 || n === INFINITY) throw %make_range_error(kInvalidCountValue);
- var r = "";
- while (true) {
- if (n & 1) r += s;
- n >>= 1;
- if (n === 0) return r;
- s += s;
- }
-}
+ // Early return to allow an arbitrarily-large repeat of the empty string.
+ if (s.length === 0) return "";
+ // The maximum string length is stored in a smi, so a longer repeat
+ // must result in a range error.
+ if (n > %_MaxSmi()) throw %make_range_error(kInvalidStringLength);
-// ES6 Draft 05-22-2014, section 21.1.3.3
-function StringCodePointAt(pos) {
- CHECK_OBJECT_COERCIBLE(this, "String.prototype.codePointAt");
+ var r = "";
+ while (true) {
+ if (n & 1) r += s;
+ n >>= 1;
+ if (n === 0) return r;
+ s += s;
+ }
+ }
- var string = TO_STRING(this);
- var size = string.length;
- pos = TO_INTEGER(pos);
- if (pos < 0 || pos >= size) {
- return UNDEFINED;
- }
- var first = %_StringCharCodeAt(string, pos);
- if (first < 0xD800 || first > 0xDBFF || pos + 1 == size) {
- return first;
- }
- var second = %_StringCharCodeAt(string, pos + 1);
- if (second < 0xDC00 || second > 0xDFFF) {
- return first;
+ /* ES#sec-string.prototype.codepointat */
+ codePointAt(pos) {
+ CHECK_OBJECT_COERCIBLE(this, "String.prototype.codePointAt");
+
+ var string = TO_STRING(this);
+ var size = string.length;
+ pos = TO_INTEGER(pos);
+ if (pos < 0 || pos >= size) {
+ return UNDEFINED;
+ }
+ var first = %_StringCharCodeAt(string, pos);
+ if (first < 0xD800 || first > 0xDBFF || pos + 1 == size) {
+ return first;
+ }
+ var second = %_StringCharCodeAt(string, pos + 1);
+ if (second < 0xDC00 || second > 0xDFFF) {
+ return first;
+ }
+ return (first - 0xD800) * 0x400 + second + 0x2400;
+ }
}
- return (first - 0xD800) * 0x400 + second + 0x2400;
-}
+);
function StringPad(thisString, maxLength, fillString) {
maxLength = TO_LENGTH(maxLength);
@@ -233,78 +226,58 @@ function StringPad(thisString, maxLength, fillString) {
return filler;
}
-// ES#sec-string.prototype.padstart
-// String.prototype.padStart(maxLength [, fillString])
-function StringPadStart(maxLength, fillString) {
- CHECK_OBJECT_COERCIBLE(this, "String.prototype.padStart");
- var thisString = TO_STRING(this);
+DEFINE_METHODS_LEN(
+ GlobalString.prototype,
+ {
+ /* ES#sec-string.prototype.padstart */
+ /* String.prototype.padStart(maxLength [, fillString]) */
+ padStart(maxLength, fillString) {
+ CHECK_OBJECT_COERCIBLE(this, "String.prototype.padStart");
+ var thisString = TO_STRING(this);
- return StringPad(thisString, maxLength, fillString) + thisString;
-}
-%FunctionSetLength(StringPadStart, 1);
+ return StringPad(thisString, maxLength, fillString) + thisString;
+ }
-// ES#sec-string.prototype.padend
-// String.prototype.padEnd(maxLength [, fillString])
-function StringPadEnd(maxLength, fillString) {
- CHECK_OBJECT_COERCIBLE(this, "String.prototype.padEnd");
- var thisString = TO_STRING(this);
+ /* ES#sec-string.prototype.padend */
+ /* String.prototype.padEnd(maxLength [, fillString]) */
+ padEnd(maxLength, fillString) {
+ CHECK_OBJECT_COERCIBLE(this, "String.prototype.padEnd");
+ var thisString = TO_STRING(this);
- return thisString + StringPad(thisString, maxLength, fillString);
-}
-%FunctionSetLength(StringPadEnd, 1);
+ return thisString + StringPad(thisString, maxLength, fillString);
+ }
+ },
+ 1 /* Set functions length */
+);
// -------------------------------------------------------------------
// String methods related to templates
-// ES6 Draft 03-17-2015, section 21.1.2.4
-function StringRaw(callSite) {
- "use strict";
- var numberOfSubstitutions = arguments.length;
- var cooked = TO_OBJECT(callSite);
- var raw = TO_OBJECT(cooked.raw);
- var literalSegments = TO_LENGTH(raw.length);
- if (literalSegments <= 0) return "";
-
- var result = TO_STRING(raw[0]);
-
- for (var i = 1; i < literalSegments; ++i) {
- if (i < numberOfSubstitutions) {
- result += TO_STRING(arguments[i]);
+// Set up the non-enumerable functions on the String object.
+DEFINE_METHOD(
+ GlobalString,
+
+ /* ES#sec-string.raw */
+ raw(callSite) {
+ var numberOfSubstitutions = arguments.length;
+ var cooked = TO_OBJECT(callSite);
+ var raw = TO_OBJECT(cooked.raw);
+ var literalSegments = TO_LENGTH(raw.length);
+ if (literalSegments <= 0) return "";
+
+ var result = TO_STRING(raw[0]);
+
+ for (var i = 1; i < literalSegments; ++i) {
+ if (i < numberOfSubstitutions) {
+ result += TO_STRING(arguments[i]);
+ }
+ result += TO_STRING(raw[i]);
}
- result += TO_STRING(raw[i]);
- }
- return result;
-}
+ return result;
+ }
+);
// -------------------------------------------------------------------
-// Set up the non-enumerable functions on the String object.
-utils.InstallFunctions(GlobalString, DONT_ENUM, [
- "raw", StringRaw
-]);
-
-// Set up the non-enumerable functions on the String prototype object.
-utils.InstallFunctions(GlobalString.prototype, DONT_ENUM, [
- "codePointAt", StringCodePointAt,
- "match", StringMatchJS,
- "padEnd", StringPadEnd,
- "padStart", StringPadStart,
- "repeat", StringRepeat,
- "search", StringSearch,
- "link", StringLink,
- "anchor", StringAnchor,
- "fontcolor", StringFontcolor,
- "fontsize", StringFontsize,
- "big", StringBig,
- "blink", StringBlink,
- "bold", StringBold,
- "fixed", StringFixed,
- "italics", StringItalics,
- "small", StringSmall,
- "strike", StringStrike,
- "sub", StringSub,
- "sup", StringSup
-]);
-
})