Commit e13aed2d authored by olehougaard's avatar olehougaard

Do not cache functions until we know they are fully constructed. This is...

Do not cache functions until we know they are fully constructed. This is needed in case of a stack overflow during construction.
Review URL: http://codereview.chromium.org/17354

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1056 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 21d28657
......@@ -59,23 +59,34 @@ function Instantiate(data, name) {
function InstantiateFunction(data, name) {
// We need a reference to kApiFunctionCache in the stack frame
// if we need to bail out from a stack overflow.
var cache = kApiFunctionCache;
var serialNumber = %GetTemplateField(data, kApiSerialNumberOffset);
if (!(serialNumber in kApiFunctionCache)) {
kApiFunctionCache[serialNumber] = null;
var fun = %CreateApiFunction(data);
if (name) %FunctionSetName(fun, name);
kApiFunctionCache[serialNumber] = fun;
var prototype = %GetTemplateField(data, kApiPrototypeTemplateOffset);
fun.prototype = prototype ? Instantiate(prototype) : {};
%SetProperty(fun.prototype, "constructor", fun, DONT_ENUM);
var parent = %GetTemplateField(data, kApiParentTemplateOffset);
if (parent) {
var parent_fun = Instantiate(parent);
fun.prototype.__proto__ = parent_fun.prototype;
var isFunctionCached =
(serialNumber in cache) &&
(cache[serialNumber] != -1);
if (!isFunctionCached) {
try {
cache[serialNumber] = null;
var fun = %CreateApiFunction(data);
if (name) %FunctionSetName(fun, name);
cache[serialNumber] = fun;
var prototype = %GetTemplateField(data, kApiPrototypeTemplateOffset);
fun.prototype = prototype ? Instantiate(prototype) : {};
%SetProperty(fun.prototype, "constructor", fun, DONT_ENUM);
var parent = %GetTemplateField(data, kApiParentTemplateOffset);
if (parent) {
var parent_fun = Instantiate(parent);
fun.prototype.__proto__ = parent_fun.prototype;
}
ConfigureTemplateInstance(fun, data);
} catch (e) {
cache[serialNumber] = -1;
throw e;
}
ConfigureTemplateInstance(fun, data);
}
return kApiFunctionCache[serialNumber];
return cache[serialNumber];
}
......
......@@ -439,7 +439,7 @@ Handle<JSFunction> Execution::InstantiateFunction(
int serial_number = Smi::cast(data->serial_number())->value();
Object* elm =
Top::global_context()->function_cache()->GetElement(serial_number);
if (!elm->IsUndefined()) return Handle<JSFunction>(JSFunction::cast(elm));
if (elm->IsJSFunction()) return Handle<JSFunction>(JSFunction::cast(elm));
// The function has not yet been instantiated in this context; do it.
Object** args[1] = { Handle<Object>::cast(data).location() };
Handle<Object> result =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment