Index: src/harmony-string.js |
diff --git a/src/harmony-string.js b/src/harmony-string.js |
index 4cd8e6687edaeacb51079801b74480a21cc352b0..a8ef1ddb1246842e8bbb3336551c8e26428e6f22 100644 |
--- a/src/harmony-string.js |
+++ b/src/harmony-string.js |
@@ -120,17 +120,73 @@ function StringContains(searchString /* position */) { // length == 1 |
} |
+// ES6 Draft 05-22-2014, section 21.1.3.3 |
+function StringCodePointAt(pos) { |
+ CHECK_OBJECT_COERCIBLE(this, "String.prototype.codePointAt"); |
+ |
+ var string = TO_STRING_INLINE(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; |
+} |
+ |
+ |
+// ES6 Draft 05-22-2014, section 21.1.2.2 |
+function StringFromCodePoint(_) { // length = 1 |
+ var code; |
+ var length = %_ArgumentsLength(); |
+ var index; |
+ var result = ""; |
+ for (index = 0; index < length; index++) { |
+ code = %_Arguments(index); |
+ if (!%_IsSmi(code)) { |
+ code = ToNumber(code); |
+ } |
+ if (code < 0 || code > 0x10FFFF || code !== TO_INTEGER(code)) { |
+ throw MakeRangeError("invalid_code_point", [code]); |
+ } |
+ if (code <= 0xFFFF) { |
+ result += %_StringCharFromCode(code); |
+ } else { |
+ code -= 0x10000; |
+ result += StringFromCharCode( |
+ code >>> 10 & 0x3FF | 0xD800, |
+ 0xDC00 | code & 0x3FF |
+ ); |
+ } |
+ } |
+ return result; |
+} |
+ |
+ |
// ------------------------------------------------------------------- |
function ExtendStringPrototype() { |
%CheckIsBootstrapping(); |
+ // Set up the non-enumerable functions on the String object. |
+ InstallFunctions($String, DONT_ENUM, $Array( |
+ "fromCodePoint", StringFromCodePoint |
+ )); |
+ |
// Set up the non-enumerable functions on the String prototype object. |
InstallFunctions($String.prototype, DONT_ENUM, $Array( |
- "repeat", StringRepeat, |
- "startsWith", StringStartsWith, |
+ "codePointAt", StringCodePointAt, |
+ "contains", StringContains, |
"endsWith", StringEndsWith, |
- "contains", StringContains |
+ "repeat", StringRepeat, |
+ "startsWith", StringStartsWith |
)); |
} |