OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 "use strict"; | 5 "use strict"; |
6 | 6 |
| 7 // Called from a desugaring in the parser. |
| 8 var GetTemplateCallSite; |
| 9 |
| 10 (function() { |
| 11 |
| 12 %CheckIsBootstrapping(); |
| 13 |
7 var callSiteCache = new $Map; | 14 var callSiteCache = new $Map; |
| 15 var mapGetFn = $Map.prototype.get; |
| 16 var mapSetFn = $Map.prototype.set; |
| 17 |
8 | 18 |
9 function SameCallSiteElements(rawStrings, other) { | 19 function SameCallSiteElements(rawStrings, other) { |
10 var length = rawStrings.length; | 20 var length = rawStrings.length; |
11 var other = other.raw; | 21 var other = other.raw; |
12 | 22 |
13 if (length !== other.length) return false; | 23 if (length !== other.length) return false; |
14 | 24 |
15 for (var i = 0; i < length; ++i) { | 25 for (var i = 0; i < length; ++i) { |
16 if (rawStrings[i] !== other[i]) return false; | 26 if (rawStrings[i] !== other[i]) return false; |
17 } | 27 } |
18 | 28 |
19 return true; | 29 return true; |
20 } | 30 } |
21 | 31 |
22 | 32 |
23 function GetCachedCallSite(siteObj, hash) { | 33 function GetCachedCallSite(siteObj, hash) { |
24 var obj = %_CallFunction(callSiteCache, hash, $MapGet); | 34 var obj = %_CallFunction(callSiteCache, hash, mapGetFn); |
25 | 35 |
26 if (IS_UNDEFINED(obj)) return; | 36 if (IS_UNDEFINED(obj)) return; |
27 | 37 |
28 var length = obj.length; | 38 var length = obj.length; |
29 for (var i = 0; i < length; ++i) { | 39 for (var i = 0; i < length; ++i) { |
30 if (SameCallSiteElements(siteObj, obj[i])) return obj[i]; | 40 if (SameCallSiteElements(siteObj, obj[i])) return obj[i]; |
31 } | 41 } |
32 } | 42 } |
33 | 43 |
34 | 44 |
35 function SetCachedCallSite(siteObj, hash) { | 45 function SetCachedCallSite(siteObj, hash) { |
36 var obj = %_CallFunction(callSiteCache, hash, $MapGet); | 46 var obj = %_CallFunction(callSiteCache, hash, mapGetFn); |
37 var array; | 47 var array; |
38 | 48 |
39 if (IS_UNDEFINED(obj)) { | 49 if (IS_UNDEFINED(obj)) { |
40 array = new InternalArray(1); | 50 array = new InternalArray(1); |
41 array[0] = siteObj; | 51 array[0] = siteObj; |
42 %_CallFunction(callSiteCache, hash, array, $MapSet); | 52 %_CallFunction(callSiteCache, hash, array, mapSetFn); |
43 } else { | 53 } else { |
44 obj.push(siteObj); | 54 obj.push(siteObj); |
45 } | 55 } |
46 | 56 |
47 return siteObj; | 57 return siteObj; |
48 } | 58 } |
49 | 59 |
50 | 60 |
51 function GetTemplateCallSite(siteObj, rawStrings, hash) { | 61 GetTemplateCallSite = function(siteObj, rawStrings, hash) { |
52 var cached = GetCachedCallSite(rawStrings, hash); | 62 var cached = GetCachedCallSite(rawStrings, hash); |
53 | 63 |
54 if (!IS_UNDEFINED(cached)) return cached; | 64 if (!IS_UNDEFINED(cached)) return cached; |
55 | 65 |
56 %AddNamedProperty(siteObj, "raw", %ObjectFreeze(rawStrings), | 66 %AddNamedProperty(siteObj, "raw", %ObjectFreeze(rawStrings), |
57 READ_ONLY | DONT_ENUM | DONT_DELETE); | 67 READ_ONLY | DONT_ENUM | DONT_DELETE); |
58 | 68 |
59 return SetCachedCallSite(%ObjectFreeze(siteObj), hash); | 69 return SetCachedCallSite(%ObjectFreeze(siteObj), hash); |
60 } | 70 } |
| 71 |
| 72 })(); |
OLD | NEW |