Fixed issue 54, under some circumstances internal field count set on
authorchristian.plesner.hansen@gmail.com <christian.plesner.hansen@gmail.com@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 9 Sep 2008 07:57:43 +0000 (07:57 +0000)
committerchristian.plesner.hansen@gmail.com <christian.plesner.hansen@gmail.com@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 9 Sep 2008 07:57:43 +0000 (07:57 +0000)
object templates did not take effect.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@226 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/api.cc
test/cctest/test-api.cc

index 6ff2bd69ebbbb6cb2263537e6225f3608c862207..f8bd63f482ceba71eef28b896779f7582522e962 100644 (file)
@@ -979,6 +979,12 @@ void ObjectTemplate::SetInternalFieldCount(int value) {
                 "Invalid internal field count")) {
     return;
   }
+  if (value > 0) {
+    // The internal field count is set by the constructor function's
+    // construct code, so we ensure that there is a constructor
+    // function to do the setting.
+    EnsureConstructor(this);
+  }
   Utils::OpenHandle(this)->set_internal_field_count(i::Smi::FromInt(value));
 }
 
index d70fd8e8e0ed3f837d3b97d4de9a8c00ef2e2931..a550e5ea36ffaf4da75359cda48949bdabe0f3d3 100644 (file)
@@ -4825,3 +4825,21 @@ THREADED_TEST(DisposeEnteredContext) {
     inner->Exit();
   }
 }
+
+
+// Regression test for issue 54, object templates with internal fields
+// but no accessors or interceptors did not get their internal field
+// count set on instances.
+THREADED_TEST(Regress54) {
+  v8::HandleScope outer;
+  LocalContext context;
+  static v8::Persistent<v8::ObjectTemplate> templ;
+  if (templ.IsEmpty()) {
+    v8::HandleScope inner;
+    v8::Handle<v8::ObjectTemplate> local = v8::ObjectTemplate::New();
+    local->SetInternalFieldCount(1);
+    templ = v8::Persistent<v8::ObjectTemplate>::New(inner.Close(local));
+  }
+  v8::Handle<v8::Object> result = templ->NewInstance();
+  CHECK_EQ(1, result->InternalFieldCount());
+}