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

Unified Diff: src/harmony-templates.js

Issue 731573004: Implement ES6 String.raw behind --harmony-templates (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Nits 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') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/harmony-templates.js
diff --git a/src/harmony-templates.js b/src/harmony-templates.js
index dd122cce85f28ae5e478af25fb9a1a8c8bbb2c9c..712d8d3a12bbb996d1bd838c09d81fd9d180e3e6 100644
--- a/src/harmony-templates.js
+++ b/src/harmony-templates.js
@@ -12,3 +12,37 @@ function GetTemplateCallSite(siteObj, rawStrings) {
return %ObjectFreeze(siteObj);
}
+
+
+// ES6 Draft 10-14-2014, section 21.1.2.4
+function StringRaw(callSite) {
+ // TODO(caitp): Use rest parameters when implemented
+ var numberOfSubstitutions = %_ArgumentsLength();
+ var cooked = ToObject(callSite);
+ var raw = ToObject(cooked.raw);
+ var literalSegments = ToLength(raw.length);
+ if (literalSegments <= 0) return "";
+
+ var result = ToString(raw[0]);
+
+ for (var i = 1; i < literalSegments; ++i) {
+ if (i < numberOfSubstitutions) {
+ result += ToString(%_Arguments(i));
+ }
+ result += ToString(raw[i]);
+ }
+
+ return result;
+}
+
+
+function ExtendStringForTemplates() {
+ %CheckIsBootstrapping();
+
+ // Set up the non-enumerable functions on the String object.
+ InstallFunctions($String, DONT_ENUM, $Array(
+ "raw", StringRaw
+ ));
+}
+
+ExtendStringForTemplates();
« no previous file with comments | « no previous file | test/mjsunit/harmony/string-raw.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698