Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1546)

Unified Diff: src/harmony-string.js

Issue 731573004: Implement ES6 String.raw behind --harmony-templates (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: oops Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/mjsunit/harmony/string-raw.js » ('j') | test/mjsunit/harmony/string-raw.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
« no previous file with comments | « no previous file | test/mjsunit/harmony/string-raw.js » ('j') | test/mjsunit/harmony/string-raw.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698