Fixed building on Mac OS X by recognizing i386 and friends as IA-32 platforms.

Added propagation of stack overflow exceptions that occur while compiling nested functions.

Improved debugger with support for recursive break points and handling of exceptions that occur in the debugger JavaScript code.

Renamed GetInternal to GetInternalField and SetInternal to SetInternalField in the API and moved InternalFieldCount and SetInternalFieldCount from FunctionTemplate to ObjectTemplate.


git-svn-id: http://v8.googlecode.com/svn/trunk@5 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
diff --git a/ChangeLog b/ChangeLog
index 12f56e0..884bed4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2008-07-16: Version 0.1.2 (127441)
+
+        Fixed building on Mac OS X by recognizing i386 and friends as
+        IA-32 platforms.
+
+        Added propagation of stack overflow exceptions that occur while
+        compiling nested functions.
+
+        Improved debugger with support for recursive break points and
+        handling of exceptions that occur in the debugger JavaScript code.
+
+        Renamed GetInternal to GetInternalField and SetInternal to
+        SetInternalField in the API and moved InternalFieldCount and
+        SetInternalFieldCount from FunctionTemplate to ObjectTemplate.
+
+
 2008-07-09: Version 0.1.1 (126448)
 
         Fixed bug in stack overflow check code for IA-32 targets where a
diff --git a/SConstruct b/SConstruct
index 81f2bf0..b31e65f 100644
--- a/SConstruct
+++ b/SConstruct
@@ -26,6 +26,7 @@
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 import platform
+import re
 import sys
 from os.path import join, dirname, abspath
 root_dir = dirname(File('SConstruct').rfile().abspath)
@@ -47,17 +48,17 @@
   elif id == 'Windows':
     return 'win32'
   else:
-    Abort("Don't know how to build v8 for OS '%s'." % id)
+    return '<none>'
 
 
 def GuessProcessor():
   id = platform.machine()
   if id.startswith('arm'):
     return 'arm'
-  elif (not id) or id.startswith('x86'):
+  elif (not id) or (not re.match('(x|i[3-6])86', id) is None):
     return 'ia32'
   else:
-    Abort("Don't know how to build v8 for processor '%s'." %  id)
+    return '<none>'
 
 
 def GuessToolchain(os):
@@ -70,8 +71,7 @@
   elif 'msvc' in tools:
     return 'msvc'
   else:
-    tools = ', '.join(tools)
-    Abort("Don't know how to build v8 using these tools: %s" % tools)
+    return '<none>'
 
 
 def GetOptions():
diff --git a/public/v8.h b/public/v8.h
index 891cb2e..256d5ba 100644
--- a/public/v8.h
+++ b/public/v8.h
@@ -905,10 +905,12 @@
    */
   Local<String> ObjectProtoToString();
 
-  // TODO(1245384): Naming, consistent.
+  /** Gets the number of internal fields for this Object. */
   int InternalFieldCount();
-  Local<Value> GetInternal(int index);
-  void SetInternal(int index, Handle<Value> value);
+  /** Gets the value in an internal field. */
+  Local<Value> GetInternalField(int index);
+  /** Sets the value in an internal field. */
+  void SetInternalField(int index, Handle<Value> value);
 
   // Testers for local properties.
   bool HasRealNamedProperty(Handle<String> key);
@@ -924,7 +926,7 @@
   /** Tests for a named lookup interceptor.*/
   bool HasNamedLookupInterceptor();
 
-    /** Tests for an index lookup interceptor.*/
+  /** Tests for an index lookup interceptor.*/
   bool HasIndexedLookupInterceptor();
 
 
@@ -1282,11 +1284,6 @@
    */
   Local<ObjectTemplate> PrototypeTemplate();
 
-  int InternalFieldCount();
-
-  /** Sets the number of internal fields on the object template.*/
-  void SetInternalFieldCount(int value);
-
   void SetClassName(Handle<String> name);
 
   /**
@@ -1406,6 +1403,18 @@
                                IndexedSecurityCallback indexed_handler,
                                Handle<Value> data = Handle<Value>());
 
+  /**
+   * Gets the number of internal fields for objects generated from
+   * this template.
+   */
+  int InternalFieldCount();
+
+  /**
+   * Sets the number of internal fields for objects generated from
+   * this template.
+   */
+  void SetInternalFieldCount(int value);
+
  private:
   ObjectTemplate();
   static Local<ObjectTemplate> New(Handle<FunctionTemplate> constructor);
diff --git a/src/api.cc b/src/api.cc
index 92d70af..5f1a94c 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -559,14 +559,6 @@
 }
 
 
-int FunctionTemplate::InternalFieldCount() {
-  if (IsDeadCheck("v8::FunctionTemplate::InternalFieldCount()")) {
-    return 0;
-  }
-  return i::Smi::cast(Utils::OpenHandle(this)->internal_field_count())->value();
-}
-
-
 Local<ObjectTemplate> FunctionTemplate::PrototypeTemplate() {
   if (IsDeadCheck("v8::FunctionTemplate::PrototypeTemplate()")) {
     return Local<ObjectTemplate>();
@@ -586,17 +578,6 @@
 }
 
 
-void FunctionTemplate::SetInternalFieldCount(int value) {
-  if (IsDeadCheck("v8::FunctionTemplate::SetInternalFieldCount()")) return;
-  if (!ApiCheck(i::Smi::IsValid(value),
-                "v8::FunctionTemplate::SetInternalFieldCount()",
-                "Invalid internal field count")) {
-    return;
-  }
-  Utils::OpenHandle(this)->set_internal_field_count(i::Smi::FromInt(value));
-}
-
-
 // To distinguish the function templates, so that we can find them in the
 // function cache of the global context.
 static int next_serial_number = 0;
@@ -612,7 +593,6 @@
       i::Handle<i::FunctionTemplateInfo>::cast(struct_obj);
   InitializeFunctionTemplate(obj);
   obj->set_serial_number(i::Smi::FromInt(next_serial_number++));
-  obj->set_internal_field_count(i::Smi::FromInt(0));
   if (callback != 0) {
     if (data.IsEmpty()) data = v8::Undefined();
     Utils::ToLocal(obj)->SetCallHandler(callback, data);
@@ -750,6 +730,89 @@
 }
 
 
+void FunctionTemplate::SetClassName(Handle<String> name) {
+  if (IsDeadCheck("v8::FunctionTemplate::SetClassName()")) return;
+  Utils::OpenHandle(this)->set_class_name(*Utils::OpenHandle(*name));
+}
+
+
+void FunctionTemplate::SetHiddenPrototype(bool value) {
+  if (IsDeadCheck("v8::FunctionTemplate::SetHiddenPrototype()")) return;
+  Utils::OpenHandle(this)->set_hidden_prototype(value);
+}
+
+
+void FunctionTemplate::SetNamedInstancePropertyHandler(
+      NamedPropertyGetter getter,
+      NamedPropertySetter setter,
+      NamedPropertyQuery query,
+      NamedPropertyDeleter remover,
+      NamedPropertyEnumerator enumerator,
+      Handle<Value> data) {
+  if (IsDeadCheck("v8::FunctionTemplate::SetNamedInstancePropertyHandler()")) {
+    return;
+  }
+  HandleScope scope;
+  i::Handle<i::Struct> struct_obj =
+      i::Factory::NewStruct(i::INTERCEPTOR_INFO_TYPE);
+  i::Handle<i::InterceptorInfo> obj =
+      i::Handle<i::InterceptorInfo>::cast(struct_obj);
+  if (getter != 0) obj->set_getter(*FromCData(getter));
+  if (setter != 0) obj->set_setter(*FromCData(setter));
+  if (query != 0) obj->set_query(*FromCData(query));
+  if (remover != 0) obj->set_deleter(*FromCData(remover));
+  if (enumerator != 0) obj->set_enumerator(*FromCData(enumerator));
+  if (data.IsEmpty()) data = v8::Undefined();
+  obj->set_data(*Utils::OpenHandle(*data));
+  Utils::OpenHandle(this)->set_named_property_handler(*obj);
+}
+
+
+void FunctionTemplate::SetIndexedInstancePropertyHandler(
+      IndexedPropertyGetter getter,
+      IndexedPropertySetter setter,
+      IndexedPropertyQuery query,
+      IndexedPropertyDeleter remover,
+      IndexedPropertyEnumerator enumerator,
+      Handle<Value> data) {
+  if (IsDeadCheck(
+        "v8::FunctionTemplate::SetIndexedInstancePropertyHandler()")) {
+    return;
+  }
+  HandleScope scope;
+  i::Handle<i::Struct> struct_obj =
+      i::Factory::NewStruct(i::INTERCEPTOR_INFO_TYPE);
+  i::Handle<i::InterceptorInfo> obj =
+      i::Handle<i::InterceptorInfo>::cast(struct_obj);
+  if (getter != 0) obj->set_getter(*FromCData(getter));
+  if (setter != 0) obj->set_setter(*FromCData(setter));
+  if (query != 0) obj->set_query(*FromCData(query));
+  if (remover != 0) obj->set_deleter(*FromCData(remover));
+  if (enumerator != 0) obj->set_enumerator(*FromCData(enumerator));
+  if (data.IsEmpty()) data = v8::Undefined();
+  obj->set_data(*Utils::OpenHandle(*data));
+  Utils::OpenHandle(this)->set_indexed_property_handler(*obj);
+}
+
+
+void FunctionTemplate::SetInstanceCallAsFunctionHandler(
+      InvocationCallback callback,
+      Handle<Value> data) {
+  if (IsDeadCheck("v8::FunctionTemplate::SetInstanceCallAsFunctionHandler()")) {
+    return;
+  }
+  HandleScope scope;
+  i::Handle<i::Struct> struct_obj =
+      i::Factory::NewStruct(i::CALL_HANDLER_INFO_TYPE);
+  i::Handle<i::CallHandlerInfo> obj =
+      i::Handle<i::CallHandlerInfo>::cast(struct_obj);
+  obj->set_callback(*FromCData(callback));
+  if (data.IsEmpty()) data = v8::Undefined();
+  obj->set_data(*Utils::OpenHandle(*data));
+  Utils::OpenHandle(this)->set_instance_call_handler(*obj);
+}
+
+
 // --- O b j e c t T e m p l a t e ---
 
 
@@ -770,6 +833,7 @@
   InitializeTemplate(obj, Consts::OBJECT_TEMPLATE);
   if (!constructor.IsEmpty())
     obj->set_constructor(*Utils::OpenHandle(*constructor));
+  obj->set_internal_field_count(i::Smi::FromInt(0));
   return Utils::ToLocal(obj);
 }
 
@@ -898,87 +962,26 @@
 }
 
 
-void FunctionTemplate::SetClassName(Handle<String> name) {
-  if (IsDeadCheck("v8::FunctionTemplate::SetClassName()")) return;
-  Utils::OpenHandle(this)->set_class_name(*Utils::OpenHandle(*name));
+int ObjectTemplate::InternalFieldCount() {
+  if (IsDeadCheck("v8::ObjectTemplate::InternalFieldCount()")) {
+    return 0;
+  }
+  return i::Smi::cast(Utils::OpenHandle(this)->internal_field_count())->value();
 }
 
 
-void FunctionTemplate::SetHiddenPrototype(bool value) {
-  if (IsDeadCheck("v8::FunctionTemplate::SetHiddenPrototype()")) return;
-  Utils::OpenHandle(this)->set_hidden_prototype(value);
-}
-
-
-void FunctionTemplate::SetNamedInstancePropertyHandler(
-      NamedPropertyGetter getter,
-      NamedPropertySetter setter,
-      NamedPropertyQuery query,
-      NamedPropertyDeleter remover,
-      NamedPropertyEnumerator enumerator,
-      Handle<Value> data) {
-  if (IsDeadCheck("v8::FunctionTemplate::SetNamedInstancePropertyHandler()")) {
+void ObjectTemplate::SetInternalFieldCount(int value) {
+  if (IsDeadCheck("v8::ObjectTemplate::SetInternalFieldCount()")) return;
+  if (!ApiCheck(i::Smi::IsValid(value),
+                "v8::ObjectTemplate::SetInternalFieldCount()",
+                "Invalid internal field count")) {
     return;
   }
-  HandleScope scope;
-  i::Handle<i::Struct> struct_obj =
-      i::Factory::NewStruct(i::INTERCEPTOR_INFO_TYPE);
-  i::Handle<i::InterceptorInfo> obj =
-      i::Handle<i::InterceptorInfo>::cast(struct_obj);
-  if (getter != 0) obj->set_getter(*FromCData(getter));
-  if (setter != 0) obj->set_setter(*FromCData(setter));
-  if (query != 0) obj->set_query(*FromCData(query));
-  if (remover != 0) obj->set_deleter(*FromCData(remover));
-  if (enumerator != 0) obj->set_enumerator(*FromCData(enumerator));
-  if (data.IsEmpty()) data = v8::Undefined();
-  obj->set_data(*Utils::OpenHandle(*data));
-  Utils::OpenHandle(this)->set_named_property_handler(*obj);
+  Utils::OpenHandle(this)->set_internal_field_count(i::Smi::FromInt(value));
 }
 
 
-void FunctionTemplate::SetIndexedInstancePropertyHandler(
-      IndexedPropertyGetter getter,
-      IndexedPropertySetter setter,
-      IndexedPropertyQuery query,
-      IndexedPropertyDeleter remover,
-      IndexedPropertyEnumerator enumerator,
-      Handle<Value> data) {
-  if (IsDeadCheck(
-        "v8::FunctionTemplate::SetIndexedInstancePropertyHandler()")) {
-    return;
-  }
-  HandleScope scope;
-  i::Handle<i::Struct> struct_obj =
-      i::Factory::NewStruct(i::INTERCEPTOR_INFO_TYPE);
-  i::Handle<i::InterceptorInfo> obj =
-      i::Handle<i::InterceptorInfo>::cast(struct_obj);
-  if (getter != 0) obj->set_getter(*FromCData(getter));
-  if (setter != 0) obj->set_setter(*FromCData(setter));
-  if (query != 0) obj->set_query(*FromCData(query));
-  if (remover != 0) obj->set_deleter(*FromCData(remover));
-  if (enumerator != 0) obj->set_enumerator(*FromCData(enumerator));
-  if (data.IsEmpty()) data = v8::Undefined();
-  obj->set_data(*Utils::OpenHandle(*data));
-  Utils::OpenHandle(this)->set_indexed_property_handler(*obj);
-}
-
-
-void FunctionTemplate::SetInstanceCallAsFunctionHandler(
-      InvocationCallback callback,
-      Handle<Value> data) {
-  if (IsDeadCheck("v8::FunctionTemplate::SetInstanceCallAsFunctionHandler()")) {
-    return;
-  }
-  HandleScope scope;
-  i::Handle<i::Struct> struct_obj =
-      i::Factory::NewStruct(i::CALL_HANDLER_INFO_TYPE);
-  i::Handle<i::CallHandlerInfo> obj =
-      i::Handle<i::CallHandlerInfo>::cast(struct_obj);
-  obj->set_callback(*FromCData(callback));
-  if (data.IsEmpty()) data = v8::Undefined();
-  obj->set_data(*Utils::OpenHandle(*data));
-  Utils::OpenHandle(this)->set_instance_call_handler(*obj);
-}
+// --- S c r i p t D a t a ---
 
 
 ScriptData* ScriptData::PreCompile(const char* input, int length) {
@@ -2041,11 +2044,11 @@
 }
 
 
-Local<Value> v8::Object::GetInternal(int index) {
-  if (IsDeadCheck("v8::Object::GetInternal()")) return Local<Value>();
+Local<Value> v8::Object::GetInternalField(int index) {
+  if (IsDeadCheck("v8::Object::GetInternalField()")) return Local<Value>();
   i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
   if (!ApiCheck(index < obj->GetInternalFieldCount(),
-                "v8::Object::GetInternal()",
+                "v8::Object::GetInternalField()",
                 "Reading internal field out of bounds")) {
     return Local<Value>();
   }
@@ -2054,11 +2057,11 @@
 }
 
 
-void v8::Object::SetInternal(int index, v8::Handle<Value> value) {
-  if (IsDeadCheck("v8::Object::SetInternal()")) return;
+void v8::Object::SetInternalField(int index, v8::Handle<Value> value) {
+  if (IsDeadCheck("v8::Object::SetInternalField()")) return;
   i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
   if (!ApiCheck(index < obj->GetInternalFieldCount(),
-                "v8::Object::SetInternal()",
+                "v8::Object::SetInternalField()",
                 "Writing internal field out of bounds")) {
     return;
   }
diff --git a/src/ast.h b/src/ast.h
index 48b5dc7..1a5e0e0 100644
--- a/src/ast.h
+++ b/src/ast.h
@@ -1217,6 +1217,12 @@
     return (stack_overflow_ = true);
   }
 
+  // If a stack-overflow exception is encountered when visiting a
+  // node, calling SetStackOverflow will make sure that the visitor
+  // bails out without visiting more nodes.
+  void SetStackOverflow() { stack_overflow_ = true; }
+
+
   // Individual nodes
 #define DEF_VISIT(type)                         \
   virtual void Visit##type(type* node) = 0;
diff --git a/src/codegen-arm.cc b/src/codegen-arm.cc
index 25f165f..ac870fb 100644
--- a/src/codegen-arm.cc
+++ b/src/codegen-arm.cc
@@ -346,7 +346,7 @@
   ArmCodeGenerator cgen(initial_buffer_size, script, is_eval);
   cgen.GenCode(flit);
   if (cgen.HasStackOverflow()) {
-    Top::StackOverflow();
+    ASSERT(!Top::has_pending_exception());
     return Handle<Code>::null();
   }
 
@@ -546,6 +546,9 @@
     } else {
       Comment cmnt(masm_, "[ declarations");
       ProcessDeclarations(scope->declarations());
+      // Bail out if a stack-overflow exception occured when
+      // processing declarations.
+      if (HasStackOverflow()) return;
     }
 
     if (FLAG_trace) __ CallRuntime(Runtime::kTraceEnter, 1);
@@ -2903,6 +2906,8 @@
 
   // Build the function boilerplate and instantiate it.
   Handle<JSFunction> boilerplate = BuildBoilerplate(node);
+  // Check for stack-overflow exception.
+  if (HasStackOverflow()) return;
   InstantiateBoilerplate(boilerplate);
 }
 
diff --git a/src/codegen-ia32.cc b/src/codegen-ia32.cc
index cb3abe2..f4ee826 100644
--- a/src/codegen-ia32.cc
+++ b/src/codegen-ia32.cc
@@ -361,7 +361,7 @@
   Ia32CodeGenerator cgen(initial_buffer_size, script, is_eval);
   cgen.GenCode(flit);
   if (cgen.HasStackOverflow()) {
-    Top::StackOverflow();
+    ASSERT(!Top::has_pending_exception());
     return Handle<Code>::null();
   }
 
@@ -571,6 +571,9 @@
     } else {
       Comment cmnt(masm_, "[ declarations");
       ProcessDeclarations(scope->declarations());
+      // Bail out if a stack-overflow exception occured when
+      // processing declarations.
+      if (HasStackOverflow()) return;
     }
 
     if (FLAG_trace) {
@@ -3250,6 +3253,8 @@
 
   // Build the function boilerplate and instantiate it.
   Handle<JSFunction> boilerplate = BuildBoilerplate(node);
+  // Check for stack-overflow exception.
+  if (HasStackOverflow()) return;
   InstantiateBoilerplate(boilerplate);
 }
 
diff --git a/src/codegen.cc b/src/codegen.cc
index 3b80aa9..9f428ac 100644
--- a/src/codegen.cc
+++ b/src/codegen.cc
@@ -115,6 +115,12 @@
   } else {
     code = MakeCode(node, script_, false);
 
+    // Check for stack-overflow exception.
+    if (code.is_null()) {
+      SetStackOverflow();
+      return Handle<JSFunction>::null();
+    }
+
     // Function compilation complete.
     LOG(CodeCreateEvent("Function", *code, *node->name()));
   }
@@ -186,7 +192,10 @@
           array->set_undefined(j++);
         }
       } else {
-        array->set(j++, *BuildBoilerplate(node->fun()));
+        Handle<JSFunction> function = BuildBoilerplate(node->fun());
+        // Check for stack-overflow exception.
+        if (HasStackOverflow()) return;
+        array->set(j++, *function);
       }
     }
   }
diff --git a/src/compiler.cc b/src/compiler.cc
index 0af486c..48502ca 100644
--- a/src/compiler.cc
+++ b/src/compiler.cc
@@ -77,7 +77,8 @@
 
   // Rewrite the AST by introducing .result assignments where needed.
   if (!Rewriter::Process(literal) || !AnalyzeVariableUsage(literal)) {
-    Top::StackOverflow();
+    // Signal a stack overflow by returning a null handle.  The stack
+    // overflow exception will be thrown by the caller.
     return Handle<Code>::null();
   }
 
@@ -122,6 +123,13 @@
   // Build AST.
   FunctionLiteral* lit = MakeAST(is_global, script, extension, pre_data);
 
+  // Check for parse errors.
+  if (lit == NULL) {
+    ASSERT(Top::has_pending_exception());
+    StackGuard::EnableInterrupts();
+    return Handle<JSFunction>::null();
+  }
+
   // Measure how long it takes to do the compilation; only take the
   // rest of the function into account to avoid overlap with the
   // parsing statistics.
@@ -131,12 +139,11 @@
   StatsRateScope timer(rate);
 
   // Compile the code.
-  Handle<Code> code = Handle<Code>::null();
-  if (lit != NULL) code = MakeCode(lit, script, is_eval);
+  Handle<Code> code = MakeCode(lit, script, is_eval);
 
-  // Check for stack overflow.
+  // Check for stack-overflow exceptions.
   if (code.is_null()) {
-    ASSERT(Top::has_pending_exception());
+    Top::StackOverflow();
     StackGuard::EnableInterrupts();
     return Handle<JSFunction>::null();
   }
@@ -253,18 +260,24 @@
                                      end_position,
                                      is_expression);
 
+  // Check for parse errors.
+  if (lit == NULL) {
+    ASSERT(Top::has_pending_exception());
+    StackGuard::EnableInterrupts();
+    return false;
+  }
+
   // Measure how long it takes to do the lazy compilation; only take
   // the rest of the function into account to avoid overlap with the
   // lazy parsing statistics.
   StatsRateScope timer(&Counters::compile_lazy);
 
-  // Compile the code (if we have a syntax tree).
-  Handle<Code> code = Handle<Code>::null();
-  if (lit != NULL) code = MakeCode(lit, script, false);
+  // Compile the code.
+  Handle<Code> code = MakeCode(lit, script, false);
 
-  // Check for stack-overflow during compilation.
+  // Check for stack-overflow exception.
   if (code.is_null()) {
-    ASSERT(Top::has_pending_exception());
+    Top::StackOverflow();
     StackGuard::EnableInterrupts();
     return false;
   }
diff --git a/src/debug.cc b/src/debug.cc
index 997e937..e7f5ee2 100644
--- a/src/debug.cc
+++ b/src/debug.cc
@@ -578,9 +578,7 @@
 
 bool Debug::Load() {
   // Return if debugger is already loaded.
-  if (IsLoaded()) {
-    return true;
-  }
+  if (IsLoaded()) return true;
 
   // Create the debugger context.
   HandleScope scope;
@@ -1499,17 +1497,20 @@
 
   // Call ProcessDebugRequest expect String result. The ProcessDebugRequest
   // will never throw an exception (see debug.js).
-  bool has_pending_exception = false;
+  bool caught_exception;
   const int argc = 3;
   Object** argv[argc] = { exec_state.location(),
                           request.location(),
                           stopped ? Factory::true_value().location() :
                                     Factory::false_value().location()};
-  Handle<Object> result = Execution::Call(process_denbug_request,
-                                          Factory::undefined_value(),
-                                          argc, argv,
-                                          &has_pending_exception);
-  ASSERT(!has_pending_exception);
+  Handle<Object> result = Execution::TryCall(process_denbug_request,
+                                             Factory::undefined_value(),
+                                             argc, argv,
+                                             &caught_exception);
+  if (caught_exception) {
+    return Factory::empty_symbol();
+  }
+
   return Handle<String>::cast(result);
 }
 
@@ -1522,14 +1523,17 @@
         *Factory::LookupAsciiSymbol("IsPlainBreakRequest"))));
 
   // Call ProcessDebugRequest expect String result.
-  bool has_pending_exception = false;
+  bool caught_exception;
   const int argc = 1;
   Object** argv[argc] = { request.location() };
-  Handle<Object> result = Execution::Call(process_denbug_request,
-                                          Factory::undefined_value(),
-                                          argc, argv,
-                                          &has_pending_exception);
-  ASSERT(!has_pending_exception);
+  Handle<Object> result = Execution::TryCall(process_denbug_request,
+                                             Factory::undefined_value(),
+                                             argc, argv,
+                                             &caught_exception);
+  if (caught_exception) {
+    return false;
+  }
+
   return *result == Heap::true_value();
 }
 
@@ -1551,7 +1555,8 @@
     if (!Debug::break_on_exception()) return;
   }
 
-  // Enter the debugger.
+  // Enter the debugger.  Bail out if the debugger cannot be loaded.
+  if (!Debug::Load()) return;
   SaveBreakFrame save;
   EnterDebuggerContext enter;
 
@@ -1579,6 +1584,9 @@
 void Debugger::OnDebugBreak(Handle<Object> break_points_hit) {
   HandleScope scope;
 
+  // Debugger has already been entered by caller.
+  ASSERT(Top::context() == *Debug::debug_context());
+
   // Bail out if there is no listener for this event
   if (!Debugger::EventActive(v8::Break)) return;
 
@@ -1611,8 +1619,8 @@
   if (compiling_natives()) return;
   if (!EventActive(v8::BeforeCompile)) return;
 
-  // Enter the debugger.
-  Debug::Load();
+  // Enter the debugger.  Bail out if the debugger cannot be loaded.
+  if (!Debug::Load()) return;
   SaveBreakFrame save;
   EnterDebuggerContext enter;
 
@@ -1633,15 +1641,18 @@
 
 // Handle debugger actions when a new script is compiled.
 void Debugger::OnAfterCompile(Handle<Script> script, Handle<JSFunction> fun) {
+  HandleScope scope;
+
   // No compile events while compiling natives.
   if (compiling_natives()) return;
 
   // No more to do if not debugging.
   if (!debugger_active()) return;
 
-  HandleScope scope;
+  // Enter the debugger.  Bail out if the debugger cannot be loaded.
+  if (!Debug::Load()) return;
+  SaveBreakFrame save;
   EnterDebuggerContext enter;
-  bool caught_exception = false;
 
   // If debugging there might be script break points registered for this
   // script. Make sure that these break points are set.
@@ -1660,6 +1671,7 @@
   Handle<JSValue> wrapper = GetScriptWrapper(script);
 
   // Call UpdateScriptBreakPoints expect no exceptions.
+  bool caught_exception = false;
   const int argc = 1;
   Object** argv[argc] = { reinterpret_cast<Object**>(wrapper.location()) };
   Handle<Object> result = Execution::TryCall(
@@ -1697,7 +1709,8 @@
   if (compiling_natives()) return;
   if (!Debugger::EventActive(v8::NewFunction)) return;
 
-  // Enter the debugger.
+  // Enter the debugger.  Bail out if the debugger cannot be loaded.
+  if (!Debug::Load()) return;
   SaveBreakFrame save;
   EnterDebuggerContext enter;
 
@@ -1954,9 +1967,7 @@
 void DebugMessageThread::DebugEvent(v8::DebugEvent event,
                                     Handle<Object> exec_state,
                                     Handle<Object> event_data) {
-  if (!Debug::Load()) {
-    return;
-  }
+  if (!Debug::Load()) return;
 
   // Process the individual events.
   bool interactive = false;
diff --git a/src/factory.cc b/src/factory.cc
index 6a5aafd..1fcaf0b 100644
--- a/src/factory.cc
+++ b/src/factory.cc
@@ -619,18 +619,27 @@
     bool is_global) {
   Handle<Code> code = Handle<Code>(Builtins::builtin(Builtins::HandleApiCall));
 
-  int internal_field_count = Smi::cast(obj->internal_field_count())->value();
-  int size = kPointerSize * internal_field_count;
+  int internal_field_count = 0;
+  if (!obj->instance_template()->IsUndefined()) {
+    Handle<ObjectTemplateInfo> instance_template =
+        Handle<ObjectTemplateInfo>(
+            ObjectTemplateInfo::cast(obj->instance_template()));
+    internal_field_count =
+        Smi::cast(instance_template->internal_field_count())->value();
+  }
+
+  int instance_size = kPointerSize * internal_field_count;
   if (is_global) {
-    size += JSGlobalObject::kSize;
+    instance_size += JSGlobalObject::kSize;
   } else {
-    size += JSObject::kHeaderSize;
+    instance_size += JSObject::kHeaderSize;
   }
 
   InstanceType type = is_global ? JS_GLOBAL_OBJECT_TYPE : JS_OBJECT_TYPE;
 
   Handle<JSFunction> result =
-      Factory::NewFunction(Factory::empty_symbol(), type, size, code, true);
+      Factory::NewFunction(Factory::empty_symbol(), type, instance_size,
+                           code, true);
   // Set class name.
   Handle<Object> class_name = Handle<Object>(obj->class_name());
   if (class_name->IsString()) {
diff --git a/src/macros.py b/src/macros.py
index 6be0e20..ba54b2c 100644
--- a/src/macros.py
+++ b/src/macros.py
@@ -37,13 +37,13 @@
 const GETTER = 0;
 const SETTER = 1;
 
-# These definitions must match the constants defined in v9.h
+# These definitions must match the index of the properties in objects.h.
 const kApiTagOffset =                  0;
 const kApiPropertyListOffset =         1;
 const kApiSerialNumberOffset =         2;
 const kApiConstructorOffset =          2;
-const kApiPrototypeTemplateOffset =    6;
-const kApiParentTemplateOffset =       7;
+const kApiPrototypeTemplateOffset =    5;
+const kApiParentTemplateOffset =       6;
 
 const NO_HINT     = 0;
 const NUMBER_HINT = 1;
diff --git a/src/objects-debug.cc b/src/objects-debug.cc
index 61e2b4d..2a78c5d 100644
--- a/src/objects-debug.cc
+++ b/src/objects-debug.cc
@@ -757,7 +757,6 @@
   TemplateInfoVerify();
   VerifyPointer(serial_number());
   VerifyPointer(call_code());
-  VerifyPointer(internal_field_count());
   VerifyPointer(property_accessors());
   VerifyPointer(prototype_template());
   VerifyPointer(parent_template());
@@ -778,8 +777,6 @@
   serial_number()->ShortPrint();
   PrintF("\n - call_code: ");
   call_code()->ShortPrint();
-  PrintF("\n - internal_field_count: ");
-  internal_field_count()->ShortPrint();
   PrintF("\n - property_accessors: ");
   property_accessors()->ShortPrint();
   PrintF("\n - prototype_template: ");
@@ -805,12 +802,15 @@
   CHECK(IsObjectTemplateInfo());
   TemplateInfoVerify();
   VerifyPointer(constructor());
+  VerifyPointer(internal_field_count());
 }
 
 void ObjectTemplateInfo::ObjectTemplateInfoPrint() {
   PrintF("ObjectTemplateInfo");
-  PrintF("\n - constructor");
+  PrintF("\n - constructor: ");
   constructor()->ShortPrint();
+  PrintF("\n - internal_field_count: ");
+  internal_field_count()->ShortPrint();
 }
 
 void SignatureInfo::SignatureInfoVerify() {
@@ -821,9 +821,9 @@
 
 void SignatureInfo::SignatureInfoPrint() {
   PrintF("SignatureInfo");
-  PrintF("\n - receiver");
+  PrintF("\n - receiver: ");
   receiver()->ShortPrint();
-  PrintF("\n - args");
+  PrintF("\n - args: ");
   args()->ShortPrint();
 }
 
@@ -834,7 +834,7 @@
 
 void TypeSwitchInfo::TypeSwitchInfoPrint() {
   PrintF("TypeSwitchInfo");
-  PrintF("\n - types");
+  PrintF("\n - types: ");
   types()->ShortPrint();
 }
 
diff --git a/src/objects-inl.h b/src/objects-inl.h
index 5ff5326..121f59c 100644
--- a/src/objects-inl.h
+++ b/src/objects-inl.h
@@ -1522,8 +1522,6 @@
 
 ACCESSORS(FunctionTemplateInfo, serial_number, Object, kSerialNumberOffset)
 ACCESSORS(FunctionTemplateInfo, call_code, Object, kCallCodeOffset)
-ACCESSORS(FunctionTemplateInfo, internal_field_count, Object,
-          kInternalFieldCountOffset)
 ACCESSORS(FunctionTemplateInfo, property_accessors, Object,
           kPropertyAccessorsOffset)
 ACCESSORS(FunctionTemplateInfo, prototype_template, Object,
@@ -1545,6 +1543,8 @@
 ACCESSORS(FunctionTemplateInfo, flag, Smi, kFlagOffset)
 
 ACCESSORS(ObjectTemplateInfo, constructor, Object, kConstructorOffset)
+ACCESSORS(ObjectTemplateInfo, internal_field_count, Object,
+          kInternalFieldCountOffset)
 
 ACCESSORS(SignatureInfo, receiver, Object, kReceiverOffset)
 ACCESSORS(SignatureInfo, args, Object, kArgsOffset)
diff --git a/src/objects.h b/src/objects.h
index 595a550..f51d894 100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -3326,7 +3326,6 @@
  public:
   DECL_ACCESSORS(serial_number, Object)
   DECL_ACCESSORS(call_code, Object)
-  DECL_ACCESSORS(internal_field_count, Object)
   DECL_ACCESSORS(property_accessors, Object)
   DECL_ACCESSORS(prototype_template, Object)
   DECL_ACCESSORS(parent_template, Object)
@@ -3356,9 +3355,7 @@
 
   static const int kSerialNumberOffset = TemplateInfo::kHeaderSize;
   static const int kCallCodeOffset = kSerialNumberOffset + kPointerSize;
-  static const int kInternalFieldCountOffset = kCallCodeOffset + kPointerSize;
-  static const int kPropertyAccessorsOffset =
-      kInternalFieldCountOffset + kPointerSize;
+  static const int kPropertyAccessorsOffset = kCallCodeOffset + kPointerSize;
   static const int kPrototypeTemplateOffset =
       kPropertyAccessorsOffset + kPointerSize;
   static const int kParentTemplateOffset =
@@ -3392,6 +3389,7 @@
 class ObjectTemplateInfo: public TemplateInfo {
  public:
   DECL_ACCESSORS(constructor, Object)
+  DECL_ACCESSORS(internal_field_count, Object)
 
   static inline ObjectTemplateInfo* cast(Object* obj);
 
@@ -3401,7 +3399,9 @@
 #endif
 
   static const int kConstructorOffset = TemplateInfo::kHeaderSize;
-  static const int kSize              = kConstructorOffset + kHeaderSize;
+  static const int kInternalFieldCountOffset =
+      kConstructorOffset + kPointerSize;
+  static const int kSize = kInternalFieldCountOffset + kHeaderSize;
 };