Index: src/harmony-string.js |
diff --git a/src/harmony-string.js b/src/harmony-string.js |
index 1c477e2fa5c996fc279a3b8bac500286da8eb9c0..037a7416b1119d173353ff778b6411aaabb915f0 100644 |
--- a/src/harmony-string.js |
+++ b/src/harmony-string.js |
@@ -171,6 +171,32 @@ function StringFromCodePoint(_) { // length = 1 |
} |
+// ES6 Draft 10-14-2014, section 21.1.2.4 |
+function StringRaw(callSite) { |
+ // TODO(*): Use rest parameters when implemented |
+ var substitutions = $Array.prototype.slice.call(arguments, 1); |
arv (Not doing code reviews)
2014/11/14 22:54:25
This is not safe. Use a c-style for loop using %_A
caitp (gmail)
2014/11/14 23:29:58
Done.
|
+ var numberOfSubstitutions = substitutions.length; |
+ var cooked = ToObject(callSite); |
+ var raw = ToObject(cooked.raw); |
+ var literalSegments = ToLength(raw.length); |
+ if (literalSegments <= 0) return ""; |
+ |
+ var result = ""; |
+ var nextIndex = 0; |
+ |
+ while (true) { |
arv (Not doing code reviews)
2014/11/14 22:54:25
for (var nextIndex = 0; ; nextIndex++) {
caitp (gmail)
2014/11/14 23:29:58
I've fixed this slightly differently, so it looks
arv (Not doing code reviews)
2014/11/14 23:42:17
I like your new code better. Easier to grok.
|
+ var next = ToString(raw[nextIndex]); |
arv (Not doing code reviews)
2014/11/14 22:54:25
Don't we know that these are all strings?
caitp (gmail)
2014/11/14 23:29:58
The algorithm specifically calls for ToString(), w
arv (Not doing code reviews)
2014/11/14 23:42:17
I guess it doesn't hurt to call ToString on a stri
|
+ result = result + next; |
arv (Not doing code reviews)
2014/11/14 22:54:25
+=
caitp (gmail)
2014/11/14 23:29:58
Acknowledged.
|
+ if (nextIndex + 1 === literalSegments) return result; |
+ if (nextIndex < numberOfSubstitutions) { |
+ next = ToString(substitutions[nextIndex]); |
+ result = result + next; |
+ } |
+ nextIndex++; |
+ } |
+} |
+ |
+ |
// ------------------------------------------------------------------- |
function ExtendStringPrototype() { |
@@ -178,7 +204,8 @@ function ExtendStringPrototype() { |
// Set up the non-enumerable functions on the String object. |
InstallFunctions($String, DONT_ENUM, $Array( |
- "fromCodePoint", StringFromCodePoint |
+ "fromCodePoint", StringFromCodePoint, |
+ "raw", StringRaw |
)); |
// Set up the non-enumerable functions on the String prototype object. |