2014-11-14 18:53:41 +00:00
|
|
|
// Copyright 2014 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2015-04-07 19:00:34 +00:00
|
|
|
// Called from a desugaring in the parser.
|
2015-04-16 12:17:46 +00:00
|
|
|
|
|
|
|
var $getTemplateCallSite;
|
2015-04-07 19:00:34 +00:00
|
|
|
|
2015-05-20 15:59:51 +00:00
|
|
|
(function(global, shared, exports) {
|
2015-04-07 19:00:34 +00:00
|
|
|
|
2015-04-16 12:17:46 +00:00
|
|
|
"use strict";
|
|
|
|
|
2015-04-07 19:00:34 +00:00
|
|
|
%CheckIsBootstrapping();
|
|
|
|
|
2015-05-12 14:00:47 +00:00
|
|
|
// -------------------------------------------------------------------
|
|
|
|
// Imports
|
|
|
|
|
|
|
|
var GlobalMap = global.Map;
|
2015-05-20 15:59:51 +00:00
|
|
|
var InternalArray = shared.InternalArray;
|
2015-05-12 14:00:47 +00:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
|
|
|
|
var callSiteCache = new GlobalMap;
|
|
|
|
var mapGetFn = GlobalMap.prototype.get;
|
|
|
|
var mapSetFn = GlobalMap.prototype.set;
|
2015-04-07 19:00:34 +00:00
|
|
|
|
2014-11-20 22:37:31 +00:00
|
|
|
|
|
|
|
function SameCallSiteElements(rawStrings, other) {
|
|
|
|
var length = rawStrings.length;
|
|
|
|
var other = other.raw;
|
|
|
|
|
|
|
|
if (length !== other.length) return false;
|
|
|
|
|
|
|
|
for (var i = 0; i < length; ++i) {
|
|
|
|
if (rawStrings[i] !== other[i]) return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function GetCachedCallSite(siteObj, hash) {
|
2015-04-07 19:00:34 +00:00
|
|
|
var obj = %_CallFunction(callSiteCache, hash, mapGetFn);
|
2014-11-20 22:37:31 +00:00
|
|
|
|
|
|
|
if (IS_UNDEFINED(obj)) return;
|
|
|
|
|
|
|
|
var length = obj.length;
|
|
|
|
for (var i = 0; i < length; ++i) {
|
|
|
|
if (SameCallSiteElements(siteObj, obj[i])) return obj[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function SetCachedCallSite(siteObj, hash) {
|
2015-04-07 19:00:34 +00:00
|
|
|
var obj = %_CallFunction(callSiteCache, hash, mapGetFn);
|
2014-11-20 22:37:31 +00:00
|
|
|
var array;
|
|
|
|
|
|
|
|
if (IS_UNDEFINED(obj)) {
|
|
|
|
array = new InternalArray(1);
|
|
|
|
array[0] = siteObj;
|
2015-04-07 19:00:34 +00:00
|
|
|
%_CallFunction(callSiteCache, hash, array, mapSetFn);
|
2014-11-20 22:37:31 +00:00
|
|
|
} else {
|
|
|
|
obj.push(siteObj);
|
|
|
|
}
|
|
|
|
|
|
|
|
return siteObj;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-16 12:17:46 +00:00
|
|
|
$getTemplateCallSite = function(siteObj, rawStrings, hash) {
|
2014-11-20 22:37:31 +00:00
|
|
|
var cached = GetCachedCallSite(rawStrings, hash);
|
|
|
|
|
|
|
|
if (!IS_UNDEFINED(cached)) return cached;
|
2014-11-14 18:53:41 +00:00
|
|
|
|
|
|
|
%AddNamedProperty(siteObj, "raw", %ObjectFreeze(rawStrings),
|
|
|
|
READ_ONLY | DONT_ENUM | DONT_DELETE);
|
|
|
|
|
2014-11-20 22:37:31 +00:00
|
|
|
return SetCachedCallSite(%ObjectFreeze(siteObj), hash);
|
2014-11-14 18:53:41 +00:00
|
|
|
}
|
2015-04-07 19:00:34 +00:00
|
|
|
|
2015-05-11 08:14:54 +00:00
|
|
|
})
|