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

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: Fixup assertions 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-templates.js
diff --git a/src/harmony-templates.js b/src/harmony-templates.js
index dd122cce85f28ae5e478af25fb9a1a8c8bbb2c9c..b272a628b2862565b73b6ca3eb2bf8f76fe54ac6 100644
--- a/src/harmony-templates.js
+++ b/src/harmony-templates.js
@@ -12,3 +12,39 @@ function GetTemplateCallSite(siteObj, rawStrings) {
return %ObjectFreeze(siteObj);
}
+
+
+// ES6 Draft 10-14-2014, section 21.1.2.4
+function StringRaw(callSite) {
+ // TODO(*): Use rest parameters when implemented
arv (Not doing code reviews) 2014/11/18 19:05:27 We always use a name here. The name should be of t
caitp (gmail) 2014/11/18 19:11:54 Done.
+ 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;
+}
+
+
+// -------------------------------------------------------------------
arv (Not doing code reviews) 2014/11/18 19:05:27 skip this line
caitp (gmail) 2014/11/18 19:11:54 Done.
+
+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') | test/mjsunit/harmony/string-raw.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698