Author: olehougaard
Date: Mon Jan 12 23:13:33 2009
New Revision: 1056

Modified:
    branches/bleeding_edge/src/apinatives.js
    branches/bleeding_edge/src/execution.cc

Log:
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

Modified: branches/bleeding_edge/src/apinatives.js
==============================================================================
--- branches/bleeding_edge/src/apinatives.js    (original)
+++ branches/bleeding_edge/src/apinatives.js    Mon Jan 12 23:13:33 2009
@@ -59,23 +59,34 @@


  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];
  }



Modified: branches/bleeding_edge/src/execution.cc
==============================================================================
--- branches/bleeding_edge/src/execution.cc     (original)
+++ branches/bleeding_edge/src/execution.cc     Mon Jan 12 23:13:33 2009
@@ -439,7 +439,7 @@
    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 =

--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to