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

Side by Side Diff: src/templates.js

Issue 1398733002: Move builtin JavaScript sources into own directory. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Also move macros.py file. Created 5 years, 2 months 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 unified diff | Download patch
« no previous file with comments | « src/symbol.js ('k') | src/typedarray.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Called from a desugaring in the parser.
6
7 (function(global, utils) {
8
9 "use strict";
10
11 %CheckIsBootstrapping();
12
13 // -------------------------------------------------------------------
14 // Imports
15
16 var GlobalMap = global.Map;
17 var InternalArray = utils.InternalArray;
18
19 // -------------------------------------------------------------------
20
21 var callSiteCache = new GlobalMap;
22 var mapGetFn = GlobalMap.prototype.get;
23 var mapSetFn = GlobalMap.prototype.set;
24
25
26 function SameCallSiteElements(rawStrings, other) {
27 var length = rawStrings.length;
28 var other = other.raw;
29
30 if (length !== other.length) return false;
31
32 for (var i = 0; i < length; ++i) {
33 if (rawStrings[i] !== other[i]) return false;
34 }
35
36 return true;
37 }
38
39
40 function GetCachedCallSite(siteObj, hash) {
41 var obj = %_CallFunction(callSiteCache, hash, mapGetFn);
42
43 if (IS_UNDEFINED(obj)) return;
44
45 var length = obj.length;
46 for (var i = 0; i < length; ++i) {
47 if (SameCallSiteElements(siteObj, obj[i])) return obj[i];
48 }
49 }
50
51
52 function SetCachedCallSite(siteObj, hash) {
53 var obj = %_CallFunction(callSiteCache, hash, mapGetFn);
54 var array;
55
56 if (IS_UNDEFINED(obj)) {
57 array = new InternalArray(1);
58 array[0] = siteObj;
59 %_CallFunction(callSiteCache, hash, array, mapSetFn);
60 } else {
61 obj.push(siteObj);
62 }
63
64 return siteObj;
65 }
66
67
68 function GetTemplateCallSite(siteObj, rawStrings, hash) {
69 var cached = GetCachedCallSite(rawStrings, hash);
70
71 if (!IS_UNDEFINED(cached)) return cached;
72
73 %AddNamedProperty(siteObj, "raw", %ObjectFreeze(rawStrings),
74 READ_ONLY | DONT_ENUM | DONT_DELETE);
75
76 return SetCachedCallSite(%ObjectFreeze(siteObj), hash);
77 }
78
79 // ----------------------------------------------------------------------------
80 // Exports
81
82 %InstallToContext(["get_template_call_site", GetTemplateCallSite]);
83
84 })
OLDNEW
« no previous file with comments | « src/symbol.js ('k') | src/typedarray.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698